lpfc_sli.c 500 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2012 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *,
  63. struct lpfc_cqe *);
  64. static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *,
  65. int);
  66. static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *,
  67. uint32_t);
  68. static IOCB_t *
  69. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  70. {
  71. return &iocbq->iocb;
  72. }
  73. /**
  74. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  75. * @q: The Work Queue to operate on.
  76. * @wqe: The work Queue Entry to put on the Work queue.
  77. *
  78. * This routine will copy the contents of @wqe to the next available entry on
  79. * the @q. This function will then ring the Work Queue Doorbell to signal the
  80. * HBA to start processing the Work Queue Entry. This function returns 0 if
  81. * successful. If no entries are available on @q then this function will return
  82. * -ENOMEM.
  83. * The caller is expected to hold the hbalock when calling this routine.
  84. **/
  85. static uint32_t
  86. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  87. {
  88. union lpfc_wqe *temp_wqe;
  89. struct lpfc_register doorbell;
  90. uint32_t host_index;
  91. uint32_t idx;
  92. /* sanity check on queue memory */
  93. if (unlikely(!q))
  94. return -ENOMEM;
  95. temp_wqe = q->qe[q->host_index].wqe;
  96. /* If the host has not yet processed the next entry then we are done */
  97. idx = ((q->host_index + 1) % q->entry_count);
  98. if (idx == q->hba_index) {
  99. q->WQ_overflow++;
  100. return -ENOMEM;
  101. }
  102. q->WQ_posted++;
  103. /* set consumption flag every once in a while */
  104. if (!((q->host_index + 1) % q->entry_repost))
  105. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  106. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  107. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  108. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  109. /* Update the host index before invoking device */
  110. host_index = q->host_index;
  111. q->host_index = idx;
  112. /* Ring Doorbell */
  113. doorbell.word0 = 0;
  114. if (q->db_format == LPFC_DB_LIST_FORMAT) {
  115. bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
  116. bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index);
  117. bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
  118. } else if (q->db_format == LPFC_DB_RING_FORMAT) {
  119. bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
  120. bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
  121. } else {
  122. return -EINVAL;
  123. }
  124. writel(doorbell.word0, q->db_regaddr);
  125. return 0;
  126. }
  127. /**
  128. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  129. * @q: The Work Queue to operate on.
  130. * @index: The index to advance the hba index to.
  131. *
  132. * This routine will update the HBA index of a queue to reflect consumption of
  133. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  134. * an entry the host calls this function to update the queue's internal
  135. * pointers. This routine returns the number of entries that were consumed by
  136. * the HBA.
  137. **/
  138. static uint32_t
  139. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  140. {
  141. uint32_t released = 0;
  142. /* sanity check on queue memory */
  143. if (unlikely(!q))
  144. return 0;
  145. if (q->hba_index == index)
  146. return 0;
  147. do {
  148. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  149. released++;
  150. } while (q->hba_index != index);
  151. return released;
  152. }
  153. /**
  154. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  155. * @q: The Mailbox Queue to operate on.
  156. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  157. *
  158. * This routine will copy the contents of @mqe to the next available entry on
  159. * the @q. This function will then ring the Work Queue Doorbell to signal the
  160. * HBA to start processing the Work Queue Entry. This function returns 0 if
  161. * successful. If no entries are available on @q then this function will return
  162. * -ENOMEM.
  163. * The caller is expected to hold the hbalock when calling this routine.
  164. **/
  165. static uint32_t
  166. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  167. {
  168. struct lpfc_mqe *temp_mqe;
  169. struct lpfc_register doorbell;
  170. uint32_t host_index;
  171. /* sanity check on queue memory */
  172. if (unlikely(!q))
  173. return -ENOMEM;
  174. temp_mqe = q->qe[q->host_index].mqe;
  175. /* If the host has not yet processed the next entry then we are done */
  176. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  177. return -ENOMEM;
  178. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  179. /* Save off the mailbox pointer for completion */
  180. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  181. /* Update the host index before invoking device */
  182. host_index = q->host_index;
  183. q->host_index = ((q->host_index + 1) % q->entry_count);
  184. /* Ring Doorbell */
  185. doorbell.word0 = 0;
  186. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  187. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  188. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  189. return 0;
  190. }
  191. /**
  192. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  193. * @q: The Mailbox Queue to operate on.
  194. *
  195. * This routine will update the HBA index of a queue to reflect consumption of
  196. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  197. * an entry the host calls this function to update the queue's internal
  198. * pointers. This routine returns the number of entries that were consumed by
  199. * the HBA.
  200. **/
  201. static uint32_t
  202. lpfc_sli4_mq_release(struct lpfc_queue *q)
  203. {
  204. /* sanity check on queue memory */
  205. if (unlikely(!q))
  206. return 0;
  207. /* Clear the mailbox pointer for completion */
  208. q->phba->mbox = NULL;
  209. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  210. return 1;
  211. }
  212. /**
  213. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  214. * @q: The Event Queue to get the first valid EQE from
  215. *
  216. * This routine will get the first valid Event Queue Entry from @q, update
  217. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  218. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  219. * processed, but not popped back to the HBA then this routine will return NULL.
  220. **/
  221. static struct lpfc_eqe *
  222. lpfc_sli4_eq_get(struct lpfc_queue *q)
  223. {
  224. struct lpfc_eqe *eqe;
  225. uint32_t idx;
  226. /* sanity check on queue memory */
  227. if (unlikely(!q))
  228. return NULL;
  229. eqe = q->qe[q->hba_index].eqe;
  230. /* If the next EQE is not valid then we are done */
  231. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  232. return NULL;
  233. /* If the host has not yet processed the next entry then we are done */
  234. idx = ((q->hba_index + 1) % q->entry_count);
  235. if (idx == q->host_index)
  236. return NULL;
  237. q->hba_index = idx;
  238. return eqe;
  239. }
  240. /**
  241. * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
  242. * @q: The Event Queue to disable interrupts
  243. *
  244. **/
  245. static inline void
  246. lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
  247. {
  248. struct lpfc_register doorbell;
  249. doorbell.word0 = 0;
  250. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  251. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  252. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  253. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  254. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  255. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  256. }
  257. /**
  258. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  259. * @q: The Event Queue that the host has completed processing for.
  260. * @arm: Indicates whether the host wants to arms this CQ.
  261. *
  262. * This routine will mark all Event Queue Entries on @q, from the last
  263. * known completed entry to the last entry that was processed, as completed
  264. * by clearing the valid bit for each completion queue entry. Then it will
  265. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  266. * The internal host index in the @q will be updated by this routine to indicate
  267. * that the host has finished processing the entries. The @arm parameter
  268. * indicates that the queue should be rearmed when ringing the doorbell.
  269. *
  270. * This function will return the number of EQEs that were popped.
  271. **/
  272. uint32_t
  273. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  274. {
  275. uint32_t released = 0;
  276. struct lpfc_eqe *temp_eqe;
  277. struct lpfc_register doorbell;
  278. /* sanity check on queue memory */
  279. if (unlikely(!q))
  280. return 0;
  281. /* while there are valid entries */
  282. while (q->hba_index != q->host_index) {
  283. temp_eqe = q->qe[q->host_index].eqe;
  284. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  285. released++;
  286. q->host_index = ((q->host_index + 1) % q->entry_count);
  287. }
  288. if (unlikely(released == 0 && !arm))
  289. return 0;
  290. /* ring doorbell for number popped */
  291. doorbell.word0 = 0;
  292. if (arm) {
  293. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  294. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  295. }
  296. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  297. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  298. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  299. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  300. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  301. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  302. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  303. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  304. readl(q->phba->sli4_hba.EQCQDBregaddr);
  305. return released;
  306. }
  307. /**
  308. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  309. * @q: The Completion Queue to get the first valid CQE from
  310. *
  311. * This routine will get the first valid Completion Queue Entry from @q, update
  312. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  313. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  314. * processed, but not popped back to the HBA then this routine will return NULL.
  315. **/
  316. static struct lpfc_cqe *
  317. lpfc_sli4_cq_get(struct lpfc_queue *q)
  318. {
  319. struct lpfc_cqe *cqe;
  320. uint32_t idx;
  321. /* sanity check on queue memory */
  322. if (unlikely(!q))
  323. return NULL;
  324. /* If the next CQE is not valid then we are done */
  325. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  326. return NULL;
  327. /* If the host has not yet processed the next entry then we are done */
  328. idx = ((q->hba_index + 1) % q->entry_count);
  329. if (idx == q->host_index)
  330. return NULL;
  331. cqe = q->qe[q->hba_index].cqe;
  332. q->hba_index = idx;
  333. return cqe;
  334. }
  335. /**
  336. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  337. * @q: The Completion Queue that the host has completed processing for.
  338. * @arm: Indicates whether the host wants to arms this CQ.
  339. *
  340. * This routine will mark all Completion queue entries on @q, from the last
  341. * known completed entry to the last entry that was processed, as completed
  342. * by clearing the valid bit for each completion queue entry. Then it will
  343. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  344. * The internal host index in the @q will be updated by this routine to indicate
  345. * that the host has finished processing the entries. The @arm parameter
  346. * indicates that the queue should be rearmed when ringing the doorbell.
  347. *
  348. * This function will return the number of CQEs that were released.
  349. **/
  350. uint32_t
  351. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  352. {
  353. uint32_t released = 0;
  354. struct lpfc_cqe *temp_qe;
  355. struct lpfc_register doorbell;
  356. /* sanity check on queue memory */
  357. if (unlikely(!q))
  358. return 0;
  359. /* while there are valid entries */
  360. while (q->hba_index != q->host_index) {
  361. temp_qe = q->qe[q->host_index].cqe;
  362. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  363. released++;
  364. q->host_index = ((q->host_index + 1) % q->entry_count);
  365. }
  366. if (unlikely(released == 0 && !arm))
  367. return 0;
  368. /* ring doorbell for number popped */
  369. doorbell.word0 = 0;
  370. if (arm)
  371. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  372. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  373. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  374. bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
  375. (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
  376. bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
  377. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  378. return released;
  379. }
  380. /**
  381. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  382. * @q: The Header Receive Queue to operate on.
  383. * @wqe: The Receive Queue Entry to put on the Receive queue.
  384. *
  385. * This routine will copy the contents of @wqe to the next available entry on
  386. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  387. * HBA to start processing the Receive Queue Entry. This function returns the
  388. * index that the rqe was copied to if successful. If no entries are available
  389. * on @q then this function will return -ENOMEM.
  390. * The caller is expected to hold the hbalock when calling this routine.
  391. **/
  392. static int
  393. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  394. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  395. {
  396. struct lpfc_rqe *temp_hrqe;
  397. struct lpfc_rqe *temp_drqe;
  398. struct lpfc_register doorbell;
  399. int put_index;
  400. /* sanity check on queue memory */
  401. if (unlikely(!hq) || unlikely(!dq))
  402. return -ENOMEM;
  403. put_index = hq->host_index;
  404. temp_hrqe = hq->qe[hq->host_index].rqe;
  405. temp_drqe = dq->qe[dq->host_index].rqe;
  406. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  407. return -EINVAL;
  408. if (hq->host_index != dq->host_index)
  409. return -EINVAL;
  410. /* If the host has not yet processed the next entry then we are done */
  411. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  412. return -EBUSY;
  413. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  414. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  415. /* Update the host index to point to the next slot */
  416. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  417. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  418. /* Ring The Header Receive Queue Doorbell */
  419. if (!(hq->host_index % hq->entry_repost)) {
  420. doorbell.word0 = 0;
  421. if (hq->db_format == LPFC_DB_RING_FORMAT) {
  422. bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
  423. hq->entry_repost);
  424. bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
  425. } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
  426. bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
  427. hq->entry_repost);
  428. bf_set(lpfc_rq_db_list_fm_index, &doorbell,
  429. hq->host_index);
  430. bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
  431. } else {
  432. return -EINVAL;
  433. }
  434. writel(doorbell.word0, hq->db_regaddr);
  435. }
  436. return put_index;
  437. }
  438. /**
  439. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  440. * @q: The Header Receive Queue to operate on.
  441. *
  442. * This routine will update the HBA index of a queue to reflect consumption of
  443. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  444. * consumed an entry the host calls this function to update the queue's
  445. * internal pointers. This routine returns the number of entries that were
  446. * consumed by the HBA.
  447. **/
  448. static uint32_t
  449. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  450. {
  451. /* sanity check on queue memory */
  452. if (unlikely(!hq) || unlikely(!dq))
  453. return 0;
  454. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  455. return 0;
  456. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  457. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  458. return 1;
  459. }
  460. /**
  461. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  462. * @phba: Pointer to HBA context object.
  463. * @pring: Pointer to driver SLI ring object.
  464. *
  465. * This function returns pointer to next command iocb entry
  466. * in the command ring. The caller must hold hbalock to prevent
  467. * other threads consume the next command iocb.
  468. * SLI-2/SLI-3 provide different sized iocbs.
  469. **/
  470. static inline IOCB_t *
  471. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  472. {
  473. return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
  474. pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
  475. }
  476. /**
  477. * lpfc_resp_iocb - Get next response iocb entry in the ring
  478. * @phba: Pointer to HBA context object.
  479. * @pring: Pointer to driver SLI ring object.
  480. *
  481. * This function returns pointer to next response iocb entry
  482. * in the response ring. The caller must hold hbalock to make sure
  483. * that no other thread consume the next response iocb.
  484. * SLI-2/SLI-3 provide different sized iocbs.
  485. **/
  486. static inline IOCB_t *
  487. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  488. {
  489. return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
  490. pring->sli.sli3.rspidx * phba->iocb_rsp_size);
  491. }
  492. /**
  493. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  494. * @phba: Pointer to HBA context object.
  495. *
  496. * This function is called with hbalock held. This function
  497. * allocates a new driver iocb object from the iocb pool. If the
  498. * allocation is successful, it returns pointer to the newly
  499. * allocated iocb object else it returns NULL.
  500. **/
  501. struct lpfc_iocbq *
  502. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  503. {
  504. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  505. struct lpfc_iocbq * iocbq = NULL;
  506. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  507. if (iocbq)
  508. phba->iocb_cnt++;
  509. if (phba->iocb_cnt > phba->iocb_max)
  510. phba->iocb_max = phba->iocb_cnt;
  511. return iocbq;
  512. }
  513. /**
  514. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  515. * @phba: Pointer to HBA context object.
  516. * @xritag: XRI value.
  517. *
  518. * This function clears the sglq pointer from the array of acive
  519. * sglq's. The xritag that is passed in is used to index into the
  520. * array. Before the xritag can be used it needs to be adjusted
  521. * by subtracting the xribase.
  522. *
  523. * Returns sglq ponter = success, NULL = Failure.
  524. **/
  525. static struct lpfc_sglq *
  526. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  527. {
  528. struct lpfc_sglq *sglq;
  529. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  530. phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
  531. return sglq;
  532. }
  533. /**
  534. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  535. * @phba: Pointer to HBA context object.
  536. * @xritag: XRI value.
  537. *
  538. * This function returns the sglq pointer from the array of acive
  539. * sglq's. The xritag that is passed in is used to index into the
  540. * array. Before the xritag can be used it needs to be adjusted
  541. * by subtracting the xribase.
  542. *
  543. * Returns sglq ponter = success, NULL = Failure.
  544. **/
  545. struct lpfc_sglq *
  546. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  547. {
  548. struct lpfc_sglq *sglq;
  549. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  550. return sglq;
  551. }
  552. /**
  553. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  554. * @phba: Pointer to HBA context object.
  555. * @xritag: xri used in this exchange.
  556. * @rrq: The RRQ to be cleared.
  557. *
  558. **/
  559. void
  560. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  561. uint16_t xritag,
  562. struct lpfc_node_rrq *rrq)
  563. {
  564. struct lpfc_nodelist *ndlp = NULL;
  565. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  566. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  567. /* The target DID could have been swapped (cable swap)
  568. * we should use the ndlp from the findnode if it is
  569. * available.
  570. */
  571. if ((!ndlp) && rrq->ndlp)
  572. ndlp = rrq->ndlp;
  573. if (!ndlp)
  574. goto out;
  575. if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) {
  576. rrq->send_rrq = 0;
  577. rrq->xritag = 0;
  578. rrq->rrq_stop_time = 0;
  579. }
  580. out:
  581. mempool_free(rrq, phba->rrq_pool);
  582. }
  583. /**
  584. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  585. * @phba: Pointer to HBA context object.
  586. *
  587. * This function is called with hbalock held. This function
  588. * Checks if stop_time (ratov from setting rrq active) has
  589. * been reached, if it has and the send_rrq flag is set then
  590. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  591. * then it will just call the routine to clear the rrq and
  592. * free the rrq resource.
  593. * The timer is set to the next rrq that is going to expire before
  594. * leaving the routine.
  595. *
  596. **/
  597. void
  598. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  599. {
  600. struct lpfc_node_rrq *rrq;
  601. struct lpfc_node_rrq *nextrrq;
  602. unsigned long next_time;
  603. unsigned long iflags;
  604. LIST_HEAD(send_rrq);
  605. spin_lock_irqsave(&phba->hbalock, iflags);
  606. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  607. next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  608. list_for_each_entry_safe(rrq, nextrrq,
  609. &phba->active_rrq_list, list) {
  610. if (time_after(jiffies, rrq->rrq_stop_time))
  611. list_move(&rrq->list, &send_rrq);
  612. else if (time_before(rrq->rrq_stop_time, next_time))
  613. next_time = rrq->rrq_stop_time;
  614. }
  615. spin_unlock_irqrestore(&phba->hbalock, iflags);
  616. if (!list_empty(&phba->active_rrq_list))
  617. mod_timer(&phba->rrq_tmr, next_time);
  618. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  619. list_del(&rrq->list);
  620. if (!rrq->send_rrq)
  621. /* this call will free the rrq */
  622. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  623. else if (lpfc_send_rrq(phba, rrq)) {
  624. /* if we send the rrq then the completion handler
  625. * will clear the bit in the xribitmap.
  626. */
  627. lpfc_clr_rrq_active(phba, rrq->xritag,
  628. rrq);
  629. }
  630. }
  631. }
  632. /**
  633. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  634. * @vport: Pointer to vport context object.
  635. * @xri: The xri used in the exchange.
  636. * @did: The targets DID for this exchange.
  637. *
  638. * returns NULL = rrq not found in the phba->active_rrq_list.
  639. * rrq = rrq for this xri and target.
  640. **/
  641. struct lpfc_node_rrq *
  642. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  643. {
  644. struct lpfc_hba *phba = vport->phba;
  645. struct lpfc_node_rrq *rrq;
  646. struct lpfc_node_rrq *nextrrq;
  647. unsigned long iflags;
  648. if (phba->sli_rev != LPFC_SLI_REV4)
  649. return NULL;
  650. spin_lock_irqsave(&phba->hbalock, iflags);
  651. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  652. if (rrq->vport == vport && rrq->xritag == xri &&
  653. rrq->nlp_DID == did){
  654. list_del(&rrq->list);
  655. spin_unlock_irqrestore(&phba->hbalock, iflags);
  656. return rrq;
  657. }
  658. }
  659. spin_unlock_irqrestore(&phba->hbalock, iflags);
  660. return NULL;
  661. }
  662. /**
  663. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  664. * @vport: Pointer to vport context object.
  665. * @ndlp: Pointer to the lpfc_node_list structure.
  666. * If ndlp is NULL Remove all active RRQs for this vport from the
  667. * phba->active_rrq_list and clear the rrq.
  668. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  669. **/
  670. void
  671. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  672. {
  673. struct lpfc_hba *phba = vport->phba;
  674. struct lpfc_node_rrq *rrq;
  675. struct lpfc_node_rrq *nextrrq;
  676. unsigned long iflags;
  677. LIST_HEAD(rrq_list);
  678. if (phba->sli_rev != LPFC_SLI_REV4)
  679. return;
  680. if (!ndlp) {
  681. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  682. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  683. }
  684. spin_lock_irqsave(&phba->hbalock, iflags);
  685. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  686. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  687. list_move(&rrq->list, &rrq_list);
  688. spin_unlock_irqrestore(&phba->hbalock, iflags);
  689. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  690. list_del(&rrq->list);
  691. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  692. }
  693. }
  694. /**
  695. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  696. * @phba: Pointer to HBA context object.
  697. *
  698. * Remove all rrqs from the phba->active_rrq_list and free them by
  699. * calling __lpfc_clr_active_rrq
  700. *
  701. **/
  702. void
  703. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  704. {
  705. struct lpfc_node_rrq *rrq;
  706. struct lpfc_node_rrq *nextrrq;
  707. unsigned long next_time;
  708. unsigned long iflags;
  709. LIST_HEAD(rrq_list);
  710. if (phba->sli_rev != LPFC_SLI_REV4)
  711. return;
  712. spin_lock_irqsave(&phba->hbalock, iflags);
  713. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  714. next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2));
  715. list_splice_init(&phba->active_rrq_list, &rrq_list);
  716. spin_unlock_irqrestore(&phba->hbalock, iflags);
  717. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  718. list_del(&rrq->list);
  719. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  720. }
  721. if (!list_empty(&phba->active_rrq_list))
  722. mod_timer(&phba->rrq_tmr, next_time);
  723. }
  724. /**
  725. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  726. * @phba: Pointer to HBA context object.
  727. * @ndlp: Targets nodelist pointer for this exchange.
  728. * @xritag the xri in the bitmap to test.
  729. *
  730. * This function is called with hbalock held. This function
  731. * returns 0 = rrq not active for this xri
  732. * 1 = rrq is valid for this xri.
  733. **/
  734. int
  735. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  736. uint16_t xritag)
  737. {
  738. if (!ndlp)
  739. return 0;
  740. if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  741. return 1;
  742. else
  743. return 0;
  744. }
  745. /**
  746. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  747. * @phba: Pointer to HBA context object.
  748. * @ndlp: nodelist pointer for this target.
  749. * @xritag: xri used in this exchange.
  750. * @rxid: Remote Exchange ID.
  751. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  752. *
  753. * This function takes the hbalock.
  754. * The active bit is always set in the active rrq xri_bitmap even
  755. * if there is no slot avaiable for the other rrq information.
  756. *
  757. * returns 0 rrq actived for this xri
  758. * < 0 No memory or invalid ndlp.
  759. **/
  760. int
  761. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  762. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  763. {
  764. unsigned long iflags;
  765. struct lpfc_node_rrq *rrq;
  766. int empty;
  767. if (!ndlp)
  768. return -EINVAL;
  769. if (!phba->cfg_enable_rrq)
  770. return -EINVAL;
  771. spin_lock_irqsave(&phba->hbalock, iflags);
  772. if (phba->pport->load_flag & FC_UNLOADING) {
  773. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  774. goto out;
  775. }
  776. /*
  777. * set the active bit even if there is no mem available.
  778. */
  779. if (NLP_CHK_FREE_REQ(ndlp))
  780. goto out;
  781. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  782. goto out;
  783. if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  784. goto out;
  785. spin_unlock_irqrestore(&phba->hbalock, iflags);
  786. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  787. if (!rrq) {
  788. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  789. "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
  790. " DID:0x%x Send:%d\n",
  791. xritag, rxid, ndlp->nlp_DID, send_rrq);
  792. return -EINVAL;
  793. }
  794. if (phba->cfg_enable_rrq == 1)
  795. rrq->send_rrq = send_rrq;
  796. else
  797. rrq->send_rrq = 0;
  798. rrq->xritag = xritag;
  799. rrq->rrq_stop_time = jiffies +
  800. msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  801. rrq->ndlp = ndlp;
  802. rrq->nlp_DID = ndlp->nlp_DID;
  803. rrq->vport = ndlp->vport;
  804. rrq->rxid = rxid;
  805. spin_lock_irqsave(&phba->hbalock, iflags);
  806. empty = list_empty(&phba->active_rrq_list);
  807. list_add_tail(&rrq->list, &phba->active_rrq_list);
  808. phba->hba_flag |= HBA_RRQ_ACTIVE;
  809. if (empty)
  810. lpfc_worker_wake_up(phba);
  811. spin_unlock_irqrestore(&phba->hbalock, iflags);
  812. return 0;
  813. out:
  814. spin_unlock_irqrestore(&phba->hbalock, iflags);
  815. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  816. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  817. " DID:0x%x Send:%d\n",
  818. xritag, rxid, ndlp->nlp_DID, send_rrq);
  819. return -EINVAL;
  820. }
  821. /**
  822. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  823. * @phba: Pointer to HBA context object.
  824. * @piocb: Pointer to the iocbq.
  825. *
  826. * This function is called with hbalock held. This function
  827. * gets a new driver sglq object from the sglq list. If the
  828. * list is not empty then it is successful, it returns pointer to the newly
  829. * allocated sglq object else it returns NULL.
  830. **/
  831. static struct lpfc_sglq *
  832. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  833. {
  834. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  835. struct lpfc_sglq *sglq = NULL;
  836. struct lpfc_sglq *start_sglq = NULL;
  837. struct lpfc_scsi_buf *lpfc_cmd;
  838. struct lpfc_nodelist *ndlp;
  839. int found = 0;
  840. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  841. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  842. ndlp = lpfc_cmd->rdata->pnode;
  843. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  844. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  845. ndlp = piocbq->context_un.ndlp;
  846. else if (piocbq->iocb_flag & LPFC_IO_LIBDFC)
  847. ndlp = piocbq->context_un.ndlp;
  848. else
  849. ndlp = piocbq->context1;
  850. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  851. start_sglq = sglq;
  852. while (!found) {
  853. if (!sglq)
  854. return NULL;
  855. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) {
  856. /* This xri has an rrq outstanding for this DID.
  857. * put it back in the list and get another xri.
  858. */
  859. list_add_tail(&sglq->list, lpfc_sgl_list);
  860. sglq = NULL;
  861. list_remove_head(lpfc_sgl_list, sglq,
  862. struct lpfc_sglq, list);
  863. if (sglq == start_sglq) {
  864. sglq = NULL;
  865. break;
  866. } else
  867. continue;
  868. }
  869. sglq->ndlp = ndlp;
  870. found = 1;
  871. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  872. sglq->state = SGL_ALLOCATED;
  873. }
  874. return sglq;
  875. }
  876. /**
  877. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  878. * @phba: Pointer to HBA context object.
  879. *
  880. * This function is called with no lock held. This function
  881. * allocates a new driver iocb object from the iocb pool. If the
  882. * allocation is successful, it returns pointer to the newly
  883. * allocated iocb object else it returns NULL.
  884. **/
  885. struct lpfc_iocbq *
  886. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  887. {
  888. struct lpfc_iocbq * iocbq = NULL;
  889. unsigned long iflags;
  890. spin_lock_irqsave(&phba->hbalock, iflags);
  891. iocbq = __lpfc_sli_get_iocbq(phba);
  892. spin_unlock_irqrestore(&phba->hbalock, iflags);
  893. return iocbq;
  894. }
  895. /**
  896. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  897. * @phba: Pointer to HBA context object.
  898. * @iocbq: Pointer to driver iocb object.
  899. *
  900. * This function is called with hbalock held to release driver
  901. * iocb object to the iocb pool. The iotag in the iocb object
  902. * does not change for each use of the iocb object. This function
  903. * clears all other fields of the iocb object when it is freed.
  904. * The sqlq structure that holds the xritag and phys and virtual
  905. * mappings for the scatter gather list is retrieved from the
  906. * active array of sglq. The get of the sglq pointer also clears
  907. * the entry in the array. If the status of the IO indiactes that
  908. * this IO was aborted then the sglq entry it put on the
  909. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  910. * IO has good status or fails for any other reason then the sglq
  911. * entry is added to the free list (lpfc_sgl_list).
  912. **/
  913. static void
  914. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  915. {
  916. struct lpfc_sglq *sglq;
  917. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  918. unsigned long iflag = 0;
  919. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  920. if (iocbq->sli4_xritag == NO_XRI)
  921. sglq = NULL;
  922. else
  923. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  924. /*
  925. ** This should have been removed from the txcmplq before calling
  926. ** iocbq_release. The normal completion
  927. ** path should have already done the list_del_init.
  928. */
  929. if (unlikely(!list_empty(&iocbq->list))) {
  930. if (iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)
  931. iocbq->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  932. list_del_init(&iocbq->list);
  933. }
  934. if (sglq) {
  935. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  936. (sglq->state != SGL_XRI_ABORTED)) {
  937. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  938. iflag);
  939. list_add(&sglq->list,
  940. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  941. spin_unlock_irqrestore(
  942. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  943. } else {
  944. sglq->state = SGL_FREED;
  945. sglq->ndlp = NULL;
  946. list_add_tail(&sglq->list,
  947. &phba->sli4_hba.lpfc_sgl_list);
  948. /* Check if TXQ queue needs to be serviced */
  949. if (!list_empty(&pring->txq))
  950. lpfc_worker_wake_up(phba);
  951. }
  952. }
  953. /*
  954. * Clean all volatile data fields, preserve iotag and node struct.
  955. */
  956. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  957. iocbq->sli4_lxritag = NO_XRI;
  958. iocbq->sli4_xritag = NO_XRI;
  959. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  960. }
  961. /**
  962. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  963. * @phba: Pointer to HBA context object.
  964. * @iocbq: Pointer to driver iocb object.
  965. *
  966. * This function is called with hbalock held to release driver
  967. * iocb object to the iocb pool. The iotag in the iocb object
  968. * does not change for each use of the iocb object. This function
  969. * clears all other fields of the iocb object when it is freed.
  970. **/
  971. static void
  972. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  973. {
  974. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  975. /*
  976. ** This should have been removed from the txcmplq before calling
  977. ** iocbq_release. The normal completion
  978. ** path should have already done the list_del_init.
  979. */
  980. if (unlikely(!list_empty(&iocbq->list)))
  981. list_del_init(&iocbq->list);
  982. /*
  983. * Clean all volatile data fields, preserve iotag and node struct.
  984. */
  985. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  986. iocbq->sli4_xritag = NO_XRI;
  987. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  988. }
  989. /**
  990. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  991. * @phba: Pointer to HBA context object.
  992. * @iocbq: Pointer to driver iocb object.
  993. *
  994. * This function is called with hbalock held to release driver
  995. * iocb object to the iocb pool. The iotag in the iocb object
  996. * does not change for each use of the iocb object. This function
  997. * clears all other fields of the iocb object when it is freed.
  998. **/
  999. static void
  1000. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1001. {
  1002. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  1003. phba->iocb_cnt--;
  1004. }
  1005. /**
  1006. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  1007. * @phba: Pointer to HBA context object.
  1008. * @iocbq: Pointer to driver iocb object.
  1009. *
  1010. * This function is called with no lock held to release the iocb to
  1011. * iocb pool.
  1012. **/
  1013. void
  1014. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1015. {
  1016. unsigned long iflags;
  1017. /*
  1018. * Clean all volatile data fields, preserve iotag and node struct.
  1019. */
  1020. spin_lock_irqsave(&phba->hbalock, iflags);
  1021. __lpfc_sli_release_iocbq(phba, iocbq);
  1022. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1023. }
  1024. /**
  1025. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  1026. * @phba: Pointer to HBA context object.
  1027. * @iocblist: List of IOCBs.
  1028. * @ulpstatus: ULP status in IOCB command field.
  1029. * @ulpWord4: ULP word-4 in IOCB command field.
  1030. *
  1031. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  1032. * on the list by invoking the complete callback function associated with the
  1033. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  1034. * fields.
  1035. **/
  1036. void
  1037. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  1038. uint32_t ulpstatus, uint32_t ulpWord4)
  1039. {
  1040. struct lpfc_iocbq *piocb;
  1041. while (!list_empty(iocblist)) {
  1042. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  1043. if (!piocb->iocb_cmpl)
  1044. lpfc_sli_release_iocbq(phba, piocb);
  1045. else {
  1046. piocb->iocb.ulpStatus = ulpstatus;
  1047. piocb->iocb.un.ulpWord[4] = ulpWord4;
  1048. (piocb->iocb_cmpl) (phba, piocb, piocb);
  1049. }
  1050. }
  1051. return;
  1052. }
  1053. /**
  1054. * lpfc_sli_iocb_cmd_type - Get the iocb type
  1055. * @iocb_cmnd: iocb command code.
  1056. *
  1057. * This function is called by ring event handler function to get the iocb type.
  1058. * This function translates the iocb command to an iocb command type used to
  1059. * decide the final disposition of each completed IOCB.
  1060. * The function returns
  1061. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1062. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1063. * LPFC_ABORT_IOCB if it is an abort iocb
  1064. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1065. *
  1066. * The caller is not required to hold any lock.
  1067. **/
  1068. static lpfc_iocb_type
  1069. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1070. {
  1071. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1072. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1073. return 0;
  1074. switch (iocb_cmnd) {
  1075. case CMD_XMIT_SEQUENCE_CR:
  1076. case CMD_XMIT_SEQUENCE_CX:
  1077. case CMD_XMIT_BCAST_CN:
  1078. case CMD_XMIT_BCAST_CX:
  1079. case CMD_ELS_REQUEST_CR:
  1080. case CMD_ELS_REQUEST_CX:
  1081. case CMD_CREATE_XRI_CR:
  1082. case CMD_CREATE_XRI_CX:
  1083. case CMD_GET_RPI_CN:
  1084. case CMD_XMIT_ELS_RSP_CX:
  1085. case CMD_GET_RPI_CR:
  1086. case CMD_FCP_IWRITE_CR:
  1087. case CMD_FCP_IWRITE_CX:
  1088. case CMD_FCP_IREAD_CR:
  1089. case CMD_FCP_IREAD_CX:
  1090. case CMD_FCP_ICMND_CR:
  1091. case CMD_FCP_ICMND_CX:
  1092. case CMD_FCP_TSEND_CX:
  1093. case CMD_FCP_TRSP_CX:
  1094. case CMD_FCP_TRECEIVE_CX:
  1095. case CMD_FCP_AUTO_TRSP_CX:
  1096. case CMD_ADAPTER_MSG:
  1097. case CMD_ADAPTER_DUMP:
  1098. case CMD_XMIT_SEQUENCE64_CR:
  1099. case CMD_XMIT_SEQUENCE64_CX:
  1100. case CMD_XMIT_BCAST64_CN:
  1101. case CMD_XMIT_BCAST64_CX:
  1102. case CMD_ELS_REQUEST64_CR:
  1103. case CMD_ELS_REQUEST64_CX:
  1104. case CMD_FCP_IWRITE64_CR:
  1105. case CMD_FCP_IWRITE64_CX:
  1106. case CMD_FCP_IREAD64_CR:
  1107. case CMD_FCP_IREAD64_CX:
  1108. case CMD_FCP_ICMND64_CR:
  1109. case CMD_FCP_ICMND64_CX:
  1110. case CMD_FCP_TSEND64_CX:
  1111. case CMD_FCP_TRSP64_CX:
  1112. case CMD_FCP_TRECEIVE64_CX:
  1113. case CMD_GEN_REQUEST64_CR:
  1114. case CMD_GEN_REQUEST64_CX:
  1115. case CMD_XMIT_ELS_RSP64_CX:
  1116. case DSSCMD_IWRITE64_CR:
  1117. case DSSCMD_IWRITE64_CX:
  1118. case DSSCMD_IREAD64_CR:
  1119. case DSSCMD_IREAD64_CX:
  1120. type = LPFC_SOL_IOCB;
  1121. break;
  1122. case CMD_ABORT_XRI_CN:
  1123. case CMD_ABORT_XRI_CX:
  1124. case CMD_CLOSE_XRI_CN:
  1125. case CMD_CLOSE_XRI_CX:
  1126. case CMD_XRI_ABORTED_CX:
  1127. case CMD_ABORT_MXRI64_CN:
  1128. case CMD_XMIT_BLS_RSP64_CX:
  1129. type = LPFC_ABORT_IOCB;
  1130. break;
  1131. case CMD_RCV_SEQUENCE_CX:
  1132. case CMD_RCV_ELS_REQ_CX:
  1133. case CMD_RCV_SEQUENCE64_CX:
  1134. case CMD_RCV_ELS_REQ64_CX:
  1135. case CMD_ASYNC_STATUS:
  1136. case CMD_IOCB_RCV_SEQ64_CX:
  1137. case CMD_IOCB_RCV_ELS64_CX:
  1138. case CMD_IOCB_RCV_CONT64_CX:
  1139. case CMD_IOCB_RET_XRI64_CX:
  1140. type = LPFC_UNSOL_IOCB;
  1141. break;
  1142. case CMD_IOCB_XMIT_MSEQ64_CR:
  1143. case CMD_IOCB_XMIT_MSEQ64_CX:
  1144. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1145. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1146. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1147. case CMD_IOCB_ABORT_EXTENDED_CN:
  1148. case CMD_IOCB_RET_HBQE64_CN:
  1149. case CMD_IOCB_FCP_IBIDIR64_CR:
  1150. case CMD_IOCB_FCP_IBIDIR64_CX:
  1151. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1152. case CMD_IOCB_LOGENTRY_CN:
  1153. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1154. printk("%s - Unhandled SLI-3 Command x%x\n",
  1155. __func__, iocb_cmnd);
  1156. type = LPFC_UNKNOWN_IOCB;
  1157. break;
  1158. default:
  1159. type = LPFC_UNKNOWN_IOCB;
  1160. break;
  1161. }
  1162. return type;
  1163. }
  1164. /**
  1165. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1166. * @phba: Pointer to HBA context object.
  1167. *
  1168. * This function is called from SLI initialization code
  1169. * to configure every ring of the HBA's SLI interface. The
  1170. * caller is not required to hold any lock. This function issues
  1171. * a config_ring mailbox command for each ring.
  1172. * This function returns zero if successful else returns a negative
  1173. * error code.
  1174. **/
  1175. static int
  1176. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1177. {
  1178. struct lpfc_sli *psli = &phba->sli;
  1179. LPFC_MBOXQ_t *pmb;
  1180. MAILBOX_t *pmbox;
  1181. int i, rc, ret = 0;
  1182. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1183. if (!pmb)
  1184. return -ENOMEM;
  1185. pmbox = &pmb->u.mb;
  1186. phba->link_state = LPFC_INIT_MBX_CMDS;
  1187. for (i = 0; i < psli->num_rings; i++) {
  1188. lpfc_config_ring(phba, i, pmb);
  1189. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1190. if (rc != MBX_SUCCESS) {
  1191. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1192. "0446 Adapter failed to init (%d), "
  1193. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1194. "ring %d\n",
  1195. rc, pmbox->mbxCommand,
  1196. pmbox->mbxStatus, i);
  1197. phba->link_state = LPFC_HBA_ERROR;
  1198. ret = -ENXIO;
  1199. break;
  1200. }
  1201. }
  1202. mempool_free(pmb, phba->mbox_mem_pool);
  1203. return ret;
  1204. }
  1205. /**
  1206. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1207. * @phba: Pointer to HBA context object.
  1208. * @pring: Pointer to driver SLI ring object.
  1209. * @piocb: Pointer to the driver iocb object.
  1210. *
  1211. * This function is called with hbalock held. The function adds the
  1212. * new iocb to txcmplq of the given ring. This function always returns
  1213. * 0. If this function is called for ELS ring, this function checks if
  1214. * there is a vport associated with the ELS command. This function also
  1215. * starts els_tmofunc timer if this is an ELS command.
  1216. **/
  1217. static int
  1218. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1219. struct lpfc_iocbq *piocb)
  1220. {
  1221. list_add_tail(&piocb->list, &pring->txcmplq);
  1222. piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
  1223. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1224. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1225. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1226. if (!piocb->vport)
  1227. BUG();
  1228. else
  1229. mod_timer(&piocb->vport->els_tmofunc,
  1230. jiffies +
  1231. msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
  1232. }
  1233. return 0;
  1234. }
  1235. /**
  1236. * lpfc_sli_ringtx_get - Get first element of the txq
  1237. * @phba: Pointer to HBA context object.
  1238. * @pring: Pointer to driver SLI ring object.
  1239. *
  1240. * This function is called with hbalock held to get next
  1241. * iocb in txq of the given ring. If there is any iocb in
  1242. * the txq, the function returns first iocb in the list after
  1243. * removing the iocb from the list, else it returns NULL.
  1244. **/
  1245. struct lpfc_iocbq *
  1246. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1247. {
  1248. struct lpfc_iocbq *cmd_iocb;
  1249. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1250. return cmd_iocb;
  1251. }
  1252. /**
  1253. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1254. * @phba: Pointer to HBA context object.
  1255. * @pring: Pointer to driver SLI ring object.
  1256. *
  1257. * This function is called with hbalock held and the caller must post the
  1258. * iocb without releasing the lock. If the caller releases the lock,
  1259. * iocb slot returned by the function is not guaranteed to be available.
  1260. * The function returns pointer to the next available iocb slot if there
  1261. * is available slot in the ring, else it returns NULL.
  1262. * If the get index of the ring is ahead of the put index, the function
  1263. * will post an error attention event to the worker thread to take the
  1264. * HBA to offline state.
  1265. **/
  1266. static IOCB_t *
  1267. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1268. {
  1269. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1270. uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
  1271. if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
  1272. (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
  1273. pring->sli.sli3.next_cmdidx = 0;
  1274. if (unlikely(pring->sli.sli3.local_getidx ==
  1275. pring->sli.sli3.next_cmdidx)) {
  1276. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1277. if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
  1278. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1279. "0315 Ring %d issue: portCmdGet %d "
  1280. "is bigger than cmd ring %d\n",
  1281. pring->ringno,
  1282. pring->sli.sli3.local_getidx,
  1283. max_cmd_idx);
  1284. phba->link_state = LPFC_HBA_ERROR;
  1285. /*
  1286. * All error attention handlers are posted to
  1287. * worker thread
  1288. */
  1289. phba->work_ha |= HA_ERATT;
  1290. phba->work_hs = HS_FFER3;
  1291. lpfc_worker_wake_up(phba);
  1292. return NULL;
  1293. }
  1294. if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
  1295. return NULL;
  1296. }
  1297. return lpfc_cmd_iocb(phba, pring);
  1298. }
  1299. /**
  1300. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1301. * @phba: Pointer to HBA context object.
  1302. * @iocbq: Pointer to driver iocb object.
  1303. *
  1304. * This function gets an iotag for the iocb. If there is no unused iotag and
  1305. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1306. * array and assigns a new iotag.
  1307. * The function returns the allocated iotag if successful, else returns zero.
  1308. * Zero is not a valid iotag.
  1309. * The caller is not required to hold any lock.
  1310. **/
  1311. uint16_t
  1312. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1313. {
  1314. struct lpfc_iocbq **new_arr;
  1315. struct lpfc_iocbq **old_arr;
  1316. size_t new_len;
  1317. struct lpfc_sli *psli = &phba->sli;
  1318. uint16_t iotag;
  1319. spin_lock_irq(&phba->hbalock);
  1320. iotag = psli->last_iotag;
  1321. if(++iotag < psli->iocbq_lookup_len) {
  1322. psli->last_iotag = iotag;
  1323. psli->iocbq_lookup[iotag] = iocbq;
  1324. spin_unlock_irq(&phba->hbalock);
  1325. iocbq->iotag = iotag;
  1326. return iotag;
  1327. } else if (psli->iocbq_lookup_len < (0xffff
  1328. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1329. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1330. spin_unlock_irq(&phba->hbalock);
  1331. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1332. GFP_KERNEL);
  1333. if (new_arr) {
  1334. spin_lock_irq(&phba->hbalock);
  1335. old_arr = psli->iocbq_lookup;
  1336. if (new_len <= psli->iocbq_lookup_len) {
  1337. /* highly unprobable case */
  1338. kfree(new_arr);
  1339. iotag = psli->last_iotag;
  1340. if(++iotag < psli->iocbq_lookup_len) {
  1341. psli->last_iotag = iotag;
  1342. psli->iocbq_lookup[iotag] = iocbq;
  1343. spin_unlock_irq(&phba->hbalock);
  1344. iocbq->iotag = iotag;
  1345. return iotag;
  1346. }
  1347. spin_unlock_irq(&phba->hbalock);
  1348. return 0;
  1349. }
  1350. if (psli->iocbq_lookup)
  1351. memcpy(new_arr, old_arr,
  1352. ((psli->last_iotag + 1) *
  1353. sizeof (struct lpfc_iocbq *)));
  1354. psli->iocbq_lookup = new_arr;
  1355. psli->iocbq_lookup_len = new_len;
  1356. psli->last_iotag = iotag;
  1357. psli->iocbq_lookup[iotag] = iocbq;
  1358. spin_unlock_irq(&phba->hbalock);
  1359. iocbq->iotag = iotag;
  1360. kfree(old_arr);
  1361. return iotag;
  1362. }
  1363. } else
  1364. spin_unlock_irq(&phba->hbalock);
  1365. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1366. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1367. psli->last_iotag);
  1368. return 0;
  1369. }
  1370. /**
  1371. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1372. * @phba: Pointer to HBA context object.
  1373. * @pring: Pointer to driver SLI ring object.
  1374. * @iocb: Pointer to iocb slot in the ring.
  1375. * @nextiocb: Pointer to driver iocb object which need to be
  1376. * posted to firmware.
  1377. *
  1378. * This function is called with hbalock held to post a new iocb to
  1379. * the firmware. This function copies the new iocb to ring iocb slot and
  1380. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1381. * a completion call back for this iocb else the function will free the
  1382. * iocb object.
  1383. **/
  1384. static void
  1385. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1386. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1387. {
  1388. /*
  1389. * Set up an iotag
  1390. */
  1391. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1392. if (pring->ringno == LPFC_ELS_RING) {
  1393. lpfc_debugfs_slow_ring_trc(phba,
  1394. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1395. *(((uint32_t *) &nextiocb->iocb) + 4),
  1396. *(((uint32_t *) &nextiocb->iocb) + 6),
  1397. *(((uint32_t *) &nextiocb->iocb) + 7));
  1398. }
  1399. /*
  1400. * Issue iocb command to adapter
  1401. */
  1402. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1403. wmb();
  1404. pring->stats.iocb_cmd++;
  1405. /*
  1406. * If there is no completion routine to call, we can release the
  1407. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1408. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1409. */
  1410. if (nextiocb->iocb_cmpl)
  1411. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1412. else
  1413. __lpfc_sli_release_iocbq(phba, nextiocb);
  1414. /*
  1415. * Let the HBA know what IOCB slot will be the next one the
  1416. * driver will put a command into.
  1417. */
  1418. pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
  1419. writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1420. }
  1421. /**
  1422. * lpfc_sli_update_full_ring - Update the chip attention register
  1423. * @phba: Pointer to HBA context object.
  1424. * @pring: Pointer to driver SLI ring object.
  1425. *
  1426. * The caller is not required to hold any lock for calling this function.
  1427. * This function updates the chip attention bits for the ring to inform firmware
  1428. * that there are pending work to be done for this ring and requests an
  1429. * interrupt when there is space available in the ring. This function is
  1430. * called when the driver is unable to post more iocbs to the ring due
  1431. * to unavailability of space in the ring.
  1432. **/
  1433. static void
  1434. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1435. {
  1436. int ringno = pring->ringno;
  1437. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1438. wmb();
  1439. /*
  1440. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1441. * The HBA will tell us when an IOCB entry is available.
  1442. */
  1443. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1444. readl(phba->CAregaddr); /* flush */
  1445. pring->stats.iocb_cmd_full++;
  1446. }
  1447. /**
  1448. * lpfc_sli_update_ring - Update chip attention register
  1449. * @phba: Pointer to HBA context object.
  1450. * @pring: Pointer to driver SLI ring object.
  1451. *
  1452. * This function updates the chip attention register bit for the
  1453. * given ring to inform HBA that there is more work to be done
  1454. * in this ring. The caller is not required to hold any lock.
  1455. **/
  1456. static void
  1457. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1458. {
  1459. int ringno = pring->ringno;
  1460. /*
  1461. * Tell the HBA that there is work to do in this ring.
  1462. */
  1463. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1464. wmb();
  1465. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1466. readl(phba->CAregaddr); /* flush */
  1467. }
  1468. }
  1469. /**
  1470. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1471. * @phba: Pointer to HBA context object.
  1472. * @pring: Pointer to driver SLI ring object.
  1473. *
  1474. * This function is called with hbalock held to post pending iocbs
  1475. * in the txq to the firmware. This function is called when driver
  1476. * detects space available in the ring.
  1477. **/
  1478. static void
  1479. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1480. {
  1481. IOCB_t *iocb;
  1482. struct lpfc_iocbq *nextiocb;
  1483. /*
  1484. * Check to see if:
  1485. * (a) there is anything on the txq to send
  1486. * (b) link is up
  1487. * (c) link attention events can be processed (fcp ring only)
  1488. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1489. */
  1490. if (lpfc_is_link_up(phba) &&
  1491. (!list_empty(&pring->txq)) &&
  1492. (pring->ringno != phba->sli.fcp_ring ||
  1493. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1494. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1495. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1496. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1497. if (iocb)
  1498. lpfc_sli_update_ring(phba, pring);
  1499. else
  1500. lpfc_sli_update_full_ring(phba, pring);
  1501. }
  1502. return;
  1503. }
  1504. /**
  1505. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1506. * @phba: Pointer to HBA context object.
  1507. * @hbqno: HBQ number.
  1508. *
  1509. * This function is called with hbalock held to get the next
  1510. * available slot for the given HBQ. If there is free slot
  1511. * available for the HBQ it will return pointer to the next available
  1512. * HBQ entry else it will return NULL.
  1513. **/
  1514. static struct lpfc_hbq_entry *
  1515. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1516. {
  1517. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1518. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1519. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1520. hbqp->next_hbqPutIdx = 0;
  1521. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1522. uint32_t raw_index = phba->hbq_get[hbqno];
  1523. uint32_t getidx = le32_to_cpu(raw_index);
  1524. hbqp->local_hbqGetIdx = getidx;
  1525. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1526. lpfc_printf_log(phba, KERN_ERR,
  1527. LOG_SLI | LOG_VPORT,
  1528. "1802 HBQ %d: local_hbqGetIdx "
  1529. "%u is > than hbqp->entry_count %u\n",
  1530. hbqno, hbqp->local_hbqGetIdx,
  1531. hbqp->entry_count);
  1532. phba->link_state = LPFC_HBA_ERROR;
  1533. return NULL;
  1534. }
  1535. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1536. return NULL;
  1537. }
  1538. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1539. hbqp->hbqPutIdx;
  1540. }
  1541. /**
  1542. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1543. * @phba: Pointer to HBA context object.
  1544. *
  1545. * This function is called with no lock held to free all the
  1546. * hbq buffers while uninitializing the SLI interface. It also
  1547. * frees the HBQ buffers returned by the firmware but not yet
  1548. * processed by the upper layers.
  1549. **/
  1550. void
  1551. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1552. {
  1553. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1554. struct hbq_dmabuf *hbq_buf;
  1555. unsigned long flags;
  1556. int i, hbq_count;
  1557. uint32_t hbqno;
  1558. hbq_count = lpfc_sli_hbq_count();
  1559. /* Return all memory used by all HBQs */
  1560. spin_lock_irqsave(&phba->hbalock, flags);
  1561. for (i = 0; i < hbq_count; ++i) {
  1562. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1563. &phba->hbqs[i].hbq_buffer_list, list) {
  1564. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1565. list_del(&hbq_buf->dbuf.list);
  1566. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1567. }
  1568. phba->hbqs[i].buffer_count = 0;
  1569. }
  1570. /* Return all HBQ buffer that are in-fly */
  1571. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1572. list) {
  1573. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1574. list_del(&hbq_buf->dbuf.list);
  1575. if (hbq_buf->tag == -1) {
  1576. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1577. (phba, hbq_buf);
  1578. } else {
  1579. hbqno = hbq_buf->tag >> 16;
  1580. if (hbqno >= LPFC_MAX_HBQS)
  1581. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1582. (phba, hbq_buf);
  1583. else
  1584. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1585. hbq_buf);
  1586. }
  1587. }
  1588. /* Mark the HBQs not in use */
  1589. phba->hbq_in_use = 0;
  1590. spin_unlock_irqrestore(&phba->hbalock, flags);
  1591. }
  1592. /**
  1593. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1594. * @phba: Pointer to HBA context object.
  1595. * @hbqno: HBQ number.
  1596. * @hbq_buf: Pointer to HBQ buffer.
  1597. *
  1598. * This function is called with the hbalock held to post a
  1599. * hbq buffer to the firmware. If the function finds an empty
  1600. * slot in the HBQ, it will post the buffer. The function will return
  1601. * pointer to the hbq entry if it successfully post the buffer
  1602. * else it will return NULL.
  1603. **/
  1604. static int
  1605. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1606. struct hbq_dmabuf *hbq_buf)
  1607. {
  1608. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1609. }
  1610. /**
  1611. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1612. * @phba: Pointer to HBA context object.
  1613. * @hbqno: HBQ number.
  1614. * @hbq_buf: Pointer to HBQ buffer.
  1615. *
  1616. * This function is called with the hbalock held to post a hbq buffer to the
  1617. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1618. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1619. * it successfully post the buffer else it will return an error.
  1620. **/
  1621. static int
  1622. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1623. struct hbq_dmabuf *hbq_buf)
  1624. {
  1625. struct lpfc_hbq_entry *hbqe;
  1626. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1627. /* Get next HBQ entry slot to use */
  1628. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1629. if (hbqe) {
  1630. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1631. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1632. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1633. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1634. hbqe->bde.tus.f.bdeFlags = 0;
  1635. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1636. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1637. /* Sync SLIM */
  1638. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1639. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1640. /* flush */
  1641. readl(phba->hbq_put + hbqno);
  1642. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1643. return 0;
  1644. } else
  1645. return -ENOMEM;
  1646. }
  1647. /**
  1648. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1649. * @phba: Pointer to HBA context object.
  1650. * @hbqno: HBQ number.
  1651. * @hbq_buf: Pointer to HBQ buffer.
  1652. *
  1653. * This function is called with the hbalock held to post an RQE to the SLI4
  1654. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1655. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1656. **/
  1657. static int
  1658. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1659. struct hbq_dmabuf *hbq_buf)
  1660. {
  1661. int rc;
  1662. struct lpfc_rqe hrqe;
  1663. struct lpfc_rqe drqe;
  1664. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1665. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1666. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1667. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1668. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1669. &hrqe, &drqe);
  1670. if (rc < 0)
  1671. return rc;
  1672. hbq_buf->tag = rc;
  1673. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1674. return 0;
  1675. }
  1676. /* HBQ for ELS and CT traffic. */
  1677. static struct lpfc_hbq_init lpfc_els_hbq = {
  1678. .rn = 1,
  1679. .entry_count = 256,
  1680. .mask_count = 0,
  1681. .profile = 0,
  1682. .ring_mask = (1 << LPFC_ELS_RING),
  1683. .buffer_count = 0,
  1684. .init_count = 40,
  1685. .add_count = 40,
  1686. };
  1687. /* HBQ for the extra ring if needed */
  1688. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1689. .rn = 1,
  1690. .entry_count = 200,
  1691. .mask_count = 0,
  1692. .profile = 0,
  1693. .ring_mask = (1 << LPFC_EXTRA_RING),
  1694. .buffer_count = 0,
  1695. .init_count = 0,
  1696. .add_count = 5,
  1697. };
  1698. /* Array of HBQs */
  1699. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1700. &lpfc_els_hbq,
  1701. &lpfc_extra_hbq,
  1702. };
  1703. /**
  1704. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1705. * @phba: Pointer to HBA context object.
  1706. * @hbqno: HBQ number.
  1707. * @count: Number of HBQ buffers to be posted.
  1708. *
  1709. * This function is called with no lock held to post more hbq buffers to the
  1710. * given HBQ. The function returns the number of HBQ buffers successfully
  1711. * posted.
  1712. **/
  1713. static int
  1714. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1715. {
  1716. uint32_t i, posted = 0;
  1717. unsigned long flags;
  1718. struct hbq_dmabuf *hbq_buffer;
  1719. LIST_HEAD(hbq_buf_list);
  1720. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1721. return 0;
  1722. if ((phba->hbqs[hbqno].buffer_count + count) >
  1723. lpfc_hbq_defs[hbqno]->entry_count)
  1724. count = lpfc_hbq_defs[hbqno]->entry_count -
  1725. phba->hbqs[hbqno].buffer_count;
  1726. if (!count)
  1727. return 0;
  1728. /* Allocate HBQ entries */
  1729. for (i = 0; i < count; i++) {
  1730. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1731. if (!hbq_buffer)
  1732. break;
  1733. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1734. }
  1735. /* Check whether HBQ is still in use */
  1736. spin_lock_irqsave(&phba->hbalock, flags);
  1737. if (!phba->hbq_in_use)
  1738. goto err;
  1739. while (!list_empty(&hbq_buf_list)) {
  1740. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1741. dbuf.list);
  1742. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1743. (hbqno << 16));
  1744. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1745. phba->hbqs[hbqno].buffer_count++;
  1746. posted++;
  1747. } else
  1748. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1749. }
  1750. spin_unlock_irqrestore(&phba->hbalock, flags);
  1751. return posted;
  1752. err:
  1753. spin_unlock_irqrestore(&phba->hbalock, flags);
  1754. while (!list_empty(&hbq_buf_list)) {
  1755. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1756. dbuf.list);
  1757. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1758. }
  1759. return 0;
  1760. }
  1761. /**
  1762. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1763. * @phba: Pointer to HBA context object.
  1764. * @qno: HBQ number.
  1765. *
  1766. * This function posts more buffers to the HBQ. This function
  1767. * is called with no lock held. The function returns the number of HBQ entries
  1768. * successfully allocated.
  1769. **/
  1770. int
  1771. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1772. {
  1773. if (phba->sli_rev == LPFC_SLI_REV4)
  1774. return 0;
  1775. else
  1776. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1777. lpfc_hbq_defs[qno]->add_count);
  1778. }
  1779. /**
  1780. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1781. * @phba: Pointer to HBA context object.
  1782. * @qno: HBQ queue number.
  1783. *
  1784. * This function is called from SLI initialization code path with
  1785. * no lock held to post initial HBQ buffers to firmware. The
  1786. * function returns the number of HBQ entries successfully allocated.
  1787. **/
  1788. static int
  1789. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1790. {
  1791. if (phba->sli_rev == LPFC_SLI_REV4)
  1792. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1793. lpfc_hbq_defs[qno]->entry_count);
  1794. else
  1795. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1796. lpfc_hbq_defs[qno]->init_count);
  1797. }
  1798. /**
  1799. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1800. * @phba: Pointer to HBA context object.
  1801. * @hbqno: HBQ number.
  1802. *
  1803. * This function removes the first hbq buffer on an hbq list and returns a
  1804. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1805. **/
  1806. static struct hbq_dmabuf *
  1807. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1808. {
  1809. struct lpfc_dmabuf *d_buf;
  1810. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1811. if (!d_buf)
  1812. return NULL;
  1813. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1814. }
  1815. /**
  1816. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1817. * @phba: Pointer to HBA context object.
  1818. * @tag: Tag of the hbq buffer.
  1819. *
  1820. * This function is called with hbalock held. This function searches
  1821. * for the hbq buffer associated with the given tag in the hbq buffer
  1822. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1823. * it returns NULL.
  1824. **/
  1825. static struct hbq_dmabuf *
  1826. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1827. {
  1828. struct lpfc_dmabuf *d_buf;
  1829. struct hbq_dmabuf *hbq_buf;
  1830. uint32_t hbqno;
  1831. hbqno = tag >> 16;
  1832. if (hbqno >= LPFC_MAX_HBQS)
  1833. return NULL;
  1834. spin_lock_irq(&phba->hbalock);
  1835. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1836. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1837. if (hbq_buf->tag == tag) {
  1838. spin_unlock_irq(&phba->hbalock);
  1839. return hbq_buf;
  1840. }
  1841. }
  1842. spin_unlock_irq(&phba->hbalock);
  1843. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1844. "1803 Bad hbq tag. Data: x%x x%x\n",
  1845. tag, phba->hbqs[tag >> 16].buffer_count);
  1846. return NULL;
  1847. }
  1848. /**
  1849. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1850. * @phba: Pointer to HBA context object.
  1851. * @hbq_buffer: Pointer to HBQ buffer.
  1852. *
  1853. * This function is called with hbalock. This function gives back
  1854. * the hbq buffer to firmware. If the HBQ does not have space to
  1855. * post the buffer, it will free the buffer.
  1856. **/
  1857. void
  1858. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1859. {
  1860. uint32_t hbqno;
  1861. if (hbq_buffer) {
  1862. hbqno = hbq_buffer->tag >> 16;
  1863. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1864. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1865. }
  1866. }
  1867. /**
  1868. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1869. * @mbxCommand: mailbox command code.
  1870. *
  1871. * This function is called by the mailbox event handler function to verify
  1872. * that the completed mailbox command is a legitimate mailbox command. If the
  1873. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1874. * and the mailbox event handler will take the HBA offline.
  1875. **/
  1876. static int
  1877. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1878. {
  1879. uint8_t ret;
  1880. switch (mbxCommand) {
  1881. case MBX_LOAD_SM:
  1882. case MBX_READ_NV:
  1883. case MBX_WRITE_NV:
  1884. case MBX_WRITE_VPARMS:
  1885. case MBX_RUN_BIU_DIAG:
  1886. case MBX_INIT_LINK:
  1887. case MBX_DOWN_LINK:
  1888. case MBX_CONFIG_LINK:
  1889. case MBX_CONFIG_RING:
  1890. case MBX_RESET_RING:
  1891. case MBX_READ_CONFIG:
  1892. case MBX_READ_RCONFIG:
  1893. case MBX_READ_SPARM:
  1894. case MBX_READ_STATUS:
  1895. case MBX_READ_RPI:
  1896. case MBX_READ_XRI:
  1897. case MBX_READ_REV:
  1898. case MBX_READ_LNK_STAT:
  1899. case MBX_REG_LOGIN:
  1900. case MBX_UNREG_LOGIN:
  1901. case MBX_CLEAR_LA:
  1902. case MBX_DUMP_MEMORY:
  1903. case MBX_DUMP_CONTEXT:
  1904. case MBX_RUN_DIAGS:
  1905. case MBX_RESTART:
  1906. case MBX_UPDATE_CFG:
  1907. case MBX_DOWN_LOAD:
  1908. case MBX_DEL_LD_ENTRY:
  1909. case MBX_RUN_PROGRAM:
  1910. case MBX_SET_MASK:
  1911. case MBX_SET_VARIABLE:
  1912. case MBX_UNREG_D_ID:
  1913. case MBX_KILL_BOARD:
  1914. case MBX_CONFIG_FARP:
  1915. case MBX_BEACON:
  1916. case MBX_LOAD_AREA:
  1917. case MBX_RUN_BIU_DIAG64:
  1918. case MBX_CONFIG_PORT:
  1919. case MBX_READ_SPARM64:
  1920. case MBX_READ_RPI64:
  1921. case MBX_REG_LOGIN64:
  1922. case MBX_READ_TOPOLOGY:
  1923. case MBX_WRITE_WWN:
  1924. case MBX_SET_DEBUG:
  1925. case MBX_LOAD_EXP_ROM:
  1926. case MBX_ASYNCEVT_ENABLE:
  1927. case MBX_REG_VPI:
  1928. case MBX_UNREG_VPI:
  1929. case MBX_HEARTBEAT:
  1930. case MBX_PORT_CAPABILITIES:
  1931. case MBX_PORT_IOV_CONTROL:
  1932. case MBX_SLI4_CONFIG:
  1933. case MBX_SLI4_REQ_FTRS:
  1934. case MBX_REG_FCFI:
  1935. case MBX_UNREG_FCFI:
  1936. case MBX_REG_VFI:
  1937. case MBX_UNREG_VFI:
  1938. case MBX_INIT_VPI:
  1939. case MBX_INIT_VFI:
  1940. case MBX_RESUME_RPI:
  1941. case MBX_READ_EVENT_LOG_STATUS:
  1942. case MBX_READ_EVENT_LOG:
  1943. case MBX_SECURITY_MGMT:
  1944. case MBX_AUTH_PORT:
  1945. case MBX_ACCESS_VDATA:
  1946. ret = mbxCommand;
  1947. break;
  1948. default:
  1949. ret = MBX_SHUTDOWN;
  1950. break;
  1951. }
  1952. return ret;
  1953. }
  1954. /**
  1955. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1956. * @phba: Pointer to HBA context object.
  1957. * @pmboxq: Pointer to mailbox command.
  1958. *
  1959. * This is completion handler function for mailbox commands issued from
  1960. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1961. * mailbox event handler function with no lock held. This function
  1962. * will wake up thread waiting on the wait queue pointed by context1
  1963. * of the mailbox.
  1964. **/
  1965. void
  1966. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1967. {
  1968. wait_queue_head_t *pdone_q;
  1969. unsigned long drvr_flag;
  1970. /*
  1971. * If pdone_q is empty, the driver thread gave up waiting and
  1972. * continued running.
  1973. */
  1974. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1975. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1976. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1977. if (pdone_q)
  1978. wake_up_interruptible(pdone_q);
  1979. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1980. return;
  1981. }
  1982. /**
  1983. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1984. * @phba: Pointer to HBA context object.
  1985. * @pmb: Pointer to mailbox object.
  1986. *
  1987. * This function is the default mailbox completion handler. It
  1988. * frees the memory resources associated with the completed mailbox
  1989. * command. If the completed command is a REG_LOGIN mailbox command,
  1990. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1991. **/
  1992. void
  1993. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1994. {
  1995. struct lpfc_vport *vport = pmb->vport;
  1996. struct lpfc_dmabuf *mp;
  1997. struct lpfc_nodelist *ndlp;
  1998. struct Scsi_Host *shost;
  1999. uint16_t rpi, vpi;
  2000. int rc;
  2001. mp = (struct lpfc_dmabuf *) (pmb->context1);
  2002. if (mp) {
  2003. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2004. kfree(mp);
  2005. }
  2006. /*
  2007. * If a REG_LOGIN succeeded after node is destroyed or node
  2008. * is in re-discovery driver need to cleanup the RPI.
  2009. */
  2010. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  2011. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  2012. !pmb->u.mb.mbxStatus) {
  2013. rpi = pmb->u.mb.un.varWords[0];
  2014. vpi = pmb->u.mb.un.varRegLogin.vpi;
  2015. lpfc_unreg_login(phba, vpi, rpi, pmb);
  2016. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2017. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2018. if (rc != MBX_NOT_FINISHED)
  2019. return;
  2020. }
  2021. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  2022. !(phba->pport->load_flag & FC_UNLOADING) &&
  2023. !pmb->u.mb.mbxStatus) {
  2024. shost = lpfc_shost_from_vport(vport);
  2025. spin_lock_irq(shost->host_lock);
  2026. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2027. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  2028. spin_unlock_irq(shost->host_lock);
  2029. }
  2030. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  2031. ndlp = (struct lpfc_nodelist *)pmb->context2;
  2032. lpfc_nlp_put(ndlp);
  2033. pmb->context2 = NULL;
  2034. }
  2035. /* Check security permission status on INIT_LINK mailbox command */
  2036. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  2037. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  2038. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2039. "2860 SLI authentication is required "
  2040. "for INIT_LINK but has not done yet\n");
  2041. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  2042. lpfc_sli4_mbox_cmd_free(phba, pmb);
  2043. else
  2044. mempool_free(pmb, phba->mbox_mem_pool);
  2045. }
  2046. /**
  2047. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  2048. * @phba: Pointer to HBA context object.
  2049. *
  2050. * This function is called with no lock held. This function processes all
  2051. * the completed mailbox commands and gives it to upper layers. The interrupt
  2052. * service routine processes mailbox completion interrupt and adds completed
  2053. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  2054. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  2055. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  2056. * function returns the mailbox commands to the upper layer by calling the
  2057. * completion handler function of each mailbox.
  2058. **/
  2059. int
  2060. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2061. {
  2062. MAILBOX_t *pmbox;
  2063. LPFC_MBOXQ_t *pmb;
  2064. int rc;
  2065. LIST_HEAD(cmplq);
  2066. phba->sli.slistat.mbox_event++;
  2067. /* Get all completed mailboxe buffers into the cmplq */
  2068. spin_lock_irq(&phba->hbalock);
  2069. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2070. spin_unlock_irq(&phba->hbalock);
  2071. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2072. do {
  2073. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2074. if (pmb == NULL)
  2075. break;
  2076. pmbox = &pmb->u.mb;
  2077. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2078. if (pmb->vport) {
  2079. lpfc_debugfs_disc_trc(pmb->vport,
  2080. LPFC_DISC_TRC_MBOX_VPORT,
  2081. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2082. (uint32_t)pmbox->mbxCommand,
  2083. pmbox->un.varWords[0],
  2084. pmbox->un.varWords[1]);
  2085. }
  2086. else {
  2087. lpfc_debugfs_disc_trc(phba->pport,
  2088. LPFC_DISC_TRC_MBOX,
  2089. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2090. (uint32_t)pmbox->mbxCommand,
  2091. pmbox->un.varWords[0],
  2092. pmbox->un.varWords[1]);
  2093. }
  2094. }
  2095. /*
  2096. * It is a fatal error if unknown mbox command completion.
  2097. */
  2098. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2099. MBX_SHUTDOWN) {
  2100. /* Unknown mailbox command compl */
  2101. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2102. "(%d):0323 Unknown Mailbox command "
  2103. "x%x (x%x/x%x) Cmpl\n",
  2104. pmb->vport ? pmb->vport->vpi : 0,
  2105. pmbox->mbxCommand,
  2106. lpfc_sli_config_mbox_subsys_get(phba,
  2107. pmb),
  2108. lpfc_sli_config_mbox_opcode_get(phba,
  2109. pmb));
  2110. phba->link_state = LPFC_HBA_ERROR;
  2111. phba->work_hs = HS_FFER3;
  2112. lpfc_handle_eratt(phba);
  2113. continue;
  2114. }
  2115. if (pmbox->mbxStatus) {
  2116. phba->sli.slistat.mbox_stat_err++;
  2117. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2118. /* Mbox cmd cmpl error - RETRYing */
  2119. lpfc_printf_log(phba, KERN_INFO,
  2120. LOG_MBOX | LOG_SLI,
  2121. "(%d):0305 Mbox cmd cmpl "
  2122. "error - RETRYing Data: x%x "
  2123. "(x%x/x%x) x%x x%x x%x\n",
  2124. pmb->vport ? pmb->vport->vpi : 0,
  2125. pmbox->mbxCommand,
  2126. lpfc_sli_config_mbox_subsys_get(phba,
  2127. pmb),
  2128. lpfc_sli_config_mbox_opcode_get(phba,
  2129. pmb),
  2130. pmbox->mbxStatus,
  2131. pmbox->un.varWords[0],
  2132. pmb->vport->port_state);
  2133. pmbox->mbxStatus = 0;
  2134. pmbox->mbxOwner = OWN_HOST;
  2135. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2136. if (rc != MBX_NOT_FINISHED)
  2137. continue;
  2138. }
  2139. }
  2140. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2141. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2142. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
  2143. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  2144. "x%x x%x x%x\n",
  2145. pmb->vport ? pmb->vport->vpi : 0,
  2146. pmbox->mbxCommand,
  2147. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2148. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2149. pmb->mbox_cmpl,
  2150. *((uint32_t *) pmbox),
  2151. pmbox->un.varWords[0],
  2152. pmbox->un.varWords[1],
  2153. pmbox->un.varWords[2],
  2154. pmbox->un.varWords[3],
  2155. pmbox->un.varWords[4],
  2156. pmbox->un.varWords[5],
  2157. pmbox->un.varWords[6],
  2158. pmbox->un.varWords[7],
  2159. pmbox->un.varWords[8],
  2160. pmbox->un.varWords[9],
  2161. pmbox->un.varWords[10]);
  2162. if (pmb->mbox_cmpl)
  2163. pmb->mbox_cmpl(phba,pmb);
  2164. } while (1);
  2165. return 0;
  2166. }
  2167. /**
  2168. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2169. * @phba: Pointer to HBA context object.
  2170. * @pring: Pointer to driver SLI ring object.
  2171. * @tag: buffer tag.
  2172. *
  2173. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2174. * is set in the tag the buffer is posted for a particular exchange,
  2175. * the function will return the buffer without replacing the buffer.
  2176. * If the buffer is for unsolicited ELS or CT traffic, this function
  2177. * returns the buffer and also posts another buffer to the firmware.
  2178. **/
  2179. static struct lpfc_dmabuf *
  2180. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2181. struct lpfc_sli_ring *pring,
  2182. uint32_t tag)
  2183. {
  2184. struct hbq_dmabuf *hbq_entry;
  2185. if (tag & QUE_BUFTAG_BIT)
  2186. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2187. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2188. if (!hbq_entry)
  2189. return NULL;
  2190. return &hbq_entry->dbuf;
  2191. }
  2192. /**
  2193. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2194. * @phba: Pointer to HBA context object.
  2195. * @pring: Pointer to driver SLI ring object.
  2196. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2197. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2198. * @fch_type: the type for the first frame of the sequence.
  2199. *
  2200. * This function is called with no lock held. This function uses the r_ctl and
  2201. * type of the received sequence to find the correct callback function to call
  2202. * to process the sequence.
  2203. **/
  2204. static int
  2205. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2206. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2207. uint32_t fch_type)
  2208. {
  2209. int i;
  2210. /* unSolicited Responses */
  2211. if (pring->prt[0].profile) {
  2212. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2213. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2214. saveq);
  2215. return 1;
  2216. }
  2217. /* We must search, based on rctl / type
  2218. for the right routine */
  2219. for (i = 0; i < pring->num_mask; i++) {
  2220. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2221. (pring->prt[i].type == fch_type)) {
  2222. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2223. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2224. (phba, pring, saveq);
  2225. return 1;
  2226. }
  2227. }
  2228. return 0;
  2229. }
  2230. /**
  2231. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2232. * @phba: Pointer to HBA context object.
  2233. * @pring: Pointer to driver SLI ring object.
  2234. * @saveq: Pointer to the unsolicited iocb.
  2235. *
  2236. * This function is called with no lock held by the ring event handler
  2237. * when there is an unsolicited iocb posted to the response ring by the
  2238. * firmware. This function gets the buffer associated with the iocbs
  2239. * and calls the event handler for the ring. This function handles both
  2240. * qring buffers and hbq buffers.
  2241. * When the function returns 1 the caller can free the iocb object otherwise
  2242. * upper layer functions will free the iocb objects.
  2243. **/
  2244. static int
  2245. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2246. struct lpfc_iocbq *saveq)
  2247. {
  2248. IOCB_t * irsp;
  2249. WORD5 * w5p;
  2250. uint32_t Rctl, Type;
  2251. uint32_t match;
  2252. struct lpfc_iocbq *iocbq;
  2253. struct lpfc_dmabuf *dmzbuf;
  2254. match = 0;
  2255. irsp = &(saveq->iocb);
  2256. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2257. if (pring->lpfc_sli_rcv_async_status)
  2258. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2259. else
  2260. lpfc_printf_log(phba,
  2261. KERN_WARNING,
  2262. LOG_SLI,
  2263. "0316 Ring %d handler: unexpected "
  2264. "ASYNC_STATUS iocb received evt_code "
  2265. "0x%x\n",
  2266. pring->ringno,
  2267. irsp->un.asyncstat.evt_code);
  2268. return 1;
  2269. }
  2270. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2271. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2272. if (irsp->ulpBdeCount > 0) {
  2273. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2274. irsp->un.ulpWord[3]);
  2275. lpfc_in_buf_free(phba, dmzbuf);
  2276. }
  2277. if (irsp->ulpBdeCount > 1) {
  2278. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2279. irsp->unsli3.sli3Words[3]);
  2280. lpfc_in_buf_free(phba, dmzbuf);
  2281. }
  2282. if (irsp->ulpBdeCount > 2) {
  2283. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2284. irsp->unsli3.sli3Words[7]);
  2285. lpfc_in_buf_free(phba, dmzbuf);
  2286. }
  2287. return 1;
  2288. }
  2289. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2290. if (irsp->ulpBdeCount != 0) {
  2291. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2292. irsp->un.ulpWord[3]);
  2293. if (!saveq->context2)
  2294. lpfc_printf_log(phba,
  2295. KERN_ERR,
  2296. LOG_SLI,
  2297. "0341 Ring %d Cannot find buffer for "
  2298. "an unsolicited iocb. tag 0x%x\n",
  2299. pring->ringno,
  2300. irsp->un.ulpWord[3]);
  2301. }
  2302. if (irsp->ulpBdeCount == 2) {
  2303. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2304. irsp->unsli3.sli3Words[7]);
  2305. if (!saveq->context3)
  2306. lpfc_printf_log(phba,
  2307. KERN_ERR,
  2308. LOG_SLI,
  2309. "0342 Ring %d Cannot find buffer for an"
  2310. " unsolicited iocb. tag 0x%x\n",
  2311. pring->ringno,
  2312. irsp->unsli3.sli3Words[7]);
  2313. }
  2314. list_for_each_entry(iocbq, &saveq->list, list) {
  2315. irsp = &(iocbq->iocb);
  2316. if (irsp->ulpBdeCount != 0) {
  2317. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2318. irsp->un.ulpWord[3]);
  2319. if (!iocbq->context2)
  2320. lpfc_printf_log(phba,
  2321. KERN_ERR,
  2322. LOG_SLI,
  2323. "0343 Ring %d Cannot find "
  2324. "buffer for an unsolicited iocb"
  2325. ". tag 0x%x\n", pring->ringno,
  2326. irsp->un.ulpWord[3]);
  2327. }
  2328. if (irsp->ulpBdeCount == 2) {
  2329. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2330. irsp->unsli3.sli3Words[7]);
  2331. if (!iocbq->context3)
  2332. lpfc_printf_log(phba,
  2333. KERN_ERR,
  2334. LOG_SLI,
  2335. "0344 Ring %d Cannot find "
  2336. "buffer for an unsolicited "
  2337. "iocb. tag 0x%x\n",
  2338. pring->ringno,
  2339. irsp->unsli3.sli3Words[7]);
  2340. }
  2341. }
  2342. }
  2343. if (irsp->ulpBdeCount != 0 &&
  2344. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2345. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2346. int found = 0;
  2347. /* search continue save q for same XRI */
  2348. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2349. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  2350. saveq->iocb.unsli3.rcvsli3.ox_id) {
  2351. list_add_tail(&saveq->list, &iocbq->list);
  2352. found = 1;
  2353. break;
  2354. }
  2355. }
  2356. if (!found)
  2357. list_add_tail(&saveq->clist,
  2358. &pring->iocb_continue_saveq);
  2359. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2360. list_del_init(&iocbq->clist);
  2361. saveq = iocbq;
  2362. irsp = &(saveq->iocb);
  2363. } else
  2364. return 0;
  2365. }
  2366. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2367. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2368. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2369. Rctl = FC_RCTL_ELS_REQ;
  2370. Type = FC_TYPE_ELS;
  2371. } else {
  2372. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2373. Rctl = w5p->hcsw.Rctl;
  2374. Type = w5p->hcsw.Type;
  2375. /* Firmware Workaround */
  2376. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2377. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2378. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2379. Rctl = FC_RCTL_ELS_REQ;
  2380. Type = FC_TYPE_ELS;
  2381. w5p->hcsw.Rctl = Rctl;
  2382. w5p->hcsw.Type = Type;
  2383. }
  2384. }
  2385. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2386. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2387. "0313 Ring %d handler: unexpected Rctl x%x "
  2388. "Type x%x received\n",
  2389. pring->ringno, Rctl, Type);
  2390. return 1;
  2391. }
  2392. /**
  2393. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2394. * @phba: Pointer to HBA context object.
  2395. * @pring: Pointer to driver SLI ring object.
  2396. * @prspiocb: Pointer to response iocb object.
  2397. *
  2398. * This function looks up the iocb_lookup table to get the command iocb
  2399. * corresponding to the given response iocb using the iotag of the
  2400. * response iocb. This function is called with the hbalock held.
  2401. * This function returns the command iocb object if it finds the command
  2402. * iocb else returns NULL.
  2403. **/
  2404. static struct lpfc_iocbq *
  2405. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2406. struct lpfc_sli_ring *pring,
  2407. struct lpfc_iocbq *prspiocb)
  2408. {
  2409. struct lpfc_iocbq *cmd_iocb = NULL;
  2410. uint16_t iotag;
  2411. iotag = prspiocb->iocb.ulpIoTag;
  2412. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2413. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2414. list_del_init(&cmd_iocb->list);
  2415. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2416. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2417. }
  2418. return cmd_iocb;
  2419. }
  2420. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2421. "0317 iotag x%x is out off "
  2422. "range: max iotag x%x wd0 x%x\n",
  2423. iotag, phba->sli.last_iotag,
  2424. *(((uint32_t *) &prspiocb->iocb) + 7));
  2425. return NULL;
  2426. }
  2427. /**
  2428. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2429. * @phba: Pointer to HBA context object.
  2430. * @pring: Pointer to driver SLI ring object.
  2431. * @iotag: IOCB tag.
  2432. *
  2433. * This function looks up the iocb_lookup table to get the command iocb
  2434. * corresponding to the given iotag. This function is called with the
  2435. * hbalock held.
  2436. * This function returns the command iocb object if it finds the command
  2437. * iocb else returns NULL.
  2438. **/
  2439. static struct lpfc_iocbq *
  2440. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2441. struct lpfc_sli_ring *pring, uint16_t iotag)
  2442. {
  2443. struct lpfc_iocbq *cmd_iocb;
  2444. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2445. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2446. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2447. /* remove from txcmpl queue list */
  2448. list_del_init(&cmd_iocb->list);
  2449. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2450. return cmd_iocb;
  2451. }
  2452. }
  2453. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2454. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2455. iotag, phba->sli.last_iotag);
  2456. return NULL;
  2457. }
  2458. /**
  2459. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2460. * @phba: Pointer to HBA context object.
  2461. * @pring: Pointer to driver SLI ring object.
  2462. * @saveq: Pointer to the response iocb to be processed.
  2463. *
  2464. * This function is called by the ring event handler for non-fcp
  2465. * rings when there is a new response iocb in the response ring.
  2466. * The caller is not required to hold any locks. This function
  2467. * gets the command iocb associated with the response iocb and
  2468. * calls the completion handler for the command iocb. If there
  2469. * is no completion handler, the function will free the resources
  2470. * associated with command iocb. If the response iocb is for
  2471. * an already aborted command iocb, the status of the completion
  2472. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2473. * This function always returns 1.
  2474. **/
  2475. static int
  2476. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2477. struct lpfc_iocbq *saveq)
  2478. {
  2479. struct lpfc_iocbq *cmdiocbp;
  2480. int rc = 1;
  2481. unsigned long iflag;
  2482. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2483. spin_lock_irqsave(&phba->hbalock, iflag);
  2484. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2485. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2486. if (cmdiocbp) {
  2487. if (cmdiocbp->iocb_cmpl) {
  2488. /*
  2489. * If an ELS command failed send an event to mgmt
  2490. * application.
  2491. */
  2492. if (saveq->iocb.ulpStatus &&
  2493. (pring->ringno == LPFC_ELS_RING) &&
  2494. (cmdiocbp->iocb.ulpCommand ==
  2495. CMD_ELS_REQUEST64_CR))
  2496. lpfc_send_els_failure_event(phba,
  2497. cmdiocbp, saveq);
  2498. /*
  2499. * Post all ELS completions to the worker thread.
  2500. * All other are passed to the completion callback.
  2501. */
  2502. if (pring->ringno == LPFC_ELS_RING) {
  2503. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2504. (cmdiocbp->iocb_flag &
  2505. LPFC_DRIVER_ABORTED)) {
  2506. spin_lock_irqsave(&phba->hbalock,
  2507. iflag);
  2508. cmdiocbp->iocb_flag &=
  2509. ~LPFC_DRIVER_ABORTED;
  2510. spin_unlock_irqrestore(&phba->hbalock,
  2511. iflag);
  2512. saveq->iocb.ulpStatus =
  2513. IOSTAT_LOCAL_REJECT;
  2514. saveq->iocb.un.ulpWord[4] =
  2515. IOERR_SLI_ABORTED;
  2516. /* Firmware could still be in progress
  2517. * of DMAing payload, so don't free data
  2518. * buffer till after a hbeat.
  2519. */
  2520. spin_lock_irqsave(&phba->hbalock,
  2521. iflag);
  2522. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2523. spin_unlock_irqrestore(&phba->hbalock,
  2524. iflag);
  2525. }
  2526. if (phba->sli_rev == LPFC_SLI_REV4) {
  2527. if (saveq->iocb_flag &
  2528. LPFC_EXCHANGE_BUSY) {
  2529. /* Set cmdiocb flag for the
  2530. * exchange busy so sgl (xri)
  2531. * will not be released until
  2532. * the abort xri is received
  2533. * from hba.
  2534. */
  2535. spin_lock_irqsave(
  2536. &phba->hbalock, iflag);
  2537. cmdiocbp->iocb_flag |=
  2538. LPFC_EXCHANGE_BUSY;
  2539. spin_unlock_irqrestore(
  2540. &phba->hbalock, iflag);
  2541. }
  2542. if (cmdiocbp->iocb_flag &
  2543. LPFC_DRIVER_ABORTED) {
  2544. /*
  2545. * Clear LPFC_DRIVER_ABORTED
  2546. * bit in case it was driver
  2547. * initiated abort.
  2548. */
  2549. spin_lock_irqsave(
  2550. &phba->hbalock, iflag);
  2551. cmdiocbp->iocb_flag &=
  2552. ~LPFC_DRIVER_ABORTED;
  2553. spin_unlock_irqrestore(
  2554. &phba->hbalock, iflag);
  2555. cmdiocbp->iocb.ulpStatus =
  2556. IOSTAT_LOCAL_REJECT;
  2557. cmdiocbp->iocb.un.ulpWord[4] =
  2558. IOERR_ABORT_REQUESTED;
  2559. /*
  2560. * For SLI4, irsiocb contains
  2561. * NO_XRI in sli_xritag, it
  2562. * shall not affect releasing
  2563. * sgl (xri) process.
  2564. */
  2565. saveq->iocb.ulpStatus =
  2566. IOSTAT_LOCAL_REJECT;
  2567. saveq->iocb.un.ulpWord[4] =
  2568. IOERR_SLI_ABORTED;
  2569. spin_lock_irqsave(
  2570. &phba->hbalock, iflag);
  2571. saveq->iocb_flag |=
  2572. LPFC_DELAY_MEM_FREE;
  2573. spin_unlock_irqrestore(
  2574. &phba->hbalock, iflag);
  2575. }
  2576. }
  2577. }
  2578. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2579. } else
  2580. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2581. } else {
  2582. /*
  2583. * Unknown initiating command based on the response iotag.
  2584. * This could be the case on the ELS ring because of
  2585. * lpfc_els_abort().
  2586. */
  2587. if (pring->ringno != LPFC_ELS_RING) {
  2588. /*
  2589. * Ring <ringno> handler: unexpected completion IoTag
  2590. * <IoTag>
  2591. */
  2592. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2593. "0322 Ring %d handler: "
  2594. "unexpected completion IoTag x%x "
  2595. "Data: x%x x%x x%x x%x\n",
  2596. pring->ringno,
  2597. saveq->iocb.ulpIoTag,
  2598. saveq->iocb.ulpStatus,
  2599. saveq->iocb.un.ulpWord[4],
  2600. saveq->iocb.ulpCommand,
  2601. saveq->iocb.ulpContext);
  2602. }
  2603. }
  2604. return rc;
  2605. }
  2606. /**
  2607. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2608. * @phba: Pointer to HBA context object.
  2609. * @pring: Pointer to driver SLI ring object.
  2610. *
  2611. * This function is called from the iocb ring event handlers when
  2612. * put pointer is ahead of the get pointer for a ring. This function signal
  2613. * an error attention condition to the worker thread and the worker
  2614. * thread will transition the HBA to offline state.
  2615. **/
  2616. static void
  2617. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2618. {
  2619. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2620. /*
  2621. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2622. * rsp ring <portRspMax>
  2623. */
  2624. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2625. "0312 Ring %d handler: portRspPut %d "
  2626. "is bigger than rsp ring %d\n",
  2627. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2628. pring->sli.sli3.numRiocb);
  2629. phba->link_state = LPFC_HBA_ERROR;
  2630. /*
  2631. * All error attention handlers are posted to
  2632. * worker thread
  2633. */
  2634. phba->work_ha |= HA_ERATT;
  2635. phba->work_hs = HS_FFER3;
  2636. lpfc_worker_wake_up(phba);
  2637. return;
  2638. }
  2639. /**
  2640. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2641. * @ptr: Pointer to address of HBA context object.
  2642. *
  2643. * This function is invoked by the Error Attention polling timer when the
  2644. * timer times out. It will check the SLI Error Attention register for
  2645. * possible attention events. If so, it will post an Error Attention event
  2646. * and wake up worker thread to process it. Otherwise, it will set up the
  2647. * Error Attention polling timer for the next poll.
  2648. **/
  2649. void lpfc_poll_eratt(unsigned long ptr)
  2650. {
  2651. struct lpfc_hba *phba;
  2652. uint32_t eratt = 0, rem;
  2653. uint64_t sli_intr, cnt;
  2654. phba = (struct lpfc_hba *)ptr;
  2655. /* Here we will also keep track of interrupts per sec of the hba */
  2656. sli_intr = phba->sli.slistat.sli_intr;
  2657. if (phba->sli.slistat.sli_prev_intr > sli_intr)
  2658. cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
  2659. sli_intr);
  2660. else
  2661. cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
  2662. /* 64-bit integer division not supporte on 32-bit x86 - use do_div */
  2663. rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL);
  2664. phba->sli.slistat.sli_ips = cnt;
  2665. phba->sli.slistat.sli_prev_intr = sli_intr;
  2666. /* Check chip HA register for error event */
  2667. eratt = lpfc_sli_check_eratt(phba);
  2668. if (eratt)
  2669. /* Tell the worker thread there is work to do */
  2670. lpfc_worker_wake_up(phba);
  2671. else
  2672. /* Restart the timer for next eratt poll */
  2673. mod_timer(&phba->eratt_poll,
  2674. jiffies +
  2675. msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
  2676. return;
  2677. }
  2678. /**
  2679. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2680. * @phba: Pointer to HBA context object.
  2681. * @pring: Pointer to driver SLI ring object.
  2682. * @mask: Host attention register mask for this ring.
  2683. *
  2684. * This function is called from the interrupt context when there is a ring
  2685. * event for the fcp ring. The caller does not hold any lock.
  2686. * The function processes each response iocb in the response ring until it
  2687. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2688. * LE bit set. The function will call the completion handler of the command iocb
  2689. * if the response iocb indicates a completion for a command iocb or it is
  2690. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2691. * function if this is an unsolicited iocb.
  2692. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2693. * to check it explicitly.
  2694. */
  2695. int
  2696. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2697. struct lpfc_sli_ring *pring, uint32_t mask)
  2698. {
  2699. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2700. IOCB_t *irsp = NULL;
  2701. IOCB_t *entry = NULL;
  2702. struct lpfc_iocbq *cmdiocbq = NULL;
  2703. struct lpfc_iocbq rspiocbq;
  2704. uint32_t status;
  2705. uint32_t portRspPut, portRspMax;
  2706. int rc = 1;
  2707. lpfc_iocb_type type;
  2708. unsigned long iflag;
  2709. uint32_t rsp_cmpl = 0;
  2710. spin_lock_irqsave(&phba->hbalock, iflag);
  2711. pring->stats.iocb_event++;
  2712. /*
  2713. * The next available response entry should never exceed the maximum
  2714. * entries. If it does, treat it as an adapter hardware error.
  2715. */
  2716. portRspMax = pring->sli.sli3.numRiocb;
  2717. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2718. if (unlikely(portRspPut >= portRspMax)) {
  2719. lpfc_sli_rsp_pointers_error(phba, pring);
  2720. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2721. return 1;
  2722. }
  2723. if (phba->fcp_ring_in_use) {
  2724. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2725. return 1;
  2726. } else
  2727. phba->fcp_ring_in_use = 1;
  2728. rmb();
  2729. while (pring->sli.sli3.rspidx != portRspPut) {
  2730. /*
  2731. * Fetch an entry off the ring and copy it into a local data
  2732. * structure. The copy involves a byte-swap since the
  2733. * network byte order and pci byte orders are different.
  2734. */
  2735. entry = lpfc_resp_iocb(phba, pring);
  2736. phba->last_completion_time = jiffies;
  2737. if (++pring->sli.sli3.rspidx >= portRspMax)
  2738. pring->sli.sli3.rspidx = 0;
  2739. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2740. (uint32_t *) &rspiocbq.iocb,
  2741. phba->iocb_rsp_size);
  2742. INIT_LIST_HEAD(&(rspiocbq.list));
  2743. irsp = &rspiocbq.iocb;
  2744. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2745. pring->stats.iocb_rsp++;
  2746. rsp_cmpl++;
  2747. if (unlikely(irsp->ulpStatus)) {
  2748. /*
  2749. * If resource errors reported from HBA, reduce
  2750. * queuedepths of the SCSI device.
  2751. */
  2752. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2753. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2754. IOERR_NO_RESOURCES)) {
  2755. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2756. phba->lpfc_rampdown_queue_depth(phba);
  2757. spin_lock_irqsave(&phba->hbalock, iflag);
  2758. }
  2759. /* Rsp ring <ringno> error: IOCB */
  2760. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2761. "0336 Rsp Ring %d error: IOCB Data: "
  2762. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2763. pring->ringno,
  2764. irsp->un.ulpWord[0],
  2765. irsp->un.ulpWord[1],
  2766. irsp->un.ulpWord[2],
  2767. irsp->un.ulpWord[3],
  2768. irsp->un.ulpWord[4],
  2769. irsp->un.ulpWord[5],
  2770. *(uint32_t *)&irsp->un1,
  2771. *((uint32_t *)&irsp->un1 + 1));
  2772. }
  2773. switch (type) {
  2774. case LPFC_ABORT_IOCB:
  2775. case LPFC_SOL_IOCB:
  2776. /*
  2777. * Idle exchange closed via ABTS from port. No iocb
  2778. * resources need to be recovered.
  2779. */
  2780. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2781. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2782. "0333 IOCB cmd 0x%x"
  2783. " processed. Skipping"
  2784. " completion\n",
  2785. irsp->ulpCommand);
  2786. break;
  2787. }
  2788. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2789. &rspiocbq);
  2790. if (unlikely(!cmdiocbq))
  2791. break;
  2792. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2793. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2794. if (cmdiocbq->iocb_cmpl) {
  2795. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2796. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2797. &rspiocbq);
  2798. spin_lock_irqsave(&phba->hbalock, iflag);
  2799. }
  2800. break;
  2801. case LPFC_UNSOL_IOCB:
  2802. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2803. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2804. spin_lock_irqsave(&phba->hbalock, iflag);
  2805. break;
  2806. default:
  2807. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2808. char adaptermsg[LPFC_MAX_ADPTMSG];
  2809. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2810. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2811. MAX_MSG_DATA);
  2812. dev_warn(&((phba->pcidev)->dev),
  2813. "lpfc%d: %s\n",
  2814. phba->brd_no, adaptermsg);
  2815. } else {
  2816. /* Unknown IOCB command */
  2817. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2818. "0334 Unknown IOCB command "
  2819. "Data: x%x, x%x x%x x%x x%x\n",
  2820. type, irsp->ulpCommand,
  2821. irsp->ulpStatus,
  2822. irsp->ulpIoTag,
  2823. irsp->ulpContext);
  2824. }
  2825. break;
  2826. }
  2827. /*
  2828. * The response IOCB has been processed. Update the ring
  2829. * pointer in SLIM. If the port response put pointer has not
  2830. * been updated, sync the pgp->rspPutInx and fetch the new port
  2831. * response put pointer.
  2832. */
  2833. writel(pring->sli.sli3.rspidx,
  2834. &phba->host_gp[pring->ringno].rspGetInx);
  2835. if (pring->sli.sli3.rspidx == portRspPut)
  2836. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2837. }
  2838. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2839. pring->stats.iocb_rsp_full++;
  2840. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2841. writel(status, phba->CAregaddr);
  2842. readl(phba->CAregaddr);
  2843. }
  2844. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2845. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2846. pring->stats.iocb_cmd_empty++;
  2847. /* Force update of the local copy of cmdGetInx */
  2848. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2849. lpfc_sli_resume_iocb(phba, pring);
  2850. if ((pring->lpfc_sli_cmd_available))
  2851. (pring->lpfc_sli_cmd_available) (phba, pring);
  2852. }
  2853. phba->fcp_ring_in_use = 0;
  2854. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2855. return rc;
  2856. }
  2857. /**
  2858. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2859. * @phba: Pointer to HBA context object.
  2860. * @pring: Pointer to driver SLI ring object.
  2861. * @rspiocbp: Pointer to driver response IOCB object.
  2862. *
  2863. * This function is called from the worker thread when there is a slow-path
  2864. * response IOCB to process. This function chains all the response iocbs until
  2865. * seeing the iocb with the LE bit set. The function will call
  2866. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2867. * completion of a command iocb. The function will call the
  2868. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2869. * The function frees the resources or calls the completion handler if this
  2870. * iocb is an abort completion. The function returns NULL when the response
  2871. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2872. * this function shall chain the iocb on to the iocb_continueq and return the
  2873. * response iocb passed in.
  2874. **/
  2875. static struct lpfc_iocbq *
  2876. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2877. struct lpfc_iocbq *rspiocbp)
  2878. {
  2879. struct lpfc_iocbq *saveq;
  2880. struct lpfc_iocbq *cmdiocbp;
  2881. struct lpfc_iocbq *next_iocb;
  2882. IOCB_t *irsp = NULL;
  2883. uint32_t free_saveq;
  2884. uint8_t iocb_cmd_type;
  2885. lpfc_iocb_type type;
  2886. unsigned long iflag;
  2887. int rc;
  2888. spin_lock_irqsave(&phba->hbalock, iflag);
  2889. /* First add the response iocb to the countinueq list */
  2890. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2891. pring->iocb_continueq_cnt++;
  2892. /* Now, determine whether the list is completed for processing */
  2893. irsp = &rspiocbp->iocb;
  2894. if (irsp->ulpLe) {
  2895. /*
  2896. * By default, the driver expects to free all resources
  2897. * associated with this iocb completion.
  2898. */
  2899. free_saveq = 1;
  2900. saveq = list_get_first(&pring->iocb_continueq,
  2901. struct lpfc_iocbq, list);
  2902. irsp = &(saveq->iocb);
  2903. list_del_init(&pring->iocb_continueq);
  2904. pring->iocb_continueq_cnt = 0;
  2905. pring->stats.iocb_rsp++;
  2906. /*
  2907. * If resource errors reported from HBA, reduce
  2908. * queuedepths of the SCSI device.
  2909. */
  2910. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2911. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2912. IOERR_NO_RESOURCES)) {
  2913. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2914. phba->lpfc_rampdown_queue_depth(phba);
  2915. spin_lock_irqsave(&phba->hbalock, iflag);
  2916. }
  2917. if (irsp->ulpStatus) {
  2918. /* Rsp ring <ringno> error: IOCB */
  2919. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2920. "0328 Rsp Ring %d error: "
  2921. "IOCB Data: "
  2922. "x%x x%x x%x x%x "
  2923. "x%x x%x x%x x%x "
  2924. "x%x x%x x%x x%x "
  2925. "x%x x%x x%x x%x\n",
  2926. pring->ringno,
  2927. irsp->un.ulpWord[0],
  2928. irsp->un.ulpWord[1],
  2929. irsp->un.ulpWord[2],
  2930. irsp->un.ulpWord[3],
  2931. irsp->un.ulpWord[4],
  2932. irsp->un.ulpWord[5],
  2933. *(((uint32_t *) irsp) + 6),
  2934. *(((uint32_t *) irsp) + 7),
  2935. *(((uint32_t *) irsp) + 8),
  2936. *(((uint32_t *) irsp) + 9),
  2937. *(((uint32_t *) irsp) + 10),
  2938. *(((uint32_t *) irsp) + 11),
  2939. *(((uint32_t *) irsp) + 12),
  2940. *(((uint32_t *) irsp) + 13),
  2941. *(((uint32_t *) irsp) + 14),
  2942. *(((uint32_t *) irsp) + 15));
  2943. }
  2944. /*
  2945. * Fetch the IOCB command type and call the correct completion
  2946. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2947. * get freed back to the lpfc_iocb_list by the discovery
  2948. * kernel thread.
  2949. */
  2950. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2951. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2952. switch (type) {
  2953. case LPFC_SOL_IOCB:
  2954. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2955. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2956. spin_lock_irqsave(&phba->hbalock, iflag);
  2957. break;
  2958. case LPFC_UNSOL_IOCB:
  2959. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2960. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2961. spin_lock_irqsave(&phba->hbalock, iflag);
  2962. if (!rc)
  2963. free_saveq = 0;
  2964. break;
  2965. case LPFC_ABORT_IOCB:
  2966. cmdiocbp = NULL;
  2967. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2968. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2969. saveq);
  2970. if (cmdiocbp) {
  2971. /* Call the specified completion routine */
  2972. if (cmdiocbp->iocb_cmpl) {
  2973. spin_unlock_irqrestore(&phba->hbalock,
  2974. iflag);
  2975. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2976. saveq);
  2977. spin_lock_irqsave(&phba->hbalock,
  2978. iflag);
  2979. } else
  2980. __lpfc_sli_release_iocbq(phba,
  2981. cmdiocbp);
  2982. }
  2983. break;
  2984. case LPFC_UNKNOWN_IOCB:
  2985. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2986. char adaptermsg[LPFC_MAX_ADPTMSG];
  2987. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2988. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2989. MAX_MSG_DATA);
  2990. dev_warn(&((phba->pcidev)->dev),
  2991. "lpfc%d: %s\n",
  2992. phba->brd_no, adaptermsg);
  2993. } else {
  2994. /* Unknown IOCB command */
  2995. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2996. "0335 Unknown IOCB "
  2997. "command Data: x%x "
  2998. "x%x x%x x%x\n",
  2999. irsp->ulpCommand,
  3000. irsp->ulpStatus,
  3001. irsp->ulpIoTag,
  3002. irsp->ulpContext);
  3003. }
  3004. break;
  3005. }
  3006. if (free_saveq) {
  3007. list_for_each_entry_safe(rspiocbp, next_iocb,
  3008. &saveq->list, list) {
  3009. list_del(&rspiocbp->list);
  3010. __lpfc_sli_release_iocbq(phba, rspiocbp);
  3011. }
  3012. __lpfc_sli_release_iocbq(phba, saveq);
  3013. }
  3014. rspiocbp = NULL;
  3015. }
  3016. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3017. return rspiocbp;
  3018. }
  3019. /**
  3020. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  3021. * @phba: Pointer to HBA context object.
  3022. * @pring: Pointer to driver SLI ring object.
  3023. * @mask: Host attention register mask for this ring.
  3024. *
  3025. * This routine wraps the actual slow_ring event process routine from the
  3026. * API jump table function pointer from the lpfc_hba struct.
  3027. **/
  3028. void
  3029. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  3030. struct lpfc_sli_ring *pring, uint32_t mask)
  3031. {
  3032. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  3033. }
  3034. /**
  3035. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  3036. * @phba: Pointer to HBA context object.
  3037. * @pring: Pointer to driver SLI ring object.
  3038. * @mask: Host attention register mask for this ring.
  3039. *
  3040. * This function is called from the worker thread when there is a ring event
  3041. * for non-fcp rings. The caller does not hold any lock. The function will
  3042. * remove each response iocb in the response ring and calls the handle
  3043. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3044. **/
  3045. static void
  3046. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  3047. struct lpfc_sli_ring *pring, uint32_t mask)
  3048. {
  3049. struct lpfc_pgp *pgp;
  3050. IOCB_t *entry;
  3051. IOCB_t *irsp = NULL;
  3052. struct lpfc_iocbq *rspiocbp = NULL;
  3053. uint32_t portRspPut, portRspMax;
  3054. unsigned long iflag;
  3055. uint32_t status;
  3056. pgp = &phba->port_gp[pring->ringno];
  3057. spin_lock_irqsave(&phba->hbalock, iflag);
  3058. pring->stats.iocb_event++;
  3059. /*
  3060. * The next available response entry should never exceed the maximum
  3061. * entries. If it does, treat it as an adapter hardware error.
  3062. */
  3063. portRspMax = pring->sli.sli3.numRiocb;
  3064. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3065. if (portRspPut >= portRspMax) {
  3066. /*
  3067. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  3068. * rsp ring <portRspMax>
  3069. */
  3070. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3071. "0303 Ring %d handler: portRspPut %d "
  3072. "is bigger than rsp ring %d\n",
  3073. pring->ringno, portRspPut, portRspMax);
  3074. phba->link_state = LPFC_HBA_ERROR;
  3075. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3076. phba->work_hs = HS_FFER3;
  3077. lpfc_handle_eratt(phba);
  3078. return;
  3079. }
  3080. rmb();
  3081. while (pring->sli.sli3.rspidx != portRspPut) {
  3082. /*
  3083. * Build a completion list and call the appropriate handler.
  3084. * The process is to get the next available response iocb, get
  3085. * a free iocb from the list, copy the response data into the
  3086. * free iocb, insert to the continuation list, and update the
  3087. * next response index to slim. This process makes response
  3088. * iocb's in the ring available to DMA as fast as possible but
  3089. * pays a penalty for a copy operation. Since the iocb is
  3090. * only 32 bytes, this penalty is considered small relative to
  3091. * the PCI reads for register values and a slim write. When
  3092. * the ulpLe field is set, the entire Command has been
  3093. * received.
  3094. */
  3095. entry = lpfc_resp_iocb(phba, pring);
  3096. phba->last_completion_time = jiffies;
  3097. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3098. if (rspiocbp == NULL) {
  3099. printk(KERN_ERR "%s: out of buffers! Failing "
  3100. "completion.\n", __func__);
  3101. break;
  3102. }
  3103. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3104. phba->iocb_rsp_size);
  3105. irsp = &rspiocbp->iocb;
  3106. if (++pring->sli.sli3.rspidx >= portRspMax)
  3107. pring->sli.sli3.rspidx = 0;
  3108. if (pring->ringno == LPFC_ELS_RING) {
  3109. lpfc_debugfs_slow_ring_trc(phba,
  3110. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3111. *(((uint32_t *) irsp) + 4),
  3112. *(((uint32_t *) irsp) + 6),
  3113. *(((uint32_t *) irsp) + 7));
  3114. }
  3115. writel(pring->sli.sli3.rspidx,
  3116. &phba->host_gp[pring->ringno].rspGetInx);
  3117. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3118. /* Handle the response IOCB */
  3119. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3120. spin_lock_irqsave(&phba->hbalock, iflag);
  3121. /*
  3122. * If the port response put pointer has not been updated, sync
  3123. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3124. * response put pointer.
  3125. */
  3126. if (pring->sli.sli3.rspidx == portRspPut) {
  3127. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3128. }
  3129. } /* while (pring->sli.sli3.rspidx != portRspPut) */
  3130. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3131. /* At least one response entry has been freed */
  3132. pring->stats.iocb_rsp_full++;
  3133. /* SET RxRE_RSP in Chip Att register */
  3134. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3135. writel(status, phba->CAregaddr);
  3136. readl(phba->CAregaddr); /* flush */
  3137. }
  3138. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3139. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3140. pring->stats.iocb_cmd_empty++;
  3141. /* Force update of the local copy of cmdGetInx */
  3142. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3143. lpfc_sli_resume_iocb(phba, pring);
  3144. if ((pring->lpfc_sli_cmd_available))
  3145. (pring->lpfc_sli_cmd_available) (phba, pring);
  3146. }
  3147. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3148. return;
  3149. }
  3150. /**
  3151. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3152. * @phba: Pointer to HBA context object.
  3153. * @pring: Pointer to driver SLI ring object.
  3154. * @mask: Host attention register mask for this ring.
  3155. *
  3156. * This function is called from the worker thread when there is a pending
  3157. * ELS response iocb on the driver internal slow-path response iocb worker
  3158. * queue. The caller does not hold any lock. The function will remove each
  3159. * response iocb from the response worker queue and calls the handle
  3160. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3161. **/
  3162. static void
  3163. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3164. struct lpfc_sli_ring *pring, uint32_t mask)
  3165. {
  3166. struct lpfc_iocbq *irspiocbq;
  3167. struct hbq_dmabuf *dmabuf;
  3168. struct lpfc_cq_event *cq_event;
  3169. unsigned long iflag;
  3170. spin_lock_irqsave(&phba->hbalock, iflag);
  3171. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3172. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3173. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3174. /* Get the response iocb from the head of work queue */
  3175. spin_lock_irqsave(&phba->hbalock, iflag);
  3176. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3177. cq_event, struct lpfc_cq_event, list);
  3178. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3179. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3180. case CQE_CODE_COMPL_WQE:
  3181. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3182. cq_event);
  3183. /* Translate ELS WCQE to response IOCBQ */
  3184. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3185. irspiocbq);
  3186. if (irspiocbq)
  3187. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3188. irspiocbq);
  3189. break;
  3190. case CQE_CODE_RECEIVE:
  3191. case CQE_CODE_RECEIVE_V1:
  3192. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3193. cq_event);
  3194. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3195. break;
  3196. default:
  3197. break;
  3198. }
  3199. }
  3200. }
  3201. /**
  3202. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3203. * @phba: Pointer to HBA context object.
  3204. * @pring: Pointer to driver SLI ring object.
  3205. *
  3206. * This function aborts all iocbs in the given ring and frees all the iocb
  3207. * objects in txq. This function issues an abort iocb for all the iocb commands
  3208. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3209. * the return of this function. The caller is not required to hold any locks.
  3210. **/
  3211. void
  3212. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3213. {
  3214. LIST_HEAD(completions);
  3215. struct lpfc_iocbq *iocb, *next_iocb;
  3216. if (pring->ringno == LPFC_ELS_RING) {
  3217. lpfc_fabric_abort_hba(phba);
  3218. }
  3219. /* Error everything on txq and txcmplq
  3220. * First do the txq.
  3221. */
  3222. spin_lock_irq(&phba->hbalock);
  3223. list_splice_init(&pring->txq, &completions);
  3224. /* Next issue ABTS for everything on the txcmplq */
  3225. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3226. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3227. spin_unlock_irq(&phba->hbalock);
  3228. /* Cancel all the IOCBs from the completions list */
  3229. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3230. IOERR_SLI_ABORTED);
  3231. }
  3232. /**
  3233. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3234. * @phba: Pointer to HBA context object.
  3235. *
  3236. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3237. * objects in txq and txcmplq. This function will not issue abort iocbs
  3238. * for all the iocb commands in txcmplq, they will just be returned with
  3239. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3240. * slot has been permanently disabled.
  3241. **/
  3242. void
  3243. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3244. {
  3245. LIST_HEAD(txq);
  3246. LIST_HEAD(txcmplq);
  3247. struct lpfc_sli *psli = &phba->sli;
  3248. struct lpfc_sli_ring *pring;
  3249. /* Currently, only one fcp ring */
  3250. pring = &psli->ring[psli->fcp_ring];
  3251. spin_lock_irq(&phba->hbalock);
  3252. /* Retrieve everything on txq */
  3253. list_splice_init(&pring->txq, &txq);
  3254. /* Retrieve everything on the txcmplq */
  3255. list_splice_init(&pring->txcmplq, &txcmplq);
  3256. /* Indicate the I/O queues are flushed */
  3257. phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
  3258. spin_unlock_irq(&phba->hbalock);
  3259. /* Flush the txq */
  3260. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3261. IOERR_SLI_DOWN);
  3262. /* Flush the txcmpq */
  3263. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3264. IOERR_SLI_DOWN);
  3265. }
  3266. /**
  3267. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3268. * @phba: Pointer to HBA context object.
  3269. * @mask: Bit mask to be checked.
  3270. *
  3271. * This function reads the host status register and compares
  3272. * with the provided bit mask to check if HBA completed
  3273. * the restart. This function will wait in a loop for the
  3274. * HBA to complete restart. If the HBA does not restart within
  3275. * 15 iterations, the function will reset the HBA again. The
  3276. * function returns 1 when HBA fail to restart otherwise returns
  3277. * zero.
  3278. **/
  3279. static int
  3280. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3281. {
  3282. uint32_t status;
  3283. int i = 0;
  3284. int retval = 0;
  3285. /* Read the HBA Host Status Register */
  3286. if (lpfc_readl(phba->HSregaddr, &status))
  3287. return 1;
  3288. /*
  3289. * Check status register every 100ms for 5 retries, then every
  3290. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3291. * every 2.5 sec for 4.
  3292. * Break our of the loop if errors occurred during init.
  3293. */
  3294. while (((status & mask) != mask) &&
  3295. !(status & HS_FFERM) &&
  3296. i++ < 20) {
  3297. if (i <= 5)
  3298. msleep(10);
  3299. else if (i <= 10)
  3300. msleep(500);
  3301. else
  3302. msleep(2500);
  3303. if (i == 15) {
  3304. /* Do post */
  3305. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3306. lpfc_sli_brdrestart(phba);
  3307. }
  3308. /* Read the HBA Host Status Register */
  3309. if (lpfc_readl(phba->HSregaddr, &status)) {
  3310. retval = 1;
  3311. break;
  3312. }
  3313. }
  3314. /* Check to see if any errors occurred during init */
  3315. if ((status & HS_FFERM) || (i >= 20)) {
  3316. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3317. "2751 Adapter failed to restart, "
  3318. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3319. status,
  3320. readl(phba->MBslimaddr + 0xa8),
  3321. readl(phba->MBslimaddr + 0xac));
  3322. phba->link_state = LPFC_HBA_ERROR;
  3323. retval = 1;
  3324. }
  3325. return retval;
  3326. }
  3327. /**
  3328. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3329. * @phba: Pointer to HBA context object.
  3330. * @mask: Bit mask to be checked.
  3331. *
  3332. * This function checks the host status register to check if HBA is
  3333. * ready. This function will wait in a loop for the HBA to be ready
  3334. * If the HBA is not ready , the function will will reset the HBA PCI
  3335. * function again. The function returns 1 when HBA fail to be ready
  3336. * otherwise returns zero.
  3337. **/
  3338. static int
  3339. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3340. {
  3341. uint32_t status;
  3342. int retval = 0;
  3343. /* Read the HBA Host Status Register */
  3344. status = lpfc_sli4_post_status_check(phba);
  3345. if (status) {
  3346. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3347. lpfc_sli_brdrestart(phba);
  3348. status = lpfc_sli4_post_status_check(phba);
  3349. }
  3350. /* Check to see if any errors occurred during init */
  3351. if (status) {
  3352. phba->link_state = LPFC_HBA_ERROR;
  3353. retval = 1;
  3354. } else
  3355. phba->sli4_hba.intr_enable = 0;
  3356. return retval;
  3357. }
  3358. /**
  3359. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3360. * @phba: Pointer to HBA context object.
  3361. * @mask: Bit mask to be checked.
  3362. *
  3363. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3364. * from the API jump table function pointer from the lpfc_hba struct.
  3365. **/
  3366. int
  3367. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3368. {
  3369. return phba->lpfc_sli_brdready(phba, mask);
  3370. }
  3371. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3372. /**
  3373. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3374. * @phba: Pointer to HBA context object.
  3375. *
  3376. * This function is called before resetting an HBA. This function is called
  3377. * with hbalock held and requests HBA to quiesce DMAs before a reset.
  3378. **/
  3379. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3380. {
  3381. uint32_t __iomem *resp_buf;
  3382. uint32_t __iomem *mbox_buf;
  3383. volatile uint32_t mbox;
  3384. uint32_t hc_copy, ha_copy, resp_data;
  3385. int i;
  3386. uint8_t hdrtype;
  3387. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3388. if (hdrtype != 0x80 ||
  3389. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3390. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3391. return;
  3392. /*
  3393. * Tell the other part of the chip to suspend temporarily all
  3394. * its DMA activity.
  3395. */
  3396. resp_buf = phba->MBslimaddr;
  3397. /* Disable the error attention */
  3398. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3399. return;
  3400. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3401. readl(phba->HCregaddr); /* flush */
  3402. phba->link_flag |= LS_IGNORE_ERATT;
  3403. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3404. return;
  3405. if (ha_copy & HA_ERATT) {
  3406. /* Clear Chip error bit */
  3407. writel(HA_ERATT, phba->HAregaddr);
  3408. phba->pport->stopped = 1;
  3409. }
  3410. mbox = 0;
  3411. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3412. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3413. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3414. mbox_buf = phba->MBslimaddr;
  3415. writel(mbox, mbox_buf);
  3416. for (i = 0; i < 50; i++) {
  3417. if (lpfc_readl((resp_buf + 1), &resp_data))
  3418. return;
  3419. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3420. mdelay(1);
  3421. else
  3422. break;
  3423. }
  3424. resp_data = 0;
  3425. if (lpfc_readl((resp_buf + 1), &resp_data))
  3426. return;
  3427. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3428. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3429. phba->pport->stopped)
  3430. goto restore_hc;
  3431. else
  3432. goto clear_errat;
  3433. }
  3434. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3435. resp_data = 0;
  3436. for (i = 0; i < 500; i++) {
  3437. if (lpfc_readl(resp_buf, &resp_data))
  3438. return;
  3439. if (resp_data != mbox)
  3440. mdelay(1);
  3441. else
  3442. break;
  3443. }
  3444. clear_errat:
  3445. while (++i < 500) {
  3446. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3447. return;
  3448. if (!(ha_copy & HA_ERATT))
  3449. mdelay(1);
  3450. else
  3451. break;
  3452. }
  3453. if (readl(phba->HAregaddr) & HA_ERATT) {
  3454. writel(HA_ERATT, phba->HAregaddr);
  3455. phba->pport->stopped = 1;
  3456. }
  3457. restore_hc:
  3458. phba->link_flag &= ~LS_IGNORE_ERATT;
  3459. writel(hc_copy, phba->HCregaddr);
  3460. readl(phba->HCregaddr); /* flush */
  3461. }
  3462. /**
  3463. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3464. * @phba: Pointer to HBA context object.
  3465. *
  3466. * This function issues a kill_board mailbox command and waits for
  3467. * the error attention interrupt. This function is called for stopping
  3468. * the firmware processing. The caller is not required to hold any
  3469. * locks. This function calls lpfc_hba_down_post function to free
  3470. * any pending commands after the kill. The function will return 1 when it
  3471. * fails to kill the board else will return 0.
  3472. **/
  3473. int
  3474. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3475. {
  3476. struct lpfc_sli *psli;
  3477. LPFC_MBOXQ_t *pmb;
  3478. uint32_t status;
  3479. uint32_t ha_copy;
  3480. int retval;
  3481. int i = 0;
  3482. psli = &phba->sli;
  3483. /* Kill HBA */
  3484. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3485. "0329 Kill HBA Data: x%x x%x\n",
  3486. phba->pport->port_state, psli->sli_flag);
  3487. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3488. if (!pmb)
  3489. return 1;
  3490. /* Disable the error attention */
  3491. spin_lock_irq(&phba->hbalock);
  3492. if (lpfc_readl(phba->HCregaddr, &status)) {
  3493. spin_unlock_irq(&phba->hbalock);
  3494. mempool_free(pmb, phba->mbox_mem_pool);
  3495. return 1;
  3496. }
  3497. status &= ~HC_ERINT_ENA;
  3498. writel(status, phba->HCregaddr);
  3499. readl(phba->HCregaddr); /* flush */
  3500. phba->link_flag |= LS_IGNORE_ERATT;
  3501. spin_unlock_irq(&phba->hbalock);
  3502. lpfc_kill_board(phba, pmb);
  3503. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3504. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3505. if (retval != MBX_SUCCESS) {
  3506. if (retval != MBX_BUSY)
  3507. mempool_free(pmb, phba->mbox_mem_pool);
  3508. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3509. "2752 KILL_BOARD command failed retval %d\n",
  3510. retval);
  3511. spin_lock_irq(&phba->hbalock);
  3512. phba->link_flag &= ~LS_IGNORE_ERATT;
  3513. spin_unlock_irq(&phba->hbalock);
  3514. return 1;
  3515. }
  3516. spin_lock_irq(&phba->hbalock);
  3517. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3518. spin_unlock_irq(&phba->hbalock);
  3519. mempool_free(pmb, phba->mbox_mem_pool);
  3520. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3521. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3522. * 3 seconds we still set HBA_ERROR state because the status of the
  3523. * board is now undefined.
  3524. */
  3525. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3526. return 1;
  3527. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3528. mdelay(100);
  3529. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3530. return 1;
  3531. }
  3532. del_timer_sync(&psli->mbox_tmo);
  3533. if (ha_copy & HA_ERATT) {
  3534. writel(HA_ERATT, phba->HAregaddr);
  3535. phba->pport->stopped = 1;
  3536. }
  3537. spin_lock_irq(&phba->hbalock);
  3538. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3539. psli->mbox_active = NULL;
  3540. phba->link_flag &= ~LS_IGNORE_ERATT;
  3541. spin_unlock_irq(&phba->hbalock);
  3542. lpfc_hba_down_post(phba);
  3543. phba->link_state = LPFC_HBA_ERROR;
  3544. return ha_copy & HA_ERATT ? 0 : 1;
  3545. }
  3546. /**
  3547. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3548. * @phba: Pointer to HBA context object.
  3549. *
  3550. * This function resets the HBA by writing HC_INITFF to the control
  3551. * register. After the HBA resets, this function resets all the iocb ring
  3552. * indices. This function disables PCI layer parity checking during
  3553. * the reset.
  3554. * This function returns 0 always.
  3555. * The caller is not required to hold any locks.
  3556. **/
  3557. int
  3558. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3559. {
  3560. struct lpfc_sli *psli;
  3561. struct lpfc_sli_ring *pring;
  3562. uint16_t cfg_value;
  3563. int i;
  3564. psli = &phba->sli;
  3565. /* Reset HBA */
  3566. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3567. "0325 Reset HBA Data: x%x x%x\n",
  3568. phba->pport->port_state, psli->sli_flag);
  3569. /* perform board reset */
  3570. phba->fc_eventTag = 0;
  3571. phba->link_events = 0;
  3572. phba->pport->fc_myDID = 0;
  3573. phba->pport->fc_prevDID = 0;
  3574. /* Turn off parity checking and serr during the physical reset */
  3575. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3576. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3577. (cfg_value &
  3578. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3579. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3580. /* Now toggle INITFF bit in the Host Control Register */
  3581. writel(HC_INITFF, phba->HCregaddr);
  3582. mdelay(1);
  3583. readl(phba->HCregaddr); /* flush */
  3584. writel(0, phba->HCregaddr);
  3585. readl(phba->HCregaddr); /* flush */
  3586. /* Restore PCI cmd register */
  3587. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3588. /* Initialize relevant SLI info */
  3589. for (i = 0; i < psli->num_rings; i++) {
  3590. pring = &psli->ring[i];
  3591. pring->flag = 0;
  3592. pring->sli.sli3.rspidx = 0;
  3593. pring->sli.sli3.next_cmdidx = 0;
  3594. pring->sli.sli3.local_getidx = 0;
  3595. pring->sli.sli3.cmdidx = 0;
  3596. pring->missbufcnt = 0;
  3597. }
  3598. phba->link_state = LPFC_WARM_START;
  3599. return 0;
  3600. }
  3601. /**
  3602. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3603. * @phba: Pointer to HBA context object.
  3604. *
  3605. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3606. * checking during resets the device. The caller is not required to hold
  3607. * any locks.
  3608. *
  3609. * This function returns 0 always.
  3610. **/
  3611. int
  3612. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3613. {
  3614. struct lpfc_sli *psli = &phba->sli;
  3615. uint16_t cfg_value;
  3616. int rc;
  3617. /* Reset HBA */
  3618. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3619. "0295 Reset HBA Data: x%x x%x\n",
  3620. phba->pport->port_state, psli->sli_flag);
  3621. /* perform board reset */
  3622. phba->fc_eventTag = 0;
  3623. phba->link_events = 0;
  3624. phba->pport->fc_myDID = 0;
  3625. phba->pport->fc_prevDID = 0;
  3626. spin_lock_irq(&phba->hbalock);
  3627. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3628. phba->fcf.fcf_flag = 0;
  3629. spin_unlock_irq(&phba->hbalock);
  3630. /* Now physically reset the device */
  3631. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3632. "0389 Performing PCI function reset!\n");
  3633. /* Turn off parity checking and serr during the physical reset */
  3634. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3635. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3636. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3637. /* Perform FCoE PCI function reset before freeing queue memory */
  3638. rc = lpfc_pci_function_reset(phba);
  3639. lpfc_sli4_queue_destroy(phba);
  3640. /* Restore PCI cmd register */
  3641. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3642. return rc;
  3643. }
  3644. /**
  3645. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3646. * @phba: Pointer to HBA context object.
  3647. *
  3648. * This function is called in the SLI initialization code path to
  3649. * restart the HBA. The caller is not required to hold any lock.
  3650. * This function writes MBX_RESTART mailbox command to the SLIM and
  3651. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3652. * function to free any pending commands. The function enables
  3653. * POST only during the first initialization. The function returns zero.
  3654. * The function does not guarantee completion of MBX_RESTART mailbox
  3655. * command before the return of this function.
  3656. **/
  3657. static int
  3658. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3659. {
  3660. MAILBOX_t *mb;
  3661. struct lpfc_sli *psli;
  3662. volatile uint32_t word0;
  3663. void __iomem *to_slim;
  3664. uint32_t hba_aer_enabled;
  3665. spin_lock_irq(&phba->hbalock);
  3666. /* Take PCIe device Advanced Error Reporting (AER) state */
  3667. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3668. psli = &phba->sli;
  3669. /* Restart HBA */
  3670. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3671. "0337 Restart HBA Data: x%x x%x\n",
  3672. phba->pport->port_state, psli->sli_flag);
  3673. word0 = 0;
  3674. mb = (MAILBOX_t *) &word0;
  3675. mb->mbxCommand = MBX_RESTART;
  3676. mb->mbxHc = 1;
  3677. lpfc_reset_barrier(phba);
  3678. to_slim = phba->MBslimaddr;
  3679. writel(*(uint32_t *) mb, to_slim);
  3680. readl(to_slim); /* flush */
  3681. /* Only skip post after fc_ffinit is completed */
  3682. if (phba->pport->port_state)
  3683. word0 = 1; /* This is really setting up word1 */
  3684. else
  3685. word0 = 0; /* This is really setting up word1 */
  3686. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3687. writel(*(uint32_t *) mb, to_slim);
  3688. readl(to_slim); /* flush */
  3689. lpfc_sli_brdreset(phba);
  3690. phba->pport->stopped = 0;
  3691. phba->link_state = LPFC_INIT_START;
  3692. phba->hba_flag = 0;
  3693. spin_unlock_irq(&phba->hbalock);
  3694. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3695. psli->stats_start = get_seconds();
  3696. /* Give the INITFF and Post time to settle. */
  3697. mdelay(100);
  3698. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3699. if (hba_aer_enabled)
  3700. pci_disable_pcie_error_reporting(phba->pcidev);
  3701. lpfc_hba_down_post(phba);
  3702. return 0;
  3703. }
  3704. /**
  3705. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3706. * @phba: Pointer to HBA context object.
  3707. *
  3708. * This function is called in the SLI initialization code path to restart
  3709. * a SLI4 HBA. The caller is not required to hold any lock.
  3710. * At the end of the function, it calls lpfc_hba_down_post function to
  3711. * free any pending commands.
  3712. **/
  3713. static int
  3714. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3715. {
  3716. struct lpfc_sli *psli = &phba->sli;
  3717. uint32_t hba_aer_enabled;
  3718. int rc;
  3719. /* Restart HBA */
  3720. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3721. "0296 Restart HBA Data: x%x x%x\n",
  3722. phba->pport->port_state, psli->sli_flag);
  3723. /* Take PCIe device Advanced Error Reporting (AER) state */
  3724. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3725. rc = lpfc_sli4_brdreset(phba);
  3726. spin_lock_irq(&phba->hbalock);
  3727. phba->pport->stopped = 0;
  3728. phba->link_state = LPFC_INIT_START;
  3729. phba->hba_flag = 0;
  3730. spin_unlock_irq(&phba->hbalock);
  3731. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3732. psli->stats_start = get_seconds();
  3733. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3734. if (hba_aer_enabled)
  3735. pci_disable_pcie_error_reporting(phba->pcidev);
  3736. lpfc_hba_down_post(phba);
  3737. return rc;
  3738. }
  3739. /**
  3740. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3741. * @phba: Pointer to HBA context object.
  3742. *
  3743. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3744. * API jump table function pointer from the lpfc_hba struct.
  3745. **/
  3746. int
  3747. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3748. {
  3749. return phba->lpfc_sli_brdrestart(phba);
  3750. }
  3751. /**
  3752. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3753. * @phba: Pointer to HBA context object.
  3754. *
  3755. * This function is called after a HBA restart to wait for successful
  3756. * restart of the HBA. Successful restart of the HBA is indicated by
  3757. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3758. * iteration, the function will restart the HBA again. The function returns
  3759. * zero if HBA successfully restarted else returns negative error code.
  3760. **/
  3761. static int
  3762. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3763. {
  3764. uint32_t status, i = 0;
  3765. /* Read the HBA Host Status Register */
  3766. if (lpfc_readl(phba->HSregaddr, &status))
  3767. return -EIO;
  3768. /* Check status register to see what current state is */
  3769. i = 0;
  3770. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3771. /* Check every 10ms for 10 retries, then every 100ms for 90
  3772. * retries, then every 1 sec for 50 retires for a total of
  3773. * ~60 seconds before reset the board again and check every
  3774. * 1 sec for 50 retries. The up to 60 seconds before the
  3775. * board ready is required by the Falcon FIPS zeroization
  3776. * complete, and any reset the board in between shall cause
  3777. * restart of zeroization, further delay the board ready.
  3778. */
  3779. if (i++ >= 200) {
  3780. /* Adapter failed to init, timeout, status reg
  3781. <status> */
  3782. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3783. "0436 Adapter failed to init, "
  3784. "timeout, status reg x%x, "
  3785. "FW Data: A8 x%x AC x%x\n", status,
  3786. readl(phba->MBslimaddr + 0xa8),
  3787. readl(phba->MBslimaddr + 0xac));
  3788. phba->link_state = LPFC_HBA_ERROR;
  3789. return -ETIMEDOUT;
  3790. }
  3791. /* Check to see if any errors occurred during init */
  3792. if (status & HS_FFERM) {
  3793. /* ERROR: During chipset initialization */
  3794. /* Adapter failed to init, chipset, status reg
  3795. <status> */
  3796. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3797. "0437 Adapter failed to init, "
  3798. "chipset, status reg x%x, "
  3799. "FW Data: A8 x%x AC x%x\n", status,
  3800. readl(phba->MBslimaddr + 0xa8),
  3801. readl(phba->MBslimaddr + 0xac));
  3802. phba->link_state = LPFC_HBA_ERROR;
  3803. return -EIO;
  3804. }
  3805. if (i <= 10)
  3806. msleep(10);
  3807. else if (i <= 100)
  3808. msleep(100);
  3809. else
  3810. msleep(1000);
  3811. if (i == 150) {
  3812. /* Do post */
  3813. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3814. lpfc_sli_brdrestart(phba);
  3815. }
  3816. /* Read the HBA Host Status Register */
  3817. if (lpfc_readl(phba->HSregaddr, &status))
  3818. return -EIO;
  3819. }
  3820. /* Check to see if any errors occurred during init */
  3821. if (status & HS_FFERM) {
  3822. /* ERROR: During chipset initialization */
  3823. /* Adapter failed to init, chipset, status reg <status> */
  3824. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3825. "0438 Adapter failed to init, chipset, "
  3826. "status reg x%x, "
  3827. "FW Data: A8 x%x AC x%x\n", status,
  3828. readl(phba->MBslimaddr + 0xa8),
  3829. readl(phba->MBslimaddr + 0xac));
  3830. phba->link_state = LPFC_HBA_ERROR;
  3831. return -EIO;
  3832. }
  3833. /* Clear all interrupt enable conditions */
  3834. writel(0, phba->HCregaddr);
  3835. readl(phba->HCregaddr); /* flush */
  3836. /* setup host attn register */
  3837. writel(0xffffffff, phba->HAregaddr);
  3838. readl(phba->HAregaddr); /* flush */
  3839. return 0;
  3840. }
  3841. /**
  3842. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3843. *
  3844. * This function calculates and returns the number of HBQs required to be
  3845. * configured.
  3846. **/
  3847. int
  3848. lpfc_sli_hbq_count(void)
  3849. {
  3850. return ARRAY_SIZE(lpfc_hbq_defs);
  3851. }
  3852. /**
  3853. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3854. *
  3855. * This function adds the number of hbq entries in every HBQ to get
  3856. * the total number of hbq entries required for the HBA and returns
  3857. * the total count.
  3858. **/
  3859. static int
  3860. lpfc_sli_hbq_entry_count(void)
  3861. {
  3862. int hbq_count = lpfc_sli_hbq_count();
  3863. int count = 0;
  3864. int i;
  3865. for (i = 0; i < hbq_count; ++i)
  3866. count += lpfc_hbq_defs[i]->entry_count;
  3867. return count;
  3868. }
  3869. /**
  3870. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3871. *
  3872. * This function calculates amount of memory required for all hbq entries
  3873. * to be configured and returns the total memory required.
  3874. **/
  3875. int
  3876. lpfc_sli_hbq_size(void)
  3877. {
  3878. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3879. }
  3880. /**
  3881. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3882. * @phba: Pointer to HBA context object.
  3883. *
  3884. * This function is called during the SLI initialization to configure
  3885. * all the HBQs and post buffers to the HBQ. The caller is not
  3886. * required to hold any locks. This function will return zero if successful
  3887. * else it will return negative error code.
  3888. **/
  3889. static int
  3890. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3891. {
  3892. int hbq_count = lpfc_sli_hbq_count();
  3893. LPFC_MBOXQ_t *pmb;
  3894. MAILBOX_t *pmbox;
  3895. uint32_t hbqno;
  3896. uint32_t hbq_entry_index;
  3897. /* Get a Mailbox buffer to setup mailbox
  3898. * commands for HBA initialization
  3899. */
  3900. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3901. if (!pmb)
  3902. return -ENOMEM;
  3903. pmbox = &pmb->u.mb;
  3904. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3905. phba->link_state = LPFC_INIT_MBX_CMDS;
  3906. phba->hbq_in_use = 1;
  3907. hbq_entry_index = 0;
  3908. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3909. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3910. phba->hbqs[hbqno].hbqPutIdx = 0;
  3911. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3912. phba->hbqs[hbqno].entry_count =
  3913. lpfc_hbq_defs[hbqno]->entry_count;
  3914. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3915. hbq_entry_index, pmb);
  3916. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3917. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3918. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3919. mbxStatus <status>, ring <num> */
  3920. lpfc_printf_log(phba, KERN_ERR,
  3921. LOG_SLI | LOG_VPORT,
  3922. "1805 Adapter failed to init. "
  3923. "Data: x%x x%x x%x\n",
  3924. pmbox->mbxCommand,
  3925. pmbox->mbxStatus, hbqno);
  3926. phba->link_state = LPFC_HBA_ERROR;
  3927. mempool_free(pmb, phba->mbox_mem_pool);
  3928. return -ENXIO;
  3929. }
  3930. }
  3931. phba->hbq_count = hbq_count;
  3932. mempool_free(pmb, phba->mbox_mem_pool);
  3933. /* Initially populate or replenish the HBQs */
  3934. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3935. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3936. return 0;
  3937. }
  3938. /**
  3939. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3940. * @phba: Pointer to HBA context object.
  3941. *
  3942. * This function is called during the SLI initialization to configure
  3943. * all the HBQs and post buffers to the HBQ. The caller is not
  3944. * required to hold any locks. This function will return zero if successful
  3945. * else it will return negative error code.
  3946. **/
  3947. static int
  3948. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3949. {
  3950. phba->hbq_in_use = 1;
  3951. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3952. phba->hbq_count = 1;
  3953. /* Initially populate or replenish the HBQs */
  3954. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3955. return 0;
  3956. }
  3957. /**
  3958. * lpfc_sli_config_port - Issue config port mailbox command
  3959. * @phba: Pointer to HBA context object.
  3960. * @sli_mode: sli mode - 2/3
  3961. *
  3962. * This function is called by the sli intialization code path
  3963. * to issue config_port mailbox command. This function restarts the
  3964. * HBA firmware and issues a config_port mailbox command to configure
  3965. * the SLI interface in the sli mode specified by sli_mode
  3966. * variable. The caller is not required to hold any locks.
  3967. * The function returns 0 if successful, else returns negative error
  3968. * code.
  3969. **/
  3970. int
  3971. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3972. {
  3973. LPFC_MBOXQ_t *pmb;
  3974. uint32_t resetcount = 0, rc = 0, done = 0;
  3975. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3976. if (!pmb) {
  3977. phba->link_state = LPFC_HBA_ERROR;
  3978. return -ENOMEM;
  3979. }
  3980. phba->sli_rev = sli_mode;
  3981. while (resetcount < 2 && !done) {
  3982. spin_lock_irq(&phba->hbalock);
  3983. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3984. spin_unlock_irq(&phba->hbalock);
  3985. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3986. lpfc_sli_brdrestart(phba);
  3987. rc = lpfc_sli_chipset_init(phba);
  3988. if (rc)
  3989. break;
  3990. spin_lock_irq(&phba->hbalock);
  3991. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3992. spin_unlock_irq(&phba->hbalock);
  3993. resetcount++;
  3994. /* Call pre CONFIG_PORT mailbox command initialization. A
  3995. * value of 0 means the call was successful. Any other
  3996. * nonzero value is a failure, but if ERESTART is returned,
  3997. * the driver may reset the HBA and try again.
  3998. */
  3999. rc = lpfc_config_port_prep(phba);
  4000. if (rc == -ERESTART) {
  4001. phba->link_state = LPFC_LINK_UNKNOWN;
  4002. continue;
  4003. } else if (rc)
  4004. break;
  4005. phba->link_state = LPFC_INIT_MBX_CMDS;
  4006. lpfc_config_port(phba, pmb);
  4007. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  4008. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  4009. LPFC_SLI3_HBQ_ENABLED |
  4010. LPFC_SLI3_CRP_ENABLED |
  4011. LPFC_SLI3_BG_ENABLED |
  4012. LPFC_SLI3_DSS_ENABLED);
  4013. if (rc != MBX_SUCCESS) {
  4014. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4015. "0442 Adapter failed to init, mbxCmd x%x "
  4016. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  4017. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  4018. spin_lock_irq(&phba->hbalock);
  4019. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  4020. spin_unlock_irq(&phba->hbalock);
  4021. rc = -ENXIO;
  4022. } else {
  4023. /* Allow asynchronous mailbox command to go through */
  4024. spin_lock_irq(&phba->hbalock);
  4025. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4026. spin_unlock_irq(&phba->hbalock);
  4027. done = 1;
  4028. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  4029. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  4030. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4031. "3110 Port did not grant ASABT\n");
  4032. }
  4033. }
  4034. if (!done) {
  4035. rc = -EINVAL;
  4036. goto do_prep_failed;
  4037. }
  4038. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  4039. if (!pmb->u.mb.un.varCfgPort.cMA) {
  4040. rc = -ENXIO;
  4041. goto do_prep_failed;
  4042. }
  4043. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  4044. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  4045. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  4046. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  4047. phba->max_vpi : phba->max_vports;
  4048. } else
  4049. phba->max_vpi = 0;
  4050. phba->fips_level = 0;
  4051. phba->fips_spec_rev = 0;
  4052. if (pmb->u.mb.un.varCfgPort.gdss) {
  4053. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  4054. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  4055. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  4056. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4057. "2850 Security Crypto Active. FIPS x%d "
  4058. "(Spec Rev: x%d)",
  4059. phba->fips_level, phba->fips_spec_rev);
  4060. }
  4061. if (pmb->u.mb.un.varCfgPort.sec_err) {
  4062. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4063. "2856 Config Port Security Crypto "
  4064. "Error: x%x ",
  4065. pmb->u.mb.un.varCfgPort.sec_err);
  4066. }
  4067. if (pmb->u.mb.un.varCfgPort.gerbm)
  4068. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  4069. if (pmb->u.mb.un.varCfgPort.gcrp)
  4070. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  4071. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  4072. phba->port_gp = phba->mbox->us.s3_pgp.port;
  4073. if (phba->cfg_enable_bg) {
  4074. if (pmb->u.mb.un.varCfgPort.gbg)
  4075. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  4076. else
  4077. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4078. "0443 Adapter did not grant "
  4079. "BlockGuard\n");
  4080. }
  4081. } else {
  4082. phba->hbq_get = NULL;
  4083. phba->port_gp = phba->mbox->us.s2.port;
  4084. phba->max_vpi = 0;
  4085. }
  4086. do_prep_failed:
  4087. mempool_free(pmb, phba->mbox_mem_pool);
  4088. return rc;
  4089. }
  4090. /**
  4091. * lpfc_sli_hba_setup - SLI intialization function
  4092. * @phba: Pointer to HBA context object.
  4093. *
  4094. * This function is the main SLI intialization function. This function
  4095. * is called by the HBA intialization code, HBA reset code and HBA
  4096. * error attention handler code. Caller is not required to hold any
  4097. * locks. This function issues config_port mailbox command to configure
  4098. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4099. * calls the config_port_post function to issue init_link mailbox
  4100. * command and to start the discovery. The function will return zero
  4101. * if successful, else it will return negative error code.
  4102. **/
  4103. int
  4104. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4105. {
  4106. uint32_t rc;
  4107. int mode = 3, i;
  4108. int longs;
  4109. switch (lpfc_sli_mode) {
  4110. case 2:
  4111. if (phba->cfg_enable_npiv) {
  4112. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4113. "1824 NPIV enabled: Override lpfc_sli_mode "
  4114. "parameter (%d) to auto (0).\n",
  4115. lpfc_sli_mode);
  4116. break;
  4117. }
  4118. mode = 2;
  4119. break;
  4120. case 0:
  4121. case 3:
  4122. break;
  4123. default:
  4124. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4125. "1819 Unrecognized lpfc_sli_mode "
  4126. "parameter: %d.\n", lpfc_sli_mode);
  4127. break;
  4128. }
  4129. rc = lpfc_sli_config_port(phba, mode);
  4130. if (rc && lpfc_sli_mode == 3)
  4131. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4132. "1820 Unable to select SLI-3. "
  4133. "Not supported by adapter.\n");
  4134. if (rc && mode != 2)
  4135. rc = lpfc_sli_config_port(phba, 2);
  4136. if (rc)
  4137. goto lpfc_sli_hba_setup_error;
  4138. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4139. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4140. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4141. if (!rc) {
  4142. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4143. "2709 This device supports "
  4144. "Advanced Error Reporting (AER)\n");
  4145. spin_lock_irq(&phba->hbalock);
  4146. phba->hba_flag |= HBA_AER_ENABLED;
  4147. spin_unlock_irq(&phba->hbalock);
  4148. } else {
  4149. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4150. "2708 This device does not support "
  4151. "Advanced Error Reporting (AER)\n");
  4152. phba->cfg_aer_support = 0;
  4153. }
  4154. }
  4155. if (phba->sli_rev == 3) {
  4156. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4157. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4158. } else {
  4159. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4160. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4161. phba->sli3_options = 0;
  4162. }
  4163. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4164. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4165. phba->sli_rev, phba->max_vpi);
  4166. rc = lpfc_sli_ring_map(phba);
  4167. if (rc)
  4168. goto lpfc_sli_hba_setup_error;
  4169. /* Initialize VPIs. */
  4170. if (phba->sli_rev == LPFC_SLI_REV3) {
  4171. /*
  4172. * The VPI bitmask and physical ID array are allocated
  4173. * and initialized once only - at driver load. A port
  4174. * reset doesn't need to reinitialize this memory.
  4175. */
  4176. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4177. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4178. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4179. GFP_KERNEL);
  4180. if (!phba->vpi_bmask) {
  4181. rc = -ENOMEM;
  4182. goto lpfc_sli_hba_setup_error;
  4183. }
  4184. phba->vpi_ids = kzalloc(
  4185. (phba->max_vpi+1) * sizeof(uint16_t),
  4186. GFP_KERNEL);
  4187. if (!phba->vpi_ids) {
  4188. kfree(phba->vpi_bmask);
  4189. rc = -ENOMEM;
  4190. goto lpfc_sli_hba_setup_error;
  4191. }
  4192. for (i = 0; i < phba->max_vpi; i++)
  4193. phba->vpi_ids[i] = i;
  4194. }
  4195. }
  4196. /* Init HBQs */
  4197. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4198. rc = lpfc_sli_hbq_setup(phba);
  4199. if (rc)
  4200. goto lpfc_sli_hba_setup_error;
  4201. }
  4202. spin_lock_irq(&phba->hbalock);
  4203. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4204. spin_unlock_irq(&phba->hbalock);
  4205. rc = lpfc_config_port_post(phba);
  4206. if (rc)
  4207. goto lpfc_sli_hba_setup_error;
  4208. return rc;
  4209. lpfc_sli_hba_setup_error:
  4210. phba->link_state = LPFC_HBA_ERROR;
  4211. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4212. "0445 Firmware initialization failed\n");
  4213. return rc;
  4214. }
  4215. /**
  4216. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4217. * @phba: Pointer to HBA context object.
  4218. * @mboxq: mailbox pointer.
  4219. * This function issue a dump mailbox command to read config region
  4220. * 23 and parse the records in the region and populate driver
  4221. * data structure.
  4222. **/
  4223. static int
  4224. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4225. {
  4226. LPFC_MBOXQ_t *mboxq;
  4227. struct lpfc_dmabuf *mp;
  4228. struct lpfc_mqe *mqe;
  4229. uint32_t data_length;
  4230. int rc;
  4231. /* Program the default value of vlan_id and fc_map */
  4232. phba->valid_vlan = 0;
  4233. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4234. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4235. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4236. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4237. if (!mboxq)
  4238. return -ENOMEM;
  4239. mqe = &mboxq->u.mqe;
  4240. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4241. rc = -ENOMEM;
  4242. goto out_free_mboxq;
  4243. }
  4244. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4245. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4246. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4247. "(%d):2571 Mailbox cmd x%x Status x%x "
  4248. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4249. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4250. "CQ: x%x x%x x%x x%x\n",
  4251. mboxq->vport ? mboxq->vport->vpi : 0,
  4252. bf_get(lpfc_mqe_command, mqe),
  4253. bf_get(lpfc_mqe_status, mqe),
  4254. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4255. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4256. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4257. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4258. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4259. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4260. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4261. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4262. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4263. mboxq->mcqe.word0,
  4264. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4265. mboxq->mcqe.trailer);
  4266. if (rc) {
  4267. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4268. kfree(mp);
  4269. rc = -EIO;
  4270. goto out_free_mboxq;
  4271. }
  4272. data_length = mqe->un.mb_words[5];
  4273. if (data_length > DMP_RGN23_SIZE) {
  4274. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4275. kfree(mp);
  4276. rc = -EIO;
  4277. goto out_free_mboxq;
  4278. }
  4279. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4280. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4281. kfree(mp);
  4282. rc = 0;
  4283. out_free_mboxq:
  4284. mempool_free(mboxq, phba->mbox_mem_pool);
  4285. return rc;
  4286. }
  4287. /**
  4288. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4289. * @phba: pointer to lpfc hba data structure.
  4290. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4291. * @vpd: pointer to the memory to hold resulting port vpd data.
  4292. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4293. * On output, the number of data bytes in @vpd.
  4294. *
  4295. * This routine executes a READ_REV SLI4 mailbox command. In
  4296. * addition, this routine gets the port vpd data.
  4297. *
  4298. * Return codes
  4299. * 0 - successful
  4300. * -ENOMEM - could not allocated memory.
  4301. **/
  4302. static int
  4303. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4304. uint8_t *vpd, uint32_t *vpd_size)
  4305. {
  4306. int rc = 0;
  4307. uint32_t dma_size;
  4308. struct lpfc_dmabuf *dmabuf;
  4309. struct lpfc_mqe *mqe;
  4310. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4311. if (!dmabuf)
  4312. return -ENOMEM;
  4313. /*
  4314. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4315. * mailbox command.
  4316. */
  4317. dma_size = *vpd_size;
  4318. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4319. dma_size,
  4320. &dmabuf->phys,
  4321. GFP_KERNEL);
  4322. if (!dmabuf->virt) {
  4323. kfree(dmabuf);
  4324. return -ENOMEM;
  4325. }
  4326. memset(dmabuf->virt, 0, dma_size);
  4327. /*
  4328. * The SLI4 implementation of READ_REV conflicts at word1,
  4329. * bits 31:16 and SLI4 adds vpd functionality not present
  4330. * in SLI3. This code corrects the conflicts.
  4331. */
  4332. lpfc_read_rev(phba, mboxq);
  4333. mqe = &mboxq->u.mqe;
  4334. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4335. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4336. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4337. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4338. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4339. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4340. if (rc) {
  4341. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4342. dmabuf->virt, dmabuf->phys);
  4343. kfree(dmabuf);
  4344. return -EIO;
  4345. }
  4346. /*
  4347. * The available vpd length cannot be bigger than the
  4348. * DMA buffer passed to the port. Catch the less than
  4349. * case and update the caller's size.
  4350. */
  4351. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4352. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4353. memcpy(vpd, dmabuf->virt, *vpd_size);
  4354. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4355. dmabuf->virt, dmabuf->phys);
  4356. kfree(dmabuf);
  4357. return 0;
  4358. }
  4359. /**
  4360. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4361. * @phba: pointer to lpfc hba data structure.
  4362. *
  4363. * This routine retrieves SLI4 device physical port name this PCI function
  4364. * is attached to.
  4365. *
  4366. * Return codes
  4367. * 0 - successful
  4368. * otherwise - failed to retrieve physical port name
  4369. **/
  4370. static int
  4371. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4372. {
  4373. LPFC_MBOXQ_t *mboxq;
  4374. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4375. struct lpfc_controller_attribute *cntl_attr;
  4376. struct lpfc_mbx_get_port_name *get_port_name;
  4377. void *virtaddr = NULL;
  4378. uint32_t alloclen, reqlen;
  4379. uint32_t shdr_status, shdr_add_status;
  4380. union lpfc_sli4_cfg_shdr *shdr;
  4381. char cport_name = 0;
  4382. int rc;
  4383. /* We assume nothing at this point */
  4384. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4385. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4386. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4387. if (!mboxq)
  4388. return -ENOMEM;
  4389. /* obtain link type and link number via READ_CONFIG */
  4390. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4391. lpfc_sli4_read_config(phba);
  4392. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4393. goto retrieve_ppname;
  4394. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4395. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4396. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4397. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4398. LPFC_SLI4_MBX_NEMBED);
  4399. if (alloclen < reqlen) {
  4400. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4401. "3084 Allocated DMA memory size (%d) is "
  4402. "less than the requested DMA memory size "
  4403. "(%d)\n", alloclen, reqlen);
  4404. rc = -ENOMEM;
  4405. goto out_free_mboxq;
  4406. }
  4407. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4408. virtaddr = mboxq->sge_array->addr[0];
  4409. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4410. shdr = &mbx_cntl_attr->cfg_shdr;
  4411. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4412. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4413. if (shdr_status || shdr_add_status || rc) {
  4414. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4415. "3085 Mailbox x%x (x%x/x%x) failed, "
  4416. "rc:x%x, status:x%x, add_status:x%x\n",
  4417. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4418. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4419. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4420. rc, shdr_status, shdr_add_status);
  4421. rc = -ENXIO;
  4422. goto out_free_mboxq;
  4423. }
  4424. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4425. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4426. phba->sli4_hba.lnk_info.lnk_tp =
  4427. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4428. phba->sli4_hba.lnk_info.lnk_no =
  4429. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4430. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4431. "3086 lnk_type:%d, lnk_numb:%d\n",
  4432. phba->sli4_hba.lnk_info.lnk_tp,
  4433. phba->sli4_hba.lnk_info.lnk_no);
  4434. retrieve_ppname:
  4435. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4436. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4437. sizeof(struct lpfc_mbx_get_port_name) -
  4438. sizeof(struct lpfc_sli4_cfg_mhdr),
  4439. LPFC_SLI4_MBX_EMBED);
  4440. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4441. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4442. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4443. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4444. phba->sli4_hba.lnk_info.lnk_tp);
  4445. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4446. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4447. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4448. if (shdr_status || shdr_add_status || rc) {
  4449. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4450. "3087 Mailbox x%x (x%x/x%x) failed: "
  4451. "rc:x%x, status:x%x, add_status:x%x\n",
  4452. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4453. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4454. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4455. rc, shdr_status, shdr_add_status);
  4456. rc = -ENXIO;
  4457. goto out_free_mboxq;
  4458. }
  4459. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4460. case LPFC_LINK_NUMBER_0:
  4461. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4462. &get_port_name->u.response);
  4463. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4464. break;
  4465. case LPFC_LINK_NUMBER_1:
  4466. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4467. &get_port_name->u.response);
  4468. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4469. break;
  4470. case LPFC_LINK_NUMBER_2:
  4471. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4472. &get_port_name->u.response);
  4473. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4474. break;
  4475. case LPFC_LINK_NUMBER_3:
  4476. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4477. &get_port_name->u.response);
  4478. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4479. break;
  4480. default:
  4481. break;
  4482. }
  4483. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4484. phba->Port[0] = cport_name;
  4485. phba->Port[1] = '\0';
  4486. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4487. "3091 SLI get port name: %s\n", phba->Port);
  4488. }
  4489. out_free_mboxq:
  4490. if (rc != MBX_TIMEOUT) {
  4491. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4492. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4493. else
  4494. mempool_free(mboxq, phba->mbox_mem_pool);
  4495. }
  4496. return rc;
  4497. }
  4498. /**
  4499. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4500. * @phba: pointer to lpfc hba data structure.
  4501. *
  4502. * This routine is called to explicitly arm the SLI4 device's completion and
  4503. * event queues
  4504. **/
  4505. static void
  4506. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4507. {
  4508. int fcp_eqidx;
  4509. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4510. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4511. fcp_eqidx = 0;
  4512. if (phba->sli4_hba.fcp_cq) {
  4513. do {
  4514. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4515. LPFC_QUEUE_REARM);
  4516. } while (++fcp_eqidx < phba->cfg_fcp_io_channel);
  4517. }
  4518. if (phba->sli4_hba.hba_eq) {
  4519. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
  4520. fcp_eqidx++)
  4521. lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx],
  4522. LPFC_QUEUE_REARM);
  4523. }
  4524. }
  4525. /**
  4526. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4527. * @phba: Pointer to HBA context object.
  4528. * @type: The resource extent type.
  4529. * @extnt_count: buffer to hold port available extent count.
  4530. * @extnt_size: buffer to hold element count per extent.
  4531. *
  4532. * This function calls the port and retrievs the number of available
  4533. * extents and their size for a particular extent type.
  4534. *
  4535. * Returns: 0 if successful. Nonzero otherwise.
  4536. **/
  4537. int
  4538. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4539. uint16_t *extnt_count, uint16_t *extnt_size)
  4540. {
  4541. int rc = 0;
  4542. uint32_t length;
  4543. uint32_t mbox_tmo;
  4544. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4545. LPFC_MBOXQ_t *mbox;
  4546. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4547. if (!mbox)
  4548. return -ENOMEM;
  4549. /* Find out how many extents are available for this resource type */
  4550. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4551. sizeof(struct lpfc_sli4_cfg_mhdr));
  4552. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4553. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4554. length, LPFC_SLI4_MBX_EMBED);
  4555. /* Send an extents count of 0 - the GET doesn't use it. */
  4556. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4557. LPFC_SLI4_MBX_EMBED);
  4558. if (unlikely(rc)) {
  4559. rc = -EIO;
  4560. goto err_exit;
  4561. }
  4562. if (!phba->sli4_hba.intr_enable)
  4563. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4564. else {
  4565. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4566. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4567. }
  4568. if (unlikely(rc)) {
  4569. rc = -EIO;
  4570. goto err_exit;
  4571. }
  4572. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4573. if (bf_get(lpfc_mbox_hdr_status,
  4574. &rsrc_info->header.cfg_shdr.response)) {
  4575. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4576. "2930 Failed to get resource extents "
  4577. "Status 0x%x Add'l Status 0x%x\n",
  4578. bf_get(lpfc_mbox_hdr_status,
  4579. &rsrc_info->header.cfg_shdr.response),
  4580. bf_get(lpfc_mbox_hdr_add_status,
  4581. &rsrc_info->header.cfg_shdr.response));
  4582. rc = -EIO;
  4583. goto err_exit;
  4584. }
  4585. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4586. &rsrc_info->u.rsp);
  4587. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4588. &rsrc_info->u.rsp);
  4589. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4590. "3162 Retrieved extents type-%d from port: count:%d, "
  4591. "size:%d\n", type, *extnt_count, *extnt_size);
  4592. err_exit:
  4593. mempool_free(mbox, phba->mbox_mem_pool);
  4594. return rc;
  4595. }
  4596. /**
  4597. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4598. * @phba: Pointer to HBA context object.
  4599. * @type: The extent type to check.
  4600. *
  4601. * This function reads the current available extents from the port and checks
  4602. * if the extent count or extent size has changed since the last access.
  4603. * Callers use this routine post port reset to understand if there is a
  4604. * extent reprovisioning requirement.
  4605. *
  4606. * Returns:
  4607. * -Error: error indicates problem.
  4608. * 1: Extent count or size has changed.
  4609. * 0: No changes.
  4610. **/
  4611. static int
  4612. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4613. {
  4614. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4615. uint16_t size_diff, rsrc_ext_size;
  4616. int rc = 0;
  4617. struct lpfc_rsrc_blks *rsrc_entry;
  4618. struct list_head *rsrc_blk_list = NULL;
  4619. size_diff = 0;
  4620. curr_ext_cnt = 0;
  4621. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4622. &rsrc_ext_cnt,
  4623. &rsrc_ext_size);
  4624. if (unlikely(rc))
  4625. return -EIO;
  4626. switch (type) {
  4627. case LPFC_RSC_TYPE_FCOE_RPI:
  4628. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4629. break;
  4630. case LPFC_RSC_TYPE_FCOE_VPI:
  4631. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4632. break;
  4633. case LPFC_RSC_TYPE_FCOE_XRI:
  4634. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4635. break;
  4636. case LPFC_RSC_TYPE_FCOE_VFI:
  4637. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4638. break;
  4639. default:
  4640. break;
  4641. }
  4642. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4643. curr_ext_cnt++;
  4644. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4645. size_diff++;
  4646. }
  4647. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4648. rc = 1;
  4649. return rc;
  4650. }
  4651. /**
  4652. * lpfc_sli4_cfg_post_extnts -
  4653. * @phba: Pointer to HBA context object.
  4654. * @extnt_cnt - number of available extents.
  4655. * @type - the extent type (rpi, xri, vfi, vpi).
  4656. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4657. * @mbox - pointer to the caller's allocated mailbox structure.
  4658. *
  4659. * This function executes the extents allocation request. It also
  4660. * takes care of the amount of memory needed to allocate or get the
  4661. * allocated extents. It is the caller's responsibility to evaluate
  4662. * the response.
  4663. *
  4664. * Returns:
  4665. * -Error: Error value describes the condition found.
  4666. * 0: if successful
  4667. **/
  4668. static int
  4669. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
  4670. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4671. {
  4672. int rc = 0;
  4673. uint32_t req_len;
  4674. uint32_t emb_len;
  4675. uint32_t alloc_len, mbox_tmo;
  4676. /* Calculate the total requested length of the dma memory */
  4677. req_len = extnt_cnt * sizeof(uint16_t);
  4678. /*
  4679. * Calculate the size of an embedded mailbox. The uint32_t
  4680. * accounts for extents-specific word.
  4681. */
  4682. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4683. sizeof(uint32_t);
  4684. /*
  4685. * Presume the allocation and response will fit into an embedded
  4686. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4687. */
  4688. *emb = LPFC_SLI4_MBX_EMBED;
  4689. if (req_len > emb_len) {
  4690. req_len = extnt_cnt * sizeof(uint16_t) +
  4691. sizeof(union lpfc_sli4_cfg_shdr) +
  4692. sizeof(uint32_t);
  4693. *emb = LPFC_SLI4_MBX_NEMBED;
  4694. }
  4695. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4696. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4697. req_len, *emb);
  4698. if (alloc_len < req_len) {
  4699. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4700. "2982 Allocated DMA memory size (x%x) is "
  4701. "less than the requested DMA memory "
  4702. "size (x%x)\n", alloc_len, req_len);
  4703. return -ENOMEM;
  4704. }
  4705. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
  4706. if (unlikely(rc))
  4707. return -EIO;
  4708. if (!phba->sli4_hba.intr_enable)
  4709. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4710. else {
  4711. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4712. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4713. }
  4714. if (unlikely(rc))
  4715. rc = -EIO;
  4716. return rc;
  4717. }
  4718. /**
  4719. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4720. * @phba: Pointer to HBA context object.
  4721. * @type: The resource extent type to allocate.
  4722. *
  4723. * This function allocates the number of elements for the specified
  4724. * resource type.
  4725. **/
  4726. static int
  4727. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4728. {
  4729. bool emb = false;
  4730. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4731. uint16_t rsrc_id, rsrc_start, j, k;
  4732. uint16_t *ids;
  4733. int i, rc;
  4734. unsigned long longs;
  4735. unsigned long *bmask;
  4736. struct lpfc_rsrc_blks *rsrc_blks;
  4737. LPFC_MBOXQ_t *mbox;
  4738. uint32_t length;
  4739. struct lpfc_id_range *id_array = NULL;
  4740. void *virtaddr = NULL;
  4741. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4742. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4743. struct list_head *ext_blk_list;
  4744. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4745. &rsrc_cnt,
  4746. &rsrc_size);
  4747. if (unlikely(rc))
  4748. return -EIO;
  4749. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4750. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4751. "3009 No available Resource Extents "
  4752. "for resource type 0x%x: Count: 0x%x, "
  4753. "Size 0x%x\n", type, rsrc_cnt,
  4754. rsrc_size);
  4755. return -ENOMEM;
  4756. }
  4757. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
  4758. "2903 Post resource extents type-0x%x: "
  4759. "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
  4760. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4761. if (!mbox)
  4762. return -ENOMEM;
  4763. rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
  4764. if (unlikely(rc)) {
  4765. rc = -EIO;
  4766. goto err_exit;
  4767. }
  4768. /*
  4769. * Figure out where the response is located. Then get local pointers
  4770. * to the response data. The port does not guarantee to respond to
  4771. * all extents counts request so update the local variable with the
  4772. * allocated count from the port.
  4773. */
  4774. if (emb == LPFC_SLI4_MBX_EMBED) {
  4775. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4776. id_array = &rsrc_ext->u.rsp.id[0];
  4777. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4778. } else {
  4779. virtaddr = mbox->sge_array->addr[0];
  4780. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4781. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4782. id_array = &n_rsrc->id;
  4783. }
  4784. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4785. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4786. /*
  4787. * Based on the resource size and count, correct the base and max
  4788. * resource values.
  4789. */
  4790. length = sizeof(struct lpfc_rsrc_blks);
  4791. switch (type) {
  4792. case LPFC_RSC_TYPE_FCOE_RPI:
  4793. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4794. sizeof(unsigned long),
  4795. GFP_KERNEL);
  4796. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4797. rc = -ENOMEM;
  4798. goto err_exit;
  4799. }
  4800. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4801. sizeof(uint16_t),
  4802. GFP_KERNEL);
  4803. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4804. kfree(phba->sli4_hba.rpi_bmask);
  4805. rc = -ENOMEM;
  4806. goto err_exit;
  4807. }
  4808. /*
  4809. * The next_rpi was initialized with the maximum available
  4810. * count but the port may allocate a smaller number. Catch
  4811. * that case and update the next_rpi.
  4812. */
  4813. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4814. /* Initialize local ptrs for common extent processing later. */
  4815. bmask = phba->sli4_hba.rpi_bmask;
  4816. ids = phba->sli4_hba.rpi_ids;
  4817. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4818. break;
  4819. case LPFC_RSC_TYPE_FCOE_VPI:
  4820. phba->vpi_bmask = kzalloc(longs *
  4821. sizeof(unsigned long),
  4822. GFP_KERNEL);
  4823. if (unlikely(!phba->vpi_bmask)) {
  4824. rc = -ENOMEM;
  4825. goto err_exit;
  4826. }
  4827. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4828. sizeof(uint16_t),
  4829. GFP_KERNEL);
  4830. if (unlikely(!phba->vpi_ids)) {
  4831. kfree(phba->vpi_bmask);
  4832. rc = -ENOMEM;
  4833. goto err_exit;
  4834. }
  4835. /* Initialize local ptrs for common extent processing later. */
  4836. bmask = phba->vpi_bmask;
  4837. ids = phba->vpi_ids;
  4838. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4839. break;
  4840. case LPFC_RSC_TYPE_FCOE_XRI:
  4841. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4842. sizeof(unsigned long),
  4843. GFP_KERNEL);
  4844. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4845. rc = -ENOMEM;
  4846. goto err_exit;
  4847. }
  4848. phba->sli4_hba.max_cfg_param.xri_used = 0;
  4849. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4850. sizeof(uint16_t),
  4851. GFP_KERNEL);
  4852. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4853. kfree(phba->sli4_hba.xri_bmask);
  4854. rc = -ENOMEM;
  4855. goto err_exit;
  4856. }
  4857. /* Initialize local ptrs for common extent processing later. */
  4858. bmask = phba->sli4_hba.xri_bmask;
  4859. ids = phba->sli4_hba.xri_ids;
  4860. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4861. break;
  4862. case LPFC_RSC_TYPE_FCOE_VFI:
  4863. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4864. sizeof(unsigned long),
  4865. GFP_KERNEL);
  4866. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4867. rc = -ENOMEM;
  4868. goto err_exit;
  4869. }
  4870. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4871. sizeof(uint16_t),
  4872. GFP_KERNEL);
  4873. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4874. kfree(phba->sli4_hba.vfi_bmask);
  4875. rc = -ENOMEM;
  4876. goto err_exit;
  4877. }
  4878. /* Initialize local ptrs for common extent processing later. */
  4879. bmask = phba->sli4_hba.vfi_bmask;
  4880. ids = phba->sli4_hba.vfi_ids;
  4881. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4882. break;
  4883. default:
  4884. /* Unsupported Opcode. Fail call. */
  4885. id_array = NULL;
  4886. bmask = NULL;
  4887. ids = NULL;
  4888. ext_blk_list = NULL;
  4889. goto err_exit;
  4890. }
  4891. /*
  4892. * Complete initializing the extent configuration with the
  4893. * allocated ids assigned to this function. The bitmask serves
  4894. * as an index into the array and manages the available ids. The
  4895. * array just stores the ids communicated to the port via the wqes.
  4896. */
  4897. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  4898. if ((i % 2) == 0)
  4899. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  4900. &id_array[k]);
  4901. else
  4902. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  4903. &id_array[k]);
  4904. rsrc_blks = kzalloc(length, GFP_KERNEL);
  4905. if (unlikely(!rsrc_blks)) {
  4906. rc = -ENOMEM;
  4907. kfree(bmask);
  4908. kfree(ids);
  4909. goto err_exit;
  4910. }
  4911. rsrc_blks->rsrc_start = rsrc_id;
  4912. rsrc_blks->rsrc_size = rsrc_size;
  4913. list_add_tail(&rsrc_blks->list, ext_blk_list);
  4914. rsrc_start = rsrc_id;
  4915. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  4916. phba->sli4_hba.scsi_xri_start = rsrc_start +
  4917. lpfc_sli4_get_els_iocb_cnt(phba);
  4918. while (rsrc_id < (rsrc_start + rsrc_size)) {
  4919. ids[j] = rsrc_id;
  4920. rsrc_id++;
  4921. j++;
  4922. }
  4923. /* Entire word processed. Get next word.*/
  4924. if ((i % 2) == 1)
  4925. k++;
  4926. }
  4927. err_exit:
  4928. lpfc_sli4_mbox_cmd_free(phba, mbox);
  4929. return rc;
  4930. }
  4931. /**
  4932. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  4933. * @phba: Pointer to HBA context object.
  4934. * @type: the extent's type.
  4935. *
  4936. * This function deallocates all extents of a particular resource type.
  4937. * SLI4 does not allow for deallocating a particular extent range. It
  4938. * is the caller's responsibility to release all kernel memory resources.
  4939. **/
  4940. static int
  4941. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  4942. {
  4943. int rc;
  4944. uint32_t length, mbox_tmo = 0;
  4945. LPFC_MBOXQ_t *mbox;
  4946. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  4947. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  4948. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4949. if (!mbox)
  4950. return -ENOMEM;
  4951. /*
  4952. * This function sends an embedded mailbox because it only sends the
  4953. * the resource type. All extents of this type are released by the
  4954. * port.
  4955. */
  4956. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  4957. sizeof(struct lpfc_sli4_cfg_mhdr));
  4958. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4959. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  4960. length, LPFC_SLI4_MBX_EMBED);
  4961. /* Send an extents count of 0 - the dealloc doesn't use it. */
  4962. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4963. LPFC_SLI4_MBX_EMBED);
  4964. if (unlikely(rc)) {
  4965. rc = -EIO;
  4966. goto out_free_mbox;
  4967. }
  4968. if (!phba->sli4_hba.intr_enable)
  4969. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4970. else {
  4971. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4972. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4973. }
  4974. if (unlikely(rc)) {
  4975. rc = -EIO;
  4976. goto out_free_mbox;
  4977. }
  4978. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  4979. if (bf_get(lpfc_mbox_hdr_status,
  4980. &dealloc_rsrc->header.cfg_shdr.response)) {
  4981. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4982. "2919 Failed to release resource extents "
  4983. "for type %d - Status 0x%x Add'l Status 0x%x. "
  4984. "Resource memory not released.\n",
  4985. type,
  4986. bf_get(lpfc_mbox_hdr_status,
  4987. &dealloc_rsrc->header.cfg_shdr.response),
  4988. bf_get(lpfc_mbox_hdr_add_status,
  4989. &dealloc_rsrc->header.cfg_shdr.response));
  4990. rc = -EIO;
  4991. goto out_free_mbox;
  4992. }
  4993. /* Release kernel memory resources for the specific type. */
  4994. switch (type) {
  4995. case LPFC_RSC_TYPE_FCOE_VPI:
  4996. kfree(phba->vpi_bmask);
  4997. kfree(phba->vpi_ids);
  4998. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4999. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5000. &phba->lpfc_vpi_blk_list, list) {
  5001. list_del_init(&rsrc_blk->list);
  5002. kfree(rsrc_blk);
  5003. }
  5004. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5005. break;
  5006. case LPFC_RSC_TYPE_FCOE_XRI:
  5007. kfree(phba->sli4_hba.xri_bmask);
  5008. kfree(phba->sli4_hba.xri_ids);
  5009. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5010. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  5011. list_del_init(&rsrc_blk->list);
  5012. kfree(rsrc_blk);
  5013. }
  5014. break;
  5015. case LPFC_RSC_TYPE_FCOE_VFI:
  5016. kfree(phba->sli4_hba.vfi_bmask);
  5017. kfree(phba->sli4_hba.vfi_ids);
  5018. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5019. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5020. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  5021. list_del_init(&rsrc_blk->list);
  5022. kfree(rsrc_blk);
  5023. }
  5024. break;
  5025. case LPFC_RSC_TYPE_FCOE_RPI:
  5026. /* RPI bitmask and physical id array are cleaned up earlier. */
  5027. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5028. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  5029. list_del_init(&rsrc_blk->list);
  5030. kfree(rsrc_blk);
  5031. }
  5032. break;
  5033. default:
  5034. break;
  5035. }
  5036. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5037. out_free_mbox:
  5038. mempool_free(mbox, phba->mbox_mem_pool);
  5039. return rc;
  5040. }
  5041. /**
  5042. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  5043. * @phba: Pointer to HBA context object.
  5044. *
  5045. * This function allocates all SLI4 resource identifiers.
  5046. **/
  5047. int
  5048. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  5049. {
  5050. int i, rc, error = 0;
  5051. uint16_t count, base;
  5052. unsigned long longs;
  5053. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5054. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  5055. if (phba->sli4_hba.extents_in_use) {
  5056. /*
  5057. * The port supports resource extents. The XRI, VPI, VFI, RPI
  5058. * resource extent count must be read and allocated before
  5059. * provisioning the resource id arrays.
  5060. */
  5061. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5062. LPFC_IDX_RSRC_RDY) {
  5063. /*
  5064. * Extent-based resources are set - the driver could
  5065. * be in a port reset. Figure out if any corrective
  5066. * actions need to be taken.
  5067. */
  5068. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5069. LPFC_RSC_TYPE_FCOE_VFI);
  5070. if (rc != 0)
  5071. error++;
  5072. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5073. LPFC_RSC_TYPE_FCOE_VPI);
  5074. if (rc != 0)
  5075. error++;
  5076. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5077. LPFC_RSC_TYPE_FCOE_XRI);
  5078. if (rc != 0)
  5079. error++;
  5080. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5081. LPFC_RSC_TYPE_FCOE_RPI);
  5082. if (rc != 0)
  5083. error++;
  5084. /*
  5085. * It's possible that the number of resources
  5086. * provided to this port instance changed between
  5087. * resets. Detect this condition and reallocate
  5088. * resources. Otherwise, there is no action.
  5089. */
  5090. if (error) {
  5091. lpfc_printf_log(phba, KERN_INFO,
  5092. LOG_MBOX | LOG_INIT,
  5093. "2931 Detected extent resource "
  5094. "change. Reallocating all "
  5095. "extents.\n");
  5096. rc = lpfc_sli4_dealloc_extent(phba,
  5097. LPFC_RSC_TYPE_FCOE_VFI);
  5098. rc = lpfc_sli4_dealloc_extent(phba,
  5099. LPFC_RSC_TYPE_FCOE_VPI);
  5100. rc = lpfc_sli4_dealloc_extent(phba,
  5101. LPFC_RSC_TYPE_FCOE_XRI);
  5102. rc = lpfc_sli4_dealloc_extent(phba,
  5103. LPFC_RSC_TYPE_FCOE_RPI);
  5104. } else
  5105. return 0;
  5106. }
  5107. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5108. if (unlikely(rc))
  5109. goto err_exit;
  5110. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5111. if (unlikely(rc))
  5112. goto err_exit;
  5113. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5114. if (unlikely(rc))
  5115. goto err_exit;
  5116. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5117. if (unlikely(rc))
  5118. goto err_exit;
  5119. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5120. LPFC_IDX_RSRC_RDY);
  5121. return rc;
  5122. } else {
  5123. /*
  5124. * The port does not support resource extents. The XRI, VPI,
  5125. * VFI, RPI resource ids were determined from READ_CONFIG.
  5126. * Just allocate the bitmasks and provision the resource id
  5127. * arrays. If a port reset is active, the resources don't
  5128. * need any action - just exit.
  5129. */
  5130. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5131. LPFC_IDX_RSRC_RDY) {
  5132. lpfc_sli4_dealloc_resource_identifiers(phba);
  5133. lpfc_sli4_remove_rpis(phba);
  5134. }
  5135. /* RPIs. */
  5136. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5137. if (count <= 0) {
  5138. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5139. "3279 Invalid provisioning of "
  5140. "rpi:%d\n", count);
  5141. rc = -EINVAL;
  5142. goto err_exit;
  5143. }
  5144. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5145. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5146. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5147. sizeof(unsigned long),
  5148. GFP_KERNEL);
  5149. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5150. rc = -ENOMEM;
  5151. goto err_exit;
  5152. }
  5153. phba->sli4_hba.rpi_ids = kzalloc(count *
  5154. sizeof(uint16_t),
  5155. GFP_KERNEL);
  5156. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5157. rc = -ENOMEM;
  5158. goto free_rpi_bmask;
  5159. }
  5160. for (i = 0; i < count; i++)
  5161. phba->sli4_hba.rpi_ids[i] = base + i;
  5162. /* VPIs. */
  5163. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5164. if (count <= 0) {
  5165. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5166. "3280 Invalid provisioning of "
  5167. "vpi:%d\n", count);
  5168. rc = -EINVAL;
  5169. goto free_rpi_ids;
  5170. }
  5171. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5172. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5173. phba->vpi_bmask = kzalloc(longs *
  5174. sizeof(unsigned long),
  5175. GFP_KERNEL);
  5176. if (unlikely(!phba->vpi_bmask)) {
  5177. rc = -ENOMEM;
  5178. goto free_rpi_ids;
  5179. }
  5180. phba->vpi_ids = kzalloc(count *
  5181. sizeof(uint16_t),
  5182. GFP_KERNEL);
  5183. if (unlikely(!phba->vpi_ids)) {
  5184. rc = -ENOMEM;
  5185. goto free_vpi_bmask;
  5186. }
  5187. for (i = 0; i < count; i++)
  5188. phba->vpi_ids[i] = base + i;
  5189. /* XRIs. */
  5190. count = phba->sli4_hba.max_cfg_param.max_xri;
  5191. if (count <= 0) {
  5192. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5193. "3281 Invalid provisioning of "
  5194. "xri:%d\n", count);
  5195. rc = -EINVAL;
  5196. goto free_vpi_ids;
  5197. }
  5198. base = phba->sli4_hba.max_cfg_param.xri_base;
  5199. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5200. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5201. sizeof(unsigned long),
  5202. GFP_KERNEL);
  5203. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5204. rc = -ENOMEM;
  5205. goto free_vpi_ids;
  5206. }
  5207. phba->sli4_hba.max_cfg_param.xri_used = 0;
  5208. phba->sli4_hba.xri_ids = kzalloc(count *
  5209. sizeof(uint16_t),
  5210. GFP_KERNEL);
  5211. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5212. rc = -ENOMEM;
  5213. goto free_xri_bmask;
  5214. }
  5215. for (i = 0; i < count; i++)
  5216. phba->sli4_hba.xri_ids[i] = base + i;
  5217. /* VFIs. */
  5218. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5219. if (count <= 0) {
  5220. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5221. "3282 Invalid provisioning of "
  5222. "vfi:%d\n", count);
  5223. rc = -EINVAL;
  5224. goto free_xri_ids;
  5225. }
  5226. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5227. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5228. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5229. sizeof(unsigned long),
  5230. GFP_KERNEL);
  5231. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5232. rc = -ENOMEM;
  5233. goto free_xri_ids;
  5234. }
  5235. phba->sli4_hba.vfi_ids = kzalloc(count *
  5236. sizeof(uint16_t),
  5237. GFP_KERNEL);
  5238. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5239. rc = -ENOMEM;
  5240. goto free_vfi_bmask;
  5241. }
  5242. for (i = 0; i < count; i++)
  5243. phba->sli4_hba.vfi_ids[i] = base + i;
  5244. /*
  5245. * Mark all resources ready. An HBA reset doesn't need
  5246. * to reset the initialization.
  5247. */
  5248. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5249. LPFC_IDX_RSRC_RDY);
  5250. return 0;
  5251. }
  5252. free_vfi_bmask:
  5253. kfree(phba->sli4_hba.vfi_bmask);
  5254. free_xri_ids:
  5255. kfree(phba->sli4_hba.xri_ids);
  5256. free_xri_bmask:
  5257. kfree(phba->sli4_hba.xri_bmask);
  5258. free_vpi_ids:
  5259. kfree(phba->vpi_ids);
  5260. free_vpi_bmask:
  5261. kfree(phba->vpi_bmask);
  5262. free_rpi_ids:
  5263. kfree(phba->sli4_hba.rpi_ids);
  5264. free_rpi_bmask:
  5265. kfree(phba->sli4_hba.rpi_bmask);
  5266. err_exit:
  5267. return rc;
  5268. }
  5269. /**
  5270. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5271. * @phba: Pointer to HBA context object.
  5272. *
  5273. * This function allocates the number of elements for the specified
  5274. * resource type.
  5275. **/
  5276. int
  5277. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5278. {
  5279. if (phba->sli4_hba.extents_in_use) {
  5280. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5281. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5282. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5283. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5284. } else {
  5285. kfree(phba->vpi_bmask);
  5286. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5287. kfree(phba->vpi_ids);
  5288. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5289. kfree(phba->sli4_hba.xri_bmask);
  5290. kfree(phba->sli4_hba.xri_ids);
  5291. kfree(phba->sli4_hba.vfi_bmask);
  5292. kfree(phba->sli4_hba.vfi_ids);
  5293. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5294. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5295. }
  5296. return 0;
  5297. }
  5298. /**
  5299. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5300. * @phba: Pointer to HBA context object.
  5301. * @type: The resource extent type.
  5302. * @extnt_count: buffer to hold port extent count response
  5303. * @extnt_size: buffer to hold port extent size response.
  5304. *
  5305. * This function calls the port to read the host allocated extents
  5306. * for a particular type.
  5307. **/
  5308. int
  5309. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5310. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5311. {
  5312. bool emb;
  5313. int rc = 0;
  5314. uint16_t curr_blks = 0;
  5315. uint32_t req_len, emb_len;
  5316. uint32_t alloc_len, mbox_tmo;
  5317. struct list_head *blk_list_head;
  5318. struct lpfc_rsrc_blks *rsrc_blk;
  5319. LPFC_MBOXQ_t *mbox;
  5320. void *virtaddr = NULL;
  5321. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5322. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5323. union lpfc_sli4_cfg_shdr *shdr;
  5324. switch (type) {
  5325. case LPFC_RSC_TYPE_FCOE_VPI:
  5326. blk_list_head = &phba->lpfc_vpi_blk_list;
  5327. break;
  5328. case LPFC_RSC_TYPE_FCOE_XRI:
  5329. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5330. break;
  5331. case LPFC_RSC_TYPE_FCOE_VFI:
  5332. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5333. break;
  5334. case LPFC_RSC_TYPE_FCOE_RPI:
  5335. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5336. break;
  5337. default:
  5338. return -EIO;
  5339. }
  5340. /* Count the number of extents currently allocatd for this type. */
  5341. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5342. if (curr_blks == 0) {
  5343. /*
  5344. * The GET_ALLOCATED mailbox does not return the size,
  5345. * just the count. The size should be just the size
  5346. * stored in the current allocated block and all sizes
  5347. * for an extent type are the same so set the return
  5348. * value now.
  5349. */
  5350. *extnt_size = rsrc_blk->rsrc_size;
  5351. }
  5352. curr_blks++;
  5353. }
  5354. /* Calculate the total requested length of the dma memory. */
  5355. req_len = curr_blks * sizeof(uint16_t);
  5356. /*
  5357. * Calculate the size of an embedded mailbox. The uint32_t
  5358. * accounts for extents-specific word.
  5359. */
  5360. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5361. sizeof(uint32_t);
  5362. /*
  5363. * Presume the allocation and response will fit into an embedded
  5364. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5365. */
  5366. emb = LPFC_SLI4_MBX_EMBED;
  5367. req_len = emb_len;
  5368. if (req_len > emb_len) {
  5369. req_len = curr_blks * sizeof(uint16_t) +
  5370. sizeof(union lpfc_sli4_cfg_shdr) +
  5371. sizeof(uint32_t);
  5372. emb = LPFC_SLI4_MBX_NEMBED;
  5373. }
  5374. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5375. if (!mbox)
  5376. return -ENOMEM;
  5377. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5378. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5379. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5380. req_len, emb);
  5381. if (alloc_len < req_len) {
  5382. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5383. "2983 Allocated DMA memory size (x%x) is "
  5384. "less than the requested DMA memory "
  5385. "size (x%x)\n", alloc_len, req_len);
  5386. rc = -ENOMEM;
  5387. goto err_exit;
  5388. }
  5389. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5390. if (unlikely(rc)) {
  5391. rc = -EIO;
  5392. goto err_exit;
  5393. }
  5394. if (!phba->sli4_hba.intr_enable)
  5395. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5396. else {
  5397. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5398. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5399. }
  5400. if (unlikely(rc)) {
  5401. rc = -EIO;
  5402. goto err_exit;
  5403. }
  5404. /*
  5405. * Figure out where the response is located. Then get local pointers
  5406. * to the response data. The port does not guarantee to respond to
  5407. * all extents counts request so update the local variable with the
  5408. * allocated count from the port.
  5409. */
  5410. if (emb == LPFC_SLI4_MBX_EMBED) {
  5411. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5412. shdr = &rsrc_ext->header.cfg_shdr;
  5413. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5414. } else {
  5415. virtaddr = mbox->sge_array->addr[0];
  5416. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5417. shdr = &n_rsrc->cfg_shdr;
  5418. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5419. }
  5420. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5421. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5422. "2984 Failed to read allocated resources "
  5423. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5424. type,
  5425. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5426. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5427. rc = -EIO;
  5428. goto err_exit;
  5429. }
  5430. err_exit:
  5431. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5432. return rc;
  5433. }
  5434. /**
  5435. * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
  5436. * @phba: pointer to lpfc hba data structure.
  5437. *
  5438. * This routine walks the list of els buffers that have been allocated and
  5439. * repost them to the port by using SGL block post. This is needed after a
  5440. * pci_function_reset/warm_start or start. It attempts to construct blocks
  5441. * of els buffer sgls which contains contiguous xris and uses the non-embedded
  5442. * SGL block post mailbox commands to post them to the port. For single els
  5443. * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
  5444. * mailbox command for posting.
  5445. *
  5446. * Returns: 0 = success, non-zero failure.
  5447. **/
  5448. static int
  5449. lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
  5450. {
  5451. struct lpfc_sglq *sglq_entry = NULL;
  5452. struct lpfc_sglq *sglq_entry_next = NULL;
  5453. struct lpfc_sglq *sglq_entry_first = NULL;
  5454. int status, total_cnt, post_cnt = 0, num_posted = 0, block_cnt = 0;
  5455. int last_xritag = NO_XRI;
  5456. LIST_HEAD(prep_sgl_list);
  5457. LIST_HEAD(blck_sgl_list);
  5458. LIST_HEAD(allc_sgl_list);
  5459. LIST_HEAD(post_sgl_list);
  5460. LIST_HEAD(free_sgl_list);
  5461. spin_lock_irq(&phba->hbalock);
  5462. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
  5463. spin_unlock_irq(&phba->hbalock);
  5464. total_cnt = phba->sli4_hba.els_xri_cnt;
  5465. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  5466. &allc_sgl_list, list) {
  5467. list_del_init(&sglq_entry->list);
  5468. block_cnt++;
  5469. if ((last_xritag != NO_XRI) &&
  5470. (sglq_entry->sli4_xritag != last_xritag + 1)) {
  5471. /* a hole in xri block, form a sgl posting block */
  5472. list_splice_init(&prep_sgl_list, &blck_sgl_list);
  5473. post_cnt = block_cnt - 1;
  5474. /* prepare list for next posting block */
  5475. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5476. block_cnt = 1;
  5477. } else {
  5478. /* prepare list for next posting block */
  5479. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5480. /* enough sgls for non-embed sgl mbox command */
  5481. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  5482. list_splice_init(&prep_sgl_list,
  5483. &blck_sgl_list);
  5484. post_cnt = block_cnt;
  5485. block_cnt = 0;
  5486. }
  5487. }
  5488. num_posted++;
  5489. /* keep track of last sgl's xritag */
  5490. last_xritag = sglq_entry->sli4_xritag;
  5491. /* end of repost sgl list condition for els buffers */
  5492. if (num_posted == phba->sli4_hba.els_xri_cnt) {
  5493. if (post_cnt == 0) {
  5494. list_splice_init(&prep_sgl_list,
  5495. &blck_sgl_list);
  5496. post_cnt = block_cnt;
  5497. } else if (block_cnt == 1) {
  5498. status = lpfc_sli4_post_sgl(phba,
  5499. sglq_entry->phys, 0,
  5500. sglq_entry->sli4_xritag);
  5501. if (!status) {
  5502. /* successful, put sgl to posted list */
  5503. list_add_tail(&sglq_entry->list,
  5504. &post_sgl_list);
  5505. } else {
  5506. /* Failure, put sgl to free list */
  5507. lpfc_printf_log(phba, KERN_WARNING,
  5508. LOG_SLI,
  5509. "3159 Failed to post els "
  5510. "sgl, xritag:x%x\n",
  5511. sglq_entry->sli4_xritag);
  5512. list_add_tail(&sglq_entry->list,
  5513. &free_sgl_list);
  5514. total_cnt--;
  5515. }
  5516. }
  5517. }
  5518. /* continue until a nembed page worth of sgls */
  5519. if (post_cnt == 0)
  5520. continue;
  5521. /* post the els buffer list sgls as a block */
  5522. status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
  5523. post_cnt);
  5524. if (!status) {
  5525. /* success, put sgl list to posted sgl list */
  5526. list_splice_init(&blck_sgl_list, &post_sgl_list);
  5527. } else {
  5528. /* Failure, put sgl list to free sgl list */
  5529. sglq_entry_first = list_first_entry(&blck_sgl_list,
  5530. struct lpfc_sglq,
  5531. list);
  5532. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5533. "3160 Failed to post els sgl-list, "
  5534. "xritag:x%x-x%x\n",
  5535. sglq_entry_first->sli4_xritag,
  5536. (sglq_entry_first->sli4_xritag +
  5537. post_cnt - 1));
  5538. list_splice_init(&blck_sgl_list, &free_sgl_list);
  5539. total_cnt -= post_cnt;
  5540. }
  5541. /* don't reset xirtag due to hole in xri block */
  5542. if (block_cnt == 0)
  5543. last_xritag = NO_XRI;
  5544. /* reset els sgl post count for next round of posting */
  5545. post_cnt = 0;
  5546. }
  5547. /* update the number of XRIs posted for ELS */
  5548. phba->sli4_hba.els_xri_cnt = total_cnt;
  5549. /* free the els sgls failed to post */
  5550. lpfc_free_sgl_list(phba, &free_sgl_list);
  5551. /* push els sgls posted to the availble list */
  5552. if (!list_empty(&post_sgl_list)) {
  5553. spin_lock_irq(&phba->hbalock);
  5554. list_splice_init(&post_sgl_list,
  5555. &phba->sli4_hba.lpfc_sgl_list);
  5556. spin_unlock_irq(&phba->hbalock);
  5557. } else {
  5558. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5559. "3161 Failure to post els sgl to port.\n");
  5560. return -EIO;
  5561. }
  5562. return 0;
  5563. }
  5564. /**
  5565. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5566. * @phba: Pointer to HBA context object.
  5567. *
  5568. * This function is the main SLI4 device intialization PCI function. This
  5569. * function is called by the HBA intialization code, HBA reset code and
  5570. * HBA error attention handler code. Caller is not required to hold any
  5571. * locks.
  5572. **/
  5573. int
  5574. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5575. {
  5576. int rc;
  5577. LPFC_MBOXQ_t *mboxq;
  5578. struct lpfc_mqe *mqe;
  5579. uint8_t *vpd;
  5580. uint32_t vpd_size;
  5581. uint32_t ftr_rsp = 0;
  5582. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5583. struct lpfc_vport *vport = phba->pport;
  5584. struct lpfc_dmabuf *mp;
  5585. /* Perform a PCI function reset to start from clean */
  5586. rc = lpfc_pci_function_reset(phba);
  5587. if (unlikely(rc))
  5588. return -ENODEV;
  5589. /* Check the HBA Host Status Register for readyness */
  5590. rc = lpfc_sli4_post_status_check(phba);
  5591. if (unlikely(rc))
  5592. return -ENODEV;
  5593. else {
  5594. spin_lock_irq(&phba->hbalock);
  5595. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5596. spin_unlock_irq(&phba->hbalock);
  5597. }
  5598. /*
  5599. * Allocate a single mailbox container for initializing the
  5600. * port.
  5601. */
  5602. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5603. if (!mboxq)
  5604. return -ENOMEM;
  5605. /* Issue READ_REV to collect vpd and FW information. */
  5606. vpd_size = SLI4_PAGE_SIZE;
  5607. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5608. if (!vpd) {
  5609. rc = -ENOMEM;
  5610. goto out_free_mbox;
  5611. }
  5612. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5613. if (unlikely(rc)) {
  5614. kfree(vpd);
  5615. goto out_free_mbox;
  5616. }
  5617. mqe = &mboxq->u.mqe;
  5618. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5619. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  5620. phba->hba_flag |= HBA_FCOE_MODE;
  5621. else
  5622. phba->hba_flag &= ~HBA_FCOE_MODE;
  5623. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5624. LPFC_DCBX_CEE_MODE)
  5625. phba->hba_flag |= HBA_FIP_SUPPORT;
  5626. else
  5627. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5628. phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
  5629. if (phba->sli_rev != LPFC_SLI_REV4) {
  5630. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5631. "0376 READ_REV Error. SLI Level %d "
  5632. "FCoE enabled %d\n",
  5633. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5634. rc = -EIO;
  5635. kfree(vpd);
  5636. goto out_free_mbox;
  5637. }
  5638. /*
  5639. * Continue initialization with default values even if driver failed
  5640. * to read FCoE param config regions, only read parameters if the
  5641. * board is FCoE
  5642. */
  5643. if (phba->hba_flag & HBA_FCOE_MODE &&
  5644. lpfc_sli4_read_fcoe_params(phba))
  5645. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5646. "2570 Failed to read FCoE parameters\n");
  5647. /*
  5648. * Retrieve sli4 device physical port name, failure of doing it
  5649. * is considered as non-fatal.
  5650. */
  5651. rc = lpfc_sli4_retrieve_pport_name(phba);
  5652. if (!rc)
  5653. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5654. "3080 Successful retrieving SLI4 device "
  5655. "physical port name: %s.\n", phba->Port);
  5656. /*
  5657. * Evaluate the read rev and vpd data. Populate the driver
  5658. * state with the results. If this routine fails, the failure
  5659. * is not fatal as the driver will use generic values.
  5660. */
  5661. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5662. if (unlikely(!rc)) {
  5663. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5664. "0377 Error %d parsing vpd. "
  5665. "Using defaults.\n", rc);
  5666. rc = 0;
  5667. }
  5668. kfree(vpd);
  5669. /* Save information as VPD data */
  5670. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5671. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5672. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5673. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5674. &mqe->un.read_rev);
  5675. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5676. &mqe->un.read_rev);
  5677. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5678. &mqe->un.read_rev);
  5679. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5680. &mqe->un.read_rev);
  5681. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5682. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5683. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5684. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5685. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5686. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5687. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5688. "(%d):0380 READ_REV Status x%x "
  5689. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5690. mboxq->vport ? mboxq->vport->vpi : 0,
  5691. bf_get(lpfc_mqe_status, mqe),
  5692. phba->vpd.rev.opFwName,
  5693. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5694. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5695. /*
  5696. * Discover the port's supported feature set and match it against the
  5697. * hosts requests.
  5698. */
  5699. lpfc_request_features(phba, mboxq);
  5700. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5701. if (unlikely(rc)) {
  5702. rc = -EIO;
  5703. goto out_free_mbox;
  5704. }
  5705. /*
  5706. * The port must support FCP initiator mode as this is the
  5707. * only mode running in the host.
  5708. */
  5709. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5710. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5711. "0378 No support for fcpi mode.\n");
  5712. ftr_rsp++;
  5713. }
  5714. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5715. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5716. else
  5717. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5718. /*
  5719. * If the port cannot support the host's requested features
  5720. * then turn off the global config parameters to disable the
  5721. * feature in the driver. This is not a fatal error.
  5722. */
  5723. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5724. if (phba->cfg_enable_bg) {
  5725. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5726. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5727. else
  5728. ftr_rsp++;
  5729. }
  5730. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5731. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5732. ftr_rsp++;
  5733. if (ftr_rsp) {
  5734. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5735. "0379 Feature Mismatch Data: x%08x %08x "
  5736. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5737. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5738. phba->cfg_enable_npiv, phba->max_vpi);
  5739. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5740. phba->cfg_enable_bg = 0;
  5741. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5742. phba->cfg_enable_npiv = 0;
  5743. }
  5744. /* These SLI3 features are assumed in SLI4 */
  5745. spin_lock_irq(&phba->hbalock);
  5746. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5747. spin_unlock_irq(&phba->hbalock);
  5748. /*
  5749. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5750. * calls depends on these resources to complete port setup.
  5751. */
  5752. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5753. if (rc) {
  5754. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5755. "2920 Failed to alloc Resource IDs "
  5756. "rc = x%x\n", rc);
  5757. goto out_free_mbox;
  5758. }
  5759. /* Read the port's service parameters. */
  5760. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5761. if (rc) {
  5762. phba->link_state = LPFC_HBA_ERROR;
  5763. rc = -ENOMEM;
  5764. goto out_free_mbox;
  5765. }
  5766. mboxq->vport = vport;
  5767. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5768. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5769. if (rc == MBX_SUCCESS) {
  5770. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5771. rc = 0;
  5772. }
  5773. /*
  5774. * This memory was allocated by the lpfc_read_sparam routine. Release
  5775. * it to the mbuf pool.
  5776. */
  5777. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5778. kfree(mp);
  5779. mboxq->context1 = NULL;
  5780. if (unlikely(rc)) {
  5781. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5782. "0382 READ_SPARAM command failed "
  5783. "status %d, mbxStatus x%x\n",
  5784. rc, bf_get(lpfc_mqe_status, mqe));
  5785. phba->link_state = LPFC_HBA_ERROR;
  5786. rc = -EIO;
  5787. goto out_free_mbox;
  5788. }
  5789. lpfc_update_vport_wwn(vport);
  5790. /* Update the fc_host data structures with new wwn. */
  5791. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5792. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5793. /* update host els and scsi xri-sgl sizes and mappings */
  5794. rc = lpfc_sli4_xri_sgl_update(phba);
  5795. if (unlikely(rc)) {
  5796. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5797. "1400 Failed to update xri-sgl size and "
  5798. "mapping: %d\n", rc);
  5799. goto out_free_mbox;
  5800. }
  5801. /* register the els sgl pool to the port */
  5802. rc = lpfc_sli4_repost_els_sgl_list(phba);
  5803. if (unlikely(rc)) {
  5804. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5805. "0582 Error %d during els sgl post "
  5806. "operation\n", rc);
  5807. rc = -ENODEV;
  5808. goto out_free_mbox;
  5809. }
  5810. /* register the allocated scsi sgl pool to the port */
  5811. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  5812. if (unlikely(rc)) {
  5813. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5814. "0383 Error %d during scsi sgl post "
  5815. "operation\n", rc);
  5816. /* Some Scsi buffers were moved to the abort scsi list */
  5817. /* A pci function reset will repost them */
  5818. rc = -ENODEV;
  5819. goto out_free_mbox;
  5820. }
  5821. /* Post the rpi header region to the device. */
  5822. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  5823. if (unlikely(rc)) {
  5824. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5825. "0393 Error %d during rpi post operation\n",
  5826. rc);
  5827. rc = -ENODEV;
  5828. goto out_free_mbox;
  5829. }
  5830. lpfc_sli4_node_prep(phba);
  5831. /* Create all the SLI4 queues */
  5832. rc = lpfc_sli4_queue_create(phba);
  5833. if (rc) {
  5834. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5835. "3089 Failed to allocate queues\n");
  5836. rc = -ENODEV;
  5837. goto out_stop_timers;
  5838. }
  5839. /* Set up all the queues to the device */
  5840. rc = lpfc_sli4_queue_setup(phba);
  5841. if (unlikely(rc)) {
  5842. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5843. "0381 Error %d during queue setup.\n ", rc);
  5844. goto out_destroy_queue;
  5845. }
  5846. /* Arm the CQs and then EQs on device */
  5847. lpfc_sli4_arm_cqeq_intr(phba);
  5848. /* Indicate device interrupt mode */
  5849. phba->sli4_hba.intr_enable = 1;
  5850. /* Allow asynchronous mailbox command to go through */
  5851. spin_lock_irq(&phba->hbalock);
  5852. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5853. spin_unlock_irq(&phba->hbalock);
  5854. /* Post receive buffers to the device */
  5855. lpfc_sli4_rb_setup(phba);
  5856. /* Reset HBA FCF states after HBA reset */
  5857. phba->fcf.fcf_flag = 0;
  5858. phba->fcf.current_rec.flag = 0;
  5859. /* Start the ELS watchdog timer */
  5860. mod_timer(&vport->els_tmofunc,
  5861. jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
  5862. /* Start heart beat timer */
  5863. mod_timer(&phba->hb_tmofunc,
  5864. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  5865. phba->hb_outstanding = 0;
  5866. phba->last_completion_time = jiffies;
  5867. /* Start error attention (ERATT) polling timer */
  5868. mod_timer(&phba->eratt_poll,
  5869. jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
  5870. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  5871. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  5872. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  5873. if (!rc) {
  5874. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5875. "2829 This device supports "
  5876. "Advanced Error Reporting (AER)\n");
  5877. spin_lock_irq(&phba->hbalock);
  5878. phba->hba_flag |= HBA_AER_ENABLED;
  5879. spin_unlock_irq(&phba->hbalock);
  5880. } else {
  5881. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5882. "2830 This device does not support "
  5883. "Advanced Error Reporting (AER)\n");
  5884. phba->cfg_aer_support = 0;
  5885. }
  5886. rc = 0;
  5887. }
  5888. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  5889. /*
  5890. * The FC Port needs to register FCFI (index 0)
  5891. */
  5892. lpfc_reg_fcfi(phba, mboxq);
  5893. mboxq->vport = phba->pport;
  5894. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5895. if (rc != MBX_SUCCESS)
  5896. goto out_unset_queue;
  5897. rc = 0;
  5898. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  5899. &mboxq->u.mqe.un.reg_fcfi);
  5900. /* Check if the port is configured to be disabled */
  5901. lpfc_sli_read_link_ste(phba);
  5902. }
  5903. /*
  5904. * The port is ready, set the host's link state to LINK_DOWN
  5905. * in preparation for link interrupts.
  5906. */
  5907. spin_lock_irq(&phba->hbalock);
  5908. phba->link_state = LPFC_LINK_DOWN;
  5909. spin_unlock_irq(&phba->hbalock);
  5910. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  5911. (phba->hba_flag & LINK_DISABLED)) {
  5912. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5913. "3103 Adapter Link is disabled.\n");
  5914. lpfc_down_link(phba, mboxq);
  5915. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5916. if (rc != MBX_SUCCESS) {
  5917. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5918. "3104 Adapter failed to issue "
  5919. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  5920. goto out_unset_queue;
  5921. }
  5922. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  5923. /* don't perform init_link on SLI4 FC port loopback test */
  5924. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  5925. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  5926. if (rc)
  5927. goto out_unset_queue;
  5928. }
  5929. }
  5930. mempool_free(mboxq, phba->mbox_mem_pool);
  5931. return rc;
  5932. out_unset_queue:
  5933. /* Unset all the queues set up in this routine when error out */
  5934. lpfc_sli4_queue_unset(phba);
  5935. out_destroy_queue:
  5936. lpfc_sli4_queue_destroy(phba);
  5937. out_stop_timers:
  5938. lpfc_stop_hba_timers(phba);
  5939. out_free_mbox:
  5940. mempool_free(mboxq, phba->mbox_mem_pool);
  5941. return rc;
  5942. }
  5943. /**
  5944. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  5945. * @ptr: context object - pointer to hba structure.
  5946. *
  5947. * This is the callback function for mailbox timer. The mailbox
  5948. * timer is armed when a new mailbox command is issued and the timer
  5949. * is deleted when the mailbox complete. The function is called by
  5950. * the kernel timer code when a mailbox does not complete within
  5951. * expected time. This function wakes up the worker thread to
  5952. * process the mailbox timeout and returns. All the processing is
  5953. * done by the worker thread function lpfc_mbox_timeout_handler.
  5954. **/
  5955. void
  5956. lpfc_mbox_timeout(unsigned long ptr)
  5957. {
  5958. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  5959. unsigned long iflag;
  5960. uint32_t tmo_posted;
  5961. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  5962. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  5963. if (!tmo_posted)
  5964. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  5965. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  5966. if (!tmo_posted)
  5967. lpfc_worker_wake_up(phba);
  5968. return;
  5969. }
  5970. /**
  5971. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  5972. * @phba: Pointer to HBA context object.
  5973. *
  5974. * This function is called from worker thread when a mailbox command times out.
  5975. * The caller is not required to hold any locks. This function will reset the
  5976. * HBA and recover all the pending commands.
  5977. **/
  5978. void
  5979. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  5980. {
  5981. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  5982. MAILBOX_t *mb = &pmbox->u.mb;
  5983. struct lpfc_sli *psli = &phba->sli;
  5984. struct lpfc_sli_ring *pring;
  5985. /* Check the pmbox pointer first. There is a race condition
  5986. * between the mbox timeout handler getting executed in the
  5987. * worklist and the mailbox actually completing. When this
  5988. * race condition occurs, the mbox_active will be NULL.
  5989. */
  5990. spin_lock_irq(&phba->hbalock);
  5991. if (pmbox == NULL) {
  5992. lpfc_printf_log(phba, KERN_WARNING,
  5993. LOG_MBOX | LOG_SLI,
  5994. "0353 Active Mailbox cleared - mailbox timeout "
  5995. "exiting\n");
  5996. spin_unlock_irq(&phba->hbalock);
  5997. return;
  5998. }
  5999. /* Mbox cmd <mbxCommand> timeout */
  6000. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6001. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  6002. mb->mbxCommand,
  6003. phba->pport->port_state,
  6004. phba->sli.sli_flag,
  6005. phba->sli.mbox_active);
  6006. spin_unlock_irq(&phba->hbalock);
  6007. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  6008. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  6009. * it to fail all outstanding SCSI IO.
  6010. */
  6011. spin_lock_irq(&phba->pport->work_port_lock);
  6012. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6013. spin_unlock_irq(&phba->pport->work_port_lock);
  6014. spin_lock_irq(&phba->hbalock);
  6015. phba->link_state = LPFC_LINK_UNKNOWN;
  6016. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  6017. spin_unlock_irq(&phba->hbalock);
  6018. pring = &psli->ring[psli->fcp_ring];
  6019. lpfc_sli_abort_iocb_ring(phba, pring);
  6020. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6021. "0345 Resetting board due to mailbox timeout\n");
  6022. /* Reset the HBA device */
  6023. lpfc_reset_hba(phba);
  6024. }
  6025. /**
  6026. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  6027. * @phba: Pointer to HBA context object.
  6028. * @pmbox: Pointer to mailbox object.
  6029. * @flag: Flag indicating how the mailbox need to be processed.
  6030. *
  6031. * This function is called by discovery code and HBA management code
  6032. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  6033. * function gets the hbalock to protect the data structures.
  6034. * The mailbox command can be submitted in polling mode, in which case
  6035. * this function will wait in a polling loop for the completion of the
  6036. * mailbox.
  6037. * If the mailbox is submitted in no_wait mode (not polling) the
  6038. * function will submit the command and returns immediately without waiting
  6039. * for the mailbox completion. The no_wait is supported only when HBA
  6040. * is in SLI2/SLI3 mode - interrupts are enabled.
  6041. * The SLI interface allows only one mailbox pending at a time. If the
  6042. * mailbox is issued in polling mode and there is already a mailbox
  6043. * pending, then the function will return an error. If the mailbox is issued
  6044. * in NO_WAIT mode and there is a mailbox pending already, the function
  6045. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  6046. * The sli layer owns the mailbox object until the completion of mailbox
  6047. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  6048. * return codes the caller owns the mailbox command after the return of
  6049. * the function.
  6050. **/
  6051. static int
  6052. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  6053. uint32_t flag)
  6054. {
  6055. MAILBOX_t *mbx;
  6056. struct lpfc_sli *psli = &phba->sli;
  6057. uint32_t status, evtctr;
  6058. uint32_t ha_copy, hc_copy;
  6059. int i;
  6060. unsigned long timeout;
  6061. unsigned long drvr_flag = 0;
  6062. uint32_t word0, ldata;
  6063. void __iomem *to_slim;
  6064. int processing_queue = 0;
  6065. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6066. if (!pmbox) {
  6067. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6068. /* processing mbox queue from intr_handler */
  6069. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6070. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6071. return MBX_SUCCESS;
  6072. }
  6073. processing_queue = 1;
  6074. pmbox = lpfc_mbox_get(phba);
  6075. if (!pmbox) {
  6076. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6077. return MBX_SUCCESS;
  6078. }
  6079. }
  6080. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  6081. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  6082. if(!pmbox->vport) {
  6083. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6084. lpfc_printf_log(phba, KERN_ERR,
  6085. LOG_MBOX | LOG_VPORT,
  6086. "1806 Mbox x%x failed. No vport\n",
  6087. pmbox->u.mb.mbxCommand);
  6088. dump_stack();
  6089. goto out_not_finished;
  6090. }
  6091. }
  6092. /* If the PCI channel is in offline state, do not post mbox. */
  6093. if (unlikely(pci_channel_offline(phba->pcidev))) {
  6094. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6095. goto out_not_finished;
  6096. }
  6097. /* If HBA has a deferred error attention, fail the iocb. */
  6098. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  6099. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6100. goto out_not_finished;
  6101. }
  6102. psli = &phba->sli;
  6103. mbx = &pmbox->u.mb;
  6104. status = MBX_SUCCESS;
  6105. if (phba->link_state == LPFC_HBA_ERROR) {
  6106. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6107. /* Mbox command <mbxCommand> cannot issue */
  6108. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6109. "(%d):0311 Mailbox command x%x cannot "
  6110. "issue Data: x%x x%x\n",
  6111. pmbox->vport ? pmbox->vport->vpi : 0,
  6112. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6113. goto out_not_finished;
  6114. }
  6115. if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  6116. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  6117. !(hc_copy & HC_MBINT_ENA)) {
  6118. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6119. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6120. "(%d):2528 Mailbox command x%x cannot "
  6121. "issue Data: x%x x%x\n",
  6122. pmbox->vport ? pmbox->vport->vpi : 0,
  6123. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6124. goto out_not_finished;
  6125. }
  6126. }
  6127. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6128. /* Polling for a mbox command when another one is already active
  6129. * is not allowed in SLI. Also, the driver must have established
  6130. * SLI2 mode to queue and process multiple mbox commands.
  6131. */
  6132. if (flag & MBX_POLL) {
  6133. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6134. /* Mbox command <mbxCommand> cannot issue */
  6135. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6136. "(%d):2529 Mailbox command x%x "
  6137. "cannot issue Data: x%x x%x\n",
  6138. pmbox->vport ? pmbox->vport->vpi : 0,
  6139. pmbox->u.mb.mbxCommand,
  6140. psli->sli_flag, flag);
  6141. goto out_not_finished;
  6142. }
  6143. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6144. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6145. /* Mbox command <mbxCommand> cannot issue */
  6146. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6147. "(%d):2530 Mailbox command x%x "
  6148. "cannot issue Data: x%x x%x\n",
  6149. pmbox->vport ? pmbox->vport->vpi : 0,
  6150. pmbox->u.mb.mbxCommand,
  6151. psli->sli_flag, flag);
  6152. goto out_not_finished;
  6153. }
  6154. /* Another mailbox command is still being processed, queue this
  6155. * command to be processed later.
  6156. */
  6157. lpfc_mbox_put(phba, pmbox);
  6158. /* Mbox cmd issue - BUSY */
  6159. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6160. "(%d):0308 Mbox cmd issue - BUSY Data: "
  6161. "x%x x%x x%x x%x\n",
  6162. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  6163. mbx->mbxCommand, phba->pport->port_state,
  6164. psli->sli_flag, flag);
  6165. psli->slistat.mbox_busy++;
  6166. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6167. if (pmbox->vport) {
  6168. lpfc_debugfs_disc_trc(pmbox->vport,
  6169. LPFC_DISC_TRC_MBOX_VPORT,
  6170. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  6171. (uint32_t)mbx->mbxCommand,
  6172. mbx->un.varWords[0], mbx->un.varWords[1]);
  6173. }
  6174. else {
  6175. lpfc_debugfs_disc_trc(phba->pport,
  6176. LPFC_DISC_TRC_MBOX,
  6177. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  6178. (uint32_t)mbx->mbxCommand,
  6179. mbx->un.varWords[0], mbx->un.varWords[1]);
  6180. }
  6181. return MBX_BUSY;
  6182. }
  6183. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6184. /* If we are not polling, we MUST be in SLI2 mode */
  6185. if (flag != MBX_POLL) {
  6186. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  6187. (mbx->mbxCommand != MBX_KILL_BOARD)) {
  6188. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6189. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6190. /* Mbox command <mbxCommand> cannot issue */
  6191. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6192. "(%d):2531 Mailbox command x%x "
  6193. "cannot issue Data: x%x x%x\n",
  6194. pmbox->vport ? pmbox->vport->vpi : 0,
  6195. pmbox->u.mb.mbxCommand,
  6196. psli->sli_flag, flag);
  6197. goto out_not_finished;
  6198. }
  6199. /* timeout active mbox command */
  6200. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6201. 1000);
  6202. mod_timer(&psli->mbox_tmo, jiffies + timeout);
  6203. }
  6204. /* Mailbox cmd <cmd> issue */
  6205. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6206. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  6207. "x%x\n",
  6208. pmbox->vport ? pmbox->vport->vpi : 0,
  6209. mbx->mbxCommand, phba->pport->port_state,
  6210. psli->sli_flag, flag);
  6211. if (mbx->mbxCommand != MBX_HEARTBEAT) {
  6212. if (pmbox->vport) {
  6213. lpfc_debugfs_disc_trc(pmbox->vport,
  6214. LPFC_DISC_TRC_MBOX_VPORT,
  6215. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6216. (uint32_t)mbx->mbxCommand,
  6217. mbx->un.varWords[0], mbx->un.varWords[1]);
  6218. }
  6219. else {
  6220. lpfc_debugfs_disc_trc(phba->pport,
  6221. LPFC_DISC_TRC_MBOX,
  6222. "MBOX Send: cmd:x%x mb:x%x x%x",
  6223. (uint32_t)mbx->mbxCommand,
  6224. mbx->un.varWords[0], mbx->un.varWords[1]);
  6225. }
  6226. }
  6227. psli->slistat.mbox_cmd++;
  6228. evtctr = psli->slistat.mbox_event;
  6229. /* next set own bit for the adapter and copy over command word */
  6230. mbx->mbxOwner = OWN_CHIP;
  6231. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6232. /* Populate mbox extension offset word. */
  6233. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  6234. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6235. = (uint8_t *)phba->mbox_ext
  6236. - (uint8_t *)phba->mbox;
  6237. }
  6238. /* Copy the mailbox extension data */
  6239. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6240. lpfc_sli_pcimem_bcopy(pmbox->context2,
  6241. (uint8_t *)phba->mbox_ext,
  6242. pmbox->in_ext_byte_len);
  6243. }
  6244. /* Copy command data to host SLIM area */
  6245. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6246. } else {
  6247. /* Populate mbox extension offset word. */
  6248. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  6249. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6250. = MAILBOX_HBA_EXT_OFFSET;
  6251. /* Copy the mailbox extension data */
  6252. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6253. lpfc_memcpy_to_slim(phba->MBslimaddr +
  6254. MAILBOX_HBA_EXT_OFFSET,
  6255. pmbox->context2, pmbox->in_ext_byte_len);
  6256. }
  6257. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6258. /* copy command data into host mbox for cmpl */
  6259. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6260. }
  6261. /* First copy mbox command data to HBA SLIM, skip past first
  6262. word */
  6263. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6264. lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
  6265. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6266. /* Next copy over first word, with mbxOwner set */
  6267. ldata = *((uint32_t *)mbx);
  6268. to_slim = phba->MBslimaddr;
  6269. writel(ldata, to_slim);
  6270. readl(to_slim); /* flush */
  6271. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6272. /* switch over to host mailbox */
  6273. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6274. }
  6275. }
  6276. wmb();
  6277. switch (flag) {
  6278. case MBX_NOWAIT:
  6279. /* Set up reference to mailbox command */
  6280. psli->mbox_active = pmbox;
  6281. /* Interrupt board to do it */
  6282. writel(CA_MBATT, phba->CAregaddr);
  6283. readl(phba->CAregaddr); /* flush */
  6284. /* Don't wait for it to finish, just return */
  6285. break;
  6286. case MBX_POLL:
  6287. /* Set up null reference to mailbox command */
  6288. psli->mbox_active = NULL;
  6289. /* Interrupt board to do it */
  6290. writel(CA_MBATT, phba->CAregaddr);
  6291. readl(phba->CAregaddr); /* flush */
  6292. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6293. /* First read mbox status word */
  6294. word0 = *((uint32_t *)phba->mbox);
  6295. word0 = le32_to_cpu(word0);
  6296. } else {
  6297. /* First read mbox status word */
  6298. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6299. spin_unlock_irqrestore(&phba->hbalock,
  6300. drvr_flag);
  6301. goto out_not_finished;
  6302. }
  6303. }
  6304. /* Read the HBA Host Attention Register */
  6305. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6306. spin_unlock_irqrestore(&phba->hbalock,
  6307. drvr_flag);
  6308. goto out_not_finished;
  6309. }
  6310. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6311. 1000) + jiffies;
  6312. i = 0;
  6313. /* Wait for command to complete */
  6314. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6315. (!(ha_copy & HA_MBATT) &&
  6316. (phba->link_state > LPFC_WARM_START))) {
  6317. if (time_after(jiffies, timeout)) {
  6318. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6319. spin_unlock_irqrestore(&phba->hbalock,
  6320. drvr_flag);
  6321. goto out_not_finished;
  6322. }
  6323. /* Check if we took a mbox interrupt while we were
  6324. polling */
  6325. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6326. && (evtctr != psli->slistat.mbox_event))
  6327. break;
  6328. if (i++ > 10) {
  6329. spin_unlock_irqrestore(&phba->hbalock,
  6330. drvr_flag);
  6331. msleep(1);
  6332. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6333. }
  6334. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6335. /* First copy command data */
  6336. word0 = *((uint32_t *)phba->mbox);
  6337. word0 = le32_to_cpu(word0);
  6338. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6339. MAILBOX_t *slimmb;
  6340. uint32_t slimword0;
  6341. /* Check real SLIM for any errors */
  6342. slimword0 = readl(phba->MBslimaddr);
  6343. slimmb = (MAILBOX_t *) & slimword0;
  6344. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6345. && slimmb->mbxStatus) {
  6346. psli->sli_flag &=
  6347. ~LPFC_SLI_ACTIVE;
  6348. word0 = slimword0;
  6349. }
  6350. }
  6351. } else {
  6352. /* First copy command data */
  6353. word0 = readl(phba->MBslimaddr);
  6354. }
  6355. /* Read the HBA Host Attention Register */
  6356. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6357. spin_unlock_irqrestore(&phba->hbalock,
  6358. drvr_flag);
  6359. goto out_not_finished;
  6360. }
  6361. }
  6362. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6363. /* copy results back to user */
  6364. lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE);
  6365. /* Copy the mailbox extension data */
  6366. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6367. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6368. pmbox->context2,
  6369. pmbox->out_ext_byte_len);
  6370. }
  6371. } else {
  6372. /* First copy command data */
  6373. lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
  6374. MAILBOX_CMD_SIZE);
  6375. /* Copy the mailbox extension data */
  6376. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6377. lpfc_memcpy_from_slim(pmbox->context2,
  6378. phba->MBslimaddr +
  6379. MAILBOX_HBA_EXT_OFFSET,
  6380. pmbox->out_ext_byte_len);
  6381. }
  6382. }
  6383. writel(HA_MBATT, phba->HAregaddr);
  6384. readl(phba->HAregaddr); /* flush */
  6385. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6386. status = mbx->mbxStatus;
  6387. }
  6388. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6389. return status;
  6390. out_not_finished:
  6391. if (processing_queue) {
  6392. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6393. lpfc_mbox_cmpl_put(phba, pmbox);
  6394. }
  6395. return MBX_NOT_FINISHED;
  6396. }
  6397. /**
  6398. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6399. * @phba: Pointer to HBA context object.
  6400. *
  6401. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6402. * the driver internal pending mailbox queue. It will then try to wait out the
  6403. * possible outstanding mailbox command before return.
  6404. *
  6405. * Returns:
  6406. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6407. * the outstanding mailbox command timed out.
  6408. **/
  6409. static int
  6410. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6411. {
  6412. struct lpfc_sli *psli = &phba->sli;
  6413. int rc = 0;
  6414. unsigned long timeout = 0;
  6415. /* Mark the asynchronous mailbox command posting as blocked */
  6416. spin_lock_irq(&phba->hbalock);
  6417. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6418. /* Determine how long we might wait for the active mailbox
  6419. * command to be gracefully completed by firmware.
  6420. */
  6421. if (phba->sli.mbox_active)
  6422. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6423. phba->sli.mbox_active) *
  6424. 1000) + jiffies;
  6425. spin_unlock_irq(&phba->hbalock);
  6426. /* Wait for the outstnading mailbox command to complete */
  6427. while (phba->sli.mbox_active) {
  6428. /* Check active mailbox complete status every 2ms */
  6429. msleep(2);
  6430. if (time_after(jiffies, timeout)) {
  6431. /* Timeout, marked the outstanding cmd not complete */
  6432. rc = 1;
  6433. break;
  6434. }
  6435. }
  6436. /* Can not cleanly block async mailbox command, fails it */
  6437. if (rc) {
  6438. spin_lock_irq(&phba->hbalock);
  6439. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6440. spin_unlock_irq(&phba->hbalock);
  6441. }
  6442. return rc;
  6443. }
  6444. /**
  6445. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6446. * @phba: Pointer to HBA context object.
  6447. *
  6448. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6449. * commands from the driver internal pending mailbox queue. It makes sure
  6450. * that there is no outstanding mailbox command before resuming posting
  6451. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6452. * mailbox command, it will try to wait it out before resuming asynchronous
  6453. * mailbox command posting.
  6454. **/
  6455. static void
  6456. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6457. {
  6458. struct lpfc_sli *psli = &phba->sli;
  6459. spin_lock_irq(&phba->hbalock);
  6460. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6461. /* Asynchronous mailbox posting is not blocked, do nothing */
  6462. spin_unlock_irq(&phba->hbalock);
  6463. return;
  6464. }
  6465. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6466. * successful or timeout, after timing-out the outstanding mailbox
  6467. * command shall always be removed, so just unblock posting async
  6468. * mailbox command and resume
  6469. */
  6470. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6471. spin_unlock_irq(&phba->hbalock);
  6472. /* wake up worker thread to post asynchronlous mailbox command */
  6473. lpfc_worker_wake_up(phba);
  6474. }
  6475. /**
  6476. * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
  6477. * @phba: Pointer to HBA context object.
  6478. * @mboxq: Pointer to mailbox object.
  6479. *
  6480. * The function waits for the bootstrap mailbox register ready bit from
  6481. * port for twice the regular mailbox command timeout value.
  6482. *
  6483. * 0 - no timeout on waiting for bootstrap mailbox register ready.
  6484. * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
  6485. **/
  6486. static int
  6487. lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6488. {
  6489. uint32_t db_ready;
  6490. unsigned long timeout;
  6491. struct lpfc_register bmbx_reg;
  6492. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6493. * 1000) + jiffies;
  6494. do {
  6495. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6496. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6497. if (!db_ready)
  6498. msleep(2);
  6499. if (time_after(jiffies, timeout))
  6500. return MBXERR_ERROR;
  6501. } while (!db_ready);
  6502. return 0;
  6503. }
  6504. /**
  6505. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6506. * @phba: Pointer to HBA context object.
  6507. * @mboxq: Pointer to mailbox object.
  6508. *
  6509. * The function posts a mailbox to the port. The mailbox is expected
  6510. * to be comletely filled in and ready for the port to operate on it.
  6511. * This routine executes a synchronous completion operation on the
  6512. * mailbox by polling for its completion.
  6513. *
  6514. * The caller must not be holding any locks when calling this routine.
  6515. *
  6516. * Returns:
  6517. * MBX_SUCCESS - mailbox posted successfully
  6518. * Any of the MBX error values.
  6519. **/
  6520. static int
  6521. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6522. {
  6523. int rc = MBX_SUCCESS;
  6524. unsigned long iflag;
  6525. uint32_t mcqe_status;
  6526. uint32_t mbx_cmnd;
  6527. struct lpfc_sli *psli = &phba->sli;
  6528. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6529. struct lpfc_bmbx_create *mbox_rgn;
  6530. struct dma_address *dma_address;
  6531. /*
  6532. * Only one mailbox can be active to the bootstrap mailbox region
  6533. * at a time and there is no queueing provided.
  6534. */
  6535. spin_lock_irqsave(&phba->hbalock, iflag);
  6536. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6537. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6538. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6539. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6540. "cannot issue Data: x%x x%x\n",
  6541. mboxq->vport ? mboxq->vport->vpi : 0,
  6542. mboxq->u.mb.mbxCommand,
  6543. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6544. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6545. psli->sli_flag, MBX_POLL);
  6546. return MBXERR_ERROR;
  6547. }
  6548. /* The server grabs the token and owns it until release */
  6549. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6550. phba->sli.mbox_active = mboxq;
  6551. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6552. /* wait for bootstrap mbox register for readyness */
  6553. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6554. if (rc)
  6555. goto exit;
  6556. /*
  6557. * Initialize the bootstrap memory region to avoid stale data areas
  6558. * in the mailbox post. Then copy the caller's mailbox contents to
  6559. * the bmbx mailbox region.
  6560. */
  6561. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6562. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6563. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6564. sizeof(struct lpfc_mqe));
  6565. /* Post the high mailbox dma address to the port and wait for ready. */
  6566. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6567. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6568. /* wait for bootstrap mbox register for hi-address write done */
  6569. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6570. if (rc)
  6571. goto exit;
  6572. /* Post the low mailbox dma address to the port. */
  6573. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6574. /* wait for bootstrap mbox register for low address write done */
  6575. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6576. if (rc)
  6577. goto exit;
  6578. /*
  6579. * Read the CQ to ensure the mailbox has completed.
  6580. * If so, update the mailbox status so that the upper layers
  6581. * can complete the request normally.
  6582. */
  6583. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6584. sizeof(struct lpfc_mqe));
  6585. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6586. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6587. sizeof(struct lpfc_mcqe));
  6588. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6589. /*
  6590. * When the CQE status indicates a failure and the mailbox status
  6591. * indicates success then copy the CQE status into the mailbox status
  6592. * (and prefix it with x4000).
  6593. */
  6594. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6595. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6596. bf_set(lpfc_mqe_status, mb,
  6597. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6598. rc = MBXERR_ERROR;
  6599. } else
  6600. lpfc_sli4_swap_str(phba, mboxq);
  6601. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6602. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6603. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6604. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6605. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6606. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6607. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6608. bf_get(lpfc_mqe_status, mb),
  6609. mb->un.mb_words[0], mb->un.mb_words[1],
  6610. mb->un.mb_words[2], mb->un.mb_words[3],
  6611. mb->un.mb_words[4], mb->un.mb_words[5],
  6612. mb->un.mb_words[6], mb->un.mb_words[7],
  6613. mb->un.mb_words[8], mb->un.mb_words[9],
  6614. mb->un.mb_words[10], mb->un.mb_words[11],
  6615. mb->un.mb_words[12], mboxq->mcqe.word0,
  6616. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6617. mboxq->mcqe.trailer);
  6618. exit:
  6619. /* We are holding the token, no needed for lock when release */
  6620. spin_lock_irqsave(&phba->hbalock, iflag);
  6621. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6622. phba->sli.mbox_active = NULL;
  6623. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6624. return rc;
  6625. }
  6626. /**
  6627. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6628. * @phba: Pointer to HBA context object.
  6629. * @pmbox: Pointer to mailbox object.
  6630. * @flag: Flag indicating how the mailbox need to be processed.
  6631. *
  6632. * This function is called by discovery code and HBA management code to submit
  6633. * a mailbox command to firmware with SLI-4 interface spec.
  6634. *
  6635. * Return codes the caller owns the mailbox command after the return of the
  6636. * function.
  6637. **/
  6638. static int
  6639. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6640. uint32_t flag)
  6641. {
  6642. struct lpfc_sli *psli = &phba->sli;
  6643. unsigned long iflags;
  6644. int rc;
  6645. /* dump from issue mailbox command if setup */
  6646. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6647. rc = lpfc_mbox_dev_check(phba);
  6648. if (unlikely(rc)) {
  6649. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6650. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6651. "cannot issue Data: x%x x%x\n",
  6652. mboxq->vport ? mboxq->vport->vpi : 0,
  6653. mboxq->u.mb.mbxCommand,
  6654. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6655. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6656. psli->sli_flag, flag);
  6657. goto out_not_finished;
  6658. }
  6659. /* Detect polling mode and jump to a handler */
  6660. if (!phba->sli4_hba.intr_enable) {
  6661. if (flag == MBX_POLL)
  6662. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6663. else
  6664. rc = -EIO;
  6665. if (rc != MBX_SUCCESS)
  6666. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6667. "(%d):2541 Mailbox command x%x "
  6668. "(x%x/x%x) failure: "
  6669. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6670. "Data: x%x x%x\n,",
  6671. mboxq->vport ? mboxq->vport->vpi : 0,
  6672. mboxq->u.mb.mbxCommand,
  6673. lpfc_sli_config_mbox_subsys_get(phba,
  6674. mboxq),
  6675. lpfc_sli_config_mbox_opcode_get(phba,
  6676. mboxq),
  6677. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6678. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6679. bf_get(lpfc_mcqe_ext_status,
  6680. &mboxq->mcqe),
  6681. psli->sli_flag, flag);
  6682. return rc;
  6683. } else if (flag == MBX_POLL) {
  6684. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6685. "(%d):2542 Try to issue mailbox command "
  6686. "x%x (x%x/x%x) synchronously ahead of async"
  6687. "mailbox command queue: x%x x%x\n",
  6688. mboxq->vport ? mboxq->vport->vpi : 0,
  6689. mboxq->u.mb.mbxCommand,
  6690. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6691. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6692. psli->sli_flag, flag);
  6693. /* Try to block the asynchronous mailbox posting */
  6694. rc = lpfc_sli4_async_mbox_block(phba);
  6695. if (!rc) {
  6696. /* Successfully blocked, now issue sync mbox cmd */
  6697. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6698. if (rc != MBX_SUCCESS)
  6699. lpfc_printf_log(phba, KERN_WARNING,
  6700. LOG_MBOX | LOG_SLI,
  6701. "(%d):2597 Sync Mailbox command "
  6702. "x%x (x%x/x%x) failure: "
  6703. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6704. "Data: x%x x%x\n,",
  6705. mboxq->vport ? mboxq->vport->vpi : 0,
  6706. mboxq->u.mb.mbxCommand,
  6707. lpfc_sli_config_mbox_subsys_get(phba,
  6708. mboxq),
  6709. lpfc_sli_config_mbox_opcode_get(phba,
  6710. mboxq),
  6711. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6712. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6713. bf_get(lpfc_mcqe_ext_status,
  6714. &mboxq->mcqe),
  6715. psli->sli_flag, flag);
  6716. /* Unblock the async mailbox posting afterward */
  6717. lpfc_sli4_async_mbox_unblock(phba);
  6718. }
  6719. return rc;
  6720. }
  6721. /* Now, interrupt mode asynchrous mailbox command */
  6722. rc = lpfc_mbox_cmd_check(phba, mboxq);
  6723. if (rc) {
  6724. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6725. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  6726. "cannot issue Data: x%x x%x\n",
  6727. mboxq->vport ? mboxq->vport->vpi : 0,
  6728. mboxq->u.mb.mbxCommand,
  6729. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6730. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6731. psli->sli_flag, flag);
  6732. goto out_not_finished;
  6733. }
  6734. /* Put the mailbox command to the driver internal FIFO */
  6735. psli->slistat.mbox_busy++;
  6736. spin_lock_irqsave(&phba->hbalock, iflags);
  6737. lpfc_mbox_put(phba, mboxq);
  6738. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6739. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6740. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  6741. "x%x (x%x/x%x) x%x x%x x%x\n",
  6742. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  6743. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  6744. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6745. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6746. phba->pport->port_state,
  6747. psli->sli_flag, MBX_NOWAIT);
  6748. /* Wake up worker thread to transport mailbox command from head */
  6749. lpfc_worker_wake_up(phba);
  6750. return MBX_BUSY;
  6751. out_not_finished:
  6752. return MBX_NOT_FINISHED;
  6753. }
  6754. /**
  6755. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  6756. * @phba: Pointer to HBA context object.
  6757. *
  6758. * This function is called by worker thread to send a mailbox command to
  6759. * SLI4 HBA firmware.
  6760. *
  6761. **/
  6762. int
  6763. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  6764. {
  6765. struct lpfc_sli *psli = &phba->sli;
  6766. LPFC_MBOXQ_t *mboxq;
  6767. int rc = MBX_SUCCESS;
  6768. unsigned long iflags;
  6769. struct lpfc_mqe *mqe;
  6770. uint32_t mbx_cmnd;
  6771. /* Check interrupt mode before post async mailbox command */
  6772. if (unlikely(!phba->sli4_hba.intr_enable))
  6773. return MBX_NOT_FINISHED;
  6774. /* Check for mailbox command service token */
  6775. spin_lock_irqsave(&phba->hbalock, iflags);
  6776. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6777. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6778. return MBX_NOT_FINISHED;
  6779. }
  6780. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6781. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6782. return MBX_NOT_FINISHED;
  6783. }
  6784. if (unlikely(phba->sli.mbox_active)) {
  6785. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6786. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6787. "0384 There is pending active mailbox cmd\n");
  6788. return MBX_NOT_FINISHED;
  6789. }
  6790. /* Take the mailbox command service token */
  6791. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6792. /* Get the next mailbox command from head of queue */
  6793. mboxq = lpfc_mbox_get(phba);
  6794. /* If no more mailbox command waiting for post, we're done */
  6795. if (!mboxq) {
  6796. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6797. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6798. return MBX_SUCCESS;
  6799. }
  6800. phba->sli.mbox_active = mboxq;
  6801. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6802. /* Check device readiness for posting mailbox command */
  6803. rc = lpfc_mbox_dev_check(phba);
  6804. if (unlikely(rc))
  6805. /* Driver clean routine will clean up pending mailbox */
  6806. goto out_not_finished;
  6807. /* Prepare the mbox command to be posted */
  6808. mqe = &mboxq->u.mqe;
  6809. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  6810. /* Start timer for the mbox_tmo and log some mailbox post messages */
  6811. mod_timer(&psli->mbox_tmo, (jiffies +
  6812. msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
  6813. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6814. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  6815. "x%x x%x\n",
  6816. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6817. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6818. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6819. phba->pport->port_state, psli->sli_flag);
  6820. if (mbx_cmnd != MBX_HEARTBEAT) {
  6821. if (mboxq->vport) {
  6822. lpfc_debugfs_disc_trc(mboxq->vport,
  6823. LPFC_DISC_TRC_MBOX_VPORT,
  6824. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6825. mbx_cmnd, mqe->un.mb_words[0],
  6826. mqe->un.mb_words[1]);
  6827. } else {
  6828. lpfc_debugfs_disc_trc(phba->pport,
  6829. LPFC_DISC_TRC_MBOX,
  6830. "MBOX Send: cmd:x%x mb:x%x x%x",
  6831. mbx_cmnd, mqe->un.mb_words[0],
  6832. mqe->un.mb_words[1]);
  6833. }
  6834. }
  6835. psli->slistat.mbox_cmd++;
  6836. /* Post the mailbox command to the port */
  6837. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  6838. if (rc != MBX_SUCCESS) {
  6839. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6840. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  6841. "cannot issue Data: x%x x%x\n",
  6842. mboxq->vport ? mboxq->vport->vpi : 0,
  6843. mboxq->u.mb.mbxCommand,
  6844. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6845. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6846. psli->sli_flag, MBX_NOWAIT);
  6847. goto out_not_finished;
  6848. }
  6849. return rc;
  6850. out_not_finished:
  6851. spin_lock_irqsave(&phba->hbalock, iflags);
  6852. if (phba->sli.mbox_active) {
  6853. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6854. __lpfc_mbox_cmpl_put(phba, mboxq);
  6855. /* Release the token */
  6856. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6857. phba->sli.mbox_active = NULL;
  6858. }
  6859. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6860. return MBX_NOT_FINISHED;
  6861. }
  6862. /**
  6863. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  6864. * @phba: Pointer to HBA context object.
  6865. * @pmbox: Pointer to mailbox object.
  6866. * @flag: Flag indicating how the mailbox need to be processed.
  6867. *
  6868. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  6869. * the API jump table function pointer from the lpfc_hba struct.
  6870. *
  6871. * Return codes the caller owns the mailbox command after the return of the
  6872. * function.
  6873. **/
  6874. int
  6875. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  6876. {
  6877. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  6878. }
  6879. /**
  6880. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  6881. * @phba: The hba struct for which this call is being executed.
  6882. * @dev_grp: The HBA PCI-Device group number.
  6883. *
  6884. * This routine sets up the mbox interface API function jump table in @phba
  6885. * struct.
  6886. * Returns: 0 - success, -ENODEV - failure.
  6887. **/
  6888. int
  6889. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6890. {
  6891. switch (dev_grp) {
  6892. case LPFC_PCI_DEV_LP:
  6893. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  6894. phba->lpfc_sli_handle_slow_ring_event =
  6895. lpfc_sli_handle_slow_ring_event_s3;
  6896. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  6897. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  6898. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  6899. break;
  6900. case LPFC_PCI_DEV_OC:
  6901. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  6902. phba->lpfc_sli_handle_slow_ring_event =
  6903. lpfc_sli_handle_slow_ring_event_s4;
  6904. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  6905. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  6906. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  6907. break;
  6908. default:
  6909. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6910. "1420 Invalid HBA PCI-device group: 0x%x\n",
  6911. dev_grp);
  6912. return -ENODEV;
  6913. break;
  6914. }
  6915. return 0;
  6916. }
  6917. /**
  6918. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  6919. * @phba: Pointer to HBA context object.
  6920. * @pring: Pointer to driver SLI ring object.
  6921. * @piocb: Pointer to address of newly added command iocb.
  6922. *
  6923. * This function is called with hbalock held to add a command
  6924. * iocb to the txq when SLI layer cannot submit the command iocb
  6925. * to the ring.
  6926. **/
  6927. void
  6928. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6929. struct lpfc_iocbq *piocb)
  6930. {
  6931. /* Insert the caller's iocb in the txq tail for later processing. */
  6932. list_add_tail(&piocb->list, &pring->txq);
  6933. }
  6934. /**
  6935. * lpfc_sli_next_iocb - Get the next iocb in the txq
  6936. * @phba: Pointer to HBA context object.
  6937. * @pring: Pointer to driver SLI ring object.
  6938. * @piocb: Pointer to address of newly added command iocb.
  6939. *
  6940. * This function is called with hbalock held before a new
  6941. * iocb is submitted to the firmware. This function checks
  6942. * txq to flush the iocbs in txq to Firmware before
  6943. * submitting new iocbs to the Firmware.
  6944. * If there are iocbs in the txq which need to be submitted
  6945. * to firmware, lpfc_sli_next_iocb returns the first element
  6946. * of the txq after dequeuing it from txq.
  6947. * If there is no iocb in the txq then the function will return
  6948. * *piocb and *piocb is set to NULL. Caller needs to check
  6949. * *piocb to find if there are more commands in the txq.
  6950. **/
  6951. static struct lpfc_iocbq *
  6952. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6953. struct lpfc_iocbq **piocb)
  6954. {
  6955. struct lpfc_iocbq * nextiocb;
  6956. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  6957. if (!nextiocb) {
  6958. nextiocb = *piocb;
  6959. *piocb = NULL;
  6960. }
  6961. return nextiocb;
  6962. }
  6963. /**
  6964. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  6965. * @phba: Pointer to HBA context object.
  6966. * @ring_number: SLI ring number to issue iocb on.
  6967. * @piocb: Pointer to command iocb.
  6968. * @flag: Flag indicating if this command can be put into txq.
  6969. *
  6970. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  6971. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  6972. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  6973. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  6974. * this function allows only iocbs for posting buffers. This function finds
  6975. * next available slot in the command ring and posts the command to the
  6976. * available slot and writes the port attention register to request HBA start
  6977. * processing new iocb. If there is no slot available in the ring and
  6978. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  6979. * the function returns IOCB_BUSY.
  6980. *
  6981. * This function is called with hbalock held. The function will return success
  6982. * after it successfully submit the iocb to firmware or after adding to the
  6983. * txq.
  6984. **/
  6985. static int
  6986. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  6987. struct lpfc_iocbq *piocb, uint32_t flag)
  6988. {
  6989. struct lpfc_iocbq *nextiocb;
  6990. IOCB_t *iocb;
  6991. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6992. if (piocb->iocb_cmpl && (!piocb->vport) &&
  6993. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  6994. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  6995. lpfc_printf_log(phba, KERN_ERR,
  6996. LOG_SLI | LOG_VPORT,
  6997. "1807 IOCB x%x failed. No vport\n",
  6998. piocb->iocb.ulpCommand);
  6999. dump_stack();
  7000. return IOCB_ERROR;
  7001. }
  7002. /* If the PCI channel is in offline state, do not post iocbs. */
  7003. if (unlikely(pci_channel_offline(phba->pcidev)))
  7004. return IOCB_ERROR;
  7005. /* If HBA has a deferred error attention, fail the iocb. */
  7006. if (unlikely(phba->hba_flag & DEFER_ERATT))
  7007. return IOCB_ERROR;
  7008. /*
  7009. * We should never get an IOCB if we are in a < LINK_DOWN state
  7010. */
  7011. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7012. return IOCB_ERROR;
  7013. /*
  7014. * Check to see if we are blocking IOCB processing because of a
  7015. * outstanding event.
  7016. */
  7017. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  7018. goto iocb_busy;
  7019. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  7020. /*
  7021. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  7022. * can be issued if the link is not up.
  7023. */
  7024. switch (piocb->iocb.ulpCommand) {
  7025. case CMD_GEN_REQUEST64_CR:
  7026. case CMD_GEN_REQUEST64_CX:
  7027. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  7028. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  7029. FC_RCTL_DD_UNSOL_CMD) ||
  7030. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  7031. MENLO_TRANSPORT_TYPE))
  7032. goto iocb_busy;
  7033. break;
  7034. case CMD_QUE_RING_BUF_CN:
  7035. case CMD_QUE_RING_BUF64_CN:
  7036. /*
  7037. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  7038. * completion, iocb_cmpl MUST be 0.
  7039. */
  7040. if (piocb->iocb_cmpl)
  7041. piocb->iocb_cmpl = NULL;
  7042. /*FALLTHROUGH*/
  7043. case CMD_CREATE_XRI_CR:
  7044. case CMD_CLOSE_XRI_CN:
  7045. case CMD_CLOSE_XRI_CX:
  7046. break;
  7047. default:
  7048. goto iocb_busy;
  7049. }
  7050. /*
  7051. * For FCP commands, we must be in a state where we can process link
  7052. * attention events.
  7053. */
  7054. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  7055. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  7056. goto iocb_busy;
  7057. }
  7058. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  7059. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  7060. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  7061. if (iocb)
  7062. lpfc_sli_update_ring(phba, pring);
  7063. else
  7064. lpfc_sli_update_full_ring(phba, pring);
  7065. if (!piocb)
  7066. return IOCB_SUCCESS;
  7067. goto out_busy;
  7068. iocb_busy:
  7069. pring->stats.iocb_cmd_delay++;
  7070. out_busy:
  7071. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7072. __lpfc_sli_ringtx_put(phba, pring, piocb);
  7073. return IOCB_SUCCESS;
  7074. }
  7075. return IOCB_BUSY;
  7076. }
  7077. /**
  7078. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  7079. * @phba: Pointer to HBA context object.
  7080. * @piocb: Pointer to command iocb.
  7081. * @sglq: Pointer to the scatter gather queue object.
  7082. *
  7083. * This routine converts the bpl or bde that is in the IOCB
  7084. * to a sgl list for the sli4 hardware. The physical address
  7085. * of the bpl/bde is converted back to a virtual address.
  7086. * If the IOCB contains a BPL then the list of BDE's is
  7087. * converted to sli4_sge's. If the IOCB contains a single
  7088. * BDE then it is converted to a single sli_sge.
  7089. * The IOCB is still in cpu endianess so the contents of
  7090. * the bpl can be used without byte swapping.
  7091. *
  7092. * Returns valid XRI = Success, NO_XRI = Failure.
  7093. **/
  7094. static uint16_t
  7095. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  7096. struct lpfc_sglq *sglq)
  7097. {
  7098. uint16_t xritag = NO_XRI;
  7099. struct ulp_bde64 *bpl = NULL;
  7100. struct ulp_bde64 bde;
  7101. struct sli4_sge *sgl = NULL;
  7102. struct lpfc_dmabuf *dmabuf;
  7103. IOCB_t *icmd;
  7104. int numBdes = 0;
  7105. int i = 0;
  7106. uint32_t offset = 0; /* accumulated offset in the sg request list */
  7107. int inbound = 0; /* number of sg reply entries inbound from firmware */
  7108. if (!piocbq || !sglq)
  7109. return xritag;
  7110. sgl = (struct sli4_sge *)sglq->sgl;
  7111. icmd = &piocbq->iocb;
  7112. if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  7113. return sglq->sli4_xritag;
  7114. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7115. numBdes = icmd->un.genreq64.bdl.bdeSize /
  7116. sizeof(struct ulp_bde64);
  7117. /* The addrHigh and addrLow fields within the IOCB
  7118. * have not been byteswapped yet so there is no
  7119. * need to swap them back.
  7120. */
  7121. if (piocbq->context3)
  7122. dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
  7123. else
  7124. return xritag;
  7125. bpl = (struct ulp_bde64 *)dmabuf->virt;
  7126. if (!bpl)
  7127. return xritag;
  7128. for (i = 0; i < numBdes; i++) {
  7129. /* Should already be byte swapped. */
  7130. sgl->addr_hi = bpl->addrHigh;
  7131. sgl->addr_lo = bpl->addrLow;
  7132. sgl->word2 = le32_to_cpu(sgl->word2);
  7133. if ((i+1) == numBdes)
  7134. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7135. else
  7136. bf_set(lpfc_sli4_sge_last, sgl, 0);
  7137. /* swap the size field back to the cpu so we
  7138. * can assign it to the sgl.
  7139. */
  7140. bde.tus.w = le32_to_cpu(bpl->tus.w);
  7141. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  7142. /* The offsets in the sgl need to be accumulated
  7143. * separately for the request and reply lists.
  7144. * The request is always first, the reply follows.
  7145. */
  7146. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  7147. /* add up the reply sg entries */
  7148. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  7149. inbound++;
  7150. /* first inbound? reset the offset */
  7151. if (inbound == 1)
  7152. offset = 0;
  7153. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  7154. bf_set(lpfc_sli4_sge_type, sgl,
  7155. LPFC_SGE_TYPE_DATA);
  7156. offset += bde.tus.f.bdeSize;
  7157. }
  7158. sgl->word2 = cpu_to_le32(sgl->word2);
  7159. bpl++;
  7160. sgl++;
  7161. }
  7162. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  7163. /* The addrHigh and addrLow fields of the BDE have not
  7164. * been byteswapped yet so they need to be swapped
  7165. * before putting them in the sgl.
  7166. */
  7167. sgl->addr_hi =
  7168. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  7169. sgl->addr_lo =
  7170. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  7171. sgl->word2 = le32_to_cpu(sgl->word2);
  7172. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7173. sgl->word2 = cpu_to_le32(sgl->word2);
  7174. sgl->sge_len =
  7175. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  7176. }
  7177. return sglq->sli4_xritag;
  7178. }
  7179. /**
  7180. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  7181. * @phba: Pointer to HBA context object.
  7182. *
  7183. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  7184. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  7185. * held.
  7186. *
  7187. * Return: index into SLI4 fast-path FCP queue index.
  7188. **/
  7189. static inline uint32_t
  7190. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  7191. {
  7192. int i;
  7193. if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU)
  7194. i = smp_processor_id();
  7195. else
  7196. i = atomic_add_return(1, &phba->fcp_qidx);
  7197. i = (i % phba->cfg_fcp_io_channel);
  7198. return i;
  7199. }
  7200. /**
  7201. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  7202. * @phba: Pointer to HBA context object.
  7203. * @piocb: Pointer to command iocb.
  7204. * @wqe: Pointer to the work queue entry.
  7205. *
  7206. * This routine converts the iocb command to its Work Queue Entry
  7207. * equivalent. The wqe pointer should not have any fields set when
  7208. * this routine is called because it will memcpy over them.
  7209. * This routine does not set the CQ_ID or the WQEC bits in the
  7210. * wqe.
  7211. *
  7212. * Returns: 0 = Success, IOCB_ERROR = Failure.
  7213. **/
  7214. static int
  7215. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  7216. union lpfc_wqe *wqe)
  7217. {
  7218. uint32_t xmit_len = 0, total_len = 0;
  7219. uint8_t ct = 0;
  7220. uint32_t fip;
  7221. uint32_t abort_tag;
  7222. uint8_t command_type = ELS_COMMAND_NON_FIP;
  7223. uint8_t cmnd;
  7224. uint16_t xritag;
  7225. uint16_t abrt_iotag;
  7226. struct lpfc_iocbq *abrtiocbq;
  7227. struct ulp_bde64 *bpl = NULL;
  7228. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  7229. int numBdes, i;
  7230. struct ulp_bde64 bde;
  7231. struct lpfc_nodelist *ndlp;
  7232. uint32_t *pcmd;
  7233. uint32_t if_type;
  7234. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  7235. /* The fcp commands will set command type */
  7236. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7237. command_type = FCP_COMMAND;
  7238. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  7239. command_type = ELS_COMMAND_FIP;
  7240. else
  7241. command_type = ELS_COMMAND_NON_FIP;
  7242. /* Some of the fields are in the right position already */
  7243. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  7244. abort_tag = (uint32_t) iocbq->iotag;
  7245. xritag = iocbq->sli4_xritag;
  7246. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  7247. /* words0-2 bpl convert bde */
  7248. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7249. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7250. sizeof(struct ulp_bde64);
  7251. bpl = (struct ulp_bde64 *)
  7252. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  7253. if (!bpl)
  7254. return IOCB_ERROR;
  7255. /* Should already be byte swapped. */
  7256. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  7257. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  7258. /* swap the size field back to the cpu so we
  7259. * can assign it to the sgl.
  7260. */
  7261. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  7262. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  7263. total_len = 0;
  7264. for (i = 0; i < numBdes; i++) {
  7265. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7266. total_len += bde.tus.f.bdeSize;
  7267. }
  7268. } else
  7269. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  7270. iocbq->iocb.ulpIoTag = iocbq->iotag;
  7271. cmnd = iocbq->iocb.ulpCommand;
  7272. switch (iocbq->iocb.ulpCommand) {
  7273. case CMD_ELS_REQUEST64_CR:
  7274. if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
  7275. ndlp = iocbq->context_un.ndlp;
  7276. else
  7277. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7278. if (!iocbq->iocb.ulpLe) {
  7279. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7280. "2007 Only Limited Edition cmd Format"
  7281. " supported 0x%x\n",
  7282. iocbq->iocb.ulpCommand);
  7283. return IOCB_ERROR;
  7284. }
  7285. wqe->els_req.payload_len = xmit_len;
  7286. /* Els_reguest64 has a TMO */
  7287. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  7288. iocbq->iocb.ulpTimeout);
  7289. /* Need a VF for word 4 set the vf bit*/
  7290. bf_set(els_req64_vf, &wqe->els_req, 0);
  7291. /* And a VFID for word 12 */
  7292. bf_set(els_req64_vfid, &wqe->els_req, 0);
  7293. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7294. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7295. iocbq->iocb.ulpContext);
  7296. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  7297. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  7298. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7299. if (command_type == ELS_COMMAND_FIP)
  7300. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7301. >> LPFC_FIP_ELS_ID_SHIFT);
  7302. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7303. iocbq->context2)->virt);
  7304. if_type = bf_get(lpfc_sli_intf_if_type,
  7305. &phba->sli4_hba.sli_intf);
  7306. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7307. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7308. *pcmd == ELS_CMD_SCR ||
  7309. *pcmd == ELS_CMD_FDISC ||
  7310. *pcmd == ELS_CMD_LOGO ||
  7311. *pcmd == ELS_CMD_PLOGI)) {
  7312. bf_set(els_req64_sp, &wqe->els_req, 1);
  7313. bf_set(els_req64_sid, &wqe->els_req,
  7314. iocbq->vport->fc_myDID);
  7315. if ((*pcmd == ELS_CMD_FLOGI) &&
  7316. !(phba->fc_topology ==
  7317. LPFC_TOPOLOGY_LOOP))
  7318. bf_set(els_req64_sid, &wqe->els_req, 0);
  7319. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7320. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7321. phba->vpi_ids[iocbq->vport->vpi]);
  7322. } else if (pcmd && iocbq->context1) {
  7323. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7324. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7325. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7326. }
  7327. }
  7328. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7329. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7330. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7331. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7332. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7333. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7334. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7335. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7336. break;
  7337. case CMD_XMIT_SEQUENCE64_CX:
  7338. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7339. iocbq->iocb.un.ulpWord[3]);
  7340. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7341. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7342. /* The entire sequence is transmitted for this IOCB */
  7343. xmit_len = total_len;
  7344. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7345. if (phba->link_flag & LS_LOOPBACK_MODE)
  7346. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  7347. case CMD_XMIT_SEQUENCE64_CR:
  7348. /* word3 iocb=io_tag32 wqe=reserved */
  7349. wqe->xmit_sequence.rsvd3 = 0;
  7350. /* word4 relative_offset memcpy */
  7351. /* word5 r_ctl/df_ctl memcpy */
  7352. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7353. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7354. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7355. LPFC_WQE_IOD_WRITE);
  7356. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7357. LPFC_WQE_LENLOC_WORD12);
  7358. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7359. wqe->xmit_sequence.xmit_len = xmit_len;
  7360. command_type = OTHER_COMMAND;
  7361. break;
  7362. case CMD_XMIT_BCAST64_CN:
  7363. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7364. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7365. /* word4 iocb=rsvd wqe=rsvd */
  7366. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7367. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7368. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7369. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7370. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7371. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7372. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7373. LPFC_WQE_LENLOC_WORD3);
  7374. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7375. break;
  7376. case CMD_FCP_IWRITE64_CR:
  7377. command_type = FCP_COMMAND_DATA_OUT;
  7378. /* word3 iocb=iotag wqe=payload_offset_len */
  7379. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7380. wqe->fcp_iwrite.payload_offset_len =
  7381. xmit_len + sizeof(struct fcp_rsp);
  7382. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7383. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7384. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7385. iocbq->iocb.ulpFCP2Rcvy);
  7386. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7387. /* Always open the exchange */
  7388. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  7389. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7390. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7391. LPFC_WQE_LENLOC_WORD4);
  7392. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  7393. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7394. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7395. break;
  7396. case CMD_FCP_IREAD64_CR:
  7397. /* word3 iocb=iotag wqe=payload_offset_len */
  7398. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7399. wqe->fcp_iread.payload_offset_len =
  7400. xmit_len + sizeof(struct fcp_rsp);
  7401. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7402. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7403. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7404. iocbq->iocb.ulpFCP2Rcvy);
  7405. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7406. /* Always open the exchange */
  7407. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  7408. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7409. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7410. LPFC_WQE_LENLOC_WORD4);
  7411. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  7412. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7413. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7414. break;
  7415. case CMD_FCP_ICMND64_CR:
  7416. /* word3 iocb=IO_TAG wqe=reserved */
  7417. wqe->fcp_icmd.rsrvd3 = 0;
  7418. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7419. /* Always open the exchange */
  7420. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  7421. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7422. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7423. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7424. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7425. LPFC_WQE_LENLOC_NONE);
  7426. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  7427. bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
  7428. iocbq->iocb.ulpFCP2Rcvy);
  7429. break;
  7430. case CMD_GEN_REQUEST64_CR:
  7431. /* For this command calculate the xmit length of the
  7432. * request bde.
  7433. */
  7434. xmit_len = 0;
  7435. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7436. sizeof(struct ulp_bde64);
  7437. for (i = 0; i < numBdes; i++) {
  7438. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7439. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7440. break;
  7441. xmit_len += bde.tus.f.bdeSize;
  7442. }
  7443. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7444. wqe->gen_req.request_payload_len = xmit_len;
  7445. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7446. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7447. /* word6 context tag copied in memcpy */
  7448. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7449. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7450. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7451. "2015 Invalid CT %x command 0x%x\n",
  7452. ct, iocbq->iocb.ulpCommand);
  7453. return IOCB_ERROR;
  7454. }
  7455. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7456. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7457. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7458. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7459. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7460. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7461. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7462. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7463. command_type = OTHER_COMMAND;
  7464. break;
  7465. case CMD_XMIT_ELS_RSP64_CX:
  7466. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7467. /* words0-2 BDE memcpy */
  7468. /* word3 iocb=iotag32 wqe=response_payload_len */
  7469. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7470. /* word4 */
  7471. wqe->xmit_els_rsp.word4 = 0;
  7472. /* word5 iocb=rsvd wge=did */
  7473. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7474. iocbq->iocb.un.xseq64.xmit_els_remoteID);
  7475. if_type = bf_get(lpfc_sli_intf_if_type,
  7476. &phba->sli4_hba.sli_intf);
  7477. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7478. if (iocbq->vport->fc_flag & FC_PT2PT) {
  7479. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7480. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7481. iocbq->vport->fc_myDID);
  7482. if (iocbq->vport->fc_myDID == Fabric_DID) {
  7483. bf_set(wqe_els_did,
  7484. &wqe->xmit_els_rsp.wqe_dest, 0);
  7485. }
  7486. }
  7487. }
  7488. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7489. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7490. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7491. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7492. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7493. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7494. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7495. phba->vpi_ids[iocbq->vport->vpi]);
  7496. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7497. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7498. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7499. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7500. LPFC_WQE_LENLOC_WORD3);
  7501. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7502. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7503. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7504. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7505. iocbq->context2)->virt);
  7506. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7507. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7508. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7509. iocbq->vport->fc_myDID);
  7510. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
  7511. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7512. phba->vpi_ids[phba->pport->vpi]);
  7513. }
  7514. command_type = OTHER_COMMAND;
  7515. break;
  7516. case CMD_CLOSE_XRI_CN:
  7517. case CMD_ABORT_XRI_CN:
  7518. case CMD_ABORT_XRI_CX:
  7519. /* words 0-2 memcpy should be 0 rserved */
  7520. /* port will send abts */
  7521. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7522. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7523. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7524. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7525. } else
  7526. fip = 0;
  7527. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7528. /*
  7529. * The link is down, or the command was ELS_FIP
  7530. * so the fw does not need to send abts
  7531. * on the wire.
  7532. */
  7533. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7534. else
  7535. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7536. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7537. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7538. wqe->abort_cmd.rsrvd5 = 0;
  7539. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7540. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7541. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7542. /*
  7543. * The abort handler will send us CMD_ABORT_XRI_CN or
  7544. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7545. */
  7546. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7547. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7548. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7549. LPFC_WQE_LENLOC_NONE);
  7550. cmnd = CMD_ABORT_XRI_CX;
  7551. command_type = OTHER_COMMAND;
  7552. xritag = 0;
  7553. break;
  7554. case CMD_XMIT_BLS_RSP64_CX:
  7555. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7556. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7557. * we re-construct this WQE here based on information in
  7558. * iocbq from scratch.
  7559. */
  7560. memset(wqe, 0, sizeof(union lpfc_wqe));
  7561. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7562. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7563. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7564. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7565. LPFC_ABTS_UNSOL_INT) {
  7566. /* ABTS sent by initiator to CT exchange, the
  7567. * RX_ID field will be filled with the newly
  7568. * allocated responder XRI.
  7569. */
  7570. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7571. iocbq->sli4_xritag);
  7572. } else {
  7573. /* ABTS sent by responder to CT exchange, the
  7574. * RX_ID field will be filled with the responder
  7575. * RX_ID from ABTS.
  7576. */
  7577. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7578. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7579. }
  7580. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7581. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7582. /* Use CT=VPI */
  7583. bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
  7584. ndlp->nlp_DID);
  7585. bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
  7586. iocbq->iocb.ulpContext);
  7587. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  7588. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7589. phba->vpi_ids[phba->pport->vpi]);
  7590. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7591. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7592. LPFC_WQE_LENLOC_NONE);
  7593. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7594. command_type = OTHER_COMMAND;
  7595. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7596. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7597. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7598. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7599. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7600. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7601. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7602. }
  7603. break;
  7604. case CMD_XRI_ABORTED_CX:
  7605. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7606. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7607. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7608. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7609. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7610. default:
  7611. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7612. "2014 Invalid command 0x%x\n",
  7613. iocbq->iocb.ulpCommand);
  7614. return IOCB_ERROR;
  7615. break;
  7616. }
  7617. if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
  7618. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
  7619. else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
  7620. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
  7621. else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
  7622. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
  7623. iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
  7624. LPFC_IO_DIF_INSERT);
  7625. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7626. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7627. wqe->generic.wqe_com.abort_tag = abort_tag;
  7628. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  7629. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  7630. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  7631. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  7632. return 0;
  7633. }
  7634. /**
  7635. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  7636. * @phba: Pointer to HBA context object.
  7637. * @ring_number: SLI ring number to issue iocb on.
  7638. * @piocb: Pointer to command iocb.
  7639. * @flag: Flag indicating if this command can be put into txq.
  7640. *
  7641. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  7642. * an iocb command to an HBA with SLI-4 interface spec.
  7643. *
  7644. * This function is called with hbalock held. The function will return success
  7645. * after it successfully submit the iocb to firmware or after adding to the
  7646. * txq.
  7647. **/
  7648. static int
  7649. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  7650. struct lpfc_iocbq *piocb, uint32_t flag)
  7651. {
  7652. struct lpfc_sglq *sglq;
  7653. union lpfc_wqe wqe;
  7654. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7655. if (piocb->sli4_xritag == NO_XRI) {
  7656. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  7657. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  7658. sglq = NULL;
  7659. else {
  7660. if (!list_empty(&pring->txq)) {
  7661. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7662. __lpfc_sli_ringtx_put(phba,
  7663. pring, piocb);
  7664. return IOCB_SUCCESS;
  7665. } else {
  7666. return IOCB_BUSY;
  7667. }
  7668. } else {
  7669. sglq = __lpfc_sli_get_sglq(phba, piocb);
  7670. if (!sglq) {
  7671. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7672. __lpfc_sli_ringtx_put(phba,
  7673. pring,
  7674. piocb);
  7675. return IOCB_SUCCESS;
  7676. } else
  7677. return IOCB_BUSY;
  7678. }
  7679. }
  7680. }
  7681. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  7682. /* These IO's already have an XRI and a mapped sgl. */
  7683. sglq = NULL;
  7684. } else {
  7685. /*
  7686. * This is a continuation of a commandi,(CX) so this
  7687. * sglq is on the active list
  7688. */
  7689. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
  7690. if (!sglq)
  7691. return IOCB_ERROR;
  7692. }
  7693. if (sglq) {
  7694. piocb->sli4_lxritag = sglq->sli4_lxritag;
  7695. piocb->sli4_xritag = sglq->sli4_xritag;
  7696. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  7697. return IOCB_ERROR;
  7698. }
  7699. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  7700. return IOCB_ERROR;
  7701. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  7702. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  7703. if (unlikely(!phba->sli4_hba.fcp_wq))
  7704. return IOCB_ERROR;
  7705. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  7706. &wqe))
  7707. return IOCB_ERROR;
  7708. } else {
  7709. if (unlikely(!phba->sli4_hba.els_wq))
  7710. return IOCB_ERROR;
  7711. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  7712. return IOCB_ERROR;
  7713. }
  7714. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  7715. return 0;
  7716. }
  7717. /**
  7718. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  7719. *
  7720. * This routine wraps the actual lockless version for issusing IOCB function
  7721. * pointer from the lpfc_hba struct.
  7722. *
  7723. * Return codes:
  7724. * IOCB_ERROR - Error
  7725. * IOCB_SUCCESS - Success
  7726. * IOCB_BUSY - Busy
  7727. **/
  7728. int
  7729. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7730. struct lpfc_iocbq *piocb, uint32_t flag)
  7731. {
  7732. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7733. }
  7734. /**
  7735. * lpfc_sli_api_table_setup - Set up sli api function jump table
  7736. * @phba: The hba struct for which this call is being executed.
  7737. * @dev_grp: The HBA PCI-Device group number.
  7738. *
  7739. * This routine sets up the SLI interface API function jump table in @phba
  7740. * struct.
  7741. * Returns: 0 - success, -ENODEV - failure.
  7742. **/
  7743. int
  7744. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7745. {
  7746. switch (dev_grp) {
  7747. case LPFC_PCI_DEV_LP:
  7748. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  7749. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  7750. break;
  7751. case LPFC_PCI_DEV_OC:
  7752. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  7753. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  7754. break;
  7755. default:
  7756. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7757. "1419 Invalid HBA PCI-device group: 0x%x\n",
  7758. dev_grp);
  7759. return -ENODEV;
  7760. break;
  7761. }
  7762. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  7763. return 0;
  7764. }
  7765. /**
  7766. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  7767. * @phba: Pointer to HBA context object.
  7768. * @pring: Pointer to driver SLI ring object.
  7769. * @piocb: Pointer to command iocb.
  7770. * @flag: Flag indicating if this command can be put into txq.
  7771. *
  7772. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  7773. * function. This function gets the hbalock and calls
  7774. * __lpfc_sli_issue_iocb function and will return the error returned
  7775. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  7776. * functions which do not hold hbalock.
  7777. **/
  7778. int
  7779. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7780. struct lpfc_iocbq *piocb, uint32_t flag)
  7781. {
  7782. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  7783. struct lpfc_sli_ring *pring;
  7784. struct lpfc_queue *fpeq;
  7785. struct lpfc_eqe *eqe;
  7786. unsigned long iflags;
  7787. int rc, idx;
  7788. if (phba->sli_rev == LPFC_SLI_REV4) {
  7789. if (piocb->iocb_flag & LPFC_IO_FCP) {
  7790. if (unlikely(!phba->sli4_hba.fcp_wq))
  7791. return IOCB_ERROR;
  7792. idx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  7793. piocb->fcp_wqidx = idx;
  7794. ring_number = MAX_SLI3_CONFIGURED_RINGS + idx;
  7795. pring = &phba->sli.ring[ring_number];
  7796. spin_lock_irqsave(&pring->ring_lock, iflags);
  7797. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7798. flag);
  7799. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  7800. if (lpfc_fcp_look_ahead) {
  7801. fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx];
  7802. if (atomic_dec_and_test(&fcp_eq_hdl->
  7803. fcp_eq_in_use)) {
  7804. /* Get associated EQ with this index */
  7805. fpeq = phba->sli4_hba.hba_eq[idx];
  7806. /* Turn off interrupts from this EQ */
  7807. lpfc_sli4_eq_clr_intr(fpeq);
  7808. /*
  7809. * Process all the events on FCP EQ
  7810. */
  7811. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  7812. lpfc_sli4_hba_handle_eqe(phba,
  7813. eqe, idx);
  7814. fpeq->EQ_processed++;
  7815. }
  7816. /* Always clear and re-arm the EQ */
  7817. lpfc_sli4_eq_release(fpeq,
  7818. LPFC_QUEUE_REARM);
  7819. }
  7820. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  7821. }
  7822. } else {
  7823. pring = &phba->sli.ring[ring_number];
  7824. spin_lock_irqsave(&pring->ring_lock, iflags);
  7825. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7826. flag);
  7827. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  7828. }
  7829. } else {
  7830. /* For now, SLI2/3 will still use hbalock */
  7831. spin_lock_irqsave(&phba->hbalock, iflags);
  7832. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7833. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7834. }
  7835. return rc;
  7836. }
  7837. /**
  7838. * lpfc_extra_ring_setup - Extra ring setup function
  7839. * @phba: Pointer to HBA context object.
  7840. *
  7841. * This function is called while driver attaches with the
  7842. * HBA to setup the extra ring. The extra ring is used
  7843. * only when driver needs to support target mode functionality
  7844. * or IP over FC functionalities.
  7845. *
  7846. * This function is called with no lock held.
  7847. **/
  7848. static int
  7849. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  7850. {
  7851. struct lpfc_sli *psli;
  7852. struct lpfc_sli_ring *pring;
  7853. psli = &phba->sli;
  7854. /* Adjust cmd/rsp ring iocb entries more evenly */
  7855. /* Take some away from the FCP ring */
  7856. pring = &psli->ring[psli->fcp_ring];
  7857. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7858. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7859. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7860. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7861. /* and give them to the extra ring */
  7862. pring = &psli->ring[psli->extra_ring];
  7863. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7864. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7865. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7866. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7867. /* Setup default profile for this ring */
  7868. pring->iotag_max = 4096;
  7869. pring->num_mask = 1;
  7870. pring->prt[0].profile = 0; /* Mask 0 */
  7871. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  7872. pring->prt[0].type = phba->cfg_multi_ring_type;
  7873. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  7874. return 0;
  7875. }
  7876. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  7877. * @phba: Pointer to HBA context object.
  7878. * @iocbq: Pointer to iocb object.
  7879. *
  7880. * The async_event handler calls this routine when it receives
  7881. * an ASYNC_STATUS_CN event from the port. The port generates
  7882. * this event when an Abort Sequence request to an rport fails
  7883. * twice in succession. The abort could be originated by the
  7884. * driver or by the port. The ABTS could have been for an ELS
  7885. * or FCP IO. The port only generates this event when an ABTS
  7886. * fails to complete after one retry.
  7887. */
  7888. static void
  7889. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  7890. struct lpfc_iocbq *iocbq)
  7891. {
  7892. struct lpfc_nodelist *ndlp = NULL;
  7893. uint16_t rpi = 0, vpi = 0;
  7894. struct lpfc_vport *vport = NULL;
  7895. /* The rpi in the ulpContext is vport-sensitive. */
  7896. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  7897. rpi = iocbq->iocb.ulpContext;
  7898. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7899. "3092 Port generated ABTS async event "
  7900. "on vpi %d rpi %d status 0x%x\n",
  7901. vpi, rpi, iocbq->iocb.ulpStatus);
  7902. vport = lpfc_find_vport_by_vpid(phba, vpi);
  7903. if (!vport)
  7904. goto err_exit;
  7905. ndlp = lpfc_findnode_rpi(vport, rpi);
  7906. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  7907. goto err_exit;
  7908. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  7909. lpfc_sli_abts_recover_port(vport, ndlp);
  7910. return;
  7911. err_exit:
  7912. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7913. "3095 Event Context not found, no "
  7914. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  7915. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  7916. vpi, rpi);
  7917. }
  7918. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  7919. * @phba: pointer to HBA context object.
  7920. * @ndlp: nodelist pointer for the impacted rport.
  7921. * @axri: pointer to the wcqe containing the failed exchange.
  7922. *
  7923. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  7924. * port. The port generates this event when an abort exchange request to an
  7925. * rport fails twice in succession with no reply. The abort could be originated
  7926. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  7927. */
  7928. void
  7929. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  7930. struct lpfc_nodelist *ndlp,
  7931. struct sli4_wcqe_xri_aborted *axri)
  7932. {
  7933. struct lpfc_vport *vport;
  7934. uint32_t ext_status = 0;
  7935. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  7936. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7937. "3115 Node Context not found, driver "
  7938. "ignoring abts err event\n");
  7939. return;
  7940. }
  7941. vport = ndlp->vport;
  7942. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7943. "3116 Port generated FCP XRI ABORT event on "
  7944. "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
  7945. ndlp->vport->vpi, ndlp->nlp_rpi,
  7946. bf_get(lpfc_wcqe_xa_xri, axri),
  7947. bf_get(lpfc_wcqe_xa_status, axri),
  7948. axri->parameter);
  7949. /*
  7950. * Catch the ABTS protocol failure case. Older OCe FW releases returned
  7951. * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
  7952. * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
  7953. */
  7954. ext_status = axri->parameter & IOERR_PARAM_MASK;
  7955. if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
  7956. ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
  7957. lpfc_sli_abts_recover_port(vport, ndlp);
  7958. }
  7959. /**
  7960. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  7961. * @phba: Pointer to HBA context object.
  7962. * @pring: Pointer to driver SLI ring object.
  7963. * @iocbq: Pointer to iocb object.
  7964. *
  7965. * This function is called by the slow ring event handler
  7966. * function when there is an ASYNC event iocb in the ring.
  7967. * This function is called with no lock held.
  7968. * Currently this function handles only temperature related
  7969. * ASYNC events. The function decodes the temperature sensor
  7970. * event message and posts events for the management applications.
  7971. **/
  7972. static void
  7973. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  7974. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  7975. {
  7976. IOCB_t *icmd;
  7977. uint16_t evt_code;
  7978. struct temp_event temp_event_data;
  7979. struct Scsi_Host *shost;
  7980. uint32_t *iocb_w;
  7981. icmd = &iocbq->iocb;
  7982. evt_code = icmd->un.asyncstat.evt_code;
  7983. switch (evt_code) {
  7984. case ASYNC_TEMP_WARN:
  7985. case ASYNC_TEMP_SAFE:
  7986. temp_event_data.data = (uint32_t) icmd->ulpContext;
  7987. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  7988. if (evt_code == ASYNC_TEMP_WARN) {
  7989. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  7990. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7991. "0347 Adapter is very hot, please take "
  7992. "corrective action. temperature : %d Celsius\n",
  7993. (uint32_t) icmd->ulpContext);
  7994. } else {
  7995. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  7996. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7997. "0340 Adapter temperature is OK now. "
  7998. "temperature : %d Celsius\n",
  7999. (uint32_t) icmd->ulpContext);
  8000. }
  8001. /* Send temperature change event to applications */
  8002. shost = lpfc_shost_from_vport(phba->pport);
  8003. fc_host_post_vendor_event(shost, fc_get_event_number(),
  8004. sizeof(temp_event_data), (char *) &temp_event_data,
  8005. LPFC_NL_VENDOR_ID);
  8006. break;
  8007. case ASYNC_STATUS_CN:
  8008. lpfc_sli_abts_err_handler(phba, iocbq);
  8009. break;
  8010. default:
  8011. iocb_w = (uint32_t *) icmd;
  8012. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8013. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  8014. " evt_code 0x%x\n"
  8015. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  8016. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  8017. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  8018. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  8019. pring->ringno, icmd->un.asyncstat.evt_code,
  8020. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  8021. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  8022. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  8023. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  8024. break;
  8025. }
  8026. }
  8027. /**
  8028. * lpfc_sli_setup - SLI ring setup function
  8029. * @phba: Pointer to HBA context object.
  8030. *
  8031. * lpfc_sli_setup sets up rings of the SLI interface with
  8032. * number of iocbs per ring and iotags. This function is
  8033. * called while driver attach to the HBA and before the
  8034. * interrupts are enabled. So there is no need for locking.
  8035. *
  8036. * This function always returns 0.
  8037. **/
  8038. int
  8039. lpfc_sli_setup(struct lpfc_hba *phba)
  8040. {
  8041. int i, totiocbsize = 0;
  8042. struct lpfc_sli *psli = &phba->sli;
  8043. struct lpfc_sli_ring *pring;
  8044. psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
  8045. if (phba->sli_rev == LPFC_SLI_REV4)
  8046. psli->num_rings += phba->cfg_fcp_io_channel;
  8047. psli->sli_flag = 0;
  8048. psli->fcp_ring = LPFC_FCP_RING;
  8049. psli->next_ring = LPFC_FCP_NEXT_RING;
  8050. psli->extra_ring = LPFC_EXTRA_RING;
  8051. psli->iocbq_lookup = NULL;
  8052. psli->iocbq_lookup_len = 0;
  8053. psli->last_iotag = 0;
  8054. for (i = 0; i < psli->num_rings; i++) {
  8055. pring = &psli->ring[i];
  8056. switch (i) {
  8057. case LPFC_FCP_RING: /* ring 0 - FCP */
  8058. /* numCiocb and numRiocb are used in config_port */
  8059. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  8060. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  8061. pring->sli.sli3.numCiocb +=
  8062. SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8063. pring->sli.sli3.numRiocb +=
  8064. SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8065. pring->sli.sli3.numCiocb +=
  8066. SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8067. pring->sli.sli3.numRiocb +=
  8068. SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8069. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8070. SLI3_IOCB_CMD_SIZE :
  8071. SLI2_IOCB_CMD_SIZE;
  8072. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8073. SLI3_IOCB_RSP_SIZE :
  8074. SLI2_IOCB_RSP_SIZE;
  8075. pring->iotag_ctr = 0;
  8076. pring->iotag_max =
  8077. (phba->cfg_hba_queue_depth * 2);
  8078. pring->fast_iotag = pring->iotag_max;
  8079. pring->num_mask = 0;
  8080. break;
  8081. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  8082. /* numCiocb and numRiocb are used in config_port */
  8083. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  8084. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  8085. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8086. SLI3_IOCB_CMD_SIZE :
  8087. SLI2_IOCB_CMD_SIZE;
  8088. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8089. SLI3_IOCB_RSP_SIZE :
  8090. SLI2_IOCB_RSP_SIZE;
  8091. pring->iotag_max = phba->cfg_hba_queue_depth;
  8092. pring->num_mask = 0;
  8093. break;
  8094. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  8095. /* numCiocb and numRiocb are used in config_port */
  8096. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  8097. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  8098. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8099. SLI3_IOCB_CMD_SIZE :
  8100. SLI2_IOCB_CMD_SIZE;
  8101. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8102. SLI3_IOCB_RSP_SIZE :
  8103. SLI2_IOCB_RSP_SIZE;
  8104. pring->fast_iotag = 0;
  8105. pring->iotag_ctr = 0;
  8106. pring->iotag_max = 4096;
  8107. pring->lpfc_sli_rcv_async_status =
  8108. lpfc_sli_async_event_handler;
  8109. pring->num_mask = LPFC_MAX_RING_MASK;
  8110. pring->prt[0].profile = 0; /* Mask 0 */
  8111. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  8112. pring->prt[0].type = FC_TYPE_ELS;
  8113. pring->prt[0].lpfc_sli_rcv_unsol_event =
  8114. lpfc_els_unsol_event;
  8115. pring->prt[1].profile = 0; /* Mask 1 */
  8116. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  8117. pring->prt[1].type = FC_TYPE_ELS;
  8118. pring->prt[1].lpfc_sli_rcv_unsol_event =
  8119. lpfc_els_unsol_event;
  8120. pring->prt[2].profile = 0; /* Mask 2 */
  8121. /* NameServer Inquiry */
  8122. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  8123. /* NameServer */
  8124. pring->prt[2].type = FC_TYPE_CT;
  8125. pring->prt[2].lpfc_sli_rcv_unsol_event =
  8126. lpfc_ct_unsol_event;
  8127. pring->prt[3].profile = 0; /* Mask 3 */
  8128. /* NameServer response */
  8129. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  8130. /* NameServer */
  8131. pring->prt[3].type = FC_TYPE_CT;
  8132. pring->prt[3].lpfc_sli_rcv_unsol_event =
  8133. lpfc_ct_unsol_event;
  8134. break;
  8135. }
  8136. totiocbsize += (pring->sli.sli3.numCiocb *
  8137. pring->sli.sli3.sizeCiocb) +
  8138. (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
  8139. }
  8140. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  8141. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  8142. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  8143. "SLI2 SLIM Data: x%x x%lx\n",
  8144. phba->brd_no, totiocbsize,
  8145. (unsigned long) MAX_SLIM_IOCB_SIZE);
  8146. }
  8147. if (phba->cfg_multi_ring_support == 2)
  8148. lpfc_extra_ring_setup(phba);
  8149. return 0;
  8150. }
  8151. /**
  8152. * lpfc_sli_queue_setup - Queue initialization function
  8153. * @phba: Pointer to HBA context object.
  8154. *
  8155. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  8156. * ring. This function also initializes ring indices of each ring.
  8157. * This function is called during the initialization of the SLI
  8158. * interface of an HBA.
  8159. * This function is called with no lock held and always returns
  8160. * 1.
  8161. **/
  8162. int
  8163. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  8164. {
  8165. struct lpfc_sli *psli;
  8166. struct lpfc_sli_ring *pring;
  8167. int i;
  8168. psli = &phba->sli;
  8169. spin_lock_irq(&phba->hbalock);
  8170. INIT_LIST_HEAD(&psli->mboxq);
  8171. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  8172. /* Initialize list headers for txq and txcmplq as double linked lists */
  8173. for (i = 0; i < psli->num_rings; i++) {
  8174. pring = &psli->ring[i];
  8175. pring->ringno = i;
  8176. pring->sli.sli3.next_cmdidx = 0;
  8177. pring->sli.sli3.local_getidx = 0;
  8178. pring->sli.sli3.cmdidx = 0;
  8179. INIT_LIST_HEAD(&pring->txq);
  8180. INIT_LIST_HEAD(&pring->txcmplq);
  8181. INIT_LIST_HEAD(&pring->iocb_continueq);
  8182. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  8183. INIT_LIST_HEAD(&pring->postbufq);
  8184. spin_lock_init(&pring->ring_lock);
  8185. }
  8186. spin_unlock_irq(&phba->hbalock);
  8187. return 1;
  8188. }
  8189. /**
  8190. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  8191. * @phba: Pointer to HBA context object.
  8192. *
  8193. * This routine flushes the mailbox command subsystem. It will unconditionally
  8194. * flush all the mailbox commands in the three possible stages in the mailbox
  8195. * command sub-system: pending mailbox command queue; the outstanding mailbox
  8196. * command; and completed mailbox command queue. It is caller's responsibility
  8197. * to make sure that the driver is in the proper state to flush the mailbox
  8198. * command sub-system. Namely, the posting of mailbox commands into the
  8199. * pending mailbox command queue from the various clients must be stopped;
  8200. * either the HBA is in a state that it will never works on the outstanding
  8201. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  8202. * mailbox command has been completed.
  8203. **/
  8204. static void
  8205. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  8206. {
  8207. LIST_HEAD(completions);
  8208. struct lpfc_sli *psli = &phba->sli;
  8209. LPFC_MBOXQ_t *pmb;
  8210. unsigned long iflag;
  8211. /* Flush all the mailbox commands in the mbox system */
  8212. spin_lock_irqsave(&phba->hbalock, iflag);
  8213. /* The pending mailbox command queue */
  8214. list_splice_init(&phba->sli.mboxq, &completions);
  8215. /* The outstanding active mailbox command */
  8216. if (psli->mbox_active) {
  8217. list_add_tail(&psli->mbox_active->list, &completions);
  8218. psli->mbox_active = NULL;
  8219. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8220. }
  8221. /* The completed mailbox command queue */
  8222. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  8223. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8224. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  8225. while (!list_empty(&completions)) {
  8226. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  8227. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8228. if (pmb->mbox_cmpl)
  8229. pmb->mbox_cmpl(phba, pmb);
  8230. }
  8231. }
  8232. /**
  8233. * lpfc_sli_host_down - Vport cleanup function
  8234. * @vport: Pointer to virtual port object.
  8235. *
  8236. * lpfc_sli_host_down is called to clean up the resources
  8237. * associated with a vport before destroying virtual
  8238. * port data structures.
  8239. * This function does following operations:
  8240. * - Free discovery resources associated with this virtual
  8241. * port.
  8242. * - Free iocbs associated with this virtual port in
  8243. * the txq.
  8244. * - Send abort for all iocb commands associated with this
  8245. * vport in txcmplq.
  8246. *
  8247. * This function is called with no lock held and always returns 1.
  8248. **/
  8249. int
  8250. lpfc_sli_host_down(struct lpfc_vport *vport)
  8251. {
  8252. LIST_HEAD(completions);
  8253. struct lpfc_hba *phba = vport->phba;
  8254. struct lpfc_sli *psli = &phba->sli;
  8255. struct lpfc_sli_ring *pring;
  8256. struct lpfc_iocbq *iocb, *next_iocb;
  8257. int i;
  8258. unsigned long flags = 0;
  8259. uint16_t prev_pring_flag;
  8260. lpfc_cleanup_discovery_resources(vport);
  8261. spin_lock_irqsave(&phba->hbalock, flags);
  8262. for (i = 0; i < psli->num_rings; i++) {
  8263. pring = &psli->ring[i];
  8264. prev_pring_flag = pring->flag;
  8265. /* Only slow rings */
  8266. if (pring->ringno == LPFC_ELS_RING) {
  8267. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8268. /* Set the lpfc data pending flag */
  8269. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8270. }
  8271. /*
  8272. * Error everything on the txq since these iocbs have not been
  8273. * given to the FW yet.
  8274. */
  8275. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  8276. if (iocb->vport != vport)
  8277. continue;
  8278. list_move_tail(&iocb->list, &completions);
  8279. }
  8280. /* Next issue ABTS for everything on the txcmplq */
  8281. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  8282. list) {
  8283. if (iocb->vport != vport)
  8284. continue;
  8285. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  8286. }
  8287. pring->flag = prev_pring_flag;
  8288. }
  8289. spin_unlock_irqrestore(&phba->hbalock, flags);
  8290. /* Cancel all the IOCBs from the completions list */
  8291. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8292. IOERR_SLI_DOWN);
  8293. return 1;
  8294. }
  8295. /**
  8296. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  8297. * @phba: Pointer to HBA context object.
  8298. *
  8299. * This function cleans up all iocb, buffers, mailbox commands
  8300. * while shutting down the HBA. This function is called with no
  8301. * lock held and always returns 1.
  8302. * This function does the following to cleanup driver resources:
  8303. * - Free discovery resources for each virtual port
  8304. * - Cleanup any pending fabric iocbs
  8305. * - Iterate through the iocb txq and free each entry
  8306. * in the list.
  8307. * - Free up any buffer posted to the HBA
  8308. * - Free mailbox commands in the mailbox queue.
  8309. **/
  8310. int
  8311. lpfc_sli_hba_down(struct lpfc_hba *phba)
  8312. {
  8313. LIST_HEAD(completions);
  8314. struct lpfc_sli *psli = &phba->sli;
  8315. struct lpfc_sli_ring *pring;
  8316. struct lpfc_dmabuf *buf_ptr;
  8317. unsigned long flags = 0;
  8318. int i;
  8319. /* Shutdown the mailbox command sub-system */
  8320. lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
  8321. lpfc_hba_down_prep(phba);
  8322. lpfc_fabric_abort_hba(phba);
  8323. spin_lock_irqsave(&phba->hbalock, flags);
  8324. for (i = 0; i < psli->num_rings; i++) {
  8325. pring = &psli->ring[i];
  8326. /* Only slow rings */
  8327. if (pring->ringno == LPFC_ELS_RING) {
  8328. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8329. /* Set the lpfc data pending flag */
  8330. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8331. }
  8332. /*
  8333. * Error everything on the txq since these iocbs have not been
  8334. * given to the FW yet.
  8335. */
  8336. list_splice_init(&pring->txq, &completions);
  8337. }
  8338. spin_unlock_irqrestore(&phba->hbalock, flags);
  8339. /* Cancel all the IOCBs from the completions list */
  8340. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8341. IOERR_SLI_DOWN);
  8342. spin_lock_irqsave(&phba->hbalock, flags);
  8343. list_splice_init(&phba->elsbuf, &completions);
  8344. phba->elsbuf_cnt = 0;
  8345. phba->elsbuf_prev_cnt = 0;
  8346. spin_unlock_irqrestore(&phba->hbalock, flags);
  8347. while (!list_empty(&completions)) {
  8348. list_remove_head(&completions, buf_ptr,
  8349. struct lpfc_dmabuf, list);
  8350. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8351. kfree(buf_ptr);
  8352. }
  8353. /* Return any active mbox cmds */
  8354. del_timer_sync(&psli->mbox_tmo);
  8355. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8356. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8357. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8358. return 1;
  8359. }
  8360. /**
  8361. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8362. * @srcp: Source memory pointer.
  8363. * @destp: Destination memory pointer.
  8364. * @cnt: Number of words required to be copied.
  8365. *
  8366. * This function is used for copying data between driver memory
  8367. * and the SLI memory. This function also changes the endianness
  8368. * of each word if native endianness is different from SLI
  8369. * endianness. This function can be called with or without
  8370. * lock.
  8371. **/
  8372. void
  8373. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8374. {
  8375. uint32_t *src = srcp;
  8376. uint32_t *dest = destp;
  8377. uint32_t ldata;
  8378. int i;
  8379. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8380. ldata = *src;
  8381. ldata = le32_to_cpu(ldata);
  8382. *dest = ldata;
  8383. src++;
  8384. dest++;
  8385. }
  8386. }
  8387. /**
  8388. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8389. * @srcp: Source memory pointer.
  8390. * @destp: Destination memory pointer.
  8391. * @cnt: Number of words required to be copied.
  8392. *
  8393. * This function is used for copying data between a data structure
  8394. * with big endian representation to local endianness.
  8395. * This function can be called with or without lock.
  8396. **/
  8397. void
  8398. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8399. {
  8400. uint32_t *src = srcp;
  8401. uint32_t *dest = destp;
  8402. uint32_t ldata;
  8403. int i;
  8404. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8405. ldata = *src;
  8406. ldata = be32_to_cpu(ldata);
  8407. *dest = ldata;
  8408. src++;
  8409. dest++;
  8410. }
  8411. }
  8412. /**
  8413. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8414. * @phba: Pointer to HBA context object.
  8415. * @pring: Pointer to driver SLI ring object.
  8416. * @mp: Pointer to driver buffer object.
  8417. *
  8418. * This function is called with no lock held.
  8419. * It always return zero after adding the buffer to the postbufq
  8420. * buffer list.
  8421. **/
  8422. int
  8423. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8424. struct lpfc_dmabuf *mp)
  8425. {
  8426. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8427. later */
  8428. spin_lock_irq(&phba->hbalock);
  8429. list_add_tail(&mp->list, &pring->postbufq);
  8430. pring->postbufq_cnt++;
  8431. spin_unlock_irq(&phba->hbalock);
  8432. return 0;
  8433. }
  8434. /**
  8435. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8436. * @phba: Pointer to HBA context object.
  8437. *
  8438. * When HBQ is enabled, buffers are searched based on tags. This function
  8439. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8440. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8441. * does not conflict with tags of buffer posted for unsolicited events.
  8442. * The function returns the allocated tag. The function is called with
  8443. * no locks held.
  8444. **/
  8445. uint32_t
  8446. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8447. {
  8448. spin_lock_irq(&phba->hbalock);
  8449. phba->buffer_tag_count++;
  8450. /*
  8451. * Always set the QUE_BUFTAG_BIT to distiguish between
  8452. * a tag assigned by HBQ.
  8453. */
  8454. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8455. spin_unlock_irq(&phba->hbalock);
  8456. return phba->buffer_tag_count;
  8457. }
  8458. /**
  8459. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8460. * @phba: Pointer to HBA context object.
  8461. * @pring: Pointer to driver SLI ring object.
  8462. * @tag: Buffer tag.
  8463. *
  8464. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8465. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8466. * iocb is posted to the response ring with the tag of the buffer.
  8467. * This function searches the pring->postbufq list using the tag
  8468. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8469. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8470. * buffer is returned to the caller else NULL is returned.
  8471. * This function is called with no lock held.
  8472. **/
  8473. struct lpfc_dmabuf *
  8474. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8475. uint32_t tag)
  8476. {
  8477. struct lpfc_dmabuf *mp, *next_mp;
  8478. struct list_head *slp = &pring->postbufq;
  8479. /* Search postbufq, from the beginning, looking for a match on tag */
  8480. spin_lock_irq(&phba->hbalock);
  8481. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8482. if (mp->buffer_tag == tag) {
  8483. list_del_init(&mp->list);
  8484. pring->postbufq_cnt--;
  8485. spin_unlock_irq(&phba->hbalock);
  8486. return mp;
  8487. }
  8488. }
  8489. spin_unlock_irq(&phba->hbalock);
  8490. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8491. "0402 Cannot find virtual addr for buffer tag on "
  8492. "ring %d Data x%lx x%p x%p x%x\n",
  8493. pring->ringno, (unsigned long) tag,
  8494. slp->next, slp->prev, pring->postbufq_cnt);
  8495. return NULL;
  8496. }
  8497. /**
  8498. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8499. * @phba: Pointer to HBA context object.
  8500. * @pring: Pointer to driver SLI ring object.
  8501. * @phys: DMA address of the buffer.
  8502. *
  8503. * This function searches the buffer list using the dma_address
  8504. * of unsolicited event to find the driver's lpfc_dmabuf object
  8505. * corresponding to the dma_address. The function returns the
  8506. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8507. * This function is called by the ct and els unsolicited event
  8508. * handlers to get the buffer associated with the unsolicited
  8509. * event.
  8510. *
  8511. * This function is called with no lock held.
  8512. **/
  8513. struct lpfc_dmabuf *
  8514. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8515. dma_addr_t phys)
  8516. {
  8517. struct lpfc_dmabuf *mp, *next_mp;
  8518. struct list_head *slp = &pring->postbufq;
  8519. /* Search postbufq, from the beginning, looking for a match on phys */
  8520. spin_lock_irq(&phba->hbalock);
  8521. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8522. if (mp->phys == phys) {
  8523. list_del_init(&mp->list);
  8524. pring->postbufq_cnt--;
  8525. spin_unlock_irq(&phba->hbalock);
  8526. return mp;
  8527. }
  8528. }
  8529. spin_unlock_irq(&phba->hbalock);
  8530. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8531. "0410 Cannot find virtual addr for mapped buf on "
  8532. "ring %d Data x%llx x%p x%p x%x\n",
  8533. pring->ringno, (unsigned long long)phys,
  8534. slp->next, slp->prev, pring->postbufq_cnt);
  8535. return NULL;
  8536. }
  8537. /**
  8538. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8539. * @phba: Pointer to HBA context object.
  8540. * @cmdiocb: Pointer to driver command iocb object.
  8541. * @rspiocb: Pointer to driver response iocb object.
  8542. *
  8543. * This function is the completion handler for the abort iocbs for
  8544. * ELS commands. This function is called from the ELS ring event
  8545. * handler with no lock held. This function frees memory resources
  8546. * associated with the abort iocb.
  8547. **/
  8548. static void
  8549. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8550. struct lpfc_iocbq *rspiocb)
  8551. {
  8552. IOCB_t *irsp = &rspiocb->iocb;
  8553. uint16_t abort_iotag, abort_context;
  8554. struct lpfc_iocbq *abort_iocb = NULL;
  8555. if (irsp->ulpStatus) {
  8556. /*
  8557. * Assume that the port already completed and returned, or
  8558. * will return the iocb. Just Log the message.
  8559. */
  8560. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8561. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8562. spin_lock_irq(&phba->hbalock);
  8563. if (phba->sli_rev < LPFC_SLI_REV4) {
  8564. if (abort_iotag != 0 &&
  8565. abort_iotag <= phba->sli.last_iotag)
  8566. abort_iocb =
  8567. phba->sli.iocbq_lookup[abort_iotag];
  8568. } else
  8569. /* For sli4 the abort_tag is the XRI,
  8570. * so the abort routine puts the iotag of the iocb
  8571. * being aborted in the context field of the abort
  8572. * IOCB.
  8573. */
  8574. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8575. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8576. "0327 Cannot abort els iocb %p "
  8577. "with tag %x context %x, abort status %x, "
  8578. "abort code %x\n",
  8579. abort_iocb, abort_iotag, abort_context,
  8580. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8581. spin_unlock_irq(&phba->hbalock);
  8582. }
  8583. lpfc_sli_release_iocbq(phba, cmdiocb);
  8584. return;
  8585. }
  8586. /**
  8587. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  8588. * @phba: Pointer to HBA context object.
  8589. * @cmdiocb: Pointer to driver command iocb object.
  8590. * @rspiocb: Pointer to driver response iocb object.
  8591. *
  8592. * The function is called from SLI ring event handler with no
  8593. * lock held. This function is the completion handler for ELS commands
  8594. * which are aborted. The function frees memory resources used for
  8595. * the aborted ELS commands.
  8596. **/
  8597. static void
  8598. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8599. struct lpfc_iocbq *rspiocb)
  8600. {
  8601. IOCB_t *irsp = &rspiocb->iocb;
  8602. /* ELS cmd tag <ulpIoTag> completes */
  8603. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8604. "0139 Ignoring ELS cmd tag x%x completion Data: "
  8605. "x%x x%x x%x\n",
  8606. irsp->ulpIoTag, irsp->ulpStatus,
  8607. irsp->un.ulpWord[4], irsp->ulpTimeout);
  8608. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  8609. lpfc_ct_free_iocb(phba, cmdiocb);
  8610. else
  8611. lpfc_els_free_iocb(phba, cmdiocb);
  8612. return;
  8613. }
  8614. /**
  8615. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  8616. * @phba: Pointer to HBA context object.
  8617. * @pring: Pointer to driver SLI ring object.
  8618. * @cmdiocb: Pointer to driver command iocb object.
  8619. *
  8620. * This function issues an abort iocb for the provided command iocb down to
  8621. * the port. Other than the case the outstanding command iocb is an abort
  8622. * request, this function issues abort out unconditionally. This function is
  8623. * called with hbalock held. The function returns 0 when it fails due to
  8624. * memory allocation failure or when the command iocb is an abort request.
  8625. **/
  8626. static int
  8627. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8628. struct lpfc_iocbq *cmdiocb)
  8629. {
  8630. struct lpfc_vport *vport = cmdiocb->vport;
  8631. struct lpfc_iocbq *abtsiocbp;
  8632. IOCB_t *icmd = NULL;
  8633. IOCB_t *iabt = NULL;
  8634. int retval;
  8635. unsigned long iflags;
  8636. /*
  8637. * There are certain command types we don't want to abort. And we
  8638. * don't want to abort commands that are already in the process of
  8639. * being aborted.
  8640. */
  8641. icmd = &cmdiocb->iocb;
  8642. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8643. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8644. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8645. return 0;
  8646. /* issue ABTS for this IOCB based on iotag */
  8647. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  8648. if (abtsiocbp == NULL)
  8649. return 0;
  8650. /* This signals the response to set the correct status
  8651. * before calling the completion handler
  8652. */
  8653. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  8654. iabt = &abtsiocbp->iocb;
  8655. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  8656. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  8657. if (phba->sli_rev == LPFC_SLI_REV4) {
  8658. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  8659. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  8660. }
  8661. else
  8662. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  8663. iabt->ulpLe = 1;
  8664. iabt->ulpClass = icmd->ulpClass;
  8665. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8666. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  8667. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  8668. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  8669. if (phba->link_state >= LPFC_LINK_UP)
  8670. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  8671. else
  8672. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  8673. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  8674. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  8675. "0339 Abort xri x%x, original iotag x%x, "
  8676. "abort cmd iotag x%x\n",
  8677. iabt->un.acxri.abortIoTag,
  8678. iabt->un.acxri.abortContextTag,
  8679. abtsiocbp->iotag);
  8680. if (phba->sli_rev == LPFC_SLI_REV4) {
  8681. /* Note: both hbalock and ring_lock need to be set here */
  8682. spin_lock_irqsave(&pring->ring_lock, iflags);
  8683. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  8684. abtsiocbp, 0);
  8685. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  8686. } else {
  8687. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  8688. abtsiocbp, 0);
  8689. }
  8690. if (retval)
  8691. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  8692. /*
  8693. * Caller to this routine should check for IOCB_ERROR
  8694. * and handle it properly. This routine no longer removes
  8695. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8696. */
  8697. return retval;
  8698. }
  8699. /**
  8700. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  8701. * @phba: Pointer to HBA context object.
  8702. * @pring: Pointer to driver SLI ring object.
  8703. * @cmdiocb: Pointer to driver command iocb object.
  8704. *
  8705. * This function issues an abort iocb for the provided command iocb. In case
  8706. * of unloading, the abort iocb will not be issued to commands on the ELS
  8707. * ring. Instead, the callback function shall be changed to those commands
  8708. * so that nothing happens when them finishes. This function is called with
  8709. * hbalock held. The function returns 0 when the command iocb is an abort
  8710. * request.
  8711. **/
  8712. int
  8713. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8714. struct lpfc_iocbq *cmdiocb)
  8715. {
  8716. struct lpfc_vport *vport = cmdiocb->vport;
  8717. int retval = IOCB_ERROR;
  8718. IOCB_t *icmd = NULL;
  8719. /*
  8720. * There are certain command types we don't want to abort. And we
  8721. * don't want to abort commands that are already in the process of
  8722. * being aborted.
  8723. */
  8724. icmd = &cmdiocb->iocb;
  8725. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8726. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8727. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8728. return 0;
  8729. /*
  8730. * If we're unloading, don't abort iocb on the ELS ring, but change
  8731. * the callback so that nothing happens when it finishes.
  8732. */
  8733. if ((vport->load_flag & FC_UNLOADING) &&
  8734. (pring->ringno == LPFC_ELS_RING)) {
  8735. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  8736. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  8737. else
  8738. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  8739. goto abort_iotag_exit;
  8740. }
  8741. /* Now, we try to issue the abort to the cmdiocb out */
  8742. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  8743. abort_iotag_exit:
  8744. /*
  8745. * Caller to this routine should check for IOCB_ERROR
  8746. * and handle it properly. This routine no longer removes
  8747. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8748. */
  8749. return retval;
  8750. }
  8751. /**
  8752. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  8753. * @phba: Pointer to HBA context object.
  8754. * @pring: Pointer to driver SLI ring object.
  8755. *
  8756. * This function aborts all iocbs in the given ring and frees all the iocb
  8757. * objects in txq. This function issues abort iocbs unconditionally for all
  8758. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  8759. * to complete before the return of this function. The caller is not required
  8760. * to hold any locks.
  8761. **/
  8762. static void
  8763. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  8764. {
  8765. LIST_HEAD(completions);
  8766. struct lpfc_iocbq *iocb, *next_iocb;
  8767. if (pring->ringno == LPFC_ELS_RING)
  8768. lpfc_fabric_abort_hba(phba);
  8769. spin_lock_irq(&phba->hbalock);
  8770. /* Take off all the iocbs on txq for cancelling */
  8771. list_splice_init(&pring->txq, &completions);
  8772. pring->txq_cnt = 0;
  8773. /* Next issue ABTS for everything on the txcmplq */
  8774. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  8775. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  8776. spin_unlock_irq(&phba->hbalock);
  8777. /* Cancel all the IOCBs from the completions list */
  8778. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8779. IOERR_SLI_ABORTED);
  8780. }
  8781. /**
  8782. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  8783. * @phba: pointer to lpfc HBA data structure.
  8784. *
  8785. * This routine will abort all pending and outstanding iocbs to an HBA.
  8786. **/
  8787. void
  8788. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  8789. {
  8790. struct lpfc_sli *psli = &phba->sli;
  8791. struct lpfc_sli_ring *pring;
  8792. int i;
  8793. for (i = 0; i < psli->num_rings; i++) {
  8794. pring = &psli->ring[i];
  8795. lpfc_sli_iocb_ring_abort(phba, pring);
  8796. }
  8797. }
  8798. /**
  8799. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  8800. * @iocbq: Pointer to driver iocb object.
  8801. * @vport: Pointer to driver virtual port object.
  8802. * @tgt_id: SCSI ID of the target.
  8803. * @lun_id: LUN ID of the scsi device.
  8804. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  8805. *
  8806. * This function acts as an iocb filter for functions which abort or count
  8807. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  8808. * 0 if the filtering criteria is met for the given iocb and will return
  8809. * 1 if the filtering criteria is not met.
  8810. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  8811. * given iocb is for the SCSI device specified by vport, tgt_id and
  8812. * lun_id parameter.
  8813. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  8814. * given iocb is for the SCSI target specified by vport and tgt_id
  8815. * parameters.
  8816. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  8817. * given iocb is for the SCSI host associated with the given vport.
  8818. * This function is called with no locks held.
  8819. **/
  8820. static int
  8821. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  8822. uint16_t tgt_id, uint64_t lun_id,
  8823. lpfc_ctx_cmd ctx_cmd)
  8824. {
  8825. struct lpfc_scsi_buf *lpfc_cmd;
  8826. int rc = 1;
  8827. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  8828. return rc;
  8829. if (iocbq->vport != vport)
  8830. return rc;
  8831. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  8832. if (lpfc_cmd->pCmd == NULL)
  8833. return rc;
  8834. switch (ctx_cmd) {
  8835. case LPFC_CTX_LUN:
  8836. if ((lpfc_cmd->rdata->pnode) &&
  8837. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  8838. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  8839. rc = 0;
  8840. break;
  8841. case LPFC_CTX_TGT:
  8842. if ((lpfc_cmd->rdata->pnode) &&
  8843. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  8844. rc = 0;
  8845. break;
  8846. case LPFC_CTX_HOST:
  8847. rc = 0;
  8848. break;
  8849. default:
  8850. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  8851. __func__, ctx_cmd);
  8852. break;
  8853. }
  8854. return rc;
  8855. }
  8856. /**
  8857. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  8858. * @vport: Pointer to virtual port.
  8859. * @tgt_id: SCSI ID of the target.
  8860. * @lun_id: LUN ID of the scsi device.
  8861. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8862. *
  8863. * This function returns number of FCP commands pending for the vport.
  8864. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  8865. * commands pending on the vport associated with SCSI device specified
  8866. * by tgt_id and lun_id parameters.
  8867. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  8868. * commands pending on the vport associated with SCSI target specified
  8869. * by tgt_id parameter.
  8870. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  8871. * commands pending on the vport.
  8872. * This function returns the number of iocbs which satisfy the filter.
  8873. * This function is called without any lock held.
  8874. **/
  8875. int
  8876. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  8877. lpfc_ctx_cmd ctx_cmd)
  8878. {
  8879. struct lpfc_hba *phba = vport->phba;
  8880. struct lpfc_iocbq *iocbq;
  8881. int sum, i;
  8882. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  8883. iocbq = phba->sli.iocbq_lookup[i];
  8884. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  8885. ctx_cmd) == 0)
  8886. sum++;
  8887. }
  8888. return sum;
  8889. }
  8890. /**
  8891. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  8892. * @phba: Pointer to HBA context object
  8893. * @cmdiocb: Pointer to command iocb object.
  8894. * @rspiocb: Pointer to response iocb object.
  8895. *
  8896. * This function is called when an aborted FCP iocb completes. This
  8897. * function is called by the ring event handler with no lock held.
  8898. * This function frees the iocb.
  8899. **/
  8900. void
  8901. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8902. struct lpfc_iocbq *rspiocb)
  8903. {
  8904. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8905. "3096 ABORT_XRI_CN completing on xri x%x "
  8906. "original iotag x%x, abort cmd iotag x%x "
  8907. "status 0x%x, reason 0x%x\n",
  8908. cmdiocb->iocb.un.acxri.abortContextTag,
  8909. cmdiocb->iocb.un.acxri.abortIoTag,
  8910. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  8911. rspiocb->iocb.un.ulpWord[4]);
  8912. lpfc_sli_release_iocbq(phba, cmdiocb);
  8913. return;
  8914. }
  8915. /**
  8916. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  8917. * @vport: Pointer to virtual port.
  8918. * @pring: Pointer to driver SLI ring object.
  8919. * @tgt_id: SCSI ID of the target.
  8920. * @lun_id: LUN ID of the scsi device.
  8921. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8922. *
  8923. * This function sends an abort command for every SCSI command
  8924. * associated with the given virtual port pending on the ring
  8925. * filtered by lpfc_sli_validate_fcp_iocb function.
  8926. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  8927. * FCP iocbs associated with lun specified by tgt_id and lun_id
  8928. * parameters
  8929. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  8930. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  8931. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  8932. * FCP iocbs associated with virtual port.
  8933. * This function returns number of iocbs it failed to abort.
  8934. * This function is called with no locks held.
  8935. **/
  8936. int
  8937. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  8938. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  8939. {
  8940. struct lpfc_hba *phba = vport->phba;
  8941. struct lpfc_iocbq *iocbq;
  8942. struct lpfc_iocbq *abtsiocb;
  8943. IOCB_t *cmd = NULL;
  8944. int errcnt = 0, ret_val = 0;
  8945. int i;
  8946. for (i = 1; i <= phba->sli.last_iotag; i++) {
  8947. iocbq = phba->sli.iocbq_lookup[i];
  8948. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  8949. abort_cmd) != 0)
  8950. continue;
  8951. /* issue ABTS for this IOCB based on iotag */
  8952. abtsiocb = lpfc_sli_get_iocbq(phba);
  8953. if (abtsiocb == NULL) {
  8954. errcnt++;
  8955. continue;
  8956. }
  8957. cmd = &iocbq->iocb;
  8958. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  8959. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  8960. if (phba->sli_rev == LPFC_SLI_REV4)
  8961. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  8962. else
  8963. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  8964. abtsiocb->iocb.ulpLe = 1;
  8965. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  8966. abtsiocb->vport = phba->pport;
  8967. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8968. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  8969. if (iocbq->iocb_flag & LPFC_IO_FCP)
  8970. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  8971. if (lpfc_is_link_up(phba))
  8972. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  8973. else
  8974. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  8975. /* Setup callback routine and issue the command. */
  8976. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  8977. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  8978. abtsiocb, 0);
  8979. if (ret_val == IOCB_ERROR) {
  8980. lpfc_sli_release_iocbq(phba, abtsiocb);
  8981. errcnt++;
  8982. continue;
  8983. }
  8984. }
  8985. return errcnt;
  8986. }
  8987. /**
  8988. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  8989. * @phba: Pointer to HBA context object.
  8990. * @cmdiocbq: Pointer to command iocb.
  8991. * @rspiocbq: Pointer to response iocb.
  8992. *
  8993. * This function is the completion handler for iocbs issued using
  8994. * lpfc_sli_issue_iocb_wait function. This function is called by the
  8995. * ring event handler function without any lock held. This function
  8996. * can be called from both worker thread context and interrupt
  8997. * context. This function also can be called from other thread which
  8998. * cleans up the SLI layer objects.
  8999. * This function copy the contents of the response iocb to the
  9000. * response iocb memory object provided by the caller of
  9001. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  9002. * sleeps for the iocb completion.
  9003. **/
  9004. static void
  9005. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  9006. struct lpfc_iocbq *cmdiocbq,
  9007. struct lpfc_iocbq *rspiocbq)
  9008. {
  9009. wait_queue_head_t *pdone_q;
  9010. unsigned long iflags;
  9011. struct lpfc_scsi_buf *lpfc_cmd;
  9012. spin_lock_irqsave(&phba->hbalock, iflags);
  9013. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  9014. if (cmdiocbq->context2 && rspiocbq)
  9015. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  9016. &rspiocbq->iocb, sizeof(IOCB_t));
  9017. /* Set the exchange busy flag for task management commands */
  9018. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  9019. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  9020. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  9021. cur_iocbq);
  9022. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  9023. }
  9024. pdone_q = cmdiocbq->context_un.wait_queue;
  9025. if (pdone_q)
  9026. wake_up(pdone_q);
  9027. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9028. return;
  9029. }
  9030. /**
  9031. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  9032. * @phba: Pointer to HBA context object..
  9033. * @piocbq: Pointer to command iocb.
  9034. * @flag: Flag to test.
  9035. *
  9036. * This routine grabs the hbalock and then test the iocb_flag to
  9037. * see if the passed in flag is set.
  9038. * Returns:
  9039. * 1 if flag is set.
  9040. * 0 if flag is not set.
  9041. **/
  9042. static int
  9043. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  9044. struct lpfc_iocbq *piocbq, uint32_t flag)
  9045. {
  9046. unsigned long iflags;
  9047. int ret;
  9048. spin_lock_irqsave(&phba->hbalock, iflags);
  9049. ret = piocbq->iocb_flag & flag;
  9050. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9051. return ret;
  9052. }
  9053. /**
  9054. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  9055. * @phba: Pointer to HBA context object..
  9056. * @pring: Pointer to sli ring.
  9057. * @piocb: Pointer to command iocb.
  9058. * @prspiocbq: Pointer to response iocb.
  9059. * @timeout: Timeout in number of seconds.
  9060. *
  9061. * This function issues the iocb to firmware and waits for the
  9062. * iocb to complete. If the iocb command is not
  9063. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  9064. * Caller should not free the iocb resources if this function
  9065. * returns IOCB_TIMEDOUT.
  9066. * The function waits for the iocb completion using an
  9067. * non-interruptible wait.
  9068. * This function will sleep while waiting for iocb completion.
  9069. * So, this function should not be called from any context which
  9070. * does not allow sleeping. Due to the same reason, this function
  9071. * cannot be called with interrupt disabled.
  9072. * This function assumes that the iocb completions occur while
  9073. * this function sleep. So, this function cannot be called from
  9074. * the thread which process iocb completion for this ring.
  9075. * This function clears the iocb_flag of the iocb object before
  9076. * issuing the iocb and the iocb completion handler sets this
  9077. * flag and wakes this thread when the iocb completes.
  9078. * The contents of the response iocb will be copied to prspiocbq
  9079. * by the completion handler when the command completes.
  9080. * This function returns IOCB_SUCCESS when success.
  9081. * This function is called with no lock held.
  9082. **/
  9083. int
  9084. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  9085. uint32_t ring_number,
  9086. struct lpfc_iocbq *piocb,
  9087. struct lpfc_iocbq *prspiocbq,
  9088. uint32_t timeout)
  9089. {
  9090. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9091. long timeleft, timeout_req = 0;
  9092. int retval = IOCB_SUCCESS;
  9093. uint32_t creg_val;
  9094. struct lpfc_iocbq *iocb;
  9095. int txq_cnt = 0;
  9096. int txcmplq_cnt = 0;
  9097. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9098. /*
  9099. * If the caller has provided a response iocbq buffer, then context2
  9100. * is NULL or its an error.
  9101. */
  9102. if (prspiocbq) {
  9103. if (piocb->context2)
  9104. return IOCB_ERROR;
  9105. piocb->context2 = prspiocbq;
  9106. }
  9107. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  9108. piocb->context_un.wait_queue = &done_q;
  9109. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  9110. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9111. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9112. return IOCB_ERROR;
  9113. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  9114. writel(creg_val, phba->HCregaddr);
  9115. readl(phba->HCregaddr); /* flush */
  9116. }
  9117. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  9118. SLI_IOCB_RET_IOCB);
  9119. if (retval == IOCB_SUCCESS) {
  9120. timeout_req = msecs_to_jiffies(timeout * 1000);
  9121. timeleft = wait_event_timeout(done_q,
  9122. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  9123. timeout_req);
  9124. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  9125. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9126. "0331 IOCB wake signaled\n");
  9127. } else if (timeleft == 0) {
  9128. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9129. "0338 IOCB wait timeout error - no "
  9130. "wake response Data x%x\n", timeout);
  9131. retval = IOCB_TIMEDOUT;
  9132. } else {
  9133. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9134. "0330 IOCB wake NOT set, "
  9135. "Data x%x x%lx\n",
  9136. timeout, (timeleft / jiffies));
  9137. retval = IOCB_TIMEDOUT;
  9138. }
  9139. } else if (retval == IOCB_BUSY) {
  9140. if (phba->cfg_log_verbose & LOG_SLI) {
  9141. list_for_each_entry(iocb, &pring->txq, list) {
  9142. txq_cnt++;
  9143. }
  9144. list_for_each_entry(iocb, &pring->txcmplq, list) {
  9145. txcmplq_cnt++;
  9146. }
  9147. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9148. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  9149. phba->iocb_cnt, txq_cnt, txcmplq_cnt);
  9150. }
  9151. return retval;
  9152. } else {
  9153. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9154. "0332 IOCB wait issue failed, Data x%x\n",
  9155. retval);
  9156. retval = IOCB_ERROR;
  9157. }
  9158. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9159. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9160. return IOCB_ERROR;
  9161. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  9162. writel(creg_val, phba->HCregaddr);
  9163. readl(phba->HCregaddr); /* flush */
  9164. }
  9165. if (prspiocbq)
  9166. piocb->context2 = NULL;
  9167. piocb->context_un.wait_queue = NULL;
  9168. piocb->iocb_cmpl = NULL;
  9169. return retval;
  9170. }
  9171. /**
  9172. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  9173. * @phba: Pointer to HBA context object.
  9174. * @pmboxq: Pointer to driver mailbox object.
  9175. * @timeout: Timeout in number of seconds.
  9176. *
  9177. * This function issues the mailbox to firmware and waits for the
  9178. * mailbox command to complete. If the mailbox command is not
  9179. * completed within timeout seconds, it returns MBX_TIMEOUT.
  9180. * The function waits for the mailbox completion using an
  9181. * interruptible wait. If the thread is woken up due to a
  9182. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  9183. * should not free the mailbox resources, if this function returns
  9184. * MBX_TIMEOUT.
  9185. * This function will sleep while waiting for mailbox completion.
  9186. * So, this function should not be called from any context which
  9187. * does not allow sleeping. Due to the same reason, this function
  9188. * cannot be called with interrupt disabled.
  9189. * This function assumes that the mailbox completion occurs while
  9190. * this function sleep. So, this function cannot be called from
  9191. * the worker thread which processes mailbox completion.
  9192. * This function is called in the context of HBA management
  9193. * applications.
  9194. * This function returns MBX_SUCCESS when successful.
  9195. * This function is called with no lock held.
  9196. **/
  9197. int
  9198. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  9199. uint32_t timeout)
  9200. {
  9201. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9202. int retval;
  9203. unsigned long flag;
  9204. /* The caller must leave context1 empty. */
  9205. if (pmboxq->context1)
  9206. return MBX_NOT_FINISHED;
  9207. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  9208. /* setup wake call as IOCB callback */
  9209. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  9210. /* setup context field to pass wait_queue pointer to wake function */
  9211. pmboxq->context1 = &done_q;
  9212. /* now issue the command */
  9213. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  9214. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  9215. wait_event_interruptible_timeout(done_q,
  9216. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  9217. msecs_to_jiffies(timeout * 1000));
  9218. spin_lock_irqsave(&phba->hbalock, flag);
  9219. pmboxq->context1 = NULL;
  9220. /*
  9221. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  9222. * else do not free the resources.
  9223. */
  9224. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  9225. retval = MBX_SUCCESS;
  9226. lpfc_sli4_swap_str(phba, pmboxq);
  9227. } else {
  9228. retval = MBX_TIMEOUT;
  9229. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9230. }
  9231. spin_unlock_irqrestore(&phba->hbalock, flag);
  9232. }
  9233. return retval;
  9234. }
  9235. /**
  9236. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  9237. * @phba: Pointer to HBA context.
  9238. *
  9239. * This function is called to shutdown the driver's mailbox sub-system.
  9240. * It first marks the mailbox sub-system is in a block state to prevent
  9241. * the asynchronous mailbox command from issued off the pending mailbox
  9242. * command queue. If the mailbox command sub-system shutdown is due to
  9243. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  9244. * the mailbox sub-system flush routine to forcefully bring down the
  9245. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  9246. * as with offline or HBA function reset), this routine will wait for the
  9247. * outstanding mailbox command to complete before invoking the mailbox
  9248. * sub-system flush routine to gracefully bring down mailbox sub-system.
  9249. **/
  9250. void
  9251. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
  9252. {
  9253. struct lpfc_sli *psli = &phba->sli;
  9254. unsigned long timeout;
  9255. if (mbx_action == LPFC_MBX_NO_WAIT) {
  9256. /* delay 100ms for port state */
  9257. msleep(100);
  9258. lpfc_sli_mbox_sys_flush(phba);
  9259. return;
  9260. }
  9261. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  9262. spin_lock_irq(&phba->hbalock);
  9263. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  9264. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  9265. /* Determine how long we might wait for the active mailbox
  9266. * command to be gracefully completed by firmware.
  9267. */
  9268. if (phba->sli.mbox_active)
  9269. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  9270. phba->sli.mbox_active) *
  9271. 1000) + jiffies;
  9272. spin_unlock_irq(&phba->hbalock);
  9273. while (phba->sli.mbox_active) {
  9274. /* Check active mailbox complete status every 2ms */
  9275. msleep(2);
  9276. if (time_after(jiffies, timeout))
  9277. /* Timeout, let the mailbox flush routine to
  9278. * forcefully release active mailbox command
  9279. */
  9280. break;
  9281. }
  9282. } else
  9283. spin_unlock_irq(&phba->hbalock);
  9284. lpfc_sli_mbox_sys_flush(phba);
  9285. }
  9286. /**
  9287. * lpfc_sli_eratt_read - read sli-3 error attention events
  9288. * @phba: Pointer to HBA context.
  9289. *
  9290. * This function is called to read the SLI3 device error attention registers
  9291. * for possible error attention events. The caller must hold the hostlock
  9292. * with spin_lock_irq().
  9293. *
  9294. * This function returns 1 when there is Error Attention in the Host Attention
  9295. * Register and returns 0 otherwise.
  9296. **/
  9297. static int
  9298. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  9299. {
  9300. uint32_t ha_copy;
  9301. /* Read chip Host Attention (HA) register */
  9302. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9303. goto unplug_err;
  9304. if (ha_copy & HA_ERATT) {
  9305. /* Read host status register to retrieve error event */
  9306. if (lpfc_sli_read_hs(phba))
  9307. goto unplug_err;
  9308. /* Check if there is a deferred error condition is active */
  9309. if ((HS_FFER1 & phba->work_hs) &&
  9310. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9311. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  9312. phba->hba_flag |= DEFER_ERATT;
  9313. /* Clear all interrupt enable conditions */
  9314. writel(0, phba->HCregaddr);
  9315. readl(phba->HCregaddr);
  9316. }
  9317. /* Set the driver HA work bitmap */
  9318. phba->work_ha |= HA_ERATT;
  9319. /* Indicate polling handles this ERATT */
  9320. phba->hba_flag |= HBA_ERATT_HANDLED;
  9321. return 1;
  9322. }
  9323. return 0;
  9324. unplug_err:
  9325. /* Set the driver HS work bitmap */
  9326. phba->work_hs |= UNPLUG_ERR;
  9327. /* Set the driver HA work bitmap */
  9328. phba->work_ha |= HA_ERATT;
  9329. /* Indicate polling handles this ERATT */
  9330. phba->hba_flag |= HBA_ERATT_HANDLED;
  9331. return 1;
  9332. }
  9333. /**
  9334. * lpfc_sli4_eratt_read - read sli-4 error attention events
  9335. * @phba: Pointer to HBA context.
  9336. *
  9337. * This function is called to read the SLI4 device error attention registers
  9338. * for possible error attention events. The caller must hold the hostlock
  9339. * with spin_lock_irq().
  9340. *
  9341. * This function returns 1 when there is Error Attention in the Host Attention
  9342. * Register and returns 0 otherwise.
  9343. **/
  9344. static int
  9345. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  9346. {
  9347. uint32_t uerr_sta_hi, uerr_sta_lo;
  9348. uint32_t if_type, portsmphr;
  9349. struct lpfc_register portstat_reg;
  9350. /*
  9351. * For now, use the SLI4 device internal unrecoverable error
  9352. * registers for error attention. This can be changed later.
  9353. */
  9354. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9355. switch (if_type) {
  9356. case LPFC_SLI_INTF_IF_TYPE_0:
  9357. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  9358. &uerr_sta_lo) ||
  9359. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  9360. &uerr_sta_hi)) {
  9361. phba->work_hs |= UNPLUG_ERR;
  9362. phba->work_ha |= HA_ERATT;
  9363. phba->hba_flag |= HBA_ERATT_HANDLED;
  9364. return 1;
  9365. }
  9366. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  9367. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  9368. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9369. "1423 HBA Unrecoverable error: "
  9370. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9371. "ue_mask_lo_reg=0x%x, "
  9372. "ue_mask_hi_reg=0x%x\n",
  9373. uerr_sta_lo, uerr_sta_hi,
  9374. phba->sli4_hba.ue_mask_lo,
  9375. phba->sli4_hba.ue_mask_hi);
  9376. phba->work_status[0] = uerr_sta_lo;
  9377. phba->work_status[1] = uerr_sta_hi;
  9378. phba->work_ha |= HA_ERATT;
  9379. phba->hba_flag |= HBA_ERATT_HANDLED;
  9380. return 1;
  9381. }
  9382. break;
  9383. case LPFC_SLI_INTF_IF_TYPE_2:
  9384. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9385. &portstat_reg.word0) ||
  9386. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9387. &portsmphr)){
  9388. phba->work_hs |= UNPLUG_ERR;
  9389. phba->work_ha |= HA_ERATT;
  9390. phba->hba_flag |= HBA_ERATT_HANDLED;
  9391. return 1;
  9392. }
  9393. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9394. phba->work_status[0] =
  9395. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9396. phba->work_status[1] =
  9397. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9398. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9399. "2885 Port Status Event: "
  9400. "port status reg 0x%x, "
  9401. "port smphr reg 0x%x, "
  9402. "error 1=0x%x, error 2=0x%x\n",
  9403. portstat_reg.word0,
  9404. portsmphr,
  9405. phba->work_status[0],
  9406. phba->work_status[1]);
  9407. phba->work_ha |= HA_ERATT;
  9408. phba->hba_flag |= HBA_ERATT_HANDLED;
  9409. return 1;
  9410. }
  9411. break;
  9412. case LPFC_SLI_INTF_IF_TYPE_1:
  9413. default:
  9414. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9415. "2886 HBA Error Attention on unsupported "
  9416. "if type %d.", if_type);
  9417. return 1;
  9418. }
  9419. return 0;
  9420. }
  9421. /**
  9422. * lpfc_sli_check_eratt - check error attention events
  9423. * @phba: Pointer to HBA context.
  9424. *
  9425. * This function is called from timer soft interrupt context to check HBA's
  9426. * error attention register bit for error attention events.
  9427. *
  9428. * This function returns 1 when there is Error Attention in the Host Attention
  9429. * Register and returns 0 otherwise.
  9430. **/
  9431. int
  9432. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9433. {
  9434. uint32_t ha_copy;
  9435. /* If somebody is waiting to handle an eratt, don't process it
  9436. * here. The brdkill function will do this.
  9437. */
  9438. if (phba->link_flag & LS_IGNORE_ERATT)
  9439. return 0;
  9440. /* Check if interrupt handler handles this ERATT */
  9441. spin_lock_irq(&phba->hbalock);
  9442. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  9443. /* Interrupt handler has handled ERATT */
  9444. spin_unlock_irq(&phba->hbalock);
  9445. return 0;
  9446. }
  9447. /*
  9448. * If there is deferred error attention, do not check for error
  9449. * attention
  9450. */
  9451. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9452. spin_unlock_irq(&phba->hbalock);
  9453. return 0;
  9454. }
  9455. /* If PCI channel is offline, don't process it */
  9456. if (unlikely(pci_channel_offline(phba->pcidev))) {
  9457. spin_unlock_irq(&phba->hbalock);
  9458. return 0;
  9459. }
  9460. switch (phba->sli_rev) {
  9461. case LPFC_SLI_REV2:
  9462. case LPFC_SLI_REV3:
  9463. /* Read chip Host Attention (HA) register */
  9464. ha_copy = lpfc_sli_eratt_read(phba);
  9465. break;
  9466. case LPFC_SLI_REV4:
  9467. /* Read device Uncoverable Error (UERR) registers */
  9468. ha_copy = lpfc_sli4_eratt_read(phba);
  9469. break;
  9470. default:
  9471. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9472. "0299 Invalid SLI revision (%d)\n",
  9473. phba->sli_rev);
  9474. ha_copy = 0;
  9475. break;
  9476. }
  9477. spin_unlock_irq(&phba->hbalock);
  9478. return ha_copy;
  9479. }
  9480. /**
  9481. * lpfc_intr_state_check - Check device state for interrupt handling
  9482. * @phba: Pointer to HBA context.
  9483. *
  9484. * This inline routine checks whether a device or its PCI slot is in a state
  9485. * that the interrupt should be handled.
  9486. *
  9487. * This function returns 0 if the device or the PCI slot is in a state that
  9488. * interrupt should be handled, otherwise -EIO.
  9489. */
  9490. static inline int
  9491. lpfc_intr_state_check(struct lpfc_hba *phba)
  9492. {
  9493. /* If the pci channel is offline, ignore all the interrupts */
  9494. if (unlikely(pci_channel_offline(phba->pcidev)))
  9495. return -EIO;
  9496. /* Update device level interrupt statistics */
  9497. phba->sli.slistat.sli_intr++;
  9498. /* Ignore all interrupts during initialization. */
  9499. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  9500. return -EIO;
  9501. return 0;
  9502. }
  9503. /**
  9504. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  9505. * @irq: Interrupt number.
  9506. * @dev_id: The device context pointer.
  9507. *
  9508. * This function is directly called from the PCI layer as an interrupt
  9509. * service routine when device with SLI-3 interface spec is enabled with
  9510. * MSI-X multi-message interrupt mode and there are slow-path events in
  9511. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9512. * interrupt mode, this function is called as part of the device-level
  9513. * interrupt handler. When the PCI slot is in error recovery or the HBA
  9514. * is undergoing initialization, the interrupt handler will not process
  9515. * the interrupt. The link attention and ELS ring attention events are
  9516. * handled by the worker thread. The interrupt handler signals the worker
  9517. * thread and returns for these events. This function is called without
  9518. * any lock held. It gets the hbalock to access and update SLI data
  9519. * structures.
  9520. *
  9521. * This function returns IRQ_HANDLED when interrupt is handled else it
  9522. * returns IRQ_NONE.
  9523. **/
  9524. irqreturn_t
  9525. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  9526. {
  9527. struct lpfc_hba *phba;
  9528. uint32_t ha_copy, hc_copy;
  9529. uint32_t work_ha_copy;
  9530. unsigned long status;
  9531. unsigned long iflag;
  9532. uint32_t control;
  9533. MAILBOX_t *mbox, *pmbox;
  9534. struct lpfc_vport *vport;
  9535. struct lpfc_nodelist *ndlp;
  9536. struct lpfc_dmabuf *mp;
  9537. LPFC_MBOXQ_t *pmb;
  9538. int rc;
  9539. /*
  9540. * Get the driver's phba structure from the dev_id and
  9541. * assume the HBA is not interrupting.
  9542. */
  9543. phba = (struct lpfc_hba *)dev_id;
  9544. if (unlikely(!phba))
  9545. return IRQ_NONE;
  9546. /*
  9547. * Stuff needs to be attented to when this function is invoked as an
  9548. * individual interrupt handler in MSI-X multi-message interrupt mode
  9549. */
  9550. if (phba->intr_type == MSIX) {
  9551. /* Check device state for handling interrupt */
  9552. if (lpfc_intr_state_check(phba))
  9553. return IRQ_NONE;
  9554. /* Need to read HA REG for slow-path events */
  9555. spin_lock_irqsave(&phba->hbalock, iflag);
  9556. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9557. goto unplug_error;
  9558. /* If somebody is waiting to handle an eratt don't process it
  9559. * here. The brdkill function will do this.
  9560. */
  9561. if (phba->link_flag & LS_IGNORE_ERATT)
  9562. ha_copy &= ~HA_ERATT;
  9563. /* Check the need for handling ERATT in interrupt handler */
  9564. if (ha_copy & HA_ERATT) {
  9565. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9566. /* ERATT polling has handled ERATT */
  9567. ha_copy &= ~HA_ERATT;
  9568. else
  9569. /* Indicate interrupt handler handles ERATT */
  9570. phba->hba_flag |= HBA_ERATT_HANDLED;
  9571. }
  9572. /*
  9573. * If there is deferred error attention, do not check for any
  9574. * interrupt.
  9575. */
  9576. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9577. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9578. return IRQ_NONE;
  9579. }
  9580. /* Clear up only attention source related to slow-path */
  9581. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  9582. goto unplug_error;
  9583. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  9584. HC_LAINT_ENA | HC_ERINT_ENA),
  9585. phba->HCregaddr);
  9586. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  9587. phba->HAregaddr);
  9588. writel(hc_copy, phba->HCregaddr);
  9589. readl(phba->HAregaddr); /* flush */
  9590. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9591. } else
  9592. ha_copy = phba->ha_copy;
  9593. work_ha_copy = ha_copy & phba->work_ha_mask;
  9594. if (work_ha_copy) {
  9595. if (work_ha_copy & HA_LATT) {
  9596. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  9597. /*
  9598. * Turn off Link Attention interrupts
  9599. * until CLEAR_LA done
  9600. */
  9601. spin_lock_irqsave(&phba->hbalock, iflag);
  9602. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  9603. if (lpfc_readl(phba->HCregaddr, &control))
  9604. goto unplug_error;
  9605. control &= ~HC_LAINT_ENA;
  9606. writel(control, phba->HCregaddr);
  9607. readl(phba->HCregaddr); /* flush */
  9608. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9609. }
  9610. else
  9611. work_ha_copy &= ~HA_LATT;
  9612. }
  9613. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  9614. /*
  9615. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  9616. * the only slow ring.
  9617. */
  9618. status = (work_ha_copy &
  9619. (HA_RXMASK << (4*LPFC_ELS_RING)));
  9620. status >>= (4*LPFC_ELS_RING);
  9621. if (status & HA_RXMASK) {
  9622. spin_lock_irqsave(&phba->hbalock, iflag);
  9623. if (lpfc_readl(phba->HCregaddr, &control))
  9624. goto unplug_error;
  9625. lpfc_debugfs_slow_ring_trc(phba,
  9626. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  9627. control, status,
  9628. (uint32_t)phba->sli.slistat.sli_intr);
  9629. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  9630. lpfc_debugfs_slow_ring_trc(phba,
  9631. "ISR Disable ring:"
  9632. "pwork:x%x hawork:x%x wait:x%x",
  9633. phba->work_ha, work_ha_copy,
  9634. (uint32_t)((unsigned long)
  9635. &phba->work_waitq));
  9636. control &=
  9637. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  9638. writel(control, phba->HCregaddr);
  9639. readl(phba->HCregaddr); /* flush */
  9640. }
  9641. else {
  9642. lpfc_debugfs_slow_ring_trc(phba,
  9643. "ISR slow ring: pwork:"
  9644. "x%x hawork:x%x wait:x%x",
  9645. phba->work_ha, work_ha_copy,
  9646. (uint32_t)((unsigned long)
  9647. &phba->work_waitq));
  9648. }
  9649. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9650. }
  9651. }
  9652. spin_lock_irqsave(&phba->hbalock, iflag);
  9653. if (work_ha_copy & HA_ERATT) {
  9654. if (lpfc_sli_read_hs(phba))
  9655. goto unplug_error;
  9656. /*
  9657. * Check if there is a deferred error condition
  9658. * is active
  9659. */
  9660. if ((HS_FFER1 & phba->work_hs) &&
  9661. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9662. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  9663. phba->work_hs)) {
  9664. phba->hba_flag |= DEFER_ERATT;
  9665. /* Clear all interrupt enable conditions */
  9666. writel(0, phba->HCregaddr);
  9667. readl(phba->HCregaddr);
  9668. }
  9669. }
  9670. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  9671. pmb = phba->sli.mbox_active;
  9672. pmbox = &pmb->u.mb;
  9673. mbox = phba->mbox;
  9674. vport = pmb->vport;
  9675. /* First check out the status word */
  9676. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  9677. if (pmbox->mbxOwner != OWN_HOST) {
  9678. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9679. /*
  9680. * Stray Mailbox Interrupt, mbxCommand <cmd>
  9681. * mbxStatus <status>
  9682. */
  9683. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9684. LOG_SLI,
  9685. "(%d):0304 Stray Mailbox "
  9686. "Interrupt mbxCommand x%x "
  9687. "mbxStatus x%x\n",
  9688. (vport ? vport->vpi : 0),
  9689. pmbox->mbxCommand,
  9690. pmbox->mbxStatus);
  9691. /* clear mailbox attention bit */
  9692. work_ha_copy &= ~HA_MBATT;
  9693. } else {
  9694. phba->sli.mbox_active = NULL;
  9695. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9696. phba->last_completion_time = jiffies;
  9697. del_timer(&phba->sli.mbox_tmo);
  9698. if (pmb->mbox_cmpl) {
  9699. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  9700. MAILBOX_CMD_SIZE);
  9701. if (pmb->out_ext_byte_len &&
  9702. pmb->context2)
  9703. lpfc_sli_pcimem_bcopy(
  9704. phba->mbox_ext,
  9705. pmb->context2,
  9706. pmb->out_ext_byte_len);
  9707. }
  9708. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  9709. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  9710. lpfc_debugfs_disc_trc(vport,
  9711. LPFC_DISC_TRC_MBOX_VPORT,
  9712. "MBOX dflt rpi: : "
  9713. "status:x%x rpi:x%x",
  9714. (uint32_t)pmbox->mbxStatus,
  9715. pmbox->un.varWords[0], 0);
  9716. if (!pmbox->mbxStatus) {
  9717. mp = (struct lpfc_dmabuf *)
  9718. (pmb->context1);
  9719. ndlp = (struct lpfc_nodelist *)
  9720. pmb->context2;
  9721. /* Reg_LOGIN of dflt RPI was
  9722. * successful. new lets get
  9723. * rid of the RPI using the
  9724. * same mbox buffer.
  9725. */
  9726. lpfc_unreg_login(phba,
  9727. vport->vpi,
  9728. pmbox->un.varWords[0],
  9729. pmb);
  9730. pmb->mbox_cmpl =
  9731. lpfc_mbx_cmpl_dflt_rpi;
  9732. pmb->context1 = mp;
  9733. pmb->context2 = ndlp;
  9734. pmb->vport = vport;
  9735. rc = lpfc_sli_issue_mbox(phba,
  9736. pmb,
  9737. MBX_NOWAIT);
  9738. if (rc != MBX_BUSY)
  9739. lpfc_printf_log(phba,
  9740. KERN_ERR,
  9741. LOG_MBOX | LOG_SLI,
  9742. "0350 rc should have"
  9743. "been MBX_BUSY\n");
  9744. if (rc != MBX_NOT_FINISHED)
  9745. goto send_current_mbox;
  9746. }
  9747. }
  9748. spin_lock_irqsave(
  9749. &phba->pport->work_port_lock,
  9750. iflag);
  9751. phba->pport->work_port_events &=
  9752. ~WORKER_MBOX_TMO;
  9753. spin_unlock_irqrestore(
  9754. &phba->pport->work_port_lock,
  9755. iflag);
  9756. lpfc_mbox_cmpl_put(phba, pmb);
  9757. }
  9758. } else
  9759. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9760. if ((work_ha_copy & HA_MBATT) &&
  9761. (phba->sli.mbox_active == NULL)) {
  9762. send_current_mbox:
  9763. /* Process next mailbox command if there is one */
  9764. do {
  9765. rc = lpfc_sli_issue_mbox(phba, NULL,
  9766. MBX_NOWAIT);
  9767. } while (rc == MBX_NOT_FINISHED);
  9768. if (rc != MBX_SUCCESS)
  9769. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9770. LOG_SLI, "0349 rc should be "
  9771. "MBX_SUCCESS\n");
  9772. }
  9773. spin_lock_irqsave(&phba->hbalock, iflag);
  9774. phba->work_ha |= work_ha_copy;
  9775. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9776. lpfc_worker_wake_up(phba);
  9777. }
  9778. return IRQ_HANDLED;
  9779. unplug_error:
  9780. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9781. return IRQ_HANDLED;
  9782. } /* lpfc_sli_sp_intr_handler */
  9783. /**
  9784. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  9785. * @irq: Interrupt number.
  9786. * @dev_id: The device context pointer.
  9787. *
  9788. * This function is directly called from the PCI layer as an interrupt
  9789. * service routine when device with SLI-3 interface spec is enabled with
  9790. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9791. * ring event in the HBA. However, when the device is enabled with either
  9792. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9793. * device-level interrupt handler. When the PCI slot is in error recovery
  9794. * or the HBA is undergoing initialization, the interrupt handler will not
  9795. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9796. * the intrrupt context. This function is called without any lock held.
  9797. * It gets the hbalock to access and update SLI data structures.
  9798. *
  9799. * This function returns IRQ_HANDLED when interrupt is handled else it
  9800. * returns IRQ_NONE.
  9801. **/
  9802. irqreturn_t
  9803. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  9804. {
  9805. struct lpfc_hba *phba;
  9806. uint32_t ha_copy;
  9807. unsigned long status;
  9808. unsigned long iflag;
  9809. /* Get the driver's phba structure from the dev_id and
  9810. * assume the HBA is not interrupting.
  9811. */
  9812. phba = (struct lpfc_hba *) dev_id;
  9813. if (unlikely(!phba))
  9814. return IRQ_NONE;
  9815. /*
  9816. * Stuff needs to be attented to when this function is invoked as an
  9817. * individual interrupt handler in MSI-X multi-message interrupt mode
  9818. */
  9819. if (phba->intr_type == MSIX) {
  9820. /* Check device state for handling interrupt */
  9821. if (lpfc_intr_state_check(phba))
  9822. return IRQ_NONE;
  9823. /* Need to read HA REG for FCP ring and other ring events */
  9824. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9825. return IRQ_HANDLED;
  9826. /* Clear up only attention source related to fast-path */
  9827. spin_lock_irqsave(&phba->hbalock, iflag);
  9828. /*
  9829. * If there is deferred error attention, do not check for
  9830. * any interrupt.
  9831. */
  9832. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9833. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9834. return IRQ_NONE;
  9835. }
  9836. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  9837. phba->HAregaddr);
  9838. readl(phba->HAregaddr); /* flush */
  9839. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9840. } else
  9841. ha_copy = phba->ha_copy;
  9842. /*
  9843. * Process all events on FCP ring. Take the optimized path for FCP IO.
  9844. */
  9845. ha_copy &= ~(phba->work_ha_mask);
  9846. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9847. status >>= (4*LPFC_FCP_RING);
  9848. if (status & HA_RXMASK)
  9849. lpfc_sli_handle_fast_ring_event(phba,
  9850. &phba->sli.ring[LPFC_FCP_RING],
  9851. status);
  9852. if (phba->cfg_multi_ring_support == 2) {
  9853. /*
  9854. * Process all events on extra ring. Take the optimized path
  9855. * for extra ring IO.
  9856. */
  9857. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9858. status >>= (4*LPFC_EXTRA_RING);
  9859. if (status & HA_RXMASK) {
  9860. lpfc_sli_handle_fast_ring_event(phba,
  9861. &phba->sli.ring[LPFC_EXTRA_RING],
  9862. status);
  9863. }
  9864. }
  9865. return IRQ_HANDLED;
  9866. } /* lpfc_sli_fp_intr_handler */
  9867. /**
  9868. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  9869. * @irq: Interrupt number.
  9870. * @dev_id: The device context pointer.
  9871. *
  9872. * This function is the HBA device-level interrupt handler to device with
  9873. * SLI-3 interface spec, called from the PCI layer when either MSI or
  9874. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  9875. * requires driver attention. This function invokes the slow-path interrupt
  9876. * attention handling function and fast-path interrupt attention handling
  9877. * function in turn to process the relevant HBA attention events. This
  9878. * function is called without any lock held. It gets the hbalock to access
  9879. * and update SLI data structures.
  9880. *
  9881. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9882. * returns IRQ_NONE.
  9883. **/
  9884. irqreturn_t
  9885. lpfc_sli_intr_handler(int irq, void *dev_id)
  9886. {
  9887. struct lpfc_hba *phba;
  9888. irqreturn_t sp_irq_rc, fp_irq_rc;
  9889. unsigned long status1, status2;
  9890. uint32_t hc_copy;
  9891. /*
  9892. * Get the driver's phba structure from the dev_id and
  9893. * assume the HBA is not interrupting.
  9894. */
  9895. phba = (struct lpfc_hba *) dev_id;
  9896. if (unlikely(!phba))
  9897. return IRQ_NONE;
  9898. /* Check device state for handling interrupt */
  9899. if (lpfc_intr_state_check(phba))
  9900. return IRQ_NONE;
  9901. spin_lock(&phba->hbalock);
  9902. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  9903. spin_unlock(&phba->hbalock);
  9904. return IRQ_HANDLED;
  9905. }
  9906. if (unlikely(!phba->ha_copy)) {
  9907. spin_unlock(&phba->hbalock);
  9908. return IRQ_NONE;
  9909. } else if (phba->ha_copy & HA_ERATT) {
  9910. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9911. /* ERATT polling has handled ERATT */
  9912. phba->ha_copy &= ~HA_ERATT;
  9913. else
  9914. /* Indicate interrupt handler handles ERATT */
  9915. phba->hba_flag |= HBA_ERATT_HANDLED;
  9916. }
  9917. /*
  9918. * If there is deferred error attention, do not check for any interrupt.
  9919. */
  9920. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9921. spin_unlock(&phba->hbalock);
  9922. return IRQ_NONE;
  9923. }
  9924. /* Clear attention sources except link and error attentions */
  9925. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  9926. spin_unlock(&phba->hbalock);
  9927. return IRQ_HANDLED;
  9928. }
  9929. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  9930. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  9931. phba->HCregaddr);
  9932. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  9933. writel(hc_copy, phba->HCregaddr);
  9934. readl(phba->HAregaddr); /* flush */
  9935. spin_unlock(&phba->hbalock);
  9936. /*
  9937. * Invokes slow-path host attention interrupt handling as appropriate.
  9938. */
  9939. /* status of events with mailbox and link attention */
  9940. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  9941. /* status of events with ELS ring */
  9942. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  9943. status2 >>= (4*LPFC_ELS_RING);
  9944. if (status1 || (status2 & HA_RXMASK))
  9945. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  9946. else
  9947. sp_irq_rc = IRQ_NONE;
  9948. /*
  9949. * Invoke fast-path host attention interrupt handling as appropriate.
  9950. */
  9951. /* status of events with FCP ring */
  9952. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9953. status1 >>= (4*LPFC_FCP_RING);
  9954. /* status of events with extra ring */
  9955. if (phba->cfg_multi_ring_support == 2) {
  9956. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9957. status2 >>= (4*LPFC_EXTRA_RING);
  9958. } else
  9959. status2 = 0;
  9960. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  9961. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  9962. else
  9963. fp_irq_rc = IRQ_NONE;
  9964. /* Return device-level interrupt handling status */
  9965. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  9966. } /* lpfc_sli_intr_handler */
  9967. /**
  9968. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  9969. * @phba: pointer to lpfc hba data structure.
  9970. *
  9971. * This routine is invoked by the worker thread to process all the pending
  9972. * SLI4 FCP abort XRI events.
  9973. **/
  9974. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  9975. {
  9976. struct lpfc_cq_event *cq_event;
  9977. /* First, declare the fcp xri abort event has been handled */
  9978. spin_lock_irq(&phba->hbalock);
  9979. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  9980. spin_unlock_irq(&phba->hbalock);
  9981. /* Now, handle all the fcp xri abort events */
  9982. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  9983. /* Get the first event from the head of the event queue */
  9984. spin_lock_irq(&phba->hbalock);
  9985. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  9986. cq_event, struct lpfc_cq_event, list);
  9987. spin_unlock_irq(&phba->hbalock);
  9988. /* Notify aborted XRI for FCP work queue */
  9989. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9990. /* Free the event processed back to the free pool */
  9991. lpfc_sli4_cq_event_release(phba, cq_event);
  9992. }
  9993. }
  9994. /**
  9995. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  9996. * @phba: pointer to lpfc hba data structure.
  9997. *
  9998. * This routine is invoked by the worker thread to process all the pending
  9999. * SLI4 els abort xri events.
  10000. **/
  10001. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  10002. {
  10003. struct lpfc_cq_event *cq_event;
  10004. /* First, declare the els xri abort event has been handled */
  10005. spin_lock_irq(&phba->hbalock);
  10006. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  10007. spin_unlock_irq(&phba->hbalock);
  10008. /* Now, handle all the els xri abort events */
  10009. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  10010. /* Get the first event from the head of the event queue */
  10011. spin_lock_irq(&phba->hbalock);
  10012. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  10013. cq_event, struct lpfc_cq_event, list);
  10014. spin_unlock_irq(&phba->hbalock);
  10015. /* Notify aborted XRI for ELS work queue */
  10016. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  10017. /* Free the event processed back to the free pool */
  10018. lpfc_sli4_cq_event_release(phba, cq_event);
  10019. }
  10020. }
  10021. /**
  10022. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  10023. * @phba: pointer to lpfc hba data structure
  10024. * @pIocbIn: pointer to the rspiocbq
  10025. * @pIocbOut: pointer to the cmdiocbq
  10026. * @wcqe: pointer to the complete wcqe
  10027. *
  10028. * This routine transfers the fields of a command iocbq to a response iocbq
  10029. * by copying all the IOCB fields from command iocbq and transferring the
  10030. * completion status information from the complete wcqe.
  10031. **/
  10032. static void
  10033. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  10034. struct lpfc_iocbq *pIocbIn,
  10035. struct lpfc_iocbq *pIocbOut,
  10036. struct lpfc_wcqe_complete *wcqe)
  10037. {
  10038. unsigned long iflags;
  10039. uint32_t status;
  10040. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  10041. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  10042. sizeof(struct lpfc_iocbq) - offset);
  10043. /* Map WCQE parameters into irspiocb parameters */
  10044. status = bf_get(lpfc_wcqe_c_status, wcqe);
  10045. pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
  10046. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  10047. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  10048. pIocbIn->iocb.un.fcpi.fcpi_parm =
  10049. pIocbOut->iocb.un.fcpi.fcpi_parm -
  10050. wcqe->total_data_placed;
  10051. else
  10052. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10053. else {
  10054. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10055. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  10056. }
  10057. /* Convert BG errors for completion status */
  10058. if (status == CQE_STATUS_DI_ERROR) {
  10059. pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  10060. if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
  10061. pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
  10062. else
  10063. pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
  10064. pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
  10065. if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
  10066. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10067. BGS_GUARD_ERR_MASK;
  10068. if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
  10069. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10070. BGS_APPTAG_ERR_MASK;
  10071. if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
  10072. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10073. BGS_REFTAG_ERR_MASK;
  10074. /* Check to see if there was any good data before the error */
  10075. if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
  10076. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10077. BGS_HI_WATER_MARK_PRESENT_MASK;
  10078. pIocbIn->iocb.unsli3.sli3_bg.bghm =
  10079. wcqe->total_data_placed;
  10080. }
  10081. /*
  10082. * Set ALL the error bits to indicate we don't know what
  10083. * type of error it is.
  10084. */
  10085. if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
  10086. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10087. (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
  10088. BGS_GUARD_ERR_MASK);
  10089. }
  10090. /* Pick up HBA exchange busy condition */
  10091. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  10092. spin_lock_irqsave(&phba->hbalock, iflags);
  10093. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  10094. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10095. }
  10096. }
  10097. /**
  10098. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  10099. * @phba: Pointer to HBA context object.
  10100. * @wcqe: Pointer to work-queue completion queue entry.
  10101. *
  10102. * This routine handles an ELS work-queue completion event and construct
  10103. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  10104. * discovery engine to handle.
  10105. *
  10106. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  10107. **/
  10108. static struct lpfc_iocbq *
  10109. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  10110. struct lpfc_iocbq *irspiocbq)
  10111. {
  10112. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  10113. struct lpfc_iocbq *cmdiocbq;
  10114. struct lpfc_wcqe_complete *wcqe;
  10115. unsigned long iflags;
  10116. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  10117. spin_lock_irqsave(&pring->ring_lock, iflags);
  10118. pring->stats.iocb_event++;
  10119. /* Look up the ELS command IOCB and create pseudo response IOCB */
  10120. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10121. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10122. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10123. if (unlikely(!cmdiocbq)) {
  10124. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10125. "0386 ELS complete with no corresponding "
  10126. "cmdiocb: iotag (%d)\n",
  10127. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10128. lpfc_sli_release_iocbq(phba, irspiocbq);
  10129. return NULL;
  10130. }
  10131. /* Fake the irspiocbq and copy necessary response information */
  10132. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  10133. return irspiocbq;
  10134. }
  10135. /**
  10136. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  10137. * @phba: Pointer to HBA context object.
  10138. * @cqe: Pointer to mailbox completion queue entry.
  10139. *
  10140. * This routine process a mailbox completion queue entry with asynchrous
  10141. * event.
  10142. *
  10143. * Return: true if work posted to worker thread, otherwise false.
  10144. **/
  10145. static bool
  10146. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10147. {
  10148. struct lpfc_cq_event *cq_event;
  10149. unsigned long iflags;
  10150. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  10151. "0392 Async Event: word0:x%x, word1:x%x, "
  10152. "word2:x%x, word3:x%x\n", mcqe->word0,
  10153. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  10154. /* Allocate a new internal CQ_EVENT entry */
  10155. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10156. if (!cq_event) {
  10157. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10158. "0394 Failed to allocate CQ_EVENT entry\n");
  10159. return false;
  10160. }
  10161. /* Move the CQE into an asynchronous event entry */
  10162. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  10163. spin_lock_irqsave(&phba->hbalock, iflags);
  10164. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  10165. /* Set the async event flag */
  10166. phba->hba_flag |= ASYNC_EVENT;
  10167. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10168. return true;
  10169. }
  10170. /**
  10171. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  10172. * @phba: Pointer to HBA context object.
  10173. * @cqe: Pointer to mailbox completion queue entry.
  10174. *
  10175. * This routine process a mailbox completion queue entry with mailbox
  10176. * completion event.
  10177. *
  10178. * Return: true if work posted to worker thread, otherwise false.
  10179. **/
  10180. static bool
  10181. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10182. {
  10183. uint32_t mcqe_status;
  10184. MAILBOX_t *mbox, *pmbox;
  10185. struct lpfc_mqe *mqe;
  10186. struct lpfc_vport *vport;
  10187. struct lpfc_nodelist *ndlp;
  10188. struct lpfc_dmabuf *mp;
  10189. unsigned long iflags;
  10190. LPFC_MBOXQ_t *pmb;
  10191. bool workposted = false;
  10192. int rc;
  10193. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  10194. if (!bf_get(lpfc_trailer_completed, mcqe))
  10195. goto out_no_mqe_complete;
  10196. /* Get the reference to the active mbox command */
  10197. spin_lock_irqsave(&phba->hbalock, iflags);
  10198. pmb = phba->sli.mbox_active;
  10199. if (unlikely(!pmb)) {
  10200. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10201. "1832 No pending MBOX command to handle\n");
  10202. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10203. goto out_no_mqe_complete;
  10204. }
  10205. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10206. mqe = &pmb->u.mqe;
  10207. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  10208. mbox = phba->mbox;
  10209. vport = pmb->vport;
  10210. /* Reset heartbeat timer */
  10211. phba->last_completion_time = jiffies;
  10212. del_timer(&phba->sli.mbox_tmo);
  10213. /* Move mbox data to caller's mailbox region, do endian swapping */
  10214. if (pmb->mbox_cmpl && mbox)
  10215. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  10216. /*
  10217. * For mcqe errors, conditionally move a modified error code to
  10218. * the mbox so that the error will not be missed.
  10219. */
  10220. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  10221. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  10222. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  10223. bf_set(lpfc_mqe_status, mqe,
  10224. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  10225. }
  10226. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10227. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10228. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  10229. "MBOX dflt rpi: status:x%x rpi:x%x",
  10230. mcqe_status,
  10231. pmbox->un.varWords[0], 0);
  10232. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  10233. mp = (struct lpfc_dmabuf *)(pmb->context1);
  10234. ndlp = (struct lpfc_nodelist *)pmb->context2;
  10235. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  10236. * RID of the PPI using the same mbox buffer.
  10237. */
  10238. lpfc_unreg_login(phba, vport->vpi,
  10239. pmbox->un.varWords[0], pmb);
  10240. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  10241. pmb->context1 = mp;
  10242. pmb->context2 = ndlp;
  10243. pmb->vport = vport;
  10244. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  10245. if (rc != MBX_BUSY)
  10246. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10247. LOG_SLI, "0385 rc should "
  10248. "have been MBX_BUSY\n");
  10249. if (rc != MBX_NOT_FINISHED)
  10250. goto send_current_mbox;
  10251. }
  10252. }
  10253. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  10254. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  10255. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  10256. /* There is mailbox completion work to do */
  10257. spin_lock_irqsave(&phba->hbalock, iflags);
  10258. __lpfc_mbox_cmpl_put(phba, pmb);
  10259. phba->work_ha |= HA_MBATT;
  10260. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10261. workposted = true;
  10262. send_current_mbox:
  10263. spin_lock_irqsave(&phba->hbalock, iflags);
  10264. /* Release the mailbox command posting token */
  10265. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  10266. /* Setting active mailbox pointer need to be in sync to flag clear */
  10267. phba->sli.mbox_active = NULL;
  10268. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10269. /* Wake up worker thread to post the next pending mailbox command */
  10270. lpfc_worker_wake_up(phba);
  10271. out_no_mqe_complete:
  10272. if (bf_get(lpfc_trailer_consumed, mcqe))
  10273. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  10274. return workposted;
  10275. }
  10276. /**
  10277. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  10278. * @phba: Pointer to HBA context object.
  10279. * @cqe: Pointer to mailbox completion queue entry.
  10280. *
  10281. * This routine process a mailbox completion queue entry, it invokes the
  10282. * proper mailbox complete handling or asynchrous event handling routine
  10283. * according to the MCQE's async bit.
  10284. *
  10285. * Return: true if work posted to worker thread, otherwise false.
  10286. **/
  10287. static bool
  10288. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  10289. {
  10290. struct lpfc_mcqe mcqe;
  10291. bool workposted;
  10292. /* Copy the mailbox MCQE and convert endian order as needed */
  10293. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  10294. /* Invoke the proper event handling routine */
  10295. if (!bf_get(lpfc_trailer_async, &mcqe))
  10296. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  10297. else
  10298. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  10299. return workposted;
  10300. }
  10301. /**
  10302. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  10303. * @phba: Pointer to HBA context object.
  10304. * @cq: Pointer to associated CQ
  10305. * @wcqe: Pointer to work-queue completion queue entry.
  10306. *
  10307. * This routine handles an ELS work-queue completion event.
  10308. *
  10309. * Return: true if work posted to worker thread, otherwise false.
  10310. **/
  10311. static bool
  10312. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10313. struct lpfc_wcqe_complete *wcqe)
  10314. {
  10315. struct lpfc_iocbq *irspiocbq;
  10316. unsigned long iflags;
  10317. struct lpfc_sli_ring *pring = cq->pring;
  10318. int txq_cnt = 0;
  10319. int txcmplq_cnt = 0;
  10320. int fcp_txcmplq_cnt = 0;
  10321. /* Get an irspiocbq for later ELS response processing use */
  10322. irspiocbq = lpfc_sli_get_iocbq(phba);
  10323. if (!irspiocbq) {
  10324. if (!list_empty(&pring->txq))
  10325. txq_cnt++;
  10326. if (!list_empty(&pring->txcmplq))
  10327. txcmplq_cnt++;
  10328. if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq))
  10329. fcp_txcmplq_cnt++;
  10330. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10331. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  10332. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  10333. txq_cnt, phba->iocb_cnt,
  10334. fcp_txcmplq_cnt,
  10335. txcmplq_cnt);
  10336. return false;
  10337. }
  10338. /* Save off the slow-path queue event for work thread to process */
  10339. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  10340. spin_lock_irqsave(&phba->hbalock, iflags);
  10341. list_add_tail(&irspiocbq->cq_event.list,
  10342. &phba->sli4_hba.sp_queue_event);
  10343. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10344. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10345. return true;
  10346. }
  10347. /**
  10348. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  10349. * @phba: Pointer to HBA context object.
  10350. * @wcqe: Pointer to work-queue completion queue entry.
  10351. *
  10352. * This routine handles slow-path WQ entry comsumed event by invoking the
  10353. * proper WQ release routine to the slow-path WQ.
  10354. **/
  10355. static void
  10356. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  10357. struct lpfc_wcqe_release *wcqe)
  10358. {
  10359. /* sanity check on queue memory */
  10360. if (unlikely(!phba->sli4_hba.els_wq))
  10361. return;
  10362. /* Check for the slow-path ELS work queue */
  10363. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  10364. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  10365. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10366. else
  10367. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10368. "2579 Slow-path wqe consume event carries "
  10369. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  10370. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  10371. phba->sli4_hba.els_wq->queue_id);
  10372. }
  10373. /**
  10374. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  10375. * @phba: Pointer to HBA context object.
  10376. * @cq: Pointer to a WQ completion queue.
  10377. * @wcqe: Pointer to work-queue completion queue entry.
  10378. *
  10379. * This routine handles an XRI abort event.
  10380. *
  10381. * Return: true if work posted to worker thread, otherwise false.
  10382. **/
  10383. static bool
  10384. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  10385. struct lpfc_queue *cq,
  10386. struct sli4_wcqe_xri_aborted *wcqe)
  10387. {
  10388. bool workposted = false;
  10389. struct lpfc_cq_event *cq_event;
  10390. unsigned long iflags;
  10391. /* Allocate a new internal CQ_EVENT entry */
  10392. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10393. if (!cq_event) {
  10394. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10395. "0602 Failed to allocate CQ_EVENT entry\n");
  10396. return false;
  10397. }
  10398. /* Move the CQE into the proper xri abort event list */
  10399. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  10400. switch (cq->subtype) {
  10401. case LPFC_FCP:
  10402. spin_lock_irqsave(&phba->hbalock, iflags);
  10403. list_add_tail(&cq_event->list,
  10404. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  10405. /* Set the fcp xri abort event flag */
  10406. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  10407. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10408. workposted = true;
  10409. break;
  10410. case LPFC_ELS:
  10411. spin_lock_irqsave(&phba->hbalock, iflags);
  10412. list_add_tail(&cq_event->list,
  10413. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  10414. /* Set the els xri abort event flag */
  10415. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  10416. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10417. workposted = true;
  10418. break;
  10419. default:
  10420. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10421. "0603 Invalid work queue CQE subtype (x%x)\n",
  10422. cq->subtype);
  10423. workposted = false;
  10424. break;
  10425. }
  10426. return workposted;
  10427. }
  10428. /**
  10429. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  10430. * @phba: Pointer to HBA context object.
  10431. * @rcqe: Pointer to receive-queue completion queue entry.
  10432. *
  10433. * This routine process a receive-queue completion queue entry.
  10434. *
  10435. * Return: true if work posted to worker thread, otherwise false.
  10436. **/
  10437. static bool
  10438. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  10439. {
  10440. bool workposted = false;
  10441. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  10442. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  10443. struct hbq_dmabuf *dma_buf;
  10444. uint32_t status, rq_id;
  10445. unsigned long iflags;
  10446. /* sanity check on queue memory */
  10447. if (unlikely(!hrq) || unlikely(!drq))
  10448. return workposted;
  10449. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  10450. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  10451. else
  10452. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  10453. if (rq_id != hrq->queue_id)
  10454. goto out;
  10455. status = bf_get(lpfc_rcqe_status, rcqe);
  10456. switch (status) {
  10457. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  10458. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10459. "2537 Receive Frame Truncated!!\n");
  10460. hrq->RQ_buf_trunc++;
  10461. case FC_STATUS_RQ_SUCCESS:
  10462. lpfc_sli4_rq_release(hrq, drq);
  10463. spin_lock_irqsave(&phba->hbalock, iflags);
  10464. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  10465. if (!dma_buf) {
  10466. hrq->RQ_no_buf_found++;
  10467. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10468. goto out;
  10469. }
  10470. hrq->RQ_rcv_buf++;
  10471. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  10472. /* save off the frame for the word thread to process */
  10473. list_add_tail(&dma_buf->cq_event.list,
  10474. &phba->sli4_hba.sp_queue_event);
  10475. /* Frame received */
  10476. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10477. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10478. workposted = true;
  10479. break;
  10480. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  10481. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  10482. hrq->RQ_no_posted_buf++;
  10483. /* Post more buffers if possible */
  10484. spin_lock_irqsave(&phba->hbalock, iflags);
  10485. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  10486. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10487. workposted = true;
  10488. break;
  10489. }
  10490. out:
  10491. return workposted;
  10492. }
  10493. /**
  10494. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  10495. * @phba: Pointer to HBA context object.
  10496. * @cq: Pointer to the completion queue.
  10497. * @wcqe: Pointer to a completion queue entry.
  10498. *
  10499. * This routine process a slow-path work-queue or receive queue completion queue
  10500. * entry.
  10501. *
  10502. * Return: true if work posted to worker thread, otherwise false.
  10503. **/
  10504. static bool
  10505. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10506. struct lpfc_cqe *cqe)
  10507. {
  10508. struct lpfc_cqe cqevt;
  10509. bool workposted = false;
  10510. /* Copy the work queue CQE and convert endian order if needed */
  10511. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  10512. /* Check and process for different type of WCQE and dispatch */
  10513. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  10514. case CQE_CODE_COMPL_WQE:
  10515. /* Process the WQ/RQ complete event */
  10516. phba->last_completion_time = jiffies;
  10517. workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
  10518. (struct lpfc_wcqe_complete *)&cqevt);
  10519. break;
  10520. case CQE_CODE_RELEASE_WQE:
  10521. /* Process the WQ release event */
  10522. lpfc_sli4_sp_handle_rel_wcqe(phba,
  10523. (struct lpfc_wcqe_release *)&cqevt);
  10524. break;
  10525. case CQE_CODE_XRI_ABORTED:
  10526. /* Process the WQ XRI abort event */
  10527. phba->last_completion_time = jiffies;
  10528. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10529. (struct sli4_wcqe_xri_aborted *)&cqevt);
  10530. break;
  10531. case CQE_CODE_RECEIVE:
  10532. case CQE_CODE_RECEIVE_V1:
  10533. /* Process the RQ event */
  10534. phba->last_completion_time = jiffies;
  10535. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  10536. (struct lpfc_rcqe *)&cqevt);
  10537. break;
  10538. default:
  10539. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10540. "0388 Not a valid WCQE code: x%x\n",
  10541. bf_get(lpfc_cqe_code, &cqevt));
  10542. break;
  10543. }
  10544. return workposted;
  10545. }
  10546. /**
  10547. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  10548. * @phba: Pointer to HBA context object.
  10549. * @eqe: Pointer to fast-path event queue entry.
  10550. *
  10551. * This routine process a event queue entry from the slow-path event queue.
  10552. * It will check the MajorCode and MinorCode to determine this is for a
  10553. * completion event on a completion queue, if not, an error shall be logged
  10554. * and just return. Otherwise, it will get to the corresponding completion
  10555. * queue and process all the entries on that completion queue, rearm the
  10556. * completion queue, and then return.
  10557. *
  10558. **/
  10559. static void
  10560. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10561. struct lpfc_queue *speq)
  10562. {
  10563. struct lpfc_queue *cq = NULL, *childq;
  10564. struct lpfc_cqe *cqe;
  10565. bool workposted = false;
  10566. int ecount = 0;
  10567. uint16_t cqid;
  10568. /* Get the reference to the corresponding CQ */
  10569. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10570. list_for_each_entry(childq, &speq->child_list, list) {
  10571. if (childq->queue_id == cqid) {
  10572. cq = childq;
  10573. break;
  10574. }
  10575. }
  10576. if (unlikely(!cq)) {
  10577. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10578. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10579. "0365 Slow-path CQ identifier "
  10580. "(%d) does not exist\n", cqid);
  10581. return;
  10582. }
  10583. /* Process all the entries to the CQ */
  10584. switch (cq->type) {
  10585. case LPFC_MCQ:
  10586. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10587. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  10588. if (!(++ecount % cq->entry_repost))
  10589. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10590. cq->CQ_mbox++;
  10591. }
  10592. break;
  10593. case LPFC_WCQ:
  10594. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10595. if (cq->subtype == LPFC_FCP)
  10596. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  10597. cqe);
  10598. else
  10599. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  10600. cqe);
  10601. if (!(++ecount % cq->entry_repost))
  10602. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10603. }
  10604. /* Track the max number of CQEs processed in 1 EQ */
  10605. if (ecount > cq->CQ_max_cqe)
  10606. cq->CQ_max_cqe = ecount;
  10607. break;
  10608. default:
  10609. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10610. "0370 Invalid completion queue type (%d)\n",
  10611. cq->type);
  10612. return;
  10613. }
  10614. /* Catch the no cq entry condition, log an error */
  10615. if (unlikely(ecount == 0))
  10616. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10617. "0371 No entry from the CQ: identifier "
  10618. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  10619. /* In any case, flash and re-arm the RCQ */
  10620. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10621. /* wake up worker thread if there are works to be done */
  10622. if (workposted)
  10623. lpfc_worker_wake_up(phba);
  10624. }
  10625. /**
  10626. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  10627. * @phba: Pointer to HBA context object.
  10628. * @cq: Pointer to associated CQ
  10629. * @wcqe: Pointer to work-queue completion queue entry.
  10630. *
  10631. * This routine process a fast-path work queue completion entry from fast-path
  10632. * event queue for FCP command response completion.
  10633. **/
  10634. static void
  10635. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10636. struct lpfc_wcqe_complete *wcqe)
  10637. {
  10638. struct lpfc_sli_ring *pring = cq->pring;
  10639. struct lpfc_iocbq *cmdiocbq;
  10640. struct lpfc_iocbq irspiocbq;
  10641. unsigned long iflags;
  10642. /* Check for response status */
  10643. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  10644. /* If resource errors reported from HBA, reduce queue
  10645. * depth of the SCSI device.
  10646. */
  10647. if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
  10648. IOSTAT_LOCAL_REJECT)) &&
  10649. ((wcqe->parameter & IOERR_PARAM_MASK) ==
  10650. IOERR_NO_RESOURCES))
  10651. phba->lpfc_rampdown_queue_depth(phba);
  10652. /* Log the error status */
  10653. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10654. "0373 FCP complete error: status=x%x, "
  10655. "hw_status=x%x, total_data_specified=%d, "
  10656. "parameter=x%x, word3=x%x\n",
  10657. bf_get(lpfc_wcqe_c_status, wcqe),
  10658. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  10659. wcqe->total_data_placed, wcqe->parameter,
  10660. wcqe->word3);
  10661. }
  10662. /* Look up the FCP command IOCB and create pseudo response IOCB */
  10663. spin_lock_irqsave(&pring->ring_lock, iflags);
  10664. pring->stats.iocb_event++;
  10665. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10666. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10667. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10668. if (unlikely(!cmdiocbq)) {
  10669. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10670. "0374 FCP complete with no corresponding "
  10671. "cmdiocb: iotag (%d)\n",
  10672. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10673. return;
  10674. }
  10675. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  10676. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10677. "0375 FCP cmdiocb not callback function "
  10678. "iotag: (%d)\n",
  10679. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10680. return;
  10681. }
  10682. /* Fake the irspiocb and copy necessary response information */
  10683. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  10684. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  10685. spin_lock_irqsave(&phba->hbalock, iflags);
  10686. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  10687. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10688. }
  10689. /* Pass the cmd_iocb and the rsp state to the upper layer */
  10690. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  10691. }
  10692. /**
  10693. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  10694. * @phba: Pointer to HBA context object.
  10695. * @cq: Pointer to completion queue.
  10696. * @wcqe: Pointer to work-queue completion queue entry.
  10697. *
  10698. * This routine handles an fast-path WQ entry comsumed event by invoking the
  10699. * proper WQ release routine to the slow-path WQ.
  10700. **/
  10701. static void
  10702. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10703. struct lpfc_wcqe_release *wcqe)
  10704. {
  10705. struct lpfc_queue *childwq;
  10706. bool wqid_matched = false;
  10707. uint16_t fcp_wqid;
  10708. /* Check for fast-path FCP work queue release */
  10709. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  10710. list_for_each_entry(childwq, &cq->child_list, list) {
  10711. if (childwq->queue_id == fcp_wqid) {
  10712. lpfc_sli4_wq_release(childwq,
  10713. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10714. wqid_matched = true;
  10715. break;
  10716. }
  10717. }
  10718. /* Report warning log message if no match found */
  10719. if (wqid_matched != true)
  10720. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10721. "2580 Fast-path wqe consume event carries "
  10722. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  10723. }
  10724. /**
  10725. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  10726. * @cq: Pointer to the completion queue.
  10727. * @eqe: Pointer to fast-path completion queue entry.
  10728. *
  10729. * This routine process a fast-path work queue completion entry from fast-path
  10730. * event queue for FCP command response completion.
  10731. **/
  10732. static int
  10733. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10734. struct lpfc_cqe *cqe)
  10735. {
  10736. struct lpfc_wcqe_release wcqe;
  10737. bool workposted = false;
  10738. /* Copy the work queue CQE and convert endian order if needed */
  10739. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  10740. /* Check and process for different type of WCQE and dispatch */
  10741. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  10742. case CQE_CODE_COMPL_WQE:
  10743. cq->CQ_wq++;
  10744. /* Process the WQ complete event */
  10745. phba->last_completion_time = jiffies;
  10746. lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
  10747. (struct lpfc_wcqe_complete *)&wcqe);
  10748. break;
  10749. case CQE_CODE_RELEASE_WQE:
  10750. cq->CQ_release_wqe++;
  10751. /* Process the WQ release event */
  10752. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  10753. (struct lpfc_wcqe_release *)&wcqe);
  10754. break;
  10755. case CQE_CODE_XRI_ABORTED:
  10756. cq->CQ_xri_aborted++;
  10757. /* Process the WQ XRI abort event */
  10758. phba->last_completion_time = jiffies;
  10759. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10760. (struct sli4_wcqe_xri_aborted *)&wcqe);
  10761. break;
  10762. default:
  10763. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10764. "0144 Not a valid WCQE code: x%x\n",
  10765. bf_get(lpfc_wcqe_c_code, &wcqe));
  10766. break;
  10767. }
  10768. return workposted;
  10769. }
  10770. /**
  10771. * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
  10772. * @phba: Pointer to HBA context object.
  10773. * @eqe: Pointer to fast-path event queue entry.
  10774. *
  10775. * This routine process a event queue entry from the fast-path event queue.
  10776. * It will check the MajorCode and MinorCode to determine this is for a
  10777. * completion event on a completion queue, if not, an error shall be logged
  10778. * and just return. Otherwise, it will get to the corresponding completion
  10779. * queue and process all the entries on the completion queue, rearm the
  10780. * completion queue, and then return.
  10781. **/
  10782. static void
  10783. lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10784. uint32_t qidx)
  10785. {
  10786. struct lpfc_queue *cq;
  10787. struct lpfc_cqe *cqe;
  10788. bool workposted = false;
  10789. uint16_t cqid;
  10790. int ecount = 0;
  10791. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  10792. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10793. "0366 Not a valid completion "
  10794. "event: majorcode=x%x, minorcode=x%x\n",
  10795. bf_get_le32(lpfc_eqe_major_code, eqe),
  10796. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10797. return;
  10798. }
  10799. /* Get the reference to the corresponding CQ */
  10800. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10801. /* Check if this is a Slow path event */
  10802. if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) {
  10803. lpfc_sli4_sp_handle_eqe(phba, eqe,
  10804. phba->sli4_hba.hba_eq[qidx]);
  10805. return;
  10806. }
  10807. if (unlikely(!phba->sli4_hba.fcp_cq)) {
  10808. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10809. "3146 Fast-path completion queues "
  10810. "does not exist\n");
  10811. return;
  10812. }
  10813. cq = phba->sli4_hba.fcp_cq[qidx];
  10814. if (unlikely(!cq)) {
  10815. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10816. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10817. "0367 Fast-path completion queue "
  10818. "(%d) does not exist\n", qidx);
  10819. return;
  10820. }
  10821. if (unlikely(cqid != cq->queue_id)) {
  10822. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10823. "0368 Miss-matched fast-path completion "
  10824. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  10825. cqid, cq->queue_id);
  10826. return;
  10827. }
  10828. /* Process all the entries to the CQ */
  10829. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10830. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  10831. if (!(++ecount % cq->entry_repost))
  10832. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10833. }
  10834. /* Track the max number of CQEs processed in 1 EQ */
  10835. if (ecount > cq->CQ_max_cqe)
  10836. cq->CQ_max_cqe = ecount;
  10837. /* Catch the no cq entry condition */
  10838. if (unlikely(ecount == 0))
  10839. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10840. "0369 No entry from fast-path completion "
  10841. "queue fcpcqid=%d\n", cq->queue_id);
  10842. /* In any case, flash and re-arm the CQ */
  10843. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10844. /* wake up worker thread if there are works to be done */
  10845. if (workposted)
  10846. lpfc_worker_wake_up(phba);
  10847. }
  10848. static void
  10849. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10850. {
  10851. struct lpfc_eqe *eqe;
  10852. /* walk all the EQ entries and drop on the floor */
  10853. while ((eqe = lpfc_sli4_eq_get(eq)))
  10854. ;
  10855. /* Clear and re-arm the EQ */
  10856. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  10857. }
  10858. /**
  10859. * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
  10860. * @irq: Interrupt number.
  10861. * @dev_id: The device context pointer.
  10862. *
  10863. * This function is directly called from the PCI layer as an interrupt
  10864. * service routine when device with SLI-4 interface spec is enabled with
  10865. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10866. * ring event in the HBA. However, when the device is enabled with either
  10867. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10868. * device-level interrupt handler. When the PCI slot is in error recovery
  10869. * or the HBA is undergoing initialization, the interrupt handler will not
  10870. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10871. * the intrrupt context. This function is called without any lock held.
  10872. * It gets the hbalock to access and update SLI data structures. Note that,
  10873. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  10874. * equal to that of FCP CQ index.
  10875. *
  10876. * The link attention and ELS ring attention events are handled
  10877. * by the worker thread. The interrupt handler signals the worker thread
  10878. * and returns for these events. This function is called without any lock
  10879. * held. It gets the hbalock to access and update SLI data structures.
  10880. *
  10881. * This function returns IRQ_HANDLED when interrupt is handled else it
  10882. * returns IRQ_NONE.
  10883. **/
  10884. irqreturn_t
  10885. lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
  10886. {
  10887. struct lpfc_hba *phba;
  10888. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  10889. struct lpfc_queue *fpeq;
  10890. struct lpfc_eqe *eqe;
  10891. unsigned long iflag;
  10892. int ecount = 0;
  10893. int fcp_eqidx;
  10894. /* Get the driver's phba structure from the dev_id */
  10895. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  10896. phba = fcp_eq_hdl->phba;
  10897. fcp_eqidx = fcp_eq_hdl->idx;
  10898. if (unlikely(!phba))
  10899. return IRQ_NONE;
  10900. if (unlikely(!phba->sli4_hba.hba_eq))
  10901. return IRQ_NONE;
  10902. /* Get to the EQ struct associated with this vector */
  10903. fpeq = phba->sli4_hba.hba_eq[fcp_eqidx];
  10904. if (unlikely(!fpeq))
  10905. return IRQ_NONE;
  10906. if (lpfc_fcp_look_ahead) {
  10907. if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use))
  10908. lpfc_sli4_eq_clr_intr(fpeq);
  10909. else {
  10910. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10911. return IRQ_NONE;
  10912. }
  10913. }
  10914. /* Check device state for handling interrupt */
  10915. if (unlikely(lpfc_intr_state_check(phba))) {
  10916. fpeq->EQ_badstate++;
  10917. /* Check again for link_state with lock held */
  10918. spin_lock_irqsave(&phba->hbalock, iflag);
  10919. if (phba->link_state < LPFC_LINK_DOWN)
  10920. /* Flush, clear interrupt, and rearm the EQ */
  10921. lpfc_sli4_eq_flush(phba, fpeq);
  10922. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10923. if (lpfc_fcp_look_ahead)
  10924. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10925. return IRQ_NONE;
  10926. }
  10927. /*
  10928. * Process all the event on FCP fast-path EQ
  10929. */
  10930. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  10931. lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx);
  10932. if (!(++ecount % fpeq->entry_repost))
  10933. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  10934. fpeq->EQ_processed++;
  10935. }
  10936. /* Track the max number of EQEs processed in 1 intr */
  10937. if (ecount > fpeq->EQ_max_eqe)
  10938. fpeq->EQ_max_eqe = ecount;
  10939. /* Always clear and re-arm the fast-path EQ */
  10940. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  10941. if (unlikely(ecount == 0)) {
  10942. fpeq->EQ_no_entry++;
  10943. if (lpfc_fcp_look_ahead) {
  10944. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10945. return IRQ_NONE;
  10946. }
  10947. if (phba->intr_type == MSIX)
  10948. /* MSI-X treated interrupt served as no EQ share INT */
  10949. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10950. "0358 MSI-X interrupt with no EQE\n");
  10951. else
  10952. /* Non MSI-X treated on interrupt as EQ share INT */
  10953. return IRQ_NONE;
  10954. }
  10955. if (lpfc_fcp_look_ahead)
  10956. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10957. return IRQ_HANDLED;
  10958. } /* lpfc_sli4_fp_intr_handler */
  10959. /**
  10960. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  10961. * @irq: Interrupt number.
  10962. * @dev_id: The device context pointer.
  10963. *
  10964. * This function is the device-level interrupt handler to device with SLI-4
  10965. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  10966. * interrupt mode is enabled and there is an event in the HBA which requires
  10967. * driver attention. This function invokes the slow-path interrupt attention
  10968. * handling function and fast-path interrupt attention handling function in
  10969. * turn to process the relevant HBA attention events. This function is called
  10970. * without any lock held. It gets the hbalock to access and update SLI data
  10971. * structures.
  10972. *
  10973. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10974. * returns IRQ_NONE.
  10975. **/
  10976. irqreturn_t
  10977. lpfc_sli4_intr_handler(int irq, void *dev_id)
  10978. {
  10979. struct lpfc_hba *phba;
  10980. irqreturn_t hba_irq_rc;
  10981. bool hba_handled = false;
  10982. int fcp_eqidx;
  10983. /* Get the driver's phba structure from the dev_id */
  10984. phba = (struct lpfc_hba *)dev_id;
  10985. if (unlikely(!phba))
  10986. return IRQ_NONE;
  10987. /*
  10988. * Invoke fast-path host attention interrupt handling as appropriate.
  10989. */
  10990. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
  10991. hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
  10992. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  10993. if (hba_irq_rc == IRQ_HANDLED)
  10994. hba_handled |= true;
  10995. }
  10996. return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
  10997. } /* lpfc_sli4_intr_handler */
  10998. /**
  10999. * lpfc_sli4_queue_free - free a queue structure and associated memory
  11000. * @queue: The queue structure to free.
  11001. *
  11002. * This function frees a queue structure and the DMAable memory used for
  11003. * the host resident queue. This function must be called after destroying the
  11004. * queue on the HBA.
  11005. **/
  11006. void
  11007. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  11008. {
  11009. struct lpfc_dmabuf *dmabuf;
  11010. if (!queue)
  11011. return;
  11012. while (!list_empty(&queue->page_list)) {
  11013. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  11014. list);
  11015. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  11016. dmabuf->virt, dmabuf->phys);
  11017. kfree(dmabuf);
  11018. }
  11019. kfree(queue);
  11020. return;
  11021. }
  11022. /**
  11023. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  11024. * @phba: The HBA that this queue is being created on.
  11025. * @entry_size: The size of each queue entry for this queue.
  11026. * @entry count: The number of entries that this queue will handle.
  11027. *
  11028. * This function allocates a queue structure and the DMAable memory used for
  11029. * the host resident queue. This function must be called before creating the
  11030. * queue on the HBA.
  11031. **/
  11032. struct lpfc_queue *
  11033. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  11034. uint32_t entry_count)
  11035. {
  11036. struct lpfc_queue *queue;
  11037. struct lpfc_dmabuf *dmabuf;
  11038. int x, total_qe_count;
  11039. void *dma_pointer;
  11040. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11041. if (!phba->sli4_hba.pc_sli4_params.supported)
  11042. hw_page_size = SLI4_PAGE_SIZE;
  11043. queue = kzalloc(sizeof(struct lpfc_queue) +
  11044. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  11045. if (!queue)
  11046. return NULL;
  11047. queue->page_count = (ALIGN(entry_size * entry_count,
  11048. hw_page_size))/hw_page_size;
  11049. INIT_LIST_HEAD(&queue->list);
  11050. INIT_LIST_HEAD(&queue->page_list);
  11051. INIT_LIST_HEAD(&queue->child_list);
  11052. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  11053. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  11054. if (!dmabuf)
  11055. goto out_fail;
  11056. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  11057. hw_page_size, &dmabuf->phys,
  11058. GFP_KERNEL);
  11059. if (!dmabuf->virt) {
  11060. kfree(dmabuf);
  11061. goto out_fail;
  11062. }
  11063. memset(dmabuf->virt, 0, hw_page_size);
  11064. dmabuf->buffer_tag = x;
  11065. list_add_tail(&dmabuf->list, &queue->page_list);
  11066. /* initialize queue's entry array */
  11067. dma_pointer = dmabuf->virt;
  11068. for (; total_qe_count < entry_count &&
  11069. dma_pointer < (hw_page_size + dmabuf->virt);
  11070. total_qe_count++, dma_pointer += entry_size) {
  11071. queue->qe[total_qe_count].address = dma_pointer;
  11072. }
  11073. }
  11074. queue->entry_size = entry_size;
  11075. queue->entry_count = entry_count;
  11076. /*
  11077. * entry_repost is calculated based on the number of entries in the
  11078. * queue. This works out except for RQs. If buffers are NOT initially
  11079. * posted for every RQE, entry_repost should be adjusted accordingly.
  11080. */
  11081. queue->entry_repost = (entry_count >> 3);
  11082. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  11083. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  11084. queue->phba = phba;
  11085. return queue;
  11086. out_fail:
  11087. lpfc_sli4_queue_free(queue);
  11088. return NULL;
  11089. }
  11090. /**
  11091. * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
  11092. * @phba: HBA structure that indicates port to create a queue on.
  11093. * @pci_barset: PCI BAR set flag.
  11094. *
  11095. * This function shall perform iomap of the specified PCI BAR address to host
  11096. * memory address if not already done so and return it. The returned host
  11097. * memory address can be NULL.
  11098. */
  11099. static void __iomem *
  11100. lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
  11101. {
  11102. struct pci_dev *pdev;
  11103. unsigned long bar_map, bar_map_len;
  11104. if (!phba->pcidev)
  11105. return NULL;
  11106. else
  11107. pdev = phba->pcidev;
  11108. switch (pci_barset) {
  11109. case WQ_PCI_BAR_0_AND_1:
  11110. if (!phba->pci_bar0_memmap_p) {
  11111. bar_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
  11112. bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
  11113. phba->pci_bar0_memmap_p = ioremap(bar_map, bar_map_len);
  11114. }
  11115. return phba->pci_bar0_memmap_p;
  11116. case WQ_PCI_BAR_2_AND_3:
  11117. if (!phba->pci_bar2_memmap_p) {
  11118. bar_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
  11119. bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
  11120. phba->pci_bar2_memmap_p = ioremap(bar_map, bar_map_len);
  11121. }
  11122. return phba->pci_bar2_memmap_p;
  11123. case WQ_PCI_BAR_4_AND_5:
  11124. if (!phba->pci_bar4_memmap_p) {
  11125. bar_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
  11126. bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
  11127. phba->pci_bar4_memmap_p = ioremap(bar_map, bar_map_len);
  11128. }
  11129. return phba->pci_bar4_memmap_p;
  11130. default:
  11131. break;
  11132. }
  11133. return NULL;
  11134. }
  11135. /**
  11136. * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
  11137. * @phba: HBA structure that indicates port to create a queue on.
  11138. * @startq: The starting FCP EQ to modify
  11139. *
  11140. * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
  11141. *
  11142. * The @phba struct is used to send mailbox command to HBA. The @startq
  11143. * is used to get the starting FCP EQ to change.
  11144. * This function is asynchronous and will wait for the mailbox
  11145. * command to finish before continuing.
  11146. *
  11147. * On success this function will return a zero. If unable to allocate enough
  11148. * memory this function will return -ENOMEM. If the queue create mailbox command
  11149. * fails this function will return -ENXIO.
  11150. **/
  11151. uint32_t
  11152. lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq)
  11153. {
  11154. struct lpfc_mbx_modify_eq_delay *eq_delay;
  11155. LPFC_MBOXQ_t *mbox;
  11156. struct lpfc_queue *eq;
  11157. int cnt, rc, length, status = 0;
  11158. uint32_t shdr_status, shdr_add_status;
  11159. uint32_t result;
  11160. int fcp_eqidx;
  11161. union lpfc_sli4_cfg_shdr *shdr;
  11162. uint16_t dmult;
  11163. if (startq >= phba->cfg_fcp_io_channel)
  11164. return 0;
  11165. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11166. if (!mbox)
  11167. return -ENOMEM;
  11168. length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
  11169. sizeof(struct lpfc_sli4_cfg_mhdr));
  11170. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11171. LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
  11172. length, LPFC_SLI4_MBX_EMBED);
  11173. eq_delay = &mbox->u.mqe.un.eq_delay;
  11174. /* Calculate delay multiper from maximum interrupt per second */
  11175. result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel;
  11176. if (result > LPFC_DMULT_CONST)
  11177. dmult = 0;
  11178. else
  11179. dmult = LPFC_DMULT_CONST/result - 1;
  11180. cnt = 0;
  11181. for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel;
  11182. fcp_eqidx++) {
  11183. eq = phba->sli4_hba.hba_eq[fcp_eqidx];
  11184. if (!eq)
  11185. continue;
  11186. eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
  11187. eq_delay->u.request.eq[cnt].phase = 0;
  11188. eq_delay->u.request.eq[cnt].delay_multi = dmult;
  11189. cnt++;
  11190. if (cnt >= LPFC_MAX_EQ_DELAY)
  11191. break;
  11192. }
  11193. eq_delay->u.request.num_eq = cnt;
  11194. mbox->vport = phba->pport;
  11195. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11196. mbox->context1 = NULL;
  11197. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11198. shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
  11199. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11200. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11201. if (shdr_status || shdr_add_status || rc) {
  11202. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11203. "2512 MODIFY_EQ_DELAY mailbox failed with "
  11204. "status x%x add_status x%x, mbx status x%x\n",
  11205. shdr_status, shdr_add_status, rc);
  11206. status = -ENXIO;
  11207. }
  11208. mempool_free(mbox, phba->mbox_mem_pool);
  11209. return status;
  11210. }
  11211. /**
  11212. * lpfc_eq_create - Create an Event Queue on the HBA
  11213. * @phba: HBA structure that indicates port to create a queue on.
  11214. * @eq: The queue structure to use to create the event queue.
  11215. * @imax: The maximum interrupt per second limit.
  11216. *
  11217. * This function creates an event queue, as detailed in @eq, on a port,
  11218. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  11219. *
  11220. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  11221. * is used to get the entry count and entry size that are necessary to
  11222. * determine the number of pages to allocate and use for this queue. This
  11223. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  11224. * event queue. This function is asynchronous and will wait for the mailbox
  11225. * command to finish before continuing.
  11226. *
  11227. * On success this function will return a zero. If unable to allocate enough
  11228. * memory this function will return -ENOMEM. If the queue create mailbox command
  11229. * fails this function will return -ENXIO.
  11230. **/
  11231. uint32_t
  11232. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
  11233. {
  11234. struct lpfc_mbx_eq_create *eq_create;
  11235. LPFC_MBOXQ_t *mbox;
  11236. int rc, length, status = 0;
  11237. struct lpfc_dmabuf *dmabuf;
  11238. uint32_t shdr_status, shdr_add_status;
  11239. union lpfc_sli4_cfg_shdr *shdr;
  11240. uint16_t dmult;
  11241. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11242. /* sanity check on queue memory */
  11243. if (!eq)
  11244. return -ENODEV;
  11245. if (!phba->sli4_hba.pc_sli4_params.supported)
  11246. hw_page_size = SLI4_PAGE_SIZE;
  11247. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11248. if (!mbox)
  11249. return -ENOMEM;
  11250. length = (sizeof(struct lpfc_mbx_eq_create) -
  11251. sizeof(struct lpfc_sli4_cfg_mhdr));
  11252. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11253. LPFC_MBOX_OPCODE_EQ_CREATE,
  11254. length, LPFC_SLI4_MBX_EMBED);
  11255. eq_create = &mbox->u.mqe.un.eq_create;
  11256. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  11257. eq->page_count);
  11258. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  11259. LPFC_EQE_SIZE);
  11260. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  11261. /* Calculate delay multiper from maximum interrupt per second */
  11262. if (imax > LPFC_DMULT_CONST)
  11263. dmult = 0;
  11264. else
  11265. dmult = LPFC_DMULT_CONST/imax - 1;
  11266. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  11267. dmult);
  11268. switch (eq->entry_count) {
  11269. default:
  11270. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11271. "0360 Unsupported EQ count. (%d)\n",
  11272. eq->entry_count);
  11273. if (eq->entry_count < 256)
  11274. return -EINVAL;
  11275. /* otherwise default to smallest count (drop through) */
  11276. case 256:
  11277. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11278. LPFC_EQ_CNT_256);
  11279. break;
  11280. case 512:
  11281. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11282. LPFC_EQ_CNT_512);
  11283. break;
  11284. case 1024:
  11285. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11286. LPFC_EQ_CNT_1024);
  11287. break;
  11288. case 2048:
  11289. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11290. LPFC_EQ_CNT_2048);
  11291. break;
  11292. case 4096:
  11293. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11294. LPFC_EQ_CNT_4096);
  11295. break;
  11296. }
  11297. list_for_each_entry(dmabuf, &eq->page_list, list) {
  11298. memset(dmabuf->virt, 0, hw_page_size);
  11299. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11300. putPaddrLow(dmabuf->phys);
  11301. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11302. putPaddrHigh(dmabuf->phys);
  11303. }
  11304. mbox->vport = phba->pport;
  11305. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11306. mbox->context1 = NULL;
  11307. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11308. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  11309. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11310. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11311. if (shdr_status || shdr_add_status || rc) {
  11312. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11313. "2500 EQ_CREATE mailbox failed with "
  11314. "status x%x add_status x%x, mbx status x%x\n",
  11315. shdr_status, shdr_add_status, rc);
  11316. status = -ENXIO;
  11317. }
  11318. eq->type = LPFC_EQ;
  11319. eq->subtype = LPFC_NONE;
  11320. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  11321. if (eq->queue_id == 0xFFFF)
  11322. status = -ENXIO;
  11323. eq->host_index = 0;
  11324. eq->hba_index = 0;
  11325. mempool_free(mbox, phba->mbox_mem_pool);
  11326. return status;
  11327. }
  11328. /**
  11329. * lpfc_cq_create - Create a Completion Queue on the HBA
  11330. * @phba: HBA structure that indicates port to create a queue on.
  11331. * @cq: The queue structure to use to create the completion queue.
  11332. * @eq: The event queue to bind this completion queue to.
  11333. *
  11334. * This function creates a completion queue, as detailed in @wq, on a port,
  11335. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  11336. *
  11337. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11338. * is used to get the entry count and entry size that are necessary to
  11339. * determine the number of pages to allocate and use for this queue. The @eq
  11340. * is used to indicate which event queue to bind this completion queue to. This
  11341. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  11342. * completion queue. This function is asynchronous and will wait for the mailbox
  11343. * command to finish before continuing.
  11344. *
  11345. * On success this function will return a zero. If unable to allocate enough
  11346. * memory this function will return -ENOMEM. If the queue create mailbox command
  11347. * fails this function will return -ENXIO.
  11348. **/
  11349. uint32_t
  11350. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11351. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  11352. {
  11353. struct lpfc_mbx_cq_create *cq_create;
  11354. struct lpfc_dmabuf *dmabuf;
  11355. LPFC_MBOXQ_t *mbox;
  11356. int rc, length, status = 0;
  11357. uint32_t shdr_status, shdr_add_status;
  11358. union lpfc_sli4_cfg_shdr *shdr;
  11359. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11360. /* sanity check on queue memory */
  11361. if (!cq || !eq)
  11362. return -ENODEV;
  11363. if (!phba->sli4_hba.pc_sli4_params.supported)
  11364. hw_page_size = SLI4_PAGE_SIZE;
  11365. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11366. if (!mbox)
  11367. return -ENOMEM;
  11368. length = (sizeof(struct lpfc_mbx_cq_create) -
  11369. sizeof(struct lpfc_sli4_cfg_mhdr));
  11370. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11371. LPFC_MBOX_OPCODE_CQ_CREATE,
  11372. length, LPFC_SLI4_MBX_EMBED);
  11373. cq_create = &mbox->u.mqe.un.cq_create;
  11374. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  11375. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  11376. cq->page_count);
  11377. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  11378. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  11379. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11380. phba->sli4_hba.pc_sli4_params.cqv);
  11381. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  11382. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  11383. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  11384. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  11385. eq->queue_id);
  11386. } else {
  11387. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  11388. eq->queue_id);
  11389. }
  11390. switch (cq->entry_count) {
  11391. default:
  11392. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11393. "0361 Unsupported CQ count. (%d)\n",
  11394. cq->entry_count);
  11395. if (cq->entry_count < 256) {
  11396. status = -EINVAL;
  11397. goto out;
  11398. }
  11399. /* otherwise default to smallest count (drop through) */
  11400. case 256:
  11401. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11402. LPFC_CQ_CNT_256);
  11403. break;
  11404. case 512:
  11405. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11406. LPFC_CQ_CNT_512);
  11407. break;
  11408. case 1024:
  11409. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11410. LPFC_CQ_CNT_1024);
  11411. break;
  11412. }
  11413. list_for_each_entry(dmabuf, &cq->page_list, list) {
  11414. memset(dmabuf->virt, 0, hw_page_size);
  11415. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11416. putPaddrLow(dmabuf->phys);
  11417. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11418. putPaddrHigh(dmabuf->phys);
  11419. }
  11420. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11421. /* The IOCTL status is embedded in the mailbox subheader. */
  11422. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11423. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11424. if (shdr_status || shdr_add_status || rc) {
  11425. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11426. "2501 CQ_CREATE mailbox failed with "
  11427. "status x%x add_status x%x, mbx status x%x\n",
  11428. shdr_status, shdr_add_status, rc);
  11429. status = -ENXIO;
  11430. goto out;
  11431. }
  11432. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11433. if (cq->queue_id == 0xFFFF) {
  11434. status = -ENXIO;
  11435. goto out;
  11436. }
  11437. /* link the cq onto the parent eq child list */
  11438. list_add_tail(&cq->list, &eq->child_list);
  11439. /* Set up completion queue's type and subtype */
  11440. cq->type = type;
  11441. cq->subtype = subtype;
  11442. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11443. cq->assoc_qid = eq->queue_id;
  11444. cq->host_index = 0;
  11445. cq->hba_index = 0;
  11446. out:
  11447. mempool_free(mbox, phba->mbox_mem_pool);
  11448. return status;
  11449. }
  11450. /**
  11451. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  11452. * @phba: HBA structure that indicates port to create a queue on.
  11453. * @mq: The queue structure to use to create the mailbox queue.
  11454. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  11455. * @cq: The completion queue to associate with this cq.
  11456. *
  11457. * This function provides failback (fb) functionality when the
  11458. * mq_create_ext fails on older FW generations. It's purpose is identical
  11459. * to mq_create_ext otherwise.
  11460. *
  11461. * This routine cannot fail as all attributes were previously accessed and
  11462. * initialized in mq_create_ext.
  11463. **/
  11464. static void
  11465. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11466. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  11467. {
  11468. struct lpfc_mbx_mq_create *mq_create;
  11469. struct lpfc_dmabuf *dmabuf;
  11470. int length;
  11471. length = (sizeof(struct lpfc_mbx_mq_create) -
  11472. sizeof(struct lpfc_sli4_cfg_mhdr));
  11473. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11474. LPFC_MBOX_OPCODE_MQ_CREATE,
  11475. length, LPFC_SLI4_MBX_EMBED);
  11476. mq_create = &mbox->u.mqe.un.mq_create;
  11477. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  11478. mq->page_count);
  11479. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  11480. cq->queue_id);
  11481. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  11482. switch (mq->entry_count) {
  11483. case 16:
  11484. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11485. LPFC_MQ_RING_SIZE_16);
  11486. break;
  11487. case 32:
  11488. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11489. LPFC_MQ_RING_SIZE_32);
  11490. break;
  11491. case 64:
  11492. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11493. LPFC_MQ_RING_SIZE_64);
  11494. break;
  11495. case 128:
  11496. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11497. LPFC_MQ_RING_SIZE_128);
  11498. break;
  11499. }
  11500. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11501. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11502. putPaddrLow(dmabuf->phys);
  11503. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11504. putPaddrHigh(dmabuf->phys);
  11505. }
  11506. }
  11507. /**
  11508. * lpfc_mq_create - Create a mailbox Queue on the HBA
  11509. * @phba: HBA structure that indicates port to create a queue on.
  11510. * @mq: The queue structure to use to create the mailbox queue.
  11511. * @cq: The completion queue to associate with this cq.
  11512. * @subtype: The queue's subtype.
  11513. *
  11514. * This function creates a mailbox queue, as detailed in @mq, on a port,
  11515. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  11516. *
  11517. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11518. * is used to get the entry count and entry size that are necessary to
  11519. * determine the number of pages to allocate and use for this queue. This
  11520. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  11521. * mailbox queue. This function is asynchronous and will wait for the mailbox
  11522. * command to finish before continuing.
  11523. *
  11524. * On success this function will return a zero. If unable to allocate enough
  11525. * memory this function will return -ENOMEM. If the queue create mailbox command
  11526. * fails this function will return -ENXIO.
  11527. **/
  11528. int32_t
  11529. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11530. struct lpfc_queue *cq, uint32_t subtype)
  11531. {
  11532. struct lpfc_mbx_mq_create *mq_create;
  11533. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  11534. struct lpfc_dmabuf *dmabuf;
  11535. LPFC_MBOXQ_t *mbox;
  11536. int rc, length, status = 0;
  11537. uint32_t shdr_status, shdr_add_status;
  11538. union lpfc_sli4_cfg_shdr *shdr;
  11539. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11540. /* sanity check on queue memory */
  11541. if (!mq || !cq)
  11542. return -ENODEV;
  11543. if (!phba->sli4_hba.pc_sli4_params.supported)
  11544. hw_page_size = SLI4_PAGE_SIZE;
  11545. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11546. if (!mbox)
  11547. return -ENOMEM;
  11548. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  11549. sizeof(struct lpfc_sli4_cfg_mhdr));
  11550. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11551. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  11552. length, LPFC_SLI4_MBX_EMBED);
  11553. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  11554. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  11555. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  11556. &mq_create_ext->u.request, mq->page_count);
  11557. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  11558. &mq_create_ext->u.request, 1);
  11559. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  11560. &mq_create_ext->u.request, 1);
  11561. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  11562. &mq_create_ext->u.request, 1);
  11563. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  11564. &mq_create_ext->u.request, 1);
  11565. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  11566. &mq_create_ext->u.request, 1);
  11567. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  11568. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11569. phba->sli4_hba.pc_sli4_params.mqv);
  11570. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  11571. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  11572. cq->queue_id);
  11573. else
  11574. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  11575. cq->queue_id);
  11576. switch (mq->entry_count) {
  11577. default:
  11578. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11579. "0362 Unsupported MQ count. (%d)\n",
  11580. mq->entry_count);
  11581. if (mq->entry_count < 16) {
  11582. status = -EINVAL;
  11583. goto out;
  11584. }
  11585. /* otherwise default to smallest count (drop through) */
  11586. case 16:
  11587. bf_set(lpfc_mq_context_ring_size,
  11588. &mq_create_ext->u.request.context,
  11589. LPFC_MQ_RING_SIZE_16);
  11590. break;
  11591. case 32:
  11592. bf_set(lpfc_mq_context_ring_size,
  11593. &mq_create_ext->u.request.context,
  11594. LPFC_MQ_RING_SIZE_32);
  11595. break;
  11596. case 64:
  11597. bf_set(lpfc_mq_context_ring_size,
  11598. &mq_create_ext->u.request.context,
  11599. LPFC_MQ_RING_SIZE_64);
  11600. break;
  11601. case 128:
  11602. bf_set(lpfc_mq_context_ring_size,
  11603. &mq_create_ext->u.request.context,
  11604. LPFC_MQ_RING_SIZE_128);
  11605. break;
  11606. }
  11607. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11608. memset(dmabuf->virt, 0, hw_page_size);
  11609. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  11610. putPaddrLow(dmabuf->phys);
  11611. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  11612. putPaddrHigh(dmabuf->phys);
  11613. }
  11614. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11615. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11616. &mq_create_ext->u.response);
  11617. if (rc != MBX_SUCCESS) {
  11618. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11619. "2795 MQ_CREATE_EXT failed with "
  11620. "status x%x. Failback to MQ_CREATE.\n",
  11621. rc);
  11622. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  11623. mq_create = &mbox->u.mqe.un.mq_create;
  11624. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11625. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  11626. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11627. &mq_create->u.response);
  11628. }
  11629. /* The IOCTL status is embedded in the mailbox subheader. */
  11630. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11631. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11632. if (shdr_status || shdr_add_status || rc) {
  11633. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11634. "2502 MQ_CREATE mailbox failed with "
  11635. "status x%x add_status x%x, mbx status x%x\n",
  11636. shdr_status, shdr_add_status, rc);
  11637. status = -ENXIO;
  11638. goto out;
  11639. }
  11640. if (mq->queue_id == 0xFFFF) {
  11641. status = -ENXIO;
  11642. goto out;
  11643. }
  11644. mq->type = LPFC_MQ;
  11645. mq->assoc_qid = cq->queue_id;
  11646. mq->subtype = subtype;
  11647. mq->host_index = 0;
  11648. mq->hba_index = 0;
  11649. /* link the mq onto the parent cq child list */
  11650. list_add_tail(&mq->list, &cq->child_list);
  11651. out:
  11652. mempool_free(mbox, phba->mbox_mem_pool);
  11653. return status;
  11654. }
  11655. /**
  11656. * lpfc_wq_create - Create a Work Queue on the HBA
  11657. * @phba: HBA structure that indicates port to create a queue on.
  11658. * @wq: The queue structure to use to create the work queue.
  11659. * @cq: The completion queue to bind this work queue to.
  11660. * @subtype: The subtype of the work queue indicating its functionality.
  11661. *
  11662. * This function creates a work queue, as detailed in @wq, on a port, described
  11663. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  11664. *
  11665. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  11666. * is used to get the entry count and entry size that are necessary to
  11667. * determine the number of pages to allocate and use for this queue. The @cq
  11668. * is used to indicate which completion queue to bind this work queue to. This
  11669. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  11670. * work queue. This function is asynchronous and will wait for the mailbox
  11671. * command to finish before continuing.
  11672. *
  11673. * On success this function will return a zero. If unable to allocate enough
  11674. * memory this function will return -ENOMEM. If the queue create mailbox command
  11675. * fails this function will return -ENXIO.
  11676. **/
  11677. uint32_t
  11678. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  11679. struct lpfc_queue *cq, uint32_t subtype)
  11680. {
  11681. struct lpfc_mbx_wq_create *wq_create;
  11682. struct lpfc_dmabuf *dmabuf;
  11683. LPFC_MBOXQ_t *mbox;
  11684. int rc, length, status = 0;
  11685. uint32_t shdr_status, shdr_add_status;
  11686. union lpfc_sli4_cfg_shdr *shdr;
  11687. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11688. struct dma_address *page;
  11689. void __iomem *bar_memmap_p;
  11690. uint32_t db_offset;
  11691. uint16_t pci_barset;
  11692. /* sanity check on queue memory */
  11693. if (!wq || !cq)
  11694. return -ENODEV;
  11695. if (!phba->sli4_hba.pc_sli4_params.supported)
  11696. hw_page_size = SLI4_PAGE_SIZE;
  11697. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11698. if (!mbox)
  11699. return -ENOMEM;
  11700. length = (sizeof(struct lpfc_mbx_wq_create) -
  11701. sizeof(struct lpfc_sli4_cfg_mhdr));
  11702. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11703. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  11704. length, LPFC_SLI4_MBX_EMBED);
  11705. wq_create = &mbox->u.mqe.un.wq_create;
  11706. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  11707. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  11708. wq->page_count);
  11709. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  11710. cq->queue_id);
  11711. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11712. phba->sli4_hba.pc_sli4_params.wqv);
  11713. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  11714. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  11715. wq->entry_count);
  11716. switch (wq->entry_size) {
  11717. default:
  11718. case 64:
  11719. bf_set(lpfc_mbx_wq_create_wqe_size,
  11720. &wq_create->u.request_1,
  11721. LPFC_WQ_WQE_SIZE_64);
  11722. break;
  11723. case 128:
  11724. bf_set(lpfc_mbx_wq_create_wqe_size,
  11725. &wq_create->u.request_1,
  11726. LPFC_WQ_WQE_SIZE_128);
  11727. break;
  11728. }
  11729. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  11730. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11731. page = wq_create->u.request_1.page;
  11732. } else {
  11733. page = wq_create->u.request.page;
  11734. }
  11735. list_for_each_entry(dmabuf, &wq->page_list, list) {
  11736. memset(dmabuf->virt, 0, hw_page_size);
  11737. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  11738. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  11739. }
  11740. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  11741. bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
  11742. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11743. /* The IOCTL status is embedded in the mailbox subheader. */
  11744. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11745. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11746. if (shdr_status || shdr_add_status || rc) {
  11747. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11748. "2503 WQ_CREATE mailbox failed with "
  11749. "status x%x add_status x%x, mbx status x%x\n",
  11750. shdr_status, shdr_add_status, rc);
  11751. status = -ENXIO;
  11752. goto out;
  11753. }
  11754. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  11755. if (wq->queue_id == 0xFFFF) {
  11756. status = -ENXIO;
  11757. goto out;
  11758. }
  11759. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  11760. wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
  11761. &wq_create->u.response);
  11762. if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
  11763. (wq->db_format != LPFC_DB_RING_FORMAT)) {
  11764. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11765. "3265 WQ[%d] doorbell format not "
  11766. "supported: x%x\n", wq->queue_id,
  11767. wq->db_format);
  11768. status = -EINVAL;
  11769. goto out;
  11770. }
  11771. pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
  11772. &wq_create->u.response);
  11773. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  11774. if (!bar_memmap_p) {
  11775. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11776. "3263 WQ[%d] failed to memmap pci "
  11777. "barset:x%x\n", wq->queue_id,
  11778. pci_barset);
  11779. status = -ENOMEM;
  11780. goto out;
  11781. }
  11782. db_offset = wq_create->u.response.doorbell_offset;
  11783. if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
  11784. (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
  11785. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11786. "3252 WQ[%d] doorbell offset not "
  11787. "supported: x%x\n", wq->queue_id,
  11788. db_offset);
  11789. status = -EINVAL;
  11790. goto out;
  11791. }
  11792. wq->db_regaddr = bar_memmap_p + db_offset;
  11793. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11794. "3264 WQ[%d]: barset:x%x, offset:x%x, "
  11795. "format:x%x\n", wq->queue_id, pci_barset,
  11796. db_offset, wq->db_format);
  11797. } else {
  11798. wq->db_format = LPFC_DB_LIST_FORMAT;
  11799. wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
  11800. }
  11801. wq->type = LPFC_WQ;
  11802. wq->assoc_qid = cq->queue_id;
  11803. wq->subtype = subtype;
  11804. wq->host_index = 0;
  11805. wq->hba_index = 0;
  11806. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  11807. /* link the wq onto the parent cq child list */
  11808. list_add_tail(&wq->list, &cq->child_list);
  11809. out:
  11810. mempool_free(mbox, phba->mbox_mem_pool);
  11811. return status;
  11812. }
  11813. /**
  11814. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  11815. * @phba: HBA structure that indicates port to create a queue on.
  11816. * @rq: The queue structure to use for the receive queue.
  11817. * @qno: The associated HBQ number
  11818. *
  11819. *
  11820. * For SLI4 we need to adjust the RQ repost value based on
  11821. * the number of buffers that are initially posted to the RQ.
  11822. */
  11823. void
  11824. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  11825. {
  11826. uint32_t cnt;
  11827. /* sanity check on queue memory */
  11828. if (!rq)
  11829. return;
  11830. cnt = lpfc_hbq_defs[qno]->entry_count;
  11831. /* Recalc repost for RQs based on buffers initially posted */
  11832. cnt = (cnt >> 3);
  11833. if (cnt < LPFC_QUEUE_MIN_REPOST)
  11834. cnt = LPFC_QUEUE_MIN_REPOST;
  11835. rq->entry_repost = cnt;
  11836. }
  11837. /**
  11838. * lpfc_rq_create - Create a Receive Queue on the HBA
  11839. * @phba: HBA structure that indicates port to create a queue on.
  11840. * @hrq: The queue structure to use to create the header receive queue.
  11841. * @drq: The queue structure to use to create the data receive queue.
  11842. * @cq: The completion queue to bind this work queue to.
  11843. *
  11844. * This function creates a receive buffer queue pair , as detailed in @hrq and
  11845. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  11846. * to the HBA.
  11847. *
  11848. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  11849. * struct is used to get the entry count that is necessary to determine the
  11850. * number of pages to use for this queue. The @cq is used to indicate which
  11851. * completion queue to bind received buffers that are posted to these queues to.
  11852. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  11853. * receive queue pair. This function is asynchronous and will wait for the
  11854. * mailbox command to finish before continuing.
  11855. *
  11856. * On success this function will return a zero. If unable to allocate enough
  11857. * memory this function will return -ENOMEM. If the queue create mailbox command
  11858. * fails this function will return -ENXIO.
  11859. **/
  11860. uint32_t
  11861. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11862. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  11863. {
  11864. struct lpfc_mbx_rq_create *rq_create;
  11865. struct lpfc_dmabuf *dmabuf;
  11866. LPFC_MBOXQ_t *mbox;
  11867. int rc, length, status = 0;
  11868. uint32_t shdr_status, shdr_add_status;
  11869. union lpfc_sli4_cfg_shdr *shdr;
  11870. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11871. void __iomem *bar_memmap_p;
  11872. uint32_t db_offset;
  11873. uint16_t pci_barset;
  11874. /* sanity check on queue memory */
  11875. if (!hrq || !drq || !cq)
  11876. return -ENODEV;
  11877. if (!phba->sli4_hba.pc_sli4_params.supported)
  11878. hw_page_size = SLI4_PAGE_SIZE;
  11879. if (hrq->entry_count != drq->entry_count)
  11880. return -EINVAL;
  11881. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11882. if (!mbox)
  11883. return -ENOMEM;
  11884. length = (sizeof(struct lpfc_mbx_rq_create) -
  11885. sizeof(struct lpfc_sli4_cfg_mhdr));
  11886. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11887. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11888. length, LPFC_SLI4_MBX_EMBED);
  11889. rq_create = &mbox->u.mqe.un.rq_create;
  11890. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11891. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11892. phba->sli4_hba.pc_sli4_params.rqv);
  11893. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11894. bf_set(lpfc_rq_context_rqe_count_1,
  11895. &rq_create->u.request.context,
  11896. hrq->entry_count);
  11897. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  11898. bf_set(lpfc_rq_context_rqe_size,
  11899. &rq_create->u.request.context,
  11900. LPFC_RQE_SIZE_8);
  11901. bf_set(lpfc_rq_context_page_size,
  11902. &rq_create->u.request.context,
  11903. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11904. } else {
  11905. switch (hrq->entry_count) {
  11906. default:
  11907. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11908. "2535 Unsupported RQ count. (%d)\n",
  11909. hrq->entry_count);
  11910. if (hrq->entry_count < 512) {
  11911. status = -EINVAL;
  11912. goto out;
  11913. }
  11914. /* otherwise default to smallest count (drop through) */
  11915. case 512:
  11916. bf_set(lpfc_rq_context_rqe_count,
  11917. &rq_create->u.request.context,
  11918. LPFC_RQ_RING_SIZE_512);
  11919. break;
  11920. case 1024:
  11921. bf_set(lpfc_rq_context_rqe_count,
  11922. &rq_create->u.request.context,
  11923. LPFC_RQ_RING_SIZE_1024);
  11924. break;
  11925. case 2048:
  11926. bf_set(lpfc_rq_context_rqe_count,
  11927. &rq_create->u.request.context,
  11928. LPFC_RQ_RING_SIZE_2048);
  11929. break;
  11930. case 4096:
  11931. bf_set(lpfc_rq_context_rqe_count,
  11932. &rq_create->u.request.context,
  11933. LPFC_RQ_RING_SIZE_4096);
  11934. break;
  11935. }
  11936. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11937. LPFC_HDR_BUF_SIZE);
  11938. }
  11939. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11940. cq->queue_id);
  11941. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11942. hrq->page_count);
  11943. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  11944. memset(dmabuf->virt, 0, hw_page_size);
  11945. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11946. putPaddrLow(dmabuf->phys);
  11947. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11948. putPaddrHigh(dmabuf->phys);
  11949. }
  11950. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  11951. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  11952. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11953. /* The IOCTL status is embedded in the mailbox subheader. */
  11954. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11955. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11956. if (shdr_status || shdr_add_status || rc) {
  11957. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11958. "2504 RQ_CREATE mailbox failed with "
  11959. "status x%x add_status x%x, mbx status x%x\n",
  11960. shdr_status, shdr_add_status, rc);
  11961. status = -ENXIO;
  11962. goto out;
  11963. }
  11964. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11965. if (hrq->queue_id == 0xFFFF) {
  11966. status = -ENXIO;
  11967. goto out;
  11968. }
  11969. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  11970. hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
  11971. &rq_create->u.response);
  11972. if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
  11973. (hrq->db_format != LPFC_DB_RING_FORMAT)) {
  11974. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11975. "3262 RQ [%d] doorbell format not "
  11976. "supported: x%x\n", hrq->queue_id,
  11977. hrq->db_format);
  11978. status = -EINVAL;
  11979. goto out;
  11980. }
  11981. pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
  11982. &rq_create->u.response);
  11983. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  11984. if (!bar_memmap_p) {
  11985. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11986. "3269 RQ[%d] failed to memmap pci "
  11987. "barset:x%x\n", hrq->queue_id,
  11988. pci_barset);
  11989. status = -ENOMEM;
  11990. goto out;
  11991. }
  11992. db_offset = rq_create->u.response.doorbell_offset;
  11993. if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
  11994. (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
  11995. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11996. "3270 RQ[%d] doorbell offset not "
  11997. "supported: x%x\n", hrq->queue_id,
  11998. db_offset);
  11999. status = -EINVAL;
  12000. goto out;
  12001. }
  12002. hrq->db_regaddr = bar_memmap_p + db_offset;
  12003. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12004. "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
  12005. "format:x%x\n", hrq->queue_id, pci_barset,
  12006. db_offset, hrq->db_format);
  12007. } else {
  12008. hrq->db_format = LPFC_DB_RING_FORMAT;
  12009. hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
  12010. }
  12011. hrq->type = LPFC_HRQ;
  12012. hrq->assoc_qid = cq->queue_id;
  12013. hrq->subtype = subtype;
  12014. hrq->host_index = 0;
  12015. hrq->hba_index = 0;
  12016. /* now create the data queue */
  12017. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12018. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  12019. length, LPFC_SLI4_MBX_EMBED);
  12020. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12021. phba->sli4_hba.pc_sli4_params.rqv);
  12022. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  12023. bf_set(lpfc_rq_context_rqe_count_1,
  12024. &rq_create->u.request.context, hrq->entry_count);
  12025. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  12026. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  12027. LPFC_RQE_SIZE_8);
  12028. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  12029. (PAGE_SIZE/SLI4_PAGE_SIZE));
  12030. } else {
  12031. switch (drq->entry_count) {
  12032. default:
  12033. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12034. "2536 Unsupported RQ count. (%d)\n",
  12035. drq->entry_count);
  12036. if (drq->entry_count < 512) {
  12037. status = -EINVAL;
  12038. goto out;
  12039. }
  12040. /* otherwise default to smallest count (drop through) */
  12041. case 512:
  12042. bf_set(lpfc_rq_context_rqe_count,
  12043. &rq_create->u.request.context,
  12044. LPFC_RQ_RING_SIZE_512);
  12045. break;
  12046. case 1024:
  12047. bf_set(lpfc_rq_context_rqe_count,
  12048. &rq_create->u.request.context,
  12049. LPFC_RQ_RING_SIZE_1024);
  12050. break;
  12051. case 2048:
  12052. bf_set(lpfc_rq_context_rqe_count,
  12053. &rq_create->u.request.context,
  12054. LPFC_RQ_RING_SIZE_2048);
  12055. break;
  12056. case 4096:
  12057. bf_set(lpfc_rq_context_rqe_count,
  12058. &rq_create->u.request.context,
  12059. LPFC_RQ_RING_SIZE_4096);
  12060. break;
  12061. }
  12062. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  12063. LPFC_DATA_BUF_SIZE);
  12064. }
  12065. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  12066. cq->queue_id);
  12067. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  12068. drq->page_count);
  12069. list_for_each_entry(dmabuf, &drq->page_list, list) {
  12070. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12071. putPaddrLow(dmabuf->phys);
  12072. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12073. putPaddrHigh(dmabuf->phys);
  12074. }
  12075. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12076. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  12077. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12078. /* The IOCTL status is embedded in the mailbox subheader. */
  12079. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  12080. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12081. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12082. if (shdr_status || shdr_add_status || rc) {
  12083. status = -ENXIO;
  12084. goto out;
  12085. }
  12086. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  12087. if (drq->queue_id == 0xFFFF) {
  12088. status = -ENXIO;
  12089. goto out;
  12090. }
  12091. drq->type = LPFC_DRQ;
  12092. drq->assoc_qid = cq->queue_id;
  12093. drq->subtype = subtype;
  12094. drq->host_index = 0;
  12095. drq->hba_index = 0;
  12096. /* link the header and data RQs onto the parent cq child list */
  12097. list_add_tail(&hrq->list, &cq->child_list);
  12098. list_add_tail(&drq->list, &cq->child_list);
  12099. out:
  12100. mempool_free(mbox, phba->mbox_mem_pool);
  12101. return status;
  12102. }
  12103. /**
  12104. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  12105. * @eq: The queue structure associated with the queue to destroy.
  12106. *
  12107. * This function destroys a queue, as detailed in @eq by sending an mailbox
  12108. * command, specific to the type of queue, to the HBA.
  12109. *
  12110. * The @eq struct is used to get the queue ID of the queue to destroy.
  12111. *
  12112. * On success this function will return a zero. If the queue destroy mailbox
  12113. * command fails this function will return -ENXIO.
  12114. **/
  12115. uint32_t
  12116. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  12117. {
  12118. LPFC_MBOXQ_t *mbox;
  12119. int rc, length, status = 0;
  12120. uint32_t shdr_status, shdr_add_status;
  12121. union lpfc_sli4_cfg_shdr *shdr;
  12122. /* sanity check on queue memory */
  12123. if (!eq)
  12124. return -ENODEV;
  12125. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  12126. if (!mbox)
  12127. return -ENOMEM;
  12128. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  12129. sizeof(struct lpfc_sli4_cfg_mhdr));
  12130. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12131. LPFC_MBOX_OPCODE_EQ_DESTROY,
  12132. length, LPFC_SLI4_MBX_EMBED);
  12133. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  12134. eq->queue_id);
  12135. mbox->vport = eq->phba->pport;
  12136. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12137. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  12138. /* The IOCTL status is embedded in the mailbox subheader. */
  12139. shdr = (union lpfc_sli4_cfg_shdr *)
  12140. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  12141. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12142. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12143. if (shdr_status || shdr_add_status || rc) {
  12144. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12145. "2505 EQ_DESTROY mailbox failed with "
  12146. "status x%x add_status x%x, mbx status x%x\n",
  12147. shdr_status, shdr_add_status, rc);
  12148. status = -ENXIO;
  12149. }
  12150. /* Remove eq from any list */
  12151. list_del_init(&eq->list);
  12152. mempool_free(mbox, eq->phba->mbox_mem_pool);
  12153. return status;
  12154. }
  12155. /**
  12156. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  12157. * @cq: The queue structure associated with the queue to destroy.
  12158. *
  12159. * This function destroys a queue, as detailed in @cq by sending an mailbox
  12160. * command, specific to the type of queue, to the HBA.
  12161. *
  12162. * The @cq struct is used to get the queue ID of the queue to destroy.
  12163. *
  12164. * On success this function will return a zero. If the queue destroy mailbox
  12165. * command fails this function will return -ENXIO.
  12166. **/
  12167. uint32_t
  12168. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  12169. {
  12170. LPFC_MBOXQ_t *mbox;
  12171. int rc, length, status = 0;
  12172. uint32_t shdr_status, shdr_add_status;
  12173. union lpfc_sli4_cfg_shdr *shdr;
  12174. /* sanity check on queue memory */
  12175. if (!cq)
  12176. return -ENODEV;
  12177. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  12178. if (!mbox)
  12179. return -ENOMEM;
  12180. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  12181. sizeof(struct lpfc_sli4_cfg_mhdr));
  12182. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12183. LPFC_MBOX_OPCODE_CQ_DESTROY,
  12184. length, LPFC_SLI4_MBX_EMBED);
  12185. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  12186. cq->queue_id);
  12187. mbox->vport = cq->phba->pport;
  12188. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12189. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  12190. /* The IOCTL status is embedded in the mailbox subheader. */
  12191. shdr = (union lpfc_sli4_cfg_shdr *)
  12192. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  12193. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12194. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12195. if (shdr_status || shdr_add_status || rc) {
  12196. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12197. "2506 CQ_DESTROY mailbox failed with "
  12198. "status x%x add_status x%x, mbx status x%x\n",
  12199. shdr_status, shdr_add_status, rc);
  12200. status = -ENXIO;
  12201. }
  12202. /* Remove cq from any list */
  12203. list_del_init(&cq->list);
  12204. mempool_free(mbox, cq->phba->mbox_mem_pool);
  12205. return status;
  12206. }
  12207. /**
  12208. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  12209. * @qm: The queue structure associated with the queue to destroy.
  12210. *
  12211. * This function destroys a queue, as detailed in @mq by sending an mailbox
  12212. * command, specific to the type of queue, to the HBA.
  12213. *
  12214. * The @mq struct is used to get the queue ID of the queue to destroy.
  12215. *
  12216. * On success this function will return a zero. If the queue destroy mailbox
  12217. * command fails this function will return -ENXIO.
  12218. **/
  12219. uint32_t
  12220. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  12221. {
  12222. LPFC_MBOXQ_t *mbox;
  12223. int rc, length, status = 0;
  12224. uint32_t shdr_status, shdr_add_status;
  12225. union lpfc_sli4_cfg_shdr *shdr;
  12226. /* sanity check on queue memory */
  12227. if (!mq)
  12228. return -ENODEV;
  12229. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  12230. if (!mbox)
  12231. return -ENOMEM;
  12232. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  12233. sizeof(struct lpfc_sli4_cfg_mhdr));
  12234. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12235. LPFC_MBOX_OPCODE_MQ_DESTROY,
  12236. length, LPFC_SLI4_MBX_EMBED);
  12237. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  12238. mq->queue_id);
  12239. mbox->vport = mq->phba->pport;
  12240. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12241. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  12242. /* The IOCTL status is embedded in the mailbox subheader. */
  12243. shdr = (union lpfc_sli4_cfg_shdr *)
  12244. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  12245. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12246. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12247. if (shdr_status || shdr_add_status || rc) {
  12248. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12249. "2507 MQ_DESTROY mailbox failed with "
  12250. "status x%x add_status x%x, mbx status x%x\n",
  12251. shdr_status, shdr_add_status, rc);
  12252. status = -ENXIO;
  12253. }
  12254. /* Remove mq from any list */
  12255. list_del_init(&mq->list);
  12256. mempool_free(mbox, mq->phba->mbox_mem_pool);
  12257. return status;
  12258. }
  12259. /**
  12260. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  12261. * @wq: The queue structure associated with the queue to destroy.
  12262. *
  12263. * This function destroys a queue, as detailed in @wq by sending an mailbox
  12264. * command, specific to the type of queue, to the HBA.
  12265. *
  12266. * The @wq struct is used to get the queue ID of the queue to destroy.
  12267. *
  12268. * On success this function will return a zero. If the queue destroy mailbox
  12269. * command fails this function will return -ENXIO.
  12270. **/
  12271. uint32_t
  12272. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  12273. {
  12274. LPFC_MBOXQ_t *mbox;
  12275. int rc, length, status = 0;
  12276. uint32_t shdr_status, shdr_add_status;
  12277. union lpfc_sli4_cfg_shdr *shdr;
  12278. /* sanity check on queue memory */
  12279. if (!wq)
  12280. return -ENODEV;
  12281. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  12282. if (!mbox)
  12283. return -ENOMEM;
  12284. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  12285. sizeof(struct lpfc_sli4_cfg_mhdr));
  12286. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12287. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  12288. length, LPFC_SLI4_MBX_EMBED);
  12289. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  12290. wq->queue_id);
  12291. mbox->vport = wq->phba->pport;
  12292. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12293. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  12294. shdr = (union lpfc_sli4_cfg_shdr *)
  12295. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  12296. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12297. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12298. if (shdr_status || shdr_add_status || rc) {
  12299. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12300. "2508 WQ_DESTROY mailbox failed with "
  12301. "status x%x add_status x%x, mbx status x%x\n",
  12302. shdr_status, shdr_add_status, rc);
  12303. status = -ENXIO;
  12304. }
  12305. /* Remove wq from any list */
  12306. list_del_init(&wq->list);
  12307. mempool_free(mbox, wq->phba->mbox_mem_pool);
  12308. return status;
  12309. }
  12310. /**
  12311. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  12312. * @rq: The queue structure associated with the queue to destroy.
  12313. *
  12314. * This function destroys a queue, as detailed in @rq by sending an mailbox
  12315. * command, specific to the type of queue, to the HBA.
  12316. *
  12317. * The @rq struct is used to get the queue ID of the queue to destroy.
  12318. *
  12319. * On success this function will return a zero. If the queue destroy mailbox
  12320. * command fails this function will return -ENXIO.
  12321. **/
  12322. uint32_t
  12323. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  12324. struct lpfc_queue *drq)
  12325. {
  12326. LPFC_MBOXQ_t *mbox;
  12327. int rc, length, status = 0;
  12328. uint32_t shdr_status, shdr_add_status;
  12329. union lpfc_sli4_cfg_shdr *shdr;
  12330. /* sanity check on queue memory */
  12331. if (!hrq || !drq)
  12332. return -ENODEV;
  12333. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  12334. if (!mbox)
  12335. return -ENOMEM;
  12336. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  12337. sizeof(struct lpfc_sli4_cfg_mhdr));
  12338. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12339. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  12340. length, LPFC_SLI4_MBX_EMBED);
  12341. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12342. hrq->queue_id);
  12343. mbox->vport = hrq->phba->pport;
  12344. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12345. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  12346. /* The IOCTL status is embedded in the mailbox subheader. */
  12347. shdr = (union lpfc_sli4_cfg_shdr *)
  12348. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12349. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12350. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12351. if (shdr_status || shdr_add_status || rc) {
  12352. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12353. "2509 RQ_DESTROY mailbox failed with "
  12354. "status x%x add_status x%x, mbx status x%x\n",
  12355. shdr_status, shdr_add_status, rc);
  12356. if (rc != MBX_TIMEOUT)
  12357. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12358. return -ENXIO;
  12359. }
  12360. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12361. drq->queue_id);
  12362. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  12363. shdr = (union lpfc_sli4_cfg_shdr *)
  12364. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12365. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12366. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12367. if (shdr_status || shdr_add_status || rc) {
  12368. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12369. "2510 RQ_DESTROY mailbox failed with "
  12370. "status x%x add_status x%x, mbx status x%x\n",
  12371. shdr_status, shdr_add_status, rc);
  12372. status = -ENXIO;
  12373. }
  12374. list_del_init(&hrq->list);
  12375. list_del_init(&drq->list);
  12376. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12377. return status;
  12378. }
  12379. /**
  12380. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  12381. * @phba: The virtual port for which this call being executed.
  12382. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  12383. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  12384. * @xritag: the xritag that ties this io to the SGL pages.
  12385. *
  12386. * This routine will post the sgl pages for the IO that has the xritag
  12387. * that is in the iocbq structure. The xritag is assigned during iocbq
  12388. * creation and persists for as long as the driver is loaded.
  12389. * if the caller has fewer than 256 scatter gather segments to map then
  12390. * pdma_phys_addr1 should be 0.
  12391. * If the caller needs to map more than 256 scatter gather segment then
  12392. * pdma_phys_addr1 should be a valid physical address.
  12393. * physical address for SGLs must be 64 byte aligned.
  12394. * If you are going to map 2 SGL's then the first one must have 256 entries
  12395. * the second sgl can have between 1 and 256 entries.
  12396. *
  12397. * Return codes:
  12398. * 0 - Success
  12399. * -ENXIO, -ENOMEM - Failure
  12400. **/
  12401. int
  12402. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  12403. dma_addr_t pdma_phys_addr0,
  12404. dma_addr_t pdma_phys_addr1,
  12405. uint16_t xritag)
  12406. {
  12407. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  12408. LPFC_MBOXQ_t *mbox;
  12409. int rc;
  12410. uint32_t shdr_status, shdr_add_status;
  12411. uint32_t mbox_tmo;
  12412. union lpfc_sli4_cfg_shdr *shdr;
  12413. if (xritag == NO_XRI) {
  12414. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12415. "0364 Invalid param:\n");
  12416. return -EINVAL;
  12417. }
  12418. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12419. if (!mbox)
  12420. return -ENOMEM;
  12421. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12422. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  12423. sizeof(struct lpfc_mbx_post_sgl_pages) -
  12424. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  12425. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  12426. &mbox->u.mqe.un.post_sgl_pages;
  12427. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  12428. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  12429. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  12430. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  12431. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  12432. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  12433. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  12434. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  12435. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  12436. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  12437. if (!phba->sli4_hba.intr_enable)
  12438. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12439. else {
  12440. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12441. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12442. }
  12443. /* The IOCTL status is embedded in the mailbox subheader. */
  12444. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  12445. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12446. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12447. if (rc != MBX_TIMEOUT)
  12448. mempool_free(mbox, phba->mbox_mem_pool);
  12449. if (shdr_status || shdr_add_status || rc) {
  12450. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12451. "2511 POST_SGL mailbox failed with "
  12452. "status x%x add_status x%x, mbx status x%x\n",
  12453. shdr_status, shdr_add_status, rc);
  12454. rc = -ENXIO;
  12455. }
  12456. return 0;
  12457. }
  12458. /**
  12459. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  12460. * @phba: pointer to lpfc hba data structure.
  12461. *
  12462. * This routine is invoked to post rpi header templates to the
  12463. * HBA consistent with the SLI-4 interface spec. This routine
  12464. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  12465. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  12466. *
  12467. * Returns
  12468. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  12469. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  12470. **/
  12471. uint16_t
  12472. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  12473. {
  12474. unsigned long xri;
  12475. /*
  12476. * Fetch the next logical xri. Because this index is logical,
  12477. * the driver starts at 0 each time.
  12478. */
  12479. spin_lock_irq(&phba->hbalock);
  12480. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  12481. phba->sli4_hba.max_cfg_param.max_xri, 0);
  12482. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  12483. spin_unlock_irq(&phba->hbalock);
  12484. return NO_XRI;
  12485. } else {
  12486. set_bit(xri, phba->sli4_hba.xri_bmask);
  12487. phba->sli4_hba.max_cfg_param.xri_used++;
  12488. }
  12489. spin_unlock_irq(&phba->hbalock);
  12490. return xri;
  12491. }
  12492. /**
  12493. * lpfc_sli4_free_xri - Release an xri for reuse.
  12494. * @phba: pointer to lpfc hba data structure.
  12495. *
  12496. * This routine is invoked to release an xri to the pool of
  12497. * available rpis maintained by the driver.
  12498. **/
  12499. void
  12500. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12501. {
  12502. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  12503. phba->sli4_hba.max_cfg_param.xri_used--;
  12504. }
  12505. }
  12506. /**
  12507. * lpfc_sli4_free_xri - Release an xri for reuse.
  12508. * @phba: pointer to lpfc hba data structure.
  12509. *
  12510. * This routine is invoked to release an xri to the pool of
  12511. * available rpis maintained by the driver.
  12512. **/
  12513. void
  12514. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12515. {
  12516. spin_lock_irq(&phba->hbalock);
  12517. __lpfc_sli4_free_xri(phba, xri);
  12518. spin_unlock_irq(&phba->hbalock);
  12519. }
  12520. /**
  12521. * lpfc_sli4_next_xritag - Get an xritag for the io
  12522. * @phba: Pointer to HBA context object.
  12523. *
  12524. * This function gets an xritag for the iocb. If there is no unused xritag
  12525. * it will return 0xffff.
  12526. * The function returns the allocated xritag if successful, else returns zero.
  12527. * Zero is not a valid xritag.
  12528. * The caller is not required to hold any lock.
  12529. **/
  12530. uint16_t
  12531. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  12532. {
  12533. uint16_t xri_index;
  12534. xri_index = lpfc_sli4_alloc_xri(phba);
  12535. if (xri_index == NO_XRI)
  12536. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  12537. "2004 Failed to allocate XRI.last XRITAG is %d"
  12538. " Max XRI is %d, Used XRI is %d\n",
  12539. xri_index,
  12540. phba->sli4_hba.max_cfg_param.max_xri,
  12541. phba->sli4_hba.max_cfg_param.xri_used);
  12542. return xri_index;
  12543. }
  12544. /**
  12545. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  12546. * @phba: pointer to lpfc hba data structure.
  12547. * @post_sgl_list: pointer to els sgl entry list.
  12548. * @count: number of els sgl entries on the list.
  12549. *
  12550. * This routine is invoked to post a block of driver's sgl pages to the
  12551. * HBA using non-embedded mailbox command. No Lock is held. This routine
  12552. * is only called when the driver is loading and after all IO has been
  12553. * stopped.
  12554. **/
  12555. static int
  12556. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
  12557. struct list_head *post_sgl_list,
  12558. int post_cnt)
  12559. {
  12560. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  12561. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12562. struct sgl_page_pairs *sgl_pg_pairs;
  12563. void *viraddr;
  12564. LPFC_MBOXQ_t *mbox;
  12565. uint32_t reqlen, alloclen, pg_pairs;
  12566. uint32_t mbox_tmo;
  12567. uint16_t xritag_start = 0;
  12568. int rc = 0;
  12569. uint32_t shdr_status, shdr_add_status;
  12570. union lpfc_sli4_cfg_shdr *shdr;
  12571. reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
  12572. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12573. if (reqlen > SLI4_PAGE_SIZE) {
  12574. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12575. "2559 Block sgl registration required DMA "
  12576. "size (%d) great than a page\n", reqlen);
  12577. return -ENOMEM;
  12578. }
  12579. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12580. if (!mbox)
  12581. return -ENOMEM;
  12582. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12583. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12584. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12585. LPFC_SLI4_MBX_NEMBED);
  12586. if (alloclen < reqlen) {
  12587. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12588. "0285 Allocated DMA memory size (%d) is "
  12589. "less than the requested DMA memory "
  12590. "size (%d)\n", alloclen, reqlen);
  12591. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12592. return -ENOMEM;
  12593. }
  12594. /* Set up the SGL pages in the non-embedded DMA pages */
  12595. viraddr = mbox->sge_array->addr[0];
  12596. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12597. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12598. pg_pairs = 0;
  12599. list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
  12600. /* Set up the sge entry */
  12601. sgl_pg_pairs->sgl_pg0_addr_lo =
  12602. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  12603. sgl_pg_pairs->sgl_pg0_addr_hi =
  12604. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  12605. sgl_pg_pairs->sgl_pg1_addr_lo =
  12606. cpu_to_le32(putPaddrLow(0));
  12607. sgl_pg_pairs->sgl_pg1_addr_hi =
  12608. cpu_to_le32(putPaddrHigh(0));
  12609. /* Keep the first xritag on the list */
  12610. if (pg_pairs == 0)
  12611. xritag_start = sglq_entry->sli4_xritag;
  12612. sgl_pg_pairs++;
  12613. pg_pairs++;
  12614. }
  12615. /* Complete initialization and perform endian conversion. */
  12616. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12617. bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
  12618. sgl->word0 = cpu_to_le32(sgl->word0);
  12619. if (!phba->sli4_hba.intr_enable)
  12620. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12621. else {
  12622. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12623. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12624. }
  12625. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12626. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12627. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12628. if (rc != MBX_TIMEOUT)
  12629. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12630. if (shdr_status || shdr_add_status || rc) {
  12631. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12632. "2513 POST_SGL_BLOCK mailbox command failed "
  12633. "status x%x add_status x%x mbx status x%x\n",
  12634. shdr_status, shdr_add_status, rc);
  12635. rc = -ENXIO;
  12636. }
  12637. return rc;
  12638. }
  12639. /**
  12640. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  12641. * @phba: pointer to lpfc hba data structure.
  12642. * @sblist: pointer to scsi buffer list.
  12643. * @count: number of scsi buffers on the list.
  12644. *
  12645. * This routine is invoked to post a block of @count scsi sgl pages from a
  12646. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  12647. * No Lock is held.
  12648. *
  12649. **/
  12650. int
  12651. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
  12652. struct list_head *sblist,
  12653. int count)
  12654. {
  12655. struct lpfc_scsi_buf *psb;
  12656. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12657. struct sgl_page_pairs *sgl_pg_pairs;
  12658. void *viraddr;
  12659. LPFC_MBOXQ_t *mbox;
  12660. uint32_t reqlen, alloclen, pg_pairs;
  12661. uint32_t mbox_tmo;
  12662. uint16_t xritag_start = 0;
  12663. int rc = 0;
  12664. uint32_t shdr_status, shdr_add_status;
  12665. dma_addr_t pdma_phys_bpl1;
  12666. union lpfc_sli4_cfg_shdr *shdr;
  12667. /* Calculate the requested length of the dma memory */
  12668. reqlen = count * sizeof(struct sgl_page_pairs) +
  12669. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12670. if (reqlen > SLI4_PAGE_SIZE) {
  12671. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12672. "0217 Block sgl registration required DMA "
  12673. "size (%d) great than a page\n", reqlen);
  12674. return -ENOMEM;
  12675. }
  12676. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12677. if (!mbox) {
  12678. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12679. "0283 Failed to allocate mbox cmd memory\n");
  12680. return -ENOMEM;
  12681. }
  12682. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12683. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12684. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12685. LPFC_SLI4_MBX_NEMBED);
  12686. if (alloclen < reqlen) {
  12687. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12688. "2561 Allocated DMA memory size (%d) is "
  12689. "less than the requested DMA memory "
  12690. "size (%d)\n", alloclen, reqlen);
  12691. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12692. return -ENOMEM;
  12693. }
  12694. /* Get the first SGE entry from the non-embedded DMA memory */
  12695. viraddr = mbox->sge_array->addr[0];
  12696. /* Set up the SGL pages in the non-embedded DMA pages */
  12697. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12698. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12699. pg_pairs = 0;
  12700. list_for_each_entry(psb, sblist, list) {
  12701. /* Set up the sge entry */
  12702. sgl_pg_pairs->sgl_pg0_addr_lo =
  12703. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  12704. sgl_pg_pairs->sgl_pg0_addr_hi =
  12705. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  12706. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  12707. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  12708. else
  12709. pdma_phys_bpl1 = 0;
  12710. sgl_pg_pairs->sgl_pg1_addr_lo =
  12711. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  12712. sgl_pg_pairs->sgl_pg1_addr_hi =
  12713. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  12714. /* Keep the first xritag on the list */
  12715. if (pg_pairs == 0)
  12716. xritag_start = psb->cur_iocbq.sli4_xritag;
  12717. sgl_pg_pairs++;
  12718. pg_pairs++;
  12719. }
  12720. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12721. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  12722. /* Perform endian conversion if necessary */
  12723. sgl->word0 = cpu_to_le32(sgl->word0);
  12724. if (!phba->sli4_hba.intr_enable)
  12725. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12726. else {
  12727. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12728. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12729. }
  12730. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12731. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12732. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12733. if (rc != MBX_TIMEOUT)
  12734. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12735. if (shdr_status || shdr_add_status || rc) {
  12736. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12737. "2564 POST_SGL_BLOCK mailbox command failed "
  12738. "status x%x add_status x%x mbx status x%x\n",
  12739. shdr_status, shdr_add_status, rc);
  12740. rc = -ENXIO;
  12741. }
  12742. return rc;
  12743. }
  12744. /**
  12745. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  12746. * @phba: pointer to lpfc_hba struct that the frame was received on
  12747. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12748. *
  12749. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  12750. * valid type of frame that the LPFC driver will handle. This function will
  12751. * return a zero if the frame is a valid frame or a non zero value when the
  12752. * frame does not pass the check.
  12753. **/
  12754. static int
  12755. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  12756. {
  12757. /* make rctl_names static to save stack space */
  12758. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  12759. char *type_names[] = FC_TYPE_NAMES_INIT;
  12760. struct fc_vft_header *fc_vft_hdr;
  12761. uint32_t *header = (uint32_t *) fc_hdr;
  12762. switch (fc_hdr->fh_r_ctl) {
  12763. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  12764. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  12765. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  12766. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  12767. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  12768. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  12769. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  12770. case FC_RCTL_DD_CMD_STATUS: /* command status */
  12771. case FC_RCTL_ELS_REQ: /* extended link services request */
  12772. case FC_RCTL_ELS_REP: /* extended link services reply */
  12773. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  12774. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  12775. case FC_RCTL_BA_NOP: /* basic link service NOP */
  12776. case FC_RCTL_BA_ABTS: /* basic link service abort */
  12777. case FC_RCTL_BA_RMC: /* remove connection */
  12778. case FC_RCTL_BA_ACC: /* basic accept */
  12779. case FC_RCTL_BA_RJT: /* basic reject */
  12780. case FC_RCTL_BA_PRMT:
  12781. case FC_RCTL_ACK_1: /* acknowledge_1 */
  12782. case FC_RCTL_ACK_0: /* acknowledge_0 */
  12783. case FC_RCTL_P_RJT: /* port reject */
  12784. case FC_RCTL_F_RJT: /* fabric reject */
  12785. case FC_RCTL_P_BSY: /* port busy */
  12786. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  12787. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  12788. case FC_RCTL_LCR: /* link credit reset */
  12789. case FC_RCTL_END: /* end */
  12790. break;
  12791. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  12792. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12793. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  12794. return lpfc_fc_frame_check(phba, fc_hdr);
  12795. default:
  12796. goto drop;
  12797. }
  12798. switch (fc_hdr->fh_type) {
  12799. case FC_TYPE_BLS:
  12800. case FC_TYPE_ELS:
  12801. case FC_TYPE_FCP:
  12802. case FC_TYPE_CT:
  12803. break;
  12804. case FC_TYPE_IP:
  12805. case FC_TYPE_ILS:
  12806. default:
  12807. goto drop;
  12808. }
  12809. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12810. "2538 Received frame rctl:%s type:%s "
  12811. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  12812. rctl_names[fc_hdr->fh_r_ctl],
  12813. type_names[fc_hdr->fh_type],
  12814. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  12815. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  12816. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  12817. return 0;
  12818. drop:
  12819. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12820. "2539 Dropped frame rctl:%s type:%s\n",
  12821. rctl_names[fc_hdr->fh_r_ctl],
  12822. type_names[fc_hdr->fh_type]);
  12823. return 1;
  12824. }
  12825. /**
  12826. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  12827. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12828. *
  12829. * This function processes the FC header to retrieve the VFI from the VF
  12830. * header, if one exists. This function will return the VFI if one exists
  12831. * or 0 if no VSAN Header exists.
  12832. **/
  12833. static uint32_t
  12834. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  12835. {
  12836. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12837. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  12838. return 0;
  12839. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  12840. }
  12841. /**
  12842. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  12843. * @phba: Pointer to the HBA structure to search for the vport on
  12844. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12845. * @fcfi: The FC Fabric ID that the frame came from
  12846. *
  12847. * This function searches the @phba for a vport that matches the content of the
  12848. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  12849. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  12850. * returns the matching vport pointer or NULL if unable to match frame to a
  12851. * vport.
  12852. **/
  12853. static struct lpfc_vport *
  12854. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  12855. uint16_t fcfi)
  12856. {
  12857. struct lpfc_vport **vports;
  12858. struct lpfc_vport *vport = NULL;
  12859. int i;
  12860. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  12861. fc_hdr->fh_d_id[1] << 8 |
  12862. fc_hdr->fh_d_id[2]);
  12863. if (did == Fabric_DID)
  12864. return phba->pport;
  12865. if ((phba->pport->fc_flag & FC_PT2PT) &&
  12866. !(phba->link_state == LPFC_HBA_READY))
  12867. return phba->pport;
  12868. vports = lpfc_create_vport_work_array(phba);
  12869. if (vports != NULL)
  12870. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  12871. if (phba->fcf.fcfi == fcfi &&
  12872. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  12873. vports[i]->fc_myDID == did) {
  12874. vport = vports[i];
  12875. break;
  12876. }
  12877. }
  12878. lpfc_destroy_vport_work_array(phba, vports);
  12879. return vport;
  12880. }
  12881. /**
  12882. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  12883. * @vport: The vport to work on.
  12884. *
  12885. * This function updates the receive sequence time stamp for this vport. The
  12886. * receive sequence time stamp indicates the time that the last frame of the
  12887. * the sequence that has been idle for the longest amount of time was received.
  12888. * the driver uses this time stamp to indicate if any received sequences have
  12889. * timed out.
  12890. **/
  12891. void
  12892. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  12893. {
  12894. struct lpfc_dmabuf *h_buf;
  12895. struct hbq_dmabuf *dmabuf = NULL;
  12896. /* get the oldest sequence on the rcv list */
  12897. h_buf = list_get_first(&vport->rcv_buffer_list,
  12898. struct lpfc_dmabuf, list);
  12899. if (!h_buf)
  12900. return;
  12901. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12902. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  12903. }
  12904. /**
  12905. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  12906. * @vport: The vport that the received sequences were sent to.
  12907. *
  12908. * This function cleans up all outstanding received sequences. This is called
  12909. * by the driver when a link event or user action invalidates all the received
  12910. * sequences.
  12911. **/
  12912. void
  12913. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  12914. {
  12915. struct lpfc_dmabuf *h_buf, *hnext;
  12916. struct lpfc_dmabuf *d_buf, *dnext;
  12917. struct hbq_dmabuf *dmabuf = NULL;
  12918. /* start with the oldest sequence on the rcv list */
  12919. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12920. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12921. list_del_init(&dmabuf->hbuf.list);
  12922. list_for_each_entry_safe(d_buf, dnext,
  12923. &dmabuf->dbuf.list, list) {
  12924. list_del_init(&d_buf->list);
  12925. lpfc_in_buf_free(vport->phba, d_buf);
  12926. }
  12927. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12928. }
  12929. }
  12930. /**
  12931. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  12932. * @vport: The vport that the received sequences were sent to.
  12933. *
  12934. * This function determines whether any received sequences have timed out by
  12935. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  12936. * indicates that there is at least one timed out sequence this routine will
  12937. * go through the received sequences one at a time from most inactive to most
  12938. * active to determine which ones need to be cleaned up. Once it has determined
  12939. * that a sequence needs to be cleaned up it will simply free up the resources
  12940. * without sending an abort.
  12941. **/
  12942. void
  12943. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  12944. {
  12945. struct lpfc_dmabuf *h_buf, *hnext;
  12946. struct lpfc_dmabuf *d_buf, *dnext;
  12947. struct hbq_dmabuf *dmabuf = NULL;
  12948. unsigned long timeout;
  12949. int abort_count = 0;
  12950. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12951. vport->rcv_buffer_time_stamp);
  12952. if (list_empty(&vport->rcv_buffer_list) ||
  12953. time_before(jiffies, timeout))
  12954. return;
  12955. /* start with the oldest sequence on the rcv list */
  12956. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12957. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12958. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12959. dmabuf->time_stamp);
  12960. if (time_before(jiffies, timeout))
  12961. break;
  12962. abort_count++;
  12963. list_del_init(&dmabuf->hbuf.list);
  12964. list_for_each_entry_safe(d_buf, dnext,
  12965. &dmabuf->dbuf.list, list) {
  12966. list_del_init(&d_buf->list);
  12967. lpfc_in_buf_free(vport->phba, d_buf);
  12968. }
  12969. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12970. }
  12971. if (abort_count)
  12972. lpfc_update_rcv_time_stamp(vport);
  12973. }
  12974. /**
  12975. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  12976. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  12977. *
  12978. * This function searches through the existing incomplete sequences that have
  12979. * been sent to this @vport. If the frame matches one of the incomplete
  12980. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  12981. * make up that sequence. If no sequence is found that matches this frame then
  12982. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  12983. * This function returns a pointer to the first dmabuf in the sequence list that
  12984. * the frame was linked to.
  12985. **/
  12986. static struct hbq_dmabuf *
  12987. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  12988. {
  12989. struct fc_frame_header *new_hdr;
  12990. struct fc_frame_header *temp_hdr;
  12991. struct lpfc_dmabuf *d_buf;
  12992. struct lpfc_dmabuf *h_buf;
  12993. struct hbq_dmabuf *seq_dmabuf = NULL;
  12994. struct hbq_dmabuf *temp_dmabuf = NULL;
  12995. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12996. dmabuf->time_stamp = jiffies;
  12997. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12998. /* Use the hdr_buf to find the sequence that this frame belongs to */
  12999. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  13000. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  13001. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  13002. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  13003. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  13004. continue;
  13005. /* found a pending sequence that matches this frame */
  13006. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13007. break;
  13008. }
  13009. if (!seq_dmabuf) {
  13010. /*
  13011. * This indicates first frame received for this sequence.
  13012. * Queue the buffer on the vport's rcv_buffer_list.
  13013. */
  13014. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13015. lpfc_update_rcv_time_stamp(vport);
  13016. return dmabuf;
  13017. }
  13018. temp_hdr = seq_dmabuf->hbuf.virt;
  13019. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  13020. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13021. list_del_init(&seq_dmabuf->hbuf.list);
  13022. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13023. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13024. lpfc_update_rcv_time_stamp(vport);
  13025. return dmabuf;
  13026. }
  13027. /* move this sequence to the tail to indicate a young sequence */
  13028. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13029. seq_dmabuf->time_stamp = jiffies;
  13030. lpfc_update_rcv_time_stamp(vport);
  13031. if (list_empty(&seq_dmabuf->dbuf.list)) {
  13032. temp_hdr = dmabuf->hbuf.virt;
  13033. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13034. return seq_dmabuf;
  13035. }
  13036. /* find the correct place in the sequence to insert this frame */
  13037. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  13038. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13039. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  13040. /*
  13041. * If the frame's sequence count is greater than the frame on
  13042. * the list then insert the frame right after this frame
  13043. */
  13044. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  13045. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13046. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  13047. return seq_dmabuf;
  13048. }
  13049. }
  13050. return NULL;
  13051. }
  13052. /**
  13053. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  13054. * @vport: pointer to a vitural port
  13055. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13056. *
  13057. * This function tries to abort from the partially assembed sequence, described
  13058. * by the information from basic abbort @dmabuf. It checks to see whether such
  13059. * partially assembled sequence held by the driver. If so, it shall free up all
  13060. * the frames from the partially assembled sequence.
  13061. *
  13062. * Return
  13063. * true -- if there is matching partially assembled sequence present and all
  13064. * the frames freed with the sequence;
  13065. * false -- if there is no matching partially assembled sequence present so
  13066. * nothing got aborted in the lower layer driver
  13067. **/
  13068. static bool
  13069. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  13070. struct hbq_dmabuf *dmabuf)
  13071. {
  13072. struct fc_frame_header *new_hdr;
  13073. struct fc_frame_header *temp_hdr;
  13074. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  13075. struct hbq_dmabuf *seq_dmabuf = NULL;
  13076. /* Use the hdr_buf to find the sequence that matches this frame */
  13077. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  13078. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  13079. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13080. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  13081. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  13082. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  13083. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  13084. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  13085. continue;
  13086. /* found a pending sequence that matches this frame */
  13087. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13088. break;
  13089. }
  13090. /* Free up all the frames from the partially assembled sequence */
  13091. if (seq_dmabuf) {
  13092. list_for_each_entry_safe(d_buf, n_buf,
  13093. &seq_dmabuf->dbuf.list, list) {
  13094. list_del_init(&d_buf->list);
  13095. lpfc_in_buf_free(vport->phba, d_buf);
  13096. }
  13097. return true;
  13098. }
  13099. return false;
  13100. }
  13101. /**
  13102. * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
  13103. * @vport: pointer to a vitural port
  13104. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13105. *
  13106. * This function tries to abort from the assembed sequence from upper level
  13107. * protocol, described by the information from basic abbort @dmabuf. It
  13108. * checks to see whether such pending context exists at upper level protocol.
  13109. * If so, it shall clean up the pending context.
  13110. *
  13111. * Return
  13112. * true -- if there is matching pending context of the sequence cleaned
  13113. * at ulp;
  13114. * false -- if there is no matching pending context of the sequence present
  13115. * at ulp.
  13116. **/
  13117. static bool
  13118. lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  13119. {
  13120. struct lpfc_hba *phba = vport->phba;
  13121. int handled;
  13122. /* Accepting abort at ulp with SLI4 only */
  13123. if (phba->sli_rev < LPFC_SLI_REV4)
  13124. return false;
  13125. /* Register all caring upper level protocols to attend abort */
  13126. handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
  13127. if (handled)
  13128. return true;
  13129. return false;
  13130. }
  13131. /**
  13132. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  13133. * @phba: Pointer to HBA context object.
  13134. * @cmd_iocbq: pointer to the command iocbq structure.
  13135. * @rsp_iocbq: pointer to the response iocbq structure.
  13136. *
  13137. * This function handles the sequence abort response iocb command complete
  13138. * event. It properly releases the memory allocated to the sequence abort
  13139. * accept iocb.
  13140. **/
  13141. static void
  13142. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  13143. struct lpfc_iocbq *cmd_iocbq,
  13144. struct lpfc_iocbq *rsp_iocbq)
  13145. {
  13146. struct lpfc_nodelist *ndlp;
  13147. if (cmd_iocbq) {
  13148. ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
  13149. lpfc_nlp_put(ndlp);
  13150. lpfc_nlp_not_used(ndlp);
  13151. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  13152. }
  13153. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  13154. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  13155. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13156. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  13157. rsp_iocbq->iocb.ulpStatus,
  13158. rsp_iocbq->iocb.un.ulpWord[4]);
  13159. }
  13160. /**
  13161. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  13162. * @phba: Pointer to HBA context object.
  13163. * @xri: xri id in transaction.
  13164. *
  13165. * This function validates the xri maps to the known range of XRIs allocated an
  13166. * used by the driver.
  13167. **/
  13168. uint16_t
  13169. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  13170. uint16_t xri)
  13171. {
  13172. int i;
  13173. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  13174. if (xri == phba->sli4_hba.xri_ids[i])
  13175. return i;
  13176. }
  13177. return NO_XRI;
  13178. }
  13179. /**
  13180. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  13181. * @phba: Pointer to HBA context object.
  13182. * @fc_hdr: pointer to a FC frame header.
  13183. *
  13184. * This function sends a basic response to a previous unsol sequence abort
  13185. * event after aborting the sequence handling.
  13186. **/
  13187. static void
  13188. lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
  13189. struct fc_frame_header *fc_hdr, bool aborted)
  13190. {
  13191. struct lpfc_hba *phba = vport->phba;
  13192. struct lpfc_iocbq *ctiocb = NULL;
  13193. struct lpfc_nodelist *ndlp;
  13194. uint16_t oxid, rxid, xri, lxri;
  13195. uint32_t sid, fctl;
  13196. IOCB_t *icmd;
  13197. int rc;
  13198. if (!lpfc_is_link_up(phba))
  13199. return;
  13200. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13201. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  13202. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  13203. ndlp = lpfc_findnode_did(vport, sid);
  13204. if (!ndlp) {
  13205. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  13206. if (!ndlp) {
  13207. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13208. "1268 Failed to allocate ndlp for "
  13209. "oxid:x%x SID:x%x\n", oxid, sid);
  13210. return;
  13211. }
  13212. lpfc_nlp_init(vport, ndlp, sid);
  13213. /* Put ndlp onto pport node list */
  13214. lpfc_enqueue_node(vport, ndlp);
  13215. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  13216. /* re-setup ndlp without removing from node list */
  13217. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  13218. if (!ndlp) {
  13219. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13220. "3275 Failed to active ndlp found "
  13221. "for oxid:x%x SID:x%x\n", oxid, sid);
  13222. return;
  13223. }
  13224. }
  13225. /* Allocate buffer for rsp iocb */
  13226. ctiocb = lpfc_sli_get_iocbq(phba);
  13227. if (!ctiocb)
  13228. return;
  13229. /* Extract the F_CTL field from FC_HDR */
  13230. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  13231. icmd = &ctiocb->iocb;
  13232. icmd->un.xseq64.bdl.bdeSize = 0;
  13233. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  13234. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  13235. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  13236. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  13237. /* Fill in the rest of iocb fields */
  13238. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  13239. icmd->ulpBdeCount = 0;
  13240. icmd->ulpLe = 1;
  13241. icmd->ulpClass = CLASS3;
  13242. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  13243. ctiocb->context1 = lpfc_nlp_get(ndlp);
  13244. ctiocb->iocb_cmpl = NULL;
  13245. ctiocb->vport = phba->pport;
  13246. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  13247. ctiocb->sli4_lxritag = NO_XRI;
  13248. ctiocb->sli4_xritag = NO_XRI;
  13249. if (fctl & FC_FC_EX_CTX)
  13250. /* Exchange responder sent the abort so we
  13251. * own the oxid.
  13252. */
  13253. xri = oxid;
  13254. else
  13255. xri = rxid;
  13256. lxri = lpfc_sli4_xri_inrange(phba, xri);
  13257. if (lxri != NO_XRI)
  13258. lpfc_set_rrq_active(phba, ndlp, lxri,
  13259. (xri == oxid) ? rxid : oxid, 0);
  13260. /* For BA_ABTS from exchange responder, if the logical xri with
  13261. * the oxid maps to the FCP XRI range, the port no longer has
  13262. * that exchange context, send a BLS_RJT. Override the IOCB for
  13263. * a BA_RJT.
  13264. */
  13265. if ((fctl & FC_FC_EX_CTX) &&
  13266. (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) {
  13267. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  13268. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  13269. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  13270. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  13271. }
  13272. /* If BA_ABTS failed to abort a partially assembled receive sequence,
  13273. * the driver no longer has that exchange, send a BLS_RJT. Override
  13274. * the IOCB for a BA_RJT.
  13275. */
  13276. if (aborted == false) {
  13277. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  13278. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  13279. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  13280. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  13281. }
  13282. if (fctl & FC_FC_EX_CTX) {
  13283. /* ABTS sent by responder to CT exchange, construction
  13284. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  13285. * field and RX_ID from ABTS for RX_ID field.
  13286. */
  13287. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  13288. } else {
  13289. /* ABTS sent by initiator to CT exchange, construction
  13290. * of BA_ACC will need to allocate a new XRI as for the
  13291. * XRI_TAG field.
  13292. */
  13293. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  13294. }
  13295. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  13296. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  13297. /* Xmit CT abts response on exchange <xid> */
  13298. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  13299. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  13300. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  13301. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  13302. if (rc == IOCB_ERROR) {
  13303. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  13304. "2925 Failed to issue CT ABTS RSP x%x on "
  13305. "xri x%x, Data x%x\n",
  13306. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  13307. phba->link_state);
  13308. lpfc_nlp_put(ndlp);
  13309. ctiocb->context1 = NULL;
  13310. lpfc_sli_release_iocbq(phba, ctiocb);
  13311. }
  13312. }
  13313. /**
  13314. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  13315. * @vport: Pointer to the vport on which this sequence was received
  13316. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13317. *
  13318. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  13319. * receive sequence is only partially assembed by the driver, it shall abort
  13320. * the partially assembled frames for the sequence. Otherwise, if the
  13321. * unsolicited receive sequence has been completely assembled and passed to
  13322. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  13323. * unsolicited sequence has been aborted. After that, it will issue a basic
  13324. * accept to accept the abort.
  13325. **/
  13326. void
  13327. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  13328. struct hbq_dmabuf *dmabuf)
  13329. {
  13330. struct lpfc_hba *phba = vport->phba;
  13331. struct fc_frame_header fc_hdr;
  13332. uint32_t fctl;
  13333. bool aborted;
  13334. /* Make a copy of fc_hdr before the dmabuf being released */
  13335. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  13336. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  13337. if (fctl & FC_FC_EX_CTX) {
  13338. /* ABTS by responder to exchange, no cleanup needed */
  13339. aborted = true;
  13340. } else {
  13341. /* ABTS by initiator to exchange, need to do cleanup */
  13342. aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  13343. if (aborted == false)
  13344. aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
  13345. }
  13346. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13347. /* Respond with BA_ACC or BA_RJT accordingly */
  13348. lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
  13349. }
  13350. /**
  13351. * lpfc_seq_complete - Indicates if a sequence is complete
  13352. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13353. *
  13354. * This function checks the sequence, starting with the frame described by
  13355. * @dmabuf, to see if all the frames associated with this sequence are present.
  13356. * the frames associated with this sequence are linked to the @dmabuf using the
  13357. * dbuf list. This function looks for two major things. 1) That the first frame
  13358. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  13359. * set. 3) That there are no holes in the sequence count. The function will
  13360. * return 1 when the sequence is complete, otherwise it will return 0.
  13361. **/
  13362. static int
  13363. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  13364. {
  13365. struct fc_frame_header *hdr;
  13366. struct lpfc_dmabuf *d_buf;
  13367. struct hbq_dmabuf *seq_dmabuf;
  13368. uint32_t fctl;
  13369. int seq_count = 0;
  13370. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13371. /* make sure first fame of sequence has a sequence count of zero */
  13372. if (hdr->fh_seq_cnt != seq_count)
  13373. return 0;
  13374. fctl = (hdr->fh_f_ctl[0] << 16 |
  13375. hdr->fh_f_ctl[1] << 8 |
  13376. hdr->fh_f_ctl[2]);
  13377. /* If last frame of sequence we can return success. */
  13378. if (fctl & FC_FC_END_SEQ)
  13379. return 1;
  13380. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  13381. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13382. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13383. /* If there is a hole in the sequence count then fail. */
  13384. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  13385. return 0;
  13386. fctl = (hdr->fh_f_ctl[0] << 16 |
  13387. hdr->fh_f_ctl[1] << 8 |
  13388. hdr->fh_f_ctl[2]);
  13389. /* If last frame of sequence we can return success. */
  13390. if (fctl & FC_FC_END_SEQ)
  13391. return 1;
  13392. }
  13393. return 0;
  13394. }
  13395. /**
  13396. * lpfc_prep_seq - Prep sequence for ULP processing
  13397. * @vport: Pointer to the vport on which this sequence was received
  13398. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13399. *
  13400. * This function takes a sequence, described by a list of frames, and creates
  13401. * a list of iocbq structures to describe the sequence. This iocbq list will be
  13402. * used to issue to the generic unsolicited sequence handler. This routine
  13403. * returns a pointer to the first iocbq in the list. If the function is unable
  13404. * to allocate an iocbq then it throw out the received frames that were not
  13405. * able to be described and return a pointer to the first iocbq. If unable to
  13406. * allocate any iocbqs (including the first) this function will return NULL.
  13407. **/
  13408. static struct lpfc_iocbq *
  13409. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  13410. {
  13411. struct hbq_dmabuf *hbq_buf;
  13412. struct lpfc_dmabuf *d_buf, *n_buf;
  13413. struct lpfc_iocbq *first_iocbq, *iocbq;
  13414. struct fc_frame_header *fc_hdr;
  13415. uint32_t sid;
  13416. uint32_t len, tot_len;
  13417. struct ulp_bde64 *pbde;
  13418. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13419. /* remove from receive buffer list */
  13420. list_del_init(&seq_dmabuf->hbuf.list);
  13421. lpfc_update_rcv_time_stamp(vport);
  13422. /* get the Remote Port's SID */
  13423. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13424. tot_len = 0;
  13425. /* Get an iocbq struct to fill in. */
  13426. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  13427. if (first_iocbq) {
  13428. /* Initialize the first IOCB. */
  13429. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  13430. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  13431. /* Check FC Header to see what TYPE of frame we are rcv'ing */
  13432. if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
  13433. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
  13434. first_iocbq->iocb.un.rcvels.parmRo =
  13435. sli4_did_from_fc_hdr(fc_hdr);
  13436. first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
  13437. } else
  13438. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  13439. first_iocbq->iocb.ulpContext = NO_XRI;
  13440. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  13441. be16_to_cpu(fc_hdr->fh_ox_id);
  13442. /* iocbq is prepped for internal consumption. Physical vpi. */
  13443. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  13444. vport->phba->vpi_ids[vport->vpi];
  13445. /* put the first buffer into the first IOCBq */
  13446. first_iocbq->context2 = &seq_dmabuf->dbuf;
  13447. first_iocbq->context3 = NULL;
  13448. first_iocbq->iocb.ulpBdeCount = 1;
  13449. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13450. LPFC_DATA_BUF_SIZE;
  13451. first_iocbq->iocb.un.rcvels.remoteID = sid;
  13452. tot_len = bf_get(lpfc_rcqe_length,
  13453. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  13454. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13455. }
  13456. iocbq = first_iocbq;
  13457. /*
  13458. * Each IOCBq can have two Buffers assigned, so go through the list
  13459. * of buffers for this sequence and save two buffers in each IOCBq
  13460. */
  13461. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  13462. if (!iocbq) {
  13463. lpfc_in_buf_free(vport->phba, d_buf);
  13464. continue;
  13465. }
  13466. if (!iocbq->context3) {
  13467. iocbq->context3 = d_buf;
  13468. iocbq->iocb.ulpBdeCount++;
  13469. pbde = (struct ulp_bde64 *)
  13470. &iocbq->iocb.unsli3.sli3Words[4];
  13471. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  13472. /* We need to get the size out of the right CQE */
  13473. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13474. len = bf_get(lpfc_rcqe_length,
  13475. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13476. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  13477. tot_len += len;
  13478. } else {
  13479. iocbq = lpfc_sli_get_iocbq(vport->phba);
  13480. if (!iocbq) {
  13481. if (first_iocbq) {
  13482. first_iocbq->iocb.ulpStatus =
  13483. IOSTAT_FCP_RSP_ERROR;
  13484. first_iocbq->iocb.un.ulpWord[4] =
  13485. IOERR_NO_RESOURCES;
  13486. }
  13487. lpfc_in_buf_free(vport->phba, d_buf);
  13488. continue;
  13489. }
  13490. iocbq->context2 = d_buf;
  13491. iocbq->context3 = NULL;
  13492. iocbq->iocb.ulpBdeCount = 1;
  13493. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13494. LPFC_DATA_BUF_SIZE;
  13495. /* We need to get the size out of the right CQE */
  13496. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13497. len = bf_get(lpfc_rcqe_length,
  13498. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13499. tot_len += len;
  13500. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13501. iocbq->iocb.un.rcvels.remoteID = sid;
  13502. list_add_tail(&iocbq->list, &first_iocbq->list);
  13503. }
  13504. }
  13505. return first_iocbq;
  13506. }
  13507. static void
  13508. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  13509. struct hbq_dmabuf *seq_dmabuf)
  13510. {
  13511. struct fc_frame_header *fc_hdr;
  13512. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  13513. struct lpfc_hba *phba = vport->phba;
  13514. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13515. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  13516. if (!iocbq) {
  13517. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13518. "2707 Ring %d handler: Failed to allocate "
  13519. "iocb Rctl x%x Type x%x received\n",
  13520. LPFC_ELS_RING,
  13521. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13522. return;
  13523. }
  13524. if (!lpfc_complete_unsol_iocb(phba,
  13525. &phba->sli.ring[LPFC_ELS_RING],
  13526. iocbq, fc_hdr->fh_r_ctl,
  13527. fc_hdr->fh_type))
  13528. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13529. "2540 Ring %d handler: unexpected Rctl "
  13530. "x%x Type x%x received\n",
  13531. LPFC_ELS_RING,
  13532. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13533. /* Free iocb created in lpfc_prep_seq */
  13534. list_for_each_entry_safe(curr_iocb, next_iocb,
  13535. &iocbq->list, list) {
  13536. list_del_init(&curr_iocb->list);
  13537. lpfc_sli_release_iocbq(phba, curr_iocb);
  13538. }
  13539. lpfc_sli_release_iocbq(phba, iocbq);
  13540. }
  13541. /**
  13542. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  13543. * @phba: Pointer to HBA context object.
  13544. *
  13545. * This function is called with no lock held. This function processes all
  13546. * the received buffers and gives it to upper layers when a received buffer
  13547. * indicates that it is the final frame in the sequence. The interrupt
  13548. * service routine processes received buffers at interrupt contexts and adds
  13549. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  13550. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  13551. * appropriate receive function when the final frame in a sequence is received.
  13552. **/
  13553. void
  13554. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  13555. struct hbq_dmabuf *dmabuf)
  13556. {
  13557. struct hbq_dmabuf *seq_dmabuf;
  13558. struct fc_frame_header *fc_hdr;
  13559. struct lpfc_vport *vport;
  13560. uint32_t fcfi;
  13561. uint32_t did;
  13562. /* Process each received buffer */
  13563. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13564. /* check to see if this a valid type of frame */
  13565. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  13566. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13567. return;
  13568. }
  13569. if ((bf_get(lpfc_cqe_code,
  13570. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  13571. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  13572. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13573. else
  13574. fcfi = bf_get(lpfc_rcqe_fcf_id,
  13575. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13576. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  13577. if (!vport) {
  13578. /* throw out the frame */
  13579. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13580. return;
  13581. }
  13582. /* d_id this frame is directed to */
  13583. did = sli4_did_from_fc_hdr(fc_hdr);
  13584. /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
  13585. if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
  13586. (did != Fabric_DID)) {
  13587. /*
  13588. * Throw out the frame if we are not pt2pt.
  13589. * The pt2pt protocol allows for discovery frames
  13590. * to be received without a registered VPI.
  13591. */
  13592. if (!(vport->fc_flag & FC_PT2PT) ||
  13593. (phba->link_state == LPFC_HBA_READY)) {
  13594. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13595. return;
  13596. }
  13597. }
  13598. /* Handle the basic abort sequence (BA_ABTS) event */
  13599. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  13600. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  13601. return;
  13602. }
  13603. /* Link this frame */
  13604. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  13605. if (!seq_dmabuf) {
  13606. /* unable to add frame to vport - throw it out */
  13607. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13608. return;
  13609. }
  13610. /* If not last frame in sequence continue processing frames. */
  13611. if (!lpfc_seq_complete(seq_dmabuf))
  13612. return;
  13613. /* Send the complete sequence to the upper layer protocol */
  13614. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  13615. }
  13616. /**
  13617. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  13618. * @phba: pointer to lpfc hba data structure.
  13619. *
  13620. * This routine is invoked to post rpi header templates to the
  13621. * HBA consistent with the SLI-4 interface spec. This routine
  13622. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13623. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13624. *
  13625. * This routine does not require any locks. It's usage is expected
  13626. * to be driver load or reset recovery when the driver is
  13627. * sequential.
  13628. *
  13629. * Return codes
  13630. * 0 - successful
  13631. * -EIO - The mailbox failed to complete successfully.
  13632. * When this error occurs, the driver is not guaranteed
  13633. * to have any rpi regions posted to the device and
  13634. * must either attempt to repost the regions or take a
  13635. * fatal error.
  13636. **/
  13637. int
  13638. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  13639. {
  13640. struct lpfc_rpi_hdr *rpi_page;
  13641. uint32_t rc = 0;
  13642. uint16_t lrpi = 0;
  13643. /* SLI4 ports that support extents do not require RPI headers. */
  13644. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13645. goto exit;
  13646. if (phba->sli4_hba.extents_in_use)
  13647. return -EIO;
  13648. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  13649. /*
  13650. * Assign the rpi headers a physical rpi only if the driver
  13651. * has not initialized those resources. A port reset only
  13652. * needs the headers posted.
  13653. */
  13654. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  13655. LPFC_RPI_RSRC_RDY)
  13656. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13657. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  13658. if (rc != MBX_SUCCESS) {
  13659. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13660. "2008 Error %d posting all rpi "
  13661. "headers\n", rc);
  13662. rc = -EIO;
  13663. break;
  13664. }
  13665. }
  13666. exit:
  13667. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  13668. LPFC_RPI_RSRC_RDY);
  13669. return rc;
  13670. }
  13671. /**
  13672. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  13673. * @phba: pointer to lpfc hba data structure.
  13674. * @rpi_page: pointer to the rpi memory region.
  13675. *
  13676. * This routine is invoked to post a single rpi header to the
  13677. * HBA consistent with the SLI-4 interface spec. This memory region
  13678. * maps up to 64 rpi context regions.
  13679. *
  13680. * Return codes
  13681. * 0 - successful
  13682. * -ENOMEM - No available memory
  13683. * -EIO - The mailbox failed to complete successfully.
  13684. **/
  13685. int
  13686. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  13687. {
  13688. LPFC_MBOXQ_t *mboxq;
  13689. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  13690. uint32_t rc = 0;
  13691. uint32_t shdr_status, shdr_add_status;
  13692. union lpfc_sli4_cfg_shdr *shdr;
  13693. /* SLI4 ports that support extents do not require RPI headers. */
  13694. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13695. return rc;
  13696. if (phba->sli4_hba.extents_in_use)
  13697. return -EIO;
  13698. /* The port is notified of the header region via a mailbox command. */
  13699. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13700. if (!mboxq) {
  13701. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13702. "2001 Unable to allocate memory for issuing "
  13703. "SLI_CONFIG_SPECIAL mailbox command\n");
  13704. return -ENOMEM;
  13705. }
  13706. /* Post all rpi memory regions to the port. */
  13707. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  13708. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13709. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  13710. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  13711. sizeof(struct lpfc_sli4_cfg_mhdr),
  13712. LPFC_SLI4_MBX_EMBED);
  13713. /* Post the physical rpi to the port for this rpi header. */
  13714. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  13715. rpi_page->start_rpi);
  13716. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  13717. hdr_tmpl, rpi_page->page_count);
  13718. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  13719. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  13720. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  13721. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  13722. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13723. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13724. if (rc != MBX_TIMEOUT)
  13725. mempool_free(mboxq, phba->mbox_mem_pool);
  13726. if (shdr_status || shdr_add_status || rc) {
  13727. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13728. "2514 POST_RPI_HDR mailbox failed with "
  13729. "status x%x add_status x%x, mbx status x%x\n",
  13730. shdr_status, shdr_add_status, rc);
  13731. rc = -ENXIO;
  13732. }
  13733. return rc;
  13734. }
  13735. /**
  13736. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  13737. * @phba: pointer to lpfc hba data structure.
  13738. *
  13739. * This routine is invoked to post rpi header templates to the
  13740. * HBA consistent with the SLI-4 interface spec. This routine
  13741. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13742. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13743. *
  13744. * Returns
  13745. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13746. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13747. **/
  13748. int
  13749. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  13750. {
  13751. unsigned long rpi;
  13752. uint16_t max_rpi, rpi_limit;
  13753. uint16_t rpi_remaining, lrpi = 0;
  13754. struct lpfc_rpi_hdr *rpi_hdr;
  13755. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  13756. rpi_limit = phba->sli4_hba.next_rpi;
  13757. /*
  13758. * Fetch the next logical rpi. Because this index is logical,
  13759. * the driver starts at 0 each time.
  13760. */
  13761. spin_lock_irq(&phba->hbalock);
  13762. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  13763. if (rpi >= rpi_limit)
  13764. rpi = LPFC_RPI_ALLOC_ERROR;
  13765. else {
  13766. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  13767. phba->sli4_hba.max_cfg_param.rpi_used++;
  13768. phba->sli4_hba.rpi_count++;
  13769. }
  13770. /*
  13771. * Don't try to allocate more rpi header regions if the device limit
  13772. * has been exhausted.
  13773. */
  13774. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  13775. (phba->sli4_hba.rpi_count >= max_rpi)) {
  13776. spin_unlock_irq(&phba->hbalock);
  13777. return rpi;
  13778. }
  13779. /*
  13780. * RPI header postings are not required for SLI4 ports capable of
  13781. * extents.
  13782. */
  13783. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  13784. spin_unlock_irq(&phba->hbalock);
  13785. return rpi;
  13786. }
  13787. /*
  13788. * If the driver is running low on rpi resources, allocate another
  13789. * page now. Note that the next_rpi value is used because
  13790. * it represents how many are actually in use whereas max_rpi notes
  13791. * how many are supported max by the device.
  13792. */
  13793. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  13794. spin_unlock_irq(&phba->hbalock);
  13795. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  13796. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  13797. if (!rpi_hdr) {
  13798. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13799. "2002 Error Could not grow rpi "
  13800. "count\n");
  13801. } else {
  13802. lrpi = rpi_hdr->start_rpi;
  13803. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13804. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  13805. }
  13806. }
  13807. return rpi;
  13808. }
  13809. /**
  13810. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13811. * @phba: pointer to lpfc hba data structure.
  13812. *
  13813. * This routine is invoked to release an rpi to the pool of
  13814. * available rpis maintained by the driver.
  13815. **/
  13816. void
  13817. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13818. {
  13819. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  13820. phba->sli4_hba.rpi_count--;
  13821. phba->sli4_hba.max_cfg_param.rpi_used--;
  13822. }
  13823. }
  13824. /**
  13825. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13826. * @phba: pointer to lpfc hba data structure.
  13827. *
  13828. * This routine is invoked to release an rpi to the pool of
  13829. * available rpis maintained by the driver.
  13830. **/
  13831. void
  13832. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13833. {
  13834. spin_lock_irq(&phba->hbalock);
  13835. __lpfc_sli4_free_rpi(phba, rpi);
  13836. spin_unlock_irq(&phba->hbalock);
  13837. }
  13838. /**
  13839. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  13840. * @phba: pointer to lpfc hba data structure.
  13841. *
  13842. * This routine is invoked to remove the memory region that
  13843. * provided rpi via a bitmask.
  13844. **/
  13845. void
  13846. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  13847. {
  13848. kfree(phba->sli4_hba.rpi_bmask);
  13849. kfree(phba->sli4_hba.rpi_ids);
  13850. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  13851. }
  13852. /**
  13853. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  13854. * @phba: pointer to lpfc hba data structure.
  13855. *
  13856. * This routine is invoked to remove the memory region that
  13857. * provided rpi via a bitmask.
  13858. **/
  13859. int
  13860. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  13861. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  13862. {
  13863. LPFC_MBOXQ_t *mboxq;
  13864. struct lpfc_hba *phba = ndlp->phba;
  13865. int rc;
  13866. /* The port is notified of the header region via a mailbox command. */
  13867. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13868. if (!mboxq)
  13869. return -ENOMEM;
  13870. /* Post all rpi memory regions to the port. */
  13871. lpfc_resume_rpi(mboxq, ndlp);
  13872. if (cmpl) {
  13873. mboxq->mbox_cmpl = cmpl;
  13874. mboxq->context1 = arg;
  13875. mboxq->context2 = ndlp;
  13876. } else
  13877. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13878. mboxq->vport = ndlp->vport;
  13879. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13880. if (rc == MBX_NOT_FINISHED) {
  13881. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13882. "2010 Resume RPI Mailbox failed "
  13883. "status %d, mbxStatus x%x\n", rc,
  13884. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13885. mempool_free(mboxq, phba->mbox_mem_pool);
  13886. return -EIO;
  13887. }
  13888. return 0;
  13889. }
  13890. /**
  13891. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  13892. * @vport: Pointer to the vport for which the vpi is being initialized
  13893. *
  13894. * This routine is invoked to activate a vpi with the port.
  13895. *
  13896. * Returns:
  13897. * 0 success
  13898. * -Evalue otherwise
  13899. **/
  13900. int
  13901. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  13902. {
  13903. LPFC_MBOXQ_t *mboxq;
  13904. int rc = 0;
  13905. int retval = MBX_SUCCESS;
  13906. uint32_t mbox_tmo;
  13907. struct lpfc_hba *phba = vport->phba;
  13908. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13909. if (!mboxq)
  13910. return -ENOMEM;
  13911. lpfc_init_vpi(phba, mboxq, vport->vpi);
  13912. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  13913. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  13914. if (rc != MBX_SUCCESS) {
  13915. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  13916. "2022 INIT VPI Mailbox failed "
  13917. "status %d, mbxStatus x%x\n", rc,
  13918. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13919. retval = -EIO;
  13920. }
  13921. if (rc != MBX_TIMEOUT)
  13922. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  13923. return retval;
  13924. }
  13925. /**
  13926. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  13927. * @phba: pointer to lpfc hba data structure.
  13928. * @mboxq: Pointer to mailbox object.
  13929. *
  13930. * This routine is invoked to manually add a single FCF record. The caller
  13931. * must pass a completely initialized FCF_Record. This routine takes
  13932. * care of the nonembedded mailbox operations.
  13933. **/
  13934. static void
  13935. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  13936. {
  13937. void *virt_addr;
  13938. union lpfc_sli4_cfg_shdr *shdr;
  13939. uint32_t shdr_status, shdr_add_status;
  13940. virt_addr = mboxq->sge_array->addr[0];
  13941. /* The IOCTL status is embedded in the mailbox subheader. */
  13942. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  13943. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13944. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13945. if ((shdr_status || shdr_add_status) &&
  13946. (shdr_status != STATUS_FCF_IN_USE))
  13947. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13948. "2558 ADD_FCF_RECORD mailbox failed with "
  13949. "status x%x add_status x%x\n",
  13950. shdr_status, shdr_add_status);
  13951. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13952. }
  13953. /**
  13954. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  13955. * @phba: pointer to lpfc hba data structure.
  13956. * @fcf_record: pointer to the initialized fcf record to add.
  13957. *
  13958. * This routine is invoked to manually add a single FCF record. The caller
  13959. * must pass a completely initialized FCF_Record. This routine takes
  13960. * care of the nonembedded mailbox operations.
  13961. **/
  13962. int
  13963. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  13964. {
  13965. int rc = 0;
  13966. LPFC_MBOXQ_t *mboxq;
  13967. uint8_t *bytep;
  13968. void *virt_addr;
  13969. dma_addr_t phys_addr;
  13970. struct lpfc_mbx_sge sge;
  13971. uint32_t alloc_len, req_len;
  13972. uint32_t fcfindex;
  13973. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13974. if (!mboxq) {
  13975. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13976. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  13977. return -ENOMEM;
  13978. }
  13979. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  13980. sizeof(uint32_t);
  13981. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13982. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13983. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  13984. req_len, LPFC_SLI4_MBX_NEMBED);
  13985. if (alloc_len < req_len) {
  13986. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13987. "2523 Allocated DMA memory size (x%x) is "
  13988. "less than the requested DMA memory "
  13989. "size (x%x)\n", alloc_len, req_len);
  13990. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13991. return -ENOMEM;
  13992. }
  13993. /*
  13994. * Get the first SGE entry from the non-embedded DMA memory. This
  13995. * routine only uses a single SGE.
  13996. */
  13997. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  13998. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  13999. virt_addr = mboxq->sge_array->addr[0];
  14000. /*
  14001. * Configure the FCF record for FCFI 0. This is the driver's
  14002. * hardcoded default and gets used in nonFIP mode.
  14003. */
  14004. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  14005. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  14006. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  14007. /*
  14008. * Copy the fcf_index and the FCF Record Data. The data starts after
  14009. * the FCoE header plus word10. The data copy needs to be endian
  14010. * correct.
  14011. */
  14012. bytep += sizeof(uint32_t);
  14013. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  14014. mboxq->vport = phba->pport;
  14015. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  14016. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14017. if (rc == MBX_NOT_FINISHED) {
  14018. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14019. "2515 ADD_FCF_RECORD mailbox failed with "
  14020. "status 0x%x\n", rc);
  14021. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14022. rc = -EIO;
  14023. } else
  14024. rc = 0;
  14025. return rc;
  14026. }
  14027. /**
  14028. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  14029. * @phba: pointer to lpfc hba data structure.
  14030. * @fcf_record: pointer to the fcf record to write the default data.
  14031. * @fcf_index: FCF table entry index.
  14032. *
  14033. * This routine is invoked to build the driver's default FCF record. The
  14034. * values used are hardcoded. This routine handles memory initialization.
  14035. *
  14036. **/
  14037. void
  14038. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  14039. struct fcf_record *fcf_record,
  14040. uint16_t fcf_index)
  14041. {
  14042. memset(fcf_record, 0, sizeof(struct fcf_record));
  14043. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  14044. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  14045. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  14046. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  14047. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  14048. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  14049. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  14050. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  14051. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  14052. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  14053. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  14054. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  14055. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  14056. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  14057. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  14058. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  14059. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  14060. /* Set the VLAN bit map */
  14061. if (phba->valid_vlan) {
  14062. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  14063. = 1 << (phba->vlan_id % 8);
  14064. }
  14065. }
  14066. /**
  14067. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  14068. * @phba: pointer to lpfc hba data structure.
  14069. * @fcf_index: FCF table entry offset.
  14070. *
  14071. * This routine is invoked to scan the entire FCF table by reading FCF
  14072. * record and processing it one at a time starting from the @fcf_index
  14073. * for initial FCF discovery or fast FCF failover rediscovery.
  14074. *
  14075. * Return 0 if the mailbox command is submitted successfully, none 0
  14076. * otherwise.
  14077. **/
  14078. int
  14079. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14080. {
  14081. int rc = 0, error;
  14082. LPFC_MBOXQ_t *mboxq;
  14083. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  14084. phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
  14085. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14086. if (!mboxq) {
  14087. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14088. "2000 Failed to allocate mbox for "
  14089. "READ_FCF cmd\n");
  14090. error = -ENOMEM;
  14091. goto fail_fcf_scan;
  14092. }
  14093. /* Construct the read FCF record mailbox command */
  14094. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14095. if (rc) {
  14096. error = -EINVAL;
  14097. goto fail_fcf_scan;
  14098. }
  14099. /* Issue the mailbox command asynchronously */
  14100. mboxq->vport = phba->pport;
  14101. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  14102. spin_lock_irq(&phba->hbalock);
  14103. phba->hba_flag |= FCF_TS_INPROG;
  14104. spin_unlock_irq(&phba->hbalock);
  14105. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14106. if (rc == MBX_NOT_FINISHED)
  14107. error = -EIO;
  14108. else {
  14109. /* Reset eligible FCF count for new scan */
  14110. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  14111. phba->fcf.eligible_fcf_cnt = 0;
  14112. error = 0;
  14113. }
  14114. fail_fcf_scan:
  14115. if (error) {
  14116. if (mboxq)
  14117. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14118. /* FCF scan failed, clear FCF_TS_INPROG flag */
  14119. spin_lock_irq(&phba->hbalock);
  14120. phba->hba_flag &= ~FCF_TS_INPROG;
  14121. spin_unlock_irq(&phba->hbalock);
  14122. }
  14123. return error;
  14124. }
  14125. /**
  14126. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  14127. * @phba: pointer to lpfc hba data structure.
  14128. * @fcf_index: FCF table entry offset.
  14129. *
  14130. * This routine is invoked to read an FCF record indicated by @fcf_index
  14131. * and to use it for FLOGI roundrobin FCF failover.
  14132. *
  14133. * Return 0 if the mailbox command is submitted successfully, none 0
  14134. * otherwise.
  14135. **/
  14136. int
  14137. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14138. {
  14139. int rc = 0, error;
  14140. LPFC_MBOXQ_t *mboxq;
  14141. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14142. if (!mboxq) {
  14143. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14144. "2763 Failed to allocate mbox for "
  14145. "READ_FCF cmd\n");
  14146. error = -ENOMEM;
  14147. goto fail_fcf_read;
  14148. }
  14149. /* Construct the read FCF record mailbox command */
  14150. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14151. if (rc) {
  14152. error = -EINVAL;
  14153. goto fail_fcf_read;
  14154. }
  14155. /* Issue the mailbox command asynchronously */
  14156. mboxq->vport = phba->pport;
  14157. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  14158. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14159. if (rc == MBX_NOT_FINISHED)
  14160. error = -EIO;
  14161. else
  14162. error = 0;
  14163. fail_fcf_read:
  14164. if (error && mboxq)
  14165. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14166. return error;
  14167. }
  14168. /**
  14169. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  14170. * @phba: pointer to lpfc hba data structure.
  14171. * @fcf_index: FCF table entry offset.
  14172. *
  14173. * This routine is invoked to read an FCF record indicated by @fcf_index to
  14174. * determine whether it's eligible for FLOGI roundrobin failover list.
  14175. *
  14176. * Return 0 if the mailbox command is submitted successfully, none 0
  14177. * otherwise.
  14178. **/
  14179. int
  14180. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14181. {
  14182. int rc = 0, error;
  14183. LPFC_MBOXQ_t *mboxq;
  14184. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14185. if (!mboxq) {
  14186. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14187. "2758 Failed to allocate mbox for "
  14188. "READ_FCF cmd\n");
  14189. error = -ENOMEM;
  14190. goto fail_fcf_read;
  14191. }
  14192. /* Construct the read FCF record mailbox command */
  14193. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14194. if (rc) {
  14195. error = -EINVAL;
  14196. goto fail_fcf_read;
  14197. }
  14198. /* Issue the mailbox command asynchronously */
  14199. mboxq->vport = phba->pport;
  14200. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  14201. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14202. if (rc == MBX_NOT_FINISHED)
  14203. error = -EIO;
  14204. else
  14205. error = 0;
  14206. fail_fcf_read:
  14207. if (error && mboxq)
  14208. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14209. return error;
  14210. }
  14211. /**
  14212. * lpfc_check_next_fcf_pri
  14213. * phba pointer to the lpfc_hba struct for this port.
  14214. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  14215. * routine when the rr_bmask is empty. The FCF indecies are put into the
  14216. * rr_bmask based on their priority level. Starting from the highest priority
  14217. * to the lowest. The most likely FCF candidate will be in the highest
  14218. * priority group. When this routine is called it searches the fcf_pri list for
  14219. * next lowest priority group and repopulates the rr_bmask with only those
  14220. * fcf_indexes.
  14221. * returns:
  14222. * 1=success 0=failure
  14223. **/
  14224. int
  14225. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  14226. {
  14227. uint16_t next_fcf_pri;
  14228. uint16_t last_index;
  14229. struct lpfc_fcf_pri *fcf_pri;
  14230. int rc;
  14231. int ret = 0;
  14232. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  14233. LPFC_SLI4_FCF_TBL_INDX_MAX);
  14234. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14235. "3060 Last IDX %d\n", last_index);
  14236. /* Verify the priority list has 2 or more entries */
  14237. spin_lock_irq(&phba->hbalock);
  14238. if (list_empty(&phba->fcf.fcf_pri_list) ||
  14239. list_is_singular(&phba->fcf.fcf_pri_list)) {
  14240. spin_unlock_irq(&phba->hbalock);
  14241. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14242. "3061 Last IDX %d\n", last_index);
  14243. return 0; /* Empty rr list */
  14244. }
  14245. spin_unlock_irq(&phba->hbalock);
  14246. next_fcf_pri = 0;
  14247. /*
  14248. * Clear the rr_bmask and set all of the bits that are at this
  14249. * priority.
  14250. */
  14251. memset(phba->fcf.fcf_rr_bmask, 0,
  14252. sizeof(*phba->fcf.fcf_rr_bmask));
  14253. spin_lock_irq(&phba->hbalock);
  14254. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14255. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  14256. continue;
  14257. /*
  14258. * the 1st priority that has not FLOGI failed
  14259. * will be the highest.
  14260. */
  14261. if (!next_fcf_pri)
  14262. next_fcf_pri = fcf_pri->fcf_rec.priority;
  14263. spin_unlock_irq(&phba->hbalock);
  14264. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  14265. rc = lpfc_sli4_fcf_rr_index_set(phba,
  14266. fcf_pri->fcf_rec.fcf_index);
  14267. if (rc)
  14268. return 0;
  14269. }
  14270. spin_lock_irq(&phba->hbalock);
  14271. }
  14272. /*
  14273. * if next_fcf_pri was not set above and the list is not empty then
  14274. * we have failed flogis on all of them. So reset flogi failed
  14275. * and start at the beginning.
  14276. */
  14277. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  14278. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14279. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  14280. /*
  14281. * the 1st priority that has not FLOGI failed
  14282. * will be the highest.
  14283. */
  14284. if (!next_fcf_pri)
  14285. next_fcf_pri = fcf_pri->fcf_rec.priority;
  14286. spin_unlock_irq(&phba->hbalock);
  14287. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  14288. rc = lpfc_sli4_fcf_rr_index_set(phba,
  14289. fcf_pri->fcf_rec.fcf_index);
  14290. if (rc)
  14291. return 0;
  14292. }
  14293. spin_lock_irq(&phba->hbalock);
  14294. }
  14295. } else
  14296. ret = 1;
  14297. spin_unlock_irq(&phba->hbalock);
  14298. return ret;
  14299. }
  14300. /**
  14301. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  14302. * @phba: pointer to lpfc hba data structure.
  14303. *
  14304. * This routine is to get the next eligible FCF record index in a round
  14305. * robin fashion. If the next eligible FCF record index equals to the
  14306. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  14307. * shall be returned, otherwise, the next eligible FCF record's index
  14308. * shall be returned.
  14309. **/
  14310. uint16_t
  14311. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  14312. {
  14313. uint16_t next_fcf_index;
  14314. initial_priority:
  14315. /* Search start from next bit of currently registered FCF index */
  14316. next_fcf_index = phba->fcf.current_rec.fcf_indx;
  14317. next_priority:
  14318. /* Determine the next fcf index to check */
  14319. next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
  14320. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14321. LPFC_SLI4_FCF_TBL_INDX_MAX,
  14322. next_fcf_index);
  14323. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  14324. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14325. /*
  14326. * If we have wrapped then we need to clear the bits that
  14327. * have been tested so that we can detect when we should
  14328. * change the priority level.
  14329. */
  14330. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14331. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  14332. }
  14333. /* Check roundrobin failover list empty condition */
  14334. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  14335. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  14336. /*
  14337. * If next fcf index is not found check if there are lower
  14338. * Priority level fcf's in the fcf_priority list.
  14339. * Set up the rr_bmask with all of the avaiable fcf bits
  14340. * at that level and continue the selection process.
  14341. */
  14342. if (lpfc_check_next_fcf_pri_level(phba))
  14343. goto initial_priority;
  14344. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14345. "2844 No roundrobin failover FCF available\n");
  14346. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  14347. return LPFC_FCOE_FCF_NEXT_NONE;
  14348. else {
  14349. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14350. "3063 Only FCF available idx %d, flag %x\n",
  14351. next_fcf_index,
  14352. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  14353. return next_fcf_index;
  14354. }
  14355. }
  14356. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  14357. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  14358. LPFC_FCF_FLOGI_FAILED)
  14359. goto next_priority;
  14360. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14361. "2845 Get next roundrobin failover FCF (x%x)\n",
  14362. next_fcf_index);
  14363. return next_fcf_index;
  14364. }
  14365. /**
  14366. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  14367. * @phba: pointer to lpfc hba data structure.
  14368. *
  14369. * This routine sets the FCF record index in to the eligible bmask for
  14370. * roundrobin failover search. It checks to make sure that the index
  14371. * does not go beyond the range of the driver allocated bmask dimension
  14372. * before setting the bit.
  14373. *
  14374. * Returns 0 if the index bit successfully set, otherwise, it returns
  14375. * -EINVAL.
  14376. **/
  14377. int
  14378. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  14379. {
  14380. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14381. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14382. "2610 FCF (x%x) reached driver's book "
  14383. "keeping dimension:x%x\n",
  14384. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14385. return -EINVAL;
  14386. }
  14387. /* Set the eligible FCF record index bmask */
  14388. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14389. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14390. "2790 Set FCF (x%x) to roundrobin FCF failover "
  14391. "bmask\n", fcf_index);
  14392. return 0;
  14393. }
  14394. /**
  14395. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  14396. * @phba: pointer to lpfc hba data structure.
  14397. *
  14398. * This routine clears the FCF record index from the eligible bmask for
  14399. * roundrobin failover search. It checks to make sure that the index
  14400. * does not go beyond the range of the driver allocated bmask dimension
  14401. * before clearing the bit.
  14402. **/
  14403. void
  14404. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  14405. {
  14406. struct lpfc_fcf_pri *fcf_pri;
  14407. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14408. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14409. "2762 FCF (x%x) reached driver's book "
  14410. "keeping dimension:x%x\n",
  14411. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14412. return;
  14413. }
  14414. /* Clear the eligible FCF record index bmask */
  14415. spin_lock_irq(&phba->hbalock);
  14416. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14417. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  14418. list_del_init(&fcf_pri->list);
  14419. break;
  14420. }
  14421. }
  14422. spin_unlock_irq(&phba->hbalock);
  14423. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14424. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14425. "2791 Clear FCF (x%x) from roundrobin failover "
  14426. "bmask\n", fcf_index);
  14427. }
  14428. /**
  14429. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  14430. * @phba: pointer to lpfc hba data structure.
  14431. *
  14432. * This routine is the completion routine for the rediscover FCF table mailbox
  14433. * command. If the mailbox command returned failure, it will try to stop the
  14434. * FCF rediscover wait timer.
  14435. **/
  14436. void
  14437. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  14438. {
  14439. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14440. uint32_t shdr_status, shdr_add_status;
  14441. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14442. shdr_status = bf_get(lpfc_mbox_hdr_status,
  14443. &redisc_fcf->header.cfg_shdr.response);
  14444. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  14445. &redisc_fcf->header.cfg_shdr.response);
  14446. if (shdr_status || shdr_add_status) {
  14447. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14448. "2746 Requesting for FCF rediscovery failed "
  14449. "status x%x add_status x%x\n",
  14450. shdr_status, shdr_add_status);
  14451. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  14452. spin_lock_irq(&phba->hbalock);
  14453. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  14454. spin_unlock_irq(&phba->hbalock);
  14455. /*
  14456. * CVL event triggered FCF rediscover request failed,
  14457. * last resort to re-try current registered FCF entry.
  14458. */
  14459. lpfc_retry_pport_discovery(phba);
  14460. } else {
  14461. spin_lock_irq(&phba->hbalock);
  14462. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  14463. spin_unlock_irq(&phba->hbalock);
  14464. /*
  14465. * DEAD FCF event triggered FCF rediscover request
  14466. * failed, last resort to fail over as a link down
  14467. * to FCF registration.
  14468. */
  14469. lpfc_sli4_fcf_dead_failthrough(phba);
  14470. }
  14471. } else {
  14472. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14473. "2775 Start FCF rediscover quiescent timer\n");
  14474. /*
  14475. * Start FCF rediscovery wait timer for pending FCF
  14476. * before rescan FCF record table.
  14477. */
  14478. lpfc_fcf_redisc_wait_start_timer(phba);
  14479. }
  14480. mempool_free(mbox, phba->mbox_mem_pool);
  14481. }
  14482. /**
  14483. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  14484. * @phba: pointer to lpfc hba data structure.
  14485. *
  14486. * This routine is invoked to request for rediscovery of the entire FCF table
  14487. * by the port.
  14488. **/
  14489. int
  14490. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  14491. {
  14492. LPFC_MBOXQ_t *mbox;
  14493. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14494. int rc, length;
  14495. /* Cancel retry delay timers to all vports before FCF rediscover */
  14496. lpfc_cancel_all_vport_retry_delay_timer(phba);
  14497. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14498. if (!mbox) {
  14499. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14500. "2745 Failed to allocate mbox for "
  14501. "requesting FCF rediscover.\n");
  14502. return -ENOMEM;
  14503. }
  14504. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  14505. sizeof(struct lpfc_sli4_cfg_mhdr));
  14506. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  14507. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  14508. length, LPFC_SLI4_MBX_EMBED);
  14509. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14510. /* Set count to 0 for invalidating the entire FCF database */
  14511. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  14512. /* Issue the mailbox command asynchronously */
  14513. mbox->vport = phba->pport;
  14514. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  14515. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  14516. if (rc == MBX_NOT_FINISHED) {
  14517. mempool_free(mbox, phba->mbox_mem_pool);
  14518. return -EIO;
  14519. }
  14520. return 0;
  14521. }
  14522. /**
  14523. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  14524. * @phba: pointer to lpfc hba data structure.
  14525. *
  14526. * This function is the failover routine as a last resort to the FCF DEAD
  14527. * event when driver failed to perform fast FCF failover.
  14528. **/
  14529. void
  14530. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  14531. {
  14532. uint32_t link_state;
  14533. /*
  14534. * Last resort as FCF DEAD event failover will treat this as
  14535. * a link down, but save the link state because we don't want
  14536. * it to be changed to Link Down unless it is already down.
  14537. */
  14538. link_state = phba->link_state;
  14539. lpfc_linkdown(phba);
  14540. phba->link_state = link_state;
  14541. /* Unregister FCF if no devices connected to it */
  14542. lpfc_unregister_unused_fcf(phba);
  14543. }
  14544. /**
  14545. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  14546. * @phba: pointer to lpfc hba data structure.
  14547. * @rgn23_data: pointer to configure region 23 data.
  14548. *
  14549. * This function gets SLI3 port configure region 23 data through memory dump
  14550. * mailbox command. When it successfully retrieves data, the size of the data
  14551. * will be returned, otherwise, 0 will be returned.
  14552. **/
  14553. static uint32_t
  14554. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14555. {
  14556. LPFC_MBOXQ_t *pmb = NULL;
  14557. MAILBOX_t *mb;
  14558. uint32_t offset = 0;
  14559. int rc;
  14560. if (!rgn23_data)
  14561. return 0;
  14562. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14563. if (!pmb) {
  14564. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14565. "2600 failed to allocate mailbox memory\n");
  14566. return 0;
  14567. }
  14568. mb = &pmb->u.mb;
  14569. do {
  14570. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  14571. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  14572. if (rc != MBX_SUCCESS) {
  14573. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  14574. "2601 failed to read config "
  14575. "region 23, rc 0x%x Status 0x%x\n",
  14576. rc, mb->mbxStatus);
  14577. mb->un.varDmp.word_cnt = 0;
  14578. }
  14579. /*
  14580. * dump mem may return a zero when finished or we got a
  14581. * mailbox error, either way we are done.
  14582. */
  14583. if (mb->un.varDmp.word_cnt == 0)
  14584. break;
  14585. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  14586. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  14587. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  14588. rgn23_data + offset,
  14589. mb->un.varDmp.word_cnt);
  14590. offset += mb->un.varDmp.word_cnt;
  14591. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  14592. mempool_free(pmb, phba->mbox_mem_pool);
  14593. return offset;
  14594. }
  14595. /**
  14596. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  14597. * @phba: pointer to lpfc hba data structure.
  14598. * @rgn23_data: pointer to configure region 23 data.
  14599. *
  14600. * This function gets SLI4 port configure region 23 data through memory dump
  14601. * mailbox command. When it successfully retrieves data, the size of the data
  14602. * will be returned, otherwise, 0 will be returned.
  14603. **/
  14604. static uint32_t
  14605. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14606. {
  14607. LPFC_MBOXQ_t *mboxq = NULL;
  14608. struct lpfc_dmabuf *mp = NULL;
  14609. struct lpfc_mqe *mqe;
  14610. uint32_t data_length = 0;
  14611. int rc;
  14612. if (!rgn23_data)
  14613. return 0;
  14614. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14615. if (!mboxq) {
  14616. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14617. "3105 failed to allocate mailbox memory\n");
  14618. return 0;
  14619. }
  14620. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  14621. goto out;
  14622. mqe = &mboxq->u.mqe;
  14623. mp = (struct lpfc_dmabuf *) mboxq->context1;
  14624. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14625. if (rc)
  14626. goto out;
  14627. data_length = mqe->un.mb_words[5];
  14628. if (data_length == 0)
  14629. goto out;
  14630. if (data_length > DMP_RGN23_SIZE) {
  14631. data_length = 0;
  14632. goto out;
  14633. }
  14634. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  14635. out:
  14636. mempool_free(mboxq, phba->mbox_mem_pool);
  14637. if (mp) {
  14638. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14639. kfree(mp);
  14640. }
  14641. return data_length;
  14642. }
  14643. /**
  14644. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  14645. * @phba: pointer to lpfc hba data structure.
  14646. *
  14647. * This function read region 23 and parse TLV for port status to
  14648. * decide if the user disaled the port. If the TLV indicates the
  14649. * port is disabled, the hba_flag is set accordingly.
  14650. **/
  14651. void
  14652. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  14653. {
  14654. uint8_t *rgn23_data = NULL;
  14655. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  14656. uint32_t offset = 0;
  14657. /* Get adapter Region 23 data */
  14658. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  14659. if (!rgn23_data)
  14660. goto out;
  14661. if (phba->sli_rev < LPFC_SLI_REV4)
  14662. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  14663. else {
  14664. if_type = bf_get(lpfc_sli_intf_if_type,
  14665. &phba->sli4_hba.sli_intf);
  14666. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  14667. goto out;
  14668. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  14669. }
  14670. if (!data_size)
  14671. goto out;
  14672. /* Check the region signature first */
  14673. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  14674. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14675. "2619 Config region 23 has bad signature\n");
  14676. goto out;
  14677. }
  14678. offset += 4;
  14679. /* Check the data structure version */
  14680. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  14681. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14682. "2620 Config region 23 has bad version\n");
  14683. goto out;
  14684. }
  14685. offset += 4;
  14686. /* Parse TLV entries in the region */
  14687. while (offset < data_size) {
  14688. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  14689. break;
  14690. /*
  14691. * If the TLV is not driver specific TLV or driver id is
  14692. * not linux driver id, skip the record.
  14693. */
  14694. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  14695. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  14696. (rgn23_data[offset + 3] != 0)) {
  14697. offset += rgn23_data[offset + 1] * 4 + 4;
  14698. continue;
  14699. }
  14700. /* Driver found a driver specific TLV in the config region */
  14701. sub_tlv_len = rgn23_data[offset + 1] * 4;
  14702. offset += 4;
  14703. tlv_offset = 0;
  14704. /*
  14705. * Search for configured port state sub-TLV.
  14706. */
  14707. while ((offset < data_size) &&
  14708. (tlv_offset < sub_tlv_len)) {
  14709. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  14710. offset += 4;
  14711. tlv_offset += 4;
  14712. break;
  14713. }
  14714. if (rgn23_data[offset] != PORT_STE_TYPE) {
  14715. offset += rgn23_data[offset + 1] * 4 + 4;
  14716. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  14717. continue;
  14718. }
  14719. /* This HBA contains PORT_STE configured */
  14720. if (!rgn23_data[offset + 2])
  14721. phba->hba_flag |= LINK_DISABLED;
  14722. goto out;
  14723. }
  14724. }
  14725. out:
  14726. kfree(rgn23_data);
  14727. return;
  14728. }
  14729. /**
  14730. * lpfc_wr_object - write an object to the firmware
  14731. * @phba: HBA structure that indicates port to create a queue on.
  14732. * @dmabuf_list: list of dmabufs to write to the port.
  14733. * @size: the total byte value of the objects to write to the port.
  14734. * @offset: the current offset to be used to start the transfer.
  14735. *
  14736. * This routine will create a wr_object mailbox command to send to the port.
  14737. * the mailbox command will be constructed using the dma buffers described in
  14738. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  14739. * BDEs that the imbedded mailbox can support. The @offset variable will be
  14740. * used to indicate the starting offset of the transfer and will also return
  14741. * the offset after the write object mailbox has completed. @size is used to
  14742. * determine the end of the object and whether the eof bit should be set.
  14743. *
  14744. * Return 0 is successful and offset will contain the the new offset to use
  14745. * for the next write.
  14746. * Return negative value for error cases.
  14747. **/
  14748. int
  14749. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  14750. uint32_t size, uint32_t *offset)
  14751. {
  14752. struct lpfc_mbx_wr_object *wr_object;
  14753. LPFC_MBOXQ_t *mbox;
  14754. int rc = 0, i = 0;
  14755. uint32_t shdr_status, shdr_add_status;
  14756. uint32_t mbox_tmo;
  14757. union lpfc_sli4_cfg_shdr *shdr;
  14758. struct lpfc_dmabuf *dmabuf;
  14759. uint32_t written = 0;
  14760. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14761. if (!mbox)
  14762. return -ENOMEM;
  14763. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14764. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  14765. sizeof(struct lpfc_mbx_wr_object) -
  14766. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  14767. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  14768. wr_object->u.request.write_offset = *offset;
  14769. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  14770. wr_object->u.request.object_name[0] =
  14771. cpu_to_le32(wr_object->u.request.object_name[0]);
  14772. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  14773. list_for_each_entry(dmabuf, dmabuf_list, list) {
  14774. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  14775. break;
  14776. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  14777. wr_object->u.request.bde[i].addrHigh =
  14778. putPaddrHigh(dmabuf->phys);
  14779. if (written + SLI4_PAGE_SIZE >= size) {
  14780. wr_object->u.request.bde[i].tus.f.bdeSize =
  14781. (size - written);
  14782. written += (size - written);
  14783. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  14784. } else {
  14785. wr_object->u.request.bde[i].tus.f.bdeSize =
  14786. SLI4_PAGE_SIZE;
  14787. written += SLI4_PAGE_SIZE;
  14788. }
  14789. i++;
  14790. }
  14791. wr_object->u.request.bde_count = i;
  14792. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  14793. if (!phba->sli4_hba.intr_enable)
  14794. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14795. else {
  14796. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  14797. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  14798. }
  14799. /* The IOCTL status is embedded in the mailbox subheader. */
  14800. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  14801. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14802. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14803. if (rc != MBX_TIMEOUT)
  14804. mempool_free(mbox, phba->mbox_mem_pool);
  14805. if (shdr_status || shdr_add_status || rc) {
  14806. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14807. "3025 Write Object mailbox failed with "
  14808. "status x%x add_status x%x, mbx status x%x\n",
  14809. shdr_status, shdr_add_status, rc);
  14810. rc = -ENXIO;
  14811. } else
  14812. *offset += wr_object->u.response.actual_write_length;
  14813. return rc;
  14814. }
  14815. /**
  14816. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  14817. * @vport: pointer to vport data structure.
  14818. *
  14819. * This function iterate through the mailboxq and clean up all REG_LOGIN
  14820. * and REG_VPI mailbox commands associated with the vport. This function
  14821. * is called when driver want to restart discovery of the vport due to
  14822. * a Clear Virtual Link event.
  14823. **/
  14824. void
  14825. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  14826. {
  14827. struct lpfc_hba *phba = vport->phba;
  14828. LPFC_MBOXQ_t *mb, *nextmb;
  14829. struct lpfc_dmabuf *mp;
  14830. struct lpfc_nodelist *ndlp;
  14831. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  14832. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  14833. LIST_HEAD(mbox_cmd_list);
  14834. uint8_t restart_loop;
  14835. /* Clean up internally queued mailbox commands with the vport */
  14836. spin_lock_irq(&phba->hbalock);
  14837. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  14838. if (mb->vport != vport)
  14839. continue;
  14840. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14841. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14842. continue;
  14843. list_del(&mb->list);
  14844. list_add_tail(&mb->list, &mbox_cmd_list);
  14845. }
  14846. /* Clean up active mailbox command with the vport */
  14847. mb = phba->sli.mbox_active;
  14848. if (mb && (mb->vport == vport)) {
  14849. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  14850. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  14851. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14852. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14853. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  14854. /* Put reference count for delayed processing */
  14855. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  14856. /* Unregister the RPI when mailbox complete */
  14857. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14858. }
  14859. }
  14860. /* Cleanup any mailbox completions which are not yet processed */
  14861. do {
  14862. restart_loop = 0;
  14863. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  14864. /*
  14865. * If this mailox is already processed or it is
  14866. * for another vport ignore it.
  14867. */
  14868. if ((mb->vport != vport) ||
  14869. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  14870. continue;
  14871. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14872. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14873. continue;
  14874. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14875. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14876. ndlp = (struct lpfc_nodelist *)mb->context2;
  14877. /* Unregister the RPI when mailbox complete */
  14878. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14879. restart_loop = 1;
  14880. spin_unlock_irq(&phba->hbalock);
  14881. spin_lock(shost->host_lock);
  14882. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14883. spin_unlock(shost->host_lock);
  14884. spin_lock_irq(&phba->hbalock);
  14885. break;
  14886. }
  14887. }
  14888. } while (restart_loop);
  14889. spin_unlock_irq(&phba->hbalock);
  14890. /* Release the cleaned-up mailbox commands */
  14891. while (!list_empty(&mbox_cmd_list)) {
  14892. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  14893. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14894. mp = (struct lpfc_dmabuf *) (mb->context1);
  14895. if (mp) {
  14896. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14897. kfree(mp);
  14898. }
  14899. ndlp = (struct lpfc_nodelist *) mb->context2;
  14900. mb->context2 = NULL;
  14901. if (ndlp) {
  14902. spin_lock(shost->host_lock);
  14903. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14904. spin_unlock(shost->host_lock);
  14905. lpfc_nlp_put(ndlp);
  14906. }
  14907. }
  14908. mempool_free(mb, phba->mbox_mem_pool);
  14909. }
  14910. /* Release the ndlp with the cleaned-up active mailbox command */
  14911. if (act_mbx_ndlp) {
  14912. spin_lock(shost->host_lock);
  14913. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14914. spin_unlock(shost->host_lock);
  14915. lpfc_nlp_put(act_mbx_ndlp);
  14916. }
  14917. }
  14918. /**
  14919. * lpfc_drain_txq - Drain the txq
  14920. * @phba: Pointer to HBA context object.
  14921. *
  14922. * This function attempt to submit IOCBs on the txq
  14923. * to the adapter. For SLI4 adapters, the txq contains
  14924. * ELS IOCBs that have been deferred because the there
  14925. * are no SGLs. This congestion can occur with large
  14926. * vport counts during node discovery.
  14927. **/
  14928. uint32_t
  14929. lpfc_drain_txq(struct lpfc_hba *phba)
  14930. {
  14931. LIST_HEAD(completions);
  14932. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  14933. struct lpfc_iocbq *piocbq = 0;
  14934. unsigned long iflags = 0;
  14935. char *fail_msg = NULL;
  14936. struct lpfc_sglq *sglq;
  14937. union lpfc_wqe wqe;
  14938. int txq_cnt = 0;
  14939. spin_lock_irqsave(&phba->hbalock, iflags);
  14940. list_for_each_entry(piocbq, &pring->txq, list) {
  14941. txq_cnt++;
  14942. }
  14943. if (txq_cnt > pring->txq_max)
  14944. pring->txq_max = txq_cnt;
  14945. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14946. while (!list_empty(&pring->txq)) {
  14947. spin_lock_irqsave(&phba->hbalock, iflags);
  14948. piocbq = lpfc_sli_ringtx_get(phba, pring);
  14949. if (!piocbq) {
  14950. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14951. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14952. "2823 txq empty and txq_cnt is %d\n ",
  14953. txq_cnt);
  14954. break;
  14955. }
  14956. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  14957. if (!sglq) {
  14958. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  14959. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14960. break;
  14961. }
  14962. txq_cnt--;
  14963. /* The xri and iocb resources secured,
  14964. * attempt to issue request
  14965. */
  14966. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  14967. piocbq->sli4_xritag = sglq->sli4_xritag;
  14968. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  14969. fail_msg = "to convert bpl to sgl";
  14970. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  14971. fail_msg = "to convert iocb to wqe";
  14972. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  14973. fail_msg = " - Wq is full";
  14974. else
  14975. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  14976. if (fail_msg) {
  14977. /* Failed means we can't issue and need to cancel */
  14978. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14979. "2822 IOCB failed %s iotag 0x%x "
  14980. "xri 0x%x\n",
  14981. fail_msg,
  14982. piocbq->iotag, piocbq->sli4_xritag);
  14983. list_add_tail(&piocbq->list, &completions);
  14984. }
  14985. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14986. }
  14987. /* Cancel all the IOCBs that cannot be issued */
  14988. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  14989. IOERR_SLI_ABORTED);
  14990. return txq_cnt;
  14991. }