lpfc_sli.c 487 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877
  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 = q->qe[q->host_index].wqe;
  85. struct lpfc_register doorbell;
  86. uint32_t host_index;
  87. /* If the host has not yet processed the next entry then we are done */
  88. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  89. return -ENOMEM;
  90. /* set consumption flag every once in a while */
  91. if (!((q->host_index + 1) % q->entry_repost))
  92. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  93. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  94. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  95. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  96. /* Update the host index before invoking device */
  97. host_index = q->host_index;
  98. q->host_index = ((q->host_index + 1) % q->entry_count);
  99. /* Ring Doorbell */
  100. doorbell.word0 = 0;
  101. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  102. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  103. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  104. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  105. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  106. return 0;
  107. }
  108. /**
  109. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  110. * @q: The Work Queue to operate on.
  111. * @index: The index to advance the hba index to.
  112. *
  113. * This routine will update the HBA index of a queue to reflect consumption of
  114. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  115. * an entry the host calls this function to update the queue's internal
  116. * pointers. This routine returns the number of entries that were consumed by
  117. * the HBA.
  118. **/
  119. static uint32_t
  120. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  121. {
  122. uint32_t released = 0;
  123. if (q->hba_index == index)
  124. return 0;
  125. do {
  126. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  127. released++;
  128. } while (q->hba_index != index);
  129. return released;
  130. }
  131. /**
  132. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  133. * @q: The Mailbox Queue to operate on.
  134. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  135. *
  136. * This routine will copy the contents of @mqe to the next available entry on
  137. * the @q. This function will then ring the Work Queue Doorbell to signal the
  138. * HBA to start processing the Work Queue Entry. This function returns 0 if
  139. * successful. If no entries are available on @q then this function will return
  140. * -ENOMEM.
  141. * The caller is expected to hold the hbalock when calling this routine.
  142. **/
  143. static uint32_t
  144. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  145. {
  146. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  147. struct lpfc_register doorbell;
  148. uint32_t host_index;
  149. /* If the host has not yet processed the next entry then we are done */
  150. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  151. return -ENOMEM;
  152. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  153. /* Save off the mailbox pointer for completion */
  154. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  155. /* Update the host index before invoking device */
  156. host_index = q->host_index;
  157. q->host_index = ((q->host_index + 1) % q->entry_count);
  158. /* Ring Doorbell */
  159. doorbell.word0 = 0;
  160. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  161. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  162. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  163. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  164. return 0;
  165. }
  166. /**
  167. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  168. * @q: The Mailbox Queue to operate on.
  169. *
  170. * This routine will update the HBA index of a queue to reflect consumption of
  171. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  172. * an entry the host calls this function to update the queue's internal
  173. * pointers. This routine returns the number of entries that were consumed by
  174. * the HBA.
  175. **/
  176. static uint32_t
  177. lpfc_sli4_mq_release(struct lpfc_queue *q)
  178. {
  179. /* Clear the mailbox pointer for completion */
  180. q->phba->mbox = NULL;
  181. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  182. return 1;
  183. }
  184. /**
  185. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  186. * @q: The Event Queue to get the first valid EQE from
  187. *
  188. * This routine will get the first valid Event Queue Entry from @q, update
  189. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  190. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  191. * processed, but not popped back to the HBA then this routine will return NULL.
  192. **/
  193. static struct lpfc_eqe *
  194. lpfc_sli4_eq_get(struct lpfc_queue *q)
  195. {
  196. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  197. /* If the next EQE is not valid then we are done */
  198. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  199. return NULL;
  200. /* If the host has not yet processed the next entry then we are done */
  201. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  202. return NULL;
  203. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  204. return eqe;
  205. }
  206. /**
  207. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  208. * @q: The Event Queue that the host has completed processing for.
  209. * @arm: Indicates whether the host wants to arms this CQ.
  210. *
  211. * This routine will mark all Event Queue Entries on @q, from the last
  212. * known completed entry to the last entry that was processed, as completed
  213. * by clearing the valid bit for each completion queue entry. Then it will
  214. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  215. * The internal host index in the @q will be updated by this routine to indicate
  216. * that the host has finished processing the entries. The @arm parameter
  217. * indicates that the queue should be rearmed when ringing the doorbell.
  218. *
  219. * This function will return the number of EQEs that were popped.
  220. **/
  221. uint32_t
  222. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  223. {
  224. uint32_t released = 0;
  225. struct lpfc_eqe *temp_eqe;
  226. struct lpfc_register doorbell;
  227. /* while there are valid entries */
  228. while (q->hba_index != q->host_index) {
  229. temp_eqe = q->qe[q->host_index].eqe;
  230. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  231. released++;
  232. q->host_index = ((q->host_index + 1) % q->entry_count);
  233. }
  234. if (unlikely(released == 0 && !arm))
  235. return 0;
  236. /* ring doorbell for number popped */
  237. doorbell.word0 = 0;
  238. if (arm) {
  239. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  240. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  241. }
  242. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  243. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  244. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  245. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  246. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  247. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  248. readl(q->phba->sli4_hba.EQCQDBregaddr);
  249. return released;
  250. }
  251. /**
  252. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  253. * @q: The Completion Queue to get the first valid CQE from
  254. *
  255. * This routine will get the first valid Completion Queue Entry from @q, update
  256. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  257. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  258. * processed, but not popped back to the HBA then this routine will return NULL.
  259. **/
  260. static struct lpfc_cqe *
  261. lpfc_sli4_cq_get(struct lpfc_queue *q)
  262. {
  263. struct lpfc_cqe *cqe;
  264. /* If the next CQE is not valid then we are done */
  265. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  266. return NULL;
  267. /* If the host has not yet processed the next entry then we are done */
  268. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  269. return NULL;
  270. cqe = q->qe[q->hba_index].cqe;
  271. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  272. return cqe;
  273. }
  274. /**
  275. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  276. * @q: The Completion Queue that the host has completed processing for.
  277. * @arm: Indicates whether the host wants to arms this CQ.
  278. *
  279. * This routine will mark all Completion queue entries on @q, from the last
  280. * known completed entry to the last entry that was processed, as completed
  281. * by clearing the valid bit for each completion queue entry. Then it will
  282. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  283. * The internal host index in the @q will be updated by this routine to indicate
  284. * that the host has finished processing the entries. The @arm parameter
  285. * indicates that the queue should be rearmed when ringing the doorbell.
  286. *
  287. * This function will return the number of CQEs that were released.
  288. **/
  289. uint32_t
  290. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  291. {
  292. uint32_t released = 0;
  293. struct lpfc_cqe *temp_qe;
  294. struct lpfc_register doorbell;
  295. /* while there are valid entries */
  296. while (q->hba_index != q->host_index) {
  297. temp_qe = q->qe[q->host_index].cqe;
  298. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  299. released++;
  300. q->host_index = ((q->host_index + 1) % q->entry_count);
  301. }
  302. if (unlikely(released == 0 && !arm))
  303. return 0;
  304. /* ring doorbell for number popped */
  305. doorbell.word0 = 0;
  306. if (arm)
  307. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  308. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  309. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  310. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  311. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  312. return released;
  313. }
  314. /**
  315. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  316. * @q: The Header Receive Queue to operate on.
  317. * @wqe: The Receive Queue Entry to put on the Receive queue.
  318. *
  319. * This routine will copy the contents of @wqe to the next available entry on
  320. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  321. * HBA to start processing the Receive Queue Entry. This function returns the
  322. * index that the rqe was copied to if successful. If no entries are available
  323. * on @q then this function will return -ENOMEM.
  324. * The caller is expected to hold the hbalock when calling this routine.
  325. **/
  326. static int
  327. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  328. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  329. {
  330. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  331. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  332. struct lpfc_register doorbell;
  333. int put_index = hq->host_index;
  334. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  335. return -EINVAL;
  336. if (hq->host_index != dq->host_index)
  337. return -EINVAL;
  338. /* If the host has not yet processed the next entry then we are done */
  339. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  340. return -EBUSY;
  341. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  342. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  343. /* Update the host index to point to the next slot */
  344. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  345. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  346. /* Ring The Header Receive Queue Doorbell */
  347. if (!(hq->host_index % hq->entry_repost)) {
  348. doorbell.word0 = 0;
  349. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  350. hq->entry_repost);
  351. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  352. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  353. }
  354. return put_index;
  355. }
  356. /**
  357. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  358. * @q: The Header Receive Queue to operate on.
  359. *
  360. * This routine will update the HBA index of a queue to reflect consumption of
  361. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  362. * consumed an entry the host calls this function to update the queue's
  363. * internal pointers. This routine returns the number of entries that were
  364. * consumed by the HBA.
  365. **/
  366. static uint32_t
  367. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  368. {
  369. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  370. return 0;
  371. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  372. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  373. return 1;
  374. }
  375. /**
  376. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  377. * @phba: Pointer to HBA context object.
  378. * @pring: Pointer to driver SLI ring object.
  379. *
  380. * This function returns pointer to next command iocb entry
  381. * in the command ring. The caller must hold hbalock to prevent
  382. * other threads consume the next command iocb.
  383. * SLI-2/SLI-3 provide different sized iocbs.
  384. **/
  385. static inline IOCB_t *
  386. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  387. {
  388. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  389. pring->cmdidx * phba->iocb_cmd_size);
  390. }
  391. /**
  392. * lpfc_resp_iocb - Get next response iocb entry in the ring
  393. * @phba: Pointer to HBA context object.
  394. * @pring: Pointer to driver SLI ring object.
  395. *
  396. * This function returns pointer to next response iocb entry
  397. * in the response ring. The caller must hold hbalock to make sure
  398. * that no other thread consume the next response iocb.
  399. * SLI-2/SLI-3 provide different sized iocbs.
  400. **/
  401. static inline IOCB_t *
  402. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  403. {
  404. return (IOCB_t *) (((char *) pring->rspringaddr) +
  405. pring->rspidx * phba->iocb_rsp_size);
  406. }
  407. /**
  408. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  409. * @phba: Pointer to HBA context object.
  410. *
  411. * This function is called with hbalock held. This function
  412. * allocates a new driver iocb object from the iocb pool. If the
  413. * allocation is successful, it returns pointer to the newly
  414. * allocated iocb object else it returns NULL.
  415. **/
  416. static struct lpfc_iocbq *
  417. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  418. {
  419. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  420. struct lpfc_iocbq * iocbq = NULL;
  421. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  422. if (iocbq)
  423. phba->iocb_cnt++;
  424. if (phba->iocb_cnt > phba->iocb_max)
  425. phba->iocb_max = phba->iocb_cnt;
  426. return iocbq;
  427. }
  428. /**
  429. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  430. * @phba: Pointer to HBA context object.
  431. * @xritag: XRI value.
  432. *
  433. * This function clears the sglq pointer from the array of acive
  434. * sglq's. The xritag that is passed in is used to index into the
  435. * array. Before the xritag can be used it needs to be adjusted
  436. * by subtracting the xribase.
  437. *
  438. * Returns sglq ponter = success, NULL = Failure.
  439. **/
  440. static struct lpfc_sglq *
  441. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  442. {
  443. struct lpfc_sglq *sglq;
  444. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  445. phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
  446. return sglq;
  447. }
  448. /**
  449. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  450. * @phba: Pointer to HBA context object.
  451. * @xritag: XRI value.
  452. *
  453. * This function returns the sglq pointer from the array of acive
  454. * sglq's. The xritag that is passed in is used to index into the
  455. * array. Before the xritag can be used it needs to be adjusted
  456. * by subtracting the xribase.
  457. *
  458. * Returns sglq ponter = success, NULL = Failure.
  459. **/
  460. struct lpfc_sglq *
  461. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  462. {
  463. struct lpfc_sglq *sglq;
  464. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  465. return sglq;
  466. }
  467. /**
  468. * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
  469. * @phba: Pointer to HBA context object.
  470. * @ndlp: nodelist pointer for this target.
  471. * @xritag: xri used in this exchange.
  472. * @rxid: Remote Exchange ID.
  473. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  474. *
  475. * This function is called with hbalock held.
  476. * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
  477. * rrq struct and adds it to the active_rrq_list.
  478. *
  479. * returns 0 for rrq slot for this xri
  480. * < 0 Were not able to get rrq mem or invalid parameter.
  481. **/
  482. static int
  483. __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  484. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  485. {
  486. struct lpfc_node_rrq *rrq;
  487. int empty;
  488. uint32_t did = 0;
  489. if (!ndlp)
  490. return -EINVAL;
  491. if (!phba->cfg_enable_rrq)
  492. return -EINVAL;
  493. if (phba->pport->load_flag & FC_UNLOADING) {
  494. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  495. goto out;
  496. }
  497. did = ndlp->nlp_DID;
  498. /*
  499. * set the active bit even if there is no mem available.
  500. */
  501. if (NLP_CHK_FREE_REQ(ndlp))
  502. goto out;
  503. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  504. goto out;
  505. if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  506. goto out;
  507. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  508. if (rrq) {
  509. rrq->send_rrq = send_rrq;
  510. rrq->xritag = xritag;
  511. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  512. rrq->ndlp = ndlp;
  513. rrq->nlp_DID = ndlp->nlp_DID;
  514. rrq->vport = ndlp->vport;
  515. rrq->rxid = rxid;
  516. empty = list_empty(&phba->active_rrq_list);
  517. rrq->send_rrq = send_rrq;
  518. list_add_tail(&rrq->list, &phba->active_rrq_list);
  519. if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
  520. phba->hba_flag |= HBA_RRQ_ACTIVE;
  521. if (empty)
  522. lpfc_worker_wake_up(phba);
  523. }
  524. return 0;
  525. }
  526. out:
  527. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  528. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  529. " DID:0x%x Send:%d\n",
  530. xritag, rxid, did, send_rrq);
  531. return -EINVAL;
  532. }
  533. /**
  534. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  535. * @phba: Pointer to HBA context object.
  536. * @xritag: xri used in this exchange.
  537. * @rrq: The RRQ to be cleared.
  538. *
  539. **/
  540. void
  541. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  542. uint16_t xritag,
  543. struct lpfc_node_rrq *rrq)
  544. {
  545. struct lpfc_nodelist *ndlp = NULL;
  546. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  547. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  548. /* The target DID could have been swapped (cable swap)
  549. * we should use the ndlp from the findnode if it is
  550. * available.
  551. */
  552. if ((!ndlp) && rrq->ndlp)
  553. ndlp = rrq->ndlp;
  554. if (!ndlp)
  555. goto out;
  556. if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) {
  557. rrq->send_rrq = 0;
  558. rrq->xritag = 0;
  559. rrq->rrq_stop_time = 0;
  560. }
  561. out:
  562. mempool_free(rrq, phba->rrq_pool);
  563. }
  564. /**
  565. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  566. * @phba: Pointer to HBA context object.
  567. *
  568. * This function is called with hbalock held. This function
  569. * Checks if stop_time (ratov from setting rrq active) has
  570. * been reached, if it has and the send_rrq flag is set then
  571. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  572. * then it will just call the routine to clear the rrq and
  573. * free the rrq resource.
  574. * The timer is set to the next rrq that is going to expire before
  575. * leaving the routine.
  576. *
  577. **/
  578. void
  579. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  580. {
  581. struct lpfc_node_rrq *rrq;
  582. struct lpfc_node_rrq *nextrrq;
  583. unsigned long next_time;
  584. unsigned long iflags;
  585. LIST_HEAD(send_rrq);
  586. spin_lock_irqsave(&phba->hbalock, iflags);
  587. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  588. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  589. list_for_each_entry_safe(rrq, nextrrq,
  590. &phba->active_rrq_list, list) {
  591. if (time_after(jiffies, rrq->rrq_stop_time))
  592. list_move(&rrq->list, &send_rrq);
  593. else if (time_before(rrq->rrq_stop_time, next_time))
  594. next_time = rrq->rrq_stop_time;
  595. }
  596. spin_unlock_irqrestore(&phba->hbalock, iflags);
  597. if (!list_empty(&phba->active_rrq_list))
  598. mod_timer(&phba->rrq_tmr, next_time);
  599. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  600. list_del(&rrq->list);
  601. if (!rrq->send_rrq)
  602. /* this call will free the rrq */
  603. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  604. else if (lpfc_send_rrq(phba, rrq)) {
  605. /* if we send the rrq then the completion handler
  606. * will clear the bit in the xribitmap.
  607. */
  608. lpfc_clr_rrq_active(phba, rrq->xritag,
  609. rrq);
  610. }
  611. }
  612. }
  613. /**
  614. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  615. * @vport: Pointer to vport context object.
  616. * @xri: The xri used in the exchange.
  617. * @did: The targets DID for this exchange.
  618. *
  619. * returns NULL = rrq not found in the phba->active_rrq_list.
  620. * rrq = rrq for this xri and target.
  621. **/
  622. struct lpfc_node_rrq *
  623. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  624. {
  625. struct lpfc_hba *phba = vport->phba;
  626. struct lpfc_node_rrq *rrq;
  627. struct lpfc_node_rrq *nextrrq;
  628. unsigned long iflags;
  629. if (phba->sli_rev != LPFC_SLI_REV4)
  630. return NULL;
  631. spin_lock_irqsave(&phba->hbalock, iflags);
  632. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  633. if (rrq->vport == vport && rrq->xritag == xri &&
  634. rrq->nlp_DID == did){
  635. list_del(&rrq->list);
  636. spin_unlock_irqrestore(&phba->hbalock, iflags);
  637. return rrq;
  638. }
  639. }
  640. spin_unlock_irqrestore(&phba->hbalock, iflags);
  641. return NULL;
  642. }
  643. /**
  644. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  645. * @vport: Pointer to vport context object.
  646. * @ndlp: Pointer to the lpfc_node_list structure.
  647. * If ndlp is NULL Remove all active RRQs for this vport from the
  648. * phba->active_rrq_list and clear the rrq.
  649. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  650. **/
  651. void
  652. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  653. {
  654. struct lpfc_hba *phba = vport->phba;
  655. struct lpfc_node_rrq *rrq;
  656. struct lpfc_node_rrq *nextrrq;
  657. unsigned long iflags;
  658. LIST_HEAD(rrq_list);
  659. if (phba->sli_rev != LPFC_SLI_REV4)
  660. return;
  661. if (!ndlp) {
  662. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  663. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  664. }
  665. spin_lock_irqsave(&phba->hbalock, iflags);
  666. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  667. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  668. list_move(&rrq->list, &rrq_list);
  669. spin_unlock_irqrestore(&phba->hbalock, iflags);
  670. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  671. list_del(&rrq->list);
  672. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  673. }
  674. }
  675. /**
  676. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  677. * @phba: Pointer to HBA context object.
  678. *
  679. * Remove all rrqs from the phba->active_rrq_list and free them by
  680. * calling __lpfc_clr_active_rrq
  681. *
  682. **/
  683. void
  684. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  685. {
  686. struct lpfc_node_rrq *rrq;
  687. struct lpfc_node_rrq *nextrrq;
  688. unsigned long next_time;
  689. unsigned long iflags;
  690. LIST_HEAD(rrq_list);
  691. if (phba->sli_rev != LPFC_SLI_REV4)
  692. return;
  693. spin_lock_irqsave(&phba->hbalock, iflags);
  694. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  695. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  696. list_splice_init(&phba->active_rrq_list, &rrq_list);
  697. spin_unlock_irqrestore(&phba->hbalock, iflags);
  698. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  699. list_del(&rrq->list);
  700. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  701. }
  702. if (!list_empty(&phba->active_rrq_list))
  703. mod_timer(&phba->rrq_tmr, next_time);
  704. }
  705. /**
  706. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  707. * @phba: Pointer to HBA context object.
  708. * @ndlp: Targets nodelist pointer for this exchange.
  709. * @xritag the xri in the bitmap to test.
  710. *
  711. * This function is called with hbalock held. This function
  712. * returns 0 = rrq not active for this xri
  713. * 1 = rrq is valid for this xri.
  714. **/
  715. int
  716. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  717. uint16_t xritag)
  718. {
  719. if (!ndlp)
  720. return 0;
  721. if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  722. return 1;
  723. else
  724. return 0;
  725. }
  726. /**
  727. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  728. * @phba: Pointer to HBA context object.
  729. * @ndlp: nodelist pointer for this target.
  730. * @xritag: xri used in this exchange.
  731. * @rxid: Remote Exchange ID.
  732. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  733. *
  734. * This function takes the hbalock.
  735. * The active bit is always set in the active rrq xri_bitmap even
  736. * if there is no slot avaiable for the other rrq information.
  737. *
  738. * returns 0 rrq actived for this xri
  739. * < 0 No memory or invalid ndlp.
  740. **/
  741. int
  742. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  743. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  744. {
  745. int ret;
  746. unsigned long iflags;
  747. spin_lock_irqsave(&phba->hbalock, iflags);
  748. ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq);
  749. spin_unlock_irqrestore(&phba->hbalock, iflags);
  750. return ret;
  751. }
  752. /**
  753. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  754. * @phba: Pointer to HBA context object.
  755. * @piocb: Pointer to the iocbq.
  756. *
  757. * This function is called with hbalock held. This function
  758. * gets a new driver sglq object from the sglq list. If the
  759. * list is not empty then it is successful, it returns pointer to the newly
  760. * allocated sglq object else it returns NULL.
  761. **/
  762. static struct lpfc_sglq *
  763. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  764. {
  765. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  766. struct lpfc_sglq *sglq = NULL;
  767. struct lpfc_sglq *start_sglq = NULL;
  768. struct lpfc_scsi_buf *lpfc_cmd;
  769. struct lpfc_nodelist *ndlp;
  770. int found = 0;
  771. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  772. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  773. ndlp = lpfc_cmd->rdata->pnode;
  774. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  775. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  776. ndlp = piocbq->context_un.ndlp;
  777. else
  778. ndlp = piocbq->context1;
  779. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  780. start_sglq = sglq;
  781. while (!found) {
  782. if (!sglq)
  783. return NULL;
  784. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
  785. /* This xri has an rrq outstanding for this DID.
  786. * put it back in the list and get another xri.
  787. */
  788. list_add_tail(&sglq->list, lpfc_sgl_list);
  789. sglq = NULL;
  790. list_remove_head(lpfc_sgl_list, sglq,
  791. struct lpfc_sglq, list);
  792. if (sglq == start_sglq) {
  793. sglq = NULL;
  794. break;
  795. } else
  796. continue;
  797. }
  798. sglq->ndlp = ndlp;
  799. found = 1;
  800. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  801. sglq->state = SGL_ALLOCATED;
  802. }
  803. return sglq;
  804. }
  805. /**
  806. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  807. * @phba: Pointer to HBA context object.
  808. *
  809. * This function is called with no lock held. This function
  810. * allocates a new driver iocb object from the iocb pool. If the
  811. * allocation is successful, it returns pointer to the newly
  812. * allocated iocb object else it returns NULL.
  813. **/
  814. struct lpfc_iocbq *
  815. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  816. {
  817. struct lpfc_iocbq * iocbq = NULL;
  818. unsigned long iflags;
  819. spin_lock_irqsave(&phba->hbalock, iflags);
  820. iocbq = __lpfc_sli_get_iocbq(phba);
  821. spin_unlock_irqrestore(&phba->hbalock, iflags);
  822. return iocbq;
  823. }
  824. /**
  825. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  826. * @phba: Pointer to HBA context object.
  827. * @iocbq: Pointer to driver iocb object.
  828. *
  829. * This function is called with hbalock held to release driver
  830. * iocb object to the iocb pool. The iotag in the iocb object
  831. * does not change for each use of the iocb object. This function
  832. * clears all other fields of the iocb object when it is freed.
  833. * The sqlq structure that holds the xritag and phys and virtual
  834. * mappings for the scatter gather list is retrieved from the
  835. * active array of sglq. The get of the sglq pointer also clears
  836. * the entry in the array. If the status of the IO indiactes that
  837. * this IO was aborted then the sglq entry it put on the
  838. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  839. * IO has good status or fails for any other reason then the sglq
  840. * entry is added to the free list (lpfc_sgl_list).
  841. **/
  842. static void
  843. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  844. {
  845. struct lpfc_sglq *sglq;
  846. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  847. unsigned long iflag = 0;
  848. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  849. if (iocbq->sli4_xritag == NO_XRI)
  850. sglq = NULL;
  851. else
  852. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  853. if (sglq) {
  854. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  855. (sglq->state != SGL_XRI_ABORTED)) {
  856. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  857. iflag);
  858. list_add(&sglq->list,
  859. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  860. spin_unlock_irqrestore(
  861. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  862. } else {
  863. sglq->state = SGL_FREED;
  864. sglq->ndlp = NULL;
  865. list_add_tail(&sglq->list,
  866. &phba->sli4_hba.lpfc_sgl_list);
  867. /* Check if TXQ queue needs to be serviced */
  868. if (pring->txq_cnt)
  869. lpfc_worker_wake_up(phba);
  870. }
  871. }
  872. /*
  873. * Clean all volatile data fields, preserve iotag and node struct.
  874. */
  875. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  876. iocbq->sli4_lxritag = NO_XRI;
  877. iocbq->sli4_xritag = NO_XRI;
  878. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  879. }
  880. /**
  881. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  882. * @phba: Pointer to HBA context object.
  883. * @iocbq: Pointer to driver iocb object.
  884. *
  885. * This function is called with hbalock held to release driver
  886. * iocb object to the iocb pool. The iotag in the iocb object
  887. * does not change for each use of the iocb object. This function
  888. * clears all other fields of the iocb object when it is freed.
  889. **/
  890. static void
  891. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  892. {
  893. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  894. /*
  895. * Clean all volatile data fields, preserve iotag and node struct.
  896. */
  897. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  898. iocbq->sli4_xritag = NO_XRI;
  899. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  900. }
  901. /**
  902. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  903. * @phba: Pointer to HBA context object.
  904. * @iocbq: Pointer to driver iocb object.
  905. *
  906. * This function is called with hbalock held to release driver
  907. * iocb object to the iocb pool. The iotag in the iocb object
  908. * does not change for each use of the iocb object. This function
  909. * clears all other fields of the iocb object when it is freed.
  910. **/
  911. static void
  912. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  913. {
  914. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  915. phba->iocb_cnt--;
  916. }
  917. /**
  918. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  919. * @phba: Pointer to HBA context object.
  920. * @iocbq: Pointer to driver iocb object.
  921. *
  922. * This function is called with no lock held to release the iocb to
  923. * iocb pool.
  924. **/
  925. void
  926. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  927. {
  928. unsigned long iflags;
  929. /*
  930. * Clean all volatile data fields, preserve iotag and node struct.
  931. */
  932. spin_lock_irqsave(&phba->hbalock, iflags);
  933. __lpfc_sli_release_iocbq(phba, iocbq);
  934. spin_unlock_irqrestore(&phba->hbalock, iflags);
  935. }
  936. /**
  937. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  938. * @phba: Pointer to HBA context object.
  939. * @iocblist: List of IOCBs.
  940. * @ulpstatus: ULP status in IOCB command field.
  941. * @ulpWord4: ULP word-4 in IOCB command field.
  942. *
  943. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  944. * on the list by invoking the complete callback function associated with the
  945. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  946. * fields.
  947. **/
  948. void
  949. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  950. uint32_t ulpstatus, uint32_t ulpWord4)
  951. {
  952. struct lpfc_iocbq *piocb;
  953. while (!list_empty(iocblist)) {
  954. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  955. if (!piocb->iocb_cmpl)
  956. lpfc_sli_release_iocbq(phba, piocb);
  957. else {
  958. piocb->iocb.ulpStatus = ulpstatus;
  959. piocb->iocb.un.ulpWord[4] = ulpWord4;
  960. (piocb->iocb_cmpl) (phba, piocb, piocb);
  961. }
  962. }
  963. return;
  964. }
  965. /**
  966. * lpfc_sli_iocb_cmd_type - Get the iocb type
  967. * @iocb_cmnd: iocb command code.
  968. *
  969. * This function is called by ring event handler function to get the iocb type.
  970. * This function translates the iocb command to an iocb command type used to
  971. * decide the final disposition of each completed IOCB.
  972. * The function returns
  973. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  974. * LPFC_SOL_IOCB if it is a solicited iocb completion
  975. * LPFC_ABORT_IOCB if it is an abort iocb
  976. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  977. *
  978. * The caller is not required to hold any lock.
  979. **/
  980. static lpfc_iocb_type
  981. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  982. {
  983. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  984. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  985. return 0;
  986. switch (iocb_cmnd) {
  987. case CMD_XMIT_SEQUENCE_CR:
  988. case CMD_XMIT_SEQUENCE_CX:
  989. case CMD_XMIT_BCAST_CN:
  990. case CMD_XMIT_BCAST_CX:
  991. case CMD_ELS_REQUEST_CR:
  992. case CMD_ELS_REQUEST_CX:
  993. case CMD_CREATE_XRI_CR:
  994. case CMD_CREATE_XRI_CX:
  995. case CMD_GET_RPI_CN:
  996. case CMD_XMIT_ELS_RSP_CX:
  997. case CMD_GET_RPI_CR:
  998. case CMD_FCP_IWRITE_CR:
  999. case CMD_FCP_IWRITE_CX:
  1000. case CMD_FCP_IREAD_CR:
  1001. case CMD_FCP_IREAD_CX:
  1002. case CMD_FCP_ICMND_CR:
  1003. case CMD_FCP_ICMND_CX:
  1004. case CMD_FCP_TSEND_CX:
  1005. case CMD_FCP_TRSP_CX:
  1006. case CMD_FCP_TRECEIVE_CX:
  1007. case CMD_FCP_AUTO_TRSP_CX:
  1008. case CMD_ADAPTER_MSG:
  1009. case CMD_ADAPTER_DUMP:
  1010. case CMD_XMIT_SEQUENCE64_CR:
  1011. case CMD_XMIT_SEQUENCE64_CX:
  1012. case CMD_XMIT_BCAST64_CN:
  1013. case CMD_XMIT_BCAST64_CX:
  1014. case CMD_ELS_REQUEST64_CR:
  1015. case CMD_ELS_REQUEST64_CX:
  1016. case CMD_FCP_IWRITE64_CR:
  1017. case CMD_FCP_IWRITE64_CX:
  1018. case CMD_FCP_IREAD64_CR:
  1019. case CMD_FCP_IREAD64_CX:
  1020. case CMD_FCP_ICMND64_CR:
  1021. case CMD_FCP_ICMND64_CX:
  1022. case CMD_FCP_TSEND64_CX:
  1023. case CMD_FCP_TRSP64_CX:
  1024. case CMD_FCP_TRECEIVE64_CX:
  1025. case CMD_GEN_REQUEST64_CR:
  1026. case CMD_GEN_REQUEST64_CX:
  1027. case CMD_XMIT_ELS_RSP64_CX:
  1028. case DSSCMD_IWRITE64_CR:
  1029. case DSSCMD_IWRITE64_CX:
  1030. case DSSCMD_IREAD64_CR:
  1031. case DSSCMD_IREAD64_CX:
  1032. type = LPFC_SOL_IOCB;
  1033. break;
  1034. case CMD_ABORT_XRI_CN:
  1035. case CMD_ABORT_XRI_CX:
  1036. case CMD_CLOSE_XRI_CN:
  1037. case CMD_CLOSE_XRI_CX:
  1038. case CMD_XRI_ABORTED_CX:
  1039. case CMD_ABORT_MXRI64_CN:
  1040. case CMD_XMIT_BLS_RSP64_CX:
  1041. type = LPFC_ABORT_IOCB;
  1042. break;
  1043. case CMD_RCV_SEQUENCE_CX:
  1044. case CMD_RCV_ELS_REQ_CX:
  1045. case CMD_RCV_SEQUENCE64_CX:
  1046. case CMD_RCV_ELS_REQ64_CX:
  1047. case CMD_ASYNC_STATUS:
  1048. case CMD_IOCB_RCV_SEQ64_CX:
  1049. case CMD_IOCB_RCV_ELS64_CX:
  1050. case CMD_IOCB_RCV_CONT64_CX:
  1051. case CMD_IOCB_RET_XRI64_CX:
  1052. type = LPFC_UNSOL_IOCB;
  1053. break;
  1054. case CMD_IOCB_XMIT_MSEQ64_CR:
  1055. case CMD_IOCB_XMIT_MSEQ64_CX:
  1056. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1057. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1058. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1059. case CMD_IOCB_ABORT_EXTENDED_CN:
  1060. case CMD_IOCB_RET_HBQE64_CN:
  1061. case CMD_IOCB_FCP_IBIDIR64_CR:
  1062. case CMD_IOCB_FCP_IBIDIR64_CX:
  1063. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1064. case CMD_IOCB_LOGENTRY_CN:
  1065. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1066. printk("%s - Unhandled SLI-3 Command x%x\n",
  1067. __func__, iocb_cmnd);
  1068. type = LPFC_UNKNOWN_IOCB;
  1069. break;
  1070. default:
  1071. type = LPFC_UNKNOWN_IOCB;
  1072. break;
  1073. }
  1074. return type;
  1075. }
  1076. /**
  1077. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1078. * @phba: Pointer to HBA context object.
  1079. *
  1080. * This function is called from SLI initialization code
  1081. * to configure every ring of the HBA's SLI interface. The
  1082. * caller is not required to hold any lock. This function issues
  1083. * a config_ring mailbox command for each ring.
  1084. * This function returns zero if successful else returns a negative
  1085. * error code.
  1086. **/
  1087. static int
  1088. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1089. {
  1090. struct lpfc_sli *psli = &phba->sli;
  1091. LPFC_MBOXQ_t *pmb;
  1092. MAILBOX_t *pmbox;
  1093. int i, rc, ret = 0;
  1094. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1095. if (!pmb)
  1096. return -ENOMEM;
  1097. pmbox = &pmb->u.mb;
  1098. phba->link_state = LPFC_INIT_MBX_CMDS;
  1099. for (i = 0; i < psli->num_rings; i++) {
  1100. lpfc_config_ring(phba, i, pmb);
  1101. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1102. if (rc != MBX_SUCCESS) {
  1103. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1104. "0446 Adapter failed to init (%d), "
  1105. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1106. "ring %d\n",
  1107. rc, pmbox->mbxCommand,
  1108. pmbox->mbxStatus, i);
  1109. phba->link_state = LPFC_HBA_ERROR;
  1110. ret = -ENXIO;
  1111. break;
  1112. }
  1113. }
  1114. mempool_free(pmb, phba->mbox_mem_pool);
  1115. return ret;
  1116. }
  1117. /**
  1118. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1119. * @phba: Pointer to HBA context object.
  1120. * @pring: Pointer to driver SLI ring object.
  1121. * @piocb: Pointer to the driver iocb object.
  1122. *
  1123. * This function is called with hbalock held. The function adds the
  1124. * new iocb to txcmplq of the given ring. This function always returns
  1125. * 0. If this function is called for ELS ring, this function checks if
  1126. * there is a vport associated with the ELS command. This function also
  1127. * starts els_tmofunc timer if this is an ELS command.
  1128. **/
  1129. static int
  1130. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1131. struct lpfc_iocbq *piocb)
  1132. {
  1133. list_add_tail(&piocb->list, &pring->txcmplq);
  1134. piocb->iocb_flag |= LPFC_IO_ON_Q;
  1135. pring->txcmplq_cnt++;
  1136. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1137. pring->txcmplq_max = pring->txcmplq_cnt;
  1138. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1139. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1140. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1141. if (!piocb->vport)
  1142. BUG();
  1143. else
  1144. mod_timer(&piocb->vport->els_tmofunc,
  1145. jiffies + HZ * (phba->fc_ratov << 1));
  1146. }
  1147. return 0;
  1148. }
  1149. /**
  1150. * lpfc_sli_ringtx_get - Get first element of the txq
  1151. * @phba: Pointer to HBA context object.
  1152. * @pring: Pointer to driver SLI ring object.
  1153. *
  1154. * This function is called with hbalock held to get next
  1155. * iocb in txq of the given ring. If there is any iocb in
  1156. * the txq, the function returns first iocb in the list after
  1157. * removing the iocb from the list, else it returns NULL.
  1158. **/
  1159. struct lpfc_iocbq *
  1160. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1161. {
  1162. struct lpfc_iocbq *cmd_iocb;
  1163. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1164. if (cmd_iocb != NULL)
  1165. pring->txq_cnt--;
  1166. return cmd_iocb;
  1167. }
  1168. /**
  1169. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1170. * @phba: Pointer to HBA context object.
  1171. * @pring: Pointer to driver SLI ring object.
  1172. *
  1173. * This function is called with hbalock held and the caller must post the
  1174. * iocb without releasing the lock. If the caller releases the lock,
  1175. * iocb slot returned by the function is not guaranteed to be available.
  1176. * The function returns pointer to the next available iocb slot if there
  1177. * is available slot in the ring, else it returns NULL.
  1178. * If the get index of the ring is ahead of the put index, the function
  1179. * will post an error attention event to the worker thread to take the
  1180. * HBA to offline state.
  1181. **/
  1182. static IOCB_t *
  1183. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1184. {
  1185. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1186. uint32_t max_cmd_idx = pring->numCiocb;
  1187. if ((pring->next_cmdidx == pring->cmdidx) &&
  1188. (++pring->next_cmdidx >= max_cmd_idx))
  1189. pring->next_cmdidx = 0;
  1190. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1191. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1192. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1193. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1194. "0315 Ring %d issue: portCmdGet %d "
  1195. "is bigger than cmd ring %d\n",
  1196. pring->ringno,
  1197. pring->local_getidx, max_cmd_idx);
  1198. phba->link_state = LPFC_HBA_ERROR;
  1199. /*
  1200. * All error attention handlers are posted to
  1201. * worker thread
  1202. */
  1203. phba->work_ha |= HA_ERATT;
  1204. phba->work_hs = HS_FFER3;
  1205. lpfc_worker_wake_up(phba);
  1206. return NULL;
  1207. }
  1208. if (pring->local_getidx == pring->next_cmdidx)
  1209. return NULL;
  1210. }
  1211. return lpfc_cmd_iocb(phba, pring);
  1212. }
  1213. /**
  1214. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1215. * @phba: Pointer to HBA context object.
  1216. * @iocbq: Pointer to driver iocb object.
  1217. *
  1218. * This function gets an iotag for the iocb. If there is no unused iotag and
  1219. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1220. * array and assigns a new iotag.
  1221. * The function returns the allocated iotag if successful, else returns zero.
  1222. * Zero is not a valid iotag.
  1223. * The caller is not required to hold any lock.
  1224. **/
  1225. uint16_t
  1226. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1227. {
  1228. struct lpfc_iocbq **new_arr;
  1229. struct lpfc_iocbq **old_arr;
  1230. size_t new_len;
  1231. struct lpfc_sli *psli = &phba->sli;
  1232. uint16_t iotag;
  1233. spin_lock_irq(&phba->hbalock);
  1234. iotag = psli->last_iotag;
  1235. if(++iotag < psli->iocbq_lookup_len) {
  1236. psli->last_iotag = iotag;
  1237. psli->iocbq_lookup[iotag] = iocbq;
  1238. spin_unlock_irq(&phba->hbalock);
  1239. iocbq->iotag = iotag;
  1240. return iotag;
  1241. } else if (psli->iocbq_lookup_len < (0xffff
  1242. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1243. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1244. spin_unlock_irq(&phba->hbalock);
  1245. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1246. GFP_KERNEL);
  1247. if (new_arr) {
  1248. spin_lock_irq(&phba->hbalock);
  1249. old_arr = psli->iocbq_lookup;
  1250. if (new_len <= psli->iocbq_lookup_len) {
  1251. /* highly unprobable case */
  1252. kfree(new_arr);
  1253. iotag = psli->last_iotag;
  1254. if(++iotag < psli->iocbq_lookup_len) {
  1255. psli->last_iotag = iotag;
  1256. psli->iocbq_lookup[iotag] = iocbq;
  1257. spin_unlock_irq(&phba->hbalock);
  1258. iocbq->iotag = iotag;
  1259. return iotag;
  1260. }
  1261. spin_unlock_irq(&phba->hbalock);
  1262. return 0;
  1263. }
  1264. if (psli->iocbq_lookup)
  1265. memcpy(new_arr, old_arr,
  1266. ((psli->last_iotag + 1) *
  1267. sizeof (struct lpfc_iocbq *)));
  1268. psli->iocbq_lookup = new_arr;
  1269. psli->iocbq_lookup_len = new_len;
  1270. psli->last_iotag = iotag;
  1271. psli->iocbq_lookup[iotag] = iocbq;
  1272. spin_unlock_irq(&phba->hbalock);
  1273. iocbq->iotag = iotag;
  1274. kfree(old_arr);
  1275. return iotag;
  1276. }
  1277. } else
  1278. spin_unlock_irq(&phba->hbalock);
  1279. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1280. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1281. psli->last_iotag);
  1282. return 0;
  1283. }
  1284. /**
  1285. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1286. * @phba: Pointer to HBA context object.
  1287. * @pring: Pointer to driver SLI ring object.
  1288. * @iocb: Pointer to iocb slot in the ring.
  1289. * @nextiocb: Pointer to driver iocb object which need to be
  1290. * posted to firmware.
  1291. *
  1292. * This function is called with hbalock held to post a new iocb to
  1293. * the firmware. This function copies the new iocb to ring iocb slot and
  1294. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1295. * a completion call back for this iocb else the function will free the
  1296. * iocb object.
  1297. **/
  1298. static void
  1299. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1300. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1301. {
  1302. /*
  1303. * Set up an iotag
  1304. */
  1305. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1306. if (pring->ringno == LPFC_ELS_RING) {
  1307. lpfc_debugfs_slow_ring_trc(phba,
  1308. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1309. *(((uint32_t *) &nextiocb->iocb) + 4),
  1310. *(((uint32_t *) &nextiocb->iocb) + 6),
  1311. *(((uint32_t *) &nextiocb->iocb) + 7));
  1312. }
  1313. /*
  1314. * Issue iocb command to adapter
  1315. */
  1316. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1317. wmb();
  1318. pring->stats.iocb_cmd++;
  1319. /*
  1320. * If there is no completion routine to call, we can release the
  1321. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1322. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1323. */
  1324. if (nextiocb->iocb_cmpl)
  1325. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1326. else
  1327. __lpfc_sli_release_iocbq(phba, nextiocb);
  1328. /*
  1329. * Let the HBA know what IOCB slot will be the next one the
  1330. * driver will put a command into.
  1331. */
  1332. pring->cmdidx = pring->next_cmdidx;
  1333. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1334. }
  1335. /**
  1336. * lpfc_sli_update_full_ring - Update the chip attention register
  1337. * @phba: Pointer to HBA context object.
  1338. * @pring: Pointer to driver SLI ring object.
  1339. *
  1340. * The caller is not required to hold any lock for calling this function.
  1341. * This function updates the chip attention bits for the ring to inform firmware
  1342. * that there are pending work to be done for this ring and requests an
  1343. * interrupt when there is space available in the ring. This function is
  1344. * called when the driver is unable to post more iocbs to the ring due
  1345. * to unavailability of space in the ring.
  1346. **/
  1347. static void
  1348. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1349. {
  1350. int ringno = pring->ringno;
  1351. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1352. wmb();
  1353. /*
  1354. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1355. * The HBA will tell us when an IOCB entry is available.
  1356. */
  1357. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1358. readl(phba->CAregaddr); /* flush */
  1359. pring->stats.iocb_cmd_full++;
  1360. }
  1361. /**
  1362. * lpfc_sli_update_ring - Update chip attention register
  1363. * @phba: Pointer to HBA context object.
  1364. * @pring: Pointer to driver SLI ring object.
  1365. *
  1366. * This function updates the chip attention register bit for the
  1367. * given ring to inform HBA that there is more work to be done
  1368. * in this ring. The caller is not required to hold any lock.
  1369. **/
  1370. static void
  1371. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1372. {
  1373. int ringno = pring->ringno;
  1374. /*
  1375. * Tell the HBA that there is work to do in this ring.
  1376. */
  1377. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1378. wmb();
  1379. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1380. readl(phba->CAregaddr); /* flush */
  1381. }
  1382. }
  1383. /**
  1384. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1385. * @phba: Pointer to HBA context object.
  1386. * @pring: Pointer to driver SLI ring object.
  1387. *
  1388. * This function is called with hbalock held to post pending iocbs
  1389. * in the txq to the firmware. This function is called when driver
  1390. * detects space available in the ring.
  1391. **/
  1392. static void
  1393. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1394. {
  1395. IOCB_t *iocb;
  1396. struct lpfc_iocbq *nextiocb;
  1397. /*
  1398. * Check to see if:
  1399. * (a) there is anything on the txq to send
  1400. * (b) link is up
  1401. * (c) link attention events can be processed (fcp ring only)
  1402. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1403. */
  1404. if (pring->txq_cnt &&
  1405. lpfc_is_link_up(phba) &&
  1406. (pring->ringno != phba->sli.fcp_ring ||
  1407. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1408. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1409. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1410. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1411. if (iocb)
  1412. lpfc_sli_update_ring(phba, pring);
  1413. else
  1414. lpfc_sli_update_full_ring(phba, pring);
  1415. }
  1416. return;
  1417. }
  1418. /**
  1419. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1420. * @phba: Pointer to HBA context object.
  1421. * @hbqno: HBQ number.
  1422. *
  1423. * This function is called with hbalock held to get the next
  1424. * available slot for the given HBQ. If there is free slot
  1425. * available for the HBQ it will return pointer to the next available
  1426. * HBQ entry else it will return NULL.
  1427. **/
  1428. static struct lpfc_hbq_entry *
  1429. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1430. {
  1431. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1432. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1433. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1434. hbqp->next_hbqPutIdx = 0;
  1435. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1436. uint32_t raw_index = phba->hbq_get[hbqno];
  1437. uint32_t getidx = le32_to_cpu(raw_index);
  1438. hbqp->local_hbqGetIdx = getidx;
  1439. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1440. lpfc_printf_log(phba, KERN_ERR,
  1441. LOG_SLI | LOG_VPORT,
  1442. "1802 HBQ %d: local_hbqGetIdx "
  1443. "%u is > than hbqp->entry_count %u\n",
  1444. hbqno, hbqp->local_hbqGetIdx,
  1445. hbqp->entry_count);
  1446. phba->link_state = LPFC_HBA_ERROR;
  1447. return NULL;
  1448. }
  1449. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1450. return NULL;
  1451. }
  1452. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1453. hbqp->hbqPutIdx;
  1454. }
  1455. /**
  1456. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1457. * @phba: Pointer to HBA context object.
  1458. *
  1459. * This function is called with no lock held to free all the
  1460. * hbq buffers while uninitializing the SLI interface. It also
  1461. * frees the HBQ buffers returned by the firmware but not yet
  1462. * processed by the upper layers.
  1463. **/
  1464. void
  1465. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1466. {
  1467. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1468. struct hbq_dmabuf *hbq_buf;
  1469. unsigned long flags;
  1470. int i, hbq_count;
  1471. uint32_t hbqno;
  1472. hbq_count = lpfc_sli_hbq_count();
  1473. /* Return all memory used by all HBQs */
  1474. spin_lock_irqsave(&phba->hbalock, flags);
  1475. for (i = 0; i < hbq_count; ++i) {
  1476. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1477. &phba->hbqs[i].hbq_buffer_list, list) {
  1478. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1479. list_del(&hbq_buf->dbuf.list);
  1480. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1481. }
  1482. phba->hbqs[i].buffer_count = 0;
  1483. }
  1484. /* Return all HBQ buffer that are in-fly */
  1485. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1486. list) {
  1487. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1488. list_del(&hbq_buf->dbuf.list);
  1489. if (hbq_buf->tag == -1) {
  1490. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1491. (phba, hbq_buf);
  1492. } else {
  1493. hbqno = hbq_buf->tag >> 16;
  1494. if (hbqno >= LPFC_MAX_HBQS)
  1495. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1496. (phba, hbq_buf);
  1497. else
  1498. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1499. hbq_buf);
  1500. }
  1501. }
  1502. /* Mark the HBQs not in use */
  1503. phba->hbq_in_use = 0;
  1504. spin_unlock_irqrestore(&phba->hbalock, flags);
  1505. }
  1506. /**
  1507. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1508. * @phba: Pointer to HBA context object.
  1509. * @hbqno: HBQ number.
  1510. * @hbq_buf: Pointer to HBQ buffer.
  1511. *
  1512. * This function is called with the hbalock held to post a
  1513. * hbq buffer to the firmware. If the function finds an empty
  1514. * slot in the HBQ, it will post the buffer. The function will return
  1515. * pointer to the hbq entry if it successfully post the buffer
  1516. * else it will return NULL.
  1517. **/
  1518. static int
  1519. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1520. struct hbq_dmabuf *hbq_buf)
  1521. {
  1522. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1523. }
  1524. /**
  1525. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1526. * @phba: Pointer to HBA context object.
  1527. * @hbqno: HBQ number.
  1528. * @hbq_buf: Pointer to HBQ buffer.
  1529. *
  1530. * This function is called with the hbalock held to post a hbq buffer to the
  1531. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1532. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1533. * it successfully post the buffer else it will return an error.
  1534. **/
  1535. static int
  1536. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1537. struct hbq_dmabuf *hbq_buf)
  1538. {
  1539. struct lpfc_hbq_entry *hbqe;
  1540. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1541. /* Get next HBQ entry slot to use */
  1542. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1543. if (hbqe) {
  1544. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1545. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1546. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1547. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1548. hbqe->bde.tus.f.bdeFlags = 0;
  1549. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1550. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1551. /* Sync SLIM */
  1552. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1553. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1554. /* flush */
  1555. readl(phba->hbq_put + hbqno);
  1556. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1557. return 0;
  1558. } else
  1559. return -ENOMEM;
  1560. }
  1561. /**
  1562. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1563. * @phba: Pointer to HBA context object.
  1564. * @hbqno: HBQ number.
  1565. * @hbq_buf: Pointer to HBQ buffer.
  1566. *
  1567. * This function is called with the hbalock held to post an RQE to the SLI4
  1568. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1569. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1570. **/
  1571. static int
  1572. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1573. struct hbq_dmabuf *hbq_buf)
  1574. {
  1575. int rc;
  1576. struct lpfc_rqe hrqe;
  1577. struct lpfc_rqe drqe;
  1578. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1579. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1580. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1581. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1582. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1583. &hrqe, &drqe);
  1584. if (rc < 0)
  1585. return rc;
  1586. hbq_buf->tag = rc;
  1587. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1588. return 0;
  1589. }
  1590. /* HBQ for ELS and CT traffic. */
  1591. static struct lpfc_hbq_init lpfc_els_hbq = {
  1592. .rn = 1,
  1593. .entry_count = 256,
  1594. .mask_count = 0,
  1595. .profile = 0,
  1596. .ring_mask = (1 << LPFC_ELS_RING),
  1597. .buffer_count = 0,
  1598. .init_count = 40,
  1599. .add_count = 40,
  1600. };
  1601. /* HBQ for the extra ring if needed */
  1602. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1603. .rn = 1,
  1604. .entry_count = 200,
  1605. .mask_count = 0,
  1606. .profile = 0,
  1607. .ring_mask = (1 << LPFC_EXTRA_RING),
  1608. .buffer_count = 0,
  1609. .init_count = 0,
  1610. .add_count = 5,
  1611. };
  1612. /* Array of HBQs */
  1613. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1614. &lpfc_els_hbq,
  1615. &lpfc_extra_hbq,
  1616. };
  1617. /**
  1618. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1619. * @phba: Pointer to HBA context object.
  1620. * @hbqno: HBQ number.
  1621. * @count: Number of HBQ buffers to be posted.
  1622. *
  1623. * This function is called with no lock held to post more hbq buffers to the
  1624. * given HBQ. The function returns the number of HBQ buffers successfully
  1625. * posted.
  1626. **/
  1627. static int
  1628. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1629. {
  1630. uint32_t i, posted = 0;
  1631. unsigned long flags;
  1632. struct hbq_dmabuf *hbq_buffer;
  1633. LIST_HEAD(hbq_buf_list);
  1634. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1635. return 0;
  1636. if ((phba->hbqs[hbqno].buffer_count + count) >
  1637. lpfc_hbq_defs[hbqno]->entry_count)
  1638. count = lpfc_hbq_defs[hbqno]->entry_count -
  1639. phba->hbqs[hbqno].buffer_count;
  1640. if (!count)
  1641. return 0;
  1642. /* Allocate HBQ entries */
  1643. for (i = 0; i < count; i++) {
  1644. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1645. if (!hbq_buffer)
  1646. break;
  1647. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1648. }
  1649. /* Check whether HBQ is still in use */
  1650. spin_lock_irqsave(&phba->hbalock, flags);
  1651. if (!phba->hbq_in_use)
  1652. goto err;
  1653. while (!list_empty(&hbq_buf_list)) {
  1654. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1655. dbuf.list);
  1656. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1657. (hbqno << 16));
  1658. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1659. phba->hbqs[hbqno].buffer_count++;
  1660. posted++;
  1661. } else
  1662. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1663. }
  1664. spin_unlock_irqrestore(&phba->hbalock, flags);
  1665. return posted;
  1666. err:
  1667. spin_unlock_irqrestore(&phba->hbalock, flags);
  1668. while (!list_empty(&hbq_buf_list)) {
  1669. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1670. dbuf.list);
  1671. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1672. }
  1673. return 0;
  1674. }
  1675. /**
  1676. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1677. * @phba: Pointer to HBA context object.
  1678. * @qno: HBQ number.
  1679. *
  1680. * This function posts more buffers to the HBQ. This function
  1681. * is called with no lock held. The function returns the number of HBQ entries
  1682. * successfully allocated.
  1683. **/
  1684. int
  1685. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1686. {
  1687. if (phba->sli_rev == LPFC_SLI_REV4)
  1688. return 0;
  1689. else
  1690. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1691. lpfc_hbq_defs[qno]->add_count);
  1692. }
  1693. /**
  1694. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1695. * @phba: Pointer to HBA context object.
  1696. * @qno: HBQ queue number.
  1697. *
  1698. * This function is called from SLI initialization code path with
  1699. * no lock held to post initial HBQ buffers to firmware. The
  1700. * function returns the number of HBQ entries successfully allocated.
  1701. **/
  1702. static int
  1703. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1704. {
  1705. if (phba->sli_rev == LPFC_SLI_REV4)
  1706. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1707. lpfc_hbq_defs[qno]->entry_count);
  1708. else
  1709. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1710. lpfc_hbq_defs[qno]->init_count);
  1711. }
  1712. /**
  1713. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1714. * @phba: Pointer to HBA context object.
  1715. * @hbqno: HBQ number.
  1716. *
  1717. * This function removes the first hbq buffer on an hbq list and returns a
  1718. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1719. **/
  1720. static struct hbq_dmabuf *
  1721. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1722. {
  1723. struct lpfc_dmabuf *d_buf;
  1724. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1725. if (!d_buf)
  1726. return NULL;
  1727. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1728. }
  1729. /**
  1730. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1731. * @phba: Pointer to HBA context object.
  1732. * @tag: Tag of the hbq buffer.
  1733. *
  1734. * This function is called with hbalock held. This function searches
  1735. * for the hbq buffer associated with the given tag in the hbq buffer
  1736. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1737. * it returns NULL.
  1738. **/
  1739. static struct hbq_dmabuf *
  1740. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1741. {
  1742. struct lpfc_dmabuf *d_buf;
  1743. struct hbq_dmabuf *hbq_buf;
  1744. uint32_t hbqno;
  1745. hbqno = tag >> 16;
  1746. if (hbqno >= LPFC_MAX_HBQS)
  1747. return NULL;
  1748. spin_lock_irq(&phba->hbalock);
  1749. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1750. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1751. if (hbq_buf->tag == tag) {
  1752. spin_unlock_irq(&phba->hbalock);
  1753. return hbq_buf;
  1754. }
  1755. }
  1756. spin_unlock_irq(&phba->hbalock);
  1757. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1758. "1803 Bad hbq tag. Data: x%x x%x\n",
  1759. tag, phba->hbqs[tag >> 16].buffer_count);
  1760. return NULL;
  1761. }
  1762. /**
  1763. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1764. * @phba: Pointer to HBA context object.
  1765. * @hbq_buffer: Pointer to HBQ buffer.
  1766. *
  1767. * This function is called with hbalock. This function gives back
  1768. * the hbq buffer to firmware. If the HBQ does not have space to
  1769. * post the buffer, it will free the buffer.
  1770. **/
  1771. void
  1772. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1773. {
  1774. uint32_t hbqno;
  1775. if (hbq_buffer) {
  1776. hbqno = hbq_buffer->tag >> 16;
  1777. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1778. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1779. }
  1780. }
  1781. /**
  1782. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1783. * @mbxCommand: mailbox command code.
  1784. *
  1785. * This function is called by the mailbox event handler function to verify
  1786. * that the completed mailbox command is a legitimate mailbox command. If the
  1787. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1788. * and the mailbox event handler will take the HBA offline.
  1789. **/
  1790. static int
  1791. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1792. {
  1793. uint8_t ret;
  1794. switch (mbxCommand) {
  1795. case MBX_LOAD_SM:
  1796. case MBX_READ_NV:
  1797. case MBX_WRITE_NV:
  1798. case MBX_WRITE_VPARMS:
  1799. case MBX_RUN_BIU_DIAG:
  1800. case MBX_INIT_LINK:
  1801. case MBX_DOWN_LINK:
  1802. case MBX_CONFIG_LINK:
  1803. case MBX_CONFIG_RING:
  1804. case MBX_RESET_RING:
  1805. case MBX_READ_CONFIG:
  1806. case MBX_READ_RCONFIG:
  1807. case MBX_READ_SPARM:
  1808. case MBX_READ_STATUS:
  1809. case MBX_READ_RPI:
  1810. case MBX_READ_XRI:
  1811. case MBX_READ_REV:
  1812. case MBX_READ_LNK_STAT:
  1813. case MBX_REG_LOGIN:
  1814. case MBX_UNREG_LOGIN:
  1815. case MBX_CLEAR_LA:
  1816. case MBX_DUMP_MEMORY:
  1817. case MBX_DUMP_CONTEXT:
  1818. case MBX_RUN_DIAGS:
  1819. case MBX_RESTART:
  1820. case MBX_UPDATE_CFG:
  1821. case MBX_DOWN_LOAD:
  1822. case MBX_DEL_LD_ENTRY:
  1823. case MBX_RUN_PROGRAM:
  1824. case MBX_SET_MASK:
  1825. case MBX_SET_VARIABLE:
  1826. case MBX_UNREG_D_ID:
  1827. case MBX_KILL_BOARD:
  1828. case MBX_CONFIG_FARP:
  1829. case MBX_BEACON:
  1830. case MBX_LOAD_AREA:
  1831. case MBX_RUN_BIU_DIAG64:
  1832. case MBX_CONFIG_PORT:
  1833. case MBX_READ_SPARM64:
  1834. case MBX_READ_RPI64:
  1835. case MBX_REG_LOGIN64:
  1836. case MBX_READ_TOPOLOGY:
  1837. case MBX_WRITE_WWN:
  1838. case MBX_SET_DEBUG:
  1839. case MBX_LOAD_EXP_ROM:
  1840. case MBX_ASYNCEVT_ENABLE:
  1841. case MBX_REG_VPI:
  1842. case MBX_UNREG_VPI:
  1843. case MBX_HEARTBEAT:
  1844. case MBX_PORT_CAPABILITIES:
  1845. case MBX_PORT_IOV_CONTROL:
  1846. case MBX_SLI4_CONFIG:
  1847. case MBX_SLI4_REQ_FTRS:
  1848. case MBX_REG_FCFI:
  1849. case MBX_UNREG_FCFI:
  1850. case MBX_REG_VFI:
  1851. case MBX_UNREG_VFI:
  1852. case MBX_INIT_VPI:
  1853. case MBX_INIT_VFI:
  1854. case MBX_RESUME_RPI:
  1855. case MBX_READ_EVENT_LOG_STATUS:
  1856. case MBX_READ_EVENT_LOG:
  1857. case MBX_SECURITY_MGMT:
  1858. case MBX_AUTH_PORT:
  1859. ret = mbxCommand;
  1860. break;
  1861. default:
  1862. ret = MBX_SHUTDOWN;
  1863. break;
  1864. }
  1865. return ret;
  1866. }
  1867. /**
  1868. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1869. * @phba: Pointer to HBA context object.
  1870. * @pmboxq: Pointer to mailbox command.
  1871. *
  1872. * This is completion handler function for mailbox commands issued from
  1873. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1874. * mailbox event handler function with no lock held. This function
  1875. * will wake up thread waiting on the wait queue pointed by context1
  1876. * of the mailbox.
  1877. **/
  1878. void
  1879. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1880. {
  1881. wait_queue_head_t *pdone_q;
  1882. unsigned long drvr_flag;
  1883. /*
  1884. * If pdone_q is empty, the driver thread gave up waiting and
  1885. * continued running.
  1886. */
  1887. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1888. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1889. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1890. if (pdone_q)
  1891. wake_up_interruptible(pdone_q);
  1892. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1893. return;
  1894. }
  1895. /**
  1896. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1897. * @phba: Pointer to HBA context object.
  1898. * @pmb: Pointer to mailbox object.
  1899. *
  1900. * This function is the default mailbox completion handler. It
  1901. * frees the memory resources associated with the completed mailbox
  1902. * command. If the completed command is a REG_LOGIN mailbox command,
  1903. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1904. **/
  1905. void
  1906. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1907. {
  1908. struct lpfc_vport *vport = pmb->vport;
  1909. struct lpfc_dmabuf *mp;
  1910. struct lpfc_nodelist *ndlp;
  1911. struct Scsi_Host *shost;
  1912. uint16_t rpi, vpi;
  1913. int rc;
  1914. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1915. if (mp) {
  1916. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1917. kfree(mp);
  1918. }
  1919. /*
  1920. * If a REG_LOGIN succeeded after node is destroyed or node
  1921. * is in re-discovery driver need to cleanup the RPI.
  1922. */
  1923. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1924. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1925. !pmb->u.mb.mbxStatus) {
  1926. rpi = pmb->u.mb.un.varWords[0];
  1927. vpi = pmb->u.mb.un.varRegLogin.vpi;
  1928. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1929. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1930. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1931. if (rc != MBX_NOT_FINISHED)
  1932. return;
  1933. }
  1934. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1935. !(phba->pport->load_flag & FC_UNLOADING) &&
  1936. !pmb->u.mb.mbxStatus) {
  1937. shost = lpfc_shost_from_vport(vport);
  1938. spin_lock_irq(shost->host_lock);
  1939. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1940. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1941. spin_unlock_irq(shost->host_lock);
  1942. }
  1943. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1944. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1945. lpfc_nlp_put(ndlp);
  1946. pmb->context2 = NULL;
  1947. }
  1948. /* Check security permission status on INIT_LINK mailbox command */
  1949. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1950. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1951. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1952. "2860 SLI authentication is required "
  1953. "for INIT_LINK but has not done yet\n");
  1954. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1955. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1956. else
  1957. mempool_free(pmb, phba->mbox_mem_pool);
  1958. }
  1959. /**
  1960. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1961. * @phba: Pointer to HBA context object.
  1962. *
  1963. * This function is called with no lock held. This function processes all
  1964. * the completed mailbox commands and gives it to upper layers. The interrupt
  1965. * service routine processes mailbox completion interrupt and adds completed
  1966. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1967. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1968. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1969. * function returns the mailbox commands to the upper layer by calling the
  1970. * completion handler function of each mailbox.
  1971. **/
  1972. int
  1973. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1974. {
  1975. MAILBOX_t *pmbox;
  1976. LPFC_MBOXQ_t *pmb;
  1977. int rc;
  1978. LIST_HEAD(cmplq);
  1979. phba->sli.slistat.mbox_event++;
  1980. /* Get all completed mailboxe buffers into the cmplq */
  1981. spin_lock_irq(&phba->hbalock);
  1982. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1983. spin_unlock_irq(&phba->hbalock);
  1984. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1985. do {
  1986. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1987. if (pmb == NULL)
  1988. break;
  1989. pmbox = &pmb->u.mb;
  1990. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1991. if (pmb->vport) {
  1992. lpfc_debugfs_disc_trc(pmb->vport,
  1993. LPFC_DISC_TRC_MBOX_VPORT,
  1994. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1995. (uint32_t)pmbox->mbxCommand,
  1996. pmbox->un.varWords[0],
  1997. pmbox->un.varWords[1]);
  1998. }
  1999. else {
  2000. lpfc_debugfs_disc_trc(phba->pport,
  2001. LPFC_DISC_TRC_MBOX,
  2002. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2003. (uint32_t)pmbox->mbxCommand,
  2004. pmbox->un.varWords[0],
  2005. pmbox->un.varWords[1]);
  2006. }
  2007. }
  2008. /*
  2009. * It is a fatal error if unknown mbox command completion.
  2010. */
  2011. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2012. MBX_SHUTDOWN) {
  2013. /* Unknown mailbox command compl */
  2014. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2015. "(%d):0323 Unknown Mailbox command "
  2016. "x%x (x%x/x%x) Cmpl\n",
  2017. pmb->vport ? pmb->vport->vpi : 0,
  2018. pmbox->mbxCommand,
  2019. lpfc_sli_config_mbox_subsys_get(phba,
  2020. pmb),
  2021. lpfc_sli_config_mbox_opcode_get(phba,
  2022. pmb));
  2023. phba->link_state = LPFC_HBA_ERROR;
  2024. phba->work_hs = HS_FFER3;
  2025. lpfc_handle_eratt(phba);
  2026. continue;
  2027. }
  2028. if (pmbox->mbxStatus) {
  2029. phba->sli.slistat.mbox_stat_err++;
  2030. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2031. /* Mbox cmd cmpl error - RETRYing */
  2032. lpfc_printf_log(phba, KERN_INFO,
  2033. LOG_MBOX | LOG_SLI,
  2034. "(%d):0305 Mbox cmd cmpl "
  2035. "error - RETRYing Data: x%x "
  2036. "(x%x/x%x) x%x x%x x%x\n",
  2037. pmb->vport ? pmb->vport->vpi : 0,
  2038. pmbox->mbxCommand,
  2039. lpfc_sli_config_mbox_subsys_get(phba,
  2040. pmb),
  2041. lpfc_sli_config_mbox_opcode_get(phba,
  2042. pmb),
  2043. pmbox->mbxStatus,
  2044. pmbox->un.varWords[0],
  2045. pmb->vport->port_state);
  2046. pmbox->mbxStatus = 0;
  2047. pmbox->mbxOwner = OWN_HOST;
  2048. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2049. if (rc != MBX_NOT_FINISHED)
  2050. continue;
  2051. }
  2052. }
  2053. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2054. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2055. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
  2056. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2057. pmb->vport ? pmb->vport->vpi : 0,
  2058. pmbox->mbxCommand,
  2059. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2060. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2061. pmb->mbox_cmpl,
  2062. *((uint32_t *) pmbox),
  2063. pmbox->un.varWords[0],
  2064. pmbox->un.varWords[1],
  2065. pmbox->un.varWords[2],
  2066. pmbox->un.varWords[3],
  2067. pmbox->un.varWords[4],
  2068. pmbox->un.varWords[5],
  2069. pmbox->un.varWords[6],
  2070. pmbox->un.varWords[7]);
  2071. if (pmb->mbox_cmpl)
  2072. pmb->mbox_cmpl(phba,pmb);
  2073. } while (1);
  2074. return 0;
  2075. }
  2076. /**
  2077. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2078. * @phba: Pointer to HBA context object.
  2079. * @pring: Pointer to driver SLI ring object.
  2080. * @tag: buffer tag.
  2081. *
  2082. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2083. * is set in the tag the buffer is posted for a particular exchange,
  2084. * the function will return the buffer without replacing the buffer.
  2085. * If the buffer is for unsolicited ELS or CT traffic, this function
  2086. * returns the buffer and also posts another buffer to the firmware.
  2087. **/
  2088. static struct lpfc_dmabuf *
  2089. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2090. struct lpfc_sli_ring *pring,
  2091. uint32_t tag)
  2092. {
  2093. struct hbq_dmabuf *hbq_entry;
  2094. if (tag & QUE_BUFTAG_BIT)
  2095. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2096. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2097. if (!hbq_entry)
  2098. return NULL;
  2099. return &hbq_entry->dbuf;
  2100. }
  2101. /**
  2102. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2103. * @phba: Pointer to HBA context object.
  2104. * @pring: Pointer to driver SLI ring object.
  2105. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2106. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2107. * @fch_type: the type for the first frame of the sequence.
  2108. *
  2109. * This function is called with no lock held. This function uses the r_ctl and
  2110. * type of the received sequence to find the correct callback function to call
  2111. * to process the sequence.
  2112. **/
  2113. static int
  2114. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2115. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2116. uint32_t fch_type)
  2117. {
  2118. int i;
  2119. /* unSolicited Responses */
  2120. if (pring->prt[0].profile) {
  2121. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2122. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2123. saveq);
  2124. return 1;
  2125. }
  2126. /* We must search, based on rctl / type
  2127. for the right routine */
  2128. for (i = 0; i < pring->num_mask; i++) {
  2129. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2130. (pring->prt[i].type == fch_type)) {
  2131. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2132. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2133. (phba, pring, saveq);
  2134. return 1;
  2135. }
  2136. }
  2137. return 0;
  2138. }
  2139. /**
  2140. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2141. * @phba: Pointer to HBA context object.
  2142. * @pring: Pointer to driver SLI ring object.
  2143. * @saveq: Pointer to the unsolicited iocb.
  2144. *
  2145. * This function is called with no lock held by the ring event handler
  2146. * when there is an unsolicited iocb posted to the response ring by the
  2147. * firmware. This function gets the buffer associated with the iocbs
  2148. * and calls the event handler for the ring. This function handles both
  2149. * qring buffers and hbq buffers.
  2150. * When the function returns 1 the caller can free the iocb object otherwise
  2151. * upper layer functions will free the iocb objects.
  2152. **/
  2153. static int
  2154. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2155. struct lpfc_iocbq *saveq)
  2156. {
  2157. IOCB_t * irsp;
  2158. WORD5 * w5p;
  2159. uint32_t Rctl, Type;
  2160. uint32_t match;
  2161. struct lpfc_iocbq *iocbq;
  2162. struct lpfc_dmabuf *dmzbuf;
  2163. match = 0;
  2164. irsp = &(saveq->iocb);
  2165. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2166. if (pring->lpfc_sli_rcv_async_status)
  2167. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2168. else
  2169. lpfc_printf_log(phba,
  2170. KERN_WARNING,
  2171. LOG_SLI,
  2172. "0316 Ring %d handler: unexpected "
  2173. "ASYNC_STATUS iocb received evt_code "
  2174. "0x%x\n",
  2175. pring->ringno,
  2176. irsp->un.asyncstat.evt_code);
  2177. return 1;
  2178. }
  2179. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2180. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2181. if (irsp->ulpBdeCount > 0) {
  2182. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2183. irsp->un.ulpWord[3]);
  2184. lpfc_in_buf_free(phba, dmzbuf);
  2185. }
  2186. if (irsp->ulpBdeCount > 1) {
  2187. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2188. irsp->unsli3.sli3Words[3]);
  2189. lpfc_in_buf_free(phba, dmzbuf);
  2190. }
  2191. if (irsp->ulpBdeCount > 2) {
  2192. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2193. irsp->unsli3.sli3Words[7]);
  2194. lpfc_in_buf_free(phba, dmzbuf);
  2195. }
  2196. return 1;
  2197. }
  2198. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2199. if (irsp->ulpBdeCount != 0) {
  2200. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2201. irsp->un.ulpWord[3]);
  2202. if (!saveq->context2)
  2203. lpfc_printf_log(phba,
  2204. KERN_ERR,
  2205. LOG_SLI,
  2206. "0341 Ring %d Cannot find buffer for "
  2207. "an unsolicited iocb. tag 0x%x\n",
  2208. pring->ringno,
  2209. irsp->un.ulpWord[3]);
  2210. }
  2211. if (irsp->ulpBdeCount == 2) {
  2212. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2213. irsp->unsli3.sli3Words[7]);
  2214. if (!saveq->context3)
  2215. lpfc_printf_log(phba,
  2216. KERN_ERR,
  2217. LOG_SLI,
  2218. "0342 Ring %d Cannot find buffer for an"
  2219. " unsolicited iocb. tag 0x%x\n",
  2220. pring->ringno,
  2221. irsp->unsli3.sli3Words[7]);
  2222. }
  2223. list_for_each_entry(iocbq, &saveq->list, list) {
  2224. irsp = &(iocbq->iocb);
  2225. if (irsp->ulpBdeCount != 0) {
  2226. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2227. irsp->un.ulpWord[3]);
  2228. if (!iocbq->context2)
  2229. lpfc_printf_log(phba,
  2230. KERN_ERR,
  2231. LOG_SLI,
  2232. "0343 Ring %d Cannot find "
  2233. "buffer for an unsolicited iocb"
  2234. ". tag 0x%x\n", pring->ringno,
  2235. irsp->un.ulpWord[3]);
  2236. }
  2237. if (irsp->ulpBdeCount == 2) {
  2238. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2239. irsp->unsli3.sli3Words[7]);
  2240. if (!iocbq->context3)
  2241. lpfc_printf_log(phba,
  2242. KERN_ERR,
  2243. LOG_SLI,
  2244. "0344 Ring %d Cannot find "
  2245. "buffer for an unsolicited "
  2246. "iocb. tag 0x%x\n",
  2247. pring->ringno,
  2248. irsp->unsli3.sli3Words[7]);
  2249. }
  2250. }
  2251. }
  2252. if (irsp->ulpBdeCount != 0 &&
  2253. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2254. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2255. int found = 0;
  2256. /* search continue save q for same XRI */
  2257. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2258. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  2259. saveq->iocb.unsli3.rcvsli3.ox_id) {
  2260. list_add_tail(&saveq->list, &iocbq->list);
  2261. found = 1;
  2262. break;
  2263. }
  2264. }
  2265. if (!found)
  2266. list_add_tail(&saveq->clist,
  2267. &pring->iocb_continue_saveq);
  2268. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2269. list_del_init(&iocbq->clist);
  2270. saveq = iocbq;
  2271. irsp = &(saveq->iocb);
  2272. } else
  2273. return 0;
  2274. }
  2275. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2276. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2277. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2278. Rctl = FC_RCTL_ELS_REQ;
  2279. Type = FC_TYPE_ELS;
  2280. } else {
  2281. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2282. Rctl = w5p->hcsw.Rctl;
  2283. Type = w5p->hcsw.Type;
  2284. /* Firmware Workaround */
  2285. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2286. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2287. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2288. Rctl = FC_RCTL_ELS_REQ;
  2289. Type = FC_TYPE_ELS;
  2290. w5p->hcsw.Rctl = Rctl;
  2291. w5p->hcsw.Type = Type;
  2292. }
  2293. }
  2294. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2295. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2296. "0313 Ring %d handler: unexpected Rctl x%x "
  2297. "Type x%x received\n",
  2298. pring->ringno, Rctl, Type);
  2299. return 1;
  2300. }
  2301. /**
  2302. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2303. * @phba: Pointer to HBA context object.
  2304. * @pring: Pointer to driver SLI ring object.
  2305. * @prspiocb: Pointer to response iocb object.
  2306. *
  2307. * This function looks up the iocb_lookup table to get the command iocb
  2308. * corresponding to the given response iocb using the iotag of the
  2309. * response iocb. This function is called with the hbalock held.
  2310. * This function returns the command iocb object if it finds the command
  2311. * iocb else returns NULL.
  2312. **/
  2313. static struct lpfc_iocbq *
  2314. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2315. struct lpfc_sli_ring *pring,
  2316. struct lpfc_iocbq *prspiocb)
  2317. {
  2318. struct lpfc_iocbq *cmd_iocb = NULL;
  2319. uint16_t iotag;
  2320. iotag = prspiocb->iocb.ulpIoTag;
  2321. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2322. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2323. list_del_init(&cmd_iocb->list);
  2324. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2325. pring->txcmplq_cnt--;
  2326. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2327. }
  2328. return cmd_iocb;
  2329. }
  2330. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2331. "0317 iotag x%x is out off "
  2332. "range: max iotag x%x wd0 x%x\n",
  2333. iotag, phba->sli.last_iotag,
  2334. *(((uint32_t *) &prspiocb->iocb) + 7));
  2335. return NULL;
  2336. }
  2337. /**
  2338. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2339. * @phba: Pointer to HBA context object.
  2340. * @pring: Pointer to driver SLI ring object.
  2341. * @iotag: IOCB tag.
  2342. *
  2343. * This function looks up the iocb_lookup table to get the command iocb
  2344. * corresponding to the given iotag. This function is called with the
  2345. * hbalock held.
  2346. * This function returns the command iocb object if it finds the command
  2347. * iocb else returns NULL.
  2348. **/
  2349. static struct lpfc_iocbq *
  2350. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2351. struct lpfc_sli_ring *pring, uint16_t iotag)
  2352. {
  2353. struct lpfc_iocbq *cmd_iocb;
  2354. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2355. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2356. list_del_init(&cmd_iocb->list);
  2357. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2358. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2359. pring->txcmplq_cnt--;
  2360. }
  2361. return cmd_iocb;
  2362. }
  2363. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2364. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2365. iotag, phba->sli.last_iotag);
  2366. return NULL;
  2367. }
  2368. /**
  2369. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2370. * @phba: Pointer to HBA context object.
  2371. * @pring: Pointer to driver SLI ring object.
  2372. * @saveq: Pointer to the response iocb to be processed.
  2373. *
  2374. * This function is called by the ring event handler for non-fcp
  2375. * rings when there is a new response iocb in the response ring.
  2376. * The caller is not required to hold any locks. This function
  2377. * gets the command iocb associated with the response iocb and
  2378. * calls the completion handler for the command iocb. If there
  2379. * is no completion handler, the function will free the resources
  2380. * associated with command iocb. If the response iocb is for
  2381. * an already aborted command iocb, the status of the completion
  2382. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2383. * This function always returns 1.
  2384. **/
  2385. static int
  2386. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2387. struct lpfc_iocbq *saveq)
  2388. {
  2389. struct lpfc_iocbq *cmdiocbp;
  2390. int rc = 1;
  2391. unsigned long iflag;
  2392. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2393. spin_lock_irqsave(&phba->hbalock, iflag);
  2394. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2395. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2396. if (cmdiocbp) {
  2397. if (cmdiocbp->iocb_cmpl) {
  2398. /*
  2399. * If an ELS command failed send an event to mgmt
  2400. * application.
  2401. */
  2402. if (saveq->iocb.ulpStatus &&
  2403. (pring->ringno == LPFC_ELS_RING) &&
  2404. (cmdiocbp->iocb.ulpCommand ==
  2405. CMD_ELS_REQUEST64_CR))
  2406. lpfc_send_els_failure_event(phba,
  2407. cmdiocbp, saveq);
  2408. /*
  2409. * Post all ELS completions to the worker thread.
  2410. * All other are passed to the completion callback.
  2411. */
  2412. if (pring->ringno == LPFC_ELS_RING) {
  2413. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2414. (cmdiocbp->iocb_flag &
  2415. LPFC_DRIVER_ABORTED)) {
  2416. spin_lock_irqsave(&phba->hbalock,
  2417. iflag);
  2418. cmdiocbp->iocb_flag &=
  2419. ~LPFC_DRIVER_ABORTED;
  2420. spin_unlock_irqrestore(&phba->hbalock,
  2421. iflag);
  2422. saveq->iocb.ulpStatus =
  2423. IOSTAT_LOCAL_REJECT;
  2424. saveq->iocb.un.ulpWord[4] =
  2425. IOERR_SLI_ABORTED;
  2426. /* Firmware could still be in progress
  2427. * of DMAing payload, so don't free data
  2428. * buffer till after a hbeat.
  2429. */
  2430. spin_lock_irqsave(&phba->hbalock,
  2431. iflag);
  2432. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2433. spin_unlock_irqrestore(&phba->hbalock,
  2434. iflag);
  2435. }
  2436. if (phba->sli_rev == LPFC_SLI_REV4) {
  2437. if (saveq->iocb_flag &
  2438. LPFC_EXCHANGE_BUSY) {
  2439. /* Set cmdiocb flag for the
  2440. * exchange busy so sgl (xri)
  2441. * will not be released until
  2442. * the abort xri is received
  2443. * from hba.
  2444. */
  2445. spin_lock_irqsave(
  2446. &phba->hbalock, iflag);
  2447. cmdiocbp->iocb_flag |=
  2448. LPFC_EXCHANGE_BUSY;
  2449. spin_unlock_irqrestore(
  2450. &phba->hbalock, iflag);
  2451. }
  2452. if (cmdiocbp->iocb_flag &
  2453. LPFC_DRIVER_ABORTED) {
  2454. /*
  2455. * Clear LPFC_DRIVER_ABORTED
  2456. * bit in case it was driver
  2457. * initiated abort.
  2458. */
  2459. spin_lock_irqsave(
  2460. &phba->hbalock, iflag);
  2461. cmdiocbp->iocb_flag &=
  2462. ~LPFC_DRIVER_ABORTED;
  2463. spin_unlock_irqrestore(
  2464. &phba->hbalock, iflag);
  2465. cmdiocbp->iocb.ulpStatus =
  2466. IOSTAT_LOCAL_REJECT;
  2467. cmdiocbp->iocb.un.ulpWord[4] =
  2468. IOERR_ABORT_REQUESTED;
  2469. /*
  2470. * For SLI4, irsiocb contains
  2471. * NO_XRI in sli_xritag, it
  2472. * shall not affect releasing
  2473. * sgl (xri) process.
  2474. */
  2475. saveq->iocb.ulpStatus =
  2476. IOSTAT_LOCAL_REJECT;
  2477. saveq->iocb.un.ulpWord[4] =
  2478. IOERR_SLI_ABORTED;
  2479. spin_lock_irqsave(
  2480. &phba->hbalock, iflag);
  2481. saveq->iocb_flag |=
  2482. LPFC_DELAY_MEM_FREE;
  2483. spin_unlock_irqrestore(
  2484. &phba->hbalock, iflag);
  2485. }
  2486. }
  2487. }
  2488. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2489. } else
  2490. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2491. } else {
  2492. /*
  2493. * Unknown initiating command based on the response iotag.
  2494. * This could be the case on the ELS ring because of
  2495. * lpfc_els_abort().
  2496. */
  2497. if (pring->ringno != LPFC_ELS_RING) {
  2498. /*
  2499. * Ring <ringno> handler: unexpected completion IoTag
  2500. * <IoTag>
  2501. */
  2502. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2503. "0322 Ring %d handler: "
  2504. "unexpected completion IoTag x%x "
  2505. "Data: x%x x%x x%x x%x\n",
  2506. pring->ringno,
  2507. saveq->iocb.ulpIoTag,
  2508. saveq->iocb.ulpStatus,
  2509. saveq->iocb.un.ulpWord[4],
  2510. saveq->iocb.ulpCommand,
  2511. saveq->iocb.ulpContext);
  2512. }
  2513. }
  2514. return rc;
  2515. }
  2516. /**
  2517. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2518. * @phba: Pointer to HBA context object.
  2519. * @pring: Pointer to driver SLI ring object.
  2520. *
  2521. * This function is called from the iocb ring event handlers when
  2522. * put pointer is ahead of the get pointer for a ring. This function signal
  2523. * an error attention condition to the worker thread and the worker
  2524. * thread will transition the HBA to offline state.
  2525. **/
  2526. static void
  2527. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2528. {
  2529. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2530. /*
  2531. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2532. * rsp ring <portRspMax>
  2533. */
  2534. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2535. "0312 Ring %d handler: portRspPut %d "
  2536. "is bigger than rsp ring %d\n",
  2537. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2538. pring->numRiocb);
  2539. phba->link_state = LPFC_HBA_ERROR;
  2540. /*
  2541. * All error attention handlers are posted to
  2542. * worker thread
  2543. */
  2544. phba->work_ha |= HA_ERATT;
  2545. phba->work_hs = HS_FFER3;
  2546. lpfc_worker_wake_up(phba);
  2547. return;
  2548. }
  2549. /**
  2550. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2551. * @ptr: Pointer to address of HBA context object.
  2552. *
  2553. * This function is invoked by the Error Attention polling timer when the
  2554. * timer times out. It will check the SLI Error Attention register for
  2555. * possible attention events. If so, it will post an Error Attention event
  2556. * and wake up worker thread to process it. Otherwise, it will set up the
  2557. * Error Attention polling timer for the next poll.
  2558. **/
  2559. void lpfc_poll_eratt(unsigned long ptr)
  2560. {
  2561. struct lpfc_hba *phba;
  2562. uint32_t eratt = 0;
  2563. phba = (struct lpfc_hba *)ptr;
  2564. /* Check chip HA register for error event */
  2565. eratt = lpfc_sli_check_eratt(phba);
  2566. if (eratt)
  2567. /* Tell the worker thread there is work to do */
  2568. lpfc_worker_wake_up(phba);
  2569. else
  2570. /* Restart the timer for next eratt poll */
  2571. mod_timer(&phba->eratt_poll, jiffies +
  2572. HZ * LPFC_ERATT_POLL_INTERVAL);
  2573. return;
  2574. }
  2575. /**
  2576. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2577. * @phba: Pointer to HBA context object.
  2578. * @pring: Pointer to driver SLI ring object.
  2579. * @mask: Host attention register mask for this ring.
  2580. *
  2581. * This function is called from the interrupt context when there is a ring
  2582. * event for the fcp ring. The caller does not hold any lock.
  2583. * The function processes each response iocb in the response ring until it
  2584. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2585. * LE bit set. The function will call the completion handler of the command iocb
  2586. * if the response iocb indicates a completion for a command iocb or it is
  2587. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2588. * function if this is an unsolicited iocb.
  2589. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2590. * to check it explicitly.
  2591. */
  2592. int
  2593. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2594. struct lpfc_sli_ring *pring, uint32_t mask)
  2595. {
  2596. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2597. IOCB_t *irsp = NULL;
  2598. IOCB_t *entry = NULL;
  2599. struct lpfc_iocbq *cmdiocbq = NULL;
  2600. struct lpfc_iocbq rspiocbq;
  2601. uint32_t status;
  2602. uint32_t portRspPut, portRspMax;
  2603. int rc = 1;
  2604. lpfc_iocb_type type;
  2605. unsigned long iflag;
  2606. uint32_t rsp_cmpl = 0;
  2607. spin_lock_irqsave(&phba->hbalock, iflag);
  2608. pring->stats.iocb_event++;
  2609. /*
  2610. * The next available response entry should never exceed the maximum
  2611. * entries. If it does, treat it as an adapter hardware error.
  2612. */
  2613. portRspMax = pring->numRiocb;
  2614. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2615. if (unlikely(portRspPut >= portRspMax)) {
  2616. lpfc_sli_rsp_pointers_error(phba, pring);
  2617. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2618. return 1;
  2619. }
  2620. if (phba->fcp_ring_in_use) {
  2621. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2622. return 1;
  2623. } else
  2624. phba->fcp_ring_in_use = 1;
  2625. rmb();
  2626. while (pring->rspidx != portRspPut) {
  2627. /*
  2628. * Fetch an entry off the ring and copy it into a local data
  2629. * structure. The copy involves a byte-swap since the
  2630. * network byte order and pci byte orders are different.
  2631. */
  2632. entry = lpfc_resp_iocb(phba, pring);
  2633. phba->last_completion_time = jiffies;
  2634. if (++pring->rspidx >= portRspMax)
  2635. pring->rspidx = 0;
  2636. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2637. (uint32_t *) &rspiocbq.iocb,
  2638. phba->iocb_rsp_size);
  2639. INIT_LIST_HEAD(&(rspiocbq.list));
  2640. irsp = &rspiocbq.iocb;
  2641. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2642. pring->stats.iocb_rsp++;
  2643. rsp_cmpl++;
  2644. if (unlikely(irsp->ulpStatus)) {
  2645. /*
  2646. * If resource errors reported from HBA, reduce
  2647. * queuedepths of the SCSI device.
  2648. */
  2649. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2650. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2651. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2652. phba->lpfc_rampdown_queue_depth(phba);
  2653. spin_lock_irqsave(&phba->hbalock, iflag);
  2654. }
  2655. /* Rsp ring <ringno> error: IOCB */
  2656. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2657. "0336 Rsp Ring %d error: IOCB Data: "
  2658. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2659. pring->ringno,
  2660. irsp->un.ulpWord[0],
  2661. irsp->un.ulpWord[1],
  2662. irsp->un.ulpWord[2],
  2663. irsp->un.ulpWord[3],
  2664. irsp->un.ulpWord[4],
  2665. irsp->un.ulpWord[5],
  2666. *(uint32_t *)&irsp->un1,
  2667. *((uint32_t *)&irsp->un1 + 1));
  2668. }
  2669. switch (type) {
  2670. case LPFC_ABORT_IOCB:
  2671. case LPFC_SOL_IOCB:
  2672. /*
  2673. * Idle exchange closed via ABTS from port. No iocb
  2674. * resources need to be recovered.
  2675. */
  2676. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2677. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2678. "0333 IOCB cmd 0x%x"
  2679. " processed. Skipping"
  2680. " completion\n",
  2681. irsp->ulpCommand);
  2682. break;
  2683. }
  2684. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2685. &rspiocbq);
  2686. if (unlikely(!cmdiocbq))
  2687. break;
  2688. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2689. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2690. if (cmdiocbq->iocb_cmpl) {
  2691. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2692. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2693. &rspiocbq);
  2694. spin_lock_irqsave(&phba->hbalock, iflag);
  2695. }
  2696. break;
  2697. case LPFC_UNSOL_IOCB:
  2698. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2699. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2700. spin_lock_irqsave(&phba->hbalock, iflag);
  2701. break;
  2702. default:
  2703. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2704. char adaptermsg[LPFC_MAX_ADPTMSG];
  2705. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2706. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2707. MAX_MSG_DATA);
  2708. dev_warn(&((phba->pcidev)->dev),
  2709. "lpfc%d: %s\n",
  2710. phba->brd_no, adaptermsg);
  2711. } else {
  2712. /* Unknown IOCB command */
  2713. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2714. "0334 Unknown IOCB command "
  2715. "Data: x%x, x%x x%x x%x x%x\n",
  2716. type, irsp->ulpCommand,
  2717. irsp->ulpStatus,
  2718. irsp->ulpIoTag,
  2719. irsp->ulpContext);
  2720. }
  2721. break;
  2722. }
  2723. /*
  2724. * The response IOCB has been processed. Update the ring
  2725. * pointer in SLIM. If the port response put pointer has not
  2726. * been updated, sync the pgp->rspPutInx and fetch the new port
  2727. * response put pointer.
  2728. */
  2729. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2730. if (pring->rspidx == portRspPut)
  2731. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2732. }
  2733. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2734. pring->stats.iocb_rsp_full++;
  2735. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2736. writel(status, phba->CAregaddr);
  2737. readl(phba->CAregaddr);
  2738. }
  2739. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2740. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2741. pring->stats.iocb_cmd_empty++;
  2742. /* Force update of the local copy of cmdGetInx */
  2743. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2744. lpfc_sli_resume_iocb(phba, pring);
  2745. if ((pring->lpfc_sli_cmd_available))
  2746. (pring->lpfc_sli_cmd_available) (phba, pring);
  2747. }
  2748. phba->fcp_ring_in_use = 0;
  2749. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2750. return rc;
  2751. }
  2752. /**
  2753. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2754. * @phba: Pointer to HBA context object.
  2755. * @pring: Pointer to driver SLI ring object.
  2756. * @rspiocbp: Pointer to driver response IOCB object.
  2757. *
  2758. * This function is called from the worker thread when there is a slow-path
  2759. * response IOCB to process. This function chains all the response iocbs until
  2760. * seeing the iocb with the LE bit set. The function will call
  2761. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2762. * completion of a command iocb. The function will call the
  2763. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2764. * The function frees the resources or calls the completion handler if this
  2765. * iocb is an abort completion. The function returns NULL when the response
  2766. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2767. * this function shall chain the iocb on to the iocb_continueq and return the
  2768. * response iocb passed in.
  2769. **/
  2770. static struct lpfc_iocbq *
  2771. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2772. struct lpfc_iocbq *rspiocbp)
  2773. {
  2774. struct lpfc_iocbq *saveq;
  2775. struct lpfc_iocbq *cmdiocbp;
  2776. struct lpfc_iocbq *next_iocb;
  2777. IOCB_t *irsp = NULL;
  2778. uint32_t free_saveq;
  2779. uint8_t iocb_cmd_type;
  2780. lpfc_iocb_type type;
  2781. unsigned long iflag;
  2782. int rc;
  2783. spin_lock_irqsave(&phba->hbalock, iflag);
  2784. /* First add the response iocb to the countinueq list */
  2785. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2786. pring->iocb_continueq_cnt++;
  2787. /* Now, determine whether the list is completed for processing */
  2788. irsp = &rspiocbp->iocb;
  2789. if (irsp->ulpLe) {
  2790. /*
  2791. * By default, the driver expects to free all resources
  2792. * associated with this iocb completion.
  2793. */
  2794. free_saveq = 1;
  2795. saveq = list_get_first(&pring->iocb_continueq,
  2796. struct lpfc_iocbq, list);
  2797. irsp = &(saveq->iocb);
  2798. list_del_init(&pring->iocb_continueq);
  2799. pring->iocb_continueq_cnt = 0;
  2800. pring->stats.iocb_rsp++;
  2801. /*
  2802. * If resource errors reported from HBA, reduce
  2803. * queuedepths of the SCSI device.
  2804. */
  2805. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2806. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2807. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2808. phba->lpfc_rampdown_queue_depth(phba);
  2809. spin_lock_irqsave(&phba->hbalock, iflag);
  2810. }
  2811. if (irsp->ulpStatus) {
  2812. /* Rsp ring <ringno> error: IOCB */
  2813. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2814. "0328 Rsp Ring %d error: "
  2815. "IOCB Data: "
  2816. "x%x x%x x%x x%x "
  2817. "x%x x%x x%x x%x "
  2818. "x%x x%x x%x x%x "
  2819. "x%x x%x x%x x%x\n",
  2820. pring->ringno,
  2821. irsp->un.ulpWord[0],
  2822. irsp->un.ulpWord[1],
  2823. irsp->un.ulpWord[2],
  2824. irsp->un.ulpWord[3],
  2825. irsp->un.ulpWord[4],
  2826. irsp->un.ulpWord[5],
  2827. *(((uint32_t *) irsp) + 6),
  2828. *(((uint32_t *) irsp) + 7),
  2829. *(((uint32_t *) irsp) + 8),
  2830. *(((uint32_t *) irsp) + 9),
  2831. *(((uint32_t *) irsp) + 10),
  2832. *(((uint32_t *) irsp) + 11),
  2833. *(((uint32_t *) irsp) + 12),
  2834. *(((uint32_t *) irsp) + 13),
  2835. *(((uint32_t *) irsp) + 14),
  2836. *(((uint32_t *) irsp) + 15));
  2837. }
  2838. /*
  2839. * Fetch the IOCB command type and call the correct completion
  2840. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2841. * get freed back to the lpfc_iocb_list by the discovery
  2842. * kernel thread.
  2843. */
  2844. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2845. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2846. switch (type) {
  2847. case LPFC_SOL_IOCB:
  2848. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2849. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2850. spin_lock_irqsave(&phba->hbalock, iflag);
  2851. break;
  2852. case LPFC_UNSOL_IOCB:
  2853. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2854. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2855. spin_lock_irqsave(&phba->hbalock, iflag);
  2856. if (!rc)
  2857. free_saveq = 0;
  2858. break;
  2859. case LPFC_ABORT_IOCB:
  2860. cmdiocbp = NULL;
  2861. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2862. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2863. saveq);
  2864. if (cmdiocbp) {
  2865. /* Call the specified completion routine */
  2866. if (cmdiocbp->iocb_cmpl) {
  2867. spin_unlock_irqrestore(&phba->hbalock,
  2868. iflag);
  2869. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2870. saveq);
  2871. spin_lock_irqsave(&phba->hbalock,
  2872. iflag);
  2873. } else
  2874. __lpfc_sli_release_iocbq(phba,
  2875. cmdiocbp);
  2876. }
  2877. break;
  2878. case LPFC_UNKNOWN_IOCB:
  2879. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2880. char adaptermsg[LPFC_MAX_ADPTMSG];
  2881. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2882. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2883. MAX_MSG_DATA);
  2884. dev_warn(&((phba->pcidev)->dev),
  2885. "lpfc%d: %s\n",
  2886. phba->brd_no, adaptermsg);
  2887. } else {
  2888. /* Unknown IOCB command */
  2889. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2890. "0335 Unknown IOCB "
  2891. "command Data: x%x "
  2892. "x%x x%x x%x\n",
  2893. irsp->ulpCommand,
  2894. irsp->ulpStatus,
  2895. irsp->ulpIoTag,
  2896. irsp->ulpContext);
  2897. }
  2898. break;
  2899. }
  2900. if (free_saveq) {
  2901. list_for_each_entry_safe(rspiocbp, next_iocb,
  2902. &saveq->list, list) {
  2903. list_del(&rspiocbp->list);
  2904. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2905. }
  2906. __lpfc_sli_release_iocbq(phba, saveq);
  2907. }
  2908. rspiocbp = NULL;
  2909. }
  2910. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2911. return rspiocbp;
  2912. }
  2913. /**
  2914. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2915. * @phba: Pointer to HBA context object.
  2916. * @pring: Pointer to driver SLI ring object.
  2917. * @mask: Host attention register mask for this ring.
  2918. *
  2919. * This routine wraps the actual slow_ring event process routine from the
  2920. * API jump table function pointer from the lpfc_hba struct.
  2921. **/
  2922. void
  2923. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2924. struct lpfc_sli_ring *pring, uint32_t mask)
  2925. {
  2926. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2927. }
  2928. /**
  2929. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2930. * @phba: Pointer to HBA context object.
  2931. * @pring: Pointer to driver SLI ring object.
  2932. * @mask: Host attention register mask for this ring.
  2933. *
  2934. * This function is called from the worker thread when there is a ring event
  2935. * for non-fcp rings. The caller does not hold any lock. The function will
  2936. * remove each response iocb in the response ring and calls the handle
  2937. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2938. **/
  2939. static void
  2940. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2941. struct lpfc_sli_ring *pring, uint32_t mask)
  2942. {
  2943. struct lpfc_pgp *pgp;
  2944. IOCB_t *entry;
  2945. IOCB_t *irsp = NULL;
  2946. struct lpfc_iocbq *rspiocbp = NULL;
  2947. uint32_t portRspPut, portRspMax;
  2948. unsigned long iflag;
  2949. uint32_t status;
  2950. pgp = &phba->port_gp[pring->ringno];
  2951. spin_lock_irqsave(&phba->hbalock, iflag);
  2952. pring->stats.iocb_event++;
  2953. /*
  2954. * The next available response entry should never exceed the maximum
  2955. * entries. If it does, treat it as an adapter hardware error.
  2956. */
  2957. portRspMax = pring->numRiocb;
  2958. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2959. if (portRspPut >= portRspMax) {
  2960. /*
  2961. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2962. * rsp ring <portRspMax>
  2963. */
  2964. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2965. "0303 Ring %d handler: portRspPut %d "
  2966. "is bigger than rsp ring %d\n",
  2967. pring->ringno, portRspPut, portRspMax);
  2968. phba->link_state = LPFC_HBA_ERROR;
  2969. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2970. phba->work_hs = HS_FFER3;
  2971. lpfc_handle_eratt(phba);
  2972. return;
  2973. }
  2974. rmb();
  2975. while (pring->rspidx != portRspPut) {
  2976. /*
  2977. * Build a completion list and call the appropriate handler.
  2978. * The process is to get the next available response iocb, get
  2979. * a free iocb from the list, copy the response data into the
  2980. * free iocb, insert to the continuation list, and update the
  2981. * next response index to slim. This process makes response
  2982. * iocb's in the ring available to DMA as fast as possible but
  2983. * pays a penalty for a copy operation. Since the iocb is
  2984. * only 32 bytes, this penalty is considered small relative to
  2985. * the PCI reads for register values and a slim write. When
  2986. * the ulpLe field is set, the entire Command has been
  2987. * received.
  2988. */
  2989. entry = lpfc_resp_iocb(phba, pring);
  2990. phba->last_completion_time = jiffies;
  2991. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2992. if (rspiocbp == NULL) {
  2993. printk(KERN_ERR "%s: out of buffers! Failing "
  2994. "completion.\n", __func__);
  2995. break;
  2996. }
  2997. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2998. phba->iocb_rsp_size);
  2999. irsp = &rspiocbp->iocb;
  3000. if (++pring->rspidx >= portRspMax)
  3001. pring->rspidx = 0;
  3002. if (pring->ringno == LPFC_ELS_RING) {
  3003. lpfc_debugfs_slow_ring_trc(phba,
  3004. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3005. *(((uint32_t *) irsp) + 4),
  3006. *(((uint32_t *) irsp) + 6),
  3007. *(((uint32_t *) irsp) + 7));
  3008. }
  3009. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3010. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3011. /* Handle the response IOCB */
  3012. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3013. spin_lock_irqsave(&phba->hbalock, iflag);
  3014. /*
  3015. * If the port response put pointer has not been updated, sync
  3016. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3017. * response put pointer.
  3018. */
  3019. if (pring->rspidx == portRspPut) {
  3020. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3021. }
  3022. } /* while (pring->rspidx != portRspPut) */
  3023. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3024. /* At least one response entry has been freed */
  3025. pring->stats.iocb_rsp_full++;
  3026. /* SET RxRE_RSP in Chip Att register */
  3027. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3028. writel(status, phba->CAregaddr);
  3029. readl(phba->CAregaddr); /* flush */
  3030. }
  3031. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3032. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3033. pring->stats.iocb_cmd_empty++;
  3034. /* Force update of the local copy of cmdGetInx */
  3035. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3036. lpfc_sli_resume_iocb(phba, pring);
  3037. if ((pring->lpfc_sli_cmd_available))
  3038. (pring->lpfc_sli_cmd_available) (phba, pring);
  3039. }
  3040. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3041. return;
  3042. }
  3043. /**
  3044. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3045. * @phba: Pointer to HBA context object.
  3046. * @pring: Pointer to driver SLI ring object.
  3047. * @mask: Host attention register mask for this ring.
  3048. *
  3049. * This function is called from the worker thread when there is a pending
  3050. * ELS response iocb on the driver internal slow-path response iocb worker
  3051. * queue. The caller does not hold any lock. The function will remove each
  3052. * response iocb from the response worker queue and calls the handle
  3053. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3054. **/
  3055. static void
  3056. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3057. struct lpfc_sli_ring *pring, uint32_t mask)
  3058. {
  3059. struct lpfc_iocbq *irspiocbq;
  3060. struct hbq_dmabuf *dmabuf;
  3061. struct lpfc_cq_event *cq_event;
  3062. unsigned long iflag;
  3063. spin_lock_irqsave(&phba->hbalock, iflag);
  3064. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3065. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3066. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3067. /* Get the response iocb from the head of work queue */
  3068. spin_lock_irqsave(&phba->hbalock, iflag);
  3069. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3070. cq_event, struct lpfc_cq_event, list);
  3071. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3072. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3073. case CQE_CODE_COMPL_WQE:
  3074. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3075. cq_event);
  3076. /* Translate ELS WCQE to response IOCBQ */
  3077. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3078. irspiocbq);
  3079. if (irspiocbq)
  3080. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3081. irspiocbq);
  3082. break;
  3083. case CQE_CODE_RECEIVE:
  3084. case CQE_CODE_RECEIVE_V1:
  3085. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3086. cq_event);
  3087. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3088. break;
  3089. default:
  3090. break;
  3091. }
  3092. }
  3093. }
  3094. /**
  3095. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3096. * @phba: Pointer to HBA context object.
  3097. * @pring: Pointer to driver SLI ring object.
  3098. *
  3099. * This function aborts all iocbs in the given ring and frees all the iocb
  3100. * objects in txq. This function issues an abort iocb for all the iocb commands
  3101. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3102. * the return of this function. The caller is not required to hold any locks.
  3103. **/
  3104. void
  3105. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3106. {
  3107. LIST_HEAD(completions);
  3108. struct lpfc_iocbq *iocb, *next_iocb;
  3109. if (pring->ringno == LPFC_ELS_RING) {
  3110. lpfc_fabric_abort_hba(phba);
  3111. }
  3112. /* Error everything on txq and txcmplq
  3113. * First do the txq.
  3114. */
  3115. spin_lock_irq(&phba->hbalock);
  3116. list_splice_init(&pring->txq, &completions);
  3117. pring->txq_cnt = 0;
  3118. /* Next issue ABTS for everything on the txcmplq */
  3119. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3120. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3121. spin_unlock_irq(&phba->hbalock);
  3122. /* Cancel all the IOCBs from the completions list */
  3123. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3124. IOERR_SLI_ABORTED);
  3125. }
  3126. /**
  3127. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3128. * @phba: Pointer to HBA context object.
  3129. *
  3130. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3131. * objects in txq and txcmplq. This function will not issue abort iocbs
  3132. * for all the iocb commands in txcmplq, they will just be returned with
  3133. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3134. * slot has been permanently disabled.
  3135. **/
  3136. void
  3137. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3138. {
  3139. LIST_HEAD(txq);
  3140. LIST_HEAD(txcmplq);
  3141. struct lpfc_sli *psli = &phba->sli;
  3142. struct lpfc_sli_ring *pring;
  3143. /* Currently, only one fcp ring */
  3144. pring = &psli->ring[psli->fcp_ring];
  3145. spin_lock_irq(&phba->hbalock);
  3146. /* Retrieve everything on txq */
  3147. list_splice_init(&pring->txq, &txq);
  3148. pring->txq_cnt = 0;
  3149. /* Retrieve everything on the txcmplq */
  3150. list_splice_init(&pring->txcmplq, &txcmplq);
  3151. pring->txcmplq_cnt = 0;
  3152. spin_unlock_irq(&phba->hbalock);
  3153. /* Flush the txq */
  3154. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3155. IOERR_SLI_DOWN);
  3156. /* Flush the txcmpq */
  3157. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3158. IOERR_SLI_DOWN);
  3159. }
  3160. /**
  3161. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3162. * @phba: Pointer to HBA context object.
  3163. * @mask: Bit mask to be checked.
  3164. *
  3165. * This function reads the host status register and compares
  3166. * with the provided bit mask to check if HBA completed
  3167. * the restart. This function will wait in a loop for the
  3168. * HBA to complete restart. If the HBA does not restart within
  3169. * 15 iterations, the function will reset the HBA again. The
  3170. * function returns 1 when HBA fail to restart otherwise returns
  3171. * zero.
  3172. **/
  3173. static int
  3174. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3175. {
  3176. uint32_t status;
  3177. int i = 0;
  3178. int retval = 0;
  3179. /* Read the HBA Host Status Register */
  3180. if (lpfc_readl(phba->HSregaddr, &status))
  3181. return 1;
  3182. /*
  3183. * Check status register every 100ms for 5 retries, then every
  3184. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3185. * every 2.5 sec for 4.
  3186. * Break our of the loop if errors occurred during init.
  3187. */
  3188. while (((status & mask) != mask) &&
  3189. !(status & HS_FFERM) &&
  3190. i++ < 20) {
  3191. if (i <= 5)
  3192. msleep(10);
  3193. else if (i <= 10)
  3194. msleep(500);
  3195. else
  3196. msleep(2500);
  3197. if (i == 15) {
  3198. /* Do post */
  3199. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3200. lpfc_sli_brdrestart(phba);
  3201. }
  3202. /* Read the HBA Host Status Register */
  3203. if (lpfc_readl(phba->HSregaddr, &status)) {
  3204. retval = 1;
  3205. break;
  3206. }
  3207. }
  3208. /* Check to see if any errors occurred during init */
  3209. if ((status & HS_FFERM) || (i >= 20)) {
  3210. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3211. "2751 Adapter failed to restart, "
  3212. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3213. status,
  3214. readl(phba->MBslimaddr + 0xa8),
  3215. readl(phba->MBslimaddr + 0xac));
  3216. phba->link_state = LPFC_HBA_ERROR;
  3217. retval = 1;
  3218. }
  3219. return retval;
  3220. }
  3221. /**
  3222. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3223. * @phba: Pointer to HBA context object.
  3224. * @mask: Bit mask to be checked.
  3225. *
  3226. * This function checks the host status register to check if HBA is
  3227. * ready. This function will wait in a loop for the HBA to be ready
  3228. * If the HBA is not ready , the function will will reset the HBA PCI
  3229. * function again. The function returns 1 when HBA fail to be ready
  3230. * otherwise returns zero.
  3231. **/
  3232. static int
  3233. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3234. {
  3235. uint32_t status;
  3236. int retval = 0;
  3237. /* Read the HBA Host Status Register */
  3238. status = lpfc_sli4_post_status_check(phba);
  3239. if (status) {
  3240. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3241. lpfc_sli_brdrestart(phba);
  3242. status = lpfc_sli4_post_status_check(phba);
  3243. }
  3244. /* Check to see if any errors occurred during init */
  3245. if (status) {
  3246. phba->link_state = LPFC_HBA_ERROR;
  3247. retval = 1;
  3248. } else
  3249. phba->sli4_hba.intr_enable = 0;
  3250. return retval;
  3251. }
  3252. /**
  3253. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3254. * @phba: Pointer to HBA context object.
  3255. * @mask: Bit mask to be checked.
  3256. *
  3257. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3258. * from the API jump table function pointer from the lpfc_hba struct.
  3259. **/
  3260. int
  3261. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3262. {
  3263. return phba->lpfc_sli_brdready(phba, mask);
  3264. }
  3265. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3266. /**
  3267. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3268. * @phba: Pointer to HBA context object.
  3269. *
  3270. * This function is called before resetting an HBA. This
  3271. * function requests HBA to quiesce DMAs before a reset.
  3272. **/
  3273. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3274. {
  3275. uint32_t __iomem *resp_buf;
  3276. uint32_t __iomem *mbox_buf;
  3277. volatile uint32_t mbox;
  3278. uint32_t hc_copy, ha_copy, resp_data;
  3279. int i;
  3280. uint8_t hdrtype;
  3281. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3282. if (hdrtype != 0x80 ||
  3283. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3284. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3285. return;
  3286. /*
  3287. * Tell the other part of the chip to suspend temporarily all
  3288. * its DMA activity.
  3289. */
  3290. resp_buf = phba->MBslimaddr;
  3291. /* Disable the error attention */
  3292. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3293. return;
  3294. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3295. readl(phba->HCregaddr); /* flush */
  3296. phba->link_flag |= LS_IGNORE_ERATT;
  3297. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3298. return;
  3299. if (ha_copy & HA_ERATT) {
  3300. /* Clear Chip error bit */
  3301. writel(HA_ERATT, phba->HAregaddr);
  3302. phba->pport->stopped = 1;
  3303. }
  3304. mbox = 0;
  3305. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3306. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3307. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3308. mbox_buf = phba->MBslimaddr;
  3309. writel(mbox, mbox_buf);
  3310. for (i = 0; i < 50; i++) {
  3311. if (lpfc_readl((resp_buf + 1), &resp_data))
  3312. return;
  3313. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3314. mdelay(1);
  3315. else
  3316. break;
  3317. }
  3318. resp_data = 0;
  3319. if (lpfc_readl((resp_buf + 1), &resp_data))
  3320. return;
  3321. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3322. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3323. phba->pport->stopped)
  3324. goto restore_hc;
  3325. else
  3326. goto clear_errat;
  3327. }
  3328. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3329. resp_data = 0;
  3330. for (i = 0; i < 500; i++) {
  3331. if (lpfc_readl(resp_buf, &resp_data))
  3332. return;
  3333. if (resp_data != mbox)
  3334. mdelay(1);
  3335. else
  3336. break;
  3337. }
  3338. clear_errat:
  3339. while (++i < 500) {
  3340. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3341. return;
  3342. if (!(ha_copy & HA_ERATT))
  3343. mdelay(1);
  3344. else
  3345. break;
  3346. }
  3347. if (readl(phba->HAregaddr) & HA_ERATT) {
  3348. writel(HA_ERATT, phba->HAregaddr);
  3349. phba->pport->stopped = 1;
  3350. }
  3351. restore_hc:
  3352. phba->link_flag &= ~LS_IGNORE_ERATT;
  3353. writel(hc_copy, phba->HCregaddr);
  3354. readl(phba->HCregaddr); /* flush */
  3355. }
  3356. /**
  3357. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3358. * @phba: Pointer to HBA context object.
  3359. *
  3360. * This function issues a kill_board mailbox command and waits for
  3361. * the error attention interrupt. This function is called for stopping
  3362. * the firmware processing. The caller is not required to hold any
  3363. * locks. This function calls lpfc_hba_down_post function to free
  3364. * any pending commands after the kill. The function will return 1 when it
  3365. * fails to kill the board else will return 0.
  3366. **/
  3367. int
  3368. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3369. {
  3370. struct lpfc_sli *psli;
  3371. LPFC_MBOXQ_t *pmb;
  3372. uint32_t status;
  3373. uint32_t ha_copy;
  3374. int retval;
  3375. int i = 0;
  3376. psli = &phba->sli;
  3377. /* Kill HBA */
  3378. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3379. "0329 Kill HBA Data: x%x x%x\n",
  3380. phba->pport->port_state, psli->sli_flag);
  3381. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3382. if (!pmb)
  3383. return 1;
  3384. /* Disable the error attention */
  3385. spin_lock_irq(&phba->hbalock);
  3386. if (lpfc_readl(phba->HCregaddr, &status)) {
  3387. spin_unlock_irq(&phba->hbalock);
  3388. mempool_free(pmb, phba->mbox_mem_pool);
  3389. return 1;
  3390. }
  3391. status &= ~HC_ERINT_ENA;
  3392. writel(status, phba->HCregaddr);
  3393. readl(phba->HCregaddr); /* flush */
  3394. phba->link_flag |= LS_IGNORE_ERATT;
  3395. spin_unlock_irq(&phba->hbalock);
  3396. lpfc_kill_board(phba, pmb);
  3397. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3398. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3399. if (retval != MBX_SUCCESS) {
  3400. if (retval != MBX_BUSY)
  3401. mempool_free(pmb, phba->mbox_mem_pool);
  3402. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3403. "2752 KILL_BOARD command failed retval %d\n",
  3404. retval);
  3405. spin_lock_irq(&phba->hbalock);
  3406. phba->link_flag &= ~LS_IGNORE_ERATT;
  3407. spin_unlock_irq(&phba->hbalock);
  3408. return 1;
  3409. }
  3410. spin_lock_irq(&phba->hbalock);
  3411. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3412. spin_unlock_irq(&phba->hbalock);
  3413. mempool_free(pmb, phba->mbox_mem_pool);
  3414. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3415. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3416. * 3 seconds we still set HBA_ERROR state because the status of the
  3417. * board is now undefined.
  3418. */
  3419. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3420. return 1;
  3421. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3422. mdelay(100);
  3423. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3424. return 1;
  3425. }
  3426. del_timer_sync(&psli->mbox_tmo);
  3427. if (ha_copy & HA_ERATT) {
  3428. writel(HA_ERATT, phba->HAregaddr);
  3429. phba->pport->stopped = 1;
  3430. }
  3431. spin_lock_irq(&phba->hbalock);
  3432. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3433. psli->mbox_active = NULL;
  3434. phba->link_flag &= ~LS_IGNORE_ERATT;
  3435. spin_unlock_irq(&phba->hbalock);
  3436. lpfc_hba_down_post(phba);
  3437. phba->link_state = LPFC_HBA_ERROR;
  3438. return ha_copy & HA_ERATT ? 0 : 1;
  3439. }
  3440. /**
  3441. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3442. * @phba: Pointer to HBA context object.
  3443. *
  3444. * This function resets the HBA by writing HC_INITFF to the control
  3445. * register. After the HBA resets, this function resets all the iocb ring
  3446. * indices. This function disables PCI layer parity checking during
  3447. * the reset.
  3448. * This function returns 0 always.
  3449. * The caller is not required to hold any locks.
  3450. **/
  3451. int
  3452. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3453. {
  3454. struct lpfc_sli *psli;
  3455. struct lpfc_sli_ring *pring;
  3456. uint16_t cfg_value;
  3457. int i;
  3458. psli = &phba->sli;
  3459. /* Reset HBA */
  3460. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3461. "0325 Reset HBA Data: x%x x%x\n",
  3462. phba->pport->port_state, psli->sli_flag);
  3463. /* perform board reset */
  3464. phba->fc_eventTag = 0;
  3465. phba->link_events = 0;
  3466. phba->pport->fc_myDID = 0;
  3467. phba->pport->fc_prevDID = 0;
  3468. /* Turn off parity checking and serr during the physical reset */
  3469. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3470. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3471. (cfg_value &
  3472. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3473. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3474. /* Now toggle INITFF bit in the Host Control Register */
  3475. writel(HC_INITFF, phba->HCregaddr);
  3476. mdelay(1);
  3477. readl(phba->HCregaddr); /* flush */
  3478. writel(0, phba->HCregaddr);
  3479. readl(phba->HCregaddr); /* flush */
  3480. /* Restore PCI cmd register */
  3481. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3482. /* Initialize relevant SLI info */
  3483. for (i = 0; i < psli->num_rings; i++) {
  3484. pring = &psli->ring[i];
  3485. pring->flag = 0;
  3486. pring->rspidx = 0;
  3487. pring->next_cmdidx = 0;
  3488. pring->local_getidx = 0;
  3489. pring->cmdidx = 0;
  3490. pring->missbufcnt = 0;
  3491. }
  3492. phba->link_state = LPFC_WARM_START;
  3493. return 0;
  3494. }
  3495. /**
  3496. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3497. * @phba: Pointer to HBA context object.
  3498. *
  3499. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3500. * checking during resets the device. The caller is not required to hold
  3501. * any locks.
  3502. *
  3503. * This function returns 0 always.
  3504. **/
  3505. int
  3506. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3507. {
  3508. struct lpfc_sli *psli = &phba->sli;
  3509. uint16_t cfg_value;
  3510. uint8_t qindx;
  3511. /* Reset HBA */
  3512. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3513. "0295 Reset HBA Data: x%x x%x\n",
  3514. phba->pport->port_state, psli->sli_flag);
  3515. /* perform board reset */
  3516. phba->fc_eventTag = 0;
  3517. phba->link_events = 0;
  3518. phba->pport->fc_myDID = 0;
  3519. phba->pport->fc_prevDID = 0;
  3520. spin_lock_irq(&phba->hbalock);
  3521. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3522. phba->fcf.fcf_flag = 0;
  3523. /* Clean up the child queue list for the CQs */
  3524. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3525. list_del_init(&phba->sli4_hba.els_wq->list);
  3526. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3527. list_del_init(&phba->sli4_hba.dat_rq->list);
  3528. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3529. list_del_init(&phba->sli4_hba.els_cq->list);
  3530. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3531. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3532. qindx = 0;
  3533. do
  3534. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3535. while (++qindx < phba->cfg_fcp_eq_count);
  3536. spin_unlock_irq(&phba->hbalock);
  3537. /* Now physically reset the device */
  3538. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3539. "0389 Performing PCI function reset!\n");
  3540. /* Turn off parity checking and serr during the physical reset */
  3541. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3542. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3543. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3544. /* Perform FCoE PCI function reset */
  3545. lpfc_pci_function_reset(phba);
  3546. /* Restore PCI cmd register */
  3547. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3548. return 0;
  3549. }
  3550. /**
  3551. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3552. * @phba: Pointer to HBA context object.
  3553. *
  3554. * This function is called in the SLI initialization code path to
  3555. * restart the HBA. The caller is not required to hold any lock.
  3556. * This function writes MBX_RESTART mailbox command to the SLIM and
  3557. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3558. * function to free any pending commands. The function enables
  3559. * POST only during the first initialization. The function returns zero.
  3560. * The function does not guarantee completion of MBX_RESTART mailbox
  3561. * command before the return of this function.
  3562. **/
  3563. static int
  3564. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3565. {
  3566. MAILBOX_t *mb;
  3567. struct lpfc_sli *psli;
  3568. volatile uint32_t word0;
  3569. void __iomem *to_slim;
  3570. uint32_t hba_aer_enabled;
  3571. spin_lock_irq(&phba->hbalock);
  3572. /* Take PCIe device Advanced Error Reporting (AER) state */
  3573. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3574. psli = &phba->sli;
  3575. /* Restart HBA */
  3576. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3577. "0337 Restart HBA Data: x%x x%x\n",
  3578. phba->pport->port_state, psli->sli_flag);
  3579. word0 = 0;
  3580. mb = (MAILBOX_t *) &word0;
  3581. mb->mbxCommand = MBX_RESTART;
  3582. mb->mbxHc = 1;
  3583. lpfc_reset_barrier(phba);
  3584. to_slim = phba->MBslimaddr;
  3585. writel(*(uint32_t *) mb, to_slim);
  3586. readl(to_slim); /* flush */
  3587. /* Only skip post after fc_ffinit is completed */
  3588. if (phba->pport->port_state)
  3589. word0 = 1; /* This is really setting up word1 */
  3590. else
  3591. word0 = 0; /* This is really setting up word1 */
  3592. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3593. writel(*(uint32_t *) mb, to_slim);
  3594. readl(to_slim); /* flush */
  3595. lpfc_sli_brdreset(phba);
  3596. phba->pport->stopped = 0;
  3597. phba->link_state = LPFC_INIT_START;
  3598. phba->hba_flag = 0;
  3599. spin_unlock_irq(&phba->hbalock);
  3600. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3601. psli->stats_start = get_seconds();
  3602. /* Give the INITFF and Post time to settle. */
  3603. mdelay(100);
  3604. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3605. if (hba_aer_enabled)
  3606. pci_disable_pcie_error_reporting(phba->pcidev);
  3607. lpfc_hba_down_post(phba);
  3608. return 0;
  3609. }
  3610. /**
  3611. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3612. * @phba: Pointer to HBA context object.
  3613. *
  3614. * This function is called in the SLI initialization code path to restart
  3615. * a SLI4 HBA. The caller is not required to hold any lock.
  3616. * At the end of the function, it calls lpfc_hba_down_post function to
  3617. * free any pending commands.
  3618. **/
  3619. static int
  3620. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3621. {
  3622. struct lpfc_sli *psli = &phba->sli;
  3623. uint32_t hba_aer_enabled;
  3624. /* Restart HBA */
  3625. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3626. "0296 Restart HBA Data: x%x x%x\n",
  3627. phba->pport->port_state, psli->sli_flag);
  3628. /* Take PCIe device Advanced Error Reporting (AER) state */
  3629. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3630. lpfc_sli4_brdreset(phba);
  3631. spin_lock_irq(&phba->hbalock);
  3632. phba->pport->stopped = 0;
  3633. phba->link_state = LPFC_INIT_START;
  3634. phba->hba_flag = 0;
  3635. spin_unlock_irq(&phba->hbalock);
  3636. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3637. psli->stats_start = get_seconds();
  3638. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3639. if (hba_aer_enabled)
  3640. pci_disable_pcie_error_reporting(phba->pcidev);
  3641. lpfc_hba_down_post(phba);
  3642. return 0;
  3643. }
  3644. /**
  3645. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3646. * @phba: Pointer to HBA context object.
  3647. *
  3648. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3649. * API jump table function pointer from the lpfc_hba struct.
  3650. **/
  3651. int
  3652. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3653. {
  3654. return phba->lpfc_sli_brdrestart(phba);
  3655. }
  3656. /**
  3657. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3658. * @phba: Pointer to HBA context object.
  3659. *
  3660. * This function is called after a HBA restart to wait for successful
  3661. * restart of the HBA. Successful restart of the HBA is indicated by
  3662. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3663. * iteration, the function will restart the HBA again. The function returns
  3664. * zero if HBA successfully restarted else returns negative error code.
  3665. **/
  3666. static int
  3667. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3668. {
  3669. uint32_t status, i = 0;
  3670. /* Read the HBA Host Status Register */
  3671. if (lpfc_readl(phba->HSregaddr, &status))
  3672. return -EIO;
  3673. /* Check status register to see what current state is */
  3674. i = 0;
  3675. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3676. /* Check every 10ms for 10 retries, then every 100ms for 90
  3677. * retries, then every 1 sec for 50 retires for a total of
  3678. * ~60 seconds before reset the board again and check every
  3679. * 1 sec for 50 retries. The up to 60 seconds before the
  3680. * board ready is required by the Falcon FIPS zeroization
  3681. * complete, and any reset the board in between shall cause
  3682. * restart of zeroization, further delay the board ready.
  3683. */
  3684. if (i++ >= 200) {
  3685. /* Adapter failed to init, timeout, status reg
  3686. <status> */
  3687. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3688. "0436 Adapter failed to init, "
  3689. "timeout, status reg x%x, "
  3690. "FW Data: A8 x%x AC x%x\n", status,
  3691. readl(phba->MBslimaddr + 0xa8),
  3692. readl(phba->MBslimaddr + 0xac));
  3693. phba->link_state = LPFC_HBA_ERROR;
  3694. return -ETIMEDOUT;
  3695. }
  3696. /* Check to see if any errors occurred during init */
  3697. if (status & HS_FFERM) {
  3698. /* ERROR: During chipset initialization */
  3699. /* Adapter failed to init, chipset, status reg
  3700. <status> */
  3701. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3702. "0437 Adapter failed to init, "
  3703. "chipset, status reg x%x, "
  3704. "FW Data: A8 x%x AC x%x\n", status,
  3705. readl(phba->MBslimaddr + 0xa8),
  3706. readl(phba->MBslimaddr + 0xac));
  3707. phba->link_state = LPFC_HBA_ERROR;
  3708. return -EIO;
  3709. }
  3710. if (i <= 10)
  3711. msleep(10);
  3712. else if (i <= 100)
  3713. msleep(100);
  3714. else
  3715. msleep(1000);
  3716. if (i == 150) {
  3717. /* Do post */
  3718. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3719. lpfc_sli_brdrestart(phba);
  3720. }
  3721. /* Read the HBA Host Status Register */
  3722. if (lpfc_readl(phba->HSregaddr, &status))
  3723. return -EIO;
  3724. }
  3725. /* Check to see if any errors occurred during init */
  3726. if (status & HS_FFERM) {
  3727. /* ERROR: During chipset initialization */
  3728. /* Adapter failed to init, chipset, status reg <status> */
  3729. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3730. "0438 Adapter failed to init, chipset, "
  3731. "status reg x%x, "
  3732. "FW Data: A8 x%x AC x%x\n", status,
  3733. readl(phba->MBslimaddr + 0xa8),
  3734. readl(phba->MBslimaddr + 0xac));
  3735. phba->link_state = LPFC_HBA_ERROR;
  3736. return -EIO;
  3737. }
  3738. /* Clear all interrupt enable conditions */
  3739. writel(0, phba->HCregaddr);
  3740. readl(phba->HCregaddr); /* flush */
  3741. /* setup host attn register */
  3742. writel(0xffffffff, phba->HAregaddr);
  3743. readl(phba->HAregaddr); /* flush */
  3744. return 0;
  3745. }
  3746. /**
  3747. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3748. *
  3749. * This function calculates and returns the number of HBQs required to be
  3750. * configured.
  3751. **/
  3752. int
  3753. lpfc_sli_hbq_count(void)
  3754. {
  3755. return ARRAY_SIZE(lpfc_hbq_defs);
  3756. }
  3757. /**
  3758. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3759. *
  3760. * This function adds the number of hbq entries in every HBQ to get
  3761. * the total number of hbq entries required for the HBA and returns
  3762. * the total count.
  3763. **/
  3764. static int
  3765. lpfc_sli_hbq_entry_count(void)
  3766. {
  3767. int hbq_count = lpfc_sli_hbq_count();
  3768. int count = 0;
  3769. int i;
  3770. for (i = 0; i < hbq_count; ++i)
  3771. count += lpfc_hbq_defs[i]->entry_count;
  3772. return count;
  3773. }
  3774. /**
  3775. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3776. *
  3777. * This function calculates amount of memory required for all hbq entries
  3778. * to be configured and returns the total memory required.
  3779. **/
  3780. int
  3781. lpfc_sli_hbq_size(void)
  3782. {
  3783. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3784. }
  3785. /**
  3786. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3787. * @phba: Pointer to HBA context object.
  3788. *
  3789. * This function is called during the SLI initialization to configure
  3790. * all the HBQs and post buffers to the HBQ. The caller is not
  3791. * required to hold any locks. This function will return zero if successful
  3792. * else it will return negative error code.
  3793. **/
  3794. static int
  3795. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3796. {
  3797. int hbq_count = lpfc_sli_hbq_count();
  3798. LPFC_MBOXQ_t *pmb;
  3799. MAILBOX_t *pmbox;
  3800. uint32_t hbqno;
  3801. uint32_t hbq_entry_index;
  3802. /* Get a Mailbox buffer to setup mailbox
  3803. * commands for HBA initialization
  3804. */
  3805. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3806. if (!pmb)
  3807. return -ENOMEM;
  3808. pmbox = &pmb->u.mb;
  3809. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3810. phba->link_state = LPFC_INIT_MBX_CMDS;
  3811. phba->hbq_in_use = 1;
  3812. hbq_entry_index = 0;
  3813. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3814. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3815. phba->hbqs[hbqno].hbqPutIdx = 0;
  3816. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3817. phba->hbqs[hbqno].entry_count =
  3818. lpfc_hbq_defs[hbqno]->entry_count;
  3819. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3820. hbq_entry_index, pmb);
  3821. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3822. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3823. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3824. mbxStatus <status>, ring <num> */
  3825. lpfc_printf_log(phba, KERN_ERR,
  3826. LOG_SLI | LOG_VPORT,
  3827. "1805 Adapter failed to init. "
  3828. "Data: x%x x%x x%x\n",
  3829. pmbox->mbxCommand,
  3830. pmbox->mbxStatus, hbqno);
  3831. phba->link_state = LPFC_HBA_ERROR;
  3832. mempool_free(pmb, phba->mbox_mem_pool);
  3833. return -ENXIO;
  3834. }
  3835. }
  3836. phba->hbq_count = hbq_count;
  3837. mempool_free(pmb, phba->mbox_mem_pool);
  3838. /* Initially populate or replenish the HBQs */
  3839. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3840. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3841. return 0;
  3842. }
  3843. /**
  3844. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3845. * @phba: Pointer to HBA context object.
  3846. *
  3847. * This function is called during the SLI initialization to configure
  3848. * all the HBQs and post buffers to the HBQ. The caller is not
  3849. * required to hold any locks. This function will return zero if successful
  3850. * else it will return negative error code.
  3851. **/
  3852. static int
  3853. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3854. {
  3855. phba->hbq_in_use = 1;
  3856. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3857. phba->hbq_count = 1;
  3858. /* Initially populate or replenish the HBQs */
  3859. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3860. return 0;
  3861. }
  3862. /**
  3863. * lpfc_sli_config_port - Issue config port mailbox command
  3864. * @phba: Pointer to HBA context object.
  3865. * @sli_mode: sli mode - 2/3
  3866. *
  3867. * This function is called by the sli intialization code path
  3868. * to issue config_port mailbox command. This function restarts the
  3869. * HBA firmware and issues a config_port mailbox command to configure
  3870. * the SLI interface in the sli mode specified by sli_mode
  3871. * variable. The caller is not required to hold any locks.
  3872. * The function returns 0 if successful, else returns negative error
  3873. * code.
  3874. **/
  3875. int
  3876. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3877. {
  3878. LPFC_MBOXQ_t *pmb;
  3879. uint32_t resetcount = 0, rc = 0, done = 0;
  3880. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3881. if (!pmb) {
  3882. phba->link_state = LPFC_HBA_ERROR;
  3883. return -ENOMEM;
  3884. }
  3885. phba->sli_rev = sli_mode;
  3886. while (resetcount < 2 && !done) {
  3887. spin_lock_irq(&phba->hbalock);
  3888. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3889. spin_unlock_irq(&phba->hbalock);
  3890. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3891. lpfc_sli_brdrestart(phba);
  3892. rc = lpfc_sli_chipset_init(phba);
  3893. if (rc)
  3894. break;
  3895. spin_lock_irq(&phba->hbalock);
  3896. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3897. spin_unlock_irq(&phba->hbalock);
  3898. resetcount++;
  3899. /* Call pre CONFIG_PORT mailbox command initialization. A
  3900. * value of 0 means the call was successful. Any other
  3901. * nonzero value is a failure, but if ERESTART is returned,
  3902. * the driver may reset the HBA and try again.
  3903. */
  3904. rc = lpfc_config_port_prep(phba);
  3905. if (rc == -ERESTART) {
  3906. phba->link_state = LPFC_LINK_UNKNOWN;
  3907. continue;
  3908. } else if (rc)
  3909. break;
  3910. phba->link_state = LPFC_INIT_MBX_CMDS;
  3911. lpfc_config_port(phba, pmb);
  3912. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3913. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3914. LPFC_SLI3_HBQ_ENABLED |
  3915. LPFC_SLI3_CRP_ENABLED |
  3916. LPFC_SLI3_BG_ENABLED |
  3917. LPFC_SLI3_DSS_ENABLED);
  3918. if (rc != MBX_SUCCESS) {
  3919. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3920. "0442 Adapter failed to init, mbxCmd x%x "
  3921. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3922. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3923. spin_lock_irq(&phba->hbalock);
  3924. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3925. spin_unlock_irq(&phba->hbalock);
  3926. rc = -ENXIO;
  3927. } else {
  3928. /* Allow asynchronous mailbox command to go through */
  3929. spin_lock_irq(&phba->hbalock);
  3930. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3931. spin_unlock_irq(&phba->hbalock);
  3932. done = 1;
  3933. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  3934. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  3935. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3936. "3110 Port did not grant ASABT\n");
  3937. }
  3938. }
  3939. if (!done) {
  3940. rc = -EINVAL;
  3941. goto do_prep_failed;
  3942. }
  3943. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3944. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3945. rc = -ENXIO;
  3946. goto do_prep_failed;
  3947. }
  3948. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3949. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3950. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3951. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3952. phba->max_vpi : phba->max_vports;
  3953. } else
  3954. phba->max_vpi = 0;
  3955. phba->fips_level = 0;
  3956. phba->fips_spec_rev = 0;
  3957. if (pmb->u.mb.un.varCfgPort.gdss) {
  3958. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3959. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3960. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3961. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3962. "2850 Security Crypto Active. FIPS x%d "
  3963. "(Spec Rev: x%d)",
  3964. phba->fips_level, phba->fips_spec_rev);
  3965. }
  3966. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3967. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3968. "2856 Config Port Security Crypto "
  3969. "Error: x%x ",
  3970. pmb->u.mb.un.varCfgPort.sec_err);
  3971. }
  3972. if (pmb->u.mb.un.varCfgPort.gerbm)
  3973. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3974. if (pmb->u.mb.un.varCfgPort.gcrp)
  3975. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3976. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3977. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3978. if (phba->cfg_enable_bg) {
  3979. if (pmb->u.mb.un.varCfgPort.gbg)
  3980. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3981. else
  3982. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3983. "0443 Adapter did not grant "
  3984. "BlockGuard\n");
  3985. }
  3986. } else {
  3987. phba->hbq_get = NULL;
  3988. phba->port_gp = phba->mbox->us.s2.port;
  3989. phba->max_vpi = 0;
  3990. }
  3991. do_prep_failed:
  3992. mempool_free(pmb, phba->mbox_mem_pool);
  3993. return rc;
  3994. }
  3995. /**
  3996. * lpfc_sli_hba_setup - SLI intialization function
  3997. * @phba: Pointer to HBA context object.
  3998. *
  3999. * This function is the main SLI intialization function. This function
  4000. * is called by the HBA intialization code, HBA reset code and HBA
  4001. * error attention handler code. Caller is not required to hold any
  4002. * locks. This function issues config_port mailbox command to configure
  4003. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4004. * calls the config_port_post function to issue init_link mailbox
  4005. * command and to start the discovery. The function will return zero
  4006. * if successful, else it will return negative error code.
  4007. **/
  4008. int
  4009. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4010. {
  4011. uint32_t rc;
  4012. int mode = 3, i;
  4013. int longs;
  4014. switch (lpfc_sli_mode) {
  4015. case 2:
  4016. if (phba->cfg_enable_npiv) {
  4017. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4018. "1824 NPIV enabled: Override lpfc_sli_mode "
  4019. "parameter (%d) to auto (0).\n",
  4020. lpfc_sli_mode);
  4021. break;
  4022. }
  4023. mode = 2;
  4024. break;
  4025. case 0:
  4026. case 3:
  4027. break;
  4028. default:
  4029. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4030. "1819 Unrecognized lpfc_sli_mode "
  4031. "parameter: %d.\n", lpfc_sli_mode);
  4032. break;
  4033. }
  4034. rc = lpfc_sli_config_port(phba, mode);
  4035. if (rc && lpfc_sli_mode == 3)
  4036. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4037. "1820 Unable to select SLI-3. "
  4038. "Not supported by adapter.\n");
  4039. if (rc && mode != 2)
  4040. rc = lpfc_sli_config_port(phba, 2);
  4041. if (rc)
  4042. goto lpfc_sli_hba_setup_error;
  4043. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4044. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4045. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4046. if (!rc) {
  4047. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4048. "2709 This device supports "
  4049. "Advanced Error Reporting (AER)\n");
  4050. spin_lock_irq(&phba->hbalock);
  4051. phba->hba_flag |= HBA_AER_ENABLED;
  4052. spin_unlock_irq(&phba->hbalock);
  4053. } else {
  4054. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4055. "2708 This device does not support "
  4056. "Advanced Error Reporting (AER)\n");
  4057. phba->cfg_aer_support = 0;
  4058. }
  4059. }
  4060. if (phba->sli_rev == 3) {
  4061. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4062. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4063. } else {
  4064. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4065. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4066. phba->sli3_options = 0;
  4067. }
  4068. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4069. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4070. phba->sli_rev, phba->max_vpi);
  4071. rc = lpfc_sli_ring_map(phba);
  4072. if (rc)
  4073. goto lpfc_sli_hba_setup_error;
  4074. /* Initialize VPIs. */
  4075. if (phba->sli_rev == LPFC_SLI_REV3) {
  4076. /*
  4077. * The VPI bitmask and physical ID array are allocated
  4078. * and initialized once only - at driver load. A port
  4079. * reset doesn't need to reinitialize this memory.
  4080. */
  4081. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4082. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4083. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4084. GFP_KERNEL);
  4085. if (!phba->vpi_bmask) {
  4086. rc = -ENOMEM;
  4087. goto lpfc_sli_hba_setup_error;
  4088. }
  4089. phba->vpi_ids = kzalloc(
  4090. (phba->max_vpi+1) * sizeof(uint16_t),
  4091. GFP_KERNEL);
  4092. if (!phba->vpi_ids) {
  4093. kfree(phba->vpi_bmask);
  4094. rc = -ENOMEM;
  4095. goto lpfc_sli_hba_setup_error;
  4096. }
  4097. for (i = 0; i < phba->max_vpi; i++)
  4098. phba->vpi_ids[i] = i;
  4099. }
  4100. }
  4101. /* Init HBQs */
  4102. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4103. rc = lpfc_sli_hbq_setup(phba);
  4104. if (rc)
  4105. goto lpfc_sli_hba_setup_error;
  4106. }
  4107. spin_lock_irq(&phba->hbalock);
  4108. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4109. spin_unlock_irq(&phba->hbalock);
  4110. rc = lpfc_config_port_post(phba);
  4111. if (rc)
  4112. goto lpfc_sli_hba_setup_error;
  4113. return rc;
  4114. lpfc_sli_hba_setup_error:
  4115. phba->link_state = LPFC_HBA_ERROR;
  4116. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4117. "0445 Firmware initialization failed\n");
  4118. return rc;
  4119. }
  4120. /**
  4121. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4122. * @phba: Pointer to HBA context object.
  4123. * @mboxq: mailbox pointer.
  4124. * This function issue a dump mailbox command to read config region
  4125. * 23 and parse the records in the region and populate driver
  4126. * data structure.
  4127. **/
  4128. static int
  4129. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4130. {
  4131. LPFC_MBOXQ_t *mboxq;
  4132. struct lpfc_dmabuf *mp;
  4133. struct lpfc_mqe *mqe;
  4134. uint32_t data_length;
  4135. int rc;
  4136. /* Program the default value of vlan_id and fc_map */
  4137. phba->valid_vlan = 0;
  4138. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4139. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4140. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4141. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4142. if (!mboxq)
  4143. return -ENOMEM;
  4144. mqe = &mboxq->u.mqe;
  4145. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4146. rc = -ENOMEM;
  4147. goto out_free_mboxq;
  4148. }
  4149. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4150. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4151. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4152. "(%d):2571 Mailbox cmd x%x Status x%x "
  4153. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4154. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4155. "CQ: x%x x%x x%x x%x\n",
  4156. mboxq->vport ? mboxq->vport->vpi : 0,
  4157. bf_get(lpfc_mqe_command, mqe),
  4158. bf_get(lpfc_mqe_status, mqe),
  4159. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4160. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4161. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4162. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4163. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4164. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4165. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4166. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4167. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4168. mboxq->mcqe.word0,
  4169. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4170. mboxq->mcqe.trailer);
  4171. if (rc) {
  4172. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4173. kfree(mp);
  4174. rc = -EIO;
  4175. goto out_free_mboxq;
  4176. }
  4177. data_length = mqe->un.mb_words[5];
  4178. if (data_length > DMP_RGN23_SIZE) {
  4179. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4180. kfree(mp);
  4181. rc = -EIO;
  4182. goto out_free_mboxq;
  4183. }
  4184. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4185. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4186. kfree(mp);
  4187. rc = 0;
  4188. out_free_mboxq:
  4189. mempool_free(mboxq, phba->mbox_mem_pool);
  4190. return rc;
  4191. }
  4192. /**
  4193. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4194. * @phba: pointer to lpfc hba data structure.
  4195. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4196. * @vpd: pointer to the memory to hold resulting port vpd data.
  4197. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4198. * On output, the number of data bytes in @vpd.
  4199. *
  4200. * This routine executes a READ_REV SLI4 mailbox command. In
  4201. * addition, this routine gets the port vpd data.
  4202. *
  4203. * Return codes
  4204. * 0 - successful
  4205. * -ENOMEM - could not allocated memory.
  4206. **/
  4207. static int
  4208. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4209. uint8_t *vpd, uint32_t *vpd_size)
  4210. {
  4211. int rc = 0;
  4212. uint32_t dma_size;
  4213. struct lpfc_dmabuf *dmabuf;
  4214. struct lpfc_mqe *mqe;
  4215. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4216. if (!dmabuf)
  4217. return -ENOMEM;
  4218. /*
  4219. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4220. * mailbox command.
  4221. */
  4222. dma_size = *vpd_size;
  4223. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4224. dma_size,
  4225. &dmabuf->phys,
  4226. GFP_KERNEL);
  4227. if (!dmabuf->virt) {
  4228. kfree(dmabuf);
  4229. return -ENOMEM;
  4230. }
  4231. memset(dmabuf->virt, 0, dma_size);
  4232. /*
  4233. * The SLI4 implementation of READ_REV conflicts at word1,
  4234. * bits 31:16 and SLI4 adds vpd functionality not present
  4235. * in SLI3. This code corrects the conflicts.
  4236. */
  4237. lpfc_read_rev(phba, mboxq);
  4238. mqe = &mboxq->u.mqe;
  4239. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4240. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4241. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4242. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4243. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4244. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4245. if (rc) {
  4246. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4247. dmabuf->virt, dmabuf->phys);
  4248. kfree(dmabuf);
  4249. return -EIO;
  4250. }
  4251. /*
  4252. * The available vpd length cannot be bigger than the
  4253. * DMA buffer passed to the port. Catch the less than
  4254. * case and update the caller's size.
  4255. */
  4256. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4257. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4258. memcpy(vpd, dmabuf->virt, *vpd_size);
  4259. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4260. dmabuf->virt, dmabuf->phys);
  4261. kfree(dmabuf);
  4262. return 0;
  4263. }
  4264. /**
  4265. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4266. * @phba: pointer to lpfc hba data structure.
  4267. *
  4268. * This routine retrieves SLI4 device physical port name this PCI function
  4269. * is attached to.
  4270. *
  4271. * Return codes
  4272. * 0 - sucessful
  4273. * otherwise - failed to retrieve physical port name
  4274. **/
  4275. static int
  4276. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4277. {
  4278. LPFC_MBOXQ_t *mboxq;
  4279. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4280. struct lpfc_controller_attribute *cntl_attr;
  4281. struct lpfc_mbx_get_port_name *get_port_name;
  4282. void *virtaddr = NULL;
  4283. uint32_t alloclen, reqlen;
  4284. uint32_t shdr_status, shdr_add_status;
  4285. union lpfc_sli4_cfg_shdr *shdr;
  4286. char cport_name = 0;
  4287. int rc;
  4288. /* We assume nothing at this point */
  4289. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4290. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4291. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4292. if (!mboxq)
  4293. return -ENOMEM;
  4294. /* obtain link type and link number via READ_CONFIG */
  4295. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4296. lpfc_sli4_read_config(phba);
  4297. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4298. goto retrieve_ppname;
  4299. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4300. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4301. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4302. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4303. LPFC_SLI4_MBX_NEMBED);
  4304. if (alloclen < reqlen) {
  4305. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4306. "3084 Allocated DMA memory size (%d) is "
  4307. "less than the requested DMA memory size "
  4308. "(%d)\n", alloclen, reqlen);
  4309. rc = -ENOMEM;
  4310. goto out_free_mboxq;
  4311. }
  4312. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4313. virtaddr = mboxq->sge_array->addr[0];
  4314. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4315. shdr = &mbx_cntl_attr->cfg_shdr;
  4316. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4317. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4318. if (shdr_status || shdr_add_status || rc) {
  4319. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4320. "3085 Mailbox x%x (x%x/x%x) failed, "
  4321. "rc:x%x, status:x%x, add_status:x%x\n",
  4322. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4323. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4324. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4325. rc, shdr_status, shdr_add_status);
  4326. rc = -ENXIO;
  4327. goto out_free_mboxq;
  4328. }
  4329. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4330. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4331. phba->sli4_hba.lnk_info.lnk_tp =
  4332. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4333. phba->sli4_hba.lnk_info.lnk_no =
  4334. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4335. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4336. "3086 lnk_type:%d, lnk_numb:%d\n",
  4337. phba->sli4_hba.lnk_info.lnk_tp,
  4338. phba->sli4_hba.lnk_info.lnk_no);
  4339. retrieve_ppname:
  4340. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4341. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4342. sizeof(struct lpfc_mbx_get_port_name) -
  4343. sizeof(struct lpfc_sli4_cfg_mhdr),
  4344. LPFC_SLI4_MBX_EMBED);
  4345. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4346. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4347. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4348. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4349. phba->sli4_hba.lnk_info.lnk_tp);
  4350. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4351. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4352. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4353. if (shdr_status || shdr_add_status || rc) {
  4354. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4355. "3087 Mailbox x%x (x%x/x%x) failed: "
  4356. "rc:x%x, status:x%x, add_status:x%x\n",
  4357. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4358. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4359. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4360. rc, shdr_status, shdr_add_status);
  4361. rc = -ENXIO;
  4362. goto out_free_mboxq;
  4363. }
  4364. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4365. case LPFC_LINK_NUMBER_0:
  4366. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4367. &get_port_name->u.response);
  4368. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4369. break;
  4370. case LPFC_LINK_NUMBER_1:
  4371. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4372. &get_port_name->u.response);
  4373. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4374. break;
  4375. case LPFC_LINK_NUMBER_2:
  4376. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4377. &get_port_name->u.response);
  4378. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4379. break;
  4380. case LPFC_LINK_NUMBER_3:
  4381. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4382. &get_port_name->u.response);
  4383. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4384. break;
  4385. default:
  4386. break;
  4387. }
  4388. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4389. phba->Port[0] = cport_name;
  4390. phba->Port[1] = '\0';
  4391. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4392. "3091 SLI get port name: %s\n", phba->Port);
  4393. }
  4394. out_free_mboxq:
  4395. if (rc != MBX_TIMEOUT) {
  4396. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4397. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4398. else
  4399. mempool_free(mboxq, phba->mbox_mem_pool);
  4400. }
  4401. return rc;
  4402. }
  4403. /**
  4404. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4405. * @phba: pointer to lpfc hba data structure.
  4406. *
  4407. * This routine is called to explicitly arm the SLI4 device's completion and
  4408. * event queues
  4409. **/
  4410. static void
  4411. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4412. {
  4413. uint8_t fcp_eqidx;
  4414. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4415. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4416. fcp_eqidx = 0;
  4417. do
  4418. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4419. LPFC_QUEUE_REARM);
  4420. while (++fcp_eqidx < phba->cfg_fcp_eq_count);
  4421. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4422. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4423. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4424. LPFC_QUEUE_REARM);
  4425. }
  4426. /**
  4427. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4428. * @phba: Pointer to HBA context object.
  4429. * @type: The resource extent type.
  4430. * @extnt_count: buffer to hold port available extent count.
  4431. * @extnt_size: buffer to hold element count per extent.
  4432. *
  4433. * This function calls the port and retrievs the number of available
  4434. * extents and their size for a particular extent type.
  4435. *
  4436. * Returns: 0 if successful. Nonzero otherwise.
  4437. **/
  4438. int
  4439. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4440. uint16_t *extnt_count, uint16_t *extnt_size)
  4441. {
  4442. int rc = 0;
  4443. uint32_t length;
  4444. uint32_t mbox_tmo;
  4445. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4446. LPFC_MBOXQ_t *mbox;
  4447. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4448. if (!mbox)
  4449. return -ENOMEM;
  4450. /* Find out how many extents are available for this resource type */
  4451. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4452. sizeof(struct lpfc_sli4_cfg_mhdr));
  4453. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4454. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4455. length, LPFC_SLI4_MBX_EMBED);
  4456. /* Send an extents count of 0 - the GET doesn't use it. */
  4457. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4458. LPFC_SLI4_MBX_EMBED);
  4459. if (unlikely(rc)) {
  4460. rc = -EIO;
  4461. goto err_exit;
  4462. }
  4463. if (!phba->sli4_hba.intr_enable)
  4464. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4465. else {
  4466. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4467. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4468. }
  4469. if (unlikely(rc)) {
  4470. rc = -EIO;
  4471. goto err_exit;
  4472. }
  4473. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4474. if (bf_get(lpfc_mbox_hdr_status,
  4475. &rsrc_info->header.cfg_shdr.response)) {
  4476. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4477. "2930 Failed to get resource extents "
  4478. "Status 0x%x Add'l Status 0x%x\n",
  4479. bf_get(lpfc_mbox_hdr_status,
  4480. &rsrc_info->header.cfg_shdr.response),
  4481. bf_get(lpfc_mbox_hdr_add_status,
  4482. &rsrc_info->header.cfg_shdr.response));
  4483. rc = -EIO;
  4484. goto err_exit;
  4485. }
  4486. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4487. &rsrc_info->u.rsp);
  4488. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4489. &rsrc_info->u.rsp);
  4490. err_exit:
  4491. mempool_free(mbox, phba->mbox_mem_pool);
  4492. return rc;
  4493. }
  4494. /**
  4495. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4496. * @phba: Pointer to HBA context object.
  4497. * @type: The extent type to check.
  4498. *
  4499. * This function reads the current available extents from the port and checks
  4500. * if the extent count or extent size has changed since the last access.
  4501. * Callers use this routine post port reset to understand if there is a
  4502. * extent reprovisioning requirement.
  4503. *
  4504. * Returns:
  4505. * -Error: error indicates problem.
  4506. * 1: Extent count or size has changed.
  4507. * 0: No changes.
  4508. **/
  4509. static int
  4510. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4511. {
  4512. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4513. uint16_t size_diff, rsrc_ext_size;
  4514. int rc = 0;
  4515. struct lpfc_rsrc_blks *rsrc_entry;
  4516. struct list_head *rsrc_blk_list = NULL;
  4517. size_diff = 0;
  4518. curr_ext_cnt = 0;
  4519. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4520. &rsrc_ext_cnt,
  4521. &rsrc_ext_size);
  4522. if (unlikely(rc))
  4523. return -EIO;
  4524. switch (type) {
  4525. case LPFC_RSC_TYPE_FCOE_RPI:
  4526. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4527. break;
  4528. case LPFC_RSC_TYPE_FCOE_VPI:
  4529. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4530. break;
  4531. case LPFC_RSC_TYPE_FCOE_XRI:
  4532. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4533. break;
  4534. case LPFC_RSC_TYPE_FCOE_VFI:
  4535. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4536. break;
  4537. default:
  4538. break;
  4539. }
  4540. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4541. curr_ext_cnt++;
  4542. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4543. size_diff++;
  4544. }
  4545. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4546. rc = 1;
  4547. return rc;
  4548. }
  4549. /**
  4550. * lpfc_sli4_cfg_post_extnts -
  4551. * @phba: Pointer to HBA context object.
  4552. * @extnt_cnt - number of available extents.
  4553. * @type - the extent type (rpi, xri, vfi, vpi).
  4554. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4555. * @mbox - pointer to the caller's allocated mailbox structure.
  4556. *
  4557. * This function executes the extents allocation request. It also
  4558. * takes care of the amount of memory needed to allocate or get the
  4559. * allocated extents. It is the caller's responsibility to evaluate
  4560. * the response.
  4561. *
  4562. * Returns:
  4563. * -Error: Error value describes the condition found.
  4564. * 0: if successful
  4565. **/
  4566. static int
  4567. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t *extnt_cnt,
  4568. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4569. {
  4570. int rc = 0;
  4571. uint32_t req_len;
  4572. uint32_t emb_len;
  4573. uint32_t alloc_len, mbox_tmo;
  4574. /* Calculate the total requested length of the dma memory */
  4575. req_len = *extnt_cnt * sizeof(uint16_t);
  4576. /*
  4577. * Calculate the size of an embedded mailbox. The uint32_t
  4578. * accounts for extents-specific word.
  4579. */
  4580. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4581. sizeof(uint32_t);
  4582. /*
  4583. * Presume the allocation and response will fit into an embedded
  4584. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4585. */
  4586. *emb = LPFC_SLI4_MBX_EMBED;
  4587. if (req_len > emb_len) {
  4588. req_len = *extnt_cnt * sizeof(uint16_t) +
  4589. sizeof(union lpfc_sli4_cfg_shdr) +
  4590. sizeof(uint32_t);
  4591. *emb = LPFC_SLI4_MBX_NEMBED;
  4592. }
  4593. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4594. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4595. req_len, *emb);
  4596. if (alloc_len < req_len) {
  4597. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4598. "2982 Allocated DMA memory size (x%x) is "
  4599. "less than the requested DMA memory "
  4600. "size (x%x)\n", alloc_len, req_len);
  4601. return -ENOMEM;
  4602. }
  4603. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, *extnt_cnt, type, *emb);
  4604. if (unlikely(rc))
  4605. return -EIO;
  4606. if (!phba->sli4_hba.intr_enable)
  4607. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4608. else {
  4609. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4610. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4611. }
  4612. if (unlikely(rc))
  4613. rc = -EIO;
  4614. return rc;
  4615. }
  4616. /**
  4617. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4618. * @phba: Pointer to HBA context object.
  4619. * @type: The resource extent type to allocate.
  4620. *
  4621. * This function allocates the number of elements for the specified
  4622. * resource type.
  4623. **/
  4624. static int
  4625. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4626. {
  4627. bool emb = false;
  4628. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4629. uint16_t rsrc_id, rsrc_start, j, k;
  4630. uint16_t *ids;
  4631. int i, rc;
  4632. unsigned long longs;
  4633. unsigned long *bmask;
  4634. struct lpfc_rsrc_blks *rsrc_blks;
  4635. LPFC_MBOXQ_t *mbox;
  4636. uint32_t length;
  4637. struct lpfc_id_range *id_array = NULL;
  4638. void *virtaddr = NULL;
  4639. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4640. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4641. struct list_head *ext_blk_list;
  4642. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4643. &rsrc_cnt,
  4644. &rsrc_size);
  4645. if (unlikely(rc))
  4646. return -EIO;
  4647. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4648. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4649. "3009 No available Resource Extents "
  4650. "for resource type 0x%x: Count: 0x%x, "
  4651. "Size 0x%x\n", type, rsrc_cnt,
  4652. rsrc_size);
  4653. return -ENOMEM;
  4654. }
  4655. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT,
  4656. "2903 Available Resource Extents "
  4657. "for resource type 0x%x: Count: 0x%x, "
  4658. "Size 0x%x\n", type, rsrc_cnt,
  4659. rsrc_size);
  4660. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4661. if (!mbox)
  4662. return -ENOMEM;
  4663. rc = lpfc_sli4_cfg_post_extnts(phba, &rsrc_cnt, type, &emb, mbox);
  4664. if (unlikely(rc)) {
  4665. rc = -EIO;
  4666. goto err_exit;
  4667. }
  4668. /*
  4669. * Figure out where the response is located. Then get local pointers
  4670. * to the response data. The port does not guarantee to respond to
  4671. * all extents counts request so update the local variable with the
  4672. * allocated count from the port.
  4673. */
  4674. if (emb == LPFC_SLI4_MBX_EMBED) {
  4675. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4676. id_array = &rsrc_ext->u.rsp.id[0];
  4677. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4678. } else {
  4679. virtaddr = mbox->sge_array->addr[0];
  4680. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4681. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4682. id_array = &n_rsrc->id;
  4683. }
  4684. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4685. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4686. /*
  4687. * Based on the resource size and count, correct the base and max
  4688. * resource values.
  4689. */
  4690. length = sizeof(struct lpfc_rsrc_blks);
  4691. switch (type) {
  4692. case LPFC_RSC_TYPE_FCOE_RPI:
  4693. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4694. sizeof(unsigned long),
  4695. GFP_KERNEL);
  4696. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4697. rc = -ENOMEM;
  4698. goto err_exit;
  4699. }
  4700. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4701. sizeof(uint16_t),
  4702. GFP_KERNEL);
  4703. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4704. kfree(phba->sli4_hba.rpi_bmask);
  4705. rc = -ENOMEM;
  4706. goto err_exit;
  4707. }
  4708. /*
  4709. * The next_rpi was initialized with the maximum available
  4710. * count but the port may allocate a smaller number. Catch
  4711. * that case and update the next_rpi.
  4712. */
  4713. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4714. /* Initialize local ptrs for common extent processing later. */
  4715. bmask = phba->sli4_hba.rpi_bmask;
  4716. ids = phba->sli4_hba.rpi_ids;
  4717. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4718. break;
  4719. case LPFC_RSC_TYPE_FCOE_VPI:
  4720. phba->vpi_bmask = kzalloc(longs *
  4721. sizeof(unsigned long),
  4722. GFP_KERNEL);
  4723. if (unlikely(!phba->vpi_bmask)) {
  4724. rc = -ENOMEM;
  4725. goto err_exit;
  4726. }
  4727. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4728. sizeof(uint16_t),
  4729. GFP_KERNEL);
  4730. if (unlikely(!phba->vpi_ids)) {
  4731. kfree(phba->vpi_bmask);
  4732. rc = -ENOMEM;
  4733. goto err_exit;
  4734. }
  4735. /* Initialize local ptrs for common extent processing later. */
  4736. bmask = phba->vpi_bmask;
  4737. ids = phba->vpi_ids;
  4738. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4739. break;
  4740. case LPFC_RSC_TYPE_FCOE_XRI:
  4741. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4742. sizeof(unsigned long),
  4743. GFP_KERNEL);
  4744. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4745. rc = -ENOMEM;
  4746. goto err_exit;
  4747. }
  4748. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4749. sizeof(uint16_t),
  4750. GFP_KERNEL);
  4751. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4752. kfree(phba->sli4_hba.xri_bmask);
  4753. rc = -ENOMEM;
  4754. goto err_exit;
  4755. }
  4756. /* Initialize local ptrs for common extent processing later. */
  4757. bmask = phba->sli4_hba.xri_bmask;
  4758. ids = phba->sli4_hba.xri_ids;
  4759. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4760. break;
  4761. case LPFC_RSC_TYPE_FCOE_VFI:
  4762. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4763. sizeof(unsigned long),
  4764. GFP_KERNEL);
  4765. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4766. rc = -ENOMEM;
  4767. goto err_exit;
  4768. }
  4769. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4770. sizeof(uint16_t),
  4771. GFP_KERNEL);
  4772. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4773. kfree(phba->sli4_hba.vfi_bmask);
  4774. rc = -ENOMEM;
  4775. goto err_exit;
  4776. }
  4777. /* Initialize local ptrs for common extent processing later. */
  4778. bmask = phba->sli4_hba.vfi_bmask;
  4779. ids = phba->sli4_hba.vfi_ids;
  4780. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4781. break;
  4782. default:
  4783. /* Unsupported Opcode. Fail call. */
  4784. id_array = NULL;
  4785. bmask = NULL;
  4786. ids = NULL;
  4787. ext_blk_list = NULL;
  4788. goto err_exit;
  4789. }
  4790. /*
  4791. * Complete initializing the extent configuration with the
  4792. * allocated ids assigned to this function. The bitmask serves
  4793. * as an index into the array and manages the available ids. The
  4794. * array just stores the ids communicated to the port via the wqes.
  4795. */
  4796. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  4797. if ((i % 2) == 0)
  4798. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  4799. &id_array[k]);
  4800. else
  4801. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  4802. &id_array[k]);
  4803. rsrc_blks = kzalloc(length, GFP_KERNEL);
  4804. if (unlikely(!rsrc_blks)) {
  4805. rc = -ENOMEM;
  4806. kfree(bmask);
  4807. kfree(ids);
  4808. goto err_exit;
  4809. }
  4810. rsrc_blks->rsrc_start = rsrc_id;
  4811. rsrc_blks->rsrc_size = rsrc_size;
  4812. list_add_tail(&rsrc_blks->list, ext_blk_list);
  4813. rsrc_start = rsrc_id;
  4814. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  4815. phba->sli4_hba.scsi_xri_start = rsrc_start +
  4816. lpfc_sli4_get_els_iocb_cnt(phba);
  4817. while (rsrc_id < (rsrc_start + rsrc_size)) {
  4818. ids[j] = rsrc_id;
  4819. rsrc_id++;
  4820. j++;
  4821. }
  4822. /* Entire word processed. Get next word.*/
  4823. if ((i % 2) == 1)
  4824. k++;
  4825. }
  4826. err_exit:
  4827. lpfc_sli4_mbox_cmd_free(phba, mbox);
  4828. return rc;
  4829. }
  4830. /**
  4831. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  4832. * @phba: Pointer to HBA context object.
  4833. * @type: the extent's type.
  4834. *
  4835. * This function deallocates all extents of a particular resource type.
  4836. * SLI4 does not allow for deallocating a particular extent range. It
  4837. * is the caller's responsibility to release all kernel memory resources.
  4838. **/
  4839. static int
  4840. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  4841. {
  4842. int rc;
  4843. uint32_t length, mbox_tmo = 0;
  4844. LPFC_MBOXQ_t *mbox;
  4845. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  4846. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  4847. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4848. if (!mbox)
  4849. return -ENOMEM;
  4850. /*
  4851. * This function sends an embedded mailbox because it only sends the
  4852. * the resource type. All extents of this type are released by the
  4853. * port.
  4854. */
  4855. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  4856. sizeof(struct lpfc_sli4_cfg_mhdr));
  4857. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4858. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  4859. length, LPFC_SLI4_MBX_EMBED);
  4860. /* Send an extents count of 0 - the dealloc doesn't use it. */
  4861. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4862. LPFC_SLI4_MBX_EMBED);
  4863. if (unlikely(rc)) {
  4864. rc = -EIO;
  4865. goto out_free_mbox;
  4866. }
  4867. if (!phba->sli4_hba.intr_enable)
  4868. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4869. else {
  4870. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4871. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4872. }
  4873. if (unlikely(rc)) {
  4874. rc = -EIO;
  4875. goto out_free_mbox;
  4876. }
  4877. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  4878. if (bf_get(lpfc_mbox_hdr_status,
  4879. &dealloc_rsrc->header.cfg_shdr.response)) {
  4880. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4881. "2919 Failed to release resource extents "
  4882. "for type %d - Status 0x%x Add'l Status 0x%x. "
  4883. "Resource memory not released.\n",
  4884. type,
  4885. bf_get(lpfc_mbox_hdr_status,
  4886. &dealloc_rsrc->header.cfg_shdr.response),
  4887. bf_get(lpfc_mbox_hdr_add_status,
  4888. &dealloc_rsrc->header.cfg_shdr.response));
  4889. rc = -EIO;
  4890. goto out_free_mbox;
  4891. }
  4892. /* Release kernel memory resources for the specific type. */
  4893. switch (type) {
  4894. case LPFC_RSC_TYPE_FCOE_VPI:
  4895. kfree(phba->vpi_bmask);
  4896. kfree(phba->vpi_ids);
  4897. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4898. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4899. &phba->lpfc_vpi_blk_list, list) {
  4900. list_del_init(&rsrc_blk->list);
  4901. kfree(rsrc_blk);
  4902. }
  4903. break;
  4904. case LPFC_RSC_TYPE_FCOE_XRI:
  4905. kfree(phba->sli4_hba.xri_bmask);
  4906. kfree(phba->sli4_hba.xri_ids);
  4907. bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4908. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4909. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  4910. list_del_init(&rsrc_blk->list);
  4911. kfree(rsrc_blk);
  4912. }
  4913. break;
  4914. case LPFC_RSC_TYPE_FCOE_VFI:
  4915. kfree(phba->sli4_hba.vfi_bmask);
  4916. kfree(phba->sli4_hba.vfi_ids);
  4917. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4918. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4919. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  4920. list_del_init(&rsrc_blk->list);
  4921. kfree(rsrc_blk);
  4922. }
  4923. break;
  4924. case LPFC_RSC_TYPE_FCOE_RPI:
  4925. /* RPI bitmask and physical id array are cleaned up earlier. */
  4926. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4927. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  4928. list_del_init(&rsrc_blk->list);
  4929. kfree(rsrc_blk);
  4930. }
  4931. break;
  4932. default:
  4933. break;
  4934. }
  4935. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4936. out_free_mbox:
  4937. mempool_free(mbox, phba->mbox_mem_pool);
  4938. return rc;
  4939. }
  4940. /**
  4941. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  4942. * @phba: Pointer to HBA context object.
  4943. *
  4944. * This function allocates all SLI4 resource identifiers.
  4945. **/
  4946. int
  4947. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  4948. {
  4949. int i, rc, error = 0;
  4950. uint16_t count, base;
  4951. unsigned long longs;
  4952. if (!phba->sli4_hba.rpi_hdrs_in_use)
  4953. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  4954. if (phba->sli4_hba.extents_in_use) {
  4955. /*
  4956. * The port supports resource extents. The XRI, VPI, VFI, RPI
  4957. * resource extent count must be read and allocated before
  4958. * provisioning the resource id arrays.
  4959. */
  4960. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  4961. LPFC_IDX_RSRC_RDY) {
  4962. /*
  4963. * Extent-based resources are set - the driver could
  4964. * be in a port reset. Figure out if any corrective
  4965. * actions need to be taken.
  4966. */
  4967. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4968. LPFC_RSC_TYPE_FCOE_VFI);
  4969. if (rc != 0)
  4970. error++;
  4971. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4972. LPFC_RSC_TYPE_FCOE_VPI);
  4973. if (rc != 0)
  4974. error++;
  4975. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4976. LPFC_RSC_TYPE_FCOE_XRI);
  4977. if (rc != 0)
  4978. error++;
  4979. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4980. LPFC_RSC_TYPE_FCOE_RPI);
  4981. if (rc != 0)
  4982. error++;
  4983. /*
  4984. * It's possible that the number of resources
  4985. * provided to this port instance changed between
  4986. * resets. Detect this condition and reallocate
  4987. * resources. Otherwise, there is no action.
  4988. */
  4989. if (error) {
  4990. lpfc_printf_log(phba, KERN_INFO,
  4991. LOG_MBOX | LOG_INIT,
  4992. "2931 Detected extent resource "
  4993. "change. Reallocating all "
  4994. "extents.\n");
  4995. rc = lpfc_sli4_dealloc_extent(phba,
  4996. LPFC_RSC_TYPE_FCOE_VFI);
  4997. rc = lpfc_sli4_dealloc_extent(phba,
  4998. LPFC_RSC_TYPE_FCOE_VPI);
  4999. rc = lpfc_sli4_dealloc_extent(phba,
  5000. LPFC_RSC_TYPE_FCOE_XRI);
  5001. rc = lpfc_sli4_dealloc_extent(phba,
  5002. LPFC_RSC_TYPE_FCOE_RPI);
  5003. } else
  5004. return 0;
  5005. }
  5006. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5007. if (unlikely(rc))
  5008. goto err_exit;
  5009. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5010. if (unlikely(rc))
  5011. goto err_exit;
  5012. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5013. if (unlikely(rc))
  5014. goto err_exit;
  5015. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5016. if (unlikely(rc))
  5017. goto err_exit;
  5018. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5019. LPFC_IDX_RSRC_RDY);
  5020. return rc;
  5021. } else {
  5022. /*
  5023. * The port does not support resource extents. The XRI, VPI,
  5024. * VFI, RPI resource ids were determined from READ_CONFIG.
  5025. * Just allocate the bitmasks and provision the resource id
  5026. * arrays. If a port reset is active, the resources don't
  5027. * need any action - just exit.
  5028. */
  5029. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5030. LPFC_IDX_RSRC_RDY) {
  5031. lpfc_sli4_dealloc_resource_identifiers(phba);
  5032. lpfc_sli4_remove_rpis(phba);
  5033. }
  5034. /* RPIs. */
  5035. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5036. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5037. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5038. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5039. sizeof(unsigned long),
  5040. GFP_KERNEL);
  5041. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5042. rc = -ENOMEM;
  5043. goto err_exit;
  5044. }
  5045. phba->sli4_hba.rpi_ids = kzalloc(count *
  5046. sizeof(uint16_t),
  5047. GFP_KERNEL);
  5048. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5049. rc = -ENOMEM;
  5050. goto free_rpi_bmask;
  5051. }
  5052. for (i = 0; i < count; i++)
  5053. phba->sli4_hba.rpi_ids[i] = base + i;
  5054. /* VPIs. */
  5055. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5056. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5057. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5058. phba->vpi_bmask = kzalloc(longs *
  5059. sizeof(unsigned long),
  5060. GFP_KERNEL);
  5061. if (unlikely(!phba->vpi_bmask)) {
  5062. rc = -ENOMEM;
  5063. goto free_rpi_ids;
  5064. }
  5065. phba->vpi_ids = kzalloc(count *
  5066. sizeof(uint16_t),
  5067. GFP_KERNEL);
  5068. if (unlikely(!phba->vpi_ids)) {
  5069. rc = -ENOMEM;
  5070. goto free_vpi_bmask;
  5071. }
  5072. for (i = 0; i < count; i++)
  5073. phba->vpi_ids[i] = base + i;
  5074. /* XRIs. */
  5075. count = phba->sli4_hba.max_cfg_param.max_xri;
  5076. base = phba->sli4_hba.max_cfg_param.xri_base;
  5077. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5078. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5079. sizeof(unsigned long),
  5080. GFP_KERNEL);
  5081. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5082. rc = -ENOMEM;
  5083. goto free_vpi_ids;
  5084. }
  5085. phba->sli4_hba.xri_ids = kzalloc(count *
  5086. sizeof(uint16_t),
  5087. GFP_KERNEL);
  5088. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5089. rc = -ENOMEM;
  5090. goto free_xri_bmask;
  5091. }
  5092. for (i = 0; i < count; i++)
  5093. phba->sli4_hba.xri_ids[i] = base + i;
  5094. /* VFIs. */
  5095. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5096. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5097. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5098. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5099. sizeof(unsigned long),
  5100. GFP_KERNEL);
  5101. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5102. rc = -ENOMEM;
  5103. goto free_xri_ids;
  5104. }
  5105. phba->sli4_hba.vfi_ids = kzalloc(count *
  5106. sizeof(uint16_t),
  5107. GFP_KERNEL);
  5108. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5109. rc = -ENOMEM;
  5110. goto free_vfi_bmask;
  5111. }
  5112. for (i = 0; i < count; i++)
  5113. phba->sli4_hba.vfi_ids[i] = base + i;
  5114. /*
  5115. * Mark all resources ready. An HBA reset doesn't need
  5116. * to reset the initialization.
  5117. */
  5118. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5119. LPFC_IDX_RSRC_RDY);
  5120. return 0;
  5121. }
  5122. free_vfi_bmask:
  5123. kfree(phba->sli4_hba.vfi_bmask);
  5124. free_xri_ids:
  5125. kfree(phba->sli4_hba.xri_ids);
  5126. free_xri_bmask:
  5127. kfree(phba->sli4_hba.xri_bmask);
  5128. free_vpi_ids:
  5129. kfree(phba->vpi_ids);
  5130. free_vpi_bmask:
  5131. kfree(phba->vpi_bmask);
  5132. free_rpi_ids:
  5133. kfree(phba->sli4_hba.rpi_ids);
  5134. free_rpi_bmask:
  5135. kfree(phba->sli4_hba.rpi_bmask);
  5136. err_exit:
  5137. return rc;
  5138. }
  5139. /**
  5140. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5141. * @phba: Pointer to HBA context object.
  5142. *
  5143. * This function allocates the number of elements for the specified
  5144. * resource type.
  5145. **/
  5146. int
  5147. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5148. {
  5149. if (phba->sli4_hba.extents_in_use) {
  5150. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5151. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5152. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5153. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5154. } else {
  5155. kfree(phba->vpi_bmask);
  5156. kfree(phba->vpi_ids);
  5157. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5158. kfree(phba->sli4_hba.xri_bmask);
  5159. kfree(phba->sli4_hba.xri_ids);
  5160. bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5161. kfree(phba->sli4_hba.vfi_bmask);
  5162. kfree(phba->sli4_hba.vfi_ids);
  5163. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5164. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5165. }
  5166. return 0;
  5167. }
  5168. /**
  5169. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5170. * @phba: Pointer to HBA context object.
  5171. * @type: The resource extent type.
  5172. * @extnt_count: buffer to hold port extent count response
  5173. * @extnt_size: buffer to hold port extent size response.
  5174. *
  5175. * This function calls the port to read the host allocated extents
  5176. * for a particular type.
  5177. **/
  5178. int
  5179. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5180. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5181. {
  5182. bool emb;
  5183. int rc = 0;
  5184. uint16_t curr_blks = 0;
  5185. uint32_t req_len, emb_len;
  5186. uint32_t alloc_len, mbox_tmo;
  5187. struct list_head *blk_list_head;
  5188. struct lpfc_rsrc_blks *rsrc_blk;
  5189. LPFC_MBOXQ_t *mbox;
  5190. void *virtaddr = NULL;
  5191. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5192. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5193. union lpfc_sli4_cfg_shdr *shdr;
  5194. switch (type) {
  5195. case LPFC_RSC_TYPE_FCOE_VPI:
  5196. blk_list_head = &phba->lpfc_vpi_blk_list;
  5197. break;
  5198. case LPFC_RSC_TYPE_FCOE_XRI:
  5199. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5200. break;
  5201. case LPFC_RSC_TYPE_FCOE_VFI:
  5202. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5203. break;
  5204. case LPFC_RSC_TYPE_FCOE_RPI:
  5205. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5206. break;
  5207. default:
  5208. return -EIO;
  5209. }
  5210. /* Count the number of extents currently allocatd for this type. */
  5211. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5212. if (curr_blks == 0) {
  5213. /*
  5214. * The GET_ALLOCATED mailbox does not return the size,
  5215. * just the count. The size should be just the size
  5216. * stored in the current allocated block and all sizes
  5217. * for an extent type are the same so set the return
  5218. * value now.
  5219. */
  5220. *extnt_size = rsrc_blk->rsrc_size;
  5221. }
  5222. curr_blks++;
  5223. }
  5224. /* Calculate the total requested length of the dma memory. */
  5225. req_len = curr_blks * sizeof(uint16_t);
  5226. /*
  5227. * Calculate the size of an embedded mailbox. The uint32_t
  5228. * accounts for extents-specific word.
  5229. */
  5230. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5231. sizeof(uint32_t);
  5232. /*
  5233. * Presume the allocation and response will fit into an embedded
  5234. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5235. */
  5236. emb = LPFC_SLI4_MBX_EMBED;
  5237. req_len = emb_len;
  5238. if (req_len > emb_len) {
  5239. req_len = curr_blks * sizeof(uint16_t) +
  5240. sizeof(union lpfc_sli4_cfg_shdr) +
  5241. sizeof(uint32_t);
  5242. emb = LPFC_SLI4_MBX_NEMBED;
  5243. }
  5244. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5245. if (!mbox)
  5246. return -ENOMEM;
  5247. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5248. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5249. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5250. req_len, emb);
  5251. if (alloc_len < req_len) {
  5252. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5253. "2983 Allocated DMA memory size (x%x) is "
  5254. "less than the requested DMA memory "
  5255. "size (x%x)\n", alloc_len, req_len);
  5256. rc = -ENOMEM;
  5257. goto err_exit;
  5258. }
  5259. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5260. if (unlikely(rc)) {
  5261. rc = -EIO;
  5262. goto err_exit;
  5263. }
  5264. if (!phba->sli4_hba.intr_enable)
  5265. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5266. else {
  5267. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5268. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5269. }
  5270. if (unlikely(rc)) {
  5271. rc = -EIO;
  5272. goto err_exit;
  5273. }
  5274. /*
  5275. * Figure out where the response is located. Then get local pointers
  5276. * to the response data. The port does not guarantee to respond to
  5277. * all extents counts request so update the local variable with the
  5278. * allocated count from the port.
  5279. */
  5280. if (emb == LPFC_SLI4_MBX_EMBED) {
  5281. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5282. shdr = &rsrc_ext->header.cfg_shdr;
  5283. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5284. } else {
  5285. virtaddr = mbox->sge_array->addr[0];
  5286. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5287. shdr = &n_rsrc->cfg_shdr;
  5288. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5289. }
  5290. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5291. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5292. "2984 Failed to read allocated resources "
  5293. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5294. type,
  5295. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5296. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5297. rc = -EIO;
  5298. goto err_exit;
  5299. }
  5300. err_exit:
  5301. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5302. return rc;
  5303. }
  5304. /**
  5305. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5306. * @phba: Pointer to HBA context object.
  5307. *
  5308. * This function is the main SLI4 device intialization PCI function. This
  5309. * function is called by the HBA intialization code, HBA reset code and
  5310. * HBA error attention handler code. Caller is not required to hold any
  5311. * locks.
  5312. **/
  5313. int
  5314. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5315. {
  5316. int rc;
  5317. LPFC_MBOXQ_t *mboxq;
  5318. struct lpfc_mqe *mqe;
  5319. uint8_t *vpd;
  5320. uint32_t vpd_size;
  5321. uint32_t ftr_rsp = 0;
  5322. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5323. struct lpfc_vport *vport = phba->pport;
  5324. struct lpfc_dmabuf *mp;
  5325. /* Perform a PCI function reset to start from clean */
  5326. rc = lpfc_pci_function_reset(phba);
  5327. if (unlikely(rc))
  5328. return -ENODEV;
  5329. /* Check the HBA Host Status Register for readyness */
  5330. rc = lpfc_sli4_post_status_check(phba);
  5331. if (unlikely(rc))
  5332. return -ENODEV;
  5333. else {
  5334. spin_lock_irq(&phba->hbalock);
  5335. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5336. spin_unlock_irq(&phba->hbalock);
  5337. }
  5338. /*
  5339. * Allocate a single mailbox container for initializing the
  5340. * port.
  5341. */
  5342. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5343. if (!mboxq)
  5344. return -ENOMEM;
  5345. /* Issue READ_REV to collect vpd and FW information. */
  5346. vpd_size = SLI4_PAGE_SIZE;
  5347. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5348. if (!vpd) {
  5349. rc = -ENOMEM;
  5350. goto out_free_mbox;
  5351. }
  5352. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5353. if (unlikely(rc)) {
  5354. kfree(vpd);
  5355. goto out_free_mbox;
  5356. }
  5357. mqe = &mboxq->u.mqe;
  5358. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5359. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  5360. phba->hba_flag |= HBA_FCOE_MODE;
  5361. else
  5362. phba->hba_flag &= ~HBA_FCOE_MODE;
  5363. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5364. LPFC_DCBX_CEE_MODE)
  5365. phba->hba_flag |= HBA_FIP_SUPPORT;
  5366. else
  5367. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5368. if (phba->sli_rev != LPFC_SLI_REV4) {
  5369. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5370. "0376 READ_REV Error. SLI Level %d "
  5371. "FCoE enabled %d\n",
  5372. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5373. rc = -EIO;
  5374. kfree(vpd);
  5375. goto out_free_mbox;
  5376. }
  5377. /*
  5378. * Continue initialization with default values even if driver failed
  5379. * to read FCoE param config regions, only read parameters if the
  5380. * board is FCoE
  5381. */
  5382. if (phba->hba_flag & HBA_FCOE_MODE &&
  5383. lpfc_sli4_read_fcoe_params(phba))
  5384. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5385. "2570 Failed to read FCoE parameters\n");
  5386. /*
  5387. * Retrieve sli4 device physical port name, failure of doing it
  5388. * is considered as non-fatal.
  5389. */
  5390. rc = lpfc_sli4_retrieve_pport_name(phba);
  5391. if (!rc)
  5392. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5393. "3080 Successful retrieving SLI4 device "
  5394. "physical port name: %s.\n", phba->Port);
  5395. /*
  5396. * Evaluate the read rev and vpd data. Populate the driver
  5397. * state with the results. If this routine fails, the failure
  5398. * is not fatal as the driver will use generic values.
  5399. */
  5400. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5401. if (unlikely(!rc)) {
  5402. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5403. "0377 Error %d parsing vpd. "
  5404. "Using defaults.\n", rc);
  5405. rc = 0;
  5406. }
  5407. kfree(vpd);
  5408. /* Save information as VPD data */
  5409. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5410. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5411. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5412. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5413. &mqe->un.read_rev);
  5414. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5415. &mqe->un.read_rev);
  5416. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5417. &mqe->un.read_rev);
  5418. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5419. &mqe->un.read_rev);
  5420. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5421. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5422. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5423. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5424. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5425. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5426. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5427. "(%d):0380 READ_REV Status x%x "
  5428. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5429. mboxq->vport ? mboxq->vport->vpi : 0,
  5430. bf_get(lpfc_mqe_status, mqe),
  5431. phba->vpd.rev.opFwName,
  5432. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5433. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5434. /*
  5435. * Discover the port's supported feature set and match it against the
  5436. * hosts requests.
  5437. */
  5438. lpfc_request_features(phba, mboxq);
  5439. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5440. if (unlikely(rc)) {
  5441. rc = -EIO;
  5442. goto out_free_mbox;
  5443. }
  5444. /*
  5445. * The port must support FCP initiator mode as this is the
  5446. * only mode running in the host.
  5447. */
  5448. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5449. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5450. "0378 No support for fcpi mode.\n");
  5451. ftr_rsp++;
  5452. }
  5453. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5454. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5455. else
  5456. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5457. /*
  5458. * If the port cannot support the host's requested features
  5459. * then turn off the global config parameters to disable the
  5460. * feature in the driver. This is not a fatal error.
  5461. */
  5462. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5463. if (phba->cfg_enable_bg) {
  5464. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5465. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5466. else
  5467. ftr_rsp++;
  5468. }
  5469. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5470. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5471. ftr_rsp++;
  5472. if (ftr_rsp) {
  5473. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5474. "0379 Feature Mismatch Data: x%08x %08x "
  5475. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5476. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5477. phba->cfg_enable_npiv, phba->max_vpi);
  5478. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5479. phba->cfg_enable_bg = 0;
  5480. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5481. phba->cfg_enable_npiv = 0;
  5482. }
  5483. /* These SLI3 features are assumed in SLI4 */
  5484. spin_lock_irq(&phba->hbalock);
  5485. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5486. spin_unlock_irq(&phba->hbalock);
  5487. /*
  5488. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5489. * calls depends on these resources to complete port setup.
  5490. */
  5491. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5492. if (rc) {
  5493. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5494. "2920 Failed to alloc Resource IDs "
  5495. "rc = x%x\n", rc);
  5496. goto out_free_mbox;
  5497. }
  5498. /* update physical xri mappings in the scsi buffers */
  5499. lpfc_scsi_buf_update(phba);
  5500. /* Read the port's service parameters. */
  5501. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5502. if (rc) {
  5503. phba->link_state = LPFC_HBA_ERROR;
  5504. rc = -ENOMEM;
  5505. goto out_free_mbox;
  5506. }
  5507. mboxq->vport = vport;
  5508. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5509. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5510. if (rc == MBX_SUCCESS) {
  5511. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5512. rc = 0;
  5513. }
  5514. /*
  5515. * This memory was allocated by the lpfc_read_sparam routine. Release
  5516. * it to the mbuf pool.
  5517. */
  5518. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5519. kfree(mp);
  5520. mboxq->context1 = NULL;
  5521. if (unlikely(rc)) {
  5522. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5523. "0382 READ_SPARAM command failed "
  5524. "status %d, mbxStatus x%x\n",
  5525. rc, bf_get(lpfc_mqe_status, mqe));
  5526. phba->link_state = LPFC_HBA_ERROR;
  5527. rc = -EIO;
  5528. goto out_free_mbox;
  5529. }
  5530. lpfc_update_vport_wwn(vport);
  5531. /* Update the fc_host data structures with new wwn. */
  5532. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5533. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5534. /* Register SGL pool to the device using non-embedded mailbox command */
  5535. if (!phba->sli4_hba.extents_in_use) {
  5536. rc = lpfc_sli4_post_els_sgl_list(phba);
  5537. if (unlikely(rc)) {
  5538. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5539. "0582 Error %d during els sgl post "
  5540. "operation\n", rc);
  5541. rc = -ENODEV;
  5542. goto out_free_mbox;
  5543. }
  5544. } else {
  5545. rc = lpfc_sli4_post_els_sgl_list_ext(phba);
  5546. if (unlikely(rc)) {
  5547. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5548. "2560 Error %d during els sgl post "
  5549. "operation\n", rc);
  5550. rc = -ENODEV;
  5551. goto out_free_mbox;
  5552. }
  5553. }
  5554. /* Register SCSI SGL pool to the device */
  5555. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  5556. if (unlikely(rc)) {
  5557. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5558. "0383 Error %d during scsi sgl post "
  5559. "operation\n", rc);
  5560. /* Some Scsi buffers were moved to the abort scsi list */
  5561. /* A pci function reset will repost them */
  5562. rc = -ENODEV;
  5563. goto out_free_mbox;
  5564. }
  5565. /* Post the rpi header region to the device. */
  5566. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  5567. if (unlikely(rc)) {
  5568. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5569. "0393 Error %d during rpi post operation\n",
  5570. rc);
  5571. rc = -ENODEV;
  5572. goto out_free_mbox;
  5573. }
  5574. /* Create all the SLI4 queues */
  5575. rc = lpfc_sli4_queue_create(phba);
  5576. if (rc) {
  5577. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5578. "3089 Failed to allocate queues\n");
  5579. rc = -ENODEV;
  5580. goto out_stop_timers;
  5581. }
  5582. /* Set up all the queues to the device */
  5583. rc = lpfc_sli4_queue_setup(phba);
  5584. if (unlikely(rc)) {
  5585. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5586. "0381 Error %d during queue setup.\n ", rc);
  5587. goto out_destroy_queue;
  5588. }
  5589. /* Arm the CQs and then EQs on device */
  5590. lpfc_sli4_arm_cqeq_intr(phba);
  5591. /* Indicate device interrupt mode */
  5592. phba->sli4_hba.intr_enable = 1;
  5593. /* Allow asynchronous mailbox command to go through */
  5594. spin_lock_irq(&phba->hbalock);
  5595. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5596. spin_unlock_irq(&phba->hbalock);
  5597. /* Post receive buffers to the device */
  5598. lpfc_sli4_rb_setup(phba);
  5599. /* Reset HBA FCF states after HBA reset */
  5600. phba->fcf.fcf_flag = 0;
  5601. phba->fcf.current_rec.flag = 0;
  5602. /* Start the ELS watchdog timer */
  5603. mod_timer(&vport->els_tmofunc,
  5604. jiffies + HZ * (phba->fc_ratov * 2));
  5605. /* Start heart beat timer */
  5606. mod_timer(&phba->hb_tmofunc,
  5607. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  5608. phba->hb_outstanding = 0;
  5609. phba->last_completion_time = jiffies;
  5610. /* Start error attention (ERATT) polling timer */
  5611. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  5612. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  5613. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  5614. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  5615. if (!rc) {
  5616. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5617. "2829 This device supports "
  5618. "Advanced Error Reporting (AER)\n");
  5619. spin_lock_irq(&phba->hbalock);
  5620. phba->hba_flag |= HBA_AER_ENABLED;
  5621. spin_unlock_irq(&phba->hbalock);
  5622. } else {
  5623. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5624. "2830 This device does not support "
  5625. "Advanced Error Reporting (AER)\n");
  5626. phba->cfg_aer_support = 0;
  5627. }
  5628. rc = 0;
  5629. }
  5630. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  5631. /*
  5632. * The FC Port needs to register FCFI (index 0)
  5633. */
  5634. lpfc_reg_fcfi(phba, mboxq);
  5635. mboxq->vport = phba->pport;
  5636. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5637. if (rc != MBX_SUCCESS)
  5638. goto out_unset_queue;
  5639. rc = 0;
  5640. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  5641. &mboxq->u.mqe.un.reg_fcfi);
  5642. /* Check if the port is configured to be disabled */
  5643. lpfc_sli_read_link_ste(phba);
  5644. }
  5645. /*
  5646. * The port is ready, set the host's link state to LINK_DOWN
  5647. * in preparation for link interrupts.
  5648. */
  5649. spin_lock_irq(&phba->hbalock);
  5650. phba->link_state = LPFC_LINK_DOWN;
  5651. spin_unlock_irq(&phba->hbalock);
  5652. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  5653. (phba->hba_flag & LINK_DISABLED)) {
  5654. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5655. "3103 Adapter Link is disabled.\n");
  5656. lpfc_down_link(phba, mboxq);
  5657. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5658. if (rc != MBX_SUCCESS) {
  5659. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5660. "3104 Adapter failed to issue "
  5661. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  5662. goto out_unset_queue;
  5663. }
  5664. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  5665. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  5666. if (rc)
  5667. goto out_unset_queue;
  5668. }
  5669. mempool_free(mboxq, phba->mbox_mem_pool);
  5670. return rc;
  5671. out_unset_queue:
  5672. /* Unset all the queues set up in this routine when error out */
  5673. lpfc_sli4_queue_unset(phba);
  5674. out_destroy_queue:
  5675. lpfc_sli4_queue_destroy(phba);
  5676. out_stop_timers:
  5677. lpfc_stop_hba_timers(phba);
  5678. out_free_mbox:
  5679. mempool_free(mboxq, phba->mbox_mem_pool);
  5680. return rc;
  5681. }
  5682. /**
  5683. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  5684. * @ptr: context object - pointer to hba structure.
  5685. *
  5686. * This is the callback function for mailbox timer. The mailbox
  5687. * timer is armed when a new mailbox command is issued and the timer
  5688. * is deleted when the mailbox complete. The function is called by
  5689. * the kernel timer code when a mailbox does not complete within
  5690. * expected time. This function wakes up the worker thread to
  5691. * process the mailbox timeout and returns. All the processing is
  5692. * done by the worker thread function lpfc_mbox_timeout_handler.
  5693. **/
  5694. void
  5695. lpfc_mbox_timeout(unsigned long ptr)
  5696. {
  5697. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  5698. unsigned long iflag;
  5699. uint32_t tmo_posted;
  5700. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  5701. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  5702. if (!tmo_posted)
  5703. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  5704. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  5705. if (!tmo_posted)
  5706. lpfc_worker_wake_up(phba);
  5707. return;
  5708. }
  5709. /**
  5710. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  5711. * @phba: Pointer to HBA context object.
  5712. *
  5713. * This function is called from worker thread when a mailbox command times out.
  5714. * The caller is not required to hold any locks. This function will reset the
  5715. * HBA and recover all the pending commands.
  5716. **/
  5717. void
  5718. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  5719. {
  5720. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  5721. MAILBOX_t *mb = &pmbox->u.mb;
  5722. struct lpfc_sli *psli = &phba->sli;
  5723. struct lpfc_sli_ring *pring;
  5724. /* Check the pmbox pointer first. There is a race condition
  5725. * between the mbox timeout handler getting executed in the
  5726. * worklist and the mailbox actually completing. When this
  5727. * race condition occurs, the mbox_active will be NULL.
  5728. */
  5729. spin_lock_irq(&phba->hbalock);
  5730. if (pmbox == NULL) {
  5731. lpfc_printf_log(phba, KERN_WARNING,
  5732. LOG_MBOX | LOG_SLI,
  5733. "0353 Active Mailbox cleared - mailbox timeout "
  5734. "exiting\n");
  5735. spin_unlock_irq(&phba->hbalock);
  5736. return;
  5737. }
  5738. /* Mbox cmd <mbxCommand> timeout */
  5739. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5740. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  5741. mb->mbxCommand,
  5742. phba->pport->port_state,
  5743. phba->sli.sli_flag,
  5744. phba->sli.mbox_active);
  5745. spin_unlock_irq(&phba->hbalock);
  5746. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  5747. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  5748. * it to fail all outstanding SCSI IO.
  5749. */
  5750. spin_lock_irq(&phba->pport->work_port_lock);
  5751. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  5752. spin_unlock_irq(&phba->pport->work_port_lock);
  5753. spin_lock_irq(&phba->hbalock);
  5754. phba->link_state = LPFC_LINK_UNKNOWN;
  5755. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  5756. spin_unlock_irq(&phba->hbalock);
  5757. pring = &psli->ring[psli->fcp_ring];
  5758. lpfc_sli_abort_iocb_ring(phba, pring);
  5759. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5760. "0345 Resetting board due to mailbox timeout\n");
  5761. /* Reset the HBA device */
  5762. lpfc_reset_hba(phba);
  5763. }
  5764. /**
  5765. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  5766. * @phba: Pointer to HBA context object.
  5767. * @pmbox: Pointer to mailbox object.
  5768. * @flag: Flag indicating how the mailbox need to be processed.
  5769. *
  5770. * This function is called by discovery code and HBA management code
  5771. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  5772. * function gets the hbalock to protect the data structures.
  5773. * The mailbox command can be submitted in polling mode, in which case
  5774. * this function will wait in a polling loop for the completion of the
  5775. * mailbox.
  5776. * If the mailbox is submitted in no_wait mode (not polling) the
  5777. * function will submit the command and returns immediately without waiting
  5778. * for the mailbox completion. The no_wait is supported only when HBA
  5779. * is in SLI2/SLI3 mode - interrupts are enabled.
  5780. * The SLI interface allows only one mailbox pending at a time. If the
  5781. * mailbox is issued in polling mode and there is already a mailbox
  5782. * pending, then the function will return an error. If the mailbox is issued
  5783. * in NO_WAIT mode and there is a mailbox pending already, the function
  5784. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  5785. * The sli layer owns the mailbox object until the completion of mailbox
  5786. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  5787. * return codes the caller owns the mailbox command after the return of
  5788. * the function.
  5789. **/
  5790. static int
  5791. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  5792. uint32_t flag)
  5793. {
  5794. MAILBOX_t *mb;
  5795. struct lpfc_sli *psli = &phba->sli;
  5796. uint32_t status, evtctr;
  5797. uint32_t ha_copy, hc_copy;
  5798. int i;
  5799. unsigned long timeout;
  5800. unsigned long drvr_flag = 0;
  5801. uint32_t word0, ldata;
  5802. void __iomem *to_slim;
  5803. int processing_queue = 0;
  5804. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  5805. if (!pmbox) {
  5806. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5807. /* processing mbox queue from intr_handler */
  5808. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5809. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5810. return MBX_SUCCESS;
  5811. }
  5812. processing_queue = 1;
  5813. pmbox = lpfc_mbox_get(phba);
  5814. if (!pmbox) {
  5815. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5816. return MBX_SUCCESS;
  5817. }
  5818. }
  5819. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  5820. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  5821. if(!pmbox->vport) {
  5822. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5823. lpfc_printf_log(phba, KERN_ERR,
  5824. LOG_MBOX | LOG_VPORT,
  5825. "1806 Mbox x%x failed. No vport\n",
  5826. pmbox->u.mb.mbxCommand);
  5827. dump_stack();
  5828. goto out_not_finished;
  5829. }
  5830. }
  5831. /* If the PCI channel is in offline state, do not post mbox. */
  5832. if (unlikely(pci_channel_offline(phba->pcidev))) {
  5833. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5834. goto out_not_finished;
  5835. }
  5836. /* If HBA has a deferred error attention, fail the iocb. */
  5837. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  5838. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5839. goto out_not_finished;
  5840. }
  5841. psli = &phba->sli;
  5842. mb = &pmbox->u.mb;
  5843. status = MBX_SUCCESS;
  5844. if (phba->link_state == LPFC_HBA_ERROR) {
  5845. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5846. /* Mbox command <mbxCommand> cannot issue */
  5847. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5848. "(%d):0311 Mailbox command x%x cannot "
  5849. "issue Data: x%x x%x\n",
  5850. pmbox->vport ? pmbox->vport->vpi : 0,
  5851. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  5852. goto out_not_finished;
  5853. }
  5854. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  5855. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  5856. !(hc_copy & HC_MBINT_ENA)) {
  5857. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5858. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5859. "(%d):2528 Mailbox command x%x cannot "
  5860. "issue Data: x%x x%x\n",
  5861. pmbox->vport ? pmbox->vport->vpi : 0,
  5862. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  5863. goto out_not_finished;
  5864. }
  5865. }
  5866. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5867. /* Polling for a mbox command when another one is already active
  5868. * is not allowed in SLI. Also, the driver must have established
  5869. * SLI2 mode to queue and process multiple mbox commands.
  5870. */
  5871. if (flag & MBX_POLL) {
  5872. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5873. /* Mbox command <mbxCommand> cannot issue */
  5874. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5875. "(%d):2529 Mailbox command x%x "
  5876. "cannot issue Data: x%x x%x\n",
  5877. pmbox->vport ? pmbox->vport->vpi : 0,
  5878. pmbox->u.mb.mbxCommand,
  5879. psli->sli_flag, flag);
  5880. goto out_not_finished;
  5881. }
  5882. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  5883. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5884. /* Mbox command <mbxCommand> cannot issue */
  5885. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5886. "(%d):2530 Mailbox command x%x "
  5887. "cannot issue Data: x%x x%x\n",
  5888. pmbox->vport ? pmbox->vport->vpi : 0,
  5889. pmbox->u.mb.mbxCommand,
  5890. psli->sli_flag, flag);
  5891. goto out_not_finished;
  5892. }
  5893. /* Another mailbox command is still being processed, queue this
  5894. * command to be processed later.
  5895. */
  5896. lpfc_mbox_put(phba, pmbox);
  5897. /* Mbox cmd issue - BUSY */
  5898. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5899. "(%d):0308 Mbox cmd issue - BUSY Data: "
  5900. "x%x x%x x%x x%x\n",
  5901. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  5902. mb->mbxCommand, phba->pport->port_state,
  5903. psli->sli_flag, flag);
  5904. psli->slistat.mbox_busy++;
  5905. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5906. if (pmbox->vport) {
  5907. lpfc_debugfs_disc_trc(pmbox->vport,
  5908. LPFC_DISC_TRC_MBOX_VPORT,
  5909. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  5910. (uint32_t)mb->mbxCommand,
  5911. mb->un.varWords[0], mb->un.varWords[1]);
  5912. }
  5913. else {
  5914. lpfc_debugfs_disc_trc(phba->pport,
  5915. LPFC_DISC_TRC_MBOX,
  5916. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  5917. (uint32_t)mb->mbxCommand,
  5918. mb->un.varWords[0], mb->un.varWords[1]);
  5919. }
  5920. return MBX_BUSY;
  5921. }
  5922. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5923. /* If we are not polling, we MUST be in SLI2 mode */
  5924. if (flag != MBX_POLL) {
  5925. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  5926. (mb->mbxCommand != MBX_KILL_BOARD)) {
  5927. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5928. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5929. /* Mbox command <mbxCommand> cannot issue */
  5930. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5931. "(%d):2531 Mailbox command x%x "
  5932. "cannot issue Data: x%x x%x\n",
  5933. pmbox->vport ? pmbox->vport->vpi : 0,
  5934. pmbox->u.mb.mbxCommand,
  5935. psli->sli_flag, flag);
  5936. goto out_not_finished;
  5937. }
  5938. /* timeout active mbox command */
  5939. mod_timer(&psli->mbox_tmo, (jiffies +
  5940. (HZ * lpfc_mbox_tmo_val(phba, pmbox))));
  5941. }
  5942. /* Mailbox cmd <cmd> issue */
  5943. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5944. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  5945. "x%x\n",
  5946. pmbox->vport ? pmbox->vport->vpi : 0,
  5947. mb->mbxCommand, phba->pport->port_state,
  5948. psli->sli_flag, flag);
  5949. if (mb->mbxCommand != MBX_HEARTBEAT) {
  5950. if (pmbox->vport) {
  5951. lpfc_debugfs_disc_trc(pmbox->vport,
  5952. LPFC_DISC_TRC_MBOX_VPORT,
  5953. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5954. (uint32_t)mb->mbxCommand,
  5955. mb->un.varWords[0], mb->un.varWords[1]);
  5956. }
  5957. else {
  5958. lpfc_debugfs_disc_trc(phba->pport,
  5959. LPFC_DISC_TRC_MBOX,
  5960. "MBOX Send: cmd:x%x mb:x%x x%x",
  5961. (uint32_t)mb->mbxCommand,
  5962. mb->un.varWords[0], mb->un.varWords[1]);
  5963. }
  5964. }
  5965. psli->slistat.mbox_cmd++;
  5966. evtctr = psli->slistat.mbox_event;
  5967. /* next set own bit for the adapter and copy over command word */
  5968. mb->mbxOwner = OWN_CHIP;
  5969. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  5970. /* Populate mbox extension offset word. */
  5971. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  5972. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  5973. = (uint8_t *)phba->mbox_ext
  5974. - (uint8_t *)phba->mbox;
  5975. }
  5976. /* Copy the mailbox extension data */
  5977. if (pmbox->in_ext_byte_len && pmbox->context2) {
  5978. lpfc_sli_pcimem_bcopy(pmbox->context2,
  5979. (uint8_t *)phba->mbox_ext,
  5980. pmbox->in_ext_byte_len);
  5981. }
  5982. /* Copy command data to host SLIM area */
  5983. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  5984. } else {
  5985. /* Populate mbox extension offset word. */
  5986. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  5987. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  5988. = MAILBOX_HBA_EXT_OFFSET;
  5989. /* Copy the mailbox extension data */
  5990. if (pmbox->in_ext_byte_len && pmbox->context2) {
  5991. lpfc_memcpy_to_slim(phba->MBslimaddr +
  5992. MAILBOX_HBA_EXT_OFFSET,
  5993. pmbox->context2, pmbox->in_ext_byte_len);
  5994. }
  5995. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  5996. /* copy command data into host mbox for cmpl */
  5997. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  5998. }
  5999. /* First copy mbox command data to HBA SLIM, skip past first
  6000. word */
  6001. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6002. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  6003. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6004. /* Next copy over first word, with mbxOwner set */
  6005. ldata = *((uint32_t *)mb);
  6006. to_slim = phba->MBslimaddr;
  6007. writel(ldata, to_slim);
  6008. readl(to_slim); /* flush */
  6009. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6010. /* switch over to host mailbox */
  6011. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6012. }
  6013. }
  6014. wmb();
  6015. switch (flag) {
  6016. case MBX_NOWAIT:
  6017. /* Set up reference to mailbox command */
  6018. psli->mbox_active = pmbox;
  6019. /* Interrupt board to do it */
  6020. writel(CA_MBATT, phba->CAregaddr);
  6021. readl(phba->CAregaddr); /* flush */
  6022. /* Don't wait for it to finish, just return */
  6023. break;
  6024. case MBX_POLL:
  6025. /* Set up null reference to mailbox command */
  6026. psli->mbox_active = NULL;
  6027. /* Interrupt board to do it */
  6028. writel(CA_MBATT, phba->CAregaddr);
  6029. readl(phba->CAregaddr); /* flush */
  6030. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6031. /* First read mbox status word */
  6032. word0 = *((uint32_t *)phba->mbox);
  6033. word0 = le32_to_cpu(word0);
  6034. } else {
  6035. /* First read mbox status word */
  6036. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6037. spin_unlock_irqrestore(&phba->hbalock,
  6038. drvr_flag);
  6039. goto out_not_finished;
  6040. }
  6041. }
  6042. /* Read the HBA Host Attention Register */
  6043. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6044. spin_unlock_irqrestore(&phba->hbalock,
  6045. drvr_flag);
  6046. goto out_not_finished;
  6047. }
  6048. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6049. 1000) + jiffies;
  6050. i = 0;
  6051. /* Wait for command to complete */
  6052. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6053. (!(ha_copy & HA_MBATT) &&
  6054. (phba->link_state > LPFC_WARM_START))) {
  6055. if (time_after(jiffies, timeout)) {
  6056. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6057. spin_unlock_irqrestore(&phba->hbalock,
  6058. drvr_flag);
  6059. goto out_not_finished;
  6060. }
  6061. /* Check if we took a mbox interrupt while we were
  6062. polling */
  6063. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6064. && (evtctr != psli->slistat.mbox_event))
  6065. break;
  6066. if (i++ > 10) {
  6067. spin_unlock_irqrestore(&phba->hbalock,
  6068. drvr_flag);
  6069. msleep(1);
  6070. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6071. }
  6072. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6073. /* First copy command data */
  6074. word0 = *((uint32_t *)phba->mbox);
  6075. word0 = le32_to_cpu(word0);
  6076. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6077. MAILBOX_t *slimmb;
  6078. uint32_t slimword0;
  6079. /* Check real SLIM for any errors */
  6080. slimword0 = readl(phba->MBslimaddr);
  6081. slimmb = (MAILBOX_t *) & slimword0;
  6082. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6083. && slimmb->mbxStatus) {
  6084. psli->sli_flag &=
  6085. ~LPFC_SLI_ACTIVE;
  6086. word0 = slimword0;
  6087. }
  6088. }
  6089. } else {
  6090. /* First copy command data */
  6091. word0 = readl(phba->MBslimaddr);
  6092. }
  6093. /* Read the HBA Host Attention Register */
  6094. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6095. spin_unlock_irqrestore(&phba->hbalock,
  6096. drvr_flag);
  6097. goto out_not_finished;
  6098. }
  6099. }
  6100. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6101. /* copy results back to user */
  6102. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  6103. /* Copy the mailbox extension data */
  6104. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6105. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6106. pmbox->context2,
  6107. pmbox->out_ext_byte_len);
  6108. }
  6109. } else {
  6110. /* First copy command data */
  6111. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  6112. MAILBOX_CMD_SIZE);
  6113. /* Copy the mailbox extension data */
  6114. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6115. lpfc_memcpy_from_slim(pmbox->context2,
  6116. phba->MBslimaddr +
  6117. MAILBOX_HBA_EXT_OFFSET,
  6118. pmbox->out_ext_byte_len);
  6119. }
  6120. }
  6121. writel(HA_MBATT, phba->HAregaddr);
  6122. readl(phba->HAregaddr); /* flush */
  6123. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6124. status = mb->mbxStatus;
  6125. }
  6126. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6127. return status;
  6128. out_not_finished:
  6129. if (processing_queue) {
  6130. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6131. lpfc_mbox_cmpl_put(phba, pmbox);
  6132. }
  6133. return MBX_NOT_FINISHED;
  6134. }
  6135. /**
  6136. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6137. * @phba: Pointer to HBA context object.
  6138. *
  6139. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6140. * the driver internal pending mailbox queue. It will then try to wait out the
  6141. * possible outstanding mailbox command before return.
  6142. *
  6143. * Returns:
  6144. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6145. * the outstanding mailbox command timed out.
  6146. **/
  6147. static int
  6148. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6149. {
  6150. struct lpfc_sli *psli = &phba->sli;
  6151. int rc = 0;
  6152. unsigned long timeout = 0;
  6153. /* Mark the asynchronous mailbox command posting as blocked */
  6154. spin_lock_irq(&phba->hbalock);
  6155. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6156. /* Determine how long we might wait for the active mailbox
  6157. * command to be gracefully completed by firmware.
  6158. */
  6159. if (phba->sli.mbox_active)
  6160. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6161. phba->sli.mbox_active) *
  6162. 1000) + jiffies;
  6163. spin_unlock_irq(&phba->hbalock);
  6164. /* Wait for the outstnading mailbox command to complete */
  6165. while (phba->sli.mbox_active) {
  6166. /* Check active mailbox complete status every 2ms */
  6167. msleep(2);
  6168. if (time_after(jiffies, timeout)) {
  6169. /* Timeout, marked the outstanding cmd not complete */
  6170. rc = 1;
  6171. break;
  6172. }
  6173. }
  6174. /* Can not cleanly block async mailbox command, fails it */
  6175. if (rc) {
  6176. spin_lock_irq(&phba->hbalock);
  6177. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6178. spin_unlock_irq(&phba->hbalock);
  6179. }
  6180. return rc;
  6181. }
  6182. /**
  6183. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6184. * @phba: Pointer to HBA context object.
  6185. *
  6186. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6187. * commands from the driver internal pending mailbox queue. It makes sure
  6188. * that there is no outstanding mailbox command before resuming posting
  6189. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6190. * mailbox command, it will try to wait it out before resuming asynchronous
  6191. * mailbox command posting.
  6192. **/
  6193. static void
  6194. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6195. {
  6196. struct lpfc_sli *psli = &phba->sli;
  6197. spin_lock_irq(&phba->hbalock);
  6198. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6199. /* Asynchronous mailbox posting is not blocked, do nothing */
  6200. spin_unlock_irq(&phba->hbalock);
  6201. return;
  6202. }
  6203. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6204. * successful or timeout, after timing-out the outstanding mailbox
  6205. * command shall always be removed, so just unblock posting async
  6206. * mailbox command and resume
  6207. */
  6208. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6209. spin_unlock_irq(&phba->hbalock);
  6210. /* wake up worker thread to post asynchronlous mailbox command */
  6211. lpfc_worker_wake_up(phba);
  6212. }
  6213. /**
  6214. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6215. * @phba: Pointer to HBA context object.
  6216. * @mboxq: Pointer to mailbox object.
  6217. *
  6218. * The function posts a mailbox to the port. The mailbox is expected
  6219. * to be comletely filled in and ready for the port to operate on it.
  6220. * This routine executes a synchronous completion operation on the
  6221. * mailbox by polling for its completion.
  6222. *
  6223. * The caller must not be holding any locks when calling this routine.
  6224. *
  6225. * Returns:
  6226. * MBX_SUCCESS - mailbox posted successfully
  6227. * Any of the MBX error values.
  6228. **/
  6229. static int
  6230. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6231. {
  6232. int rc = MBX_SUCCESS;
  6233. unsigned long iflag;
  6234. uint32_t db_ready;
  6235. uint32_t mcqe_status;
  6236. uint32_t mbx_cmnd;
  6237. unsigned long timeout;
  6238. struct lpfc_sli *psli = &phba->sli;
  6239. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6240. struct lpfc_bmbx_create *mbox_rgn;
  6241. struct dma_address *dma_address;
  6242. struct lpfc_register bmbx_reg;
  6243. /*
  6244. * Only one mailbox can be active to the bootstrap mailbox region
  6245. * at a time and there is no queueing provided.
  6246. */
  6247. spin_lock_irqsave(&phba->hbalock, iflag);
  6248. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6249. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6250. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6251. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6252. "cannot issue Data: x%x x%x\n",
  6253. mboxq->vport ? mboxq->vport->vpi : 0,
  6254. mboxq->u.mb.mbxCommand,
  6255. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6256. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6257. psli->sli_flag, MBX_POLL);
  6258. return MBXERR_ERROR;
  6259. }
  6260. /* The server grabs the token and owns it until release */
  6261. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6262. phba->sli.mbox_active = mboxq;
  6263. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6264. /*
  6265. * Initialize the bootstrap memory region to avoid stale data areas
  6266. * in the mailbox post. Then copy the caller's mailbox contents to
  6267. * the bmbx mailbox region.
  6268. */
  6269. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6270. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6271. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6272. sizeof(struct lpfc_mqe));
  6273. /* Post the high mailbox dma address to the port and wait for ready. */
  6274. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6275. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6276. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6277. * 1000) + jiffies;
  6278. do {
  6279. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6280. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6281. if (!db_ready)
  6282. msleep(2);
  6283. if (time_after(jiffies, timeout)) {
  6284. rc = MBXERR_ERROR;
  6285. goto exit;
  6286. }
  6287. } while (!db_ready);
  6288. /* Post the low mailbox dma address to the port. */
  6289. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6290. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6291. * 1000) + jiffies;
  6292. do {
  6293. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6294. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6295. if (!db_ready)
  6296. msleep(2);
  6297. if (time_after(jiffies, timeout)) {
  6298. rc = MBXERR_ERROR;
  6299. goto exit;
  6300. }
  6301. } while (!db_ready);
  6302. /*
  6303. * Read the CQ to ensure the mailbox has completed.
  6304. * If so, update the mailbox status so that the upper layers
  6305. * can complete the request normally.
  6306. */
  6307. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6308. sizeof(struct lpfc_mqe));
  6309. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6310. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6311. sizeof(struct lpfc_mcqe));
  6312. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6313. /*
  6314. * When the CQE status indicates a failure and the mailbox status
  6315. * indicates success then copy the CQE status into the mailbox status
  6316. * (and prefix it with x4000).
  6317. */
  6318. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6319. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6320. bf_set(lpfc_mqe_status, mb,
  6321. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6322. rc = MBXERR_ERROR;
  6323. } else
  6324. lpfc_sli4_swap_str(phba, mboxq);
  6325. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6326. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6327. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6328. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6329. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6330. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6331. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6332. bf_get(lpfc_mqe_status, mb),
  6333. mb->un.mb_words[0], mb->un.mb_words[1],
  6334. mb->un.mb_words[2], mb->un.mb_words[3],
  6335. mb->un.mb_words[4], mb->un.mb_words[5],
  6336. mb->un.mb_words[6], mb->un.mb_words[7],
  6337. mb->un.mb_words[8], mb->un.mb_words[9],
  6338. mb->un.mb_words[10], mb->un.mb_words[11],
  6339. mb->un.mb_words[12], mboxq->mcqe.word0,
  6340. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6341. mboxq->mcqe.trailer);
  6342. exit:
  6343. /* We are holding the token, no needed for lock when release */
  6344. spin_lock_irqsave(&phba->hbalock, iflag);
  6345. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6346. phba->sli.mbox_active = NULL;
  6347. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6348. return rc;
  6349. }
  6350. /**
  6351. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6352. * @phba: Pointer to HBA context object.
  6353. * @pmbox: Pointer to mailbox object.
  6354. * @flag: Flag indicating how the mailbox need to be processed.
  6355. *
  6356. * This function is called by discovery code and HBA management code to submit
  6357. * a mailbox command to firmware with SLI-4 interface spec.
  6358. *
  6359. * Return codes the caller owns the mailbox command after the return of the
  6360. * function.
  6361. **/
  6362. static int
  6363. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6364. uint32_t flag)
  6365. {
  6366. struct lpfc_sli *psli = &phba->sli;
  6367. unsigned long iflags;
  6368. int rc;
  6369. /* dump from issue mailbox command if setup */
  6370. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6371. rc = lpfc_mbox_dev_check(phba);
  6372. if (unlikely(rc)) {
  6373. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6374. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6375. "cannot issue Data: x%x x%x\n",
  6376. mboxq->vport ? mboxq->vport->vpi : 0,
  6377. mboxq->u.mb.mbxCommand,
  6378. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6379. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6380. psli->sli_flag, flag);
  6381. goto out_not_finished;
  6382. }
  6383. /* Detect polling mode and jump to a handler */
  6384. if (!phba->sli4_hba.intr_enable) {
  6385. if (flag == MBX_POLL)
  6386. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6387. else
  6388. rc = -EIO;
  6389. if (rc != MBX_SUCCESS)
  6390. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6391. "(%d):2541 Mailbox command x%x "
  6392. "(x%x/x%x) cannot issue Data: "
  6393. "x%x x%x\n",
  6394. mboxq->vport ? mboxq->vport->vpi : 0,
  6395. mboxq->u.mb.mbxCommand,
  6396. lpfc_sli_config_mbox_subsys_get(phba,
  6397. mboxq),
  6398. lpfc_sli_config_mbox_opcode_get(phba,
  6399. mboxq),
  6400. psli->sli_flag, flag);
  6401. return rc;
  6402. } else if (flag == MBX_POLL) {
  6403. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6404. "(%d):2542 Try to issue mailbox command "
  6405. "x%x (x%x/x%x) synchronously ahead of async"
  6406. "mailbox command queue: x%x x%x\n",
  6407. mboxq->vport ? mboxq->vport->vpi : 0,
  6408. mboxq->u.mb.mbxCommand,
  6409. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6410. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6411. psli->sli_flag, flag);
  6412. /* Try to block the asynchronous mailbox posting */
  6413. rc = lpfc_sli4_async_mbox_block(phba);
  6414. if (!rc) {
  6415. /* Successfully blocked, now issue sync mbox cmd */
  6416. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6417. if (rc != MBX_SUCCESS)
  6418. lpfc_printf_log(phba, KERN_ERR,
  6419. LOG_MBOX | LOG_SLI,
  6420. "(%d):2597 Mailbox command "
  6421. "x%x (x%x/x%x) cannot issue "
  6422. "Data: x%x x%x\n",
  6423. mboxq->vport ?
  6424. mboxq->vport->vpi : 0,
  6425. mboxq->u.mb.mbxCommand,
  6426. lpfc_sli_config_mbox_subsys_get(phba,
  6427. mboxq),
  6428. lpfc_sli_config_mbox_opcode_get(phba,
  6429. mboxq),
  6430. psli->sli_flag, flag);
  6431. /* Unblock the async mailbox posting afterward */
  6432. lpfc_sli4_async_mbox_unblock(phba);
  6433. }
  6434. return rc;
  6435. }
  6436. /* Now, interrupt mode asynchrous mailbox command */
  6437. rc = lpfc_mbox_cmd_check(phba, mboxq);
  6438. if (rc) {
  6439. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6440. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  6441. "cannot issue Data: 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. goto out_not_finished;
  6448. }
  6449. /* Put the mailbox command to the driver internal FIFO */
  6450. psli->slistat.mbox_busy++;
  6451. spin_lock_irqsave(&phba->hbalock, iflags);
  6452. lpfc_mbox_put(phba, mboxq);
  6453. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6454. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6455. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  6456. "x%x (x%x/x%x) x%x x%x x%x\n",
  6457. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  6458. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  6459. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6460. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6461. phba->pport->port_state,
  6462. psli->sli_flag, MBX_NOWAIT);
  6463. /* Wake up worker thread to transport mailbox command from head */
  6464. lpfc_worker_wake_up(phba);
  6465. return MBX_BUSY;
  6466. out_not_finished:
  6467. return MBX_NOT_FINISHED;
  6468. }
  6469. /**
  6470. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  6471. * @phba: Pointer to HBA context object.
  6472. *
  6473. * This function is called by worker thread to send a mailbox command to
  6474. * SLI4 HBA firmware.
  6475. *
  6476. **/
  6477. int
  6478. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  6479. {
  6480. struct lpfc_sli *psli = &phba->sli;
  6481. LPFC_MBOXQ_t *mboxq;
  6482. int rc = MBX_SUCCESS;
  6483. unsigned long iflags;
  6484. struct lpfc_mqe *mqe;
  6485. uint32_t mbx_cmnd;
  6486. /* Check interrupt mode before post async mailbox command */
  6487. if (unlikely(!phba->sli4_hba.intr_enable))
  6488. return MBX_NOT_FINISHED;
  6489. /* Check for mailbox command service token */
  6490. spin_lock_irqsave(&phba->hbalock, iflags);
  6491. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6492. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6493. return MBX_NOT_FINISHED;
  6494. }
  6495. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6496. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6497. return MBX_NOT_FINISHED;
  6498. }
  6499. if (unlikely(phba->sli.mbox_active)) {
  6500. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6501. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6502. "0384 There is pending active mailbox cmd\n");
  6503. return MBX_NOT_FINISHED;
  6504. }
  6505. /* Take the mailbox command service token */
  6506. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6507. /* Get the next mailbox command from head of queue */
  6508. mboxq = lpfc_mbox_get(phba);
  6509. /* If no more mailbox command waiting for post, we're done */
  6510. if (!mboxq) {
  6511. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6512. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6513. return MBX_SUCCESS;
  6514. }
  6515. phba->sli.mbox_active = mboxq;
  6516. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6517. /* Check device readiness for posting mailbox command */
  6518. rc = lpfc_mbox_dev_check(phba);
  6519. if (unlikely(rc))
  6520. /* Driver clean routine will clean up pending mailbox */
  6521. goto out_not_finished;
  6522. /* Prepare the mbox command to be posted */
  6523. mqe = &mboxq->u.mqe;
  6524. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  6525. /* Start timer for the mbox_tmo and log some mailbox post messages */
  6526. mod_timer(&psli->mbox_tmo, (jiffies +
  6527. (HZ * lpfc_mbox_tmo_val(phba, mboxq))));
  6528. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6529. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  6530. "x%x x%x\n",
  6531. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6532. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6533. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6534. phba->pport->port_state, psli->sli_flag);
  6535. if (mbx_cmnd != MBX_HEARTBEAT) {
  6536. if (mboxq->vport) {
  6537. lpfc_debugfs_disc_trc(mboxq->vport,
  6538. LPFC_DISC_TRC_MBOX_VPORT,
  6539. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6540. mbx_cmnd, mqe->un.mb_words[0],
  6541. mqe->un.mb_words[1]);
  6542. } else {
  6543. lpfc_debugfs_disc_trc(phba->pport,
  6544. LPFC_DISC_TRC_MBOX,
  6545. "MBOX Send: cmd:x%x mb:x%x x%x",
  6546. mbx_cmnd, mqe->un.mb_words[0],
  6547. mqe->un.mb_words[1]);
  6548. }
  6549. }
  6550. psli->slistat.mbox_cmd++;
  6551. /* Post the mailbox command to the port */
  6552. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  6553. if (rc != MBX_SUCCESS) {
  6554. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6555. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  6556. "cannot issue Data: x%x x%x\n",
  6557. mboxq->vport ? mboxq->vport->vpi : 0,
  6558. mboxq->u.mb.mbxCommand,
  6559. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6560. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6561. psli->sli_flag, MBX_NOWAIT);
  6562. goto out_not_finished;
  6563. }
  6564. return rc;
  6565. out_not_finished:
  6566. spin_lock_irqsave(&phba->hbalock, iflags);
  6567. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6568. __lpfc_mbox_cmpl_put(phba, mboxq);
  6569. /* Release the token */
  6570. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6571. phba->sli.mbox_active = NULL;
  6572. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6573. return MBX_NOT_FINISHED;
  6574. }
  6575. /**
  6576. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  6577. * @phba: Pointer to HBA context object.
  6578. * @pmbox: Pointer to mailbox object.
  6579. * @flag: Flag indicating how the mailbox need to be processed.
  6580. *
  6581. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  6582. * the API jump table function pointer from the lpfc_hba struct.
  6583. *
  6584. * Return codes the caller owns the mailbox command after the return of the
  6585. * function.
  6586. **/
  6587. int
  6588. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  6589. {
  6590. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  6591. }
  6592. /**
  6593. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  6594. * @phba: The hba struct for which this call is being executed.
  6595. * @dev_grp: The HBA PCI-Device group number.
  6596. *
  6597. * This routine sets up the mbox interface API function jump table in @phba
  6598. * struct.
  6599. * Returns: 0 - success, -ENODEV - failure.
  6600. **/
  6601. int
  6602. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6603. {
  6604. switch (dev_grp) {
  6605. case LPFC_PCI_DEV_LP:
  6606. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  6607. phba->lpfc_sli_handle_slow_ring_event =
  6608. lpfc_sli_handle_slow_ring_event_s3;
  6609. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  6610. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  6611. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  6612. break;
  6613. case LPFC_PCI_DEV_OC:
  6614. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  6615. phba->lpfc_sli_handle_slow_ring_event =
  6616. lpfc_sli_handle_slow_ring_event_s4;
  6617. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  6618. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  6619. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  6620. break;
  6621. default:
  6622. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6623. "1420 Invalid HBA PCI-device group: 0x%x\n",
  6624. dev_grp);
  6625. return -ENODEV;
  6626. break;
  6627. }
  6628. return 0;
  6629. }
  6630. /**
  6631. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  6632. * @phba: Pointer to HBA context object.
  6633. * @pring: Pointer to driver SLI ring object.
  6634. * @piocb: Pointer to address of newly added command iocb.
  6635. *
  6636. * This function is called with hbalock held to add a command
  6637. * iocb to the txq when SLI layer cannot submit the command iocb
  6638. * to the ring.
  6639. **/
  6640. void
  6641. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6642. struct lpfc_iocbq *piocb)
  6643. {
  6644. /* Insert the caller's iocb in the txq tail for later processing. */
  6645. list_add_tail(&piocb->list, &pring->txq);
  6646. pring->txq_cnt++;
  6647. }
  6648. /**
  6649. * lpfc_sli_next_iocb - Get the next iocb in the txq
  6650. * @phba: Pointer to HBA context object.
  6651. * @pring: Pointer to driver SLI ring object.
  6652. * @piocb: Pointer to address of newly added command iocb.
  6653. *
  6654. * This function is called with hbalock held before a new
  6655. * iocb is submitted to the firmware. This function checks
  6656. * txq to flush the iocbs in txq to Firmware before
  6657. * submitting new iocbs to the Firmware.
  6658. * If there are iocbs in the txq which need to be submitted
  6659. * to firmware, lpfc_sli_next_iocb returns the first element
  6660. * of the txq after dequeuing it from txq.
  6661. * If there is no iocb in the txq then the function will return
  6662. * *piocb and *piocb is set to NULL. Caller needs to check
  6663. * *piocb to find if there are more commands in the txq.
  6664. **/
  6665. static struct lpfc_iocbq *
  6666. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6667. struct lpfc_iocbq **piocb)
  6668. {
  6669. struct lpfc_iocbq * nextiocb;
  6670. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  6671. if (!nextiocb) {
  6672. nextiocb = *piocb;
  6673. *piocb = NULL;
  6674. }
  6675. return nextiocb;
  6676. }
  6677. /**
  6678. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  6679. * @phba: Pointer to HBA context object.
  6680. * @ring_number: SLI ring number to issue iocb on.
  6681. * @piocb: Pointer to command iocb.
  6682. * @flag: Flag indicating if this command can be put into txq.
  6683. *
  6684. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  6685. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  6686. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  6687. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  6688. * this function allows only iocbs for posting buffers. This function finds
  6689. * next available slot in the command ring and posts the command to the
  6690. * available slot and writes the port attention register to request HBA start
  6691. * processing new iocb. If there is no slot available in the ring and
  6692. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  6693. * the function returns IOCB_BUSY.
  6694. *
  6695. * This function is called with hbalock held. The function will return success
  6696. * after it successfully submit the iocb to firmware or after adding to the
  6697. * txq.
  6698. **/
  6699. static int
  6700. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  6701. struct lpfc_iocbq *piocb, uint32_t flag)
  6702. {
  6703. struct lpfc_iocbq *nextiocb;
  6704. IOCB_t *iocb;
  6705. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6706. if (piocb->iocb_cmpl && (!piocb->vport) &&
  6707. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  6708. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  6709. lpfc_printf_log(phba, KERN_ERR,
  6710. LOG_SLI | LOG_VPORT,
  6711. "1807 IOCB x%x failed. No vport\n",
  6712. piocb->iocb.ulpCommand);
  6713. dump_stack();
  6714. return IOCB_ERROR;
  6715. }
  6716. /* If the PCI channel is in offline state, do not post iocbs. */
  6717. if (unlikely(pci_channel_offline(phba->pcidev)))
  6718. return IOCB_ERROR;
  6719. /* If HBA has a deferred error attention, fail the iocb. */
  6720. if (unlikely(phba->hba_flag & DEFER_ERATT))
  6721. return IOCB_ERROR;
  6722. /*
  6723. * We should never get an IOCB if we are in a < LINK_DOWN state
  6724. */
  6725. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  6726. return IOCB_ERROR;
  6727. /*
  6728. * Check to see if we are blocking IOCB processing because of a
  6729. * outstanding event.
  6730. */
  6731. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  6732. goto iocb_busy;
  6733. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  6734. /*
  6735. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  6736. * can be issued if the link is not up.
  6737. */
  6738. switch (piocb->iocb.ulpCommand) {
  6739. case CMD_GEN_REQUEST64_CR:
  6740. case CMD_GEN_REQUEST64_CX:
  6741. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  6742. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  6743. FC_RCTL_DD_UNSOL_CMD) ||
  6744. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  6745. MENLO_TRANSPORT_TYPE))
  6746. goto iocb_busy;
  6747. break;
  6748. case CMD_QUE_RING_BUF_CN:
  6749. case CMD_QUE_RING_BUF64_CN:
  6750. /*
  6751. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  6752. * completion, iocb_cmpl MUST be 0.
  6753. */
  6754. if (piocb->iocb_cmpl)
  6755. piocb->iocb_cmpl = NULL;
  6756. /*FALLTHROUGH*/
  6757. case CMD_CREATE_XRI_CR:
  6758. case CMD_CLOSE_XRI_CN:
  6759. case CMD_CLOSE_XRI_CX:
  6760. break;
  6761. default:
  6762. goto iocb_busy;
  6763. }
  6764. /*
  6765. * For FCP commands, we must be in a state where we can process link
  6766. * attention events.
  6767. */
  6768. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  6769. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  6770. goto iocb_busy;
  6771. }
  6772. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  6773. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  6774. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  6775. if (iocb)
  6776. lpfc_sli_update_ring(phba, pring);
  6777. else
  6778. lpfc_sli_update_full_ring(phba, pring);
  6779. if (!piocb)
  6780. return IOCB_SUCCESS;
  6781. goto out_busy;
  6782. iocb_busy:
  6783. pring->stats.iocb_cmd_delay++;
  6784. out_busy:
  6785. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6786. __lpfc_sli_ringtx_put(phba, pring, piocb);
  6787. return IOCB_SUCCESS;
  6788. }
  6789. return IOCB_BUSY;
  6790. }
  6791. /**
  6792. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  6793. * @phba: Pointer to HBA context object.
  6794. * @piocb: Pointer to command iocb.
  6795. * @sglq: Pointer to the scatter gather queue object.
  6796. *
  6797. * This routine converts the bpl or bde that is in the IOCB
  6798. * to a sgl list for the sli4 hardware. The physical address
  6799. * of the bpl/bde is converted back to a virtual address.
  6800. * If the IOCB contains a BPL then the list of BDE's is
  6801. * converted to sli4_sge's. If the IOCB contains a single
  6802. * BDE then it is converted to a single sli_sge.
  6803. * The IOCB is still in cpu endianess so the contents of
  6804. * the bpl can be used without byte swapping.
  6805. *
  6806. * Returns valid XRI = Success, NO_XRI = Failure.
  6807. **/
  6808. static uint16_t
  6809. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  6810. struct lpfc_sglq *sglq)
  6811. {
  6812. uint16_t xritag = NO_XRI;
  6813. struct ulp_bde64 *bpl = NULL;
  6814. struct ulp_bde64 bde;
  6815. struct sli4_sge *sgl = NULL;
  6816. IOCB_t *icmd;
  6817. int numBdes = 0;
  6818. int i = 0;
  6819. uint32_t offset = 0; /* accumulated offset in the sg request list */
  6820. int inbound = 0; /* number of sg reply entries inbound from firmware */
  6821. if (!piocbq || !sglq)
  6822. return xritag;
  6823. sgl = (struct sli4_sge *)sglq->sgl;
  6824. icmd = &piocbq->iocb;
  6825. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  6826. numBdes = icmd->un.genreq64.bdl.bdeSize /
  6827. sizeof(struct ulp_bde64);
  6828. /* The addrHigh and addrLow fields within the IOCB
  6829. * have not been byteswapped yet so there is no
  6830. * need to swap them back.
  6831. */
  6832. bpl = (struct ulp_bde64 *)
  6833. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  6834. if (!bpl)
  6835. return xritag;
  6836. for (i = 0; i < numBdes; i++) {
  6837. /* Should already be byte swapped. */
  6838. sgl->addr_hi = bpl->addrHigh;
  6839. sgl->addr_lo = bpl->addrLow;
  6840. sgl->word2 = le32_to_cpu(sgl->word2);
  6841. if ((i+1) == numBdes)
  6842. bf_set(lpfc_sli4_sge_last, sgl, 1);
  6843. else
  6844. bf_set(lpfc_sli4_sge_last, sgl, 0);
  6845. /* swap the size field back to the cpu so we
  6846. * can assign it to the sgl.
  6847. */
  6848. bde.tus.w = le32_to_cpu(bpl->tus.w);
  6849. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  6850. /* The offsets in the sgl need to be accumulated
  6851. * separately for the request and reply lists.
  6852. * The request is always first, the reply follows.
  6853. */
  6854. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  6855. /* add up the reply sg entries */
  6856. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  6857. inbound++;
  6858. /* first inbound? reset the offset */
  6859. if (inbound == 1)
  6860. offset = 0;
  6861. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  6862. bf_set(lpfc_sli4_sge_type, sgl,
  6863. LPFC_SGE_TYPE_DATA);
  6864. offset += bde.tus.f.bdeSize;
  6865. }
  6866. sgl->word2 = cpu_to_le32(sgl->word2);
  6867. bpl++;
  6868. sgl++;
  6869. }
  6870. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  6871. /* The addrHigh and addrLow fields of the BDE have not
  6872. * been byteswapped yet so they need to be swapped
  6873. * before putting them in the sgl.
  6874. */
  6875. sgl->addr_hi =
  6876. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  6877. sgl->addr_lo =
  6878. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  6879. sgl->word2 = le32_to_cpu(sgl->word2);
  6880. bf_set(lpfc_sli4_sge_last, sgl, 1);
  6881. sgl->word2 = cpu_to_le32(sgl->word2);
  6882. sgl->sge_len =
  6883. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  6884. }
  6885. return sglq->sli4_xritag;
  6886. }
  6887. /**
  6888. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  6889. * @phba: Pointer to HBA context object.
  6890. *
  6891. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  6892. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  6893. * held.
  6894. *
  6895. * Return: index into SLI4 fast-path FCP queue index.
  6896. **/
  6897. static uint32_t
  6898. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  6899. {
  6900. ++phba->fcp_qidx;
  6901. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  6902. phba->fcp_qidx = 0;
  6903. return phba->fcp_qidx;
  6904. }
  6905. /**
  6906. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  6907. * @phba: Pointer to HBA context object.
  6908. * @piocb: Pointer to command iocb.
  6909. * @wqe: Pointer to the work queue entry.
  6910. *
  6911. * This routine converts the iocb command to its Work Queue Entry
  6912. * equivalent. The wqe pointer should not have any fields set when
  6913. * this routine is called because it will memcpy over them.
  6914. * This routine does not set the CQ_ID or the WQEC bits in the
  6915. * wqe.
  6916. *
  6917. * Returns: 0 = Success, IOCB_ERROR = Failure.
  6918. **/
  6919. static int
  6920. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  6921. union lpfc_wqe *wqe)
  6922. {
  6923. uint32_t xmit_len = 0, total_len = 0;
  6924. uint8_t ct = 0;
  6925. uint32_t fip;
  6926. uint32_t abort_tag;
  6927. uint8_t command_type = ELS_COMMAND_NON_FIP;
  6928. uint8_t cmnd;
  6929. uint16_t xritag;
  6930. uint16_t abrt_iotag;
  6931. struct lpfc_iocbq *abrtiocbq;
  6932. struct ulp_bde64 *bpl = NULL;
  6933. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  6934. int numBdes, i;
  6935. struct ulp_bde64 bde;
  6936. struct lpfc_nodelist *ndlp;
  6937. uint32_t *pcmd;
  6938. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  6939. /* The fcp commands will set command type */
  6940. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6941. command_type = FCP_COMMAND;
  6942. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  6943. command_type = ELS_COMMAND_FIP;
  6944. else
  6945. command_type = ELS_COMMAND_NON_FIP;
  6946. /* Some of the fields are in the right position already */
  6947. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  6948. abort_tag = (uint32_t) iocbq->iotag;
  6949. xritag = iocbq->sli4_xritag;
  6950. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  6951. /* words0-2 bpl convert bde */
  6952. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  6953. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  6954. sizeof(struct ulp_bde64);
  6955. bpl = (struct ulp_bde64 *)
  6956. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  6957. if (!bpl)
  6958. return IOCB_ERROR;
  6959. /* Should already be byte swapped. */
  6960. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  6961. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  6962. /* swap the size field back to the cpu so we
  6963. * can assign it to the sgl.
  6964. */
  6965. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  6966. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  6967. total_len = 0;
  6968. for (i = 0; i < numBdes; i++) {
  6969. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  6970. total_len += bde.tus.f.bdeSize;
  6971. }
  6972. } else
  6973. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  6974. iocbq->iocb.ulpIoTag = iocbq->iotag;
  6975. cmnd = iocbq->iocb.ulpCommand;
  6976. switch (iocbq->iocb.ulpCommand) {
  6977. case CMD_ELS_REQUEST64_CR:
  6978. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  6979. if (!iocbq->iocb.ulpLe) {
  6980. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6981. "2007 Only Limited Edition cmd Format"
  6982. " supported 0x%x\n",
  6983. iocbq->iocb.ulpCommand);
  6984. return IOCB_ERROR;
  6985. }
  6986. wqe->els_req.payload_len = xmit_len;
  6987. /* Els_reguest64 has a TMO */
  6988. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  6989. iocbq->iocb.ulpTimeout);
  6990. /* Need a VF for word 4 set the vf bit*/
  6991. bf_set(els_req64_vf, &wqe->els_req, 0);
  6992. /* And a VFID for word 12 */
  6993. bf_set(els_req64_vfid, &wqe->els_req, 0);
  6994. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  6995. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  6996. iocbq->iocb.ulpContext);
  6997. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  6998. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  6999. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7000. if (command_type == ELS_COMMAND_FIP)
  7001. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7002. >> LPFC_FIP_ELS_ID_SHIFT);
  7003. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7004. iocbq->context2)->virt);
  7005. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7006. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7007. *pcmd == ELS_CMD_SCR ||
  7008. *pcmd == ELS_CMD_PLOGI)) {
  7009. bf_set(els_req64_sp, &wqe->els_req, 1);
  7010. bf_set(els_req64_sid, &wqe->els_req,
  7011. iocbq->vport->fc_myDID);
  7012. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7013. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7014. phba->vpi_ids[phba->pport->vpi]);
  7015. } else if (iocbq->context1) {
  7016. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7017. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7018. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7019. }
  7020. }
  7021. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7022. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7023. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7024. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7025. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7026. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7027. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7028. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7029. break;
  7030. case CMD_XMIT_SEQUENCE64_CX:
  7031. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7032. iocbq->iocb.un.ulpWord[3]);
  7033. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7034. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7035. /* The entire sequence is transmitted for this IOCB */
  7036. xmit_len = total_len;
  7037. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7038. case CMD_XMIT_SEQUENCE64_CR:
  7039. /* word3 iocb=io_tag32 wqe=reserved */
  7040. wqe->xmit_sequence.rsvd3 = 0;
  7041. /* word4 relative_offset memcpy */
  7042. /* word5 r_ctl/df_ctl memcpy */
  7043. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7044. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7045. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7046. LPFC_WQE_IOD_WRITE);
  7047. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7048. LPFC_WQE_LENLOC_WORD12);
  7049. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7050. wqe->xmit_sequence.xmit_len = xmit_len;
  7051. command_type = OTHER_COMMAND;
  7052. break;
  7053. case CMD_XMIT_BCAST64_CN:
  7054. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7055. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7056. /* word4 iocb=rsvd wqe=rsvd */
  7057. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7058. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7059. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7060. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7061. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7062. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7063. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7064. LPFC_WQE_LENLOC_WORD3);
  7065. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7066. break;
  7067. case CMD_FCP_IWRITE64_CR:
  7068. command_type = FCP_COMMAND_DATA_OUT;
  7069. /* word3 iocb=iotag wqe=payload_offset_len */
  7070. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7071. wqe->fcp_iwrite.payload_offset_len =
  7072. xmit_len + sizeof(struct fcp_rsp);
  7073. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7074. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7075. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7076. iocbq->iocb.ulpFCP2Rcvy);
  7077. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7078. /* Always open the exchange */
  7079. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  7080. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7081. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7082. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7083. LPFC_WQE_LENLOC_WORD4);
  7084. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  7085. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7086. break;
  7087. case CMD_FCP_IREAD64_CR:
  7088. /* word3 iocb=iotag wqe=payload_offset_len */
  7089. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7090. wqe->fcp_iread.payload_offset_len =
  7091. xmit_len + sizeof(struct fcp_rsp);
  7092. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7093. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7094. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7095. iocbq->iocb.ulpFCP2Rcvy);
  7096. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7097. /* Always open the exchange */
  7098. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  7099. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7100. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7101. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7102. LPFC_WQE_LENLOC_WORD4);
  7103. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  7104. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7105. break;
  7106. case CMD_FCP_ICMND64_CR:
  7107. /* word3 iocb=IO_TAG wqe=reserved */
  7108. wqe->fcp_icmd.rsrvd3 = 0;
  7109. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7110. /* Always open the exchange */
  7111. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  7112. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7113. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7114. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7115. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7116. LPFC_WQE_LENLOC_NONE);
  7117. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  7118. break;
  7119. case CMD_GEN_REQUEST64_CR:
  7120. /* For this command calculate the xmit length of the
  7121. * request bde.
  7122. */
  7123. xmit_len = 0;
  7124. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7125. sizeof(struct ulp_bde64);
  7126. for (i = 0; i < numBdes; i++) {
  7127. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7128. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7129. break;
  7130. xmit_len += bde.tus.f.bdeSize;
  7131. }
  7132. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7133. wqe->gen_req.request_payload_len = xmit_len;
  7134. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7135. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7136. /* word6 context tag copied in memcpy */
  7137. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7138. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7139. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7140. "2015 Invalid CT %x command 0x%x\n",
  7141. ct, iocbq->iocb.ulpCommand);
  7142. return IOCB_ERROR;
  7143. }
  7144. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7145. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7146. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7147. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7148. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7149. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7150. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7151. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7152. command_type = OTHER_COMMAND;
  7153. break;
  7154. case CMD_XMIT_ELS_RSP64_CX:
  7155. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7156. /* words0-2 BDE memcpy */
  7157. /* word3 iocb=iotag32 wqe=response_payload_len */
  7158. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7159. /* word4 iocb=did wge=rsvd. */
  7160. wqe->xmit_els_rsp.rsvd4 = 0;
  7161. /* word5 iocb=rsvd wge=did */
  7162. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7163. iocbq->iocb.un.elsreq64.remoteID);
  7164. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7165. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7166. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7167. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7168. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7169. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7170. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7171. phba->vpi_ids[iocbq->vport->vpi]);
  7172. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7173. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7174. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7175. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7176. LPFC_WQE_LENLOC_WORD3);
  7177. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7178. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7179. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7180. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7181. iocbq->context2)->virt);
  7182. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7183. bf_set(els_req64_sp, &wqe->els_req, 1);
  7184. bf_set(els_req64_sid, &wqe->els_req,
  7185. iocbq->vport->fc_myDID);
  7186. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7187. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7188. phba->vpi_ids[phba->pport->vpi]);
  7189. }
  7190. command_type = OTHER_COMMAND;
  7191. break;
  7192. case CMD_CLOSE_XRI_CN:
  7193. case CMD_ABORT_XRI_CN:
  7194. case CMD_ABORT_XRI_CX:
  7195. /* words 0-2 memcpy should be 0 rserved */
  7196. /* port will send abts */
  7197. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7198. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7199. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7200. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7201. } else
  7202. fip = 0;
  7203. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7204. /*
  7205. * The link is down, or the command was ELS_FIP
  7206. * so the fw does not need to send abts
  7207. * on the wire.
  7208. */
  7209. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7210. else
  7211. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7212. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7213. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7214. wqe->abort_cmd.rsrvd5 = 0;
  7215. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7216. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7217. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7218. /*
  7219. * The abort handler will send us CMD_ABORT_XRI_CN or
  7220. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7221. */
  7222. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7223. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7224. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7225. LPFC_WQE_LENLOC_NONE);
  7226. cmnd = CMD_ABORT_XRI_CX;
  7227. command_type = OTHER_COMMAND;
  7228. xritag = 0;
  7229. break;
  7230. case CMD_XMIT_BLS_RSP64_CX:
  7231. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7232. * we re-construct this WQE here based on information in
  7233. * iocbq from scratch.
  7234. */
  7235. memset(wqe, 0, sizeof(union lpfc_wqe));
  7236. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7237. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7238. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7239. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7240. LPFC_ABTS_UNSOL_INT) {
  7241. /* ABTS sent by initiator to CT exchange, the
  7242. * RX_ID field will be filled with the newly
  7243. * allocated responder XRI.
  7244. */
  7245. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7246. iocbq->sli4_xritag);
  7247. } else {
  7248. /* ABTS sent by responder to CT exchange, the
  7249. * RX_ID field will be filled with the responder
  7250. * RX_ID from ABTS.
  7251. */
  7252. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7253. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7254. }
  7255. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7256. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7257. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7258. iocbq->iocb.ulpContext);
  7259. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7260. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7261. LPFC_WQE_LENLOC_NONE);
  7262. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7263. command_type = OTHER_COMMAND;
  7264. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7265. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7266. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7267. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7268. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7269. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7270. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7271. }
  7272. break;
  7273. case CMD_XRI_ABORTED_CX:
  7274. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7275. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7276. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7277. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7278. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7279. default:
  7280. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7281. "2014 Invalid command 0x%x\n",
  7282. iocbq->iocb.ulpCommand);
  7283. return IOCB_ERROR;
  7284. break;
  7285. }
  7286. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7287. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7288. wqe->generic.wqe_com.abort_tag = abort_tag;
  7289. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  7290. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  7291. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  7292. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  7293. return 0;
  7294. }
  7295. /**
  7296. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  7297. * @phba: Pointer to HBA context object.
  7298. * @ring_number: SLI ring number to issue iocb on.
  7299. * @piocb: Pointer to command iocb.
  7300. * @flag: Flag indicating if this command can be put into txq.
  7301. *
  7302. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  7303. * an iocb command to an HBA with SLI-4 interface spec.
  7304. *
  7305. * This function is called with hbalock held. The function will return success
  7306. * after it successfully submit the iocb to firmware or after adding to the
  7307. * txq.
  7308. **/
  7309. static int
  7310. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  7311. struct lpfc_iocbq *piocb, uint32_t flag)
  7312. {
  7313. struct lpfc_sglq *sglq;
  7314. union lpfc_wqe wqe;
  7315. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7316. if (piocb->sli4_xritag == NO_XRI) {
  7317. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  7318. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN ||
  7319. piocb->iocb.ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  7320. sglq = NULL;
  7321. else {
  7322. if (pring->txq_cnt) {
  7323. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7324. __lpfc_sli_ringtx_put(phba,
  7325. pring, piocb);
  7326. return IOCB_SUCCESS;
  7327. } else {
  7328. return IOCB_BUSY;
  7329. }
  7330. } else {
  7331. sglq = __lpfc_sli_get_sglq(phba, piocb);
  7332. if (!sglq) {
  7333. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7334. __lpfc_sli_ringtx_put(phba,
  7335. pring,
  7336. piocb);
  7337. return IOCB_SUCCESS;
  7338. } else
  7339. return IOCB_BUSY;
  7340. }
  7341. }
  7342. }
  7343. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  7344. /* These IO's already have an XRI and a mapped sgl. */
  7345. sglq = NULL;
  7346. } else {
  7347. /*
  7348. * This is a continuation of a commandi,(CX) so this
  7349. * sglq is on the active list
  7350. */
  7351. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  7352. if (!sglq)
  7353. return IOCB_ERROR;
  7354. }
  7355. if (sglq) {
  7356. piocb->sli4_lxritag = sglq->sli4_lxritag;
  7357. piocb->sli4_xritag = sglq->sli4_xritag;
  7358. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  7359. return IOCB_ERROR;
  7360. }
  7361. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  7362. return IOCB_ERROR;
  7363. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  7364. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  7365. /*
  7366. * For FCP command IOCB, get a new WQ index to distribute
  7367. * WQE across the WQsr. On the other hand, for abort IOCB,
  7368. * it carries the same WQ index to the original command
  7369. * IOCB.
  7370. */
  7371. if (piocb->iocb_flag & LPFC_IO_FCP)
  7372. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  7373. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  7374. &wqe))
  7375. return IOCB_ERROR;
  7376. } else {
  7377. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  7378. return IOCB_ERROR;
  7379. }
  7380. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  7381. return 0;
  7382. }
  7383. /**
  7384. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  7385. *
  7386. * This routine wraps the actual lockless version for issusing IOCB function
  7387. * pointer from the lpfc_hba struct.
  7388. *
  7389. * Return codes:
  7390. * IOCB_ERROR - Error
  7391. * IOCB_SUCCESS - Success
  7392. * IOCB_BUSY - Busy
  7393. **/
  7394. int
  7395. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7396. struct lpfc_iocbq *piocb, uint32_t flag)
  7397. {
  7398. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7399. }
  7400. /**
  7401. * lpfc_sli_api_table_setup - Set up sli api function jump table
  7402. * @phba: The hba struct for which this call is being executed.
  7403. * @dev_grp: The HBA PCI-Device group number.
  7404. *
  7405. * This routine sets up the SLI interface API function jump table in @phba
  7406. * struct.
  7407. * Returns: 0 - success, -ENODEV - failure.
  7408. **/
  7409. int
  7410. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7411. {
  7412. switch (dev_grp) {
  7413. case LPFC_PCI_DEV_LP:
  7414. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  7415. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  7416. break;
  7417. case LPFC_PCI_DEV_OC:
  7418. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  7419. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  7420. break;
  7421. default:
  7422. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7423. "1419 Invalid HBA PCI-device group: 0x%x\n",
  7424. dev_grp);
  7425. return -ENODEV;
  7426. break;
  7427. }
  7428. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  7429. return 0;
  7430. }
  7431. /**
  7432. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  7433. * @phba: Pointer to HBA context object.
  7434. * @pring: Pointer to driver SLI ring object.
  7435. * @piocb: Pointer to command iocb.
  7436. * @flag: Flag indicating if this command can be put into txq.
  7437. *
  7438. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  7439. * function. This function gets the hbalock and calls
  7440. * __lpfc_sli_issue_iocb function and will return the error returned
  7441. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  7442. * functions which do not hold hbalock.
  7443. **/
  7444. int
  7445. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7446. struct lpfc_iocbq *piocb, uint32_t flag)
  7447. {
  7448. unsigned long iflags;
  7449. int rc;
  7450. spin_lock_irqsave(&phba->hbalock, iflags);
  7451. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7452. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7453. return rc;
  7454. }
  7455. /**
  7456. * lpfc_extra_ring_setup - Extra ring setup function
  7457. * @phba: Pointer to HBA context object.
  7458. *
  7459. * This function is called while driver attaches with the
  7460. * HBA to setup the extra ring. The extra ring is used
  7461. * only when driver needs to support target mode functionality
  7462. * or IP over FC functionalities.
  7463. *
  7464. * This function is called with no lock held.
  7465. **/
  7466. static int
  7467. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  7468. {
  7469. struct lpfc_sli *psli;
  7470. struct lpfc_sli_ring *pring;
  7471. psli = &phba->sli;
  7472. /* Adjust cmd/rsp ring iocb entries more evenly */
  7473. /* Take some away from the FCP ring */
  7474. pring = &psli->ring[psli->fcp_ring];
  7475. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7476. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7477. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7478. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7479. /* and give them to the extra ring */
  7480. pring = &psli->ring[psli->extra_ring];
  7481. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7482. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7483. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7484. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7485. /* Setup default profile for this ring */
  7486. pring->iotag_max = 4096;
  7487. pring->num_mask = 1;
  7488. pring->prt[0].profile = 0; /* Mask 0 */
  7489. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  7490. pring->prt[0].type = phba->cfg_multi_ring_type;
  7491. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  7492. return 0;
  7493. }
  7494. /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS.
  7495. * @vport: pointer to virtual port object.
  7496. * @ndlp: nodelist pointer for the impacted rport.
  7497. *
  7498. * The driver calls this routine in response to a XRI ABORT CQE
  7499. * event from the port. In this event, the driver is required to
  7500. * recover its login to the rport even though its login may be valid
  7501. * from the driver's perspective. The failed ABTS notice from the
  7502. * port indicates the rport is not responding.
  7503. */
  7504. static void
  7505. lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
  7506. struct lpfc_nodelist *ndlp)
  7507. {
  7508. struct Scsi_Host *shost;
  7509. struct lpfc_hba *phba;
  7510. unsigned long flags = 0;
  7511. shost = lpfc_shost_from_vport(vport);
  7512. phba = vport->phba;
  7513. if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
  7514. lpfc_printf_log(phba, KERN_INFO,
  7515. LOG_SLI, "3093 No rport recovery needed. "
  7516. "rport in state 0x%x\n",
  7517. ndlp->nlp_state);
  7518. return;
  7519. }
  7520. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7521. "3094 Start rport recovery on shost id 0x%x "
  7522. "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
  7523. "flags 0x%x\n",
  7524. shost->host_no, ndlp->nlp_DID,
  7525. vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
  7526. ndlp->nlp_flag);
  7527. /*
  7528. * The rport is not responding. Don't attempt ADISC recovery.
  7529. * Remove the FCP-2 flag to force a PLOGI.
  7530. */
  7531. spin_lock_irqsave(shost->host_lock, flags);
  7532. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  7533. spin_unlock_irqrestore(shost->host_lock, flags);
  7534. lpfc_disc_state_machine(vport, ndlp, NULL,
  7535. NLP_EVT_DEVICE_RECOVERY);
  7536. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  7537. spin_lock_irqsave(shost->host_lock, flags);
  7538. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  7539. spin_unlock_irqrestore(shost->host_lock, flags);
  7540. lpfc_disc_start(vport);
  7541. }
  7542. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  7543. * @phba: Pointer to HBA context object.
  7544. * @iocbq: Pointer to iocb object.
  7545. *
  7546. * The async_event handler calls this routine when it receives
  7547. * an ASYNC_STATUS_CN event from the port. The port generates
  7548. * this event when an Abort Sequence request to an rport fails
  7549. * twice in succession. The abort could be originated by the
  7550. * driver or by the port. The ABTS could have been for an ELS
  7551. * or FCP IO. The port only generates this event when an ABTS
  7552. * fails to complete after one retry.
  7553. */
  7554. static void
  7555. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  7556. struct lpfc_iocbq *iocbq)
  7557. {
  7558. struct lpfc_nodelist *ndlp = NULL;
  7559. uint16_t rpi = 0, vpi = 0;
  7560. struct lpfc_vport *vport = NULL;
  7561. /* The rpi in the ulpContext is vport-sensitive. */
  7562. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  7563. rpi = iocbq->iocb.ulpContext;
  7564. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7565. "3092 Port generated ABTS async event "
  7566. "on vpi %d rpi %d status 0x%x\n",
  7567. vpi, rpi, iocbq->iocb.ulpStatus);
  7568. vport = lpfc_find_vport_by_vpid(phba, vpi);
  7569. if (!vport)
  7570. goto err_exit;
  7571. ndlp = lpfc_findnode_rpi(vport, rpi);
  7572. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  7573. goto err_exit;
  7574. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  7575. lpfc_sli_abts_recover_port(vport, ndlp);
  7576. return;
  7577. err_exit:
  7578. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7579. "3095 Event Context not found, no "
  7580. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  7581. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  7582. vpi, rpi);
  7583. }
  7584. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  7585. * @phba: pointer to HBA context object.
  7586. * @ndlp: nodelist pointer for the impacted rport.
  7587. * @axri: pointer to the wcqe containing the failed exchange.
  7588. *
  7589. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  7590. * port. The port generates this event when an abort exchange request to an
  7591. * rport fails twice in succession with no reply. The abort could be originated
  7592. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  7593. */
  7594. void
  7595. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  7596. struct lpfc_nodelist *ndlp,
  7597. struct sli4_wcqe_xri_aborted *axri)
  7598. {
  7599. struct lpfc_vport *vport;
  7600. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  7601. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7602. "3115 Node Context not found, driver "
  7603. "ignoring abts err event\n");
  7604. vport = ndlp->vport;
  7605. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7606. "3116 Port generated FCP XRI ABORT event on "
  7607. "vpi %d rpi %d xri x%x status 0x%x\n",
  7608. ndlp->vport->vpi, ndlp->nlp_rpi,
  7609. bf_get(lpfc_wcqe_xa_xri, axri),
  7610. bf_get(lpfc_wcqe_xa_status, axri));
  7611. if (bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT)
  7612. lpfc_sli_abts_recover_port(vport, ndlp);
  7613. }
  7614. /**
  7615. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  7616. * @phba: Pointer to HBA context object.
  7617. * @pring: Pointer to driver SLI ring object.
  7618. * @iocbq: Pointer to iocb object.
  7619. *
  7620. * This function is called by the slow ring event handler
  7621. * function when there is an ASYNC event iocb in the ring.
  7622. * This function is called with no lock held.
  7623. * Currently this function handles only temperature related
  7624. * ASYNC events. The function decodes the temperature sensor
  7625. * event message and posts events for the management applications.
  7626. **/
  7627. static void
  7628. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  7629. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  7630. {
  7631. IOCB_t *icmd;
  7632. uint16_t evt_code;
  7633. struct temp_event temp_event_data;
  7634. struct Scsi_Host *shost;
  7635. uint32_t *iocb_w;
  7636. icmd = &iocbq->iocb;
  7637. evt_code = icmd->un.asyncstat.evt_code;
  7638. switch (evt_code) {
  7639. case ASYNC_TEMP_WARN:
  7640. case ASYNC_TEMP_SAFE:
  7641. temp_event_data.data = (uint32_t) icmd->ulpContext;
  7642. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  7643. if (evt_code == ASYNC_TEMP_WARN) {
  7644. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  7645. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7646. "0347 Adapter is very hot, please take "
  7647. "corrective action. temperature : %d Celsius\n",
  7648. (uint32_t) icmd->ulpContext);
  7649. } else {
  7650. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  7651. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7652. "0340 Adapter temperature is OK now. "
  7653. "temperature : %d Celsius\n",
  7654. (uint32_t) icmd->ulpContext);
  7655. }
  7656. /* Send temperature change event to applications */
  7657. shost = lpfc_shost_from_vport(phba->pport);
  7658. fc_host_post_vendor_event(shost, fc_get_event_number(),
  7659. sizeof(temp_event_data), (char *) &temp_event_data,
  7660. LPFC_NL_VENDOR_ID);
  7661. break;
  7662. case ASYNC_STATUS_CN:
  7663. lpfc_sli_abts_err_handler(phba, iocbq);
  7664. break;
  7665. default:
  7666. iocb_w = (uint32_t *) icmd;
  7667. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7668. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  7669. " evt_code 0x%x\n"
  7670. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  7671. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  7672. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  7673. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  7674. pring->ringno, icmd->un.asyncstat.evt_code,
  7675. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  7676. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  7677. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  7678. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  7679. break;
  7680. }
  7681. }
  7682. /**
  7683. * lpfc_sli_setup - SLI ring setup function
  7684. * @phba: Pointer to HBA context object.
  7685. *
  7686. * lpfc_sli_setup sets up rings of the SLI interface with
  7687. * number of iocbs per ring and iotags. This function is
  7688. * called while driver attach to the HBA and before the
  7689. * interrupts are enabled. So there is no need for locking.
  7690. *
  7691. * This function always returns 0.
  7692. **/
  7693. int
  7694. lpfc_sli_setup(struct lpfc_hba *phba)
  7695. {
  7696. int i, totiocbsize = 0;
  7697. struct lpfc_sli *psli = &phba->sli;
  7698. struct lpfc_sli_ring *pring;
  7699. psli->num_rings = MAX_CONFIGURED_RINGS;
  7700. psli->sli_flag = 0;
  7701. psli->fcp_ring = LPFC_FCP_RING;
  7702. psli->next_ring = LPFC_FCP_NEXT_RING;
  7703. psli->extra_ring = LPFC_EXTRA_RING;
  7704. psli->iocbq_lookup = NULL;
  7705. psli->iocbq_lookup_len = 0;
  7706. psli->last_iotag = 0;
  7707. for (i = 0; i < psli->num_rings; i++) {
  7708. pring = &psli->ring[i];
  7709. switch (i) {
  7710. case LPFC_FCP_RING: /* ring 0 - FCP */
  7711. /* numCiocb and numRiocb are used in config_port */
  7712. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  7713. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  7714. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7715. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7716. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7717. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7718. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7719. SLI3_IOCB_CMD_SIZE :
  7720. SLI2_IOCB_CMD_SIZE;
  7721. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7722. SLI3_IOCB_RSP_SIZE :
  7723. SLI2_IOCB_RSP_SIZE;
  7724. pring->iotag_ctr = 0;
  7725. pring->iotag_max =
  7726. (phba->cfg_hba_queue_depth * 2);
  7727. pring->fast_iotag = pring->iotag_max;
  7728. pring->num_mask = 0;
  7729. break;
  7730. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  7731. /* numCiocb and numRiocb are used in config_port */
  7732. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  7733. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  7734. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7735. SLI3_IOCB_CMD_SIZE :
  7736. SLI2_IOCB_CMD_SIZE;
  7737. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7738. SLI3_IOCB_RSP_SIZE :
  7739. SLI2_IOCB_RSP_SIZE;
  7740. pring->iotag_max = phba->cfg_hba_queue_depth;
  7741. pring->num_mask = 0;
  7742. break;
  7743. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  7744. /* numCiocb and numRiocb are used in config_port */
  7745. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  7746. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  7747. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7748. SLI3_IOCB_CMD_SIZE :
  7749. SLI2_IOCB_CMD_SIZE;
  7750. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7751. SLI3_IOCB_RSP_SIZE :
  7752. SLI2_IOCB_RSP_SIZE;
  7753. pring->fast_iotag = 0;
  7754. pring->iotag_ctr = 0;
  7755. pring->iotag_max = 4096;
  7756. pring->lpfc_sli_rcv_async_status =
  7757. lpfc_sli_async_event_handler;
  7758. pring->num_mask = LPFC_MAX_RING_MASK;
  7759. pring->prt[0].profile = 0; /* Mask 0 */
  7760. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  7761. pring->prt[0].type = FC_TYPE_ELS;
  7762. pring->prt[0].lpfc_sli_rcv_unsol_event =
  7763. lpfc_els_unsol_event;
  7764. pring->prt[1].profile = 0; /* Mask 1 */
  7765. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  7766. pring->prt[1].type = FC_TYPE_ELS;
  7767. pring->prt[1].lpfc_sli_rcv_unsol_event =
  7768. lpfc_els_unsol_event;
  7769. pring->prt[2].profile = 0; /* Mask 2 */
  7770. /* NameServer Inquiry */
  7771. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  7772. /* NameServer */
  7773. pring->prt[2].type = FC_TYPE_CT;
  7774. pring->prt[2].lpfc_sli_rcv_unsol_event =
  7775. lpfc_ct_unsol_event;
  7776. pring->prt[3].profile = 0; /* Mask 3 */
  7777. /* NameServer response */
  7778. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  7779. /* NameServer */
  7780. pring->prt[3].type = FC_TYPE_CT;
  7781. pring->prt[3].lpfc_sli_rcv_unsol_event =
  7782. lpfc_ct_unsol_event;
  7783. /* abort unsolicited sequence */
  7784. pring->prt[4].profile = 0; /* Mask 4 */
  7785. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  7786. pring->prt[4].type = FC_TYPE_BLS;
  7787. pring->prt[4].lpfc_sli_rcv_unsol_event =
  7788. lpfc_sli4_ct_abort_unsol_event;
  7789. break;
  7790. }
  7791. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  7792. (pring->numRiocb * pring->sizeRiocb);
  7793. }
  7794. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  7795. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  7796. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  7797. "SLI2 SLIM Data: x%x x%lx\n",
  7798. phba->brd_no, totiocbsize,
  7799. (unsigned long) MAX_SLIM_IOCB_SIZE);
  7800. }
  7801. if (phba->cfg_multi_ring_support == 2)
  7802. lpfc_extra_ring_setup(phba);
  7803. return 0;
  7804. }
  7805. /**
  7806. * lpfc_sli_queue_setup - Queue initialization function
  7807. * @phba: Pointer to HBA context object.
  7808. *
  7809. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  7810. * ring. This function also initializes ring indices of each ring.
  7811. * This function is called during the initialization of the SLI
  7812. * interface of an HBA.
  7813. * This function is called with no lock held and always returns
  7814. * 1.
  7815. **/
  7816. int
  7817. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  7818. {
  7819. struct lpfc_sli *psli;
  7820. struct lpfc_sli_ring *pring;
  7821. int i;
  7822. psli = &phba->sli;
  7823. spin_lock_irq(&phba->hbalock);
  7824. INIT_LIST_HEAD(&psli->mboxq);
  7825. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  7826. /* Initialize list headers for txq and txcmplq as double linked lists */
  7827. for (i = 0; i < psli->num_rings; i++) {
  7828. pring = &psli->ring[i];
  7829. pring->ringno = i;
  7830. pring->next_cmdidx = 0;
  7831. pring->local_getidx = 0;
  7832. pring->cmdidx = 0;
  7833. INIT_LIST_HEAD(&pring->txq);
  7834. INIT_LIST_HEAD(&pring->txcmplq);
  7835. INIT_LIST_HEAD(&pring->iocb_continueq);
  7836. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  7837. INIT_LIST_HEAD(&pring->postbufq);
  7838. }
  7839. spin_unlock_irq(&phba->hbalock);
  7840. return 1;
  7841. }
  7842. /**
  7843. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  7844. * @phba: Pointer to HBA context object.
  7845. *
  7846. * This routine flushes the mailbox command subsystem. It will unconditionally
  7847. * flush all the mailbox commands in the three possible stages in the mailbox
  7848. * command sub-system: pending mailbox command queue; the outstanding mailbox
  7849. * command; and completed mailbox command queue. It is caller's responsibility
  7850. * to make sure that the driver is in the proper state to flush the mailbox
  7851. * command sub-system. Namely, the posting of mailbox commands into the
  7852. * pending mailbox command queue from the various clients must be stopped;
  7853. * either the HBA is in a state that it will never works on the outstanding
  7854. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  7855. * mailbox command has been completed.
  7856. **/
  7857. static void
  7858. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  7859. {
  7860. LIST_HEAD(completions);
  7861. struct lpfc_sli *psli = &phba->sli;
  7862. LPFC_MBOXQ_t *pmb;
  7863. unsigned long iflag;
  7864. /* Flush all the mailbox commands in the mbox system */
  7865. spin_lock_irqsave(&phba->hbalock, iflag);
  7866. /* The pending mailbox command queue */
  7867. list_splice_init(&phba->sli.mboxq, &completions);
  7868. /* The outstanding active mailbox command */
  7869. if (psli->mbox_active) {
  7870. list_add_tail(&psli->mbox_active->list, &completions);
  7871. psli->mbox_active = NULL;
  7872. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7873. }
  7874. /* The completed mailbox command queue */
  7875. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  7876. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7877. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  7878. while (!list_empty(&completions)) {
  7879. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  7880. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  7881. if (pmb->mbox_cmpl)
  7882. pmb->mbox_cmpl(phba, pmb);
  7883. }
  7884. }
  7885. /**
  7886. * lpfc_sli_host_down - Vport cleanup function
  7887. * @vport: Pointer to virtual port object.
  7888. *
  7889. * lpfc_sli_host_down is called to clean up the resources
  7890. * associated with a vport before destroying virtual
  7891. * port data structures.
  7892. * This function does following operations:
  7893. * - Free discovery resources associated with this virtual
  7894. * port.
  7895. * - Free iocbs associated with this virtual port in
  7896. * the txq.
  7897. * - Send abort for all iocb commands associated with this
  7898. * vport in txcmplq.
  7899. *
  7900. * This function is called with no lock held and always returns 1.
  7901. **/
  7902. int
  7903. lpfc_sli_host_down(struct lpfc_vport *vport)
  7904. {
  7905. LIST_HEAD(completions);
  7906. struct lpfc_hba *phba = vport->phba;
  7907. struct lpfc_sli *psli = &phba->sli;
  7908. struct lpfc_sli_ring *pring;
  7909. struct lpfc_iocbq *iocb, *next_iocb;
  7910. int i;
  7911. unsigned long flags = 0;
  7912. uint16_t prev_pring_flag;
  7913. lpfc_cleanup_discovery_resources(vport);
  7914. spin_lock_irqsave(&phba->hbalock, flags);
  7915. for (i = 0; i < psli->num_rings; i++) {
  7916. pring = &psli->ring[i];
  7917. prev_pring_flag = pring->flag;
  7918. /* Only slow rings */
  7919. if (pring->ringno == LPFC_ELS_RING) {
  7920. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  7921. /* Set the lpfc data pending flag */
  7922. set_bit(LPFC_DATA_READY, &phba->data_flags);
  7923. }
  7924. /*
  7925. * Error everything on the txq since these iocbs have not been
  7926. * given to the FW yet.
  7927. */
  7928. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  7929. if (iocb->vport != vport)
  7930. continue;
  7931. list_move_tail(&iocb->list, &completions);
  7932. pring->txq_cnt--;
  7933. }
  7934. /* Next issue ABTS for everything on the txcmplq */
  7935. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  7936. list) {
  7937. if (iocb->vport != vport)
  7938. continue;
  7939. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  7940. }
  7941. pring->flag = prev_pring_flag;
  7942. }
  7943. spin_unlock_irqrestore(&phba->hbalock, flags);
  7944. /* Cancel all the IOCBs from the completions list */
  7945. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7946. IOERR_SLI_DOWN);
  7947. return 1;
  7948. }
  7949. /**
  7950. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  7951. * @phba: Pointer to HBA context object.
  7952. *
  7953. * This function cleans up all iocb, buffers, mailbox commands
  7954. * while shutting down the HBA. This function is called with no
  7955. * lock held and always returns 1.
  7956. * This function does the following to cleanup driver resources:
  7957. * - Free discovery resources for each virtual port
  7958. * - Cleanup any pending fabric iocbs
  7959. * - Iterate through the iocb txq and free each entry
  7960. * in the list.
  7961. * - Free up any buffer posted to the HBA
  7962. * - Free mailbox commands in the mailbox queue.
  7963. **/
  7964. int
  7965. lpfc_sli_hba_down(struct lpfc_hba *phba)
  7966. {
  7967. LIST_HEAD(completions);
  7968. struct lpfc_sli *psli = &phba->sli;
  7969. struct lpfc_sli_ring *pring;
  7970. struct lpfc_dmabuf *buf_ptr;
  7971. unsigned long flags = 0;
  7972. int i;
  7973. /* Shutdown the mailbox command sub-system */
  7974. lpfc_sli_mbox_sys_shutdown(phba);
  7975. lpfc_hba_down_prep(phba);
  7976. lpfc_fabric_abort_hba(phba);
  7977. spin_lock_irqsave(&phba->hbalock, flags);
  7978. for (i = 0; i < psli->num_rings; i++) {
  7979. pring = &psli->ring[i];
  7980. /* Only slow rings */
  7981. if (pring->ringno == LPFC_ELS_RING) {
  7982. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  7983. /* Set the lpfc data pending flag */
  7984. set_bit(LPFC_DATA_READY, &phba->data_flags);
  7985. }
  7986. /*
  7987. * Error everything on the txq since these iocbs have not been
  7988. * given to the FW yet.
  7989. */
  7990. list_splice_init(&pring->txq, &completions);
  7991. pring->txq_cnt = 0;
  7992. }
  7993. spin_unlock_irqrestore(&phba->hbalock, flags);
  7994. /* Cancel all the IOCBs from the completions list */
  7995. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7996. IOERR_SLI_DOWN);
  7997. spin_lock_irqsave(&phba->hbalock, flags);
  7998. list_splice_init(&phba->elsbuf, &completions);
  7999. phba->elsbuf_cnt = 0;
  8000. phba->elsbuf_prev_cnt = 0;
  8001. spin_unlock_irqrestore(&phba->hbalock, flags);
  8002. while (!list_empty(&completions)) {
  8003. list_remove_head(&completions, buf_ptr,
  8004. struct lpfc_dmabuf, list);
  8005. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8006. kfree(buf_ptr);
  8007. }
  8008. /* Return any active mbox cmds */
  8009. del_timer_sync(&psli->mbox_tmo);
  8010. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8011. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8012. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8013. return 1;
  8014. }
  8015. /**
  8016. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8017. * @srcp: Source memory pointer.
  8018. * @destp: Destination memory pointer.
  8019. * @cnt: Number of words required to be copied.
  8020. *
  8021. * This function is used for copying data between driver memory
  8022. * and the SLI memory. This function also changes the endianness
  8023. * of each word if native endianness is different from SLI
  8024. * endianness. This function can be called with or without
  8025. * lock.
  8026. **/
  8027. void
  8028. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8029. {
  8030. uint32_t *src = srcp;
  8031. uint32_t *dest = destp;
  8032. uint32_t ldata;
  8033. int i;
  8034. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8035. ldata = *src;
  8036. ldata = le32_to_cpu(ldata);
  8037. *dest = ldata;
  8038. src++;
  8039. dest++;
  8040. }
  8041. }
  8042. /**
  8043. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8044. * @srcp: Source memory pointer.
  8045. * @destp: Destination memory pointer.
  8046. * @cnt: Number of words required to be copied.
  8047. *
  8048. * This function is used for copying data between a data structure
  8049. * with big endian representation to local endianness.
  8050. * This function can be called with or without lock.
  8051. **/
  8052. void
  8053. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8054. {
  8055. uint32_t *src = srcp;
  8056. uint32_t *dest = destp;
  8057. uint32_t ldata;
  8058. int i;
  8059. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8060. ldata = *src;
  8061. ldata = be32_to_cpu(ldata);
  8062. *dest = ldata;
  8063. src++;
  8064. dest++;
  8065. }
  8066. }
  8067. /**
  8068. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8069. * @phba: Pointer to HBA context object.
  8070. * @pring: Pointer to driver SLI ring object.
  8071. * @mp: Pointer to driver buffer object.
  8072. *
  8073. * This function is called with no lock held.
  8074. * It always return zero after adding the buffer to the postbufq
  8075. * buffer list.
  8076. **/
  8077. int
  8078. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8079. struct lpfc_dmabuf *mp)
  8080. {
  8081. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8082. later */
  8083. spin_lock_irq(&phba->hbalock);
  8084. list_add_tail(&mp->list, &pring->postbufq);
  8085. pring->postbufq_cnt++;
  8086. spin_unlock_irq(&phba->hbalock);
  8087. return 0;
  8088. }
  8089. /**
  8090. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8091. * @phba: Pointer to HBA context object.
  8092. *
  8093. * When HBQ is enabled, buffers are searched based on tags. This function
  8094. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8095. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8096. * does not conflict with tags of buffer posted for unsolicited events.
  8097. * The function returns the allocated tag. The function is called with
  8098. * no locks held.
  8099. **/
  8100. uint32_t
  8101. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8102. {
  8103. spin_lock_irq(&phba->hbalock);
  8104. phba->buffer_tag_count++;
  8105. /*
  8106. * Always set the QUE_BUFTAG_BIT to distiguish between
  8107. * a tag assigned by HBQ.
  8108. */
  8109. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8110. spin_unlock_irq(&phba->hbalock);
  8111. return phba->buffer_tag_count;
  8112. }
  8113. /**
  8114. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8115. * @phba: Pointer to HBA context object.
  8116. * @pring: Pointer to driver SLI ring object.
  8117. * @tag: Buffer tag.
  8118. *
  8119. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8120. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8121. * iocb is posted to the response ring with the tag of the buffer.
  8122. * This function searches the pring->postbufq list using the tag
  8123. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8124. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8125. * buffer is returned to the caller else NULL is returned.
  8126. * This function is called with no lock held.
  8127. **/
  8128. struct lpfc_dmabuf *
  8129. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8130. uint32_t tag)
  8131. {
  8132. struct lpfc_dmabuf *mp, *next_mp;
  8133. struct list_head *slp = &pring->postbufq;
  8134. /* Search postbufq, from the beginning, looking for a match on tag */
  8135. spin_lock_irq(&phba->hbalock);
  8136. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8137. if (mp->buffer_tag == tag) {
  8138. list_del_init(&mp->list);
  8139. pring->postbufq_cnt--;
  8140. spin_unlock_irq(&phba->hbalock);
  8141. return mp;
  8142. }
  8143. }
  8144. spin_unlock_irq(&phba->hbalock);
  8145. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8146. "0402 Cannot find virtual addr for buffer tag on "
  8147. "ring %d Data x%lx x%p x%p x%x\n",
  8148. pring->ringno, (unsigned long) tag,
  8149. slp->next, slp->prev, pring->postbufq_cnt);
  8150. return NULL;
  8151. }
  8152. /**
  8153. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8154. * @phba: Pointer to HBA context object.
  8155. * @pring: Pointer to driver SLI ring object.
  8156. * @phys: DMA address of the buffer.
  8157. *
  8158. * This function searches the buffer list using the dma_address
  8159. * of unsolicited event to find the driver's lpfc_dmabuf object
  8160. * corresponding to the dma_address. The function returns the
  8161. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8162. * This function is called by the ct and els unsolicited event
  8163. * handlers to get the buffer associated with the unsolicited
  8164. * event.
  8165. *
  8166. * This function is called with no lock held.
  8167. **/
  8168. struct lpfc_dmabuf *
  8169. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8170. dma_addr_t phys)
  8171. {
  8172. struct lpfc_dmabuf *mp, *next_mp;
  8173. struct list_head *slp = &pring->postbufq;
  8174. /* Search postbufq, from the beginning, looking for a match on phys */
  8175. spin_lock_irq(&phba->hbalock);
  8176. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8177. if (mp->phys == phys) {
  8178. list_del_init(&mp->list);
  8179. pring->postbufq_cnt--;
  8180. spin_unlock_irq(&phba->hbalock);
  8181. return mp;
  8182. }
  8183. }
  8184. spin_unlock_irq(&phba->hbalock);
  8185. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8186. "0410 Cannot find virtual addr for mapped buf on "
  8187. "ring %d Data x%llx x%p x%p x%x\n",
  8188. pring->ringno, (unsigned long long)phys,
  8189. slp->next, slp->prev, pring->postbufq_cnt);
  8190. return NULL;
  8191. }
  8192. /**
  8193. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8194. * @phba: Pointer to HBA context object.
  8195. * @cmdiocb: Pointer to driver command iocb object.
  8196. * @rspiocb: Pointer to driver response iocb object.
  8197. *
  8198. * This function is the completion handler for the abort iocbs for
  8199. * ELS commands. This function is called from the ELS ring event
  8200. * handler with no lock held. This function frees memory resources
  8201. * associated with the abort iocb.
  8202. **/
  8203. static void
  8204. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8205. struct lpfc_iocbq *rspiocb)
  8206. {
  8207. IOCB_t *irsp = &rspiocb->iocb;
  8208. uint16_t abort_iotag, abort_context;
  8209. struct lpfc_iocbq *abort_iocb = NULL;
  8210. if (irsp->ulpStatus) {
  8211. /*
  8212. * Assume that the port already completed and returned, or
  8213. * will return the iocb. Just Log the message.
  8214. */
  8215. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8216. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8217. spin_lock_irq(&phba->hbalock);
  8218. if (phba->sli_rev < LPFC_SLI_REV4) {
  8219. if (abort_iotag != 0 &&
  8220. abort_iotag <= phba->sli.last_iotag)
  8221. abort_iocb =
  8222. phba->sli.iocbq_lookup[abort_iotag];
  8223. } else
  8224. /* For sli4 the abort_tag is the XRI,
  8225. * so the abort routine puts the iotag of the iocb
  8226. * being aborted in the context field of the abort
  8227. * IOCB.
  8228. */
  8229. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8230. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8231. "0327 Cannot abort els iocb %p "
  8232. "with tag %x context %x, abort status %x, "
  8233. "abort code %x\n",
  8234. abort_iocb, abort_iotag, abort_context,
  8235. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8236. spin_unlock_irq(&phba->hbalock);
  8237. }
  8238. lpfc_sli_release_iocbq(phba, cmdiocb);
  8239. return;
  8240. }
  8241. /**
  8242. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  8243. * @phba: Pointer to HBA context object.
  8244. * @cmdiocb: Pointer to driver command iocb object.
  8245. * @rspiocb: Pointer to driver response iocb object.
  8246. *
  8247. * The function is called from SLI ring event handler with no
  8248. * lock held. This function is the completion handler for ELS commands
  8249. * which are aborted. The function frees memory resources used for
  8250. * the aborted ELS commands.
  8251. **/
  8252. static void
  8253. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8254. struct lpfc_iocbq *rspiocb)
  8255. {
  8256. IOCB_t *irsp = &rspiocb->iocb;
  8257. /* ELS cmd tag <ulpIoTag> completes */
  8258. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8259. "0139 Ignoring ELS cmd tag x%x completion Data: "
  8260. "x%x x%x x%x\n",
  8261. irsp->ulpIoTag, irsp->ulpStatus,
  8262. irsp->un.ulpWord[4], irsp->ulpTimeout);
  8263. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  8264. lpfc_ct_free_iocb(phba, cmdiocb);
  8265. else
  8266. lpfc_els_free_iocb(phba, cmdiocb);
  8267. return;
  8268. }
  8269. /**
  8270. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  8271. * @phba: Pointer to HBA context object.
  8272. * @pring: Pointer to driver SLI ring object.
  8273. * @cmdiocb: Pointer to driver command iocb object.
  8274. *
  8275. * This function issues an abort iocb for the provided command iocb down to
  8276. * the port. Other than the case the outstanding command iocb is an abort
  8277. * request, this function issues abort out unconditionally. This function is
  8278. * called with hbalock held. The function returns 0 when it fails due to
  8279. * memory allocation failure or when the command iocb is an abort request.
  8280. **/
  8281. static int
  8282. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8283. struct lpfc_iocbq *cmdiocb)
  8284. {
  8285. struct lpfc_vport *vport = cmdiocb->vport;
  8286. struct lpfc_iocbq *abtsiocbp;
  8287. IOCB_t *icmd = NULL;
  8288. IOCB_t *iabt = NULL;
  8289. int retval;
  8290. /*
  8291. * There are certain command types we don't want to abort. And we
  8292. * don't want to abort commands that are already in the process of
  8293. * being aborted.
  8294. */
  8295. icmd = &cmdiocb->iocb;
  8296. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8297. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8298. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8299. return 0;
  8300. /* issue ABTS for this IOCB based on iotag */
  8301. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  8302. if (abtsiocbp == NULL)
  8303. return 0;
  8304. /* This signals the response to set the correct status
  8305. * before calling the completion handler
  8306. */
  8307. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  8308. iabt = &abtsiocbp->iocb;
  8309. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  8310. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  8311. if (phba->sli_rev == LPFC_SLI_REV4) {
  8312. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  8313. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  8314. }
  8315. else
  8316. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  8317. iabt->ulpLe = 1;
  8318. iabt->ulpClass = icmd->ulpClass;
  8319. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8320. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  8321. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  8322. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  8323. if (phba->link_state >= LPFC_LINK_UP)
  8324. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  8325. else
  8326. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  8327. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  8328. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  8329. "0339 Abort xri x%x, original iotag x%x, "
  8330. "abort cmd iotag x%x\n",
  8331. iabt->un.acxri.abortIoTag,
  8332. iabt->un.acxri.abortContextTag,
  8333. abtsiocbp->iotag);
  8334. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  8335. if (retval)
  8336. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  8337. /*
  8338. * Caller to this routine should check for IOCB_ERROR
  8339. * and handle it properly. This routine no longer removes
  8340. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8341. */
  8342. return retval;
  8343. }
  8344. /**
  8345. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  8346. * @phba: Pointer to HBA context object.
  8347. * @pring: Pointer to driver SLI ring object.
  8348. * @cmdiocb: Pointer to driver command iocb object.
  8349. *
  8350. * This function issues an abort iocb for the provided command iocb. In case
  8351. * of unloading, the abort iocb will not be issued to commands on the ELS
  8352. * ring. Instead, the callback function shall be changed to those commands
  8353. * so that nothing happens when them finishes. This function is called with
  8354. * hbalock held. The function returns 0 when the command iocb is an abort
  8355. * request.
  8356. **/
  8357. int
  8358. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8359. struct lpfc_iocbq *cmdiocb)
  8360. {
  8361. struct lpfc_vport *vport = cmdiocb->vport;
  8362. int retval = IOCB_ERROR;
  8363. IOCB_t *icmd = NULL;
  8364. /*
  8365. * There are certain command types we don't want to abort. And we
  8366. * don't want to abort commands that are already in the process of
  8367. * being aborted.
  8368. */
  8369. icmd = &cmdiocb->iocb;
  8370. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8371. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8372. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8373. return 0;
  8374. /*
  8375. * If we're unloading, don't abort iocb on the ELS ring, but change
  8376. * the callback so that nothing happens when it finishes.
  8377. */
  8378. if ((vport->load_flag & FC_UNLOADING) &&
  8379. (pring->ringno == LPFC_ELS_RING)) {
  8380. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  8381. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  8382. else
  8383. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  8384. goto abort_iotag_exit;
  8385. }
  8386. /* Now, we try to issue the abort to the cmdiocb out */
  8387. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  8388. abort_iotag_exit:
  8389. /*
  8390. * Caller to this routine should check for IOCB_ERROR
  8391. * and handle it properly. This routine no longer removes
  8392. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8393. */
  8394. return retval;
  8395. }
  8396. /**
  8397. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  8398. * @phba: Pointer to HBA context object.
  8399. * @pring: Pointer to driver SLI ring object.
  8400. *
  8401. * This function aborts all iocbs in the given ring and frees all the iocb
  8402. * objects in txq. This function issues abort iocbs unconditionally for all
  8403. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  8404. * to complete before the return of this function. The caller is not required
  8405. * to hold any locks.
  8406. **/
  8407. static void
  8408. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  8409. {
  8410. LIST_HEAD(completions);
  8411. struct lpfc_iocbq *iocb, *next_iocb;
  8412. if (pring->ringno == LPFC_ELS_RING)
  8413. lpfc_fabric_abort_hba(phba);
  8414. spin_lock_irq(&phba->hbalock);
  8415. /* Take off all the iocbs on txq for cancelling */
  8416. list_splice_init(&pring->txq, &completions);
  8417. pring->txq_cnt = 0;
  8418. /* Next issue ABTS for everything on the txcmplq */
  8419. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  8420. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  8421. spin_unlock_irq(&phba->hbalock);
  8422. /* Cancel all the IOCBs from the completions list */
  8423. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8424. IOERR_SLI_ABORTED);
  8425. }
  8426. /**
  8427. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  8428. * @phba: pointer to lpfc HBA data structure.
  8429. *
  8430. * This routine will abort all pending and outstanding iocbs to an HBA.
  8431. **/
  8432. void
  8433. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  8434. {
  8435. struct lpfc_sli *psli = &phba->sli;
  8436. struct lpfc_sli_ring *pring;
  8437. int i;
  8438. for (i = 0; i < psli->num_rings; i++) {
  8439. pring = &psli->ring[i];
  8440. lpfc_sli_iocb_ring_abort(phba, pring);
  8441. }
  8442. }
  8443. /**
  8444. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  8445. * @iocbq: Pointer to driver iocb object.
  8446. * @vport: Pointer to driver virtual port object.
  8447. * @tgt_id: SCSI ID of the target.
  8448. * @lun_id: LUN ID of the scsi device.
  8449. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  8450. *
  8451. * This function acts as an iocb filter for functions which abort or count
  8452. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  8453. * 0 if the filtering criteria is met for the given iocb and will return
  8454. * 1 if the filtering criteria is not met.
  8455. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  8456. * given iocb is for the SCSI device specified by vport, tgt_id and
  8457. * lun_id parameter.
  8458. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  8459. * given iocb is for the SCSI target specified by vport and tgt_id
  8460. * parameters.
  8461. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  8462. * given iocb is for the SCSI host associated with the given vport.
  8463. * This function is called with no locks held.
  8464. **/
  8465. static int
  8466. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  8467. uint16_t tgt_id, uint64_t lun_id,
  8468. lpfc_ctx_cmd ctx_cmd)
  8469. {
  8470. struct lpfc_scsi_buf *lpfc_cmd;
  8471. int rc = 1;
  8472. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  8473. return rc;
  8474. if (iocbq->vport != vport)
  8475. return rc;
  8476. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  8477. if (lpfc_cmd->pCmd == NULL)
  8478. return rc;
  8479. switch (ctx_cmd) {
  8480. case LPFC_CTX_LUN:
  8481. if ((lpfc_cmd->rdata->pnode) &&
  8482. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  8483. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  8484. rc = 0;
  8485. break;
  8486. case LPFC_CTX_TGT:
  8487. if ((lpfc_cmd->rdata->pnode) &&
  8488. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  8489. rc = 0;
  8490. break;
  8491. case LPFC_CTX_HOST:
  8492. rc = 0;
  8493. break;
  8494. default:
  8495. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  8496. __func__, ctx_cmd);
  8497. break;
  8498. }
  8499. return rc;
  8500. }
  8501. /**
  8502. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  8503. * @vport: Pointer to virtual port.
  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 returns number of FCP commands pending for the vport.
  8509. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  8510. * commands pending on the vport associated with SCSI device specified
  8511. * by tgt_id and lun_id parameters.
  8512. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  8513. * commands pending on the vport associated with SCSI target specified
  8514. * by tgt_id parameter.
  8515. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  8516. * commands pending on the vport.
  8517. * This function returns the number of iocbs which satisfy the filter.
  8518. * This function is called without any lock held.
  8519. **/
  8520. int
  8521. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  8522. lpfc_ctx_cmd ctx_cmd)
  8523. {
  8524. struct lpfc_hba *phba = vport->phba;
  8525. struct lpfc_iocbq *iocbq;
  8526. int sum, i;
  8527. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  8528. iocbq = phba->sli.iocbq_lookup[i];
  8529. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  8530. ctx_cmd) == 0)
  8531. sum++;
  8532. }
  8533. return sum;
  8534. }
  8535. /**
  8536. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  8537. * @phba: Pointer to HBA context object
  8538. * @cmdiocb: Pointer to command iocb object.
  8539. * @rspiocb: Pointer to response iocb object.
  8540. *
  8541. * This function is called when an aborted FCP iocb completes. This
  8542. * function is called by the ring event handler with no lock held.
  8543. * This function frees the iocb.
  8544. **/
  8545. void
  8546. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8547. struct lpfc_iocbq *rspiocb)
  8548. {
  8549. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8550. "3096 ABORT_XRI_CN completing on xri x%x "
  8551. "original iotag x%x, abort cmd iotag x%x "
  8552. "status 0x%x, reason 0x%x\n",
  8553. cmdiocb->iocb.un.acxri.abortContextTag,
  8554. cmdiocb->iocb.un.acxri.abortIoTag,
  8555. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  8556. rspiocb->iocb.un.ulpWord[4]);
  8557. lpfc_sli_release_iocbq(phba, cmdiocb);
  8558. return;
  8559. }
  8560. /**
  8561. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  8562. * @vport: Pointer to virtual port.
  8563. * @pring: Pointer to driver SLI ring object.
  8564. * @tgt_id: SCSI ID of the target.
  8565. * @lun_id: LUN ID of the scsi device.
  8566. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8567. *
  8568. * This function sends an abort command for every SCSI command
  8569. * associated with the given virtual port pending on the ring
  8570. * filtered by lpfc_sli_validate_fcp_iocb function.
  8571. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  8572. * FCP iocbs associated with lun specified by tgt_id and lun_id
  8573. * parameters
  8574. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  8575. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  8576. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  8577. * FCP iocbs associated with virtual port.
  8578. * This function returns number of iocbs it failed to abort.
  8579. * This function is called with no locks held.
  8580. **/
  8581. int
  8582. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  8583. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  8584. {
  8585. struct lpfc_hba *phba = vport->phba;
  8586. struct lpfc_iocbq *iocbq;
  8587. struct lpfc_iocbq *abtsiocb;
  8588. IOCB_t *cmd = NULL;
  8589. int errcnt = 0, ret_val = 0;
  8590. int i;
  8591. for (i = 1; i <= phba->sli.last_iotag; i++) {
  8592. iocbq = phba->sli.iocbq_lookup[i];
  8593. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  8594. abort_cmd) != 0)
  8595. continue;
  8596. /* issue ABTS for this IOCB based on iotag */
  8597. abtsiocb = lpfc_sli_get_iocbq(phba);
  8598. if (abtsiocb == NULL) {
  8599. errcnt++;
  8600. continue;
  8601. }
  8602. cmd = &iocbq->iocb;
  8603. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  8604. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  8605. if (phba->sli_rev == LPFC_SLI_REV4)
  8606. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  8607. else
  8608. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  8609. abtsiocb->iocb.ulpLe = 1;
  8610. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  8611. abtsiocb->vport = phba->pport;
  8612. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8613. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  8614. if (iocbq->iocb_flag & LPFC_IO_FCP)
  8615. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  8616. if (lpfc_is_link_up(phba))
  8617. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  8618. else
  8619. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  8620. /* Setup callback routine and issue the command. */
  8621. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  8622. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  8623. abtsiocb, 0);
  8624. if (ret_val == IOCB_ERROR) {
  8625. lpfc_sli_release_iocbq(phba, abtsiocb);
  8626. errcnt++;
  8627. continue;
  8628. }
  8629. }
  8630. return errcnt;
  8631. }
  8632. /**
  8633. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  8634. * @phba: Pointer to HBA context object.
  8635. * @cmdiocbq: Pointer to command iocb.
  8636. * @rspiocbq: Pointer to response iocb.
  8637. *
  8638. * This function is the completion handler for iocbs issued using
  8639. * lpfc_sli_issue_iocb_wait function. This function is called by the
  8640. * ring event handler function without any lock held. This function
  8641. * can be called from both worker thread context and interrupt
  8642. * context. This function also can be called from other thread which
  8643. * cleans up the SLI layer objects.
  8644. * This function copy the contents of the response iocb to the
  8645. * response iocb memory object provided by the caller of
  8646. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  8647. * sleeps for the iocb completion.
  8648. **/
  8649. static void
  8650. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  8651. struct lpfc_iocbq *cmdiocbq,
  8652. struct lpfc_iocbq *rspiocbq)
  8653. {
  8654. wait_queue_head_t *pdone_q;
  8655. unsigned long iflags;
  8656. struct lpfc_scsi_buf *lpfc_cmd;
  8657. spin_lock_irqsave(&phba->hbalock, iflags);
  8658. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  8659. if (cmdiocbq->context2 && rspiocbq)
  8660. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  8661. &rspiocbq->iocb, sizeof(IOCB_t));
  8662. /* Set the exchange busy flag for task management commands */
  8663. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  8664. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  8665. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  8666. cur_iocbq);
  8667. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  8668. }
  8669. pdone_q = cmdiocbq->context_un.wait_queue;
  8670. if (pdone_q)
  8671. wake_up(pdone_q);
  8672. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8673. return;
  8674. }
  8675. /**
  8676. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  8677. * @phba: Pointer to HBA context object..
  8678. * @piocbq: Pointer to command iocb.
  8679. * @flag: Flag to test.
  8680. *
  8681. * This routine grabs the hbalock and then test the iocb_flag to
  8682. * see if the passed in flag is set.
  8683. * Returns:
  8684. * 1 if flag is set.
  8685. * 0 if flag is not set.
  8686. **/
  8687. static int
  8688. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  8689. struct lpfc_iocbq *piocbq, uint32_t flag)
  8690. {
  8691. unsigned long iflags;
  8692. int ret;
  8693. spin_lock_irqsave(&phba->hbalock, iflags);
  8694. ret = piocbq->iocb_flag & flag;
  8695. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8696. return ret;
  8697. }
  8698. /**
  8699. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  8700. * @phba: Pointer to HBA context object..
  8701. * @pring: Pointer to sli ring.
  8702. * @piocb: Pointer to command iocb.
  8703. * @prspiocbq: Pointer to response iocb.
  8704. * @timeout: Timeout in number of seconds.
  8705. *
  8706. * This function issues the iocb to firmware and waits for the
  8707. * iocb to complete. If the iocb command is not
  8708. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  8709. * Caller should not free the iocb resources if this function
  8710. * returns IOCB_TIMEDOUT.
  8711. * The function waits for the iocb completion using an
  8712. * non-interruptible wait.
  8713. * This function will sleep while waiting for iocb completion.
  8714. * So, this function should not be called from any context which
  8715. * does not allow sleeping. Due to the same reason, this function
  8716. * cannot be called with interrupt disabled.
  8717. * This function assumes that the iocb completions occur while
  8718. * this function sleep. So, this function cannot be called from
  8719. * the thread which process iocb completion for this ring.
  8720. * This function clears the iocb_flag of the iocb object before
  8721. * issuing the iocb and the iocb completion handler sets this
  8722. * flag and wakes this thread when the iocb completes.
  8723. * The contents of the response iocb will be copied to prspiocbq
  8724. * by the completion handler when the command completes.
  8725. * This function returns IOCB_SUCCESS when success.
  8726. * This function is called with no lock held.
  8727. **/
  8728. int
  8729. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  8730. uint32_t ring_number,
  8731. struct lpfc_iocbq *piocb,
  8732. struct lpfc_iocbq *prspiocbq,
  8733. uint32_t timeout)
  8734. {
  8735. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  8736. long timeleft, timeout_req = 0;
  8737. int retval = IOCB_SUCCESS;
  8738. uint32_t creg_val;
  8739. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8740. /*
  8741. * If the caller has provided a response iocbq buffer, then context2
  8742. * is NULL or its an error.
  8743. */
  8744. if (prspiocbq) {
  8745. if (piocb->context2)
  8746. return IOCB_ERROR;
  8747. piocb->context2 = prspiocbq;
  8748. }
  8749. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  8750. piocb->context_un.wait_queue = &done_q;
  8751. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  8752. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  8753. if (lpfc_readl(phba->HCregaddr, &creg_val))
  8754. return IOCB_ERROR;
  8755. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  8756. writel(creg_val, phba->HCregaddr);
  8757. readl(phba->HCregaddr); /* flush */
  8758. }
  8759. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  8760. SLI_IOCB_RET_IOCB);
  8761. if (retval == IOCB_SUCCESS) {
  8762. timeout_req = timeout * HZ;
  8763. timeleft = wait_event_timeout(done_q,
  8764. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  8765. timeout_req);
  8766. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  8767. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8768. "0331 IOCB wake signaled\n");
  8769. } else if (timeleft == 0) {
  8770. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8771. "0338 IOCB wait timeout error - no "
  8772. "wake response Data x%x\n", timeout);
  8773. retval = IOCB_TIMEDOUT;
  8774. } else {
  8775. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8776. "0330 IOCB wake NOT set, "
  8777. "Data x%x x%lx\n",
  8778. timeout, (timeleft / jiffies));
  8779. retval = IOCB_TIMEDOUT;
  8780. }
  8781. } else if (retval == IOCB_BUSY) {
  8782. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8783. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  8784. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  8785. return retval;
  8786. } else {
  8787. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8788. "0332 IOCB wait issue failed, Data x%x\n",
  8789. retval);
  8790. retval = IOCB_ERROR;
  8791. }
  8792. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  8793. if (lpfc_readl(phba->HCregaddr, &creg_val))
  8794. return IOCB_ERROR;
  8795. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  8796. writel(creg_val, phba->HCregaddr);
  8797. readl(phba->HCregaddr); /* flush */
  8798. }
  8799. if (prspiocbq)
  8800. piocb->context2 = NULL;
  8801. piocb->context_un.wait_queue = NULL;
  8802. piocb->iocb_cmpl = NULL;
  8803. return retval;
  8804. }
  8805. /**
  8806. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  8807. * @phba: Pointer to HBA context object.
  8808. * @pmboxq: Pointer to driver mailbox object.
  8809. * @timeout: Timeout in number of seconds.
  8810. *
  8811. * This function issues the mailbox to firmware and waits for the
  8812. * mailbox command to complete. If the mailbox command is not
  8813. * completed within timeout seconds, it returns MBX_TIMEOUT.
  8814. * The function waits for the mailbox completion using an
  8815. * interruptible wait. If the thread is woken up due to a
  8816. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  8817. * should not free the mailbox resources, if this function returns
  8818. * MBX_TIMEOUT.
  8819. * This function will sleep while waiting for mailbox completion.
  8820. * So, this function should not be called from any context which
  8821. * does not allow sleeping. Due to the same reason, this function
  8822. * cannot be called with interrupt disabled.
  8823. * This function assumes that the mailbox completion occurs while
  8824. * this function sleep. So, this function cannot be called from
  8825. * the worker thread which processes mailbox completion.
  8826. * This function is called in the context of HBA management
  8827. * applications.
  8828. * This function returns MBX_SUCCESS when successful.
  8829. * This function is called with no lock held.
  8830. **/
  8831. int
  8832. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  8833. uint32_t timeout)
  8834. {
  8835. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  8836. int retval;
  8837. unsigned long flag;
  8838. /* The caller must leave context1 empty. */
  8839. if (pmboxq->context1)
  8840. return MBX_NOT_FINISHED;
  8841. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  8842. /* setup wake call as IOCB callback */
  8843. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  8844. /* setup context field to pass wait_queue pointer to wake function */
  8845. pmboxq->context1 = &done_q;
  8846. /* now issue the command */
  8847. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  8848. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  8849. wait_event_interruptible_timeout(done_q,
  8850. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  8851. timeout * HZ);
  8852. spin_lock_irqsave(&phba->hbalock, flag);
  8853. pmboxq->context1 = NULL;
  8854. /*
  8855. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  8856. * else do not free the resources.
  8857. */
  8858. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  8859. retval = MBX_SUCCESS;
  8860. lpfc_sli4_swap_str(phba, pmboxq);
  8861. } else {
  8862. retval = MBX_TIMEOUT;
  8863. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8864. }
  8865. spin_unlock_irqrestore(&phba->hbalock, flag);
  8866. }
  8867. return retval;
  8868. }
  8869. /**
  8870. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  8871. * @phba: Pointer to HBA context.
  8872. *
  8873. * This function is called to shutdown the driver's mailbox sub-system.
  8874. * It first marks the mailbox sub-system is in a block state to prevent
  8875. * the asynchronous mailbox command from issued off the pending mailbox
  8876. * command queue. If the mailbox command sub-system shutdown is due to
  8877. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  8878. * the mailbox sub-system flush routine to forcefully bring down the
  8879. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  8880. * as with offline or HBA function reset), this routine will wait for the
  8881. * outstanding mailbox command to complete before invoking the mailbox
  8882. * sub-system flush routine to gracefully bring down mailbox sub-system.
  8883. **/
  8884. void
  8885. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  8886. {
  8887. struct lpfc_sli *psli = &phba->sli;
  8888. unsigned long timeout;
  8889. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  8890. spin_lock_irq(&phba->hbalock);
  8891. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  8892. spin_unlock_irq(&phba->hbalock);
  8893. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  8894. spin_lock_irq(&phba->hbalock);
  8895. /* Determine how long we might wait for the active mailbox
  8896. * command to be gracefully completed by firmware.
  8897. */
  8898. if (phba->sli.mbox_active)
  8899. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  8900. phba->sli.mbox_active) *
  8901. 1000) + jiffies;
  8902. spin_unlock_irq(&phba->hbalock);
  8903. while (phba->sli.mbox_active) {
  8904. /* Check active mailbox complete status every 2ms */
  8905. msleep(2);
  8906. if (time_after(jiffies, timeout))
  8907. /* Timeout, let the mailbox flush routine to
  8908. * forcefully release active mailbox command
  8909. */
  8910. break;
  8911. }
  8912. }
  8913. lpfc_sli_mbox_sys_flush(phba);
  8914. }
  8915. /**
  8916. * lpfc_sli_eratt_read - read sli-3 error attention events
  8917. * @phba: Pointer to HBA context.
  8918. *
  8919. * This function is called to read the SLI3 device error attention registers
  8920. * for possible error attention events. The caller must hold the hostlock
  8921. * with spin_lock_irq().
  8922. *
  8923. * This function returns 1 when there is Error Attention in the Host Attention
  8924. * Register and returns 0 otherwise.
  8925. **/
  8926. static int
  8927. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  8928. {
  8929. uint32_t ha_copy;
  8930. /* Read chip Host Attention (HA) register */
  8931. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  8932. goto unplug_err;
  8933. if (ha_copy & HA_ERATT) {
  8934. /* Read host status register to retrieve error event */
  8935. if (lpfc_sli_read_hs(phba))
  8936. goto unplug_err;
  8937. /* Check if there is a deferred error condition is active */
  8938. if ((HS_FFER1 & phba->work_hs) &&
  8939. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  8940. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  8941. phba->hba_flag |= DEFER_ERATT;
  8942. /* Clear all interrupt enable conditions */
  8943. writel(0, phba->HCregaddr);
  8944. readl(phba->HCregaddr);
  8945. }
  8946. /* Set the driver HA work bitmap */
  8947. phba->work_ha |= HA_ERATT;
  8948. /* Indicate polling handles this ERATT */
  8949. phba->hba_flag |= HBA_ERATT_HANDLED;
  8950. return 1;
  8951. }
  8952. return 0;
  8953. unplug_err:
  8954. /* Set the driver HS work bitmap */
  8955. phba->work_hs |= UNPLUG_ERR;
  8956. /* Set the driver HA work bitmap */
  8957. phba->work_ha |= HA_ERATT;
  8958. /* Indicate polling handles this ERATT */
  8959. phba->hba_flag |= HBA_ERATT_HANDLED;
  8960. return 1;
  8961. }
  8962. /**
  8963. * lpfc_sli4_eratt_read - read sli-4 error attention events
  8964. * @phba: Pointer to HBA context.
  8965. *
  8966. * This function is called to read the SLI4 device error attention registers
  8967. * for possible error attention events. The caller must hold the hostlock
  8968. * with spin_lock_irq().
  8969. *
  8970. * This function returns 1 when there is Error Attention in the Host Attention
  8971. * Register and returns 0 otherwise.
  8972. **/
  8973. static int
  8974. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  8975. {
  8976. uint32_t uerr_sta_hi, uerr_sta_lo;
  8977. uint32_t if_type, portsmphr;
  8978. struct lpfc_register portstat_reg;
  8979. /*
  8980. * For now, use the SLI4 device internal unrecoverable error
  8981. * registers for error attention. This can be changed later.
  8982. */
  8983. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  8984. switch (if_type) {
  8985. case LPFC_SLI_INTF_IF_TYPE_0:
  8986. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  8987. &uerr_sta_lo) ||
  8988. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  8989. &uerr_sta_hi)) {
  8990. phba->work_hs |= UNPLUG_ERR;
  8991. phba->work_ha |= HA_ERATT;
  8992. phba->hba_flag |= HBA_ERATT_HANDLED;
  8993. return 1;
  8994. }
  8995. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  8996. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  8997. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8998. "1423 HBA Unrecoverable error: "
  8999. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9000. "ue_mask_lo_reg=0x%x, "
  9001. "ue_mask_hi_reg=0x%x\n",
  9002. uerr_sta_lo, uerr_sta_hi,
  9003. phba->sli4_hba.ue_mask_lo,
  9004. phba->sli4_hba.ue_mask_hi);
  9005. phba->work_status[0] = uerr_sta_lo;
  9006. phba->work_status[1] = uerr_sta_hi;
  9007. phba->work_ha |= HA_ERATT;
  9008. phba->hba_flag |= HBA_ERATT_HANDLED;
  9009. return 1;
  9010. }
  9011. break;
  9012. case LPFC_SLI_INTF_IF_TYPE_2:
  9013. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9014. &portstat_reg.word0) ||
  9015. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9016. &portsmphr)){
  9017. phba->work_hs |= UNPLUG_ERR;
  9018. phba->work_ha |= HA_ERATT;
  9019. phba->hba_flag |= HBA_ERATT_HANDLED;
  9020. return 1;
  9021. }
  9022. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9023. phba->work_status[0] =
  9024. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9025. phba->work_status[1] =
  9026. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9027. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9028. "2885 Port Error Detected: "
  9029. "port status reg 0x%x, "
  9030. "port smphr reg 0x%x, "
  9031. "error 1=0x%x, error 2=0x%x\n",
  9032. portstat_reg.word0,
  9033. portsmphr,
  9034. phba->work_status[0],
  9035. phba->work_status[1]);
  9036. phba->work_ha |= HA_ERATT;
  9037. phba->hba_flag |= HBA_ERATT_HANDLED;
  9038. return 1;
  9039. }
  9040. break;
  9041. case LPFC_SLI_INTF_IF_TYPE_1:
  9042. default:
  9043. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9044. "2886 HBA Error Attention on unsupported "
  9045. "if type %d.", if_type);
  9046. return 1;
  9047. }
  9048. return 0;
  9049. }
  9050. /**
  9051. * lpfc_sli_check_eratt - check error attention events
  9052. * @phba: Pointer to HBA context.
  9053. *
  9054. * This function is called from timer soft interrupt context to check HBA's
  9055. * error attention register bit for error attention events.
  9056. *
  9057. * This function returns 1 when there is Error Attention in the Host Attention
  9058. * Register and returns 0 otherwise.
  9059. **/
  9060. int
  9061. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9062. {
  9063. uint32_t ha_copy;
  9064. /* If somebody is waiting to handle an eratt, don't process it
  9065. * here. The brdkill function will do this.
  9066. */
  9067. if (phba->link_flag & LS_IGNORE_ERATT)
  9068. return 0;
  9069. /* Check if interrupt handler handles this ERATT */
  9070. spin_lock_irq(&phba->hbalock);
  9071. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  9072. /* Interrupt handler has handled ERATT */
  9073. spin_unlock_irq(&phba->hbalock);
  9074. return 0;
  9075. }
  9076. /*
  9077. * If there is deferred error attention, do not check for error
  9078. * attention
  9079. */
  9080. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9081. spin_unlock_irq(&phba->hbalock);
  9082. return 0;
  9083. }
  9084. /* If PCI channel is offline, don't process it */
  9085. if (unlikely(pci_channel_offline(phba->pcidev))) {
  9086. spin_unlock_irq(&phba->hbalock);
  9087. return 0;
  9088. }
  9089. switch (phba->sli_rev) {
  9090. case LPFC_SLI_REV2:
  9091. case LPFC_SLI_REV3:
  9092. /* Read chip Host Attention (HA) register */
  9093. ha_copy = lpfc_sli_eratt_read(phba);
  9094. break;
  9095. case LPFC_SLI_REV4:
  9096. /* Read device Uncoverable Error (UERR) registers */
  9097. ha_copy = lpfc_sli4_eratt_read(phba);
  9098. break;
  9099. default:
  9100. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9101. "0299 Invalid SLI revision (%d)\n",
  9102. phba->sli_rev);
  9103. ha_copy = 0;
  9104. break;
  9105. }
  9106. spin_unlock_irq(&phba->hbalock);
  9107. return ha_copy;
  9108. }
  9109. /**
  9110. * lpfc_intr_state_check - Check device state for interrupt handling
  9111. * @phba: Pointer to HBA context.
  9112. *
  9113. * This inline routine checks whether a device or its PCI slot is in a state
  9114. * that the interrupt should be handled.
  9115. *
  9116. * This function returns 0 if the device or the PCI slot is in a state that
  9117. * interrupt should be handled, otherwise -EIO.
  9118. */
  9119. static inline int
  9120. lpfc_intr_state_check(struct lpfc_hba *phba)
  9121. {
  9122. /* If the pci channel is offline, ignore all the interrupts */
  9123. if (unlikely(pci_channel_offline(phba->pcidev)))
  9124. return -EIO;
  9125. /* Update device level interrupt statistics */
  9126. phba->sli.slistat.sli_intr++;
  9127. /* Ignore all interrupts during initialization. */
  9128. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  9129. return -EIO;
  9130. return 0;
  9131. }
  9132. /**
  9133. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  9134. * @irq: Interrupt number.
  9135. * @dev_id: The device context pointer.
  9136. *
  9137. * This function is directly called from the PCI layer as an interrupt
  9138. * service routine when device with SLI-3 interface spec is enabled with
  9139. * MSI-X multi-message interrupt mode and there are slow-path events in
  9140. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9141. * interrupt mode, this function is called as part of the device-level
  9142. * interrupt handler. When the PCI slot is in error recovery or the HBA
  9143. * is undergoing initialization, the interrupt handler will not process
  9144. * the interrupt. The link attention and ELS ring attention events are
  9145. * handled by the worker thread. The interrupt handler signals the worker
  9146. * thread and returns for these events. This function is called without
  9147. * any lock held. It gets the hbalock to access and update SLI data
  9148. * structures.
  9149. *
  9150. * This function returns IRQ_HANDLED when interrupt is handled else it
  9151. * returns IRQ_NONE.
  9152. **/
  9153. irqreturn_t
  9154. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  9155. {
  9156. struct lpfc_hba *phba;
  9157. uint32_t ha_copy, hc_copy;
  9158. uint32_t work_ha_copy;
  9159. unsigned long status;
  9160. unsigned long iflag;
  9161. uint32_t control;
  9162. MAILBOX_t *mbox, *pmbox;
  9163. struct lpfc_vport *vport;
  9164. struct lpfc_nodelist *ndlp;
  9165. struct lpfc_dmabuf *mp;
  9166. LPFC_MBOXQ_t *pmb;
  9167. int rc;
  9168. /*
  9169. * Get the driver's phba structure from the dev_id and
  9170. * assume the HBA is not interrupting.
  9171. */
  9172. phba = (struct lpfc_hba *)dev_id;
  9173. if (unlikely(!phba))
  9174. return IRQ_NONE;
  9175. /*
  9176. * Stuff needs to be attented to when this function is invoked as an
  9177. * individual interrupt handler in MSI-X multi-message interrupt mode
  9178. */
  9179. if (phba->intr_type == MSIX) {
  9180. /* Check device state for handling interrupt */
  9181. if (lpfc_intr_state_check(phba))
  9182. return IRQ_NONE;
  9183. /* Need to read HA REG for slow-path events */
  9184. spin_lock_irqsave(&phba->hbalock, iflag);
  9185. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9186. goto unplug_error;
  9187. /* If somebody is waiting to handle an eratt don't process it
  9188. * here. The brdkill function will do this.
  9189. */
  9190. if (phba->link_flag & LS_IGNORE_ERATT)
  9191. ha_copy &= ~HA_ERATT;
  9192. /* Check the need for handling ERATT in interrupt handler */
  9193. if (ha_copy & HA_ERATT) {
  9194. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9195. /* ERATT polling has handled ERATT */
  9196. ha_copy &= ~HA_ERATT;
  9197. else
  9198. /* Indicate interrupt handler handles ERATT */
  9199. phba->hba_flag |= HBA_ERATT_HANDLED;
  9200. }
  9201. /*
  9202. * If there is deferred error attention, do not check for any
  9203. * interrupt.
  9204. */
  9205. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9206. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9207. return IRQ_NONE;
  9208. }
  9209. /* Clear up only attention source related to slow-path */
  9210. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  9211. goto unplug_error;
  9212. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  9213. HC_LAINT_ENA | HC_ERINT_ENA),
  9214. phba->HCregaddr);
  9215. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  9216. phba->HAregaddr);
  9217. writel(hc_copy, phba->HCregaddr);
  9218. readl(phba->HAregaddr); /* flush */
  9219. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9220. } else
  9221. ha_copy = phba->ha_copy;
  9222. work_ha_copy = ha_copy & phba->work_ha_mask;
  9223. if (work_ha_copy) {
  9224. if (work_ha_copy & HA_LATT) {
  9225. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  9226. /*
  9227. * Turn off Link Attention interrupts
  9228. * until CLEAR_LA done
  9229. */
  9230. spin_lock_irqsave(&phba->hbalock, iflag);
  9231. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  9232. if (lpfc_readl(phba->HCregaddr, &control))
  9233. goto unplug_error;
  9234. control &= ~HC_LAINT_ENA;
  9235. writel(control, phba->HCregaddr);
  9236. readl(phba->HCregaddr); /* flush */
  9237. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9238. }
  9239. else
  9240. work_ha_copy &= ~HA_LATT;
  9241. }
  9242. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  9243. /*
  9244. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  9245. * the only slow ring.
  9246. */
  9247. status = (work_ha_copy &
  9248. (HA_RXMASK << (4*LPFC_ELS_RING)));
  9249. status >>= (4*LPFC_ELS_RING);
  9250. if (status & HA_RXMASK) {
  9251. spin_lock_irqsave(&phba->hbalock, iflag);
  9252. if (lpfc_readl(phba->HCregaddr, &control))
  9253. goto unplug_error;
  9254. lpfc_debugfs_slow_ring_trc(phba,
  9255. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  9256. control, status,
  9257. (uint32_t)phba->sli.slistat.sli_intr);
  9258. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  9259. lpfc_debugfs_slow_ring_trc(phba,
  9260. "ISR Disable ring:"
  9261. "pwork:x%x hawork:x%x wait:x%x",
  9262. phba->work_ha, work_ha_copy,
  9263. (uint32_t)((unsigned long)
  9264. &phba->work_waitq));
  9265. control &=
  9266. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  9267. writel(control, phba->HCregaddr);
  9268. readl(phba->HCregaddr); /* flush */
  9269. }
  9270. else {
  9271. lpfc_debugfs_slow_ring_trc(phba,
  9272. "ISR slow ring: pwork:"
  9273. "x%x hawork:x%x wait:x%x",
  9274. phba->work_ha, work_ha_copy,
  9275. (uint32_t)((unsigned long)
  9276. &phba->work_waitq));
  9277. }
  9278. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9279. }
  9280. }
  9281. spin_lock_irqsave(&phba->hbalock, iflag);
  9282. if (work_ha_copy & HA_ERATT) {
  9283. if (lpfc_sli_read_hs(phba))
  9284. goto unplug_error;
  9285. /*
  9286. * Check if there is a deferred error condition
  9287. * is active
  9288. */
  9289. if ((HS_FFER1 & phba->work_hs) &&
  9290. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9291. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  9292. phba->work_hs)) {
  9293. phba->hba_flag |= DEFER_ERATT;
  9294. /* Clear all interrupt enable conditions */
  9295. writel(0, phba->HCregaddr);
  9296. readl(phba->HCregaddr);
  9297. }
  9298. }
  9299. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  9300. pmb = phba->sli.mbox_active;
  9301. pmbox = &pmb->u.mb;
  9302. mbox = phba->mbox;
  9303. vport = pmb->vport;
  9304. /* First check out the status word */
  9305. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  9306. if (pmbox->mbxOwner != OWN_HOST) {
  9307. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9308. /*
  9309. * Stray Mailbox Interrupt, mbxCommand <cmd>
  9310. * mbxStatus <status>
  9311. */
  9312. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9313. LOG_SLI,
  9314. "(%d):0304 Stray Mailbox "
  9315. "Interrupt mbxCommand x%x "
  9316. "mbxStatus x%x\n",
  9317. (vport ? vport->vpi : 0),
  9318. pmbox->mbxCommand,
  9319. pmbox->mbxStatus);
  9320. /* clear mailbox attention bit */
  9321. work_ha_copy &= ~HA_MBATT;
  9322. } else {
  9323. phba->sli.mbox_active = NULL;
  9324. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9325. phba->last_completion_time = jiffies;
  9326. del_timer(&phba->sli.mbox_tmo);
  9327. if (pmb->mbox_cmpl) {
  9328. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  9329. MAILBOX_CMD_SIZE);
  9330. if (pmb->out_ext_byte_len &&
  9331. pmb->context2)
  9332. lpfc_sli_pcimem_bcopy(
  9333. phba->mbox_ext,
  9334. pmb->context2,
  9335. pmb->out_ext_byte_len);
  9336. }
  9337. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  9338. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  9339. lpfc_debugfs_disc_trc(vport,
  9340. LPFC_DISC_TRC_MBOX_VPORT,
  9341. "MBOX dflt rpi: : "
  9342. "status:x%x rpi:x%x",
  9343. (uint32_t)pmbox->mbxStatus,
  9344. pmbox->un.varWords[0], 0);
  9345. if (!pmbox->mbxStatus) {
  9346. mp = (struct lpfc_dmabuf *)
  9347. (pmb->context1);
  9348. ndlp = (struct lpfc_nodelist *)
  9349. pmb->context2;
  9350. /* Reg_LOGIN of dflt RPI was
  9351. * successful. new lets get
  9352. * rid of the RPI using the
  9353. * same mbox buffer.
  9354. */
  9355. lpfc_unreg_login(phba,
  9356. vport->vpi,
  9357. pmbox->un.varWords[0],
  9358. pmb);
  9359. pmb->mbox_cmpl =
  9360. lpfc_mbx_cmpl_dflt_rpi;
  9361. pmb->context1 = mp;
  9362. pmb->context2 = ndlp;
  9363. pmb->vport = vport;
  9364. rc = lpfc_sli_issue_mbox(phba,
  9365. pmb,
  9366. MBX_NOWAIT);
  9367. if (rc != MBX_BUSY)
  9368. lpfc_printf_log(phba,
  9369. KERN_ERR,
  9370. LOG_MBOX | LOG_SLI,
  9371. "0350 rc should have"
  9372. "been MBX_BUSY\n");
  9373. if (rc != MBX_NOT_FINISHED)
  9374. goto send_current_mbox;
  9375. }
  9376. }
  9377. spin_lock_irqsave(
  9378. &phba->pport->work_port_lock,
  9379. iflag);
  9380. phba->pport->work_port_events &=
  9381. ~WORKER_MBOX_TMO;
  9382. spin_unlock_irqrestore(
  9383. &phba->pport->work_port_lock,
  9384. iflag);
  9385. lpfc_mbox_cmpl_put(phba, pmb);
  9386. }
  9387. } else
  9388. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9389. if ((work_ha_copy & HA_MBATT) &&
  9390. (phba->sli.mbox_active == NULL)) {
  9391. send_current_mbox:
  9392. /* Process next mailbox command if there is one */
  9393. do {
  9394. rc = lpfc_sli_issue_mbox(phba, NULL,
  9395. MBX_NOWAIT);
  9396. } while (rc == MBX_NOT_FINISHED);
  9397. if (rc != MBX_SUCCESS)
  9398. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9399. LOG_SLI, "0349 rc should be "
  9400. "MBX_SUCCESS\n");
  9401. }
  9402. spin_lock_irqsave(&phba->hbalock, iflag);
  9403. phba->work_ha |= work_ha_copy;
  9404. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9405. lpfc_worker_wake_up(phba);
  9406. }
  9407. return IRQ_HANDLED;
  9408. unplug_error:
  9409. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9410. return IRQ_HANDLED;
  9411. } /* lpfc_sli_sp_intr_handler */
  9412. /**
  9413. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  9414. * @irq: Interrupt number.
  9415. * @dev_id: The device context pointer.
  9416. *
  9417. * This function is directly called from the PCI layer as an interrupt
  9418. * service routine when device with SLI-3 interface spec is enabled with
  9419. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9420. * ring event in the HBA. However, when the device is enabled with either
  9421. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9422. * device-level interrupt handler. When the PCI slot is in error recovery
  9423. * or the HBA is undergoing initialization, the interrupt handler will not
  9424. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9425. * the intrrupt context. This function is called without any lock held.
  9426. * It gets the hbalock to access and update SLI data structures.
  9427. *
  9428. * This function returns IRQ_HANDLED when interrupt is handled else it
  9429. * returns IRQ_NONE.
  9430. **/
  9431. irqreturn_t
  9432. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  9433. {
  9434. struct lpfc_hba *phba;
  9435. uint32_t ha_copy;
  9436. unsigned long status;
  9437. unsigned long iflag;
  9438. /* Get the driver's phba structure from the dev_id and
  9439. * assume the HBA is not interrupting.
  9440. */
  9441. phba = (struct lpfc_hba *) dev_id;
  9442. if (unlikely(!phba))
  9443. return IRQ_NONE;
  9444. /*
  9445. * Stuff needs to be attented to when this function is invoked as an
  9446. * individual interrupt handler in MSI-X multi-message interrupt mode
  9447. */
  9448. if (phba->intr_type == MSIX) {
  9449. /* Check device state for handling interrupt */
  9450. if (lpfc_intr_state_check(phba))
  9451. return IRQ_NONE;
  9452. /* Need to read HA REG for FCP ring and other ring events */
  9453. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9454. return IRQ_HANDLED;
  9455. /* Clear up only attention source related to fast-path */
  9456. spin_lock_irqsave(&phba->hbalock, iflag);
  9457. /*
  9458. * If there is deferred error attention, do not check for
  9459. * any interrupt.
  9460. */
  9461. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9462. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9463. return IRQ_NONE;
  9464. }
  9465. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  9466. phba->HAregaddr);
  9467. readl(phba->HAregaddr); /* flush */
  9468. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9469. } else
  9470. ha_copy = phba->ha_copy;
  9471. /*
  9472. * Process all events on FCP ring. Take the optimized path for FCP IO.
  9473. */
  9474. ha_copy &= ~(phba->work_ha_mask);
  9475. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9476. status >>= (4*LPFC_FCP_RING);
  9477. if (status & HA_RXMASK)
  9478. lpfc_sli_handle_fast_ring_event(phba,
  9479. &phba->sli.ring[LPFC_FCP_RING],
  9480. status);
  9481. if (phba->cfg_multi_ring_support == 2) {
  9482. /*
  9483. * Process all events on extra ring. Take the optimized path
  9484. * for extra ring IO.
  9485. */
  9486. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9487. status >>= (4*LPFC_EXTRA_RING);
  9488. if (status & HA_RXMASK) {
  9489. lpfc_sli_handle_fast_ring_event(phba,
  9490. &phba->sli.ring[LPFC_EXTRA_RING],
  9491. status);
  9492. }
  9493. }
  9494. return IRQ_HANDLED;
  9495. } /* lpfc_sli_fp_intr_handler */
  9496. /**
  9497. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  9498. * @irq: Interrupt number.
  9499. * @dev_id: The device context pointer.
  9500. *
  9501. * This function is the HBA device-level interrupt handler to device with
  9502. * SLI-3 interface spec, called from the PCI layer when either MSI or
  9503. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  9504. * requires driver attention. This function invokes the slow-path interrupt
  9505. * attention handling function and fast-path interrupt attention handling
  9506. * function in turn to process the relevant HBA attention events. This
  9507. * function is called without any lock held. It gets the hbalock to access
  9508. * and update SLI data structures.
  9509. *
  9510. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9511. * returns IRQ_NONE.
  9512. **/
  9513. irqreturn_t
  9514. lpfc_sli_intr_handler(int irq, void *dev_id)
  9515. {
  9516. struct lpfc_hba *phba;
  9517. irqreturn_t sp_irq_rc, fp_irq_rc;
  9518. unsigned long status1, status2;
  9519. uint32_t hc_copy;
  9520. /*
  9521. * Get the driver's phba structure from the dev_id and
  9522. * assume the HBA is not interrupting.
  9523. */
  9524. phba = (struct lpfc_hba *) dev_id;
  9525. if (unlikely(!phba))
  9526. return IRQ_NONE;
  9527. /* Check device state for handling interrupt */
  9528. if (lpfc_intr_state_check(phba))
  9529. return IRQ_NONE;
  9530. spin_lock(&phba->hbalock);
  9531. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  9532. spin_unlock(&phba->hbalock);
  9533. return IRQ_HANDLED;
  9534. }
  9535. if (unlikely(!phba->ha_copy)) {
  9536. spin_unlock(&phba->hbalock);
  9537. return IRQ_NONE;
  9538. } else if (phba->ha_copy & HA_ERATT) {
  9539. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9540. /* ERATT polling has handled ERATT */
  9541. phba->ha_copy &= ~HA_ERATT;
  9542. else
  9543. /* Indicate interrupt handler handles ERATT */
  9544. phba->hba_flag |= HBA_ERATT_HANDLED;
  9545. }
  9546. /*
  9547. * If there is deferred error attention, do not check for any interrupt.
  9548. */
  9549. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9550. spin_unlock(&phba->hbalock);
  9551. return IRQ_NONE;
  9552. }
  9553. /* Clear attention sources except link and error attentions */
  9554. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  9555. spin_unlock(&phba->hbalock);
  9556. return IRQ_HANDLED;
  9557. }
  9558. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  9559. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  9560. phba->HCregaddr);
  9561. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  9562. writel(hc_copy, phba->HCregaddr);
  9563. readl(phba->HAregaddr); /* flush */
  9564. spin_unlock(&phba->hbalock);
  9565. /*
  9566. * Invokes slow-path host attention interrupt handling as appropriate.
  9567. */
  9568. /* status of events with mailbox and link attention */
  9569. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  9570. /* status of events with ELS ring */
  9571. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  9572. status2 >>= (4*LPFC_ELS_RING);
  9573. if (status1 || (status2 & HA_RXMASK))
  9574. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  9575. else
  9576. sp_irq_rc = IRQ_NONE;
  9577. /*
  9578. * Invoke fast-path host attention interrupt handling as appropriate.
  9579. */
  9580. /* status of events with FCP ring */
  9581. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9582. status1 >>= (4*LPFC_FCP_RING);
  9583. /* status of events with extra ring */
  9584. if (phba->cfg_multi_ring_support == 2) {
  9585. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9586. status2 >>= (4*LPFC_EXTRA_RING);
  9587. } else
  9588. status2 = 0;
  9589. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  9590. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  9591. else
  9592. fp_irq_rc = IRQ_NONE;
  9593. /* Return device-level interrupt handling status */
  9594. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  9595. } /* lpfc_sli_intr_handler */
  9596. /**
  9597. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  9598. * @phba: pointer to lpfc hba data structure.
  9599. *
  9600. * This routine is invoked by the worker thread to process all the pending
  9601. * SLI4 FCP abort XRI events.
  9602. **/
  9603. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  9604. {
  9605. struct lpfc_cq_event *cq_event;
  9606. /* First, declare the fcp xri abort event has been handled */
  9607. spin_lock_irq(&phba->hbalock);
  9608. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  9609. spin_unlock_irq(&phba->hbalock);
  9610. /* Now, handle all the fcp xri abort events */
  9611. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  9612. /* Get the first event from the head of the event queue */
  9613. spin_lock_irq(&phba->hbalock);
  9614. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  9615. cq_event, struct lpfc_cq_event, list);
  9616. spin_unlock_irq(&phba->hbalock);
  9617. /* Notify aborted XRI for FCP work queue */
  9618. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9619. /* Free the event processed back to the free pool */
  9620. lpfc_sli4_cq_event_release(phba, cq_event);
  9621. }
  9622. }
  9623. /**
  9624. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  9625. * @phba: pointer to lpfc hba data structure.
  9626. *
  9627. * This routine is invoked by the worker thread to process all the pending
  9628. * SLI4 els abort xri events.
  9629. **/
  9630. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  9631. {
  9632. struct lpfc_cq_event *cq_event;
  9633. /* First, declare the els xri abort event has been handled */
  9634. spin_lock_irq(&phba->hbalock);
  9635. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  9636. spin_unlock_irq(&phba->hbalock);
  9637. /* Now, handle all the els xri abort events */
  9638. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  9639. /* Get the first event from the head of the event queue */
  9640. spin_lock_irq(&phba->hbalock);
  9641. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  9642. cq_event, struct lpfc_cq_event, list);
  9643. spin_unlock_irq(&phba->hbalock);
  9644. /* Notify aborted XRI for ELS work queue */
  9645. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9646. /* Free the event processed back to the free pool */
  9647. lpfc_sli4_cq_event_release(phba, cq_event);
  9648. }
  9649. }
  9650. /**
  9651. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  9652. * @phba: pointer to lpfc hba data structure
  9653. * @pIocbIn: pointer to the rspiocbq
  9654. * @pIocbOut: pointer to the cmdiocbq
  9655. * @wcqe: pointer to the complete wcqe
  9656. *
  9657. * This routine transfers the fields of a command iocbq to a response iocbq
  9658. * by copying all the IOCB fields from command iocbq and transferring the
  9659. * completion status information from the complete wcqe.
  9660. **/
  9661. static void
  9662. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  9663. struct lpfc_iocbq *pIocbIn,
  9664. struct lpfc_iocbq *pIocbOut,
  9665. struct lpfc_wcqe_complete *wcqe)
  9666. {
  9667. unsigned long iflags;
  9668. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  9669. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  9670. sizeof(struct lpfc_iocbq) - offset);
  9671. /* Map WCQE parameters into irspiocb parameters */
  9672. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  9673. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  9674. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  9675. pIocbIn->iocb.un.fcpi.fcpi_parm =
  9676. pIocbOut->iocb.un.fcpi.fcpi_parm -
  9677. wcqe->total_data_placed;
  9678. else
  9679. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9680. else {
  9681. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9682. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  9683. }
  9684. /* Pick up HBA exchange busy condition */
  9685. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  9686. spin_lock_irqsave(&phba->hbalock, iflags);
  9687. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  9688. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9689. }
  9690. }
  9691. /**
  9692. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  9693. * @phba: Pointer to HBA context object.
  9694. * @wcqe: Pointer to work-queue completion queue entry.
  9695. *
  9696. * This routine handles an ELS work-queue completion event and construct
  9697. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  9698. * discovery engine to handle.
  9699. *
  9700. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  9701. **/
  9702. static struct lpfc_iocbq *
  9703. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  9704. struct lpfc_iocbq *irspiocbq)
  9705. {
  9706. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9707. struct lpfc_iocbq *cmdiocbq;
  9708. struct lpfc_wcqe_complete *wcqe;
  9709. unsigned long iflags;
  9710. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  9711. spin_lock_irqsave(&phba->hbalock, iflags);
  9712. pring->stats.iocb_event++;
  9713. /* Look up the ELS command IOCB and create pseudo response IOCB */
  9714. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  9715. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9716. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9717. if (unlikely(!cmdiocbq)) {
  9718. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9719. "0386 ELS complete with no corresponding "
  9720. "cmdiocb: iotag (%d)\n",
  9721. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9722. lpfc_sli_release_iocbq(phba, irspiocbq);
  9723. return NULL;
  9724. }
  9725. /* Fake the irspiocbq and copy necessary response information */
  9726. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  9727. return irspiocbq;
  9728. }
  9729. /**
  9730. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  9731. * @phba: Pointer to HBA context object.
  9732. * @cqe: Pointer to mailbox completion queue entry.
  9733. *
  9734. * This routine process a mailbox completion queue entry with asynchrous
  9735. * event.
  9736. *
  9737. * Return: true if work posted to worker thread, otherwise false.
  9738. **/
  9739. static bool
  9740. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  9741. {
  9742. struct lpfc_cq_event *cq_event;
  9743. unsigned long iflags;
  9744. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9745. "0392 Async Event: word0:x%x, word1:x%x, "
  9746. "word2:x%x, word3:x%x\n", mcqe->word0,
  9747. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  9748. /* Allocate a new internal CQ_EVENT entry */
  9749. cq_event = lpfc_sli4_cq_event_alloc(phba);
  9750. if (!cq_event) {
  9751. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9752. "0394 Failed to allocate CQ_EVENT entry\n");
  9753. return false;
  9754. }
  9755. /* Move the CQE into an asynchronous event entry */
  9756. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  9757. spin_lock_irqsave(&phba->hbalock, iflags);
  9758. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  9759. /* Set the async event flag */
  9760. phba->hba_flag |= ASYNC_EVENT;
  9761. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9762. return true;
  9763. }
  9764. /**
  9765. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  9766. * @phba: Pointer to HBA context object.
  9767. * @cqe: Pointer to mailbox completion queue entry.
  9768. *
  9769. * This routine process a mailbox completion queue entry with mailbox
  9770. * completion event.
  9771. *
  9772. * Return: true if work posted to worker thread, otherwise false.
  9773. **/
  9774. static bool
  9775. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  9776. {
  9777. uint32_t mcqe_status;
  9778. MAILBOX_t *mbox, *pmbox;
  9779. struct lpfc_mqe *mqe;
  9780. struct lpfc_vport *vport;
  9781. struct lpfc_nodelist *ndlp;
  9782. struct lpfc_dmabuf *mp;
  9783. unsigned long iflags;
  9784. LPFC_MBOXQ_t *pmb;
  9785. bool workposted = false;
  9786. int rc;
  9787. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  9788. if (!bf_get(lpfc_trailer_completed, mcqe))
  9789. goto out_no_mqe_complete;
  9790. /* Get the reference to the active mbox command */
  9791. spin_lock_irqsave(&phba->hbalock, iflags);
  9792. pmb = phba->sli.mbox_active;
  9793. if (unlikely(!pmb)) {
  9794. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9795. "1832 No pending MBOX command to handle\n");
  9796. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9797. goto out_no_mqe_complete;
  9798. }
  9799. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9800. mqe = &pmb->u.mqe;
  9801. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  9802. mbox = phba->mbox;
  9803. vport = pmb->vport;
  9804. /* Reset heartbeat timer */
  9805. phba->last_completion_time = jiffies;
  9806. del_timer(&phba->sli.mbox_tmo);
  9807. /* Move mbox data to caller's mailbox region, do endian swapping */
  9808. if (pmb->mbox_cmpl && mbox)
  9809. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  9810. /*
  9811. * For mcqe errors, conditionally move a modified error code to
  9812. * the mbox so that the error will not be missed.
  9813. */
  9814. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  9815. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  9816. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  9817. bf_set(lpfc_mqe_status, mqe,
  9818. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  9819. }
  9820. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  9821. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  9822. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  9823. "MBOX dflt rpi: status:x%x rpi:x%x",
  9824. mcqe_status,
  9825. pmbox->un.varWords[0], 0);
  9826. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  9827. mp = (struct lpfc_dmabuf *)(pmb->context1);
  9828. ndlp = (struct lpfc_nodelist *)pmb->context2;
  9829. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  9830. * RID of the PPI using the same mbox buffer.
  9831. */
  9832. lpfc_unreg_login(phba, vport->vpi,
  9833. pmbox->un.varWords[0], pmb);
  9834. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  9835. pmb->context1 = mp;
  9836. pmb->context2 = ndlp;
  9837. pmb->vport = vport;
  9838. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  9839. if (rc != MBX_BUSY)
  9840. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9841. LOG_SLI, "0385 rc should "
  9842. "have been MBX_BUSY\n");
  9843. if (rc != MBX_NOT_FINISHED)
  9844. goto send_current_mbox;
  9845. }
  9846. }
  9847. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  9848. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  9849. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  9850. /* There is mailbox completion work to do */
  9851. spin_lock_irqsave(&phba->hbalock, iflags);
  9852. __lpfc_mbox_cmpl_put(phba, pmb);
  9853. phba->work_ha |= HA_MBATT;
  9854. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9855. workposted = true;
  9856. send_current_mbox:
  9857. spin_lock_irqsave(&phba->hbalock, iflags);
  9858. /* Release the mailbox command posting token */
  9859. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  9860. /* Setting active mailbox pointer need to be in sync to flag clear */
  9861. phba->sli.mbox_active = NULL;
  9862. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9863. /* Wake up worker thread to post the next pending mailbox command */
  9864. lpfc_worker_wake_up(phba);
  9865. out_no_mqe_complete:
  9866. if (bf_get(lpfc_trailer_consumed, mcqe))
  9867. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  9868. return workposted;
  9869. }
  9870. /**
  9871. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  9872. * @phba: Pointer to HBA context object.
  9873. * @cqe: Pointer to mailbox completion queue entry.
  9874. *
  9875. * This routine process a mailbox completion queue entry, it invokes the
  9876. * proper mailbox complete handling or asynchrous event handling routine
  9877. * according to the MCQE's async bit.
  9878. *
  9879. * Return: true if work posted to worker thread, otherwise false.
  9880. **/
  9881. static bool
  9882. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  9883. {
  9884. struct lpfc_mcqe mcqe;
  9885. bool workposted;
  9886. /* Copy the mailbox MCQE and convert endian order as needed */
  9887. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  9888. /* Invoke the proper event handling routine */
  9889. if (!bf_get(lpfc_trailer_async, &mcqe))
  9890. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  9891. else
  9892. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  9893. return workposted;
  9894. }
  9895. /**
  9896. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  9897. * @phba: Pointer to HBA context object.
  9898. * @wcqe: Pointer to work-queue completion queue entry.
  9899. *
  9900. * This routine handles an ELS work-queue completion event.
  9901. *
  9902. * Return: true if work posted to worker thread, otherwise false.
  9903. **/
  9904. static bool
  9905. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  9906. struct lpfc_wcqe_complete *wcqe)
  9907. {
  9908. struct lpfc_iocbq *irspiocbq;
  9909. unsigned long iflags;
  9910. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  9911. /* Get an irspiocbq for later ELS response processing use */
  9912. irspiocbq = lpfc_sli_get_iocbq(phba);
  9913. if (!irspiocbq) {
  9914. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9915. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  9916. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  9917. pring->txq_cnt, phba->iocb_cnt,
  9918. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  9919. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  9920. return false;
  9921. }
  9922. /* Save off the slow-path queue event for work thread to process */
  9923. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  9924. spin_lock_irqsave(&phba->hbalock, iflags);
  9925. list_add_tail(&irspiocbq->cq_event.list,
  9926. &phba->sli4_hba.sp_queue_event);
  9927. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  9928. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9929. return true;
  9930. }
  9931. /**
  9932. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  9933. * @phba: Pointer to HBA context object.
  9934. * @wcqe: Pointer to work-queue completion queue entry.
  9935. *
  9936. * This routine handles slow-path WQ entry comsumed event by invoking the
  9937. * proper WQ release routine to the slow-path WQ.
  9938. **/
  9939. static void
  9940. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  9941. struct lpfc_wcqe_release *wcqe)
  9942. {
  9943. /* Check for the slow-path ELS work queue */
  9944. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  9945. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  9946. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  9947. else
  9948. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9949. "2579 Slow-path wqe consume event carries "
  9950. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  9951. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  9952. phba->sli4_hba.els_wq->queue_id);
  9953. }
  9954. /**
  9955. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  9956. * @phba: Pointer to HBA context object.
  9957. * @cq: Pointer to a WQ completion queue.
  9958. * @wcqe: Pointer to work-queue completion queue entry.
  9959. *
  9960. * This routine handles an XRI abort event.
  9961. *
  9962. * Return: true if work posted to worker thread, otherwise false.
  9963. **/
  9964. static bool
  9965. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  9966. struct lpfc_queue *cq,
  9967. struct sli4_wcqe_xri_aborted *wcqe)
  9968. {
  9969. bool workposted = false;
  9970. struct lpfc_cq_event *cq_event;
  9971. unsigned long iflags;
  9972. /* Allocate a new internal CQ_EVENT entry */
  9973. cq_event = lpfc_sli4_cq_event_alloc(phba);
  9974. if (!cq_event) {
  9975. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9976. "0602 Failed to allocate CQ_EVENT entry\n");
  9977. return false;
  9978. }
  9979. /* Move the CQE into the proper xri abort event list */
  9980. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  9981. switch (cq->subtype) {
  9982. case LPFC_FCP:
  9983. spin_lock_irqsave(&phba->hbalock, iflags);
  9984. list_add_tail(&cq_event->list,
  9985. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  9986. /* Set the fcp xri abort event flag */
  9987. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  9988. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9989. workposted = true;
  9990. break;
  9991. case LPFC_ELS:
  9992. spin_lock_irqsave(&phba->hbalock, iflags);
  9993. list_add_tail(&cq_event->list,
  9994. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  9995. /* Set the els xri abort event flag */
  9996. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  9997. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9998. workposted = true;
  9999. break;
  10000. default:
  10001. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10002. "0603 Invalid work queue CQE subtype (x%x)\n",
  10003. cq->subtype);
  10004. workposted = false;
  10005. break;
  10006. }
  10007. return workposted;
  10008. }
  10009. /**
  10010. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  10011. * @phba: Pointer to HBA context object.
  10012. * @rcqe: Pointer to receive-queue completion queue entry.
  10013. *
  10014. * This routine process a receive-queue completion queue entry.
  10015. *
  10016. * Return: true if work posted to worker thread, otherwise false.
  10017. **/
  10018. static bool
  10019. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  10020. {
  10021. bool workposted = false;
  10022. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  10023. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  10024. struct hbq_dmabuf *dma_buf;
  10025. uint32_t status, rq_id;
  10026. unsigned long iflags;
  10027. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  10028. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  10029. else
  10030. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  10031. if (rq_id != hrq->queue_id)
  10032. goto out;
  10033. status = bf_get(lpfc_rcqe_status, rcqe);
  10034. switch (status) {
  10035. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  10036. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10037. "2537 Receive Frame Truncated!!\n");
  10038. case FC_STATUS_RQ_SUCCESS:
  10039. lpfc_sli4_rq_release(hrq, drq);
  10040. spin_lock_irqsave(&phba->hbalock, iflags);
  10041. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  10042. if (!dma_buf) {
  10043. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10044. goto out;
  10045. }
  10046. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  10047. /* save off the frame for the word thread to process */
  10048. list_add_tail(&dma_buf->cq_event.list,
  10049. &phba->sli4_hba.sp_queue_event);
  10050. /* Frame received */
  10051. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10052. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10053. workposted = true;
  10054. break;
  10055. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  10056. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  10057. /* Post more buffers if possible */
  10058. spin_lock_irqsave(&phba->hbalock, iflags);
  10059. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  10060. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10061. workposted = true;
  10062. break;
  10063. }
  10064. out:
  10065. return workposted;
  10066. }
  10067. /**
  10068. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  10069. * @phba: Pointer to HBA context object.
  10070. * @cq: Pointer to the completion queue.
  10071. * @wcqe: Pointer to a completion queue entry.
  10072. *
  10073. * This routine process a slow-path work-queue or receive queue completion queue
  10074. * entry.
  10075. *
  10076. * Return: true if work posted to worker thread, otherwise false.
  10077. **/
  10078. static bool
  10079. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10080. struct lpfc_cqe *cqe)
  10081. {
  10082. struct lpfc_cqe cqevt;
  10083. bool workposted = false;
  10084. /* Copy the work queue CQE and convert endian order if needed */
  10085. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  10086. /* Check and process for different type of WCQE and dispatch */
  10087. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  10088. case CQE_CODE_COMPL_WQE:
  10089. /* Process the WQ/RQ complete event */
  10090. phba->last_completion_time = jiffies;
  10091. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  10092. (struct lpfc_wcqe_complete *)&cqevt);
  10093. break;
  10094. case CQE_CODE_RELEASE_WQE:
  10095. /* Process the WQ release event */
  10096. lpfc_sli4_sp_handle_rel_wcqe(phba,
  10097. (struct lpfc_wcqe_release *)&cqevt);
  10098. break;
  10099. case CQE_CODE_XRI_ABORTED:
  10100. /* Process the WQ XRI abort event */
  10101. phba->last_completion_time = jiffies;
  10102. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10103. (struct sli4_wcqe_xri_aborted *)&cqevt);
  10104. break;
  10105. case CQE_CODE_RECEIVE:
  10106. case CQE_CODE_RECEIVE_V1:
  10107. /* Process the RQ event */
  10108. phba->last_completion_time = jiffies;
  10109. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  10110. (struct lpfc_rcqe *)&cqevt);
  10111. break;
  10112. default:
  10113. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10114. "0388 Not a valid WCQE code: x%x\n",
  10115. bf_get(lpfc_cqe_code, &cqevt));
  10116. break;
  10117. }
  10118. return workposted;
  10119. }
  10120. /**
  10121. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  10122. * @phba: Pointer to HBA context object.
  10123. * @eqe: Pointer to fast-path event queue entry.
  10124. *
  10125. * This routine process a event queue entry from the slow-path event queue.
  10126. * It will check the MajorCode and MinorCode to determine this is for a
  10127. * completion event on a completion queue, if not, an error shall be logged
  10128. * and just return. Otherwise, it will get to the corresponding completion
  10129. * queue and process all the entries on that completion queue, rearm the
  10130. * completion queue, and then return.
  10131. *
  10132. **/
  10133. static void
  10134. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  10135. {
  10136. struct lpfc_queue *cq = NULL, *childq, *speq;
  10137. struct lpfc_cqe *cqe;
  10138. bool workposted = false;
  10139. int ecount = 0;
  10140. uint16_t cqid;
  10141. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  10142. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10143. "0359 Not a valid slow-path completion "
  10144. "event: majorcode=x%x, minorcode=x%x\n",
  10145. bf_get_le32(lpfc_eqe_major_code, eqe),
  10146. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10147. return;
  10148. }
  10149. /* Get the reference to the corresponding CQ */
  10150. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10151. /* Search for completion queue pointer matching this cqid */
  10152. speq = phba->sli4_hba.sp_eq;
  10153. list_for_each_entry(childq, &speq->child_list, list) {
  10154. if (childq->queue_id == cqid) {
  10155. cq = childq;
  10156. break;
  10157. }
  10158. }
  10159. if (unlikely(!cq)) {
  10160. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10161. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10162. "0365 Slow-path CQ identifier "
  10163. "(%d) does not exist\n", cqid);
  10164. return;
  10165. }
  10166. /* Process all the entries to the CQ */
  10167. switch (cq->type) {
  10168. case LPFC_MCQ:
  10169. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10170. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  10171. if (!(++ecount % cq->entry_repost))
  10172. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10173. }
  10174. break;
  10175. case LPFC_WCQ:
  10176. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10177. if (cq->subtype == LPFC_FCP)
  10178. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  10179. cqe);
  10180. else
  10181. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  10182. cqe);
  10183. if (!(++ecount % cq->entry_repost))
  10184. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10185. }
  10186. break;
  10187. default:
  10188. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10189. "0370 Invalid completion queue type (%d)\n",
  10190. cq->type);
  10191. return;
  10192. }
  10193. /* Catch the no cq entry condition, log an error */
  10194. if (unlikely(ecount == 0))
  10195. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10196. "0371 No entry from the CQ: identifier "
  10197. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  10198. /* In any case, flash and re-arm the RCQ */
  10199. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10200. /* wake up worker thread if there are works to be done */
  10201. if (workposted)
  10202. lpfc_worker_wake_up(phba);
  10203. }
  10204. /**
  10205. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  10206. * @eqe: Pointer to fast-path completion queue entry.
  10207. *
  10208. * This routine process a fast-path work queue completion entry from fast-path
  10209. * event queue for FCP command response completion.
  10210. **/
  10211. static void
  10212. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  10213. struct lpfc_wcqe_complete *wcqe)
  10214. {
  10215. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  10216. struct lpfc_iocbq *cmdiocbq;
  10217. struct lpfc_iocbq irspiocbq;
  10218. unsigned long iflags;
  10219. spin_lock_irqsave(&phba->hbalock, iflags);
  10220. pring->stats.iocb_event++;
  10221. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10222. /* Check for response status */
  10223. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  10224. /* If resource errors reported from HBA, reduce queue
  10225. * depth of the SCSI device.
  10226. */
  10227. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  10228. IOSTAT_LOCAL_REJECT) &&
  10229. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  10230. phba->lpfc_rampdown_queue_depth(phba);
  10231. }
  10232. /* Log the error status */
  10233. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10234. "0373 FCP complete error: status=x%x, "
  10235. "hw_status=x%x, total_data_specified=%d, "
  10236. "parameter=x%x, word3=x%x\n",
  10237. bf_get(lpfc_wcqe_c_status, wcqe),
  10238. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  10239. wcqe->total_data_placed, wcqe->parameter,
  10240. wcqe->word3);
  10241. }
  10242. /* Look up the FCP command IOCB and create pseudo response IOCB */
  10243. spin_lock_irqsave(&phba->hbalock, iflags);
  10244. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10245. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10246. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10247. if (unlikely(!cmdiocbq)) {
  10248. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10249. "0374 FCP complete with no corresponding "
  10250. "cmdiocb: iotag (%d)\n",
  10251. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10252. return;
  10253. }
  10254. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  10255. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10256. "0375 FCP cmdiocb not callback function "
  10257. "iotag: (%d)\n",
  10258. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10259. return;
  10260. }
  10261. /* Fake the irspiocb and copy necessary response information */
  10262. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  10263. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  10264. spin_lock_irqsave(&phba->hbalock, iflags);
  10265. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  10266. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10267. }
  10268. /* Pass the cmd_iocb and the rsp state to the upper layer */
  10269. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  10270. }
  10271. /**
  10272. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  10273. * @phba: Pointer to HBA context object.
  10274. * @cq: Pointer to completion queue.
  10275. * @wcqe: Pointer to work-queue completion queue entry.
  10276. *
  10277. * This routine handles an fast-path WQ entry comsumed event by invoking the
  10278. * proper WQ release routine to the slow-path WQ.
  10279. **/
  10280. static void
  10281. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10282. struct lpfc_wcqe_release *wcqe)
  10283. {
  10284. struct lpfc_queue *childwq;
  10285. bool wqid_matched = false;
  10286. uint16_t fcp_wqid;
  10287. /* Check for fast-path FCP work queue release */
  10288. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  10289. list_for_each_entry(childwq, &cq->child_list, list) {
  10290. if (childwq->queue_id == fcp_wqid) {
  10291. lpfc_sli4_wq_release(childwq,
  10292. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10293. wqid_matched = true;
  10294. break;
  10295. }
  10296. }
  10297. /* Report warning log message if no match found */
  10298. if (wqid_matched != true)
  10299. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10300. "2580 Fast-path wqe consume event carries "
  10301. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  10302. }
  10303. /**
  10304. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  10305. * @cq: Pointer to the completion queue.
  10306. * @eqe: Pointer to fast-path completion queue entry.
  10307. *
  10308. * This routine process a fast-path work queue completion entry from fast-path
  10309. * event queue for FCP command response completion.
  10310. **/
  10311. static int
  10312. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10313. struct lpfc_cqe *cqe)
  10314. {
  10315. struct lpfc_wcqe_release wcqe;
  10316. bool workposted = false;
  10317. /* Copy the work queue CQE and convert endian order if needed */
  10318. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  10319. /* Check and process for different type of WCQE and dispatch */
  10320. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  10321. case CQE_CODE_COMPL_WQE:
  10322. /* Process the WQ complete event */
  10323. phba->last_completion_time = jiffies;
  10324. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  10325. (struct lpfc_wcqe_complete *)&wcqe);
  10326. break;
  10327. case CQE_CODE_RELEASE_WQE:
  10328. /* Process the WQ release event */
  10329. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  10330. (struct lpfc_wcqe_release *)&wcqe);
  10331. break;
  10332. case CQE_CODE_XRI_ABORTED:
  10333. /* Process the WQ XRI abort event */
  10334. phba->last_completion_time = jiffies;
  10335. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10336. (struct sli4_wcqe_xri_aborted *)&wcqe);
  10337. break;
  10338. default:
  10339. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10340. "0144 Not a valid WCQE code: x%x\n",
  10341. bf_get(lpfc_wcqe_c_code, &wcqe));
  10342. break;
  10343. }
  10344. return workposted;
  10345. }
  10346. /**
  10347. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  10348. * @phba: Pointer to HBA context object.
  10349. * @eqe: Pointer to fast-path event queue entry.
  10350. *
  10351. * This routine process a event queue entry from the fast-path event queue.
  10352. * It will check the MajorCode and MinorCode to determine this is for a
  10353. * completion event on a completion queue, if not, an error shall be logged
  10354. * and just return. Otherwise, it will get to the corresponding completion
  10355. * queue and process all the entries on the completion queue, rearm the
  10356. * completion queue, and then return.
  10357. **/
  10358. static void
  10359. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10360. uint32_t fcp_cqidx)
  10361. {
  10362. struct lpfc_queue *cq;
  10363. struct lpfc_cqe *cqe;
  10364. bool workposted = false;
  10365. uint16_t cqid;
  10366. int ecount = 0;
  10367. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  10368. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10369. "0366 Not a valid fast-path completion "
  10370. "event: majorcode=x%x, minorcode=x%x\n",
  10371. bf_get_le32(lpfc_eqe_major_code, eqe),
  10372. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10373. return;
  10374. }
  10375. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  10376. if (unlikely(!cq)) {
  10377. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10378. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10379. "0367 Fast-path completion queue "
  10380. "does not exist\n");
  10381. return;
  10382. }
  10383. /* Get the reference to the corresponding CQ */
  10384. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10385. if (unlikely(cqid != cq->queue_id)) {
  10386. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10387. "0368 Miss-matched fast-path completion "
  10388. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  10389. cqid, cq->queue_id);
  10390. return;
  10391. }
  10392. /* Process all the entries to the CQ */
  10393. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10394. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  10395. if (!(++ecount % cq->entry_repost))
  10396. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10397. }
  10398. /* Catch the no cq entry condition */
  10399. if (unlikely(ecount == 0))
  10400. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10401. "0369 No entry from fast-path completion "
  10402. "queue fcpcqid=%d\n", cq->queue_id);
  10403. /* In any case, flash and re-arm the CQ */
  10404. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10405. /* wake up worker thread if there are works to be done */
  10406. if (workposted)
  10407. lpfc_worker_wake_up(phba);
  10408. }
  10409. static void
  10410. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10411. {
  10412. struct lpfc_eqe *eqe;
  10413. /* walk all the EQ entries and drop on the floor */
  10414. while ((eqe = lpfc_sli4_eq_get(eq)))
  10415. ;
  10416. /* Clear and re-arm the EQ */
  10417. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  10418. }
  10419. /**
  10420. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  10421. * @irq: Interrupt number.
  10422. * @dev_id: The device context pointer.
  10423. *
  10424. * This function is directly called from the PCI layer as an interrupt
  10425. * service routine when device with SLI-4 interface spec is enabled with
  10426. * MSI-X multi-message interrupt mode and there are slow-path events in
  10427. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  10428. * interrupt mode, this function is called as part of the device-level
  10429. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  10430. * undergoing initialization, the interrupt handler will not process the
  10431. * interrupt. The link attention and ELS ring attention events are handled
  10432. * by the worker thread. The interrupt handler signals the worker thread
  10433. * and returns for these events. This function is called without any lock
  10434. * held. It gets the hbalock to access and update SLI data structures.
  10435. *
  10436. * This function returns IRQ_HANDLED when interrupt is handled else it
  10437. * returns IRQ_NONE.
  10438. **/
  10439. irqreturn_t
  10440. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  10441. {
  10442. struct lpfc_hba *phba;
  10443. struct lpfc_queue *speq;
  10444. struct lpfc_eqe *eqe;
  10445. unsigned long iflag;
  10446. int ecount = 0;
  10447. /*
  10448. * Get the driver's phba structure from the dev_id
  10449. */
  10450. phba = (struct lpfc_hba *)dev_id;
  10451. if (unlikely(!phba))
  10452. return IRQ_NONE;
  10453. /* Get to the EQ struct associated with this vector */
  10454. speq = phba->sli4_hba.sp_eq;
  10455. if (unlikely(!speq))
  10456. return IRQ_NONE;
  10457. /* Check device state for handling interrupt */
  10458. if (unlikely(lpfc_intr_state_check(phba))) {
  10459. /* Check again for link_state with lock held */
  10460. spin_lock_irqsave(&phba->hbalock, iflag);
  10461. if (phba->link_state < LPFC_LINK_DOWN)
  10462. /* Flush, clear interrupt, and rearm the EQ */
  10463. lpfc_sli4_eq_flush(phba, speq);
  10464. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10465. return IRQ_NONE;
  10466. }
  10467. /*
  10468. * Process all the event on FCP slow-path EQ
  10469. */
  10470. while ((eqe = lpfc_sli4_eq_get(speq))) {
  10471. lpfc_sli4_sp_handle_eqe(phba, eqe);
  10472. if (!(++ecount % speq->entry_repost))
  10473. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  10474. }
  10475. /* Always clear and re-arm the slow-path EQ */
  10476. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  10477. /* Catch the no cq entry condition */
  10478. if (unlikely(ecount == 0)) {
  10479. if (phba->intr_type == MSIX)
  10480. /* MSI-X treated interrupt served as no EQ share INT */
  10481. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10482. "0357 MSI-X interrupt with no EQE\n");
  10483. else
  10484. /* Non MSI-X treated on interrupt as EQ share INT */
  10485. return IRQ_NONE;
  10486. }
  10487. return IRQ_HANDLED;
  10488. } /* lpfc_sli4_sp_intr_handler */
  10489. /**
  10490. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  10491. * @irq: Interrupt number.
  10492. * @dev_id: The device context pointer.
  10493. *
  10494. * This function is directly called from the PCI layer as an interrupt
  10495. * service routine when device with SLI-4 interface spec is enabled with
  10496. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10497. * ring event in the HBA. However, when the device is enabled with either
  10498. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10499. * device-level interrupt handler. When the PCI slot is in error recovery
  10500. * or the HBA is undergoing initialization, the interrupt handler will not
  10501. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10502. * the intrrupt context. This function is called without any lock held.
  10503. * It gets the hbalock to access and update SLI data structures. Note that,
  10504. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  10505. * equal to that of FCP CQ index.
  10506. *
  10507. * This function returns IRQ_HANDLED when interrupt is handled else it
  10508. * returns IRQ_NONE.
  10509. **/
  10510. irqreturn_t
  10511. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  10512. {
  10513. struct lpfc_hba *phba;
  10514. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  10515. struct lpfc_queue *fpeq;
  10516. struct lpfc_eqe *eqe;
  10517. unsigned long iflag;
  10518. int ecount = 0;
  10519. uint32_t fcp_eqidx;
  10520. /* Get the driver's phba structure from the dev_id */
  10521. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  10522. phba = fcp_eq_hdl->phba;
  10523. fcp_eqidx = fcp_eq_hdl->idx;
  10524. if (unlikely(!phba))
  10525. return IRQ_NONE;
  10526. if (unlikely(!phba->sli4_hba.fp_eq))
  10527. return IRQ_NONE;
  10528. /* Get to the EQ struct associated with this vector */
  10529. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  10530. /* Check device state for handling interrupt */
  10531. if (unlikely(lpfc_intr_state_check(phba))) {
  10532. /* Check again for link_state with lock held */
  10533. spin_lock_irqsave(&phba->hbalock, iflag);
  10534. if (phba->link_state < LPFC_LINK_DOWN)
  10535. /* Flush, clear interrupt, and rearm the EQ */
  10536. lpfc_sli4_eq_flush(phba, fpeq);
  10537. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10538. return IRQ_NONE;
  10539. }
  10540. /*
  10541. * Process all the event on FCP fast-path EQ
  10542. */
  10543. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  10544. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  10545. if (!(++ecount % fpeq->entry_repost))
  10546. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  10547. }
  10548. /* Always clear and re-arm the fast-path EQ */
  10549. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  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. "0358 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_fp_intr_handler */
  10561. /**
  10562. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  10563. * @irq: Interrupt number.
  10564. * @dev_id: The device context pointer.
  10565. *
  10566. * This function is the device-level interrupt handler to device with SLI-4
  10567. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  10568. * interrupt mode is enabled and there is an event in the HBA which requires
  10569. * driver attention. This function invokes the slow-path interrupt attention
  10570. * handling function and fast-path interrupt attention handling function in
  10571. * turn to process the relevant HBA attention events. This function is called
  10572. * without any lock held. It gets the hbalock to access and update SLI data
  10573. * structures.
  10574. *
  10575. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10576. * returns IRQ_NONE.
  10577. **/
  10578. irqreturn_t
  10579. lpfc_sli4_intr_handler(int irq, void *dev_id)
  10580. {
  10581. struct lpfc_hba *phba;
  10582. irqreturn_t sp_irq_rc, fp_irq_rc;
  10583. bool fp_handled = false;
  10584. uint32_t fcp_eqidx;
  10585. /* Get the driver's phba structure from the dev_id */
  10586. phba = (struct lpfc_hba *)dev_id;
  10587. if (unlikely(!phba))
  10588. return IRQ_NONE;
  10589. /*
  10590. * Invokes slow-path host attention interrupt handling as appropriate.
  10591. */
  10592. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  10593. /*
  10594. * Invoke fast-path host attention interrupt handling as appropriate.
  10595. */
  10596. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  10597. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  10598. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  10599. if (fp_irq_rc == IRQ_HANDLED)
  10600. fp_handled |= true;
  10601. }
  10602. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  10603. } /* lpfc_sli4_intr_handler */
  10604. /**
  10605. * lpfc_sli4_queue_free - free a queue structure and associated memory
  10606. * @queue: The queue structure to free.
  10607. *
  10608. * This function frees a queue structure and the DMAable memory used for
  10609. * the host resident queue. This function must be called after destroying the
  10610. * queue on the HBA.
  10611. **/
  10612. void
  10613. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  10614. {
  10615. struct lpfc_dmabuf *dmabuf;
  10616. if (!queue)
  10617. return;
  10618. while (!list_empty(&queue->page_list)) {
  10619. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  10620. list);
  10621. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  10622. dmabuf->virt, dmabuf->phys);
  10623. kfree(dmabuf);
  10624. }
  10625. kfree(queue);
  10626. return;
  10627. }
  10628. /**
  10629. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  10630. * @phba: The HBA that this queue is being created on.
  10631. * @entry_size: The size of each queue entry for this queue.
  10632. * @entry count: The number of entries that this queue will handle.
  10633. *
  10634. * This function allocates a queue structure and the DMAable memory used for
  10635. * the host resident queue. This function must be called before creating the
  10636. * queue on the HBA.
  10637. **/
  10638. struct lpfc_queue *
  10639. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  10640. uint32_t entry_count)
  10641. {
  10642. struct lpfc_queue *queue;
  10643. struct lpfc_dmabuf *dmabuf;
  10644. int x, total_qe_count;
  10645. void *dma_pointer;
  10646. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10647. if (!phba->sli4_hba.pc_sli4_params.supported)
  10648. hw_page_size = SLI4_PAGE_SIZE;
  10649. queue = kzalloc(sizeof(struct lpfc_queue) +
  10650. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  10651. if (!queue)
  10652. return NULL;
  10653. queue->page_count = (ALIGN(entry_size * entry_count,
  10654. hw_page_size))/hw_page_size;
  10655. INIT_LIST_HEAD(&queue->list);
  10656. INIT_LIST_HEAD(&queue->page_list);
  10657. INIT_LIST_HEAD(&queue->child_list);
  10658. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  10659. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  10660. if (!dmabuf)
  10661. goto out_fail;
  10662. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  10663. hw_page_size, &dmabuf->phys,
  10664. GFP_KERNEL);
  10665. if (!dmabuf->virt) {
  10666. kfree(dmabuf);
  10667. goto out_fail;
  10668. }
  10669. memset(dmabuf->virt, 0, hw_page_size);
  10670. dmabuf->buffer_tag = x;
  10671. list_add_tail(&dmabuf->list, &queue->page_list);
  10672. /* initialize queue's entry array */
  10673. dma_pointer = dmabuf->virt;
  10674. for (; total_qe_count < entry_count &&
  10675. dma_pointer < (hw_page_size + dmabuf->virt);
  10676. total_qe_count++, dma_pointer += entry_size) {
  10677. queue->qe[total_qe_count].address = dma_pointer;
  10678. }
  10679. }
  10680. queue->entry_size = entry_size;
  10681. queue->entry_count = entry_count;
  10682. /*
  10683. * entry_repost is calculated based on the number of entries in the
  10684. * queue. This works out except for RQs. If buffers are NOT initially
  10685. * posted for every RQE, entry_repost should be adjusted accordingly.
  10686. */
  10687. queue->entry_repost = (entry_count >> 3);
  10688. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  10689. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  10690. queue->phba = phba;
  10691. return queue;
  10692. out_fail:
  10693. lpfc_sli4_queue_free(queue);
  10694. return NULL;
  10695. }
  10696. /**
  10697. * lpfc_eq_create - Create an Event Queue on the HBA
  10698. * @phba: HBA structure that indicates port to create a queue on.
  10699. * @eq: The queue structure to use to create the event queue.
  10700. * @imax: The maximum interrupt per second limit.
  10701. *
  10702. * This function creates an event queue, as detailed in @eq, on a port,
  10703. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  10704. *
  10705. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  10706. * is used to get the entry count and entry size that are necessary to
  10707. * determine the number of pages to allocate and use for this queue. This
  10708. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  10709. * event queue. This function is asynchronous and will wait for the mailbox
  10710. * command to finish before continuing.
  10711. *
  10712. * On success this function will return a zero. If unable to allocate enough
  10713. * memory this function will return -ENOMEM. If the queue create mailbox command
  10714. * fails this function will return -ENXIO.
  10715. **/
  10716. uint32_t
  10717. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  10718. {
  10719. struct lpfc_mbx_eq_create *eq_create;
  10720. LPFC_MBOXQ_t *mbox;
  10721. int rc, length, status = 0;
  10722. struct lpfc_dmabuf *dmabuf;
  10723. uint32_t shdr_status, shdr_add_status;
  10724. union lpfc_sli4_cfg_shdr *shdr;
  10725. uint16_t dmult;
  10726. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10727. if (!phba->sli4_hba.pc_sli4_params.supported)
  10728. hw_page_size = SLI4_PAGE_SIZE;
  10729. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10730. if (!mbox)
  10731. return -ENOMEM;
  10732. length = (sizeof(struct lpfc_mbx_eq_create) -
  10733. sizeof(struct lpfc_sli4_cfg_mhdr));
  10734. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10735. LPFC_MBOX_OPCODE_EQ_CREATE,
  10736. length, LPFC_SLI4_MBX_EMBED);
  10737. eq_create = &mbox->u.mqe.un.eq_create;
  10738. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  10739. eq->page_count);
  10740. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  10741. LPFC_EQE_SIZE);
  10742. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  10743. /* Calculate delay multiper from maximum interrupt per second */
  10744. dmult = LPFC_DMULT_CONST/imax - 1;
  10745. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  10746. dmult);
  10747. switch (eq->entry_count) {
  10748. default:
  10749. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10750. "0360 Unsupported EQ count. (%d)\n",
  10751. eq->entry_count);
  10752. if (eq->entry_count < 256)
  10753. return -EINVAL;
  10754. /* otherwise default to smallest count (drop through) */
  10755. case 256:
  10756. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  10757. LPFC_EQ_CNT_256);
  10758. break;
  10759. case 512:
  10760. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  10761. LPFC_EQ_CNT_512);
  10762. break;
  10763. case 1024:
  10764. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  10765. LPFC_EQ_CNT_1024);
  10766. break;
  10767. case 2048:
  10768. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  10769. LPFC_EQ_CNT_2048);
  10770. break;
  10771. case 4096:
  10772. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  10773. LPFC_EQ_CNT_4096);
  10774. break;
  10775. }
  10776. list_for_each_entry(dmabuf, &eq->page_list, list) {
  10777. memset(dmabuf->virt, 0, hw_page_size);
  10778. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  10779. putPaddrLow(dmabuf->phys);
  10780. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  10781. putPaddrHigh(dmabuf->phys);
  10782. }
  10783. mbox->vport = phba->pport;
  10784. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10785. mbox->context1 = NULL;
  10786. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10787. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  10788. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10789. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10790. if (shdr_status || shdr_add_status || rc) {
  10791. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10792. "2500 EQ_CREATE mailbox failed with "
  10793. "status x%x add_status x%x, mbx status x%x\n",
  10794. shdr_status, shdr_add_status, rc);
  10795. status = -ENXIO;
  10796. }
  10797. eq->type = LPFC_EQ;
  10798. eq->subtype = LPFC_NONE;
  10799. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  10800. if (eq->queue_id == 0xFFFF)
  10801. status = -ENXIO;
  10802. eq->host_index = 0;
  10803. eq->hba_index = 0;
  10804. mempool_free(mbox, phba->mbox_mem_pool);
  10805. return status;
  10806. }
  10807. /**
  10808. * lpfc_cq_create - Create a Completion Queue on the HBA
  10809. * @phba: HBA structure that indicates port to create a queue on.
  10810. * @cq: The queue structure to use to create the completion queue.
  10811. * @eq: The event queue to bind this completion queue to.
  10812. *
  10813. * This function creates a completion queue, as detailed in @wq, on a port,
  10814. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  10815. *
  10816. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  10817. * is used to get the entry count and entry size that are necessary to
  10818. * determine the number of pages to allocate and use for this queue. The @eq
  10819. * is used to indicate which event queue to bind this completion queue to. This
  10820. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  10821. * completion queue. This function is asynchronous and will wait for the mailbox
  10822. * command to finish before continuing.
  10823. *
  10824. * On success this function will return a zero. If unable to allocate enough
  10825. * memory this function will return -ENOMEM. If the queue create mailbox command
  10826. * fails this function will return -ENXIO.
  10827. **/
  10828. uint32_t
  10829. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10830. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  10831. {
  10832. struct lpfc_mbx_cq_create *cq_create;
  10833. struct lpfc_dmabuf *dmabuf;
  10834. LPFC_MBOXQ_t *mbox;
  10835. int rc, length, status = 0;
  10836. uint32_t shdr_status, shdr_add_status;
  10837. union lpfc_sli4_cfg_shdr *shdr;
  10838. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10839. if (!phba->sli4_hba.pc_sli4_params.supported)
  10840. hw_page_size = SLI4_PAGE_SIZE;
  10841. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10842. if (!mbox)
  10843. return -ENOMEM;
  10844. length = (sizeof(struct lpfc_mbx_cq_create) -
  10845. sizeof(struct lpfc_sli4_cfg_mhdr));
  10846. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10847. LPFC_MBOX_OPCODE_CQ_CREATE,
  10848. length, LPFC_SLI4_MBX_EMBED);
  10849. cq_create = &mbox->u.mqe.un.cq_create;
  10850. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  10851. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  10852. cq->page_count);
  10853. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  10854. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  10855. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  10856. phba->sli4_hba.pc_sli4_params.cqv);
  10857. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  10858. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  10859. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  10860. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  10861. eq->queue_id);
  10862. } else {
  10863. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  10864. eq->queue_id);
  10865. }
  10866. switch (cq->entry_count) {
  10867. default:
  10868. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10869. "0361 Unsupported CQ count. (%d)\n",
  10870. cq->entry_count);
  10871. if (cq->entry_count < 256)
  10872. return -EINVAL;
  10873. /* otherwise default to smallest count (drop through) */
  10874. case 256:
  10875. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  10876. LPFC_CQ_CNT_256);
  10877. break;
  10878. case 512:
  10879. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  10880. LPFC_CQ_CNT_512);
  10881. break;
  10882. case 1024:
  10883. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  10884. LPFC_CQ_CNT_1024);
  10885. break;
  10886. }
  10887. list_for_each_entry(dmabuf, &cq->page_list, list) {
  10888. memset(dmabuf->virt, 0, hw_page_size);
  10889. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  10890. putPaddrLow(dmabuf->phys);
  10891. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  10892. putPaddrHigh(dmabuf->phys);
  10893. }
  10894. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10895. /* The IOCTL status is embedded in the mailbox subheader. */
  10896. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10897. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10898. if (shdr_status || shdr_add_status || rc) {
  10899. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10900. "2501 CQ_CREATE mailbox failed with "
  10901. "status x%x add_status x%x, mbx status x%x\n",
  10902. shdr_status, shdr_add_status, rc);
  10903. status = -ENXIO;
  10904. goto out;
  10905. }
  10906. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  10907. if (cq->queue_id == 0xFFFF) {
  10908. status = -ENXIO;
  10909. goto out;
  10910. }
  10911. /* link the cq onto the parent eq child list */
  10912. list_add_tail(&cq->list, &eq->child_list);
  10913. /* Set up completion queue's type and subtype */
  10914. cq->type = type;
  10915. cq->subtype = subtype;
  10916. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  10917. cq->assoc_qid = eq->queue_id;
  10918. cq->host_index = 0;
  10919. cq->hba_index = 0;
  10920. out:
  10921. mempool_free(mbox, phba->mbox_mem_pool);
  10922. return status;
  10923. }
  10924. /**
  10925. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  10926. * @phba: HBA structure that indicates port to create a queue on.
  10927. * @mq: The queue structure to use to create the mailbox queue.
  10928. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  10929. * @cq: The completion queue to associate with this cq.
  10930. *
  10931. * This function provides failback (fb) functionality when the
  10932. * mq_create_ext fails on older FW generations. It's purpose is identical
  10933. * to mq_create_ext otherwise.
  10934. *
  10935. * This routine cannot fail as all attributes were previously accessed and
  10936. * initialized in mq_create_ext.
  10937. **/
  10938. static void
  10939. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  10940. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  10941. {
  10942. struct lpfc_mbx_mq_create *mq_create;
  10943. struct lpfc_dmabuf *dmabuf;
  10944. int length;
  10945. length = (sizeof(struct lpfc_mbx_mq_create) -
  10946. sizeof(struct lpfc_sli4_cfg_mhdr));
  10947. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10948. LPFC_MBOX_OPCODE_MQ_CREATE,
  10949. length, LPFC_SLI4_MBX_EMBED);
  10950. mq_create = &mbox->u.mqe.un.mq_create;
  10951. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  10952. mq->page_count);
  10953. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  10954. cq->queue_id);
  10955. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  10956. switch (mq->entry_count) {
  10957. case 16:
  10958. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  10959. LPFC_MQ_RING_SIZE_16);
  10960. break;
  10961. case 32:
  10962. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  10963. LPFC_MQ_RING_SIZE_32);
  10964. break;
  10965. case 64:
  10966. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  10967. LPFC_MQ_RING_SIZE_64);
  10968. break;
  10969. case 128:
  10970. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  10971. LPFC_MQ_RING_SIZE_128);
  10972. break;
  10973. }
  10974. list_for_each_entry(dmabuf, &mq->page_list, list) {
  10975. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  10976. putPaddrLow(dmabuf->phys);
  10977. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  10978. putPaddrHigh(dmabuf->phys);
  10979. }
  10980. }
  10981. /**
  10982. * lpfc_mq_create - Create a mailbox Queue on the HBA
  10983. * @phba: HBA structure that indicates port to create a queue on.
  10984. * @mq: The queue structure to use to create the mailbox queue.
  10985. * @cq: The completion queue to associate with this cq.
  10986. * @subtype: The queue's subtype.
  10987. *
  10988. * This function creates a mailbox queue, as detailed in @mq, on a port,
  10989. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  10990. *
  10991. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  10992. * is used to get the entry count and entry size that are necessary to
  10993. * determine the number of pages to allocate and use for this queue. This
  10994. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  10995. * mailbox queue. This function is asynchronous and will wait for the mailbox
  10996. * command to finish before continuing.
  10997. *
  10998. * On success this function will return a zero. If unable to allocate enough
  10999. * memory this function will return -ENOMEM. If the queue create mailbox command
  11000. * fails this function will return -ENXIO.
  11001. **/
  11002. int32_t
  11003. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11004. struct lpfc_queue *cq, uint32_t subtype)
  11005. {
  11006. struct lpfc_mbx_mq_create *mq_create;
  11007. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  11008. struct lpfc_dmabuf *dmabuf;
  11009. LPFC_MBOXQ_t *mbox;
  11010. int rc, length, status = 0;
  11011. uint32_t shdr_status, shdr_add_status;
  11012. union lpfc_sli4_cfg_shdr *shdr;
  11013. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11014. if (!phba->sli4_hba.pc_sli4_params.supported)
  11015. hw_page_size = SLI4_PAGE_SIZE;
  11016. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11017. if (!mbox)
  11018. return -ENOMEM;
  11019. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  11020. sizeof(struct lpfc_sli4_cfg_mhdr));
  11021. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11022. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  11023. length, LPFC_SLI4_MBX_EMBED);
  11024. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  11025. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  11026. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  11027. &mq_create_ext->u.request, mq->page_count);
  11028. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  11029. &mq_create_ext->u.request, 1);
  11030. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  11031. &mq_create_ext->u.request, 1);
  11032. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  11033. &mq_create_ext->u.request, 1);
  11034. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  11035. &mq_create_ext->u.request, 1);
  11036. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  11037. &mq_create_ext->u.request, 1);
  11038. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  11039. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11040. phba->sli4_hba.pc_sli4_params.mqv);
  11041. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  11042. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  11043. cq->queue_id);
  11044. else
  11045. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  11046. cq->queue_id);
  11047. switch (mq->entry_count) {
  11048. default:
  11049. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11050. "0362 Unsupported MQ count. (%d)\n",
  11051. mq->entry_count);
  11052. if (mq->entry_count < 16)
  11053. return -EINVAL;
  11054. /* otherwise default to smallest count (drop through) */
  11055. case 16:
  11056. bf_set(lpfc_mq_context_ring_size,
  11057. &mq_create_ext->u.request.context,
  11058. LPFC_MQ_RING_SIZE_16);
  11059. break;
  11060. case 32:
  11061. bf_set(lpfc_mq_context_ring_size,
  11062. &mq_create_ext->u.request.context,
  11063. LPFC_MQ_RING_SIZE_32);
  11064. break;
  11065. case 64:
  11066. bf_set(lpfc_mq_context_ring_size,
  11067. &mq_create_ext->u.request.context,
  11068. LPFC_MQ_RING_SIZE_64);
  11069. break;
  11070. case 128:
  11071. bf_set(lpfc_mq_context_ring_size,
  11072. &mq_create_ext->u.request.context,
  11073. LPFC_MQ_RING_SIZE_128);
  11074. break;
  11075. }
  11076. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11077. memset(dmabuf->virt, 0, hw_page_size);
  11078. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  11079. putPaddrLow(dmabuf->phys);
  11080. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  11081. putPaddrHigh(dmabuf->phys);
  11082. }
  11083. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11084. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11085. &mq_create_ext->u.response);
  11086. if (rc != MBX_SUCCESS) {
  11087. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11088. "2795 MQ_CREATE_EXT failed with "
  11089. "status x%x. Failback to MQ_CREATE.\n",
  11090. rc);
  11091. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  11092. mq_create = &mbox->u.mqe.un.mq_create;
  11093. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11094. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  11095. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11096. &mq_create->u.response);
  11097. }
  11098. /* The IOCTL status is embedded in the mailbox subheader. */
  11099. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11100. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11101. if (shdr_status || shdr_add_status || rc) {
  11102. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11103. "2502 MQ_CREATE mailbox failed with "
  11104. "status x%x add_status x%x, mbx status x%x\n",
  11105. shdr_status, shdr_add_status, rc);
  11106. status = -ENXIO;
  11107. goto out;
  11108. }
  11109. if (mq->queue_id == 0xFFFF) {
  11110. status = -ENXIO;
  11111. goto out;
  11112. }
  11113. mq->type = LPFC_MQ;
  11114. mq->assoc_qid = cq->queue_id;
  11115. mq->subtype = subtype;
  11116. mq->host_index = 0;
  11117. mq->hba_index = 0;
  11118. /* link the mq onto the parent cq child list */
  11119. list_add_tail(&mq->list, &cq->child_list);
  11120. out:
  11121. mempool_free(mbox, phba->mbox_mem_pool);
  11122. return status;
  11123. }
  11124. /**
  11125. * lpfc_wq_create - Create a Work Queue on the HBA
  11126. * @phba: HBA structure that indicates port to create a queue on.
  11127. * @wq: The queue structure to use to create the work queue.
  11128. * @cq: The completion queue to bind this work queue to.
  11129. * @subtype: The subtype of the work queue indicating its functionality.
  11130. *
  11131. * This function creates a work queue, as detailed in @wq, on a port, described
  11132. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  11133. *
  11134. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  11135. * is used to get the entry count and entry size that are necessary to
  11136. * determine the number of pages to allocate and use for this queue. The @cq
  11137. * is used to indicate which completion queue to bind this work queue to. This
  11138. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  11139. * work queue. This function is asynchronous and will wait for the mailbox
  11140. * command to finish before continuing.
  11141. *
  11142. * On success this function will return a zero. If unable to allocate enough
  11143. * memory this function will return -ENOMEM. If the queue create mailbox command
  11144. * fails this function will return -ENXIO.
  11145. **/
  11146. uint32_t
  11147. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  11148. struct lpfc_queue *cq, uint32_t subtype)
  11149. {
  11150. struct lpfc_mbx_wq_create *wq_create;
  11151. struct lpfc_dmabuf *dmabuf;
  11152. LPFC_MBOXQ_t *mbox;
  11153. int rc, length, status = 0;
  11154. uint32_t shdr_status, shdr_add_status;
  11155. union lpfc_sli4_cfg_shdr *shdr;
  11156. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11157. struct dma_address *page;
  11158. if (!phba->sli4_hba.pc_sli4_params.supported)
  11159. hw_page_size = SLI4_PAGE_SIZE;
  11160. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11161. if (!mbox)
  11162. return -ENOMEM;
  11163. length = (sizeof(struct lpfc_mbx_wq_create) -
  11164. sizeof(struct lpfc_sli4_cfg_mhdr));
  11165. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11166. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  11167. length, LPFC_SLI4_MBX_EMBED);
  11168. wq_create = &mbox->u.mqe.un.wq_create;
  11169. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  11170. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  11171. wq->page_count);
  11172. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  11173. cq->queue_id);
  11174. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11175. phba->sli4_hba.pc_sli4_params.wqv);
  11176. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  11177. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  11178. wq->entry_count);
  11179. switch (wq->entry_size) {
  11180. default:
  11181. case 64:
  11182. bf_set(lpfc_mbx_wq_create_wqe_size,
  11183. &wq_create->u.request_1,
  11184. LPFC_WQ_WQE_SIZE_64);
  11185. break;
  11186. case 128:
  11187. bf_set(lpfc_mbx_wq_create_wqe_size,
  11188. &wq_create->u.request_1,
  11189. LPFC_WQ_WQE_SIZE_128);
  11190. break;
  11191. }
  11192. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  11193. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11194. page = wq_create->u.request_1.page;
  11195. } else {
  11196. page = wq_create->u.request.page;
  11197. }
  11198. list_for_each_entry(dmabuf, &wq->page_list, list) {
  11199. memset(dmabuf->virt, 0, hw_page_size);
  11200. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  11201. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  11202. }
  11203. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11204. /* The IOCTL status is embedded in the mailbox subheader. */
  11205. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11206. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11207. if (shdr_status || shdr_add_status || rc) {
  11208. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11209. "2503 WQ_CREATE mailbox failed with "
  11210. "status x%x add_status x%x, mbx status x%x\n",
  11211. shdr_status, shdr_add_status, rc);
  11212. status = -ENXIO;
  11213. goto out;
  11214. }
  11215. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  11216. if (wq->queue_id == 0xFFFF) {
  11217. status = -ENXIO;
  11218. goto out;
  11219. }
  11220. wq->type = LPFC_WQ;
  11221. wq->assoc_qid = cq->queue_id;
  11222. wq->subtype = subtype;
  11223. wq->host_index = 0;
  11224. wq->hba_index = 0;
  11225. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  11226. /* link the wq onto the parent cq child list */
  11227. list_add_tail(&wq->list, &cq->child_list);
  11228. out:
  11229. mempool_free(mbox, phba->mbox_mem_pool);
  11230. return status;
  11231. }
  11232. /**
  11233. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  11234. * @phba: HBA structure that indicates port to create a queue on.
  11235. * @rq: The queue structure to use for the receive queue.
  11236. * @qno: The associated HBQ number
  11237. *
  11238. *
  11239. * For SLI4 we need to adjust the RQ repost value based on
  11240. * the number of buffers that are initially posted to the RQ.
  11241. */
  11242. void
  11243. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  11244. {
  11245. uint32_t cnt;
  11246. cnt = lpfc_hbq_defs[qno]->entry_count;
  11247. /* Recalc repost for RQs based on buffers initially posted */
  11248. cnt = (cnt >> 3);
  11249. if (cnt < LPFC_QUEUE_MIN_REPOST)
  11250. cnt = LPFC_QUEUE_MIN_REPOST;
  11251. rq->entry_repost = cnt;
  11252. }
  11253. /**
  11254. * lpfc_rq_create - Create a Receive Queue on the HBA
  11255. * @phba: HBA structure that indicates port to create a queue on.
  11256. * @hrq: The queue structure to use to create the header receive queue.
  11257. * @drq: The queue structure to use to create the data receive queue.
  11258. * @cq: The completion queue to bind this work queue to.
  11259. *
  11260. * This function creates a receive buffer queue pair , as detailed in @hrq and
  11261. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  11262. * to the HBA.
  11263. *
  11264. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  11265. * struct is used to get the entry count that is necessary to determine the
  11266. * number of pages to use for this queue. The @cq is used to indicate which
  11267. * completion queue to bind received buffers that are posted to these queues to.
  11268. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  11269. * receive queue pair. This function is asynchronous and will wait for the
  11270. * mailbox command to finish before continuing.
  11271. *
  11272. * On success this function will return a zero. If unable to allocate enough
  11273. * memory this function will return -ENOMEM. If the queue create mailbox command
  11274. * fails this function will return -ENXIO.
  11275. **/
  11276. uint32_t
  11277. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11278. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  11279. {
  11280. struct lpfc_mbx_rq_create *rq_create;
  11281. struct lpfc_dmabuf *dmabuf;
  11282. LPFC_MBOXQ_t *mbox;
  11283. int rc, length, status = 0;
  11284. uint32_t shdr_status, shdr_add_status;
  11285. union lpfc_sli4_cfg_shdr *shdr;
  11286. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11287. if (!phba->sli4_hba.pc_sli4_params.supported)
  11288. hw_page_size = SLI4_PAGE_SIZE;
  11289. if (hrq->entry_count != drq->entry_count)
  11290. return -EINVAL;
  11291. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11292. if (!mbox)
  11293. return -ENOMEM;
  11294. length = (sizeof(struct lpfc_mbx_rq_create) -
  11295. sizeof(struct lpfc_sli4_cfg_mhdr));
  11296. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11297. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11298. length, LPFC_SLI4_MBX_EMBED);
  11299. rq_create = &mbox->u.mqe.un.rq_create;
  11300. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11301. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11302. phba->sli4_hba.pc_sli4_params.rqv);
  11303. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11304. bf_set(lpfc_rq_context_rqe_count_1,
  11305. &rq_create->u.request.context,
  11306. hrq->entry_count);
  11307. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  11308. bf_set(lpfc_rq_context_rqe_size,
  11309. &rq_create->u.request.context,
  11310. LPFC_RQE_SIZE_8);
  11311. bf_set(lpfc_rq_context_page_size,
  11312. &rq_create->u.request.context,
  11313. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11314. } else {
  11315. switch (hrq->entry_count) {
  11316. default:
  11317. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11318. "2535 Unsupported RQ count. (%d)\n",
  11319. hrq->entry_count);
  11320. if (hrq->entry_count < 512)
  11321. return -EINVAL;
  11322. /* otherwise default to smallest count (drop through) */
  11323. case 512:
  11324. bf_set(lpfc_rq_context_rqe_count,
  11325. &rq_create->u.request.context,
  11326. LPFC_RQ_RING_SIZE_512);
  11327. break;
  11328. case 1024:
  11329. bf_set(lpfc_rq_context_rqe_count,
  11330. &rq_create->u.request.context,
  11331. LPFC_RQ_RING_SIZE_1024);
  11332. break;
  11333. case 2048:
  11334. bf_set(lpfc_rq_context_rqe_count,
  11335. &rq_create->u.request.context,
  11336. LPFC_RQ_RING_SIZE_2048);
  11337. break;
  11338. case 4096:
  11339. bf_set(lpfc_rq_context_rqe_count,
  11340. &rq_create->u.request.context,
  11341. LPFC_RQ_RING_SIZE_4096);
  11342. break;
  11343. }
  11344. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11345. LPFC_HDR_BUF_SIZE);
  11346. }
  11347. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11348. cq->queue_id);
  11349. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11350. hrq->page_count);
  11351. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  11352. memset(dmabuf->virt, 0, hw_page_size);
  11353. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11354. putPaddrLow(dmabuf->phys);
  11355. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11356. putPaddrHigh(dmabuf->phys);
  11357. }
  11358. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11359. /* The IOCTL status is embedded in the mailbox subheader. */
  11360. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11361. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11362. if (shdr_status || shdr_add_status || rc) {
  11363. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11364. "2504 RQ_CREATE mailbox failed with "
  11365. "status x%x add_status x%x, mbx status x%x\n",
  11366. shdr_status, shdr_add_status, rc);
  11367. status = -ENXIO;
  11368. goto out;
  11369. }
  11370. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11371. if (hrq->queue_id == 0xFFFF) {
  11372. status = -ENXIO;
  11373. goto out;
  11374. }
  11375. hrq->type = LPFC_HRQ;
  11376. hrq->assoc_qid = cq->queue_id;
  11377. hrq->subtype = subtype;
  11378. hrq->host_index = 0;
  11379. hrq->hba_index = 0;
  11380. /* now create the data queue */
  11381. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11382. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11383. length, LPFC_SLI4_MBX_EMBED);
  11384. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11385. phba->sli4_hba.pc_sli4_params.rqv);
  11386. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11387. bf_set(lpfc_rq_context_rqe_count_1,
  11388. &rq_create->u.request.context, hrq->entry_count);
  11389. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  11390. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  11391. LPFC_RQE_SIZE_8);
  11392. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  11393. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11394. } else {
  11395. switch (drq->entry_count) {
  11396. default:
  11397. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11398. "2536 Unsupported RQ count. (%d)\n",
  11399. drq->entry_count);
  11400. if (drq->entry_count < 512)
  11401. return -EINVAL;
  11402. /* otherwise default to smallest count (drop through) */
  11403. case 512:
  11404. bf_set(lpfc_rq_context_rqe_count,
  11405. &rq_create->u.request.context,
  11406. LPFC_RQ_RING_SIZE_512);
  11407. break;
  11408. case 1024:
  11409. bf_set(lpfc_rq_context_rqe_count,
  11410. &rq_create->u.request.context,
  11411. LPFC_RQ_RING_SIZE_1024);
  11412. break;
  11413. case 2048:
  11414. bf_set(lpfc_rq_context_rqe_count,
  11415. &rq_create->u.request.context,
  11416. LPFC_RQ_RING_SIZE_2048);
  11417. break;
  11418. case 4096:
  11419. bf_set(lpfc_rq_context_rqe_count,
  11420. &rq_create->u.request.context,
  11421. LPFC_RQ_RING_SIZE_4096);
  11422. break;
  11423. }
  11424. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11425. LPFC_DATA_BUF_SIZE);
  11426. }
  11427. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11428. cq->queue_id);
  11429. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11430. drq->page_count);
  11431. list_for_each_entry(dmabuf, &drq->page_list, list) {
  11432. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11433. putPaddrLow(dmabuf->phys);
  11434. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11435. putPaddrHigh(dmabuf->phys);
  11436. }
  11437. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11438. /* The IOCTL status is embedded in the mailbox subheader. */
  11439. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11440. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11441. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11442. if (shdr_status || shdr_add_status || rc) {
  11443. status = -ENXIO;
  11444. goto out;
  11445. }
  11446. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11447. if (drq->queue_id == 0xFFFF) {
  11448. status = -ENXIO;
  11449. goto out;
  11450. }
  11451. drq->type = LPFC_DRQ;
  11452. drq->assoc_qid = cq->queue_id;
  11453. drq->subtype = subtype;
  11454. drq->host_index = 0;
  11455. drq->hba_index = 0;
  11456. /* link the header and data RQs onto the parent cq child list */
  11457. list_add_tail(&hrq->list, &cq->child_list);
  11458. list_add_tail(&drq->list, &cq->child_list);
  11459. out:
  11460. mempool_free(mbox, phba->mbox_mem_pool);
  11461. return status;
  11462. }
  11463. /**
  11464. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  11465. * @eq: The queue structure associated with the queue to destroy.
  11466. *
  11467. * This function destroys a queue, as detailed in @eq by sending an mailbox
  11468. * command, specific to the type of queue, to the HBA.
  11469. *
  11470. * The @eq struct is used to get the queue ID of the queue to destroy.
  11471. *
  11472. * On success this function will return a zero. If the queue destroy mailbox
  11473. * command fails this function will return -ENXIO.
  11474. **/
  11475. uint32_t
  11476. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  11477. {
  11478. LPFC_MBOXQ_t *mbox;
  11479. int rc, length, status = 0;
  11480. uint32_t shdr_status, shdr_add_status;
  11481. union lpfc_sli4_cfg_shdr *shdr;
  11482. if (!eq)
  11483. return -ENODEV;
  11484. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  11485. if (!mbox)
  11486. return -ENOMEM;
  11487. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  11488. sizeof(struct lpfc_sli4_cfg_mhdr));
  11489. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11490. LPFC_MBOX_OPCODE_EQ_DESTROY,
  11491. length, LPFC_SLI4_MBX_EMBED);
  11492. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  11493. eq->queue_id);
  11494. mbox->vport = eq->phba->pport;
  11495. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11496. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  11497. /* The IOCTL status is embedded in the mailbox subheader. */
  11498. shdr = (union lpfc_sli4_cfg_shdr *)
  11499. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  11500. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11501. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11502. if (shdr_status || shdr_add_status || rc) {
  11503. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11504. "2505 EQ_DESTROY mailbox failed with "
  11505. "status x%x add_status x%x, mbx status x%x\n",
  11506. shdr_status, shdr_add_status, rc);
  11507. status = -ENXIO;
  11508. }
  11509. /* Remove eq from any list */
  11510. list_del_init(&eq->list);
  11511. mempool_free(mbox, eq->phba->mbox_mem_pool);
  11512. return status;
  11513. }
  11514. /**
  11515. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  11516. * @cq: The queue structure associated with the queue to destroy.
  11517. *
  11518. * This function destroys a queue, as detailed in @cq by sending an mailbox
  11519. * command, specific to the type of queue, to the HBA.
  11520. *
  11521. * The @cq struct is used to get the queue ID of the queue to destroy.
  11522. *
  11523. * On success this function will return a zero. If the queue destroy mailbox
  11524. * command fails this function will return -ENXIO.
  11525. **/
  11526. uint32_t
  11527. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  11528. {
  11529. LPFC_MBOXQ_t *mbox;
  11530. int rc, length, status = 0;
  11531. uint32_t shdr_status, shdr_add_status;
  11532. union lpfc_sli4_cfg_shdr *shdr;
  11533. if (!cq)
  11534. return -ENODEV;
  11535. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  11536. if (!mbox)
  11537. return -ENOMEM;
  11538. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  11539. sizeof(struct lpfc_sli4_cfg_mhdr));
  11540. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11541. LPFC_MBOX_OPCODE_CQ_DESTROY,
  11542. length, LPFC_SLI4_MBX_EMBED);
  11543. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  11544. cq->queue_id);
  11545. mbox->vport = cq->phba->pport;
  11546. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11547. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  11548. /* The IOCTL status is embedded in the mailbox subheader. */
  11549. shdr = (union lpfc_sli4_cfg_shdr *)
  11550. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  11551. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11552. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11553. if (shdr_status || shdr_add_status || rc) {
  11554. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11555. "2506 CQ_DESTROY mailbox failed with "
  11556. "status x%x add_status x%x, mbx status x%x\n",
  11557. shdr_status, shdr_add_status, rc);
  11558. status = -ENXIO;
  11559. }
  11560. /* Remove cq from any list */
  11561. list_del_init(&cq->list);
  11562. mempool_free(mbox, cq->phba->mbox_mem_pool);
  11563. return status;
  11564. }
  11565. /**
  11566. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  11567. * @qm: The queue structure associated with the queue to destroy.
  11568. *
  11569. * This function destroys a queue, as detailed in @mq by sending an mailbox
  11570. * command, specific to the type of queue, to the HBA.
  11571. *
  11572. * The @mq struct is used to get the queue ID of the queue to destroy.
  11573. *
  11574. * On success this function will return a zero. If the queue destroy mailbox
  11575. * command fails this function will return -ENXIO.
  11576. **/
  11577. uint32_t
  11578. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  11579. {
  11580. LPFC_MBOXQ_t *mbox;
  11581. int rc, length, status = 0;
  11582. uint32_t shdr_status, shdr_add_status;
  11583. union lpfc_sli4_cfg_shdr *shdr;
  11584. if (!mq)
  11585. return -ENODEV;
  11586. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  11587. if (!mbox)
  11588. return -ENOMEM;
  11589. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  11590. sizeof(struct lpfc_sli4_cfg_mhdr));
  11591. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11592. LPFC_MBOX_OPCODE_MQ_DESTROY,
  11593. length, LPFC_SLI4_MBX_EMBED);
  11594. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  11595. mq->queue_id);
  11596. mbox->vport = mq->phba->pport;
  11597. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11598. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  11599. /* The IOCTL status is embedded in the mailbox subheader. */
  11600. shdr = (union lpfc_sli4_cfg_shdr *)
  11601. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  11602. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11603. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11604. if (shdr_status || shdr_add_status || rc) {
  11605. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11606. "2507 MQ_DESTROY mailbox failed with "
  11607. "status x%x add_status x%x, mbx status x%x\n",
  11608. shdr_status, shdr_add_status, rc);
  11609. status = -ENXIO;
  11610. }
  11611. /* Remove mq from any list */
  11612. list_del_init(&mq->list);
  11613. mempool_free(mbox, mq->phba->mbox_mem_pool);
  11614. return status;
  11615. }
  11616. /**
  11617. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  11618. * @wq: The queue structure associated with the queue to destroy.
  11619. *
  11620. * This function destroys a queue, as detailed in @wq by sending an mailbox
  11621. * command, specific to the type of queue, to the HBA.
  11622. *
  11623. * The @wq struct is used to get the queue ID of the queue to destroy.
  11624. *
  11625. * On success this function will return a zero. If the queue destroy mailbox
  11626. * command fails this function will return -ENXIO.
  11627. **/
  11628. uint32_t
  11629. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  11630. {
  11631. LPFC_MBOXQ_t *mbox;
  11632. int rc, length, status = 0;
  11633. uint32_t shdr_status, shdr_add_status;
  11634. union lpfc_sli4_cfg_shdr *shdr;
  11635. if (!wq)
  11636. return -ENODEV;
  11637. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  11638. if (!mbox)
  11639. return -ENOMEM;
  11640. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  11641. sizeof(struct lpfc_sli4_cfg_mhdr));
  11642. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11643. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  11644. length, LPFC_SLI4_MBX_EMBED);
  11645. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  11646. wq->queue_id);
  11647. mbox->vport = wq->phba->pport;
  11648. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11649. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  11650. shdr = (union lpfc_sli4_cfg_shdr *)
  11651. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  11652. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11653. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11654. if (shdr_status || shdr_add_status || rc) {
  11655. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11656. "2508 WQ_DESTROY mailbox failed with "
  11657. "status x%x add_status x%x, mbx status x%x\n",
  11658. shdr_status, shdr_add_status, rc);
  11659. status = -ENXIO;
  11660. }
  11661. /* Remove wq from any list */
  11662. list_del_init(&wq->list);
  11663. mempool_free(mbox, wq->phba->mbox_mem_pool);
  11664. return status;
  11665. }
  11666. /**
  11667. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  11668. * @rq: The queue structure associated with the queue to destroy.
  11669. *
  11670. * This function destroys a queue, as detailed in @rq by sending an mailbox
  11671. * command, specific to the type of queue, to the HBA.
  11672. *
  11673. * The @rq struct is used to get the queue ID of the queue to destroy.
  11674. *
  11675. * On success this function will return a zero. If the queue destroy mailbox
  11676. * command fails this function will return -ENXIO.
  11677. **/
  11678. uint32_t
  11679. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11680. struct lpfc_queue *drq)
  11681. {
  11682. LPFC_MBOXQ_t *mbox;
  11683. int rc, length, status = 0;
  11684. uint32_t shdr_status, shdr_add_status;
  11685. union lpfc_sli4_cfg_shdr *shdr;
  11686. if (!hrq || !drq)
  11687. return -ENODEV;
  11688. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  11689. if (!mbox)
  11690. return -ENOMEM;
  11691. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  11692. sizeof(struct lpfc_sli4_cfg_mhdr));
  11693. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11694. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  11695. length, LPFC_SLI4_MBX_EMBED);
  11696. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  11697. hrq->queue_id);
  11698. mbox->vport = hrq->phba->pport;
  11699. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11700. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  11701. /* The IOCTL status is embedded in the mailbox subheader. */
  11702. shdr = (union lpfc_sli4_cfg_shdr *)
  11703. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  11704. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11705. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11706. if (shdr_status || shdr_add_status || rc) {
  11707. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11708. "2509 RQ_DESTROY mailbox failed with "
  11709. "status x%x add_status x%x, mbx status x%x\n",
  11710. shdr_status, shdr_add_status, rc);
  11711. if (rc != MBX_TIMEOUT)
  11712. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  11713. return -ENXIO;
  11714. }
  11715. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  11716. drq->queue_id);
  11717. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  11718. shdr = (union lpfc_sli4_cfg_shdr *)
  11719. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  11720. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11721. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11722. if (shdr_status || shdr_add_status || rc) {
  11723. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11724. "2510 RQ_DESTROY mailbox failed with "
  11725. "status x%x add_status x%x, mbx status x%x\n",
  11726. shdr_status, shdr_add_status, rc);
  11727. status = -ENXIO;
  11728. }
  11729. list_del_init(&hrq->list);
  11730. list_del_init(&drq->list);
  11731. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  11732. return status;
  11733. }
  11734. /**
  11735. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  11736. * @phba: The virtual port for which this call being executed.
  11737. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  11738. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  11739. * @xritag: the xritag that ties this io to the SGL pages.
  11740. *
  11741. * This routine will post the sgl pages for the IO that has the xritag
  11742. * that is in the iocbq structure. The xritag is assigned during iocbq
  11743. * creation and persists for as long as the driver is loaded.
  11744. * if the caller has fewer than 256 scatter gather segments to map then
  11745. * pdma_phys_addr1 should be 0.
  11746. * If the caller needs to map more than 256 scatter gather segment then
  11747. * pdma_phys_addr1 should be a valid physical address.
  11748. * physical address for SGLs must be 64 byte aligned.
  11749. * If you are going to map 2 SGL's then the first one must have 256 entries
  11750. * the second sgl can have between 1 and 256 entries.
  11751. *
  11752. * Return codes:
  11753. * 0 - Success
  11754. * -ENXIO, -ENOMEM - Failure
  11755. **/
  11756. int
  11757. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  11758. dma_addr_t pdma_phys_addr0,
  11759. dma_addr_t pdma_phys_addr1,
  11760. uint16_t xritag)
  11761. {
  11762. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  11763. LPFC_MBOXQ_t *mbox;
  11764. int rc;
  11765. uint32_t shdr_status, shdr_add_status;
  11766. uint32_t mbox_tmo;
  11767. union lpfc_sli4_cfg_shdr *shdr;
  11768. if (xritag == NO_XRI) {
  11769. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11770. "0364 Invalid param:\n");
  11771. return -EINVAL;
  11772. }
  11773. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11774. if (!mbox)
  11775. return -ENOMEM;
  11776. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11777. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  11778. sizeof(struct lpfc_mbx_post_sgl_pages) -
  11779. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  11780. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  11781. &mbox->u.mqe.un.post_sgl_pages;
  11782. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  11783. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  11784. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  11785. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  11786. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  11787. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  11788. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  11789. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  11790. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  11791. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  11792. if (!phba->sli4_hba.intr_enable)
  11793. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11794. else {
  11795. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  11796. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  11797. }
  11798. /* The IOCTL status is embedded in the mailbox subheader. */
  11799. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  11800. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11801. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11802. if (rc != MBX_TIMEOUT)
  11803. mempool_free(mbox, phba->mbox_mem_pool);
  11804. if (shdr_status || shdr_add_status || rc) {
  11805. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11806. "2511 POST_SGL mailbox failed with "
  11807. "status x%x add_status x%x, mbx status x%x\n",
  11808. shdr_status, shdr_add_status, rc);
  11809. rc = -ENXIO;
  11810. }
  11811. return 0;
  11812. }
  11813. /**
  11814. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  11815. * @phba: pointer to lpfc hba data structure.
  11816. *
  11817. * This routine is invoked to post rpi header templates to the
  11818. * HBA consistent with the SLI-4 interface spec. This routine
  11819. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11820. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11821. *
  11822. * Returns
  11823. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  11824. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  11825. **/
  11826. uint16_t
  11827. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  11828. {
  11829. unsigned long xri;
  11830. /*
  11831. * Fetch the next logical xri. Because this index is logical,
  11832. * the driver starts at 0 each time.
  11833. */
  11834. spin_lock_irq(&phba->hbalock);
  11835. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  11836. phba->sli4_hba.max_cfg_param.max_xri, 0);
  11837. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  11838. spin_unlock_irq(&phba->hbalock);
  11839. return NO_XRI;
  11840. } else {
  11841. set_bit(xri, phba->sli4_hba.xri_bmask);
  11842. phba->sli4_hba.max_cfg_param.xri_used++;
  11843. phba->sli4_hba.xri_count++;
  11844. }
  11845. spin_unlock_irq(&phba->hbalock);
  11846. return xri;
  11847. }
  11848. /**
  11849. * lpfc_sli4_free_xri - Release an xri for reuse.
  11850. * @phba: pointer to lpfc hba data structure.
  11851. *
  11852. * This routine is invoked to release an xri to the pool of
  11853. * available rpis maintained by the driver.
  11854. **/
  11855. void
  11856. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  11857. {
  11858. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  11859. phba->sli4_hba.xri_count--;
  11860. phba->sli4_hba.max_cfg_param.xri_used--;
  11861. }
  11862. }
  11863. /**
  11864. * lpfc_sli4_free_xri - Release an xri for reuse.
  11865. * @phba: pointer to lpfc hba data structure.
  11866. *
  11867. * This routine is invoked to release an xri to the pool of
  11868. * available rpis maintained by the driver.
  11869. **/
  11870. void
  11871. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  11872. {
  11873. spin_lock_irq(&phba->hbalock);
  11874. __lpfc_sli4_free_xri(phba, xri);
  11875. spin_unlock_irq(&phba->hbalock);
  11876. }
  11877. /**
  11878. * lpfc_sli4_next_xritag - Get an xritag for the io
  11879. * @phba: Pointer to HBA context object.
  11880. *
  11881. * This function gets an xritag for the iocb. If there is no unused xritag
  11882. * it will return 0xffff.
  11883. * The function returns the allocated xritag if successful, else returns zero.
  11884. * Zero is not a valid xritag.
  11885. * The caller is not required to hold any lock.
  11886. **/
  11887. uint16_t
  11888. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  11889. {
  11890. uint16_t xri_index;
  11891. xri_index = lpfc_sli4_alloc_xri(phba);
  11892. if (xri_index != NO_XRI)
  11893. return xri_index;
  11894. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11895. "2004 Failed to allocate XRI.last XRITAG is %d"
  11896. " Max XRI is %d, Used XRI is %d\n",
  11897. xri_index,
  11898. phba->sli4_hba.max_cfg_param.max_xri,
  11899. phba->sli4_hba.max_cfg_param.xri_used);
  11900. return NO_XRI;
  11901. }
  11902. /**
  11903. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  11904. * @phba: pointer to lpfc hba data structure.
  11905. *
  11906. * This routine is invoked to post a block of driver's sgl pages to the
  11907. * HBA using non-embedded mailbox command. No Lock is held. This routine
  11908. * is only called when the driver is loading and after all IO has been
  11909. * stopped.
  11910. **/
  11911. int
  11912. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba)
  11913. {
  11914. struct lpfc_sglq *sglq_entry;
  11915. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  11916. struct sgl_page_pairs *sgl_pg_pairs;
  11917. void *viraddr;
  11918. LPFC_MBOXQ_t *mbox;
  11919. uint32_t reqlen, alloclen, pg_pairs;
  11920. uint32_t mbox_tmo;
  11921. uint16_t xritag_start = 0, lxri = 0;
  11922. int els_xri_cnt, rc = 0;
  11923. uint32_t shdr_status, shdr_add_status;
  11924. union lpfc_sli4_cfg_shdr *shdr;
  11925. /* The number of sgls to be posted */
  11926. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  11927. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  11928. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  11929. if (reqlen > SLI4_PAGE_SIZE) {
  11930. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  11931. "2559 Block sgl registration required DMA "
  11932. "size (%d) great than a page\n", reqlen);
  11933. return -ENOMEM;
  11934. }
  11935. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11936. if (!mbox)
  11937. return -ENOMEM;
  11938. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11939. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11940. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  11941. LPFC_SLI4_MBX_NEMBED);
  11942. if (alloclen < reqlen) {
  11943. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11944. "0285 Allocated DMA memory size (%d) is "
  11945. "less than the requested DMA memory "
  11946. "size (%d)\n", alloclen, reqlen);
  11947. lpfc_sli4_mbox_cmd_free(phba, mbox);
  11948. return -ENOMEM;
  11949. }
  11950. /* Set up the SGL pages in the non-embedded DMA pages */
  11951. viraddr = mbox->sge_array->addr[0];
  11952. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  11953. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  11954. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  11955. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  11956. /*
  11957. * Assign the sglq a physical xri only if the driver has not
  11958. * initialized those resources. A port reset only needs
  11959. * the sglq's posted.
  11960. */
  11961. if (bf_get(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  11962. LPFC_XRI_RSRC_RDY) {
  11963. lxri = lpfc_sli4_next_xritag(phba);
  11964. if (lxri == NO_XRI) {
  11965. lpfc_sli4_mbox_cmd_free(phba, mbox);
  11966. return -ENOMEM;
  11967. }
  11968. sglq_entry->sli4_lxritag = lxri;
  11969. sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  11970. }
  11971. /* Set up the sge entry */
  11972. sgl_pg_pairs->sgl_pg0_addr_lo =
  11973. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  11974. sgl_pg_pairs->sgl_pg0_addr_hi =
  11975. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  11976. sgl_pg_pairs->sgl_pg1_addr_lo =
  11977. cpu_to_le32(putPaddrLow(0));
  11978. sgl_pg_pairs->sgl_pg1_addr_hi =
  11979. cpu_to_le32(putPaddrHigh(0));
  11980. /* Keep the first xritag on the list */
  11981. if (pg_pairs == 0)
  11982. xritag_start = sglq_entry->sli4_xritag;
  11983. sgl_pg_pairs++;
  11984. }
  11985. /* Complete initialization and perform endian conversion. */
  11986. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  11987. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  11988. sgl->word0 = cpu_to_le32(sgl->word0);
  11989. if (!phba->sli4_hba.intr_enable)
  11990. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11991. else {
  11992. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  11993. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  11994. }
  11995. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  11996. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11997. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11998. if (rc != MBX_TIMEOUT)
  11999. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12000. if (shdr_status || shdr_add_status || rc) {
  12001. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12002. "2513 POST_SGL_BLOCK mailbox command failed "
  12003. "status x%x add_status x%x mbx status x%x\n",
  12004. shdr_status, shdr_add_status, rc);
  12005. rc = -ENXIO;
  12006. }
  12007. if (rc == 0)
  12008. bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  12009. LPFC_XRI_RSRC_RDY);
  12010. return rc;
  12011. }
  12012. /**
  12013. * lpfc_sli4_post_els_sgl_list_ext - post a block of ELS sgls to the port.
  12014. * @phba: pointer to lpfc hba data structure.
  12015. *
  12016. * This routine is invoked to post a block of driver's sgl pages to the
  12017. * HBA using non-embedded mailbox command. No Lock is held. This routine
  12018. * is only called when the driver is loading and after all IO has been
  12019. * stopped.
  12020. **/
  12021. int
  12022. lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba)
  12023. {
  12024. struct lpfc_sglq *sglq_entry;
  12025. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12026. struct sgl_page_pairs *sgl_pg_pairs;
  12027. void *viraddr;
  12028. LPFC_MBOXQ_t *mbox;
  12029. uint32_t reqlen, alloclen, index;
  12030. uint32_t mbox_tmo;
  12031. uint16_t rsrc_start, rsrc_size, els_xri_cnt;
  12032. uint16_t xritag_start = 0, lxri = 0;
  12033. struct lpfc_rsrc_blks *rsrc_blk;
  12034. int cnt, ttl_cnt, rc = 0;
  12035. int loop_cnt;
  12036. uint32_t shdr_status, shdr_add_status;
  12037. union lpfc_sli4_cfg_shdr *shdr;
  12038. /* The number of sgls to be posted */
  12039. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  12040. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  12041. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12042. if (reqlen > SLI4_PAGE_SIZE) {
  12043. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12044. "2989 Block sgl registration required DMA "
  12045. "size (%d) great than a page\n", reqlen);
  12046. return -ENOMEM;
  12047. }
  12048. cnt = 0;
  12049. ttl_cnt = 0;
  12050. list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list,
  12051. list) {
  12052. rsrc_start = rsrc_blk->rsrc_start;
  12053. rsrc_size = rsrc_blk->rsrc_size;
  12054. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12055. "3014 Working ELS Extent start %d, cnt %d\n",
  12056. rsrc_start, rsrc_size);
  12057. loop_cnt = min(els_xri_cnt, rsrc_size);
  12058. if (ttl_cnt + loop_cnt >= els_xri_cnt) {
  12059. loop_cnt = els_xri_cnt - ttl_cnt;
  12060. ttl_cnt = els_xri_cnt;
  12061. }
  12062. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12063. if (!mbox)
  12064. return -ENOMEM;
  12065. /*
  12066. * Allocate DMA memory and set up the non-embedded mailbox
  12067. * command.
  12068. */
  12069. alloclen = lpfc_sli4_config(phba, mbox,
  12070. LPFC_MBOX_SUBSYSTEM_FCOE,
  12071. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  12072. reqlen, LPFC_SLI4_MBX_NEMBED);
  12073. if (alloclen < reqlen) {
  12074. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12075. "2987 Allocated DMA memory size (%d) "
  12076. "is less than the requested DMA memory "
  12077. "size (%d)\n", alloclen, reqlen);
  12078. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12079. return -ENOMEM;
  12080. }
  12081. /* Set up the SGL pages in the non-embedded DMA pages */
  12082. viraddr = mbox->sge_array->addr[0];
  12083. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12084. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12085. /*
  12086. * The starting resource may not begin at zero. Control
  12087. * the loop variants via the block resource parameters,
  12088. * but handle the sge pointers with a zero-based index
  12089. * that doesn't get reset per loop pass.
  12090. */
  12091. for (index = rsrc_start;
  12092. index < rsrc_start + loop_cnt;
  12093. index++) {
  12094. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[cnt];
  12095. /*
  12096. * Assign the sglq a physical xri only if the driver
  12097. * has not initialized those resources. A port reset
  12098. * only needs the sglq's posted.
  12099. */
  12100. if (bf_get(lpfc_xri_rsrc_rdy,
  12101. &phba->sli4_hba.sli4_flags) !=
  12102. LPFC_XRI_RSRC_RDY) {
  12103. lxri = lpfc_sli4_next_xritag(phba);
  12104. if (lxri == NO_XRI) {
  12105. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12106. rc = -ENOMEM;
  12107. goto err_exit;
  12108. }
  12109. sglq_entry->sli4_lxritag = lxri;
  12110. sglq_entry->sli4_xritag =
  12111. phba->sli4_hba.xri_ids[lxri];
  12112. }
  12113. /* Set up the sge entry */
  12114. sgl_pg_pairs->sgl_pg0_addr_lo =
  12115. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  12116. sgl_pg_pairs->sgl_pg0_addr_hi =
  12117. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  12118. sgl_pg_pairs->sgl_pg1_addr_lo =
  12119. cpu_to_le32(putPaddrLow(0));
  12120. sgl_pg_pairs->sgl_pg1_addr_hi =
  12121. cpu_to_le32(putPaddrHigh(0));
  12122. /* Track the starting physical XRI for the mailbox. */
  12123. if (index == rsrc_start)
  12124. xritag_start = sglq_entry->sli4_xritag;
  12125. sgl_pg_pairs++;
  12126. cnt++;
  12127. }
  12128. /* Complete initialization and perform endian conversion. */
  12129. rsrc_blk->rsrc_used += loop_cnt;
  12130. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12131. bf_set(lpfc_post_sgl_pages_xricnt, sgl, loop_cnt);
  12132. sgl->word0 = cpu_to_le32(sgl->word0);
  12133. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12134. "3015 Post ELS Extent SGL, start %d, "
  12135. "cnt %d, used %d\n",
  12136. xritag_start, loop_cnt, rsrc_blk->rsrc_used);
  12137. if (!phba->sli4_hba.intr_enable)
  12138. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12139. else {
  12140. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12141. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12142. }
  12143. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12144. shdr_status = bf_get(lpfc_mbox_hdr_status,
  12145. &shdr->response);
  12146. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  12147. &shdr->response);
  12148. if (rc != MBX_TIMEOUT)
  12149. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12150. if (shdr_status || shdr_add_status || rc) {
  12151. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12152. "2988 POST_SGL_BLOCK mailbox "
  12153. "command failed status x%x "
  12154. "add_status x%x mbx status x%x\n",
  12155. shdr_status, shdr_add_status, rc);
  12156. rc = -ENXIO;
  12157. goto err_exit;
  12158. }
  12159. if (ttl_cnt >= els_xri_cnt)
  12160. break;
  12161. }
  12162. err_exit:
  12163. if (rc == 0)
  12164. bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  12165. LPFC_XRI_RSRC_RDY);
  12166. return rc;
  12167. }
  12168. /**
  12169. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  12170. * @phba: pointer to lpfc hba data structure.
  12171. * @sblist: pointer to scsi buffer list.
  12172. * @count: number of scsi buffers on the list.
  12173. *
  12174. * This routine is invoked to post a block of @count scsi sgl pages from a
  12175. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  12176. * No Lock is held.
  12177. *
  12178. **/
  12179. int
  12180. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  12181. int cnt)
  12182. {
  12183. struct lpfc_scsi_buf *psb;
  12184. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12185. struct sgl_page_pairs *sgl_pg_pairs;
  12186. void *viraddr;
  12187. LPFC_MBOXQ_t *mbox;
  12188. uint32_t reqlen, alloclen, pg_pairs;
  12189. uint32_t mbox_tmo;
  12190. uint16_t xritag_start = 0;
  12191. int rc = 0;
  12192. uint32_t shdr_status, shdr_add_status;
  12193. dma_addr_t pdma_phys_bpl1;
  12194. union lpfc_sli4_cfg_shdr *shdr;
  12195. /* Calculate the requested length of the dma memory */
  12196. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  12197. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12198. if (reqlen > SLI4_PAGE_SIZE) {
  12199. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12200. "0217 Block sgl registration required DMA "
  12201. "size (%d) great than a page\n", reqlen);
  12202. return -ENOMEM;
  12203. }
  12204. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12205. if (!mbox) {
  12206. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12207. "0283 Failed to allocate mbox cmd memory\n");
  12208. return -ENOMEM;
  12209. }
  12210. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12211. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12212. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12213. LPFC_SLI4_MBX_NEMBED);
  12214. if (alloclen < reqlen) {
  12215. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12216. "2561 Allocated DMA memory size (%d) is "
  12217. "less than the requested DMA memory "
  12218. "size (%d)\n", alloclen, reqlen);
  12219. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12220. return -ENOMEM;
  12221. }
  12222. /* Get the first SGE entry from the non-embedded DMA memory */
  12223. viraddr = mbox->sge_array->addr[0];
  12224. /* Set up the SGL pages in the non-embedded DMA pages */
  12225. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12226. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12227. pg_pairs = 0;
  12228. list_for_each_entry(psb, sblist, list) {
  12229. /* Set up the sge entry */
  12230. sgl_pg_pairs->sgl_pg0_addr_lo =
  12231. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  12232. sgl_pg_pairs->sgl_pg0_addr_hi =
  12233. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  12234. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  12235. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  12236. else
  12237. pdma_phys_bpl1 = 0;
  12238. sgl_pg_pairs->sgl_pg1_addr_lo =
  12239. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  12240. sgl_pg_pairs->sgl_pg1_addr_hi =
  12241. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  12242. /* Keep the first xritag on the list */
  12243. if (pg_pairs == 0)
  12244. xritag_start = psb->cur_iocbq.sli4_xritag;
  12245. sgl_pg_pairs++;
  12246. pg_pairs++;
  12247. }
  12248. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12249. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  12250. /* Perform endian conversion if necessary */
  12251. sgl->word0 = cpu_to_le32(sgl->word0);
  12252. if (!phba->sli4_hba.intr_enable)
  12253. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12254. else {
  12255. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12256. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12257. }
  12258. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12259. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12260. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12261. if (rc != MBX_TIMEOUT)
  12262. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12263. if (shdr_status || shdr_add_status || rc) {
  12264. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12265. "2564 POST_SGL_BLOCK mailbox command failed "
  12266. "status x%x add_status x%x mbx status x%x\n",
  12267. shdr_status, shdr_add_status, rc);
  12268. rc = -ENXIO;
  12269. }
  12270. return rc;
  12271. }
  12272. /**
  12273. * lpfc_sli4_post_scsi_sgl_blk_ext - post a block of scsi sgls to the port.
  12274. * @phba: pointer to lpfc hba data structure.
  12275. * @sblist: pointer to scsi buffer list.
  12276. * @count: number of scsi buffers on the list.
  12277. *
  12278. * This routine is invoked to post a block of @count scsi sgl pages from a
  12279. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  12280. * No Lock is held.
  12281. *
  12282. **/
  12283. int
  12284. lpfc_sli4_post_scsi_sgl_blk_ext(struct lpfc_hba *phba, struct list_head *sblist,
  12285. int cnt)
  12286. {
  12287. struct lpfc_scsi_buf *psb = NULL;
  12288. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12289. struct sgl_page_pairs *sgl_pg_pairs;
  12290. void *viraddr;
  12291. LPFC_MBOXQ_t *mbox;
  12292. uint32_t reqlen, alloclen, pg_pairs;
  12293. uint32_t mbox_tmo;
  12294. uint16_t xri_start = 0, scsi_xri_start;
  12295. uint16_t rsrc_range;
  12296. int rc = 0, avail_cnt;
  12297. uint32_t shdr_status, shdr_add_status;
  12298. dma_addr_t pdma_phys_bpl1;
  12299. union lpfc_sli4_cfg_shdr *shdr;
  12300. struct lpfc_rsrc_blks *rsrc_blk;
  12301. uint32_t xri_cnt = 0;
  12302. /* Calculate the total requested length of the dma memory */
  12303. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  12304. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12305. if (reqlen > SLI4_PAGE_SIZE) {
  12306. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12307. "2932 Block sgl registration required DMA "
  12308. "size (%d) great than a page\n", reqlen);
  12309. return -ENOMEM;
  12310. }
  12311. /*
  12312. * The use of extents requires the driver to post the sgl headers
  12313. * in multiple postings to meet the contiguous resource assignment.
  12314. */
  12315. psb = list_prepare_entry(psb, sblist, list);
  12316. scsi_xri_start = phba->sli4_hba.scsi_xri_start;
  12317. list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list,
  12318. list) {
  12319. rsrc_range = rsrc_blk->rsrc_start + rsrc_blk->rsrc_size;
  12320. if (rsrc_range < scsi_xri_start)
  12321. continue;
  12322. else if (rsrc_blk->rsrc_used >= rsrc_blk->rsrc_size)
  12323. continue;
  12324. else
  12325. avail_cnt = rsrc_blk->rsrc_size - rsrc_blk->rsrc_used;
  12326. reqlen = (avail_cnt * sizeof(struct sgl_page_pairs)) +
  12327. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12328. /*
  12329. * Allocate DMA memory and set up the non-embedded mailbox
  12330. * command. The mbox is used to post an SGL page per loop
  12331. * but the DMA memory has a use-once semantic so the mailbox
  12332. * is used and freed per loop pass.
  12333. */
  12334. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12335. if (!mbox) {
  12336. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12337. "2933 Failed to allocate mbox cmd "
  12338. "memory\n");
  12339. return -ENOMEM;
  12340. }
  12341. alloclen = lpfc_sli4_config(phba, mbox,
  12342. LPFC_MBOX_SUBSYSTEM_FCOE,
  12343. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  12344. reqlen,
  12345. LPFC_SLI4_MBX_NEMBED);
  12346. if (alloclen < reqlen) {
  12347. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12348. "2934 Allocated DMA memory size (%d) "
  12349. "is less than the requested DMA memory "
  12350. "size (%d)\n", alloclen, reqlen);
  12351. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12352. return -ENOMEM;
  12353. }
  12354. /* Get the first SGE entry from the non-embedded DMA memory */
  12355. viraddr = mbox->sge_array->addr[0];
  12356. /* Set up the SGL pages in the non-embedded DMA pages */
  12357. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12358. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12359. /* pg_pairs tracks posted SGEs per loop iteration. */
  12360. pg_pairs = 0;
  12361. list_for_each_entry_continue(psb, sblist, list) {
  12362. /* Set up the sge entry */
  12363. sgl_pg_pairs->sgl_pg0_addr_lo =
  12364. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  12365. sgl_pg_pairs->sgl_pg0_addr_hi =
  12366. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  12367. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  12368. pdma_phys_bpl1 = psb->dma_phys_bpl +
  12369. SGL_PAGE_SIZE;
  12370. else
  12371. pdma_phys_bpl1 = 0;
  12372. sgl_pg_pairs->sgl_pg1_addr_lo =
  12373. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  12374. sgl_pg_pairs->sgl_pg1_addr_hi =
  12375. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  12376. /* Keep the first xri for this extent. */
  12377. if (pg_pairs == 0)
  12378. xri_start = psb->cur_iocbq.sli4_xritag;
  12379. sgl_pg_pairs++;
  12380. pg_pairs++;
  12381. xri_cnt++;
  12382. /*
  12383. * Track two exit conditions - the loop has constructed
  12384. * all of the caller's SGE pairs or all available
  12385. * resource IDs in this extent are consumed.
  12386. */
  12387. if ((xri_cnt == cnt) || (pg_pairs >= avail_cnt))
  12388. break;
  12389. }
  12390. rsrc_blk->rsrc_used += pg_pairs;
  12391. bf_set(lpfc_post_sgl_pages_xri, sgl, xri_start);
  12392. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  12393. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12394. "3016 Post SCSI Extent SGL, start %d, cnt %d "
  12395. "blk use %d\n",
  12396. xri_start, pg_pairs, rsrc_blk->rsrc_used);
  12397. /* Perform endian conversion if necessary */
  12398. sgl->word0 = cpu_to_le32(sgl->word0);
  12399. if (!phba->sli4_hba.intr_enable)
  12400. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12401. else {
  12402. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12403. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12404. }
  12405. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12406. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12407. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  12408. &shdr->response);
  12409. if (rc != MBX_TIMEOUT)
  12410. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12411. if (shdr_status || shdr_add_status || rc) {
  12412. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12413. "2935 POST_SGL_BLOCK mailbox command "
  12414. "failed status x%x add_status x%x "
  12415. "mbx status x%x\n",
  12416. shdr_status, shdr_add_status, rc);
  12417. return -ENXIO;
  12418. }
  12419. /* Post only what is requested. */
  12420. if (xri_cnt >= cnt)
  12421. break;
  12422. }
  12423. return rc;
  12424. }
  12425. /**
  12426. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  12427. * @phba: pointer to lpfc_hba struct that the frame was received on
  12428. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12429. *
  12430. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  12431. * valid type of frame that the LPFC driver will handle. This function will
  12432. * return a zero if the frame is a valid frame or a non zero value when the
  12433. * frame does not pass the check.
  12434. **/
  12435. static int
  12436. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  12437. {
  12438. /* make rctl_names static to save stack space */
  12439. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  12440. char *type_names[] = FC_TYPE_NAMES_INIT;
  12441. struct fc_vft_header *fc_vft_hdr;
  12442. uint32_t *header = (uint32_t *) fc_hdr;
  12443. switch (fc_hdr->fh_r_ctl) {
  12444. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  12445. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  12446. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  12447. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  12448. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  12449. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  12450. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  12451. case FC_RCTL_DD_CMD_STATUS: /* command status */
  12452. case FC_RCTL_ELS_REQ: /* extended link services request */
  12453. case FC_RCTL_ELS_REP: /* extended link services reply */
  12454. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  12455. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  12456. case FC_RCTL_BA_NOP: /* basic link service NOP */
  12457. case FC_RCTL_BA_ABTS: /* basic link service abort */
  12458. case FC_RCTL_BA_RMC: /* remove connection */
  12459. case FC_RCTL_BA_ACC: /* basic accept */
  12460. case FC_RCTL_BA_RJT: /* basic reject */
  12461. case FC_RCTL_BA_PRMT:
  12462. case FC_RCTL_ACK_1: /* acknowledge_1 */
  12463. case FC_RCTL_ACK_0: /* acknowledge_0 */
  12464. case FC_RCTL_P_RJT: /* port reject */
  12465. case FC_RCTL_F_RJT: /* fabric reject */
  12466. case FC_RCTL_P_BSY: /* port busy */
  12467. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  12468. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  12469. case FC_RCTL_LCR: /* link credit reset */
  12470. case FC_RCTL_END: /* end */
  12471. break;
  12472. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  12473. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12474. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  12475. return lpfc_fc_frame_check(phba, fc_hdr);
  12476. default:
  12477. goto drop;
  12478. }
  12479. switch (fc_hdr->fh_type) {
  12480. case FC_TYPE_BLS:
  12481. case FC_TYPE_ELS:
  12482. case FC_TYPE_FCP:
  12483. case FC_TYPE_CT:
  12484. break;
  12485. case FC_TYPE_IP:
  12486. case FC_TYPE_ILS:
  12487. default:
  12488. goto drop;
  12489. }
  12490. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12491. "2538 Received frame rctl:%s type:%s "
  12492. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  12493. rctl_names[fc_hdr->fh_r_ctl],
  12494. type_names[fc_hdr->fh_type],
  12495. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  12496. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  12497. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  12498. return 0;
  12499. drop:
  12500. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12501. "2539 Dropped frame rctl:%s type:%s\n",
  12502. rctl_names[fc_hdr->fh_r_ctl],
  12503. type_names[fc_hdr->fh_type]);
  12504. return 1;
  12505. }
  12506. /**
  12507. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  12508. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12509. *
  12510. * This function processes the FC header to retrieve the VFI from the VF
  12511. * header, if one exists. This function will return the VFI if one exists
  12512. * or 0 if no VSAN Header exists.
  12513. **/
  12514. static uint32_t
  12515. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  12516. {
  12517. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12518. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  12519. return 0;
  12520. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  12521. }
  12522. /**
  12523. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  12524. * @phba: Pointer to the HBA structure to search for the vport on
  12525. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12526. * @fcfi: The FC Fabric ID that the frame came from
  12527. *
  12528. * This function searches the @phba for a vport that matches the content of the
  12529. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  12530. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  12531. * returns the matching vport pointer or NULL if unable to match frame to a
  12532. * vport.
  12533. **/
  12534. static struct lpfc_vport *
  12535. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  12536. uint16_t fcfi)
  12537. {
  12538. struct lpfc_vport **vports;
  12539. struct lpfc_vport *vport = NULL;
  12540. int i;
  12541. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  12542. fc_hdr->fh_d_id[1] << 8 |
  12543. fc_hdr->fh_d_id[2]);
  12544. if (did == Fabric_DID)
  12545. return phba->pport;
  12546. vports = lpfc_create_vport_work_array(phba);
  12547. if (vports != NULL)
  12548. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  12549. if (phba->fcf.fcfi == fcfi &&
  12550. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  12551. vports[i]->fc_myDID == did) {
  12552. vport = vports[i];
  12553. break;
  12554. }
  12555. }
  12556. lpfc_destroy_vport_work_array(phba, vports);
  12557. return vport;
  12558. }
  12559. /**
  12560. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  12561. * @vport: The vport to work on.
  12562. *
  12563. * This function updates the receive sequence time stamp for this vport. The
  12564. * receive sequence time stamp indicates the time that the last frame of the
  12565. * the sequence that has been idle for the longest amount of time was received.
  12566. * the driver uses this time stamp to indicate if any received sequences have
  12567. * timed out.
  12568. **/
  12569. void
  12570. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  12571. {
  12572. struct lpfc_dmabuf *h_buf;
  12573. struct hbq_dmabuf *dmabuf = NULL;
  12574. /* get the oldest sequence on the rcv list */
  12575. h_buf = list_get_first(&vport->rcv_buffer_list,
  12576. struct lpfc_dmabuf, list);
  12577. if (!h_buf)
  12578. return;
  12579. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12580. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  12581. }
  12582. /**
  12583. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  12584. * @vport: The vport that the received sequences were sent to.
  12585. *
  12586. * This function cleans up all outstanding received sequences. This is called
  12587. * by the driver when a link event or user action invalidates all the received
  12588. * sequences.
  12589. **/
  12590. void
  12591. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  12592. {
  12593. struct lpfc_dmabuf *h_buf, *hnext;
  12594. struct lpfc_dmabuf *d_buf, *dnext;
  12595. struct hbq_dmabuf *dmabuf = NULL;
  12596. /* start with the oldest sequence on the rcv list */
  12597. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12598. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12599. list_del_init(&dmabuf->hbuf.list);
  12600. list_for_each_entry_safe(d_buf, dnext,
  12601. &dmabuf->dbuf.list, list) {
  12602. list_del_init(&d_buf->list);
  12603. lpfc_in_buf_free(vport->phba, d_buf);
  12604. }
  12605. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12606. }
  12607. }
  12608. /**
  12609. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  12610. * @vport: The vport that the received sequences were sent to.
  12611. *
  12612. * This function determines whether any received sequences have timed out by
  12613. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  12614. * indicates that there is at least one timed out sequence this routine will
  12615. * go through the received sequences one at a time from most inactive to most
  12616. * active to determine which ones need to be cleaned up. Once it has determined
  12617. * that a sequence needs to be cleaned up it will simply free up the resources
  12618. * without sending an abort.
  12619. **/
  12620. void
  12621. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  12622. {
  12623. struct lpfc_dmabuf *h_buf, *hnext;
  12624. struct lpfc_dmabuf *d_buf, *dnext;
  12625. struct hbq_dmabuf *dmabuf = NULL;
  12626. unsigned long timeout;
  12627. int abort_count = 0;
  12628. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12629. vport->rcv_buffer_time_stamp);
  12630. if (list_empty(&vport->rcv_buffer_list) ||
  12631. time_before(jiffies, timeout))
  12632. return;
  12633. /* start with the oldest sequence on the rcv list */
  12634. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12635. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12636. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12637. dmabuf->time_stamp);
  12638. if (time_before(jiffies, timeout))
  12639. break;
  12640. abort_count++;
  12641. list_del_init(&dmabuf->hbuf.list);
  12642. list_for_each_entry_safe(d_buf, dnext,
  12643. &dmabuf->dbuf.list, list) {
  12644. list_del_init(&d_buf->list);
  12645. lpfc_in_buf_free(vport->phba, d_buf);
  12646. }
  12647. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12648. }
  12649. if (abort_count)
  12650. lpfc_update_rcv_time_stamp(vport);
  12651. }
  12652. /**
  12653. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  12654. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  12655. *
  12656. * This function searches through the existing incomplete sequences that have
  12657. * been sent to this @vport. If the frame matches one of the incomplete
  12658. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  12659. * make up that sequence. If no sequence is found that matches this frame then
  12660. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  12661. * This function returns a pointer to the first dmabuf in the sequence list that
  12662. * the frame was linked to.
  12663. **/
  12664. static struct hbq_dmabuf *
  12665. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  12666. {
  12667. struct fc_frame_header *new_hdr;
  12668. struct fc_frame_header *temp_hdr;
  12669. struct lpfc_dmabuf *d_buf;
  12670. struct lpfc_dmabuf *h_buf;
  12671. struct hbq_dmabuf *seq_dmabuf = NULL;
  12672. struct hbq_dmabuf *temp_dmabuf = NULL;
  12673. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12674. dmabuf->time_stamp = jiffies;
  12675. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12676. /* Use the hdr_buf to find the sequence that this frame belongs to */
  12677. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12678. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12679. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12680. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12681. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12682. continue;
  12683. /* found a pending sequence that matches this frame */
  12684. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12685. break;
  12686. }
  12687. if (!seq_dmabuf) {
  12688. /*
  12689. * This indicates first frame received for this sequence.
  12690. * Queue the buffer on the vport's rcv_buffer_list.
  12691. */
  12692. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12693. lpfc_update_rcv_time_stamp(vport);
  12694. return dmabuf;
  12695. }
  12696. temp_hdr = seq_dmabuf->hbuf.virt;
  12697. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  12698. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12699. list_del_init(&seq_dmabuf->hbuf.list);
  12700. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12701. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12702. lpfc_update_rcv_time_stamp(vport);
  12703. return dmabuf;
  12704. }
  12705. /* move this sequence to the tail to indicate a young sequence */
  12706. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12707. seq_dmabuf->time_stamp = jiffies;
  12708. lpfc_update_rcv_time_stamp(vport);
  12709. if (list_empty(&seq_dmabuf->dbuf.list)) {
  12710. temp_hdr = dmabuf->hbuf.virt;
  12711. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12712. return seq_dmabuf;
  12713. }
  12714. /* find the correct place in the sequence to insert this frame */
  12715. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  12716. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  12717. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  12718. /*
  12719. * If the frame's sequence count is greater than the frame on
  12720. * the list then insert the frame right after this frame
  12721. */
  12722. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  12723. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12724. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  12725. return seq_dmabuf;
  12726. }
  12727. }
  12728. return NULL;
  12729. }
  12730. /**
  12731. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  12732. * @vport: pointer to a vitural port
  12733. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12734. *
  12735. * This function tries to abort from the partially assembed sequence, described
  12736. * by the information from basic abbort @dmabuf. It checks to see whether such
  12737. * partially assembled sequence held by the driver. If so, it shall free up all
  12738. * the frames from the partially assembled sequence.
  12739. *
  12740. * Return
  12741. * true -- if there is matching partially assembled sequence present and all
  12742. * the frames freed with the sequence;
  12743. * false -- if there is no matching partially assembled sequence present so
  12744. * nothing got aborted in the lower layer driver
  12745. **/
  12746. static bool
  12747. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  12748. struct hbq_dmabuf *dmabuf)
  12749. {
  12750. struct fc_frame_header *new_hdr;
  12751. struct fc_frame_header *temp_hdr;
  12752. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  12753. struct hbq_dmabuf *seq_dmabuf = NULL;
  12754. /* Use the hdr_buf to find the sequence that matches this frame */
  12755. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12756. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  12757. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12758. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12759. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12760. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12761. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12762. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12763. continue;
  12764. /* found a pending sequence that matches this frame */
  12765. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12766. break;
  12767. }
  12768. /* Free up all the frames from the partially assembled sequence */
  12769. if (seq_dmabuf) {
  12770. list_for_each_entry_safe(d_buf, n_buf,
  12771. &seq_dmabuf->dbuf.list, list) {
  12772. list_del_init(&d_buf->list);
  12773. lpfc_in_buf_free(vport->phba, d_buf);
  12774. }
  12775. return true;
  12776. }
  12777. return false;
  12778. }
  12779. /**
  12780. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  12781. * @phba: Pointer to HBA context object.
  12782. * @cmd_iocbq: pointer to the command iocbq structure.
  12783. * @rsp_iocbq: pointer to the response iocbq structure.
  12784. *
  12785. * This function handles the sequence abort response iocb command complete
  12786. * event. It properly releases the memory allocated to the sequence abort
  12787. * accept iocb.
  12788. **/
  12789. static void
  12790. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  12791. struct lpfc_iocbq *cmd_iocbq,
  12792. struct lpfc_iocbq *rsp_iocbq)
  12793. {
  12794. if (cmd_iocbq)
  12795. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  12796. }
  12797. /**
  12798. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  12799. * @phba: Pointer to HBA context object.
  12800. * @xri: xri id in transaction.
  12801. *
  12802. * This function validates the xri maps to the known range of XRIs allocated an
  12803. * used by the driver.
  12804. **/
  12805. uint16_t
  12806. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  12807. uint16_t xri)
  12808. {
  12809. int i;
  12810. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  12811. if (xri == phba->sli4_hba.xri_ids[i])
  12812. return i;
  12813. }
  12814. return NO_XRI;
  12815. }
  12816. /**
  12817. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  12818. * @phba: Pointer to HBA context object.
  12819. * @fc_hdr: pointer to a FC frame header.
  12820. *
  12821. * This function sends a basic response to a previous unsol sequence abort
  12822. * event after aborting the sequence handling.
  12823. **/
  12824. static void
  12825. lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba,
  12826. struct fc_frame_header *fc_hdr)
  12827. {
  12828. struct lpfc_iocbq *ctiocb = NULL;
  12829. struct lpfc_nodelist *ndlp;
  12830. uint16_t oxid, rxid;
  12831. uint32_t sid, fctl;
  12832. IOCB_t *icmd;
  12833. int rc;
  12834. if (!lpfc_is_link_up(phba))
  12835. return;
  12836. sid = sli4_sid_from_fc_hdr(fc_hdr);
  12837. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  12838. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  12839. ndlp = lpfc_findnode_did(phba->pport, sid);
  12840. if (!ndlp) {
  12841. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12842. "1268 Find ndlp returned NULL for oxid:x%x "
  12843. "SID:x%x\n", oxid, sid);
  12844. return;
  12845. }
  12846. if (lpfc_sli4_xri_inrange(phba, rxid))
  12847. lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
  12848. /* Allocate buffer for rsp iocb */
  12849. ctiocb = lpfc_sli_get_iocbq(phba);
  12850. if (!ctiocb)
  12851. return;
  12852. /* Extract the F_CTL field from FC_HDR */
  12853. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  12854. icmd = &ctiocb->iocb;
  12855. icmd->un.xseq64.bdl.bdeSize = 0;
  12856. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  12857. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  12858. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  12859. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  12860. /* Fill in the rest of iocb fields */
  12861. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  12862. icmd->ulpBdeCount = 0;
  12863. icmd->ulpLe = 1;
  12864. icmd->ulpClass = CLASS3;
  12865. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  12866. ctiocb->context1 = ndlp;
  12867. ctiocb->iocb_cmpl = NULL;
  12868. ctiocb->vport = phba->pport;
  12869. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  12870. ctiocb->sli4_lxritag = NO_XRI;
  12871. ctiocb->sli4_xritag = NO_XRI;
  12872. /* If the oxid maps to the FCP XRI range or if it is out of range,
  12873. * send a BLS_RJT. The driver no longer has that exchange.
  12874. * Override the IOCB for a BA_RJT.
  12875. */
  12876. if (oxid > (phba->sli4_hba.max_cfg_param.max_xri +
  12877. phba->sli4_hba.max_cfg_param.xri_base) ||
  12878. oxid > (lpfc_sli4_get_els_iocb_cnt(phba) +
  12879. phba->sli4_hba.max_cfg_param.xri_base)) {
  12880. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  12881. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  12882. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  12883. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  12884. }
  12885. if (fctl & FC_FC_EX_CTX) {
  12886. /* ABTS sent by responder to CT exchange, construction
  12887. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  12888. * field and RX_ID from ABTS for RX_ID field.
  12889. */
  12890. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  12891. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  12892. } else {
  12893. /* ABTS sent by initiator to CT exchange, construction
  12894. * of BA_ACC will need to allocate a new XRI as for the
  12895. * XRI_TAG and RX_ID fields.
  12896. */
  12897. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  12898. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, NO_XRI);
  12899. }
  12900. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  12901. /* Xmit CT abts response on exchange <xid> */
  12902. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12903. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  12904. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  12905. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  12906. if (rc == IOCB_ERROR) {
  12907. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  12908. "2925 Failed to issue CT ABTS RSP x%x on "
  12909. "xri x%x, Data x%x\n",
  12910. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  12911. phba->link_state);
  12912. lpfc_sli_release_iocbq(phba, ctiocb);
  12913. }
  12914. }
  12915. /**
  12916. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  12917. * @vport: Pointer to the vport on which this sequence was received
  12918. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12919. *
  12920. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  12921. * receive sequence is only partially assembed by the driver, it shall abort
  12922. * the partially assembled frames for the sequence. Otherwise, if the
  12923. * unsolicited receive sequence has been completely assembled and passed to
  12924. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  12925. * unsolicited sequence has been aborted. After that, it will issue a basic
  12926. * accept to accept the abort.
  12927. **/
  12928. void
  12929. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  12930. struct hbq_dmabuf *dmabuf)
  12931. {
  12932. struct lpfc_hba *phba = vport->phba;
  12933. struct fc_frame_header fc_hdr;
  12934. uint32_t fctl;
  12935. bool abts_par;
  12936. /* Make a copy of fc_hdr before the dmabuf being released */
  12937. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  12938. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  12939. if (fctl & FC_FC_EX_CTX) {
  12940. /*
  12941. * ABTS sent by responder to exchange, just free the buffer
  12942. */
  12943. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  12944. } else {
  12945. /*
  12946. * ABTS sent by initiator to exchange, need to do cleanup
  12947. */
  12948. /* Try to abort partially assembled seq */
  12949. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  12950. /* Send abort to ULP if partially seq abort failed */
  12951. if (abts_par == false)
  12952. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  12953. else
  12954. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  12955. }
  12956. /* Send basic accept (BA_ACC) to the abort requester */
  12957. lpfc_sli4_seq_abort_rsp(phba, &fc_hdr);
  12958. }
  12959. /**
  12960. * lpfc_seq_complete - Indicates if a sequence is complete
  12961. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12962. *
  12963. * This function checks the sequence, starting with the frame described by
  12964. * @dmabuf, to see if all the frames associated with this sequence are present.
  12965. * the frames associated with this sequence are linked to the @dmabuf using the
  12966. * dbuf list. This function looks for two major things. 1) That the first frame
  12967. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  12968. * set. 3) That there are no holes in the sequence count. The function will
  12969. * return 1 when the sequence is complete, otherwise it will return 0.
  12970. **/
  12971. static int
  12972. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  12973. {
  12974. struct fc_frame_header *hdr;
  12975. struct lpfc_dmabuf *d_buf;
  12976. struct hbq_dmabuf *seq_dmabuf;
  12977. uint32_t fctl;
  12978. int seq_count = 0;
  12979. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12980. /* make sure first fame of sequence has a sequence count of zero */
  12981. if (hdr->fh_seq_cnt != seq_count)
  12982. return 0;
  12983. fctl = (hdr->fh_f_ctl[0] << 16 |
  12984. hdr->fh_f_ctl[1] << 8 |
  12985. hdr->fh_f_ctl[2]);
  12986. /* If last frame of sequence we can return success. */
  12987. if (fctl & FC_FC_END_SEQ)
  12988. return 1;
  12989. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  12990. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  12991. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  12992. /* If there is a hole in the sequence count then fail. */
  12993. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  12994. return 0;
  12995. fctl = (hdr->fh_f_ctl[0] << 16 |
  12996. hdr->fh_f_ctl[1] << 8 |
  12997. hdr->fh_f_ctl[2]);
  12998. /* If last frame of sequence we can return success. */
  12999. if (fctl & FC_FC_END_SEQ)
  13000. return 1;
  13001. }
  13002. return 0;
  13003. }
  13004. /**
  13005. * lpfc_prep_seq - Prep sequence for ULP processing
  13006. * @vport: Pointer to the vport on which this sequence was received
  13007. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13008. *
  13009. * This function takes a sequence, described by a list of frames, and creates
  13010. * a list of iocbq structures to describe the sequence. This iocbq list will be
  13011. * used to issue to the generic unsolicited sequence handler. This routine
  13012. * returns a pointer to the first iocbq in the list. If the function is unable
  13013. * to allocate an iocbq then it throw out the received frames that were not
  13014. * able to be described and return a pointer to the first iocbq. If unable to
  13015. * allocate any iocbqs (including the first) this function will return NULL.
  13016. **/
  13017. static struct lpfc_iocbq *
  13018. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  13019. {
  13020. struct hbq_dmabuf *hbq_buf;
  13021. struct lpfc_dmabuf *d_buf, *n_buf;
  13022. struct lpfc_iocbq *first_iocbq, *iocbq;
  13023. struct fc_frame_header *fc_hdr;
  13024. uint32_t sid;
  13025. uint32_t len, tot_len;
  13026. struct ulp_bde64 *pbde;
  13027. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13028. /* remove from receive buffer list */
  13029. list_del_init(&seq_dmabuf->hbuf.list);
  13030. lpfc_update_rcv_time_stamp(vport);
  13031. /* get the Remote Port's SID */
  13032. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13033. tot_len = 0;
  13034. /* Get an iocbq struct to fill in. */
  13035. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  13036. if (first_iocbq) {
  13037. /* Initialize the first IOCB. */
  13038. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  13039. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  13040. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  13041. first_iocbq->iocb.ulpContext = NO_XRI;
  13042. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  13043. be16_to_cpu(fc_hdr->fh_ox_id);
  13044. /* iocbq is prepped for internal consumption. Physical vpi. */
  13045. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  13046. vport->phba->vpi_ids[vport->vpi];
  13047. /* put the first buffer into the first IOCBq */
  13048. first_iocbq->context2 = &seq_dmabuf->dbuf;
  13049. first_iocbq->context3 = NULL;
  13050. first_iocbq->iocb.ulpBdeCount = 1;
  13051. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13052. LPFC_DATA_BUF_SIZE;
  13053. first_iocbq->iocb.un.rcvels.remoteID = sid;
  13054. tot_len = bf_get(lpfc_rcqe_length,
  13055. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  13056. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13057. }
  13058. iocbq = first_iocbq;
  13059. /*
  13060. * Each IOCBq can have two Buffers assigned, so go through the list
  13061. * of buffers for this sequence and save two buffers in each IOCBq
  13062. */
  13063. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  13064. if (!iocbq) {
  13065. lpfc_in_buf_free(vport->phba, d_buf);
  13066. continue;
  13067. }
  13068. if (!iocbq->context3) {
  13069. iocbq->context3 = d_buf;
  13070. iocbq->iocb.ulpBdeCount++;
  13071. pbde = (struct ulp_bde64 *)
  13072. &iocbq->iocb.unsli3.sli3Words[4];
  13073. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  13074. /* We need to get the size out of the right CQE */
  13075. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13076. len = bf_get(lpfc_rcqe_length,
  13077. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13078. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  13079. tot_len += len;
  13080. } else {
  13081. iocbq = lpfc_sli_get_iocbq(vport->phba);
  13082. if (!iocbq) {
  13083. if (first_iocbq) {
  13084. first_iocbq->iocb.ulpStatus =
  13085. IOSTAT_FCP_RSP_ERROR;
  13086. first_iocbq->iocb.un.ulpWord[4] =
  13087. IOERR_NO_RESOURCES;
  13088. }
  13089. lpfc_in_buf_free(vport->phba, d_buf);
  13090. continue;
  13091. }
  13092. iocbq->context2 = d_buf;
  13093. iocbq->context3 = NULL;
  13094. iocbq->iocb.ulpBdeCount = 1;
  13095. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13096. LPFC_DATA_BUF_SIZE;
  13097. /* We need to get the size out of the right CQE */
  13098. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13099. len = bf_get(lpfc_rcqe_length,
  13100. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13101. tot_len += len;
  13102. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13103. iocbq->iocb.un.rcvels.remoteID = sid;
  13104. list_add_tail(&iocbq->list, &first_iocbq->list);
  13105. }
  13106. }
  13107. return first_iocbq;
  13108. }
  13109. static void
  13110. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  13111. struct hbq_dmabuf *seq_dmabuf)
  13112. {
  13113. struct fc_frame_header *fc_hdr;
  13114. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  13115. struct lpfc_hba *phba = vport->phba;
  13116. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13117. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  13118. if (!iocbq) {
  13119. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13120. "2707 Ring %d handler: Failed to allocate "
  13121. "iocb Rctl x%x Type x%x received\n",
  13122. LPFC_ELS_RING,
  13123. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13124. return;
  13125. }
  13126. if (!lpfc_complete_unsol_iocb(phba,
  13127. &phba->sli.ring[LPFC_ELS_RING],
  13128. iocbq, fc_hdr->fh_r_ctl,
  13129. fc_hdr->fh_type))
  13130. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13131. "2540 Ring %d handler: unexpected Rctl "
  13132. "x%x Type x%x received\n",
  13133. LPFC_ELS_RING,
  13134. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13135. /* Free iocb created in lpfc_prep_seq */
  13136. list_for_each_entry_safe(curr_iocb, next_iocb,
  13137. &iocbq->list, list) {
  13138. list_del_init(&curr_iocb->list);
  13139. lpfc_sli_release_iocbq(phba, curr_iocb);
  13140. }
  13141. lpfc_sli_release_iocbq(phba, iocbq);
  13142. }
  13143. /**
  13144. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  13145. * @phba: Pointer to HBA context object.
  13146. *
  13147. * This function is called with no lock held. This function processes all
  13148. * the received buffers and gives it to upper layers when a received buffer
  13149. * indicates that it is the final frame in the sequence. The interrupt
  13150. * service routine processes received buffers at interrupt contexts and adds
  13151. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  13152. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  13153. * appropriate receive function when the final frame in a sequence is received.
  13154. **/
  13155. void
  13156. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  13157. struct hbq_dmabuf *dmabuf)
  13158. {
  13159. struct hbq_dmabuf *seq_dmabuf;
  13160. struct fc_frame_header *fc_hdr;
  13161. struct lpfc_vport *vport;
  13162. uint32_t fcfi;
  13163. /* Process each received buffer */
  13164. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13165. /* check to see if this a valid type of frame */
  13166. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  13167. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13168. return;
  13169. }
  13170. if ((bf_get(lpfc_cqe_code,
  13171. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  13172. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  13173. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13174. else
  13175. fcfi = bf_get(lpfc_rcqe_fcf_id,
  13176. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13177. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  13178. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  13179. /* throw out the frame */
  13180. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13181. return;
  13182. }
  13183. /* Handle the basic abort sequence (BA_ABTS) event */
  13184. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  13185. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  13186. return;
  13187. }
  13188. /* Link this frame */
  13189. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  13190. if (!seq_dmabuf) {
  13191. /* unable to add frame to vport - throw it out */
  13192. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13193. return;
  13194. }
  13195. /* If not last frame in sequence continue processing frames. */
  13196. if (!lpfc_seq_complete(seq_dmabuf))
  13197. return;
  13198. /* Send the complete sequence to the upper layer protocol */
  13199. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  13200. }
  13201. /**
  13202. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  13203. * @phba: pointer to lpfc hba data structure.
  13204. *
  13205. * This routine is invoked to post rpi header templates to the
  13206. * HBA consistent with the SLI-4 interface spec. This routine
  13207. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13208. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13209. *
  13210. * This routine does not require any locks. It's usage is expected
  13211. * to be driver load or reset recovery when the driver is
  13212. * sequential.
  13213. *
  13214. * Return codes
  13215. * 0 - successful
  13216. * -EIO - The mailbox failed to complete successfully.
  13217. * When this error occurs, the driver is not guaranteed
  13218. * to have any rpi regions posted to the device and
  13219. * must either attempt to repost the regions or take a
  13220. * fatal error.
  13221. **/
  13222. int
  13223. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  13224. {
  13225. struct lpfc_rpi_hdr *rpi_page;
  13226. uint32_t rc = 0;
  13227. uint16_t lrpi = 0;
  13228. /* SLI4 ports that support extents do not require RPI headers. */
  13229. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13230. goto exit;
  13231. if (phba->sli4_hba.extents_in_use)
  13232. return -EIO;
  13233. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  13234. /*
  13235. * Assign the rpi headers a physical rpi only if the driver
  13236. * has not initialized those resources. A port reset only
  13237. * needs the headers posted.
  13238. */
  13239. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  13240. LPFC_RPI_RSRC_RDY)
  13241. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13242. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  13243. if (rc != MBX_SUCCESS) {
  13244. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13245. "2008 Error %d posting all rpi "
  13246. "headers\n", rc);
  13247. rc = -EIO;
  13248. break;
  13249. }
  13250. }
  13251. exit:
  13252. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  13253. LPFC_RPI_RSRC_RDY);
  13254. return rc;
  13255. }
  13256. /**
  13257. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  13258. * @phba: pointer to lpfc hba data structure.
  13259. * @rpi_page: pointer to the rpi memory region.
  13260. *
  13261. * This routine is invoked to post a single rpi header to the
  13262. * HBA consistent with the SLI-4 interface spec. This memory region
  13263. * maps up to 64 rpi context regions.
  13264. *
  13265. * Return codes
  13266. * 0 - successful
  13267. * -ENOMEM - No available memory
  13268. * -EIO - The mailbox failed to complete successfully.
  13269. **/
  13270. int
  13271. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  13272. {
  13273. LPFC_MBOXQ_t *mboxq;
  13274. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  13275. uint32_t rc = 0;
  13276. uint32_t shdr_status, shdr_add_status;
  13277. union lpfc_sli4_cfg_shdr *shdr;
  13278. /* SLI4 ports that support extents do not require RPI headers. */
  13279. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13280. return rc;
  13281. if (phba->sli4_hba.extents_in_use)
  13282. return -EIO;
  13283. /* The port is notified of the header region via a mailbox command. */
  13284. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13285. if (!mboxq) {
  13286. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13287. "2001 Unable to allocate memory for issuing "
  13288. "SLI_CONFIG_SPECIAL mailbox command\n");
  13289. return -ENOMEM;
  13290. }
  13291. /* Post all rpi memory regions to the port. */
  13292. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  13293. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13294. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  13295. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  13296. sizeof(struct lpfc_sli4_cfg_mhdr),
  13297. LPFC_SLI4_MBX_EMBED);
  13298. /* Post the physical rpi to the port for this rpi header. */
  13299. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  13300. rpi_page->start_rpi);
  13301. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  13302. hdr_tmpl, rpi_page->page_count);
  13303. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  13304. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  13305. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  13306. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  13307. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13308. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13309. if (rc != MBX_TIMEOUT)
  13310. mempool_free(mboxq, phba->mbox_mem_pool);
  13311. if (shdr_status || shdr_add_status || rc) {
  13312. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13313. "2514 POST_RPI_HDR mailbox failed with "
  13314. "status x%x add_status x%x, mbx status x%x\n",
  13315. shdr_status, shdr_add_status, rc);
  13316. rc = -ENXIO;
  13317. }
  13318. return rc;
  13319. }
  13320. /**
  13321. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  13322. * @phba: pointer to lpfc hba data structure.
  13323. *
  13324. * This routine is invoked to post rpi header templates to the
  13325. * HBA consistent with the SLI-4 interface spec. This routine
  13326. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13327. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13328. *
  13329. * Returns
  13330. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13331. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13332. **/
  13333. int
  13334. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  13335. {
  13336. unsigned long rpi;
  13337. uint16_t max_rpi, rpi_limit;
  13338. uint16_t rpi_remaining, lrpi = 0;
  13339. struct lpfc_rpi_hdr *rpi_hdr;
  13340. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  13341. rpi_limit = phba->sli4_hba.next_rpi;
  13342. /*
  13343. * Fetch the next logical rpi. Because this index is logical,
  13344. * the driver starts at 0 each time.
  13345. */
  13346. spin_lock_irq(&phba->hbalock);
  13347. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  13348. if (rpi >= rpi_limit)
  13349. rpi = LPFC_RPI_ALLOC_ERROR;
  13350. else {
  13351. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  13352. phba->sli4_hba.max_cfg_param.rpi_used++;
  13353. phba->sli4_hba.rpi_count++;
  13354. }
  13355. /*
  13356. * Don't try to allocate more rpi header regions if the device limit
  13357. * has been exhausted.
  13358. */
  13359. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  13360. (phba->sli4_hba.rpi_count >= max_rpi)) {
  13361. spin_unlock_irq(&phba->hbalock);
  13362. return rpi;
  13363. }
  13364. /*
  13365. * RPI header postings are not required for SLI4 ports capable of
  13366. * extents.
  13367. */
  13368. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  13369. spin_unlock_irq(&phba->hbalock);
  13370. return rpi;
  13371. }
  13372. /*
  13373. * If the driver is running low on rpi resources, allocate another
  13374. * page now. Note that the next_rpi value is used because
  13375. * it represents how many are actually in use whereas max_rpi notes
  13376. * how many are supported max by the device.
  13377. */
  13378. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  13379. spin_unlock_irq(&phba->hbalock);
  13380. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  13381. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  13382. if (!rpi_hdr) {
  13383. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13384. "2002 Error Could not grow rpi "
  13385. "count\n");
  13386. } else {
  13387. lrpi = rpi_hdr->start_rpi;
  13388. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13389. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  13390. }
  13391. }
  13392. return rpi;
  13393. }
  13394. /**
  13395. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13396. * @phba: pointer to lpfc hba data structure.
  13397. *
  13398. * This routine is invoked to release an rpi to the pool of
  13399. * available rpis maintained by the driver.
  13400. **/
  13401. void
  13402. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13403. {
  13404. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  13405. phba->sli4_hba.rpi_count--;
  13406. phba->sli4_hba.max_cfg_param.rpi_used--;
  13407. }
  13408. }
  13409. /**
  13410. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13411. * @phba: pointer to lpfc hba data structure.
  13412. *
  13413. * This routine is invoked to release an rpi to the pool of
  13414. * available rpis maintained by the driver.
  13415. **/
  13416. void
  13417. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13418. {
  13419. spin_lock_irq(&phba->hbalock);
  13420. __lpfc_sli4_free_rpi(phba, rpi);
  13421. spin_unlock_irq(&phba->hbalock);
  13422. }
  13423. /**
  13424. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  13425. * @phba: pointer to lpfc hba data structure.
  13426. *
  13427. * This routine is invoked to remove the memory region that
  13428. * provided rpi via a bitmask.
  13429. **/
  13430. void
  13431. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  13432. {
  13433. kfree(phba->sli4_hba.rpi_bmask);
  13434. kfree(phba->sli4_hba.rpi_ids);
  13435. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  13436. }
  13437. /**
  13438. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  13439. * @phba: pointer to lpfc hba data structure.
  13440. *
  13441. * This routine is invoked to remove the memory region that
  13442. * provided rpi via a bitmask.
  13443. **/
  13444. int
  13445. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  13446. {
  13447. LPFC_MBOXQ_t *mboxq;
  13448. struct lpfc_hba *phba = ndlp->phba;
  13449. int rc;
  13450. /* The port is notified of the header region via a mailbox command. */
  13451. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13452. if (!mboxq)
  13453. return -ENOMEM;
  13454. /* Post all rpi memory regions to the port. */
  13455. lpfc_resume_rpi(mboxq, ndlp);
  13456. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13457. if (rc == MBX_NOT_FINISHED) {
  13458. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13459. "2010 Resume RPI Mailbox failed "
  13460. "status %d, mbxStatus x%x\n", rc,
  13461. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13462. mempool_free(mboxq, phba->mbox_mem_pool);
  13463. return -EIO;
  13464. }
  13465. return 0;
  13466. }
  13467. /**
  13468. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  13469. * @vport: Pointer to the vport for which the vpi is being initialized
  13470. *
  13471. * This routine is invoked to activate a vpi with the port.
  13472. *
  13473. * Returns:
  13474. * 0 success
  13475. * -Evalue otherwise
  13476. **/
  13477. int
  13478. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  13479. {
  13480. LPFC_MBOXQ_t *mboxq;
  13481. int rc = 0;
  13482. int retval = MBX_SUCCESS;
  13483. uint32_t mbox_tmo;
  13484. struct lpfc_hba *phba = vport->phba;
  13485. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13486. if (!mboxq)
  13487. return -ENOMEM;
  13488. lpfc_init_vpi(phba, mboxq, vport->vpi);
  13489. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  13490. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  13491. if (rc != MBX_SUCCESS) {
  13492. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  13493. "2022 INIT VPI Mailbox failed "
  13494. "status %d, mbxStatus x%x\n", rc,
  13495. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13496. retval = -EIO;
  13497. }
  13498. if (rc != MBX_TIMEOUT)
  13499. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  13500. return retval;
  13501. }
  13502. /**
  13503. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  13504. * @phba: pointer to lpfc hba data structure.
  13505. * @mboxq: Pointer to mailbox object.
  13506. *
  13507. * This routine is invoked to manually add a single FCF record. The caller
  13508. * must pass a completely initialized FCF_Record. This routine takes
  13509. * care of the nonembedded mailbox operations.
  13510. **/
  13511. static void
  13512. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  13513. {
  13514. void *virt_addr;
  13515. union lpfc_sli4_cfg_shdr *shdr;
  13516. uint32_t shdr_status, shdr_add_status;
  13517. virt_addr = mboxq->sge_array->addr[0];
  13518. /* The IOCTL status is embedded in the mailbox subheader. */
  13519. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  13520. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13521. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13522. if ((shdr_status || shdr_add_status) &&
  13523. (shdr_status != STATUS_FCF_IN_USE))
  13524. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13525. "2558 ADD_FCF_RECORD mailbox failed with "
  13526. "status x%x add_status x%x\n",
  13527. shdr_status, shdr_add_status);
  13528. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13529. }
  13530. /**
  13531. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  13532. * @phba: pointer to lpfc hba data structure.
  13533. * @fcf_record: pointer to the initialized fcf record to add.
  13534. *
  13535. * This routine is invoked to manually add a single FCF record. The caller
  13536. * must pass a completely initialized FCF_Record. This routine takes
  13537. * care of the nonembedded mailbox operations.
  13538. **/
  13539. int
  13540. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  13541. {
  13542. int rc = 0;
  13543. LPFC_MBOXQ_t *mboxq;
  13544. uint8_t *bytep;
  13545. void *virt_addr;
  13546. dma_addr_t phys_addr;
  13547. struct lpfc_mbx_sge sge;
  13548. uint32_t alloc_len, req_len;
  13549. uint32_t fcfindex;
  13550. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13551. if (!mboxq) {
  13552. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13553. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  13554. return -ENOMEM;
  13555. }
  13556. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  13557. sizeof(uint32_t);
  13558. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13559. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13560. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  13561. req_len, LPFC_SLI4_MBX_NEMBED);
  13562. if (alloc_len < req_len) {
  13563. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13564. "2523 Allocated DMA memory size (x%x) is "
  13565. "less than the requested DMA memory "
  13566. "size (x%x)\n", alloc_len, req_len);
  13567. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13568. return -ENOMEM;
  13569. }
  13570. /*
  13571. * Get the first SGE entry from the non-embedded DMA memory. This
  13572. * routine only uses a single SGE.
  13573. */
  13574. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  13575. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  13576. virt_addr = mboxq->sge_array->addr[0];
  13577. /*
  13578. * Configure the FCF record for FCFI 0. This is the driver's
  13579. * hardcoded default and gets used in nonFIP mode.
  13580. */
  13581. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  13582. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  13583. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  13584. /*
  13585. * Copy the fcf_index and the FCF Record Data. The data starts after
  13586. * the FCoE header plus word10. The data copy needs to be endian
  13587. * correct.
  13588. */
  13589. bytep += sizeof(uint32_t);
  13590. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  13591. mboxq->vport = phba->pport;
  13592. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  13593. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13594. if (rc == MBX_NOT_FINISHED) {
  13595. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13596. "2515 ADD_FCF_RECORD mailbox failed with "
  13597. "status 0x%x\n", rc);
  13598. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13599. rc = -EIO;
  13600. } else
  13601. rc = 0;
  13602. return rc;
  13603. }
  13604. /**
  13605. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  13606. * @phba: pointer to lpfc hba data structure.
  13607. * @fcf_record: pointer to the fcf record to write the default data.
  13608. * @fcf_index: FCF table entry index.
  13609. *
  13610. * This routine is invoked to build the driver's default FCF record. The
  13611. * values used are hardcoded. This routine handles memory initialization.
  13612. *
  13613. **/
  13614. void
  13615. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  13616. struct fcf_record *fcf_record,
  13617. uint16_t fcf_index)
  13618. {
  13619. memset(fcf_record, 0, sizeof(struct fcf_record));
  13620. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  13621. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  13622. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  13623. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  13624. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  13625. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  13626. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  13627. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  13628. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  13629. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  13630. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  13631. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  13632. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  13633. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  13634. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  13635. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  13636. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  13637. /* Set the VLAN bit map */
  13638. if (phba->valid_vlan) {
  13639. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  13640. = 1 << (phba->vlan_id % 8);
  13641. }
  13642. }
  13643. /**
  13644. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  13645. * @phba: pointer to lpfc hba data structure.
  13646. * @fcf_index: FCF table entry offset.
  13647. *
  13648. * This routine is invoked to scan the entire FCF table by reading FCF
  13649. * record and processing it one at a time starting from the @fcf_index
  13650. * for initial FCF discovery or fast FCF failover rediscovery.
  13651. *
  13652. * Return 0 if the mailbox command is submitted successfully, none 0
  13653. * otherwise.
  13654. **/
  13655. int
  13656. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13657. {
  13658. int rc = 0, error;
  13659. LPFC_MBOXQ_t *mboxq;
  13660. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  13661. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13662. if (!mboxq) {
  13663. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13664. "2000 Failed to allocate mbox for "
  13665. "READ_FCF cmd\n");
  13666. error = -ENOMEM;
  13667. goto fail_fcf_scan;
  13668. }
  13669. /* Construct the read FCF record mailbox command */
  13670. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13671. if (rc) {
  13672. error = -EINVAL;
  13673. goto fail_fcf_scan;
  13674. }
  13675. /* Issue the mailbox command asynchronously */
  13676. mboxq->vport = phba->pport;
  13677. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  13678. spin_lock_irq(&phba->hbalock);
  13679. phba->hba_flag |= FCF_TS_INPROG;
  13680. spin_unlock_irq(&phba->hbalock);
  13681. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13682. if (rc == MBX_NOT_FINISHED)
  13683. error = -EIO;
  13684. else {
  13685. /* Reset eligible FCF count for new scan */
  13686. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  13687. phba->fcf.eligible_fcf_cnt = 0;
  13688. error = 0;
  13689. }
  13690. fail_fcf_scan:
  13691. if (error) {
  13692. if (mboxq)
  13693. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13694. /* FCF scan failed, clear FCF_TS_INPROG flag */
  13695. spin_lock_irq(&phba->hbalock);
  13696. phba->hba_flag &= ~FCF_TS_INPROG;
  13697. spin_unlock_irq(&phba->hbalock);
  13698. }
  13699. return error;
  13700. }
  13701. /**
  13702. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  13703. * @phba: pointer to lpfc hba data structure.
  13704. * @fcf_index: FCF table entry offset.
  13705. *
  13706. * This routine is invoked to read an FCF record indicated by @fcf_index
  13707. * and to use it for FLOGI roundrobin FCF failover.
  13708. *
  13709. * Return 0 if the mailbox command is submitted successfully, none 0
  13710. * otherwise.
  13711. **/
  13712. int
  13713. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13714. {
  13715. int rc = 0, error;
  13716. LPFC_MBOXQ_t *mboxq;
  13717. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13718. if (!mboxq) {
  13719. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13720. "2763 Failed to allocate mbox for "
  13721. "READ_FCF cmd\n");
  13722. error = -ENOMEM;
  13723. goto fail_fcf_read;
  13724. }
  13725. /* Construct the read FCF record mailbox command */
  13726. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13727. if (rc) {
  13728. error = -EINVAL;
  13729. goto fail_fcf_read;
  13730. }
  13731. /* Issue the mailbox command asynchronously */
  13732. mboxq->vport = phba->pport;
  13733. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  13734. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13735. if (rc == MBX_NOT_FINISHED)
  13736. error = -EIO;
  13737. else
  13738. error = 0;
  13739. fail_fcf_read:
  13740. if (error && mboxq)
  13741. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13742. return error;
  13743. }
  13744. /**
  13745. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  13746. * @phba: pointer to lpfc hba data structure.
  13747. * @fcf_index: FCF table entry offset.
  13748. *
  13749. * This routine is invoked to read an FCF record indicated by @fcf_index to
  13750. * determine whether it's eligible for FLOGI roundrobin failover list.
  13751. *
  13752. * Return 0 if the mailbox command is submitted successfully, none 0
  13753. * otherwise.
  13754. **/
  13755. int
  13756. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13757. {
  13758. int rc = 0, error;
  13759. LPFC_MBOXQ_t *mboxq;
  13760. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13761. if (!mboxq) {
  13762. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13763. "2758 Failed to allocate mbox for "
  13764. "READ_FCF cmd\n");
  13765. error = -ENOMEM;
  13766. goto fail_fcf_read;
  13767. }
  13768. /* Construct the read FCF record mailbox command */
  13769. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13770. if (rc) {
  13771. error = -EINVAL;
  13772. goto fail_fcf_read;
  13773. }
  13774. /* Issue the mailbox command asynchronously */
  13775. mboxq->vport = phba->pport;
  13776. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  13777. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13778. if (rc == MBX_NOT_FINISHED)
  13779. error = -EIO;
  13780. else
  13781. error = 0;
  13782. fail_fcf_read:
  13783. if (error && mboxq)
  13784. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13785. return error;
  13786. }
  13787. /**
  13788. * lpfc_check_next_fcf_pri
  13789. * phba pointer to the lpfc_hba struct for this port.
  13790. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  13791. * routine when the rr_bmask is empty. The FCF indecies are put into the
  13792. * rr_bmask based on their priority level. Starting from the highest priority
  13793. * to the lowest. The most likely FCF candidate will be in the highest
  13794. * priority group. When this routine is called it searches the fcf_pri list for
  13795. * next lowest priority group and repopulates the rr_bmask with only those
  13796. * fcf_indexes.
  13797. * returns:
  13798. * 1=success 0=failure
  13799. **/
  13800. int
  13801. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  13802. {
  13803. uint16_t next_fcf_pri;
  13804. uint16_t last_index;
  13805. struct lpfc_fcf_pri *fcf_pri;
  13806. int rc;
  13807. int ret = 0;
  13808. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  13809. LPFC_SLI4_FCF_TBL_INDX_MAX);
  13810. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13811. "3060 Last IDX %d\n", last_index);
  13812. if (list_empty(&phba->fcf.fcf_pri_list)) {
  13813. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13814. "3061 Last IDX %d\n", last_index);
  13815. return 0; /* Empty rr list */
  13816. }
  13817. next_fcf_pri = 0;
  13818. /*
  13819. * Clear the rr_bmask and set all of the bits that are at this
  13820. * priority.
  13821. */
  13822. memset(phba->fcf.fcf_rr_bmask, 0,
  13823. sizeof(*phba->fcf.fcf_rr_bmask));
  13824. spin_lock_irq(&phba->hbalock);
  13825. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13826. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  13827. continue;
  13828. /*
  13829. * the 1st priority that has not FLOGI failed
  13830. * will be the highest.
  13831. */
  13832. if (!next_fcf_pri)
  13833. next_fcf_pri = fcf_pri->fcf_rec.priority;
  13834. spin_unlock_irq(&phba->hbalock);
  13835. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  13836. rc = lpfc_sli4_fcf_rr_index_set(phba,
  13837. fcf_pri->fcf_rec.fcf_index);
  13838. if (rc)
  13839. return 0;
  13840. }
  13841. spin_lock_irq(&phba->hbalock);
  13842. }
  13843. /*
  13844. * if next_fcf_pri was not set above and the list is not empty then
  13845. * we have failed flogis on all of them. So reset flogi failed
  13846. * and start at the begining.
  13847. */
  13848. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  13849. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13850. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  13851. /*
  13852. * the 1st priority that has not FLOGI failed
  13853. * will be the highest.
  13854. */
  13855. if (!next_fcf_pri)
  13856. next_fcf_pri = fcf_pri->fcf_rec.priority;
  13857. spin_unlock_irq(&phba->hbalock);
  13858. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  13859. rc = lpfc_sli4_fcf_rr_index_set(phba,
  13860. fcf_pri->fcf_rec.fcf_index);
  13861. if (rc)
  13862. return 0;
  13863. }
  13864. spin_lock_irq(&phba->hbalock);
  13865. }
  13866. } else
  13867. ret = 1;
  13868. spin_unlock_irq(&phba->hbalock);
  13869. return ret;
  13870. }
  13871. /**
  13872. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  13873. * @phba: pointer to lpfc hba data structure.
  13874. *
  13875. * This routine is to get the next eligible FCF record index in a round
  13876. * robin fashion. If the next eligible FCF record index equals to the
  13877. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  13878. * shall be returned, otherwise, the next eligible FCF record's index
  13879. * shall be returned.
  13880. **/
  13881. uint16_t
  13882. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  13883. {
  13884. uint16_t next_fcf_index;
  13885. /* Search start from next bit of currently registered FCF index */
  13886. next_priority:
  13887. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  13888. LPFC_SLI4_FCF_TBL_INDX_MAX;
  13889. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  13890. LPFC_SLI4_FCF_TBL_INDX_MAX,
  13891. next_fcf_index);
  13892. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  13893. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  13894. /*
  13895. * If we have wrapped then we need to clear the bits that
  13896. * have been tested so that we can detect when we should
  13897. * change the priority level.
  13898. */
  13899. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  13900. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  13901. }
  13902. /* Check roundrobin failover list empty condition */
  13903. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  13904. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  13905. /*
  13906. * If next fcf index is not found check if there are lower
  13907. * Priority level fcf's in the fcf_priority list.
  13908. * Set up the rr_bmask with all of the avaiable fcf bits
  13909. * at that level and continue the selection process.
  13910. */
  13911. if (lpfc_check_next_fcf_pri_level(phba))
  13912. goto next_priority;
  13913. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  13914. "2844 No roundrobin failover FCF available\n");
  13915. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  13916. return LPFC_FCOE_FCF_NEXT_NONE;
  13917. else {
  13918. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  13919. "3063 Only FCF available idx %d, flag %x\n",
  13920. next_fcf_index,
  13921. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  13922. return next_fcf_index;
  13923. }
  13924. }
  13925. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  13926. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  13927. LPFC_FCF_FLOGI_FAILED)
  13928. goto next_priority;
  13929. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13930. "2845 Get next roundrobin failover FCF (x%x)\n",
  13931. next_fcf_index);
  13932. return next_fcf_index;
  13933. }
  13934. /**
  13935. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  13936. * @phba: pointer to lpfc hba data structure.
  13937. *
  13938. * This routine sets the FCF record index in to the eligible bmask for
  13939. * roundrobin failover search. It checks to make sure that the index
  13940. * does not go beyond the range of the driver allocated bmask dimension
  13941. * before setting the bit.
  13942. *
  13943. * Returns 0 if the index bit successfully set, otherwise, it returns
  13944. * -EINVAL.
  13945. **/
  13946. int
  13947. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  13948. {
  13949. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  13950. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13951. "2610 FCF (x%x) reached driver's book "
  13952. "keeping dimension:x%x\n",
  13953. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  13954. return -EINVAL;
  13955. }
  13956. /* Set the eligible FCF record index bmask */
  13957. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  13958. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13959. "2790 Set FCF (x%x) to roundrobin FCF failover "
  13960. "bmask\n", fcf_index);
  13961. return 0;
  13962. }
  13963. /**
  13964. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  13965. * @phba: pointer to lpfc hba data structure.
  13966. *
  13967. * This routine clears the FCF record index from the eligible bmask for
  13968. * roundrobin failover search. It checks to make sure that the index
  13969. * does not go beyond the range of the driver allocated bmask dimension
  13970. * before clearing the bit.
  13971. **/
  13972. void
  13973. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  13974. {
  13975. struct lpfc_fcf_pri *fcf_pri;
  13976. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  13977. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13978. "2762 FCF (x%x) reached driver's book "
  13979. "keeping dimension:x%x\n",
  13980. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  13981. return;
  13982. }
  13983. /* Clear the eligible FCF record index bmask */
  13984. spin_lock_irq(&phba->hbalock);
  13985. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13986. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  13987. list_del_init(&fcf_pri->list);
  13988. break;
  13989. }
  13990. }
  13991. spin_unlock_irq(&phba->hbalock);
  13992. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  13993. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13994. "2791 Clear FCF (x%x) from roundrobin failover "
  13995. "bmask\n", fcf_index);
  13996. }
  13997. /**
  13998. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  13999. * @phba: pointer to lpfc hba data structure.
  14000. *
  14001. * This routine is the completion routine for the rediscover FCF table mailbox
  14002. * command. If the mailbox command returned failure, it will try to stop the
  14003. * FCF rediscover wait timer.
  14004. **/
  14005. void
  14006. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  14007. {
  14008. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14009. uint32_t shdr_status, shdr_add_status;
  14010. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14011. shdr_status = bf_get(lpfc_mbox_hdr_status,
  14012. &redisc_fcf->header.cfg_shdr.response);
  14013. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  14014. &redisc_fcf->header.cfg_shdr.response);
  14015. if (shdr_status || shdr_add_status) {
  14016. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14017. "2746 Requesting for FCF rediscovery failed "
  14018. "status x%x add_status x%x\n",
  14019. shdr_status, shdr_add_status);
  14020. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  14021. spin_lock_irq(&phba->hbalock);
  14022. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  14023. spin_unlock_irq(&phba->hbalock);
  14024. /*
  14025. * CVL event triggered FCF rediscover request failed,
  14026. * last resort to re-try current registered FCF entry.
  14027. */
  14028. lpfc_retry_pport_discovery(phba);
  14029. } else {
  14030. spin_lock_irq(&phba->hbalock);
  14031. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  14032. spin_unlock_irq(&phba->hbalock);
  14033. /*
  14034. * DEAD FCF event triggered FCF rediscover request
  14035. * failed, last resort to fail over as a link down
  14036. * to FCF registration.
  14037. */
  14038. lpfc_sli4_fcf_dead_failthrough(phba);
  14039. }
  14040. } else {
  14041. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14042. "2775 Start FCF rediscover quiescent timer\n");
  14043. /*
  14044. * Start FCF rediscovery wait timer for pending FCF
  14045. * before rescan FCF record table.
  14046. */
  14047. lpfc_fcf_redisc_wait_start_timer(phba);
  14048. }
  14049. mempool_free(mbox, phba->mbox_mem_pool);
  14050. }
  14051. /**
  14052. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  14053. * @phba: pointer to lpfc hba data structure.
  14054. *
  14055. * This routine is invoked to request for rediscovery of the entire FCF table
  14056. * by the port.
  14057. **/
  14058. int
  14059. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  14060. {
  14061. LPFC_MBOXQ_t *mbox;
  14062. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14063. int rc, length;
  14064. /* Cancel retry delay timers to all vports before FCF rediscover */
  14065. lpfc_cancel_all_vport_retry_delay_timer(phba);
  14066. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14067. if (!mbox) {
  14068. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14069. "2745 Failed to allocate mbox for "
  14070. "requesting FCF rediscover.\n");
  14071. return -ENOMEM;
  14072. }
  14073. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  14074. sizeof(struct lpfc_sli4_cfg_mhdr));
  14075. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  14076. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  14077. length, LPFC_SLI4_MBX_EMBED);
  14078. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14079. /* Set count to 0 for invalidating the entire FCF database */
  14080. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  14081. /* Issue the mailbox command asynchronously */
  14082. mbox->vport = phba->pport;
  14083. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  14084. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  14085. if (rc == MBX_NOT_FINISHED) {
  14086. mempool_free(mbox, phba->mbox_mem_pool);
  14087. return -EIO;
  14088. }
  14089. return 0;
  14090. }
  14091. /**
  14092. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  14093. * @phba: pointer to lpfc hba data structure.
  14094. *
  14095. * This function is the failover routine as a last resort to the FCF DEAD
  14096. * event when driver failed to perform fast FCF failover.
  14097. **/
  14098. void
  14099. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  14100. {
  14101. uint32_t link_state;
  14102. /*
  14103. * Last resort as FCF DEAD event failover will treat this as
  14104. * a link down, but save the link state because we don't want
  14105. * it to be changed to Link Down unless it is already down.
  14106. */
  14107. link_state = phba->link_state;
  14108. lpfc_linkdown(phba);
  14109. phba->link_state = link_state;
  14110. /* Unregister FCF if no devices connected to it */
  14111. lpfc_unregister_unused_fcf(phba);
  14112. }
  14113. /**
  14114. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  14115. * @phba: pointer to lpfc hba data structure.
  14116. * @rgn23_data: pointer to configure region 23 data.
  14117. *
  14118. * This function gets SLI3 port configure region 23 data through memory dump
  14119. * mailbox command. When it successfully retrieves data, the size of the data
  14120. * will be returned, otherwise, 0 will be returned.
  14121. **/
  14122. static uint32_t
  14123. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14124. {
  14125. LPFC_MBOXQ_t *pmb = NULL;
  14126. MAILBOX_t *mb;
  14127. uint32_t offset = 0;
  14128. int rc;
  14129. if (!rgn23_data)
  14130. return 0;
  14131. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14132. if (!pmb) {
  14133. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14134. "2600 failed to allocate mailbox memory\n");
  14135. return 0;
  14136. }
  14137. mb = &pmb->u.mb;
  14138. do {
  14139. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  14140. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  14141. if (rc != MBX_SUCCESS) {
  14142. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  14143. "2601 failed to read config "
  14144. "region 23, rc 0x%x Status 0x%x\n",
  14145. rc, mb->mbxStatus);
  14146. mb->un.varDmp.word_cnt = 0;
  14147. }
  14148. /*
  14149. * dump mem may return a zero when finished or we got a
  14150. * mailbox error, either way we are done.
  14151. */
  14152. if (mb->un.varDmp.word_cnt == 0)
  14153. break;
  14154. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  14155. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  14156. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  14157. rgn23_data + offset,
  14158. mb->un.varDmp.word_cnt);
  14159. offset += mb->un.varDmp.word_cnt;
  14160. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  14161. mempool_free(pmb, phba->mbox_mem_pool);
  14162. return offset;
  14163. }
  14164. /**
  14165. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  14166. * @phba: pointer to lpfc hba data structure.
  14167. * @rgn23_data: pointer to configure region 23 data.
  14168. *
  14169. * This function gets SLI4 port configure region 23 data through memory dump
  14170. * mailbox command. When it successfully retrieves data, the size of the data
  14171. * will be returned, otherwise, 0 will be returned.
  14172. **/
  14173. static uint32_t
  14174. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14175. {
  14176. LPFC_MBOXQ_t *mboxq = NULL;
  14177. struct lpfc_dmabuf *mp = NULL;
  14178. struct lpfc_mqe *mqe;
  14179. uint32_t data_length = 0;
  14180. int rc;
  14181. if (!rgn23_data)
  14182. return 0;
  14183. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14184. if (!mboxq) {
  14185. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14186. "3105 failed to allocate mailbox memory\n");
  14187. return 0;
  14188. }
  14189. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  14190. goto out;
  14191. mqe = &mboxq->u.mqe;
  14192. mp = (struct lpfc_dmabuf *) mboxq->context1;
  14193. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14194. if (rc)
  14195. goto out;
  14196. data_length = mqe->un.mb_words[5];
  14197. if (data_length == 0)
  14198. goto out;
  14199. if (data_length > DMP_RGN23_SIZE) {
  14200. data_length = 0;
  14201. goto out;
  14202. }
  14203. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  14204. out:
  14205. mempool_free(mboxq, phba->mbox_mem_pool);
  14206. if (mp) {
  14207. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14208. kfree(mp);
  14209. }
  14210. return data_length;
  14211. }
  14212. /**
  14213. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  14214. * @phba: pointer to lpfc hba data structure.
  14215. *
  14216. * This function read region 23 and parse TLV for port status to
  14217. * decide if the user disaled the port. If the TLV indicates the
  14218. * port is disabled, the hba_flag is set accordingly.
  14219. **/
  14220. void
  14221. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  14222. {
  14223. uint8_t *rgn23_data = NULL;
  14224. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  14225. uint32_t offset = 0;
  14226. /* Get adapter Region 23 data */
  14227. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  14228. if (!rgn23_data)
  14229. goto out;
  14230. if (phba->sli_rev < LPFC_SLI_REV4)
  14231. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  14232. else {
  14233. if_type = bf_get(lpfc_sli_intf_if_type,
  14234. &phba->sli4_hba.sli_intf);
  14235. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  14236. goto out;
  14237. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  14238. }
  14239. if (!data_size)
  14240. goto out;
  14241. /* Check the region signature first */
  14242. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  14243. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14244. "2619 Config region 23 has bad signature\n");
  14245. goto out;
  14246. }
  14247. offset += 4;
  14248. /* Check the data structure version */
  14249. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  14250. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14251. "2620 Config region 23 has bad version\n");
  14252. goto out;
  14253. }
  14254. offset += 4;
  14255. /* Parse TLV entries in the region */
  14256. while (offset < data_size) {
  14257. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  14258. break;
  14259. /*
  14260. * If the TLV is not driver specific TLV or driver id is
  14261. * not linux driver id, skip the record.
  14262. */
  14263. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  14264. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  14265. (rgn23_data[offset + 3] != 0)) {
  14266. offset += rgn23_data[offset + 1] * 4 + 4;
  14267. continue;
  14268. }
  14269. /* Driver found a driver specific TLV in the config region */
  14270. sub_tlv_len = rgn23_data[offset + 1] * 4;
  14271. offset += 4;
  14272. tlv_offset = 0;
  14273. /*
  14274. * Search for configured port state sub-TLV.
  14275. */
  14276. while ((offset < data_size) &&
  14277. (tlv_offset < sub_tlv_len)) {
  14278. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  14279. offset += 4;
  14280. tlv_offset += 4;
  14281. break;
  14282. }
  14283. if (rgn23_data[offset] != PORT_STE_TYPE) {
  14284. offset += rgn23_data[offset + 1] * 4 + 4;
  14285. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  14286. continue;
  14287. }
  14288. /* This HBA contains PORT_STE configured */
  14289. if (!rgn23_data[offset + 2])
  14290. phba->hba_flag |= LINK_DISABLED;
  14291. goto out;
  14292. }
  14293. }
  14294. out:
  14295. kfree(rgn23_data);
  14296. return;
  14297. }
  14298. /**
  14299. * lpfc_wr_object - write an object to the firmware
  14300. * @phba: HBA structure that indicates port to create a queue on.
  14301. * @dmabuf_list: list of dmabufs to write to the port.
  14302. * @size: the total byte value of the objects to write to the port.
  14303. * @offset: the current offset to be used to start the transfer.
  14304. *
  14305. * This routine will create a wr_object mailbox command to send to the port.
  14306. * the mailbox command will be constructed using the dma buffers described in
  14307. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  14308. * BDEs that the imbedded mailbox can support. The @offset variable will be
  14309. * used to indicate the starting offset of the transfer and will also return
  14310. * the offset after the write object mailbox has completed. @size is used to
  14311. * determine the end of the object and whether the eof bit should be set.
  14312. *
  14313. * Return 0 is successful and offset will contain the the new offset to use
  14314. * for the next write.
  14315. * Return negative value for error cases.
  14316. **/
  14317. int
  14318. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  14319. uint32_t size, uint32_t *offset)
  14320. {
  14321. struct lpfc_mbx_wr_object *wr_object;
  14322. LPFC_MBOXQ_t *mbox;
  14323. int rc = 0, i = 0;
  14324. uint32_t shdr_status, shdr_add_status;
  14325. uint32_t mbox_tmo;
  14326. union lpfc_sli4_cfg_shdr *shdr;
  14327. struct lpfc_dmabuf *dmabuf;
  14328. uint32_t written = 0;
  14329. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14330. if (!mbox)
  14331. return -ENOMEM;
  14332. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14333. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  14334. sizeof(struct lpfc_mbx_wr_object) -
  14335. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  14336. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  14337. wr_object->u.request.write_offset = *offset;
  14338. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  14339. wr_object->u.request.object_name[0] =
  14340. cpu_to_le32(wr_object->u.request.object_name[0]);
  14341. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  14342. list_for_each_entry(dmabuf, dmabuf_list, list) {
  14343. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  14344. break;
  14345. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  14346. wr_object->u.request.bde[i].addrHigh =
  14347. putPaddrHigh(dmabuf->phys);
  14348. if (written + SLI4_PAGE_SIZE >= size) {
  14349. wr_object->u.request.bde[i].tus.f.bdeSize =
  14350. (size - written);
  14351. written += (size - written);
  14352. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  14353. } else {
  14354. wr_object->u.request.bde[i].tus.f.bdeSize =
  14355. SLI4_PAGE_SIZE;
  14356. written += SLI4_PAGE_SIZE;
  14357. }
  14358. i++;
  14359. }
  14360. wr_object->u.request.bde_count = i;
  14361. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  14362. if (!phba->sli4_hba.intr_enable)
  14363. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14364. else {
  14365. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  14366. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  14367. }
  14368. /* The IOCTL status is embedded in the mailbox subheader. */
  14369. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  14370. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14371. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14372. if (rc != MBX_TIMEOUT)
  14373. mempool_free(mbox, phba->mbox_mem_pool);
  14374. if (shdr_status || shdr_add_status || rc) {
  14375. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14376. "3025 Write Object mailbox failed with "
  14377. "status x%x add_status x%x, mbx status x%x\n",
  14378. shdr_status, shdr_add_status, rc);
  14379. rc = -ENXIO;
  14380. } else
  14381. *offset += wr_object->u.response.actual_write_length;
  14382. return rc;
  14383. }
  14384. /**
  14385. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  14386. * @vport: pointer to vport data structure.
  14387. *
  14388. * This function iterate through the mailboxq and clean up all REG_LOGIN
  14389. * and REG_VPI mailbox commands associated with the vport. This function
  14390. * is called when driver want to restart discovery of the vport due to
  14391. * a Clear Virtual Link event.
  14392. **/
  14393. void
  14394. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  14395. {
  14396. struct lpfc_hba *phba = vport->phba;
  14397. LPFC_MBOXQ_t *mb, *nextmb;
  14398. struct lpfc_dmabuf *mp;
  14399. struct lpfc_nodelist *ndlp;
  14400. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  14401. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  14402. LIST_HEAD(mbox_cmd_list);
  14403. uint8_t restart_loop;
  14404. /* Clean up internally queued mailbox commands with the vport */
  14405. spin_lock_irq(&phba->hbalock);
  14406. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  14407. if (mb->vport != vport)
  14408. continue;
  14409. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14410. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14411. continue;
  14412. list_del(&mb->list);
  14413. list_add_tail(&mb->list, &mbox_cmd_list);
  14414. }
  14415. /* Clean up active mailbox command with the vport */
  14416. mb = phba->sli.mbox_active;
  14417. if (mb && (mb->vport == vport)) {
  14418. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  14419. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  14420. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14421. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14422. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  14423. /* Put reference count for delayed processing */
  14424. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  14425. /* Unregister the RPI when mailbox complete */
  14426. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14427. }
  14428. }
  14429. /* Cleanup any mailbox completions which are not yet processed */
  14430. do {
  14431. restart_loop = 0;
  14432. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  14433. /*
  14434. * If this mailox is already processed or it is
  14435. * for another vport ignore it.
  14436. */
  14437. if ((mb->vport != vport) ||
  14438. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  14439. continue;
  14440. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14441. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14442. continue;
  14443. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14444. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14445. ndlp = (struct lpfc_nodelist *)mb->context2;
  14446. /* Unregister the RPI when mailbox complete */
  14447. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14448. restart_loop = 1;
  14449. spin_unlock_irq(&phba->hbalock);
  14450. spin_lock(shost->host_lock);
  14451. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14452. spin_unlock(shost->host_lock);
  14453. spin_lock_irq(&phba->hbalock);
  14454. break;
  14455. }
  14456. }
  14457. } while (restart_loop);
  14458. spin_unlock_irq(&phba->hbalock);
  14459. /* Release the cleaned-up mailbox commands */
  14460. while (!list_empty(&mbox_cmd_list)) {
  14461. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  14462. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14463. mp = (struct lpfc_dmabuf *) (mb->context1);
  14464. if (mp) {
  14465. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14466. kfree(mp);
  14467. }
  14468. ndlp = (struct lpfc_nodelist *) mb->context2;
  14469. mb->context2 = NULL;
  14470. if (ndlp) {
  14471. spin_lock(shost->host_lock);
  14472. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14473. spin_unlock(shost->host_lock);
  14474. lpfc_nlp_put(ndlp);
  14475. }
  14476. }
  14477. mempool_free(mb, phba->mbox_mem_pool);
  14478. }
  14479. /* Release the ndlp with the cleaned-up active mailbox command */
  14480. if (act_mbx_ndlp) {
  14481. spin_lock(shost->host_lock);
  14482. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14483. spin_unlock(shost->host_lock);
  14484. lpfc_nlp_put(act_mbx_ndlp);
  14485. }
  14486. }
  14487. /**
  14488. * lpfc_drain_txq - Drain the txq
  14489. * @phba: Pointer to HBA context object.
  14490. *
  14491. * This function attempt to submit IOCBs on the txq
  14492. * to the adapter. For SLI4 adapters, the txq contains
  14493. * ELS IOCBs that have been deferred because the there
  14494. * are no SGLs. This congestion can occur with large
  14495. * vport counts during node discovery.
  14496. **/
  14497. uint32_t
  14498. lpfc_drain_txq(struct lpfc_hba *phba)
  14499. {
  14500. LIST_HEAD(completions);
  14501. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  14502. struct lpfc_iocbq *piocbq = 0;
  14503. unsigned long iflags = 0;
  14504. char *fail_msg = NULL;
  14505. struct lpfc_sglq *sglq;
  14506. union lpfc_wqe wqe;
  14507. spin_lock_irqsave(&phba->hbalock, iflags);
  14508. if (pring->txq_cnt > pring->txq_max)
  14509. pring->txq_max = pring->txq_cnt;
  14510. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14511. while (pring->txq_cnt) {
  14512. spin_lock_irqsave(&phba->hbalock, iflags);
  14513. piocbq = lpfc_sli_ringtx_get(phba, pring);
  14514. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  14515. if (!sglq) {
  14516. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  14517. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14518. break;
  14519. } else {
  14520. if (!piocbq) {
  14521. /* The txq_cnt out of sync. This should
  14522. * never happen
  14523. */
  14524. sglq = __lpfc_clear_active_sglq(phba,
  14525. sglq->sli4_lxritag);
  14526. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14527. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14528. "2823 txq empty and txq_cnt is %d\n ",
  14529. pring->txq_cnt);
  14530. break;
  14531. }
  14532. }
  14533. /* The xri and iocb resources secured,
  14534. * attempt to issue request
  14535. */
  14536. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  14537. piocbq->sli4_xritag = sglq->sli4_xritag;
  14538. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  14539. fail_msg = "to convert bpl to sgl";
  14540. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  14541. fail_msg = "to convert iocb to wqe";
  14542. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  14543. fail_msg = " - Wq is full";
  14544. else
  14545. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  14546. if (fail_msg) {
  14547. /* Failed means we can't issue and need to cancel */
  14548. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14549. "2822 IOCB failed %s iotag 0x%x "
  14550. "xri 0x%x\n",
  14551. fail_msg,
  14552. piocbq->iotag, piocbq->sli4_xritag);
  14553. list_add_tail(&piocbq->list, &completions);
  14554. }
  14555. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14556. }
  14557. /* Cancel all the IOCBs that cannot be issued */
  14558. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  14559. IOERR_SLI_ABORTED);
  14560. return pring->txq_cnt;
  14561. }