lpfc_sli.c 500 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356
  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.ulpCommand == CMD_ELS_REQUEST64_CR) &&
  847. (piocbq->iocb_flag & LPFC_IO_LIBDFC))
  848. ndlp = piocbq->context_un.ndlp;
  849. else
  850. ndlp = piocbq->context1;
  851. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  852. start_sglq = sglq;
  853. while (!found) {
  854. if (!sglq)
  855. return NULL;
  856. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) {
  857. /* This xri has an rrq outstanding for this DID.
  858. * put it back in the list and get another xri.
  859. */
  860. list_add_tail(&sglq->list, lpfc_sgl_list);
  861. sglq = NULL;
  862. list_remove_head(lpfc_sgl_list, sglq,
  863. struct lpfc_sglq, list);
  864. if (sglq == start_sglq) {
  865. sglq = NULL;
  866. break;
  867. } else
  868. continue;
  869. }
  870. sglq->ndlp = ndlp;
  871. found = 1;
  872. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  873. sglq->state = SGL_ALLOCATED;
  874. }
  875. return sglq;
  876. }
  877. /**
  878. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  879. * @phba: Pointer to HBA context object.
  880. *
  881. * This function is called with no lock held. This function
  882. * allocates a new driver iocb object from the iocb pool. If the
  883. * allocation is successful, it returns pointer to the newly
  884. * allocated iocb object else it returns NULL.
  885. **/
  886. struct lpfc_iocbq *
  887. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  888. {
  889. struct lpfc_iocbq * iocbq = NULL;
  890. unsigned long iflags;
  891. spin_lock_irqsave(&phba->hbalock, iflags);
  892. iocbq = __lpfc_sli_get_iocbq(phba);
  893. spin_unlock_irqrestore(&phba->hbalock, iflags);
  894. return iocbq;
  895. }
  896. /**
  897. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  898. * @phba: Pointer to HBA context object.
  899. * @iocbq: Pointer to driver iocb object.
  900. *
  901. * This function is called with hbalock held to release driver
  902. * iocb object to the iocb pool. The iotag in the iocb object
  903. * does not change for each use of the iocb object. This function
  904. * clears all other fields of the iocb object when it is freed.
  905. * The sqlq structure that holds the xritag and phys and virtual
  906. * mappings for the scatter gather list is retrieved from the
  907. * active array of sglq. The get of the sglq pointer also clears
  908. * the entry in the array. If the status of the IO indiactes that
  909. * this IO was aborted then the sglq entry it put on the
  910. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  911. * IO has good status or fails for any other reason then the sglq
  912. * entry is added to the free list (lpfc_sgl_list).
  913. **/
  914. static void
  915. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  916. {
  917. struct lpfc_sglq *sglq;
  918. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  919. unsigned long iflag = 0;
  920. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  921. if (iocbq->sli4_xritag == NO_XRI)
  922. sglq = NULL;
  923. else
  924. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  925. /*
  926. ** This should have been removed from the txcmplq before calling
  927. ** iocbq_release. The normal completion
  928. ** path should have already done the list_del_init.
  929. */
  930. if (unlikely(!list_empty(&iocbq->list))) {
  931. if (iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)
  932. iocbq->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  933. list_del_init(&iocbq->list);
  934. }
  935. if (sglq) {
  936. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  937. (sglq->state != SGL_XRI_ABORTED)) {
  938. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  939. iflag);
  940. list_add(&sglq->list,
  941. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  942. spin_unlock_irqrestore(
  943. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  944. } else {
  945. sglq->state = SGL_FREED;
  946. sglq->ndlp = NULL;
  947. list_add_tail(&sglq->list,
  948. &phba->sli4_hba.lpfc_sgl_list);
  949. /* Check if TXQ queue needs to be serviced */
  950. if (!list_empty(&pring->txq))
  951. lpfc_worker_wake_up(phba);
  952. }
  953. }
  954. /*
  955. * Clean all volatile data fields, preserve iotag and node struct.
  956. */
  957. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  958. iocbq->sli4_lxritag = NO_XRI;
  959. iocbq->sli4_xritag = NO_XRI;
  960. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  961. }
  962. /**
  963. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  964. * @phba: Pointer to HBA context object.
  965. * @iocbq: Pointer to driver iocb object.
  966. *
  967. * This function is called with hbalock held to release driver
  968. * iocb object to the iocb pool. The iotag in the iocb object
  969. * does not change for each use of the iocb object. This function
  970. * clears all other fields of the iocb object when it is freed.
  971. **/
  972. static void
  973. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  974. {
  975. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  976. /*
  977. ** This should have been removed from the txcmplq before calling
  978. ** iocbq_release. The normal completion
  979. ** path should have already done the list_del_init.
  980. */
  981. if (unlikely(!list_empty(&iocbq->list)))
  982. list_del_init(&iocbq->list);
  983. /*
  984. * Clean all volatile data fields, preserve iotag and node struct.
  985. */
  986. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  987. iocbq->sli4_xritag = NO_XRI;
  988. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  989. }
  990. /**
  991. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  992. * @phba: Pointer to HBA context object.
  993. * @iocbq: Pointer to driver iocb object.
  994. *
  995. * This function is called with hbalock held to release driver
  996. * iocb object to the iocb pool. The iotag in the iocb object
  997. * does not change for each use of the iocb object. This function
  998. * clears all other fields of the iocb object when it is freed.
  999. **/
  1000. static void
  1001. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1002. {
  1003. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  1004. phba->iocb_cnt--;
  1005. }
  1006. /**
  1007. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  1008. * @phba: Pointer to HBA context object.
  1009. * @iocbq: Pointer to driver iocb object.
  1010. *
  1011. * This function is called with no lock held to release the iocb to
  1012. * iocb pool.
  1013. **/
  1014. void
  1015. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1016. {
  1017. unsigned long iflags;
  1018. /*
  1019. * Clean all volatile data fields, preserve iotag and node struct.
  1020. */
  1021. spin_lock_irqsave(&phba->hbalock, iflags);
  1022. __lpfc_sli_release_iocbq(phba, iocbq);
  1023. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1024. }
  1025. /**
  1026. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  1027. * @phba: Pointer to HBA context object.
  1028. * @iocblist: List of IOCBs.
  1029. * @ulpstatus: ULP status in IOCB command field.
  1030. * @ulpWord4: ULP word-4 in IOCB command field.
  1031. *
  1032. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  1033. * on the list by invoking the complete callback function associated with the
  1034. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  1035. * fields.
  1036. **/
  1037. void
  1038. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  1039. uint32_t ulpstatus, uint32_t ulpWord4)
  1040. {
  1041. struct lpfc_iocbq *piocb;
  1042. while (!list_empty(iocblist)) {
  1043. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  1044. if (!piocb->iocb_cmpl)
  1045. lpfc_sli_release_iocbq(phba, piocb);
  1046. else {
  1047. piocb->iocb.ulpStatus = ulpstatus;
  1048. piocb->iocb.un.ulpWord[4] = ulpWord4;
  1049. (piocb->iocb_cmpl) (phba, piocb, piocb);
  1050. }
  1051. }
  1052. return;
  1053. }
  1054. /**
  1055. * lpfc_sli_iocb_cmd_type - Get the iocb type
  1056. * @iocb_cmnd: iocb command code.
  1057. *
  1058. * This function is called by ring event handler function to get the iocb type.
  1059. * This function translates the iocb command to an iocb command type used to
  1060. * decide the final disposition of each completed IOCB.
  1061. * The function returns
  1062. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1063. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1064. * LPFC_ABORT_IOCB if it is an abort iocb
  1065. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1066. *
  1067. * The caller is not required to hold any lock.
  1068. **/
  1069. static lpfc_iocb_type
  1070. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1071. {
  1072. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1073. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1074. return 0;
  1075. switch (iocb_cmnd) {
  1076. case CMD_XMIT_SEQUENCE_CR:
  1077. case CMD_XMIT_SEQUENCE_CX:
  1078. case CMD_XMIT_BCAST_CN:
  1079. case CMD_XMIT_BCAST_CX:
  1080. case CMD_ELS_REQUEST_CR:
  1081. case CMD_ELS_REQUEST_CX:
  1082. case CMD_CREATE_XRI_CR:
  1083. case CMD_CREATE_XRI_CX:
  1084. case CMD_GET_RPI_CN:
  1085. case CMD_XMIT_ELS_RSP_CX:
  1086. case CMD_GET_RPI_CR:
  1087. case CMD_FCP_IWRITE_CR:
  1088. case CMD_FCP_IWRITE_CX:
  1089. case CMD_FCP_IREAD_CR:
  1090. case CMD_FCP_IREAD_CX:
  1091. case CMD_FCP_ICMND_CR:
  1092. case CMD_FCP_ICMND_CX:
  1093. case CMD_FCP_TSEND_CX:
  1094. case CMD_FCP_TRSP_CX:
  1095. case CMD_FCP_TRECEIVE_CX:
  1096. case CMD_FCP_AUTO_TRSP_CX:
  1097. case CMD_ADAPTER_MSG:
  1098. case CMD_ADAPTER_DUMP:
  1099. case CMD_XMIT_SEQUENCE64_CR:
  1100. case CMD_XMIT_SEQUENCE64_CX:
  1101. case CMD_XMIT_BCAST64_CN:
  1102. case CMD_XMIT_BCAST64_CX:
  1103. case CMD_ELS_REQUEST64_CR:
  1104. case CMD_ELS_REQUEST64_CX:
  1105. case CMD_FCP_IWRITE64_CR:
  1106. case CMD_FCP_IWRITE64_CX:
  1107. case CMD_FCP_IREAD64_CR:
  1108. case CMD_FCP_IREAD64_CX:
  1109. case CMD_FCP_ICMND64_CR:
  1110. case CMD_FCP_ICMND64_CX:
  1111. case CMD_FCP_TSEND64_CX:
  1112. case CMD_FCP_TRSP64_CX:
  1113. case CMD_FCP_TRECEIVE64_CX:
  1114. case CMD_GEN_REQUEST64_CR:
  1115. case CMD_GEN_REQUEST64_CX:
  1116. case CMD_XMIT_ELS_RSP64_CX:
  1117. case DSSCMD_IWRITE64_CR:
  1118. case DSSCMD_IWRITE64_CX:
  1119. case DSSCMD_IREAD64_CR:
  1120. case DSSCMD_IREAD64_CX:
  1121. type = LPFC_SOL_IOCB;
  1122. break;
  1123. case CMD_ABORT_XRI_CN:
  1124. case CMD_ABORT_XRI_CX:
  1125. case CMD_CLOSE_XRI_CN:
  1126. case CMD_CLOSE_XRI_CX:
  1127. case CMD_XRI_ABORTED_CX:
  1128. case CMD_ABORT_MXRI64_CN:
  1129. case CMD_XMIT_BLS_RSP64_CX:
  1130. type = LPFC_ABORT_IOCB;
  1131. break;
  1132. case CMD_RCV_SEQUENCE_CX:
  1133. case CMD_RCV_ELS_REQ_CX:
  1134. case CMD_RCV_SEQUENCE64_CX:
  1135. case CMD_RCV_ELS_REQ64_CX:
  1136. case CMD_ASYNC_STATUS:
  1137. case CMD_IOCB_RCV_SEQ64_CX:
  1138. case CMD_IOCB_RCV_ELS64_CX:
  1139. case CMD_IOCB_RCV_CONT64_CX:
  1140. case CMD_IOCB_RET_XRI64_CX:
  1141. type = LPFC_UNSOL_IOCB;
  1142. break;
  1143. case CMD_IOCB_XMIT_MSEQ64_CR:
  1144. case CMD_IOCB_XMIT_MSEQ64_CX:
  1145. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1146. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1147. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1148. case CMD_IOCB_ABORT_EXTENDED_CN:
  1149. case CMD_IOCB_RET_HBQE64_CN:
  1150. case CMD_IOCB_FCP_IBIDIR64_CR:
  1151. case CMD_IOCB_FCP_IBIDIR64_CX:
  1152. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1153. case CMD_IOCB_LOGENTRY_CN:
  1154. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1155. printk("%s - Unhandled SLI-3 Command x%x\n",
  1156. __func__, iocb_cmnd);
  1157. type = LPFC_UNKNOWN_IOCB;
  1158. break;
  1159. default:
  1160. type = LPFC_UNKNOWN_IOCB;
  1161. break;
  1162. }
  1163. return type;
  1164. }
  1165. /**
  1166. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1167. * @phba: Pointer to HBA context object.
  1168. *
  1169. * This function is called from SLI initialization code
  1170. * to configure every ring of the HBA's SLI interface. The
  1171. * caller is not required to hold any lock. This function issues
  1172. * a config_ring mailbox command for each ring.
  1173. * This function returns zero if successful else returns a negative
  1174. * error code.
  1175. **/
  1176. static int
  1177. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1178. {
  1179. struct lpfc_sli *psli = &phba->sli;
  1180. LPFC_MBOXQ_t *pmb;
  1181. MAILBOX_t *pmbox;
  1182. int i, rc, ret = 0;
  1183. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1184. if (!pmb)
  1185. return -ENOMEM;
  1186. pmbox = &pmb->u.mb;
  1187. phba->link_state = LPFC_INIT_MBX_CMDS;
  1188. for (i = 0; i < psli->num_rings; i++) {
  1189. lpfc_config_ring(phba, i, pmb);
  1190. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1191. if (rc != MBX_SUCCESS) {
  1192. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1193. "0446 Adapter failed to init (%d), "
  1194. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1195. "ring %d\n",
  1196. rc, pmbox->mbxCommand,
  1197. pmbox->mbxStatus, i);
  1198. phba->link_state = LPFC_HBA_ERROR;
  1199. ret = -ENXIO;
  1200. break;
  1201. }
  1202. }
  1203. mempool_free(pmb, phba->mbox_mem_pool);
  1204. return ret;
  1205. }
  1206. /**
  1207. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1208. * @phba: Pointer to HBA context object.
  1209. * @pring: Pointer to driver SLI ring object.
  1210. * @piocb: Pointer to the driver iocb object.
  1211. *
  1212. * This function is called with hbalock held. The function adds the
  1213. * new iocb to txcmplq of the given ring. This function always returns
  1214. * 0. If this function is called for ELS ring, this function checks if
  1215. * there is a vport associated with the ELS command. This function also
  1216. * starts els_tmofunc timer if this is an ELS command.
  1217. **/
  1218. static int
  1219. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1220. struct lpfc_iocbq *piocb)
  1221. {
  1222. list_add_tail(&piocb->list, &pring->txcmplq);
  1223. piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
  1224. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1225. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1226. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1227. if (!piocb->vport)
  1228. BUG();
  1229. else
  1230. mod_timer(&piocb->vport->els_tmofunc,
  1231. jiffies +
  1232. msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
  1233. }
  1234. return 0;
  1235. }
  1236. /**
  1237. * lpfc_sli_ringtx_get - Get first element of the txq
  1238. * @phba: Pointer to HBA context object.
  1239. * @pring: Pointer to driver SLI ring object.
  1240. *
  1241. * This function is called with hbalock held to get next
  1242. * iocb in txq of the given ring. If there is any iocb in
  1243. * the txq, the function returns first iocb in the list after
  1244. * removing the iocb from the list, else it returns NULL.
  1245. **/
  1246. struct lpfc_iocbq *
  1247. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1248. {
  1249. struct lpfc_iocbq *cmd_iocb;
  1250. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1251. return cmd_iocb;
  1252. }
  1253. /**
  1254. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1255. * @phba: Pointer to HBA context object.
  1256. * @pring: Pointer to driver SLI ring object.
  1257. *
  1258. * This function is called with hbalock held and the caller must post the
  1259. * iocb without releasing the lock. If the caller releases the lock,
  1260. * iocb slot returned by the function is not guaranteed to be available.
  1261. * The function returns pointer to the next available iocb slot if there
  1262. * is available slot in the ring, else it returns NULL.
  1263. * If the get index of the ring is ahead of the put index, the function
  1264. * will post an error attention event to the worker thread to take the
  1265. * HBA to offline state.
  1266. **/
  1267. static IOCB_t *
  1268. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1269. {
  1270. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1271. uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
  1272. if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
  1273. (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
  1274. pring->sli.sli3.next_cmdidx = 0;
  1275. if (unlikely(pring->sli.sli3.local_getidx ==
  1276. pring->sli.sli3.next_cmdidx)) {
  1277. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1278. if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
  1279. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1280. "0315 Ring %d issue: portCmdGet %d "
  1281. "is bigger than cmd ring %d\n",
  1282. pring->ringno,
  1283. pring->sli.sli3.local_getidx,
  1284. max_cmd_idx);
  1285. phba->link_state = LPFC_HBA_ERROR;
  1286. /*
  1287. * All error attention handlers are posted to
  1288. * worker thread
  1289. */
  1290. phba->work_ha |= HA_ERATT;
  1291. phba->work_hs = HS_FFER3;
  1292. lpfc_worker_wake_up(phba);
  1293. return NULL;
  1294. }
  1295. if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
  1296. return NULL;
  1297. }
  1298. return lpfc_cmd_iocb(phba, pring);
  1299. }
  1300. /**
  1301. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1302. * @phba: Pointer to HBA context object.
  1303. * @iocbq: Pointer to driver iocb object.
  1304. *
  1305. * This function gets an iotag for the iocb. If there is no unused iotag and
  1306. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1307. * array and assigns a new iotag.
  1308. * The function returns the allocated iotag if successful, else returns zero.
  1309. * Zero is not a valid iotag.
  1310. * The caller is not required to hold any lock.
  1311. **/
  1312. uint16_t
  1313. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1314. {
  1315. struct lpfc_iocbq **new_arr;
  1316. struct lpfc_iocbq **old_arr;
  1317. size_t new_len;
  1318. struct lpfc_sli *psli = &phba->sli;
  1319. uint16_t iotag;
  1320. spin_lock_irq(&phba->hbalock);
  1321. iotag = psli->last_iotag;
  1322. if(++iotag < psli->iocbq_lookup_len) {
  1323. psli->last_iotag = iotag;
  1324. psli->iocbq_lookup[iotag] = iocbq;
  1325. spin_unlock_irq(&phba->hbalock);
  1326. iocbq->iotag = iotag;
  1327. return iotag;
  1328. } else if (psli->iocbq_lookup_len < (0xffff
  1329. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1330. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1331. spin_unlock_irq(&phba->hbalock);
  1332. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1333. GFP_KERNEL);
  1334. if (new_arr) {
  1335. spin_lock_irq(&phba->hbalock);
  1336. old_arr = psli->iocbq_lookup;
  1337. if (new_len <= psli->iocbq_lookup_len) {
  1338. /* highly unprobable case */
  1339. kfree(new_arr);
  1340. iotag = psli->last_iotag;
  1341. if(++iotag < psli->iocbq_lookup_len) {
  1342. psli->last_iotag = iotag;
  1343. psli->iocbq_lookup[iotag] = iocbq;
  1344. spin_unlock_irq(&phba->hbalock);
  1345. iocbq->iotag = iotag;
  1346. return iotag;
  1347. }
  1348. spin_unlock_irq(&phba->hbalock);
  1349. return 0;
  1350. }
  1351. if (psli->iocbq_lookup)
  1352. memcpy(new_arr, old_arr,
  1353. ((psli->last_iotag + 1) *
  1354. sizeof (struct lpfc_iocbq *)));
  1355. psli->iocbq_lookup = new_arr;
  1356. psli->iocbq_lookup_len = new_len;
  1357. psli->last_iotag = iotag;
  1358. psli->iocbq_lookup[iotag] = iocbq;
  1359. spin_unlock_irq(&phba->hbalock);
  1360. iocbq->iotag = iotag;
  1361. kfree(old_arr);
  1362. return iotag;
  1363. }
  1364. } else
  1365. spin_unlock_irq(&phba->hbalock);
  1366. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1367. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1368. psli->last_iotag);
  1369. return 0;
  1370. }
  1371. /**
  1372. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1373. * @phba: Pointer to HBA context object.
  1374. * @pring: Pointer to driver SLI ring object.
  1375. * @iocb: Pointer to iocb slot in the ring.
  1376. * @nextiocb: Pointer to driver iocb object which need to be
  1377. * posted to firmware.
  1378. *
  1379. * This function is called with hbalock held to post a new iocb to
  1380. * the firmware. This function copies the new iocb to ring iocb slot and
  1381. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1382. * a completion call back for this iocb else the function will free the
  1383. * iocb object.
  1384. **/
  1385. static void
  1386. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1387. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1388. {
  1389. /*
  1390. * Set up an iotag
  1391. */
  1392. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1393. if (pring->ringno == LPFC_ELS_RING) {
  1394. lpfc_debugfs_slow_ring_trc(phba,
  1395. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1396. *(((uint32_t *) &nextiocb->iocb) + 4),
  1397. *(((uint32_t *) &nextiocb->iocb) + 6),
  1398. *(((uint32_t *) &nextiocb->iocb) + 7));
  1399. }
  1400. /*
  1401. * Issue iocb command to adapter
  1402. */
  1403. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1404. wmb();
  1405. pring->stats.iocb_cmd++;
  1406. /*
  1407. * If there is no completion routine to call, we can release the
  1408. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1409. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1410. */
  1411. if (nextiocb->iocb_cmpl)
  1412. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1413. else
  1414. __lpfc_sli_release_iocbq(phba, nextiocb);
  1415. /*
  1416. * Let the HBA know what IOCB slot will be the next one the
  1417. * driver will put a command into.
  1418. */
  1419. pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
  1420. writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1421. }
  1422. /**
  1423. * lpfc_sli_update_full_ring - Update the chip attention register
  1424. * @phba: Pointer to HBA context object.
  1425. * @pring: Pointer to driver SLI ring object.
  1426. *
  1427. * The caller is not required to hold any lock for calling this function.
  1428. * This function updates the chip attention bits for the ring to inform firmware
  1429. * that there are pending work to be done for this ring and requests an
  1430. * interrupt when there is space available in the ring. This function is
  1431. * called when the driver is unable to post more iocbs to the ring due
  1432. * to unavailability of space in the ring.
  1433. **/
  1434. static void
  1435. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1436. {
  1437. int ringno = pring->ringno;
  1438. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1439. wmb();
  1440. /*
  1441. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1442. * The HBA will tell us when an IOCB entry is available.
  1443. */
  1444. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1445. readl(phba->CAregaddr); /* flush */
  1446. pring->stats.iocb_cmd_full++;
  1447. }
  1448. /**
  1449. * lpfc_sli_update_ring - Update chip attention register
  1450. * @phba: Pointer to HBA context object.
  1451. * @pring: Pointer to driver SLI ring object.
  1452. *
  1453. * This function updates the chip attention register bit for the
  1454. * given ring to inform HBA that there is more work to be done
  1455. * in this ring. The caller is not required to hold any lock.
  1456. **/
  1457. static void
  1458. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1459. {
  1460. int ringno = pring->ringno;
  1461. /*
  1462. * Tell the HBA that there is work to do in this ring.
  1463. */
  1464. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1465. wmb();
  1466. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1467. readl(phba->CAregaddr); /* flush */
  1468. }
  1469. }
  1470. /**
  1471. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1472. * @phba: Pointer to HBA context object.
  1473. * @pring: Pointer to driver SLI ring object.
  1474. *
  1475. * This function is called with hbalock held to post pending iocbs
  1476. * in the txq to the firmware. This function is called when driver
  1477. * detects space available in the ring.
  1478. **/
  1479. static void
  1480. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1481. {
  1482. IOCB_t *iocb;
  1483. struct lpfc_iocbq *nextiocb;
  1484. /*
  1485. * Check to see if:
  1486. * (a) there is anything on the txq to send
  1487. * (b) link is up
  1488. * (c) link attention events can be processed (fcp ring only)
  1489. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1490. */
  1491. if (lpfc_is_link_up(phba) &&
  1492. (!list_empty(&pring->txq)) &&
  1493. (pring->ringno != phba->sli.fcp_ring ||
  1494. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1495. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1496. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1497. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1498. if (iocb)
  1499. lpfc_sli_update_ring(phba, pring);
  1500. else
  1501. lpfc_sli_update_full_ring(phba, pring);
  1502. }
  1503. return;
  1504. }
  1505. /**
  1506. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1507. * @phba: Pointer to HBA context object.
  1508. * @hbqno: HBQ number.
  1509. *
  1510. * This function is called with hbalock held to get the next
  1511. * available slot for the given HBQ. If there is free slot
  1512. * available for the HBQ it will return pointer to the next available
  1513. * HBQ entry else it will return NULL.
  1514. **/
  1515. static struct lpfc_hbq_entry *
  1516. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1517. {
  1518. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1519. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1520. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1521. hbqp->next_hbqPutIdx = 0;
  1522. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1523. uint32_t raw_index = phba->hbq_get[hbqno];
  1524. uint32_t getidx = le32_to_cpu(raw_index);
  1525. hbqp->local_hbqGetIdx = getidx;
  1526. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1527. lpfc_printf_log(phba, KERN_ERR,
  1528. LOG_SLI | LOG_VPORT,
  1529. "1802 HBQ %d: local_hbqGetIdx "
  1530. "%u is > than hbqp->entry_count %u\n",
  1531. hbqno, hbqp->local_hbqGetIdx,
  1532. hbqp->entry_count);
  1533. phba->link_state = LPFC_HBA_ERROR;
  1534. return NULL;
  1535. }
  1536. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1537. return NULL;
  1538. }
  1539. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1540. hbqp->hbqPutIdx;
  1541. }
  1542. /**
  1543. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1544. * @phba: Pointer to HBA context object.
  1545. *
  1546. * This function is called with no lock held to free all the
  1547. * hbq buffers while uninitializing the SLI interface. It also
  1548. * frees the HBQ buffers returned by the firmware but not yet
  1549. * processed by the upper layers.
  1550. **/
  1551. void
  1552. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1553. {
  1554. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1555. struct hbq_dmabuf *hbq_buf;
  1556. unsigned long flags;
  1557. int i, hbq_count;
  1558. uint32_t hbqno;
  1559. hbq_count = lpfc_sli_hbq_count();
  1560. /* Return all memory used by all HBQs */
  1561. spin_lock_irqsave(&phba->hbalock, flags);
  1562. for (i = 0; i < hbq_count; ++i) {
  1563. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1564. &phba->hbqs[i].hbq_buffer_list, list) {
  1565. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1566. list_del(&hbq_buf->dbuf.list);
  1567. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1568. }
  1569. phba->hbqs[i].buffer_count = 0;
  1570. }
  1571. /* Return all HBQ buffer that are in-fly */
  1572. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1573. list) {
  1574. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1575. list_del(&hbq_buf->dbuf.list);
  1576. if (hbq_buf->tag == -1) {
  1577. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1578. (phba, hbq_buf);
  1579. } else {
  1580. hbqno = hbq_buf->tag >> 16;
  1581. if (hbqno >= LPFC_MAX_HBQS)
  1582. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1583. (phba, hbq_buf);
  1584. else
  1585. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1586. hbq_buf);
  1587. }
  1588. }
  1589. /* Mark the HBQs not in use */
  1590. phba->hbq_in_use = 0;
  1591. spin_unlock_irqrestore(&phba->hbalock, flags);
  1592. }
  1593. /**
  1594. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1595. * @phba: Pointer to HBA context object.
  1596. * @hbqno: HBQ number.
  1597. * @hbq_buf: Pointer to HBQ buffer.
  1598. *
  1599. * This function is called with the hbalock held to post a
  1600. * hbq buffer to the firmware. If the function finds an empty
  1601. * slot in the HBQ, it will post the buffer. The function will return
  1602. * pointer to the hbq entry if it successfully post the buffer
  1603. * else it will return NULL.
  1604. **/
  1605. static int
  1606. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1607. struct hbq_dmabuf *hbq_buf)
  1608. {
  1609. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1610. }
  1611. /**
  1612. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1613. * @phba: Pointer to HBA context object.
  1614. * @hbqno: HBQ number.
  1615. * @hbq_buf: Pointer to HBQ buffer.
  1616. *
  1617. * This function is called with the hbalock held to post a hbq buffer to the
  1618. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1619. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1620. * it successfully post the buffer else it will return an error.
  1621. **/
  1622. static int
  1623. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1624. struct hbq_dmabuf *hbq_buf)
  1625. {
  1626. struct lpfc_hbq_entry *hbqe;
  1627. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1628. /* Get next HBQ entry slot to use */
  1629. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1630. if (hbqe) {
  1631. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1632. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1633. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1634. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1635. hbqe->bde.tus.f.bdeFlags = 0;
  1636. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1637. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1638. /* Sync SLIM */
  1639. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1640. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1641. /* flush */
  1642. readl(phba->hbq_put + hbqno);
  1643. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1644. return 0;
  1645. } else
  1646. return -ENOMEM;
  1647. }
  1648. /**
  1649. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1650. * @phba: Pointer to HBA context object.
  1651. * @hbqno: HBQ number.
  1652. * @hbq_buf: Pointer to HBQ buffer.
  1653. *
  1654. * This function is called with the hbalock held to post an RQE to the SLI4
  1655. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1656. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1657. **/
  1658. static int
  1659. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1660. struct hbq_dmabuf *hbq_buf)
  1661. {
  1662. int rc;
  1663. struct lpfc_rqe hrqe;
  1664. struct lpfc_rqe drqe;
  1665. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1666. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1667. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1668. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1669. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1670. &hrqe, &drqe);
  1671. if (rc < 0)
  1672. return rc;
  1673. hbq_buf->tag = rc;
  1674. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1675. return 0;
  1676. }
  1677. /* HBQ for ELS and CT traffic. */
  1678. static struct lpfc_hbq_init lpfc_els_hbq = {
  1679. .rn = 1,
  1680. .entry_count = 256,
  1681. .mask_count = 0,
  1682. .profile = 0,
  1683. .ring_mask = (1 << LPFC_ELS_RING),
  1684. .buffer_count = 0,
  1685. .init_count = 40,
  1686. .add_count = 40,
  1687. };
  1688. /* HBQ for the extra ring if needed */
  1689. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1690. .rn = 1,
  1691. .entry_count = 200,
  1692. .mask_count = 0,
  1693. .profile = 0,
  1694. .ring_mask = (1 << LPFC_EXTRA_RING),
  1695. .buffer_count = 0,
  1696. .init_count = 0,
  1697. .add_count = 5,
  1698. };
  1699. /* Array of HBQs */
  1700. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1701. &lpfc_els_hbq,
  1702. &lpfc_extra_hbq,
  1703. };
  1704. /**
  1705. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1706. * @phba: Pointer to HBA context object.
  1707. * @hbqno: HBQ number.
  1708. * @count: Number of HBQ buffers to be posted.
  1709. *
  1710. * This function is called with no lock held to post more hbq buffers to the
  1711. * given HBQ. The function returns the number of HBQ buffers successfully
  1712. * posted.
  1713. **/
  1714. static int
  1715. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1716. {
  1717. uint32_t i, posted = 0;
  1718. unsigned long flags;
  1719. struct hbq_dmabuf *hbq_buffer;
  1720. LIST_HEAD(hbq_buf_list);
  1721. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1722. return 0;
  1723. if ((phba->hbqs[hbqno].buffer_count + count) >
  1724. lpfc_hbq_defs[hbqno]->entry_count)
  1725. count = lpfc_hbq_defs[hbqno]->entry_count -
  1726. phba->hbqs[hbqno].buffer_count;
  1727. if (!count)
  1728. return 0;
  1729. /* Allocate HBQ entries */
  1730. for (i = 0; i < count; i++) {
  1731. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1732. if (!hbq_buffer)
  1733. break;
  1734. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1735. }
  1736. /* Check whether HBQ is still in use */
  1737. spin_lock_irqsave(&phba->hbalock, flags);
  1738. if (!phba->hbq_in_use)
  1739. goto err;
  1740. while (!list_empty(&hbq_buf_list)) {
  1741. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1742. dbuf.list);
  1743. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1744. (hbqno << 16));
  1745. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1746. phba->hbqs[hbqno].buffer_count++;
  1747. posted++;
  1748. } else
  1749. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1750. }
  1751. spin_unlock_irqrestore(&phba->hbalock, flags);
  1752. return posted;
  1753. err:
  1754. spin_unlock_irqrestore(&phba->hbalock, flags);
  1755. while (!list_empty(&hbq_buf_list)) {
  1756. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1757. dbuf.list);
  1758. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1759. }
  1760. return 0;
  1761. }
  1762. /**
  1763. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1764. * @phba: Pointer to HBA context object.
  1765. * @qno: HBQ number.
  1766. *
  1767. * This function posts more buffers to the HBQ. This function
  1768. * is called with no lock held. The function returns the number of HBQ entries
  1769. * successfully allocated.
  1770. **/
  1771. int
  1772. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1773. {
  1774. if (phba->sli_rev == LPFC_SLI_REV4)
  1775. return 0;
  1776. else
  1777. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1778. lpfc_hbq_defs[qno]->add_count);
  1779. }
  1780. /**
  1781. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1782. * @phba: Pointer to HBA context object.
  1783. * @qno: HBQ queue number.
  1784. *
  1785. * This function is called from SLI initialization code path with
  1786. * no lock held to post initial HBQ buffers to firmware. The
  1787. * function returns the number of HBQ entries successfully allocated.
  1788. **/
  1789. static int
  1790. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1791. {
  1792. if (phba->sli_rev == LPFC_SLI_REV4)
  1793. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1794. lpfc_hbq_defs[qno]->entry_count);
  1795. else
  1796. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1797. lpfc_hbq_defs[qno]->init_count);
  1798. }
  1799. /**
  1800. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1801. * @phba: Pointer to HBA context object.
  1802. * @hbqno: HBQ number.
  1803. *
  1804. * This function removes the first hbq buffer on an hbq list and returns a
  1805. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1806. **/
  1807. static struct hbq_dmabuf *
  1808. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1809. {
  1810. struct lpfc_dmabuf *d_buf;
  1811. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1812. if (!d_buf)
  1813. return NULL;
  1814. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1815. }
  1816. /**
  1817. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1818. * @phba: Pointer to HBA context object.
  1819. * @tag: Tag of the hbq buffer.
  1820. *
  1821. * This function is called with hbalock held. This function searches
  1822. * for the hbq buffer associated with the given tag in the hbq buffer
  1823. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1824. * it returns NULL.
  1825. **/
  1826. static struct hbq_dmabuf *
  1827. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1828. {
  1829. struct lpfc_dmabuf *d_buf;
  1830. struct hbq_dmabuf *hbq_buf;
  1831. uint32_t hbqno;
  1832. hbqno = tag >> 16;
  1833. if (hbqno >= LPFC_MAX_HBQS)
  1834. return NULL;
  1835. spin_lock_irq(&phba->hbalock);
  1836. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1837. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1838. if (hbq_buf->tag == tag) {
  1839. spin_unlock_irq(&phba->hbalock);
  1840. return hbq_buf;
  1841. }
  1842. }
  1843. spin_unlock_irq(&phba->hbalock);
  1844. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1845. "1803 Bad hbq tag. Data: x%x x%x\n",
  1846. tag, phba->hbqs[tag >> 16].buffer_count);
  1847. return NULL;
  1848. }
  1849. /**
  1850. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1851. * @phba: Pointer to HBA context object.
  1852. * @hbq_buffer: Pointer to HBQ buffer.
  1853. *
  1854. * This function is called with hbalock. This function gives back
  1855. * the hbq buffer to firmware. If the HBQ does not have space to
  1856. * post the buffer, it will free the buffer.
  1857. **/
  1858. void
  1859. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1860. {
  1861. uint32_t hbqno;
  1862. if (hbq_buffer) {
  1863. hbqno = hbq_buffer->tag >> 16;
  1864. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1865. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1866. }
  1867. }
  1868. /**
  1869. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1870. * @mbxCommand: mailbox command code.
  1871. *
  1872. * This function is called by the mailbox event handler function to verify
  1873. * that the completed mailbox command is a legitimate mailbox command. If the
  1874. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1875. * and the mailbox event handler will take the HBA offline.
  1876. **/
  1877. static int
  1878. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1879. {
  1880. uint8_t ret;
  1881. switch (mbxCommand) {
  1882. case MBX_LOAD_SM:
  1883. case MBX_READ_NV:
  1884. case MBX_WRITE_NV:
  1885. case MBX_WRITE_VPARMS:
  1886. case MBX_RUN_BIU_DIAG:
  1887. case MBX_INIT_LINK:
  1888. case MBX_DOWN_LINK:
  1889. case MBX_CONFIG_LINK:
  1890. case MBX_CONFIG_RING:
  1891. case MBX_RESET_RING:
  1892. case MBX_READ_CONFIG:
  1893. case MBX_READ_RCONFIG:
  1894. case MBX_READ_SPARM:
  1895. case MBX_READ_STATUS:
  1896. case MBX_READ_RPI:
  1897. case MBX_READ_XRI:
  1898. case MBX_READ_REV:
  1899. case MBX_READ_LNK_STAT:
  1900. case MBX_REG_LOGIN:
  1901. case MBX_UNREG_LOGIN:
  1902. case MBX_CLEAR_LA:
  1903. case MBX_DUMP_MEMORY:
  1904. case MBX_DUMP_CONTEXT:
  1905. case MBX_RUN_DIAGS:
  1906. case MBX_RESTART:
  1907. case MBX_UPDATE_CFG:
  1908. case MBX_DOWN_LOAD:
  1909. case MBX_DEL_LD_ENTRY:
  1910. case MBX_RUN_PROGRAM:
  1911. case MBX_SET_MASK:
  1912. case MBX_SET_VARIABLE:
  1913. case MBX_UNREG_D_ID:
  1914. case MBX_KILL_BOARD:
  1915. case MBX_CONFIG_FARP:
  1916. case MBX_BEACON:
  1917. case MBX_LOAD_AREA:
  1918. case MBX_RUN_BIU_DIAG64:
  1919. case MBX_CONFIG_PORT:
  1920. case MBX_READ_SPARM64:
  1921. case MBX_READ_RPI64:
  1922. case MBX_REG_LOGIN64:
  1923. case MBX_READ_TOPOLOGY:
  1924. case MBX_WRITE_WWN:
  1925. case MBX_SET_DEBUG:
  1926. case MBX_LOAD_EXP_ROM:
  1927. case MBX_ASYNCEVT_ENABLE:
  1928. case MBX_REG_VPI:
  1929. case MBX_UNREG_VPI:
  1930. case MBX_HEARTBEAT:
  1931. case MBX_PORT_CAPABILITIES:
  1932. case MBX_PORT_IOV_CONTROL:
  1933. case MBX_SLI4_CONFIG:
  1934. case MBX_SLI4_REQ_FTRS:
  1935. case MBX_REG_FCFI:
  1936. case MBX_UNREG_FCFI:
  1937. case MBX_REG_VFI:
  1938. case MBX_UNREG_VFI:
  1939. case MBX_INIT_VPI:
  1940. case MBX_INIT_VFI:
  1941. case MBX_RESUME_RPI:
  1942. case MBX_READ_EVENT_LOG_STATUS:
  1943. case MBX_READ_EVENT_LOG:
  1944. case MBX_SECURITY_MGMT:
  1945. case MBX_AUTH_PORT:
  1946. case MBX_ACCESS_VDATA:
  1947. ret = mbxCommand;
  1948. break;
  1949. default:
  1950. ret = MBX_SHUTDOWN;
  1951. break;
  1952. }
  1953. return ret;
  1954. }
  1955. /**
  1956. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1957. * @phba: Pointer to HBA context object.
  1958. * @pmboxq: Pointer to mailbox command.
  1959. *
  1960. * This is completion handler function for mailbox commands issued from
  1961. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1962. * mailbox event handler function with no lock held. This function
  1963. * will wake up thread waiting on the wait queue pointed by context1
  1964. * of the mailbox.
  1965. **/
  1966. void
  1967. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1968. {
  1969. wait_queue_head_t *pdone_q;
  1970. unsigned long drvr_flag;
  1971. /*
  1972. * If pdone_q is empty, the driver thread gave up waiting and
  1973. * continued running.
  1974. */
  1975. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1976. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1977. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1978. if (pdone_q)
  1979. wake_up_interruptible(pdone_q);
  1980. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1981. return;
  1982. }
  1983. /**
  1984. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1985. * @phba: Pointer to HBA context object.
  1986. * @pmb: Pointer to mailbox object.
  1987. *
  1988. * This function is the default mailbox completion handler. It
  1989. * frees the memory resources associated with the completed mailbox
  1990. * command. If the completed command is a REG_LOGIN mailbox command,
  1991. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1992. **/
  1993. void
  1994. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1995. {
  1996. struct lpfc_vport *vport = pmb->vport;
  1997. struct lpfc_dmabuf *mp;
  1998. struct lpfc_nodelist *ndlp;
  1999. struct Scsi_Host *shost;
  2000. uint16_t rpi, vpi;
  2001. int rc;
  2002. mp = (struct lpfc_dmabuf *) (pmb->context1);
  2003. if (mp) {
  2004. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2005. kfree(mp);
  2006. }
  2007. /*
  2008. * If a REG_LOGIN succeeded after node is destroyed or node
  2009. * is in re-discovery driver need to cleanup the RPI.
  2010. */
  2011. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  2012. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  2013. !pmb->u.mb.mbxStatus) {
  2014. rpi = pmb->u.mb.un.varWords[0];
  2015. vpi = pmb->u.mb.un.varRegLogin.vpi;
  2016. lpfc_unreg_login(phba, vpi, rpi, pmb);
  2017. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2018. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2019. if (rc != MBX_NOT_FINISHED)
  2020. return;
  2021. }
  2022. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  2023. !(phba->pport->load_flag & FC_UNLOADING) &&
  2024. !pmb->u.mb.mbxStatus) {
  2025. shost = lpfc_shost_from_vport(vport);
  2026. spin_lock_irq(shost->host_lock);
  2027. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2028. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  2029. spin_unlock_irq(shost->host_lock);
  2030. }
  2031. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  2032. ndlp = (struct lpfc_nodelist *)pmb->context2;
  2033. lpfc_nlp_put(ndlp);
  2034. pmb->context2 = NULL;
  2035. }
  2036. /* Check security permission status on INIT_LINK mailbox command */
  2037. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  2038. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  2039. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2040. "2860 SLI authentication is required "
  2041. "for INIT_LINK but has not done yet\n");
  2042. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  2043. lpfc_sli4_mbox_cmd_free(phba, pmb);
  2044. else
  2045. mempool_free(pmb, phba->mbox_mem_pool);
  2046. }
  2047. /**
  2048. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  2049. * @phba: Pointer to HBA context object.
  2050. *
  2051. * This function is called with no lock held. This function processes all
  2052. * the completed mailbox commands and gives it to upper layers. The interrupt
  2053. * service routine processes mailbox completion interrupt and adds completed
  2054. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  2055. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  2056. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  2057. * function returns the mailbox commands to the upper layer by calling the
  2058. * completion handler function of each mailbox.
  2059. **/
  2060. int
  2061. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2062. {
  2063. MAILBOX_t *pmbox;
  2064. LPFC_MBOXQ_t *pmb;
  2065. int rc;
  2066. LIST_HEAD(cmplq);
  2067. phba->sli.slistat.mbox_event++;
  2068. /* Get all completed mailboxe buffers into the cmplq */
  2069. spin_lock_irq(&phba->hbalock);
  2070. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2071. spin_unlock_irq(&phba->hbalock);
  2072. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2073. do {
  2074. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2075. if (pmb == NULL)
  2076. break;
  2077. pmbox = &pmb->u.mb;
  2078. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2079. if (pmb->vport) {
  2080. lpfc_debugfs_disc_trc(pmb->vport,
  2081. LPFC_DISC_TRC_MBOX_VPORT,
  2082. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2083. (uint32_t)pmbox->mbxCommand,
  2084. pmbox->un.varWords[0],
  2085. pmbox->un.varWords[1]);
  2086. }
  2087. else {
  2088. lpfc_debugfs_disc_trc(phba->pport,
  2089. LPFC_DISC_TRC_MBOX,
  2090. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2091. (uint32_t)pmbox->mbxCommand,
  2092. pmbox->un.varWords[0],
  2093. pmbox->un.varWords[1]);
  2094. }
  2095. }
  2096. /*
  2097. * It is a fatal error if unknown mbox command completion.
  2098. */
  2099. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2100. MBX_SHUTDOWN) {
  2101. /* Unknown mailbox command compl */
  2102. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2103. "(%d):0323 Unknown Mailbox command "
  2104. "x%x (x%x/x%x) Cmpl\n",
  2105. pmb->vport ? pmb->vport->vpi : 0,
  2106. pmbox->mbxCommand,
  2107. lpfc_sli_config_mbox_subsys_get(phba,
  2108. pmb),
  2109. lpfc_sli_config_mbox_opcode_get(phba,
  2110. pmb));
  2111. phba->link_state = LPFC_HBA_ERROR;
  2112. phba->work_hs = HS_FFER3;
  2113. lpfc_handle_eratt(phba);
  2114. continue;
  2115. }
  2116. if (pmbox->mbxStatus) {
  2117. phba->sli.slistat.mbox_stat_err++;
  2118. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2119. /* Mbox cmd cmpl error - RETRYing */
  2120. lpfc_printf_log(phba, KERN_INFO,
  2121. LOG_MBOX | LOG_SLI,
  2122. "(%d):0305 Mbox cmd cmpl "
  2123. "error - RETRYing Data: x%x "
  2124. "(x%x/x%x) x%x x%x x%x\n",
  2125. pmb->vport ? pmb->vport->vpi : 0,
  2126. pmbox->mbxCommand,
  2127. lpfc_sli_config_mbox_subsys_get(phba,
  2128. pmb),
  2129. lpfc_sli_config_mbox_opcode_get(phba,
  2130. pmb),
  2131. pmbox->mbxStatus,
  2132. pmbox->un.varWords[0],
  2133. pmb->vport->port_state);
  2134. pmbox->mbxStatus = 0;
  2135. pmbox->mbxOwner = OWN_HOST;
  2136. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2137. if (rc != MBX_NOT_FINISHED)
  2138. continue;
  2139. }
  2140. }
  2141. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2142. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2143. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
  2144. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  2145. "x%x x%x x%x\n",
  2146. pmb->vport ? pmb->vport->vpi : 0,
  2147. pmbox->mbxCommand,
  2148. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2149. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2150. pmb->mbox_cmpl,
  2151. *((uint32_t *) pmbox),
  2152. pmbox->un.varWords[0],
  2153. pmbox->un.varWords[1],
  2154. pmbox->un.varWords[2],
  2155. pmbox->un.varWords[3],
  2156. pmbox->un.varWords[4],
  2157. pmbox->un.varWords[5],
  2158. pmbox->un.varWords[6],
  2159. pmbox->un.varWords[7],
  2160. pmbox->un.varWords[8],
  2161. pmbox->un.varWords[9],
  2162. pmbox->un.varWords[10]);
  2163. if (pmb->mbox_cmpl)
  2164. pmb->mbox_cmpl(phba,pmb);
  2165. } while (1);
  2166. return 0;
  2167. }
  2168. /**
  2169. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2170. * @phba: Pointer to HBA context object.
  2171. * @pring: Pointer to driver SLI ring object.
  2172. * @tag: buffer tag.
  2173. *
  2174. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2175. * is set in the tag the buffer is posted for a particular exchange,
  2176. * the function will return the buffer without replacing the buffer.
  2177. * If the buffer is for unsolicited ELS or CT traffic, this function
  2178. * returns the buffer and also posts another buffer to the firmware.
  2179. **/
  2180. static struct lpfc_dmabuf *
  2181. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2182. struct lpfc_sli_ring *pring,
  2183. uint32_t tag)
  2184. {
  2185. struct hbq_dmabuf *hbq_entry;
  2186. if (tag & QUE_BUFTAG_BIT)
  2187. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2188. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2189. if (!hbq_entry)
  2190. return NULL;
  2191. return &hbq_entry->dbuf;
  2192. }
  2193. /**
  2194. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2195. * @phba: Pointer to HBA context object.
  2196. * @pring: Pointer to driver SLI ring object.
  2197. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2198. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2199. * @fch_type: the type for the first frame of the sequence.
  2200. *
  2201. * This function is called with no lock held. This function uses the r_ctl and
  2202. * type of the received sequence to find the correct callback function to call
  2203. * to process the sequence.
  2204. **/
  2205. static int
  2206. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2207. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2208. uint32_t fch_type)
  2209. {
  2210. int i;
  2211. /* unSolicited Responses */
  2212. if (pring->prt[0].profile) {
  2213. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2214. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2215. saveq);
  2216. return 1;
  2217. }
  2218. /* We must search, based on rctl / type
  2219. for the right routine */
  2220. for (i = 0; i < pring->num_mask; i++) {
  2221. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2222. (pring->prt[i].type == fch_type)) {
  2223. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2224. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2225. (phba, pring, saveq);
  2226. return 1;
  2227. }
  2228. }
  2229. return 0;
  2230. }
  2231. /**
  2232. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2233. * @phba: Pointer to HBA context object.
  2234. * @pring: Pointer to driver SLI ring object.
  2235. * @saveq: Pointer to the unsolicited iocb.
  2236. *
  2237. * This function is called with no lock held by the ring event handler
  2238. * when there is an unsolicited iocb posted to the response ring by the
  2239. * firmware. This function gets the buffer associated with the iocbs
  2240. * and calls the event handler for the ring. This function handles both
  2241. * qring buffers and hbq buffers.
  2242. * When the function returns 1 the caller can free the iocb object otherwise
  2243. * upper layer functions will free the iocb objects.
  2244. **/
  2245. static int
  2246. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2247. struct lpfc_iocbq *saveq)
  2248. {
  2249. IOCB_t * irsp;
  2250. WORD5 * w5p;
  2251. uint32_t Rctl, Type;
  2252. uint32_t match;
  2253. struct lpfc_iocbq *iocbq;
  2254. struct lpfc_dmabuf *dmzbuf;
  2255. match = 0;
  2256. irsp = &(saveq->iocb);
  2257. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2258. if (pring->lpfc_sli_rcv_async_status)
  2259. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2260. else
  2261. lpfc_printf_log(phba,
  2262. KERN_WARNING,
  2263. LOG_SLI,
  2264. "0316 Ring %d handler: unexpected "
  2265. "ASYNC_STATUS iocb received evt_code "
  2266. "0x%x\n",
  2267. pring->ringno,
  2268. irsp->un.asyncstat.evt_code);
  2269. return 1;
  2270. }
  2271. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2272. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2273. if (irsp->ulpBdeCount > 0) {
  2274. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2275. irsp->un.ulpWord[3]);
  2276. lpfc_in_buf_free(phba, dmzbuf);
  2277. }
  2278. if (irsp->ulpBdeCount > 1) {
  2279. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2280. irsp->unsli3.sli3Words[3]);
  2281. lpfc_in_buf_free(phba, dmzbuf);
  2282. }
  2283. if (irsp->ulpBdeCount > 2) {
  2284. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2285. irsp->unsli3.sli3Words[7]);
  2286. lpfc_in_buf_free(phba, dmzbuf);
  2287. }
  2288. return 1;
  2289. }
  2290. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2291. if (irsp->ulpBdeCount != 0) {
  2292. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2293. irsp->un.ulpWord[3]);
  2294. if (!saveq->context2)
  2295. lpfc_printf_log(phba,
  2296. KERN_ERR,
  2297. LOG_SLI,
  2298. "0341 Ring %d Cannot find buffer for "
  2299. "an unsolicited iocb. tag 0x%x\n",
  2300. pring->ringno,
  2301. irsp->un.ulpWord[3]);
  2302. }
  2303. if (irsp->ulpBdeCount == 2) {
  2304. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2305. irsp->unsli3.sli3Words[7]);
  2306. if (!saveq->context3)
  2307. lpfc_printf_log(phba,
  2308. KERN_ERR,
  2309. LOG_SLI,
  2310. "0342 Ring %d Cannot find buffer for an"
  2311. " unsolicited iocb. tag 0x%x\n",
  2312. pring->ringno,
  2313. irsp->unsli3.sli3Words[7]);
  2314. }
  2315. list_for_each_entry(iocbq, &saveq->list, list) {
  2316. irsp = &(iocbq->iocb);
  2317. if (irsp->ulpBdeCount != 0) {
  2318. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2319. irsp->un.ulpWord[3]);
  2320. if (!iocbq->context2)
  2321. lpfc_printf_log(phba,
  2322. KERN_ERR,
  2323. LOG_SLI,
  2324. "0343 Ring %d Cannot find "
  2325. "buffer for an unsolicited iocb"
  2326. ". tag 0x%x\n", pring->ringno,
  2327. irsp->un.ulpWord[3]);
  2328. }
  2329. if (irsp->ulpBdeCount == 2) {
  2330. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2331. irsp->unsli3.sli3Words[7]);
  2332. if (!iocbq->context3)
  2333. lpfc_printf_log(phba,
  2334. KERN_ERR,
  2335. LOG_SLI,
  2336. "0344 Ring %d Cannot find "
  2337. "buffer for an unsolicited "
  2338. "iocb. tag 0x%x\n",
  2339. pring->ringno,
  2340. irsp->unsli3.sli3Words[7]);
  2341. }
  2342. }
  2343. }
  2344. if (irsp->ulpBdeCount != 0 &&
  2345. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2346. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2347. int found = 0;
  2348. /* search continue save q for same XRI */
  2349. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2350. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  2351. saveq->iocb.unsli3.rcvsli3.ox_id) {
  2352. list_add_tail(&saveq->list, &iocbq->list);
  2353. found = 1;
  2354. break;
  2355. }
  2356. }
  2357. if (!found)
  2358. list_add_tail(&saveq->clist,
  2359. &pring->iocb_continue_saveq);
  2360. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2361. list_del_init(&iocbq->clist);
  2362. saveq = iocbq;
  2363. irsp = &(saveq->iocb);
  2364. } else
  2365. return 0;
  2366. }
  2367. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2368. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2369. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2370. Rctl = FC_RCTL_ELS_REQ;
  2371. Type = FC_TYPE_ELS;
  2372. } else {
  2373. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2374. Rctl = w5p->hcsw.Rctl;
  2375. Type = w5p->hcsw.Type;
  2376. /* Firmware Workaround */
  2377. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2378. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2379. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2380. Rctl = FC_RCTL_ELS_REQ;
  2381. Type = FC_TYPE_ELS;
  2382. w5p->hcsw.Rctl = Rctl;
  2383. w5p->hcsw.Type = Type;
  2384. }
  2385. }
  2386. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2387. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2388. "0313 Ring %d handler: unexpected Rctl x%x "
  2389. "Type x%x received\n",
  2390. pring->ringno, Rctl, Type);
  2391. return 1;
  2392. }
  2393. /**
  2394. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2395. * @phba: Pointer to HBA context object.
  2396. * @pring: Pointer to driver SLI ring object.
  2397. * @prspiocb: Pointer to response iocb object.
  2398. *
  2399. * This function looks up the iocb_lookup table to get the command iocb
  2400. * corresponding to the given response iocb using the iotag of the
  2401. * response iocb. This function is called with the hbalock held.
  2402. * This function returns the command iocb object if it finds the command
  2403. * iocb else returns NULL.
  2404. **/
  2405. static struct lpfc_iocbq *
  2406. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2407. struct lpfc_sli_ring *pring,
  2408. struct lpfc_iocbq *prspiocb)
  2409. {
  2410. struct lpfc_iocbq *cmd_iocb = NULL;
  2411. uint16_t iotag;
  2412. iotag = prspiocb->iocb.ulpIoTag;
  2413. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2414. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2415. list_del_init(&cmd_iocb->list);
  2416. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2417. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2418. }
  2419. return cmd_iocb;
  2420. }
  2421. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2422. "0317 iotag x%x is out off "
  2423. "range: max iotag x%x wd0 x%x\n",
  2424. iotag, phba->sli.last_iotag,
  2425. *(((uint32_t *) &prspiocb->iocb) + 7));
  2426. return NULL;
  2427. }
  2428. /**
  2429. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2430. * @phba: Pointer to HBA context object.
  2431. * @pring: Pointer to driver SLI ring object.
  2432. * @iotag: IOCB tag.
  2433. *
  2434. * This function looks up the iocb_lookup table to get the command iocb
  2435. * corresponding to the given iotag. This function is called with the
  2436. * hbalock held.
  2437. * This function returns the command iocb object if it finds the command
  2438. * iocb else returns NULL.
  2439. **/
  2440. static struct lpfc_iocbq *
  2441. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2442. struct lpfc_sli_ring *pring, uint16_t iotag)
  2443. {
  2444. struct lpfc_iocbq *cmd_iocb;
  2445. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2446. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2447. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2448. /* remove from txcmpl queue list */
  2449. list_del_init(&cmd_iocb->list);
  2450. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2451. return cmd_iocb;
  2452. }
  2453. }
  2454. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2455. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2456. iotag, phba->sli.last_iotag);
  2457. return NULL;
  2458. }
  2459. /**
  2460. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2461. * @phba: Pointer to HBA context object.
  2462. * @pring: Pointer to driver SLI ring object.
  2463. * @saveq: Pointer to the response iocb to be processed.
  2464. *
  2465. * This function is called by the ring event handler for non-fcp
  2466. * rings when there is a new response iocb in the response ring.
  2467. * The caller is not required to hold any locks. This function
  2468. * gets the command iocb associated with the response iocb and
  2469. * calls the completion handler for the command iocb. If there
  2470. * is no completion handler, the function will free the resources
  2471. * associated with command iocb. If the response iocb is for
  2472. * an already aborted command iocb, the status of the completion
  2473. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2474. * This function always returns 1.
  2475. **/
  2476. static int
  2477. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2478. struct lpfc_iocbq *saveq)
  2479. {
  2480. struct lpfc_iocbq *cmdiocbp;
  2481. int rc = 1;
  2482. unsigned long iflag;
  2483. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2484. spin_lock_irqsave(&phba->hbalock, iflag);
  2485. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2486. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2487. if (cmdiocbp) {
  2488. if (cmdiocbp->iocb_cmpl) {
  2489. /*
  2490. * If an ELS command failed send an event to mgmt
  2491. * application.
  2492. */
  2493. if (saveq->iocb.ulpStatus &&
  2494. (pring->ringno == LPFC_ELS_RING) &&
  2495. (cmdiocbp->iocb.ulpCommand ==
  2496. CMD_ELS_REQUEST64_CR))
  2497. lpfc_send_els_failure_event(phba,
  2498. cmdiocbp, saveq);
  2499. /*
  2500. * Post all ELS completions to the worker thread.
  2501. * All other are passed to the completion callback.
  2502. */
  2503. if (pring->ringno == LPFC_ELS_RING) {
  2504. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2505. (cmdiocbp->iocb_flag &
  2506. LPFC_DRIVER_ABORTED)) {
  2507. spin_lock_irqsave(&phba->hbalock,
  2508. iflag);
  2509. cmdiocbp->iocb_flag &=
  2510. ~LPFC_DRIVER_ABORTED;
  2511. spin_unlock_irqrestore(&phba->hbalock,
  2512. iflag);
  2513. saveq->iocb.ulpStatus =
  2514. IOSTAT_LOCAL_REJECT;
  2515. saveq->iocb.un.ulpWord[4] =
  2516. IOERR_SLI_ABORTED;
  2517. /* Firmware could still be in progress
  2518. * of DMAing payload, so don't free data
  2519. * buffer till after a hbeat.
  2520. */
  2521. spin_lock_irqsave(&phba->hbalock,
  2522. iflag);
  2523. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2524. spin_unlock_irqrestore(&phba->hbalock,
  2525. iflag);
  2526. }
  2527. if (phba->sli_rev == LPFC_SLI_REV4) {
  2528. if (saveq->iocb_flag &
  2529. LPFC_EXCHANGE_BUSY) {
  2530. /* Set cmdiocb flag for the
  2531. * exchange busy so sgl (xri)
  2532. * will not be released until
  2533. * the abort xri is received
  2534. * from hba.
  2535. */
  2536. spin_lock_irqsave(
  2537. &phba->hbalock, iflag);
  2538. cmdiocbp->iocb_flag |=
  2539. LPFC_EXCHANGE_BUSY;
  2540. spin_unlock_irqrestore(
  2541. &phba->hbalock, iflag);
  2542. }
  2543. if (cmdiocbp->iocb_flag &
  2544. LPFC_DRIVER_ABORTED) {
  2545. /*
  2546. * Clear LPFC_DRIVER_ABORTED
  2547. * bit in case it was driver
  2548. * initiated abort.
  2549. */
  2550. spin_lock_irqsave(
  2551. &phba->hbalock, iflag);
  2552. cmdiocbp->iocb_flag &=
  2553. ~LPFC_DRIVER_ABORTED;
  2554. spin_unlock_irqrestore(
  2555. &phba->hbalock, iflag);
  2556. cmdiocbp->iocb.ulpStatus =
  2557. IOSTAT_LOCAL_REJECT;
  2558. cmdiocbp->iocb.un.ulpWord[4] =
  2559. IOERR_ABORT_REQUESTED;
  2560. /*
  2561. * For SLI4, irsiocb contains
  2562. * NO_XRI in sli_xritag, it
  2563. * shall not affect releasing
  2564. * sgl (xri) process.
  2565. */
  2566. saveq->iocb.ulpStatus =
  2567. IOSTAT_LOCAL_REJECT;
  2568. saveq->iocb.un.ulpWord[4] =
  2569. IOERR_SLI_ABORTED;
  2570. spin_lock_irqsave(
  2571. &phba->hbalock, iflag);
  2572. saveq->iocb_flag |=
  2573. LPFC_DELAY_MEM_FREE;
  2574. spin_unlock_irqrestore(
  2575. &phba->hbalock, iflag);
  2576. }
  2577. }
  2578. }
  2579. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2580. } else
  2581. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2582. } else {
  2583. /*
  2584. * Unknown initiating command based on the response iotag.
  2585. * This could be the case on the ELS ring because of
  2586. * lpfc_els_abort().
  2587. */
  2588. if (pring->ringno != LPFC_ELS_RING) {
  2589. /*
  2590. * Ring <ringno> handler: unexpected completion IoTag
  2591. * <IoTag>
  2592. */
  2593. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2594. "0322 Ring %d handler: "
  2595. "unexpected completion IoTag x%x "
  2596. "Data: x%x x%x x%x x%x\n",
  2597. pring->ringno,
  2598. saveq->iocb.ulpIoTag,
  2599. saveq->iocb.ulpStatus,
  2600. saveq->iocb.un.ulpWord[4],
  2601. saveq->iocb.ulpCommand,
  2602. saveq->iocb.ulpContext);
  2603. }
  2604. }
  2605. return rc;
  2606. }
  2607. /**
  2608. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2609. * @phba: Pointer to HBA context object.
  2610. * @pring: Pointer to driver SLI ring object.
  2611. *
  2612. * This function is called from the iocb ring event handlers when
  2613. * put pointer is ahead of the get pointer for a ring. This function signal
  2614. * an error attention condition to the worker thread and the worker
  2615. * thread will transition the HBA to offline state.
  2616. **/
  2617. static void
  2618. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2619. {
  2620. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2621. /*
  2622. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2623. * rsp ring <portRspMax>
  2624. */
  2625. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2626. "0312 Ring %d handler: portRspPut %d "
  2627. "is bigger than rsp ring %d\n",
  2628. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2629. pring->sli.sli3.numRiocb);
  2630. phba->link_state = LPFC_HBA_ERROR;
  2631. /*
  2632. * All error attention handlers are posted to
  2633. * worker thread
  2634. */
  2635. phba->work_ha |= HA_ERATT;
  2636. phba->work_hs = HS_FFER3;
  2637. lpfc_worker_wake_up(phba);
  2638. return;
  2639. }
  2640. /**
  2641. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2642. * @ptr: Pointer to address of HBA context object.
  2643. *
  2644. * This function is invoked by the Error Attention polling timer when the
  2645. * timer times out. It will check the SLI Error Attention register for
  2646. * possible attention events. If so, it will post an Error Attention event
  2647. * and wake up worker thread to process it. Otherwise, it will set up the
  2648. * Error Attention polling timer for the next poll.
  2649. **/
  2650. void lpfc_poll_eratt(unsigned long ptr)
  2651. {
  2652. struct lpfc_hba *phba;
  2653. uint32_t eratt = 0, rem;
  2654. uint64_t sli_intr, cnt;
  2655. phba = (struct lpfc_hba *)ptr;
  2656. /* Here we will also keep track of interrupts per sec of the hba */
  2657. sli_intr = phba->sli.slistat.sli_intr;
  2658. if (phba->sli.slistat.sli_prev_intr > sli_intr)
  2659. cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
  2660. sli_intr);
  2661. else
  2662. cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
  2663. /* 64-bit integer division not supporte on 32-bit x86 - use do_div */
  2664. rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL);
  2665. phba->sli.slistat.sli_ips = cnt;
  2666. phba->sli.slistat.sli_prev_intr = sli_intr;
  2667. /* Check chip HA register for error event */
  2668. eratt = lpfc_sli_check_eratt(phba);
  2669. if (eratt)
  2670. /* Tell the worker thread there is work to do */
  2671. lpfc_worker_wake_up(phba);
  2672. else
  2673. /* Restart the timer for next eratt poll */
  2674. mod_timer(&phba->eratt_poll,
  2675. jiffies +
  2676. msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
  2677. return;
  2678. }
  2679. /**
  2680. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2681. * @phba: Pointer to HBA context object.
  2682. * @pring: Pointer to driver SLI ring object.
  2683. * @mask: Host attention register mask for this ring.
  2684. *
  2685. * This function is called from the interrupt context when there is a ring
  2686. * event for the fcp ring. The caller does not hold any lock.
  2687. * The function processes each response iocb in the response ring until it
  2688. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2689. * LE bit set. The function will call the completion handler of the command iocb
  2690. * if the response iocb indicates a completion for a command iocb or it is
  2691. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2692. * function if this is an unsolicited iocb.
  2693. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2694. * to check it explicitly.
  2695. */
  2696. int
  2697. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2698. struct lpfc_sli_ring *pring, uint32_t mask)
  2699. {
  2700. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2701. IOCB_t *irsp = NULL;
  2702. IOCB_t *entry = NULL;
  2703. struct lpfc_iocbq *cmdiocbq = NULL;
  2704. struct lpfc_iocbq rspiocbq;
  2705. uint32_t status;
  2706. uint32_t portRspPut, portRspMax;
  2707. int rc = 1;
  2708. lpfc_iocb_type type;
  2709. unsigned long iflag;
  2710. uint32_t rsp_cmpl = 0;
  2711. spin_lock_irqsave(&phba->hbalock, iflag);
  2712. pring->stats.iocb_event++;
  2713. /*
  2714. * The next available response entry should never exceed the maximum
  2715. * entries. If it does, treat it as an adapter hardware error.
  2716. */
  2717. portRspMax = pring->sli.sli3.numRiocb;
  2718. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2719. if (unlikely(portRspPut >= portRspMax)) {
  2720. lpfc_sli_rsp_pointers_error(phba, pring);
  2721. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2722. return 1;
  2723. }
  2724. if (phba->fcp_ring_in_use) {
  2725. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2726. return 1;
  2727. } else
  2728. phba->fcp_ring_in_use = 1;
  2729. rmb();
  2730. while (pring->sli.sli3.rspidx != portRspPut) {
  2731. /*
  2732. * Fetch an entry off the ring and copy it into a local data
  2733. * structure. The copy involves a byte-swap since the
  2734. * network byte order and pci byte orders are different.
  2735. */
  2736. entry = lpfc_resp_iocb(phba, pring);
  2737. phba->last_completion_time = jiffies;
  2738. if (++pring->sli.sli3.rspidx >= portRspMax)
  2739. pring->sli.sli3.rspidx = 0;
  2740. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2741. (uint32_t *) &rspiocbq.iocb,
  2742. phba->iocb_rsp_size);
  2743. INIT_LIST_HEAD(&(rspiocbq.list));
  2744. irsp = &rspiocbq.iocb;
  2745. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2746. pring->stats.iocb_rsp++;
  2747. rsp_cmpl++;
  2748. if (unlikely(irsp->ulpStatus)) {
  2749. /*
  2750. * If resource errors reported from HBA, reduce
  2751. * queuedepths of the SCSI device.
  2752. */
  2753. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2754. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2755. IOERR_NO_RESOURCES)) {
  2756. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2757. phba->lpfc_rampdown_queue_depth(phba);
  2758. spin_lock_irqsave(&phba->hbalock, iflag);
  2759. }
  2760. /* Rsp ring <ringno> error: IOCB */
  2761. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2762. "0336 Rsp Ring %d error: IOCB Data: "
  2763. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2764. pring->ringno,
  2765. irsp->un.ulpWord[0],
  2766. irsp->un.ulpWord[1],
  2767. irsp->un.ulpWord[2],
  2768. irsp->un.ulpWord[3],
  2769. irsp->un.ulpWord[4],
  2770. irsp->un.ulpWord[5],
  2771. *(uint32_t *)&irsp->un1,
  2772. *((uint32_t *)&irsp->un1 + 1));
  2773. }
  2774. switch (type) {
  2775. case LPFC_ABORT_IOCB:
  2776. case LPFC_SOL_IOCB:
  2777. /*
  2778. * Idle exchange closed via ABTS from port. No iocb
  2779. * resources need to be recovered.
  2780. */
  2781. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2782. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2783. "0333 IOCB cmd 0x%x"
  2784. " processed. Skipping"
  2785. " completion\n",
  2786. irsp->ulpCommand);
  2787. break;
  2788. }
  2789. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2790. &rspiocbq);
  2791. if (unlikely(!cmdiocbq))
  2792. break;
  2793. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2794. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2795. if (cmdiocbq->iocb_cmpl) {
  2796. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2797. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2798. &rspiocbq);
  2799. spin_lock_irqsave(&phba->hbalock, iflag);
  2800. }
  2801. break;
  2802. case LPFC_UNSOL_IOCB:
  2803. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2804. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2805. spin_lock_irqsave(&phba->hbalock, iflag);
  2806. break;
  2807. default:
  2808. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2809. char adaptermsg[LPFC_MAX_ADPTMSG];
  2810. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2811. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2812. MAX_MSG_DATA);
  2813. dev_warn(&((phba->pcidev)->dev),
  2814. "lpfc%d: %s\n",
  2815. phba->brd_no, adaptermsg);
  2816. } else {
  2817. /* Unknown IOCB command */
  2818. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2819. "0334 Unknown IOCB command "
  2820. "Data: x%x, x%x x%x x%x x%x\n",
  2821. type, irsp->ulpCommand,
  2822. irsp->ulpStatus,
  2823. irsp->ulpIoTag,
  2824. irsp->ulpContext);
  2825. }
  2826. break;
  2827. }
  2828. /*
  2829. * The response IOCB has been processed. Update the ring
  2830. * pointer in SLIM. If the port response put pointer has not
  2831. * been updated, sync the pgp->rspPutInx and fetch the new port
  2832. * response put pointer.
  2833. */
  2834. writel(pring->sli.sli3.rspidx,
  2835. &phba->host_gp[pring->ringno].rspGetInx);
  2836. if (pring->sli.sli3.rspidx == portRspPut)
  2837. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2838. }
  2839. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2840. pring->stats.iocb_rsp_full++;
  2841. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2842. writel(status, phba->CAregaddr);
  2843. readl(phba->CAregaddr);
  2844. }
  2845. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2846. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2847. pring->stats.iocb_cmd_empty++;
  2848. /* Force update of the local copy of cmdGetInx */
  2849. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2850. lpfc_sli_resume_iocb(phba, pring);
  2851. if ((pring->lpfc_sli_cmd_available))
  2852. (pring->lpfc_sli_cmd_available) (phba, pring);
  2853. }
  2854. phba->fcp_ring_in_use = 0;
  2855. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2856. return rc;
  2857. }
  2858. /**
  2859. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2860. * @phba: Pointer to HBA context object.
  2861. * @pring: Pointer to driver SLI ring object.
  2862. * @rspiocbp: Pointer to driver response IOCB object.
  2863. *
  2864. * This function is called from the worker thread when there is a slow-path
  2865. * response IOCB to process. This function chains all the response iocbs until
  2866. * seeing the iocb with the LE bit set. The function will call
  2867. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2868. * completion of a command iocb. The function will call the
  2869. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2870. * The function frees the resources or calls the completion handler if this
  2871. * iocb is an abort completion. The function returns NULL when the response
  2872. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2873. * this function shall chain the iocb on to the iocb_continueq and return the
  2874. * response iocb passed in.
  2875. **/
  2876. static struct lpfc_iocbq *
  2877. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2878. struct lpfc_iocbq *rspiocbp)
  2879. {
  2880. struct lpfc_iocbq *saveq;
  2881. struct lpfc_iocbq *cmdiocbp;
  2882. struct lpfc_iocbq *next_iocb;
  2883. IOCB_t *irsp = NULL;
  2884. uint32_t free_saveq;
  2885. uint8_t iocb_cmd_type;
  2886. lpfc_iocb_type type;
  2887. unsigned long iflag;
  2888. int rc;
  2889. spin_lock_irqsave(&phba->hbalock, iflag);
  2890. /* First add the response iocb to the countinueq list */
  2891. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2892. pring->iocb_continueq_cnt++;
  2893. /* Now, determine whether the list is completed for processing */
  2894. irsp = &rspiocbp->iocb;
  2895. if (irsp->ulpLe) {
  2896. /*
  2897. * By default, the driver expects to free all resources
  2898. * associated with this iocb completion.
  2899. */
  2900. free_saveq = 1;
  2901. saveq = list_get_first(&pring->iocb_continueq,
  2902. struct lpfc_iocbq, list);
  2903. irsp = &(saveq->iocb);
  2904. list_del_init(&pring->iocb_continueq);
  2905. pring->iocb_continueq_cnt = 0;
  2906. pring->stats.iocb_rsp++;
  2907. /*
  2908. * If resource errors reported from HBA, reduce
  2909. * queuedepths of the SCSI device.
  2910. */
  2911. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2912. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2913. IOERR_NO_RESOURCES)) {
  2914. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2915. phba->lpfc_rampdown_queue_depth(phba);
  2916. spin_lock_irqsave(&phba->hbalock, iflag);
  2917. }
  2918. if (irsp->ulpStatus) {
  2919. /* Rsp ring <ringno> error: IOCB */
  2920. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2921. "0328 Rsp Ring %d error: "
  2922. "IOCB Data: "
  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 "
  2926. "x%x x%x x%x x%x\n",
  2927. pring->ringno,
  2928. irsp->un.ulpWord[0],
  2929. irsp->un.ulpWord[1],
  2930. irsp->un.ulpWord[2],
  2931. irsp->un.ulpWord[3],
  2932. irsp->un.ulpWord[4],
  2933. irsp->un.ulpWord[5],
  2934. *(((uint32_t *) irsp) + 6),
  2935. *(((uint32_t *) irsp) + 7),
  2936. *(((uint32_t *) irsp) + 8),
  2937. *(((uint32_t *) irsp) + 9),
  2938. *(((uint32_t *) irsp) + 10),
  2939. *(((uint32_t *) irsp) + 11),
  2940. *(((uint32_t *) irsp) + 12),
  2941. *(((uint32_t *) irsp) + 13),
  2942. *(((uint32_t *) irsp) + 14),
  2943. *(((uint32_t *) irsp) + 15));
  2944. }
  2945. /*
  2946. * Fetch the IOCB command type and call the correct completion
  2947. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2948. * get freed back to the lpfc_iocb_list by the discovery
  2949. * kernel thread.
  2950. */
  2951. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2952. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2953. switch (type) {
  2954. case LPFC_SOL_IOCB:
  2955. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2956. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2957. spin_lock_irqsave(&phba->hbalock, iflag);
  2958. break;
  2959. case LPFC_UNSOL_IOCB:
  2960. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2961. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2962. spin_lock_irqsave(&phba->hbalock, iflag);
  2963. if (!rc)
  2964. free_saveq = 0;
  2965. break;
  2966. case LPFC_ABORT_IOCB:
  2967. cmdiocbp = NULL;
  2968. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2969. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2970. saveq);
  2971. if (cmdiocbp) {
  2972. /* Call the specified completion routine */
  2973. if (cmdiocbp->iocb_cmpl) {
  2974. spin_unlock_irqrestore(&phba->hbalock,
  2975. iflag);
  2976. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2977. saveq);
  2978. spin_lock_irqsave(&phba->hbalock,
  2979. iflag);
  2980. } else
  2981. __lpfc_sli_release_iocbq(phba,
  2982. cmdiocbp);
  2983. }
  2984. break;
  2985. case LPFC_UNKNOWN_IOCB:
  2986. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2987. char adaptermsg[LPFC_MAX_ADPTMSG];
  2988. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2989. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2990. MAX_MSG_DATA);
  2991. dev_warn(&((phba->pcidev)->dev),
  2992. "lpfc%d: %s\n",
  2993. phba->brd_no, adaptermsg);
  2994. } else {
  2995. /* Unknown IOCB command */
  2996. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2997. "0335 Unknown IOCB "
  2998. "command Data: x%x "
  2999. "x%x x%x x%x\n",
  3000. irsp->ulpCommand,
  3001. irsp->ulpStatus,
  3002. irsp->ulpIoTag,
  3003. irsp->ulpContext);
  3004. }
  3005. break;
  3006. }
  3007. if (free_saveq) {
  3008. list_for_each_entry_safe(rspiocbp, next_iocb,
  3009. &saveq->list, list) {
  3010. list_del(&rspiocbp->list);
  3011. __lpfc_sli_release_iocbq(phba, rspiocbp);
  3012. }
  3013. __lpfc_sli_release_iocbq(phba, saveq);
  3014. }
  3015. rspiocbp = NULL;
  3016. }
  3017. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3018. return rspiocbp;
  3019. }
  3020. /**
  3021. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  3022. * @phba: Pointer to HBA context object.
  3023. * @pring: Pointer to driver SLI ring object.
  3024. * @mask: Host attention register mask for this ring.
  3025. *
  3026. * This routine wraps the actual slow_ring event process routine from the
  3027. * API jump table function pointer from the lpfc_hba struct.
  3028. **/
  3029. void
  3030. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  3031. struct lpfc_sli_ring *pring, uint32_t mask)
  3032. {
  3033. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  3034. }
  3035. /**
  3036. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  3037. * @phba: Pointer to HBA context object.
  3038. * @pring: Pointer to driver SLI ring object.
  3039. * @mask: Host attention register mask for this ring.
  3040. *
  3041. * This function is called from the worker thread when there is a ring event
  3042. * for non-fcp rings. The caller does not hold any lock. The function will
  3043. * remove each response iocb in the response ring and calls the handle
  3044. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3045. **/
  3046. static void
  3047. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  3048. struct lpfc_sli_ring *pring, uint32_t mask)
  3049. {
  3050. struct lpfc_pgp *pgp;
  3051. IOCB_t *entry;
  3052. IOCB_t *irsp = NULL;
  3053. struct lpfc_iocbq *rspiocbp = NULL;
  3054. uint32_t portRspPut, portRspMax;
  3055. unsigned long iflag;
  3056. uint32_t status;
  3057. pgp = &phba->port_gp[pring->ringno];
  3058. spin_lock_irqsave(&phba->hbalock, iflag);
  3059. pring->stats.iocb_event++;
  3060. /*
  3061. * The next available response entry should never exceed the maximum
  3062. * entries. If it does, treat it as an adapter hardware error.
  3063. */
  3064. portRspMax = pring->sli.sli3.numRiocb;
  3065. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3066. if (portRspPut >= portRspMax) {
  3067. /*
  3068. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  3069. * rsp ring <portRspMax>
  3070. */
  3071. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3072. "0303 Ring %d handler: portRspPut %d "
  3073. "is bigger than rsp ring %d\n",
  3074. pring->ringno, portRspPut, portRspMax);
  3075. phba->link_state = LPFC_HBA_ERROR;
  3076. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3077. phba->work_hs = HS_FFER3;
  3078. lpfc_handle_eratt(phba);
  3079. return;
  3080. }
  3081. rmb();
  3082. while (pring->sli.sli3.rspidx != portRspPut) {
  3083. /*
  3084. * Build a completion list and call the appropriate handler.
  3085. * The process is to get the next available response iocb, get
  3086. * a free iocb from the list, copy the response data into the
  3087. * free iocb, insert to the continuation list, and update the
  3088. * next response index to slim. This process makes response
  3089. * iocb's in the ring available to DMA as fast as possible but
  3090. * pays a penalty for a copy operation. Since the iocb is
  3091. * only 32 bytes, this penalty is considered small relative to
  3092. * the PCI reads for register values and a slim write. When
  3093. * the ulpLe field is set, the entire Command has been
  3094. * received.
  3095. */
  3096. entry = lpfc_resp_iocb(phba, pring);
  3097. phba->last_completion_time = jiffies;
  3098. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3099. if (rspiocbp == NULL) {
  3100. printk(KERN_ERR "%s: out of buffers! Failing "
  3101. "completion.\n", __func__);
  3102. break;
  3103. }
  3104. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3105. phba->iocb_rsp_size);
  3106. irsp = &rspiocbp->iocb;
  3107. if (++pring->sli.sli3.rspidx >= portRspMax)
  3108. pring->sli.sli3.rspidx = 0;
  3109. if (pring->ringno == LPFC_ELS_RING) {
  3110. lpfc_debugfs_slow_ring_trc(phba,
  3111. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3112. *(((uint32_t *) irsp) + 4),
  3113. *(((uint32_t *) irsp) + 6),
  3114. *(((uint32_t *) irsp) + 7));
  3115. }
  3116. writel(pring->sli.sli3.rspidx,
  3117. &phba->host_gp[pring->ringno].rspGetInx);
  3118. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3119. /* Handle the response IOCB */
  3120. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3121. spin_lock_irqsave(&phba->hbalock, iflag);
  3122. /*
  3123. * If the port response put pointer has not been updated, sync
  3124. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3125. * response put pointer.
  3126. */
  3127. if (pring->sli.sli3.rspidx == portRspPut) {
  3128. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3129. }
  3130. } /* while (pring->sli.sli3.rspidx != portRspPut) */
  3131. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3132. /* At least one response entry has been freed */
  3133. pring->stats.iocb_rsp_full++;
  3134. /* SET RxRE_RSP in Chip Att register */
  3135. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3136. writel(status, phba->CAregaddr);
  3137. readl(phba->CAregaddr); /* flush */
  3138. }
  3139. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3140. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3141. pring->stats.iocb_cmd_empty++;
  3142. /* Force update of the local copy of cmdGetInx */
  3143. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3144. lpfc_sli_resume_iocb(phba, pring);
  3145. if ((pring->lpfc_sli_cmd_available))
  3146. (pring->lpfc_sli_cmd_available) (phba, pring);
  3147. }
  3148. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3149. return;
  3150. }
  3151. /**
  3152. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3153. * @phba: Pointer to HBA context object.
  3154. * @pring: Pointer to driver SLI ring object.
  3155. * @mask: Host attention register mask for this ring.
  3156. *
  3157. * This function is called from the worker thread when there is a pending
  3158. * ELS response iocb on the driver internal slow-path response iocb worker
  3159. * queue. The caller does not hold any lock. The function will remove each
  3160. * response iocb from the response worker queue and calls the handle
  3161. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3162. **/
  3163. static void
  3164. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3165. struct lpfc_sli_ring *pring, uint32_t mask)
  3166. {
  3167. struct lpfc_iocbq *irspiocbq;
  3168. struct hbq_dmabuf *dmabuf;
  3169. struct lpfc_cq_event *cq_event;
  3170. unsigned long iflag;
  3171. spin_lock_irqsave(&phba->hbalock, iflag);
  3172. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3173. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3174. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3175. /* Get the response iocb from the head of work queue */
  3176. spin_lock_irqsave(&phba->hbalock, iflag);
  3177. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3178. cq_event, struct lpfc_cq_event, list);
  3179. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3180. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3181. case CQE_CODE_COMPL_WQE:
  3182. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3183. cq_event);
  3184. /* Translate ELS WCQE to response IOCBQ */
  3185. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3186. irspiocbq);
  3187. if (irspiocbq)
  3188. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3189. irspiocbq);
  3190. break;
  3191. case CQE_CODE_RECEIVE:
  3192. case CQE_CODE_RECEIVE_V1:
  3193. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3194. cq_event);
  3195. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3196. break;
  3197. default:
  3198. break;
  3199. }
  3200. }
  3201. }
  3202. /**
  3203. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3204. * @phba: Pointer to HBA context object.
  3205. * @pring: Pointer to driver SLI ring object.
  3206. *
  3207. * This function aborts all iocbs in the given ring and frees all the iocb
  3208. * objects in txq. This function issues an abort iocb for all the iocb commands
  3209. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3210. * the return of this function. The caller is not required to hold any locks.
  3211. **/
  3212. void
  3213. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3214. {
  3215. LIST_HEAD(completions);
  3216. struct lpfc_iocbq *iocb, *next_iocb;
  3217. if (pring->ringno == LPFC_ELS_RING) {
  3218. lpfc_fabric_abort_hba(phba);
  3219. }
  3220. /* Error everything on txq and txcmplq
  3221. * First do the txq.
  3222. */
  3223. spin_lock_irq(&phba->hbalock);
  3224. list_splice_init(&pring->txq, &completions);
  3225. /* Next issue ABTS for everything on the txcmplq */
  3226. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3227. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3228. spin_unlock_irq(&phba->hbalock);
  3229. /* Cancel all the IOCBs from the completions list */
  3230. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3231. IOERR_SLI_ABORTED);
  3232. }
  3233. /**
  3234. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3235. * @phba: Pointer to HBA context object.
  3236. *
  3237. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3238. * objects in txq and txcmplq. This function will not issue abort iocbs
  3239. * for all the iocb commands in txcmplq, they will just be returned with
  3240. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3241. * slot has been permanently disabled.
  3242. **/
  3243. void
  3244. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3245. {
  3246. LIST_HEAD(txq);
  3247. LIST_HEAD(txcmplq);
  3248. struct lpfc_sli *psli = &phba->sli;
  3249. struct lpfc_sli_ring *pring;
  3250. /* Currently, only one fcp ring */
  3251. pring = &psli->ring[psli->fcp_ring];
  3252. spin_lock_irq(&phba->hbalock);
  3253. /* Retrieve everything on txq */
  3254. list_splice_init(&pring->txq, &txq);
  3255. /* Retrieve everything on the txcmplq */
  3256. list_splice_init(&pring->txcmplq, &txcmplq);
  3257. /* Indicate the I/O queues are flushed */
  3258. phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
  3259. spin_unlock_irq(&phba->hbalock);
  3260. /* Flush the txq */
  3261. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3262. IOERR_SLI_DOWN);
  3263. /* Flush the txcmpq */
  3264. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3265. IOERR_SLI_DOWN);
  3266. }
  3267. /**
  3268. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3269. * @phba: Pointer to HBA context object.
  3270. * @mask: Bit mask to be checked.
  3271. *
  3272. * This function reads the host status register and compares
  3273. * with the provided bit mask to check if HBA completed
  3274. * the restart. This function will wait in a loop for the
  3275. * HBA to complete restart. If the HBA does not restart within
  3276. * 15 iterations, the function will reset the HBA again. The
  3277. * function returns 1 when HBA fail to restart otherwise returns
  3278. * zero.
  3279. **/
  3280. static int
  3281. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3282. {
  3283. uint32_t status;
  3284. int i = 0;
  3285. int retval = 0;
  3286. /* Read the HBA Host Status Register */
  3287. if (lpfc_readl(phba->HSregaddr, &status))
  3288. return 1;
  3289. /*
  3290. * Check status register every 100ms for 5 retries, then every
  3291. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3292. * every 2.5 sec for 4.
  3293. * Break our of the loop if errors occurred during init.
  3294. */
  3295. while (((status & mask) != mask) &&
  3296. !(status & HS_FFERM) &&
  3297. i++ < 20) {
  3298. if (i <= 5)
  3299. msleep(10);
  3300. else if (i <= 10)
  3301. msleep(500);
  3302. else
  3303. msleep(2500);
  3304. if (i == 15) {
  3305. /* Do post */
  3306. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3307. lpfc_sli_brdrestart(phba);
  3308. }
  3309. /* Read the HBA Host Status Register */
  3310. if (lpfc_readl(phba->HSregaddr, &status)) {
  3311. retval = 1;
  3312. break;
  3313. }
  3314. }
  3315. /* Check to see if any errors occurred during init */
  3316. if ((status & HS_FFERM) || (i >= 20)) {
  3317. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3318. "2751 Adapter failed to restart, "
  3319. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3320. status,
  3321. readl(phba->MBslimaddr + 0xa8),
  3322. readl(phba->MBslimaddr + 0xac));
  3323. phba->link_state = LPFC_HBA_ERROR;
  3324. retval = 1;
  3325. }
  3326. return retval;
  3327. }
  3328. /**
  3329. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3330. * @phba: Pointer to HBA context object.
  3331. * @mask: Bit mask to be checked.
  3332. *
  3333. * This function checks the host status register to check if HBA is
  3334. * ready. This function will wait in a loop for the HBA to be ready
  3335. * If the HBA is not ready , the function will will reset the HBA PCI
  3336. * function again. The function returns 1 when HBA fail to be ready
  3337. * otherwise returns zero.
  3338. **/
  3339. static int
  3340. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3341. {
  3342. uint32_t status;
  3343. int retval = 0;
  3344. /* Read the HBA Host Status Register */
  3345. status = lpfc_sli4_post_status_check(phba);
  3346. if (status) {
  3347. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3348. lpfc_sli_brdrestart(phba);
  3349. status = lpfc_sli4_post_status_check(phba);
  3350. }
  3351. /* Check to see if any errors occurred during init */
  3352. if (status) {
  3353. phba->link_state = LPFC_HBA_ERROR;
  3354. retval = 1;
  3355. } else
  3356. phba->sli4_hba.intr_enable = 0;
  3357. return retval;
  3358. }
  3359. /**
  3360. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3361. * @phba: Pointer to HBA context object.
  3362. * @mask: Bit mask to be checked.
  3363. *
  3364. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3365. * from the API jump table function pointer from the lpfc_hba struct.
  3366. **/
  3367. int
  3368. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3369. {
  3370. return phba->lpfc_sli_brdready(phba, mask);
  3371. }
  3372. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3373. /**
  3374. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3375. * @phba: Pointer to HBA context object.
  3376. *
  3377. * This function is called before resetting an HBA. This function is called
  3378. * with hbalock held and requests HBA to quiesce DMAs before a reset.
  3379. **/
  3380. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3381. {
  3382. uint32_t __iomem *resp_buf;
  3383. uint32_t __iomem *mbox_buf;
  3384. volatile uint32_t mbox;
  3385. uint32_t hc_copy, ha_copy, resp_data;
  3386. int i;
  3387. uint8_t hdrtype;
  3388. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3389. if (hdrtype != 0x80 ||
  3390. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3391. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3392. return;
  3393. /*
  3394. * Tell the other part of the chip to suspend temporarily all
  3395. * its DMA activity.
  3396. */
  3397. resp_buf = phba->MBslimaddr;
  3398. /* Disable the error attention */
  3399. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3400. return;
  3401. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3402. readl(phba->HCregaddr); /* flush */
  3403. phba->link_flag |= LS_IGNORE_ERATT;
  3404. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3405. return;
  3406. if (ha_copy & HA_ERATT) {
  3407. /* Clear Chip error bit */
  3408. writel(HA_ERATT, phba->HAregaddr);
  3409. phba->pport->stopped = 1;
  3410. }
  3411. mbox = 0;
  3412. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3413. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3414. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3415. mbox_buf = phba->MBslimaddr;
  3416. writel(mbox, mbox_buf);
  3417. for (i = 0; i < 50; i++) {
  3418. if (lpfc_readl((resp_buf + 1), &resp_data))
  3419. return;
  3420. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3421. mdelay(1);
  3422. else
  3423. break;
  3424. }
  3425. resp_data = 0;
  3426. if (lpfc_readl((resp_buf + 1), &resp_data))
  3427. return;
  3428. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3429. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3430. phba->pport->stopped)
  3431. goto restore_hc;
  3432. else
  3433. goto clear_errat;
  3434. }
  3435. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3436. resp_data = 0;
  3437. for (i = 0; i < 500; i++) {
  3438. if (lpfc_readl(resp_buf, &resp_data))
  3439. return;
  3440. if (resp_data != mbox)
  3441. mdelay(1);
  3442. else
  3443. break;
  3444. }
  3445. clear_errat:
  3446. while (++i < 500) {
  3447. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3448. return;
  3449. if (!(ha_copy & HA_ERATT))
  3450. mdelay(1);
  3451. else
  3452. break;
  3453. }
  3454. if (readl(phba->HAregaddr) & HA_ERATT) {
  3455. writel(HA_ERATT, phba->HAregaddr);
  3456. phba->pport->stopped = 1;
  3457. }
  3458. restore_hc:
  3459. phba->link_flag &= ~LS_IGNORE_ERATT;
  3460. writel(hc_copy, phba->HCregaddr);
  3461. readl(phba->HCregaddr); /* flush */
  3462. }
  3463. /**
  3464. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3465. * @phba: Pointer to HBA context object.
  3466. *
  3467. * This function issues a kill_board mailbox command and waits for
  3468. * the error attention interrupt. This function is called for stopping
  3469. * the firmware processing. The caller is not required to hold any
  3470. * locks. This function calls lpfc_hba_down_post function to free
  3471. * any pending commands after the kill. The function will return 1 when it
  3472. * fails to kill the board else will return 0.
  3473. **/
  3474. int
  3475. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3476. {
  3477. struct lpfc_sli *psli;
  3478. LPFC_MBOXQ_t *pmb;
  3479. uint32_t status;
  3480. uint32_t ha_copy;
  3481. int retval;
  3482. int i = 0;
  3483. psli = &phba->sli;
  3484. /* Kill HBA */
  3485. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3486. "0329 Kill HBA Data: x%x x%x\n",
  3487. phba->pport->port_state, psli->sli_flag);
  3488. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3489. if (!pmb)
  3490. return 1;
  3491. /* Disable the error attention */
  3492. spin_lock_irq(&phba->hbalock);
  3493. if (lpfc_readl(phba->HCregaddr, &status)) {
  3494. spin_unlock_irq(&phba->hbalock);
  3495. mempool_free(pmb, phba->mbox_mem_pool);
  3496. return 1;
  3497. }
  3498. status &= ~HC_ERINT_ENA;
  3499. writel(status, phba->HCregaddr);
  3500. readl(phba->HCregaddr); /* flush */
  3501. phba->link_flag |= LS_IGNORE_ERATT;
  3502. spin_unlock_irq(&phba->hbalock);
  3503. lpfc_kill_board(phba, pmb);
  3504. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3505. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3506. if (retval != MBX_SUCCESS) {
  3507. if (retval != MBX_BUSY)
  3508. mempool_free(pmb, phba->mbox_mem_pool);
  3509. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3510. "2752 KILL_BOARD command failed retval %d\n",
  3511. retval);
  3512. spin_lock_irq(&phba->hbalock);
  3513. phba->link_flag &= ~LS_IGNORE_ERATT;
  3514. spin_unlock_irq(&phba->hbalock);
  3515. return 1;
  3516. }
  3517. spin_lock_irq(&phba->hbalock);
  3518. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3519. spin_unlock_irq(&phba->hbalock);
  3520. mempool_free(pmb, phba->mbox_mem_pool);
  3521. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3522. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3523. * 3 seconds we still set HBA_ERROR state because the status of the
  3524. * board is now undefined.
  3525. */
  3526. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3527. return 1;
  3528. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3529. mdelay(100);
  3530. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3531. return 1;
  3532. }
  3533. del_timer_sync(&psli->mbox_tmo);
  3534. if (ha_copy & HA_ERATT) {
  3535. writel(HA_ERATT, phba->HAregaddr);
  3536. phba->pport->stopped = 1;
  3537. }
  3538. spin_lock_irq(&phba->hbalock);
  3539. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3540. psli->mbox_active = NULL;
  3541. phba->link_flag &= ~LS_IGNORE_ERATT;
  3542. spin_unlock_irq(&phba->hbalock);
  3543. lpfc_hba_down_post(phba);
  3544. phba->link_state = LPFC_HBA_ERROR;
  3545. return ha_copy & HA_ERATT ? 0 : 1;
  3546. }
  3547. /**
  3548. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3549. * @phba: Pointer to HBA context object.
  3550. *
  3551. * This function resets the HBA by writing HC_INITFF to the control
  3552. * register. After the HBA resets, this function resets all the iocb ring
  3553. * indices. This function disables PCI layer parity checking during
  3554. * the reset.
  3555. * This function returns 0 always.
  3556. * The caller is not required to hold any locks.
  3557. **/
  3558. int
  3559. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3560. {
  3561. struct lpfc_sli *psli;
  3562. struct lpfc_sli_ring *pring;
  3563. uint16_t cfg_value;
  3564. int i;
  3565. psli = &phba->sli;
  3566. /* Reset HBA */
  3567. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3568. "0325 Reset HBA Data: x%x x%x\n",
  3569. phba->pport->port_state, psli->sli_flag);
  3570. /* perform board reset */
  3571. phba->fc_eventTag = 0;
  3572. phba->link_events = 0;
  3573. phba->pport->fc_myDID = 0;
  3574. phba->pport->fc_prevDID = 0;
  3575. /* Turn off parity checking and serr during the physical reset */
  3576. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3577. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3578. (cfg_value &
  3579. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3580. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3581. /* Now toggle INITFF bit in the Host Control Register */
  3582. writel(HC_INITFF, phba->HCregaddr);
  3583. mdelay(1);
  3584. readl(phba->HCregaddr); /* flush */
  3585. writel(0, phba->HCregaddr);
  3586. readl(phba->HCregaddr); /* flush */
  3587. /* Restore PCI cmd register */
  3588. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3589. /* Initialize relevant SLI info */
  3590. for (i = 0; i < psli->num_rings; i++) {
  3591. pring = &psli->ring[i];
  3592. pring->flag = 0;
  3593. pring->sli.sli3.rspidx = 0;
  3594. pring->sli.sli3.next_cmdidx = 0;
  3595. pring->sli.sli3.local_getidx = 0;
  3596. pring->sli.sli3.cmdidx = 0;
  3597. pring->missbufcnt = 0;
  3598. }
  3599. phba->link_state = LPFC_WARM_START;
  3600. return 0;
  3601. }
  3602. /**
  3603. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3604. * @phba: Pointer to HBA context object.
  3605. *
  3606. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3607. * checking during resets the device. The caller is not required to hold
  3608. * any locks.
  3609. *
  3610. * This function returns 0 always.
  3611. **/
  3612. int
  3613. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3614. {
  3615. struct lpfc_sli *psli = &phba->sli;
  3616. uint16_t cfg_value;
  3617. int rc;
  3618. /* Reset HBA */
  3619. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3620. "0295 Reset HBA Data: x%x x%x\n",
  3621. phba->pport->port_state, psli->sli_flag);
  3622. /* perform board reset */
  3623. phba->fc_eventTag = 0;
  3624. phba->link_events = 0;
  3625. phba->pport->fc_myDID = 0;
  3626. phba->pport->fc_prevDID = 0;
  3627. spin_lock_irq(&phba->hbalock);
  3628. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3629. phba->fcf.fcf_flag = 0;
  3630. spin_unlock_irq(&phba->hbalock);
  3631. /* Now physically reset the device */
  3632. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3633. "0389 Performing PCI function reset!\n");
  3634. /* Turn off parity checking and serr during the physical reset */
  3635. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3636. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3637. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3638. /* Perform FCoE PCI function reset before freeing queue memory */
  3639. rc = lpfc_pci_function_reset(phba);
  3640. lpfc_sli4_queue_destroy(phba);
  3641. /* Restore PCI cmd register */
  3642. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3643. return rc;
  3644. }
  3645. /**
  3646. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3647. * @phba: Pointer to HBA context object.
  3648. *
  3649. * This function is called in the SLI initialization code path to
  3650. * restart the HBA. The caller is not required to hold any lock.
  3651. * This function writes MBX_RESTART mailbox command to the SLIM and
  3652. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3653. * function to free any pending commands. The function enables
  3654. * POST only during the first initialization. The function returns zero.
  3655. * The function does not guarantee completion of MBX_RESTART mailbox
  3656. * command before the return of this function.
  3657. **/
  3658. static int
  3659. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3660. {
  3661. MAILBOX_t *mb;
  3662. struct lpfc_sli *psli;
  3663. volatile uint32_t word0;
  3664. void __iomem *to_slim;
  3665. uint32_t hba_aer_enabled;
  3666. spin_lock_irq(&phba->hbalock);
  3667. /* Take PCIe device Advanced Error Reporting (AER) state */
  3668. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3669. psli = &phba->sli;
  3670. /* Restart HBA */
  3671. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3672. "0337 Restart HBA Data: x%x x%x\n",
  3673. phba->pport->port_state, psli->sli_flag);
  3674. word0 = 0;
  3675. mb = (MAILBOX_t *) &word0;
  3676. mb->mbxCommand = MBX_RESTART;
  3677. mb->mbxHc = 1;
  3678. lpfc_reset_barrier(phba);
  3679. to_slim = phba->MBslimaddr;
  3680. writel(*(uint32_t *) mb, to_slim);
  3681. readl(to_slim); /* flush */
  3682. /* Only skip post after fc_ffinit is completed */
  3683. if (phba->pport->port_state)
  3684. word0 = 1; /* This is really setting up word1 */
  3685. else
  3686. word0 = 0; /* This is really setting up word1 */
  3687. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3688. writel(*(uint32_t *) mb, to_slim);
  3689. readl(to_slim); /* flush */
  3690. lpfc_sli_brdreset(phba);
  3691. phba->pport->stopped = 0;
  3692. phba->link_state = LPFC_INIT_START;
  3693. phba->hba_flag = 0;
  3694. spin_unlock_irq(&phba->hbalock);
  3695. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3696. psli->stats_start = get_seconds();
  3697. /* Give the INITFF and Post time to settle. */
  3698. mdelay(100);
  3699. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3700. if (hba_aer_enabled)
  3701. pci_disable_pcie_error_reporting(phba->pcidev);
  3702. lpfc_hba_down_post(phba);
  3703. return 0;
  3704. }
  3705. /**
  3706. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3707. * @phba: Pointer to HBA context object.
  3708. *
  3709. * This function is called in the SLI initialization code path to restart
  3710. * a SLI4 HBA. The caller is not required to hold any lock.
  3711. * At the end of the function, it calls lpfc_hba_down_post function to
  3712. * free any pending commands.
  3713. **/
  3714. static int
  3715. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3716. {
  3717. struct lpfc_sli *psli = &phba->sli;
  3718. uint32_t hba_aer_enabled;
  3719. int rc;
  3720. /* Restart HBA */
  3721. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3722. "0296 Restart HBA Data: x%x x%x\n",
  3723. phba->pport->port_state, psli->sli_flag);
  3724. /* Take PCIe device Advanced Error Reporting (AER) state */
  3725. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3726. rc = lpfc_sli4_brdreset(phba);
  3727. spin_lock_irq(&phba->hbalock);
  3728. phba->pport->stopped = 0;
  3729. phba->link_state = LPFC_INIT_START;
  3730. phba->hba_flag = 0;
  3731. spin_unlock_irq(&phba->hbalock);
  3732. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3733. psli->stats_start = get_seconds();
  3734. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3735. if (hba_aer_enabled)
  3736. pci_disable_pcie_error_reporting(phba->pcidev);
  3737. lpfc_hba_down_post(phba);
  3738. return rc;
  3739. }
  3740. /**
  3741. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3742. * @phba: Pointer to HBA context object.
  3743. *
  3744. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3745. * API jump table function pointer from the lpfc_hba struct.
  3746. **/
  3747. int
  3748. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3749. {
  3750. return phba->lpfc_sli_brdrestart(phba);
  3751. }
  3752. /**
  3753. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3754. * @phba: Pointer to HBA context object.
  3755. *
  3756. * This function is called after a HBA restart to wait for successful
  3757. * restart of the HBA. Successful restart of the HBA is indicated by
  3758. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3759. * iteration, the function will restart the HBA again. The function returns
  3760. * zero if HBA successfully restarted else returns negative error code.
  3761. **/
  3762. static int
  3763. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3764. {
  3765. uint32_t status, i = 0;
  3766. /* Read the HBA Host Status Register */
  3767. if (lpfc_readl(phba->HSregaddr, &status))
  3768. return -EIO;
  3769. /* Check status register to see what current state is */
  3770. i = 0;
  3771. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3772. /* Check every 10ms for 10 retries, then every 100ms for 90
  3773. * retries, then every 1 sec for 50 retires for a total of
  3774. * ~60 seconds before reset the board again and check every
  3775. * 1 sec for 50 retries. The up to 60 seconds before the
  3776. * board ready is required by the Falcon FIPS zeroization
  3777. * complete, and any reset the board in between shall cause
  3778. * restart of zeroization, further delay the board ready.
  3779. */
  3780. if (i++ >= 200) {
  3781. /* Adapter failed to init, timeout, status reg
  3782. <status> */
  3783. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3784. "0436 Adapter failed to init, "
  3785. "timeout, status reg x%x, "
  3786. "FW Data: A8 x%x AC x%x\n", status,
  3787. readl(phba->MBslimaddr + 0xa8),
  3788. readl(phba->MBslimaddr + 0xac));
  3789. phba->link_state = LPFC_HBA_ERROR;
  3790. return -ETIMEDOUT;
  3791. }
  3792. /* Check to see if any errors occurred during init */
  3793. if (status & HS_FFERM) {
  3794. /* ERROR: During chipset initialization */
  3795. /* Adapter failed to init, chipset, status reg
  3796. <status> */
  3797. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3798. "0437 Adapter failed to init, "
  3799. "chipset, status reg x%x, "
  3800. "FW Data: A8 x%x AC x%x\n", status,
  3801. readl(phba->MBslimaddr + 0xa8),
  3802. readl(phba->MBslimaddr + 0xac));
  3803. phba->link_state = LPFC_HBA_ERROR;
  3804. return -EIO;
  3805. }
  3806. if (i <= 10)
  3807. msleep(10);
  3808. else if (i <= 100)
  3809. msleep(100);
  3810. else
  3811. msleep(1000);
  3812. if (i == 150) {
  3813. /* Do post */
  3814. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3815. lpfc_sli_brdrestart(phba);
  3816. }
  3817. /* Read the HBA Host Status Register */
  3818. if (lpfc_readl(phba->HSregaddr, &status))
  3819. return -EIO;
  3820. }
  3821. /* Check to see if any errors occurred during init */
  3822. if (status & HS_FFERM) {
  3823. /* ERROR: During chipset initialization */
  3824. /* Adapter failed to init, chipset, status reg <status> */
  3825. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3826. "0438 Adapter failed to init, chipset, "
  3827. "status reg x%x, "
  3828. "FW Data: A8 x%x AC x%x\n", status,
  3829. readl(phba->MBslimaddr + 0xa8),
  3830. readl(phba->MBslimaddr + 0xac));
  3831. phba->link_state = LPFC_HBA_ERROR;
  3832. return -EIO;
  3833. }
  3834. /* Clear all interrupt enable conditions */
  3835. writel(0, phba->HCregaddr);
  3836. readl(phba->HCregaddr); /* flush */
  3837. /* setup host attn register */
  3838. writel(0xffffffff, phba->HAregaddr);
  3839. readl(phba->HAregaddr); /* flush */
  3840. return 0;
  3841. }
  3842. /**
  3843. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3844. *
  3845. * This function calculates and returns the number of HBQs required to be
  3846. * configured.
  3847. **/
  3848. int
  3849. lpfc_sli_hbq_count(void)
  3850. {
  3851. return ARRAY_SIZE(lpfc_hbq_defs);
  3852. }
  3853. /**
  3854. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3855. *
  3856. * This function adds the number of hbq entries in every HBQ to get
  3857. * the total number of hbq entries required for the HBA and returns
  3858. * the total count.
  3859. **/
  3860. static int
  3861. lpfc_sli_hbq_entry_count(void)
  3862. {
  3863. int hbq_count = lpfc_sli_hbq_count();
  3864. int count = 0;
  3865. int i;
  3866. for (i = 0; i < hbq_count; ++i)
  3867. count += lpfc_hbq_defs[i]->entry_count;
  3868. return count;
  3869. }
  3870. /**
  3871. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3872. *
  3873. * This function calculates amount of memory required for all hbq entries
  3874. * to be configured and returns the total memory required.
  3875. **/
  3876. int
  3877. lpfc_sli_hbq_size(void)
  3878. {
  3879. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3880. }
  3881. /**
  3882. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3883. * @phba: Pointer to HBA context object.
  3884. *
  3885. * This function is called during the SLI initialization to configure
  3886. * all the HBQs and post buffers to the HBQ. The caller is not
  3887. * required to hold any locks. This function will return zero if successful
  3888. * else it will return negative error code.
  3889. **/
  3890. static int
  3891. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3892. {
  3893. int hbq_count = lpfc_sli_hbq_count();
  3894. LPFC_MBOXQ_t *pmb;
  3895. MAILBOX_t *pmbox;
  3896. uint32_t hbqno;
  3897. uint32_t hbq_entry_index;
  3898. /* Get a Mailbox buffer to setup mailbox
  3899. * commands for HBA initialization
  3900. */
  3901. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3902. if (!pmb)
  3903. return -ENOMEM;
  3904. pmbox = &pmb->u.mb;
  3905. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3906. phba->link_state = LPFC_INIT_MBX_CMDS;
  3907. phba->hbq_in_use = 1;
  3908. hbq_entry_index = 0;
  3909. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3910. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3911. phba->hbqs[hbqno].hbqPutIdx = 0;
  3912. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3913. phba->hbqs[hbqno].entry_count =
  3914. lpfc_hbq_defs[hbqno]->entry_count;
  3915. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3916. hbq_entry_index, pmb);
  3917. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3918. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3919. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3920. mbxStatus <status>, ring <num> */
  3921. lpfc_printf_log(phba, KERN_ERR,
  3922. LOG_SLI | LOG_VPORT,
  3923. "1805 Adapter failed to init. "
  3924. "Data: x%x x%x x%x\n",
  3925. pmbox->mbxCommand,
  3926. pmbox->mbxStatus, hbqno);
  3927. phba->link_state = LPFC_HBA_ERROR;
  3928. mempool_free(pmb, phba->mbox_mem_pool);
  3929. return -ENXIO;
  3930. }
  3931. }
  3932. phba->hbq_count = hbq_count;
  3933. mempool_free(pmb, phba->mbox_mem_pool);
  3934. /* Initially populate or replenish the HBQs */
  3935. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3936. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3937. return 0;
  3938. }
  3939. /**
  3940. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3941. * @phba: Pointer to HBA context object.
  3942. *
  3943. * This function is called during the SLI initialization to configure
  3944. * all the HBQs and post buffers to the HBQ. The caller is not
  3945. * required to hold any locks. This function will return zero if successful
  3946. * else it will return negative error code.
  3947. **/
  3948. static int
  3949. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3950. {
  3951. phba->hbq_in_use = 1;
  3952. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3953. phba->hbq_count = 1;
  3954. /* Initially populate or replenish the HBQs */
  3955. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3956. return 0;
  3957. }
  3958. /**
  3959. * lpfc_sli_config_port - Issue config port mailbox command
  3960. * @phba: Pointer to HBA context object.
  3961. * @sli_mode: sli mode - 2/3
  3962. *
  3963. * This function is called by the sli intialization code path
  3964. * to issue config_port mailbox command. This function restarts the
  3965. * HBA firmware and issues a config_port mailbox command to configure
  3966. * the SLI interface in the sli mode specified by sli_mode
  3967. * variable. The caller is not required to hold any locks.
  3968. * The function returns 0 if successful, else returns negative error
  3969. * code.
  3970. **/
  3971. int
  3972. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3973. {
  3974. LPFC_MBOXQ_t *pmb;
  3975. uint32_t resetcount = 0, rc = 0, done = 0;
  3976. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3977. if (!pmb) {
  3978. phba->link_state = LPFC_HBA_ERROR;
  3979. return -ENOMEM;
  3980. }
  3981. phba->sli_rev = sli_mode;
  3982. while (resetcount < 2 && !done) {
  3983. spin_lock_irq(&phba->hbalock);
  3984. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3985. spin_unlock_irq(&phba->hbalock);
  3986. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3987. lpfc_sli_brdrestart(phba);
  3988. rc = lpfc_sli_chipset_init(phba);
  3989. if (rc)
  3990. break;
  3991. spin_lock_irq(&phba->hbalock);
  3992. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3993. spin_unlock_irq(&phba->hbalock);
  3994. resetcount++;
  3995. /* Call pre CONFIG_PORT mailbox command initialization. A
  3996. * value of 0 means the call was successful. Any other
  3997. * nonzero value is a failure, but if ERESTART is returned,
  3998. * the driver may reset the HBA and try again.
  3999. */
  4000. rc = lpfc_config_port_prep(phba);
  4001. if (rc == -ERESTART) {
  4002. phba->link_state = LPFC_LINK_UNKNOWN;
  4003. continue;
  4004. } else if (rc)
  4005. break;
  4006. phba->link_state = LPFC_INIT_MBX_CMDS;
  4007. lpfc_config_port(phba, pmb);
  4008. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  4009. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  4010. LPFC_SLI3_HBQ_ENABLED |
  4011. LPFC_SLI3_CRP_ENABLED |
  4012. LPFC_SLI3_BG_ENABLED |
  4013. LPFC_SLI3_DSS_ENABLED);
  4014. if (rc != MBX_SUCCESS) {
  4015. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4016. "0442 Adapter failed to init, mbxCmd x%x "
  4017. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  4018. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  4019. spin_lock_irq(&phba->hbalock);
  4020. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  4021. spin_unlock_irq(&phba->hbalock);
  4022. rc = -ENXIO;
  4023. } else {
  4024. /* Allow asynchronous mailbox command to go through */
  4025. spin_lock_irq(&phba->hbalock);
  4026. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4027. spin_unlock_irq(&phba->hbalock);
  4028. done = 1;
  4029. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  4030. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  4031. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4032. "3110 Port did not grant ASABT\n");
  4033. }
  4034. }
  4035. if (!done) {
  4036. rc = -EINVAL;
  4037. goto do_prep_failed;
  4038. }
  4039. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  4040. if (!pmb->u.mb.un.varCfgPort.cMA) {
  4041. rc = -ENXIO;
  4042. goto do_prep_failed;
  4043. }
  4044. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  4045. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  4046. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  4047. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  4048. phba->max_vpi : phba->max_vports;
  4049. } else
  4050. phba->max_vpi = 0;
  4051. phba->fips_level = 0;
  4052. phba->fips_spec_rev = 0;
  4053. if (pmb->u.mb.un.varCfgPort.gdss) {
  4054. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  4055. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  4056. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  4057. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4058. "2850 Security Crypto Active. FIPS x%d "
  4059. "(Spec Rev: x%d)",
  4060. phba->fips_level, phba->fips_spec_rev);
  4061. }
  4062. if (pmb->u.mb.un.varCfgPort.sec_err) {
  4063. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4064. "2856 Config Port Security Crypto "
  4065. "Error: x%x ",
  4066. pmb->u.mb.un.varCfgPort.sec_err);
  4067. }
  4068. if (pmb->u.mb.un.varCfgPort.gerbm)
  4069. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  4070. if (pmb->u.mb.un.varCfgPort.gcrp)
  4071. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  4072. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  4073. phba->port_gp = phba->mbox->us.s3_pgp.port;
  4074. if (phba->cfg_enable_bg) {
  4075. if (pmb->u.mb.un.varCfgPort.gbg)
  4076. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  4077. else
  4078. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4079. "0443 Adapter did not grant "
  4080. "BlockGuard\n");
  4081. }
  4082. } else {
  4083. phba->hbq_get = NULL;
  4084. phba->port_gp = phba->mbox->us.s2.port;
  4085. phba->max_vpi = 0;
  4086. }
  4087. do_prep_failed:
  4088. mempool_free(pmb, phba->mbox_mem_pool);
  4089. return rc;
  4090. }
  4091. /**
  4092. * lpfc_sli_hba_setup - SLI intialization function
  4093. * @phba: Pointer to HBA context object.
  4094. *
  4095. * This function is the main SLI intialization function. This function
  4096. * is called by the HBA intialization code, HBA reset code and HBA
  4097. * error attention handler code. Caller is not required to hold any
  4098. * locks. This function issues config_port mailbox command to configure
  4099. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4100. * calls the config_port_post function to issue init_link mailbox
  4101. * command and to start the discovery. The function will return zero
  4102. * if successful, else it will return negative error code.
  4103. **/
  4104. int
  4105. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4106. {
  4107. uint32_t rc;
  4108. int mode = 3, i;
  4109. int longs;
  4110. switch (lpfc_sli_mode) {
  4111. case 2:
  4112. if (phba->cfg_enable_npiv) {
  4113. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4114. "1824 NPIV enabled: Override lpfc_sli_mode "
  4115. "parameter (%d) to auto (0).\n",
  4116. lpfc_sli_mode);
  4117. break;
  4118. }
  4119. mode = 2;
  4120. break;
  4121. case 0:
  4122. case 3:
  4123. break;
  4124. default:
  4125. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4126. "1819 Unrecognized lpfc_sli_mode "
  4127. "parameter: %d.\n", lpfc_sli_mode);
  4128. break;
  4129. }
  4130. rc = lpfc_sli_config_port(phba, mode);
  4131. if (rc && lpfc_sli_mode == 3)
  4132. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4133. "1820 Unable to select SLI-3. "
  4134. "Not supported by adapter.\n");
  4135. if (rc && mode != 2)
  4136. rc = lpfc_sli_config_port(phba, 2);
  4137. if (rc)
  4138. goto lpfc_sli_hba_setup_error;
  4139. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4140. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4141. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4142. if (!rc) {
  4143. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4144. "2709 This device supports "
  4145. "Advanced Error Reporting (AER)\n");
  4146. spin_lock_irq(&phba->hbalock);
  4147. phba->hba_flag |= HBA_AER_ENABLED;
  4148. spin_unlock_irq(&phba->hbalock);
  4149. } else {
  4150. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4151. "2708 This device does not support "
  4152. "Advanced Error Reporting (AER)\n");
  4153. phba->cfg_aer_support = 0;
  4154. }
  4155. }
  4156. if (phba->sli_rev == 3) {
  4157. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4158. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4159. } else {
  4160. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4161. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4162. phba->sli3_options = 0;
  4163. }
  4164. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4165. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4166. phba->sli_rev, phba->max_vpi);
  4167. rc = lpfc_sli_ring_map(phba);
  4168. if (rc)
  4169. goto lpfc_sli_hba_setup_error;
  4170. /* Initialize VPIs. */
  4171. if (phba->sli_rev == LPFC_SLI_REV3) {
  4172. /*
  4173. * The VPI bitmask and physical ID array are allocated
  4174. * and initialized once only - at driver load. A port
  4175. * reset doesn't need to reinitialize this memory.
  4176. */
  4177. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4178. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4179. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4180. GFP_KERNEL);
  4181. if (!phba->vpi_bmask) {
  4182. rc = -ENOMEM;
  4183. goto lpfc_sli_hba_setup_error;
  4184. }
  4185. phba->vpi_ids = kzalloc(
  4186. (phba->max_vpi+1) * sizeof(uint16_t),
  4187. GFP_KERNEL);
  4188. if (!phba->vpi_ids) {
  4189. kfree(phba->vpi_bmask);
  4190. rc = -ENOMEM;
  4191. goto lpfc_sli_hba_setup_error;
  4192. }
  4193. for (i = 0; i < phba->max_vpi; i++)
  4194. phba->vpi_ids[i] = i;
  4195. }
  4196. }
  4197. /* Init HBQs */
  4198. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4199. rc = lpfc_sli_hbq_setup(phba);
  4200. if (rc)
  4201. goto lpfc_sli_hba_setup_error;
  4202. }
  4203. spin_lock_irq(&phba->hbalock);
  4204. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4205. spin_unlock_irq(&phba->hbalock);
  4206. rc = lpfc_config_port_post(phba);
  4207. if (rc)
  4208. goto lpfc_sli_hba_setup_error;
  4209. return rc;
  4210. lpfc_sli_hba_setup_error:
  4211. phba->link_state = LPFC_HBA_ERROR;
  4212. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4213. "0445 Firmware initialization failed\n");
  4214. return rc;
  4215. }
  4216. /**
  4217. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4218. * @phba: Pointer to HBA context object.
  4219. * @mboxq: mailbox pointer.
  4220. * This function issue a dump mailbox command to read config region
  4221. * 23 and parse the records in the region and populate driver
  4222. * data structure.
  4223. **/
  4224. static int
  4225. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4226. {
  4227. LPFC_MBOXQ_t *mboxq;
  4228. struct lpfc_dmabuf *mp;
  4229. struct lpfc_mqe *mqe;
  4230. uint32_t data_length;
  4231. int rc;
  4232. /* Program the default value of vlan_id and fc_map */
  4233. phba->valid_vlan = 0;
  4234. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4235. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4236. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4237. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4238. if (!mboxq)
  4239. return -ENOMEM;
  4240. mqe = &mboxq->u.mqe;
  4241. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4242. rc = -ENOMEM;
  4243. goto out_free_mboxq;
  4244. }
  4245. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4246. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4247. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4248. "(%d):2571 Mailbox cmd x%x Status x%x "
  4249. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4250. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4251. "CQ: x%x x%x x%x x%x\n",
  4252. mboxq->vport ? mboxq->vport->vpi : 0,
  4253. bf_get(lpfc_mqe_command, mqe),
  4254. bf_get(lpfc_mqe_status, mqe),
  4255. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4256. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4257. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4258. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4259. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4260. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4261. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4262. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4263. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4264. mboxq->mcqe.word0,
  4265. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4266. mboxq->mcqe.trailer);
  4267. if (rc) {
  4268. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4269. kfree(mp);
  4270. rc = -EIO;
  4271. goto out_free_mboxq;
  4272. }
  4273. data_length = mqe->un.mb_words[5];
  4274. if (data_length > DMP_RGN23_SIZE) {
  4275. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4276. kfree(mp);
  4277. rc = -EIO;
  4278. goto out_free_mboxq;
  4279. }
  4280. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4281. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4282. kfree(mp);
  4283. rc = 0;
  4284. out_free_mboxq:
  4285. mempool_free(mboxq, phba->mbox_mem_pool);
  4286. return rc;
  4287. }
  4288. /**
  4289. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4290. * @phba: pointer to lpfc hba data structure.
  4291. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4292. * @vpd: pointer to the memory to hold resulting port vpd data.
  4293. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4294. * On output, the number of data bytes in @vpd.
  4295. *
  4296. * This routine executes a READ_REV SLI4 mailbox command. In
  4297. * addition, this routine gets the port vpd data.
  4298. *
  4299. * Return codes
  4300. * 0 - successful
  4301. * -ENOMEM - could not allocated memory.
  4302. **/
  4303. static int
  4304. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4305. uint8_t *vpd, uint32_t *vpd_size)
  4306. {
  4307. int rc = 0;
  4308. uint32_t dma_size;
  4309. struct lpfc_dmabuf *dmabuf;
  4310. struct lpfc_mqe *mqe;
  4311. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4312. if (!dmabuf)
  4313. return -ENOMEM;
  4314. /*
  4315. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4316. * mailbox command.
  4317. */
  4318. dma_size = *vpd_size;
  4319. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4320. dma_size,
  4321. &dmabuf->phys,
  4322. GFP_KERNEL);
  4323. if (!dmabuf->virt) {
  4324. kfree(dmabuf);
  4325. return -ENOMEM;
  4326. }
  4327. memset(dmabuf->virt, 0, dma_size);
  4328. /*
  4329. * The SLI4 implementation of READ_REV conflicts at word1,
  4330. * bits 31:16 and SLI4 adds vpd functionality not present
  4331. * in SLI3. This code corrects the conflicts.
  4332. */
  4333. lpfc_read_rev(phba, mboxq);
  4334. mqe = &mboxq->u.mqe;
  4335. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4336. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4337. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4338. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4339. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4340. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4341. if (rc) {
  4342. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4343. dmabuf->virt, dmabuf->phys);
  4344. kfree(dmabuf);
  4345. return -EIO;
  4346. }
  4347. /*
  4348. * The available vpd length cannot be bigger than the
  4349. * DMA buffer passed to the port. Catch the less than
  4350. * case and update the caller's size.
  4351. */
  4352. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4353. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4354. memcpy(vpd, dmabuf->virt, *vpd_size);
  4355. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4356. dmabuf->virt, dmabuf->phys);
  4357. kfree(dmabuf);
  4358. return 0;
  4359. }
  4360. /**
  4361. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4362. * @phba: pointer to lpfc hba data structure.
  4363. *
  4364. * This routine retrieves SLI4 device physical port name this PCI function
  4365. * is attached to.
  4366. *
  4367. * Return codes
  4368. * 0 - successful
  4369. * otherwise - failed to retrieve physical port name
  4370. **/
  4371. static int
  4372. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4373. {
  4374. LPFC_MBOXQ_t *mboxq;
  4375. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4376. struct lpfc_controller_attribute *cntl_attr;
  4377. struct lpfc_mbx_get_port_name *get_port_name;
  4378. void *virtaddr = NULL;
  4379. uint32_t alloclen, reqlen;
  4380. uint32_t shdr_status, shdr_add_status;
  4381. union lpfc_sli4_cfg_shdr *shdr;
  4382. char cport_name = 0;
  4383. int rc;
  4384. /* We assume nothing at this point */
  4385. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4386. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4387. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4388. if (!mboxq)
  4389. return -ENOMEM;
  4390. /* obtain link type and link number via READ_CONFIG */
  4391. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4392. lpfc_sli4_read_config(phba);
  4393. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4394. goto retrieve_ppname;
  4395. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4396. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4397. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4398. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4399. LPFC_SLI4_MBX_NEMBED);
  4400. if (alloclen < reqlen) {
  4401. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4402. "3084 Allocated DMA memory size (%d) is "
  4403. "less than the requested DMA memory size "
  4404. "(%d)\n", alloclen, reqlen);
  4405. rc = -ENOMEM;
  4406. goto out_free_mboxq;
  4407. }
  4408. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4409. virtaddr = mboxq->sge_array->addr[0];
  4410. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4411. shdr = &mbx_cntl_attr->cfg_shdr;
  4412. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4413. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4414. if (shdr_status || shdr_add_status || rc) {
  4415. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4416. "3085 Mailbox x%x (x%x/x%x) failed, "
  4417. "rc:x%x, status:x%x, add_status:x%x\n",
  4418. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4419. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4420. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4421. rc, shdr_status, shdr_add_status);
  4422. rc = -ENXIO;
  4423. goto out_free_mboxq;
  4424. }
  4425. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4426. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4427. phba->sli4_hba.lnk_info.lnk_tp =
  4428. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4429. phba->sli4_hba.lnk_info.lnk_no =
  4430. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4431. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4432. "3086 lnk_type:%d, lnk_numb:%d\n",
  4433. phba->sli4_hba.lnk_info.lnk_tp,
  4434. phba->sli4_hba.lnk_info.lnk_no);
  4435. retrieve_ppname:
  4436. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4437. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4438. sizeof(struct lpfc_mbx_get_port_name) -
  4439. sizeof(struct lpfc_sli4_cfg_mhdr),
  4440. LPFC_SLI4_MBX_EMBED);
  4441. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4442. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4443. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4444. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4445. phba->sli4_hba.lnk_info.lnk_tp);
  4446. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4447. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4448. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4449. if (shdr_status || shdr_add_status || rc) {
  4450. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4451. "3087 Mailbox x%x (x%x/x%x) failed: "
  4452. "rc:x%x, status:x%x, add_status:x%x\n",
  4453. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4454. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4455. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4456. rc, shdr_status, shdr_add_status);
  4457. rc = -ENXIO;
  4458. goto out_free_mboxq;
  4459. }
  4460. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4461. case LPFC_LINK_NUMBER_0:
  4462. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4463. &get_port_name->u.response);
  4464. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4465. break;
  4466. case LPFC_LINK_NUMBER_1:
  4467. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4468. &get_port_name->u.response);
  4469. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4470. break;
  4471. case LPFC_LINK_NUMBER_2:
  4472. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4473. &get_port_name->u.response);
  4474. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4475. break;
  4476. case LPFC_LINK_NUMBER_3:
  4477. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4478. &get_port_name->u.response);
  4479. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4480. break;
  4481. default:
  4482. break;
  4483. }
  4484. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4485. phba->Port[0] = cport_name;
  4486. phba->Port[1] = '\0';
  4487. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4488. "3091 SLI get port name: %s\n", phba->Port);
  4489. }
  4490. out_free_mboxq:
  4491. if (rc != MBX_TIMEOUT) {
  4492. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4493. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4494. else
  4495. mempool_free(mboxq, phba->mbox_mem_pool);
  4496. }
  4497. return rc;
  4498. }
  4499. /**
  4500. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4501. * @phba: pointer to lpfc hba data structure.
  4502. *
  4503. * This routine is called to explicitly arm the SLI4 device's completion and
  4504. * event queues
  4505. **/
  4506. static void
  4507. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4508. {
  4509. int fcp_eqidx;
  4510. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4511. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4512. fcp_eqidx = 0;
  4513. if (phba->sli4_hba.fcp_cq) {
  4514. do {
  4515. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4516. LPFC_QUEUE_REARM);
  4517. } while (++fcp_eqidx < phba->cfg_fcp_io_channel);
  4518. }
  4519. if (phba->sli4_hba.hba_eq) {
  4520. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
  4521. fcp_eqidx++)
  4522. lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx],
  4523. LPFC_QUEUE_REARM);
  4524. }
  4525. }
  4526. /**
  4527. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4528. * @phba: Pointer to HBA context object.
  4529. * @type: The resource extent type.
  4530. * @extnt_count: buffer to hold port available extent count.
  4531. * @extnt_size: buffer to hold element count per extent.
  4532. *
  4533. * This function calls the port and retrievs the number of available
  4534. * extents and their size for a particular extent type.
  4535. *
  4536. * Returns: 0 if successful. Nonzero otherwise.
  4537. **/
  4538. int
  4539. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4540. uint16_t *extnt_count, uint16_t *extnt_size)
  4541. {
  4542. int rc = 0;
  4543. uint32_t length;
  4544. uint32_t mbox_tmo;
  4545. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4546. LPFC_MBOXQ_t *mbox;
  4547. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4548. if (!mbox)
  4549. return -ENOMEM;
  4550. /* Find out how many extents are available for this resource type */
  4551. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4552. sizeof(struct lpfc_sli4_cfg_mhdr));
  4553. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4554. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4555. length, LPFC_SLI4_MBX_EMBED);
  4556. /* Send an extents count of 0 - the GET doesn't use it. */
  4557. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4558. LPFC_SLI4_MBX_EMBED);
  4559. if (unlikely(rc)) {
  4560. rc = -EIO;
  4561. goto err_exit;
  4562. }
  4563. if (!phba->sli4_hba.intr_enable)
  4564. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4565. else {
  4566. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4567. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4568. }
  4569. if (unlikely(rc)) {
  4570. rc = -EIO;
  4571. goto err_exit;
  4572. }
  4573. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4574. if (bf_get(lpfc_mbox_hdr_status,
  4575. &rsrc_info->header.cfg_shdr.response)) {
  4576. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4577. "2930 Failed to get resource extents "
  4578. "Status 0x%x Add'l Status 0x%x\n",
  4579. bf_get(lpfc_mbox_hdr_status,
  4580. &rsrc_info->header.cfg_shdr.response),
  4581. bf_get(lpfc_mbox_hdr_add_status,
  4582. &rsrc_info->header.cfg_shdr.response));
  4583. rc = -EIO;
  4584. goto err_exit;
  4585. }
  4586. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4587. &rsrc_info->u.rsp);
  4588. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4589. &rsrc_info->u.rsp);
  4590. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4591. "3162 Retrieved extents type-%d from port: count:%d, "
  4592. "size:%d\n", type, *extnt_count, *extnt_size);
  4593. err_exit:
  4594. mempool_free(mbox, phba->mbox_mem_pool);
  4595. return rc;
  4596. }
  4597. /**
  4598. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4599. * @phba: Pointer to HBA context object.
  4600. * @type: The extent type to check.
  4601. *
  4602. * This function reads the current available extents from the port and checks
  4603. * if the extent count or extent size has changed since the last access.
  4604. * Callers use this routine post port reset to understand if there is a
  4605. * extent reprovisioning requirement.
  4606. *
  4607. * Returns:
  4608. * -Error: error indicates problem.
  4609. * 1: Extent count or size has changed.
  4610. * 0: No changes.
  4611. **/
  4612. static int
  4613. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4614. {
  4615. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4616. uint16_t size_diff, rsrc_ext_size;
  4617. int rc = 0;
  4618. struct lpfc_rsrc_blks *rsrc_entry;
  4619. struct list_head *rsrc_blk_list = NULL;
  4620. size_diff = 0;
  4621. curr_ext_cnt = 0;
  4622. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4623. &rsrc_ext_cnt,
  4624. &rsrc_ext_size);
  4625. if (unlikely(rc))
  4626. return -EIO;
  4627. switch (type) {
  4628. case LPFC_RSC_TYPE_FCOE_RPI:
  4629. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4630. break;
  4631. case LPFC_RSC_TYPE_FCOE_VPI:
  4632. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4633. break;
  4634. case LPFC_RSC_TYPE_FCOE_XRI:
  4635. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4636. break;
  4637. case LPFC_RSC_TYPE_FCOE_VFI:
  4638. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4639. break;
  4640. default:
  4641. break;
  4642. }
  4643. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4644. curr_ext_cnt++;
  4645. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4646. size_diff++;
  4647. }
  4648. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4649. rc = 1;
  4650. return rc;
  4651. }
  4652. /**
  4653. * lpfc_sli4_cfg_post_extnts -
  4654. * @phba: Pointer to HBA context object.
  4655. * @extnt_cnt - number of available extents.
  4656. * @type - the extent type (rpi, xri, vfi, vpi).
  4657. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4658. * @mbox - pointer to the caller's allocated mailbox structure.
  4659. *
  4660. * This function executes the extents allocation request. It also
  4661. * takes care of the amount of memory needed to allocate or get the
  4662. * allocated extents. It is the caller's responsibility to evaluate
  4663. * the response.
  4664. *
  4665. * Returns:
  4666. * -Error: Error value describes the condition found.
  4667. * 0: if successful
  4668. **/
  4669. static int
  4670. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
  4671. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4672. {
  4673. int rc = 0;
  4674. uint32_t req_len;
  4675. uint32_t emb_len;
  4676. uint32_t alloc_len, mbox_tmo;
  4677. /* Calculate the total requested length of the dma memory */
  4678. req_len = extnt_cnt * sizeof(uint16_t);
  4679. /*
  4680. * Calculate the size of an embedded mailbox. The uint32_t
  4681. * accounts for extents-specific word.
  4682. */
  4683. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4684. sizeof(uint32_t);
  4685. /*
  4686. * Presume the allocation and response will fit into an embedded
  4687. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4688. */
  4689. *emb = LPFC_SLI4_MBX_EMBED;
  4690. if (req_len > emb_len) {
  4691. req_len = extnt_cnt * sizeof(uint16_t) +
  4692. sizeof(union lpfc_sli4_cfg_shdr) +
  4693. sizeof(uint32_t);
  4694. *emb = LPFC_SLI4_MBX_NEMBED;
  4695. }
  4696. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4697. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4698. req_len, *emb);
  4699. if (alloc_len < req_len) {
  4700. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4701. "2982 Allocated DMA memory size (x%x) is "
  4702. "less than the requested DMA memory "
  4703. "size (x%x)\n", alloc_len, req_len);
  4704. return -ENOMEM;
  4705. }
  4706. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
  4707. if (unlikely(rc))
  4708. return -EIO;
  4709. if (!phba->sli4_hba.intr_enable)
  4710. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4711. else {
  4712. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4713. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4714. }
  4715. if (unlikely(rc))
  4716. rc = -EIO;
  4717. return rc;
  4718. }
  4719. /**
  4720. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4721. * @phba: Pointer to HBA context object.
  4722. * @type: The resource extent type to allocate.
  4723. *
  4724. * This function allocates the number of elements for the specified
  4725. * resource type.
  4726. **/
  4727. static int
  4728. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4729. {
  4730. bool emb = false;
  4731. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4732. uint16_t rsrc_id, rsrc_start, j, k;
  4733. uint16_t *ids;
  4734. int i, rc;
  4735. unsigned long longs;
  4736. unsigned long *bmask;
  4737. struct lpfc_rsrc_blks *rsrc_blks;
  4738. LPFC_MBOXQ_t *mbox;
  4739. uint32_t length;
  4740. struct lpfc_id_range *id_array = NULL;
  4741. void *virtaddr = NULL;
  4742. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4743. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4744. struct list_head *ext_blk_list;
  4745. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4746. &rsrc_cnt,
  4747. &rsrc_size);
  4748. if (unlikely(rc))
  4749. return -EIO;
  4750. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4751. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4752. "3009 No available Resource Extents "
  4753. "for resource type 0x%x: Count: 0x%x, "
  4754. "Size 0x%x\n", type, rsrc_cnt,
  4755. rsrc_size);
  4756. return -ENOMEM;
  4757. }
  4758. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
  4759. "2903 Post resource extents type-0x%x: "
  4760. "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
  4761. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4762. if (!mbox)
  4763. return -ENOMEM;
  4764. rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
  4765. if (unlikely(rc)) {
  4766. rc = -EIO;
  4767. goto err_exit;
  4768. }
  4769. /*
  4770. * Figure out where the response is located. Then get local pointers
  4771. * to the response data. The port does not guarantee to respond to
  4772. * all extents counts request so update the local variable with the
  4773. * allocated count from the port.
  4774. */
  4775. if (emb == LPFC_SLI4_MBX_EMBED) {
  4776. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4777. id_array = &rsrc_ext->u.rsp.id[0];
  4778. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4779. } else {
  4780. virtaddr = mbox->sge_array->addr[0];
  4781. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4782. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4783. id_array = &n_rsrc->id;
  4784. }
  4785. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4786. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4787. /*
  4788. * Based on the resource size and count, correct the base and max
  4789. * resource values.
  4790. */
  4791. length = sizeof(struct lpfc_rsrc_blks);
  4792. switch (type) {
  4793. case LPFC_RSC_TYPE_FCOE_RPI:
  4794. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4795. sizeof(unsigned long),
  4796. GFP_KERNEL);
  4797. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4798. rc = -ENOMEM;
  4799. goto err_exit;
  4800. }
  4801. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4802. sizeof(uint16_t),
  4803. GFP_KERNEL);
  4804. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4805. kfree(phba->sli4_hba.rpi_bmask);
  4806. rc = -ENOMEM;
  4807. goto err_exit;
  4808. }
  4809. /*
  4810. * The next_rpi was initialized with the maximum available
  4811. * count but the port may allocate a smaller number. Catch
  4812. * that case and update the next_rpi.
  4813. */
  4814. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4815. /* Initialize local ptrs for common extent processing later. */
  4816. bmask = phba->sli4_hba.rpi_bmask;
  4817. ids = phba->sli4_hba.rpi_ids;
  4818. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4819. break;
  4820. case LPFC_RSC_TYPE_FCOE_VPI:
  4821. phba->vpi_bmask = kzalloc(longs *
  4822. sizeof(unsigned long),
  4823. GFP_KERNEL);
  4824. if (unlikely(!phba->vpi_bmask)) {
  4825. rc = -ENOMEM;
  4826. goto err_exit;
  4827. }
  4828. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4829. sizeof(uint16_t),
  4830. GFP_KERNEL);
  4831. if (unlikely(!phba->vpi_ids)) {
  4832. kfree(phba->vpi_bmask);
  4833. rc = -ENOMEM;
  4834. goto err_exit;
  4835. }
  4836. /* Initialize local ptrs for common extent processing later. */
  4837. bmask = phba->vpi_bmask;
  4838. ids = phba->vpi_ids;
  4839. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4840. break;
  4841. case LPFC_RSC_TYPE_FCOE_XRI:
  4842. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4843. sizeof(unsigned long),
  4844. GFP_KERNEL);
  4845. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4846. rc = -ENOMEM;
  4847. goto err_exit;
  4848. }
  4849. phba->sli4_hba.max_cfg_param.xri_used = 0;
  4850. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4851. sizeof(uint16_t),
  4852. GFP_KERNEL);
  4853. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4854. kfree(phba->sli4_hba.xri_bmask);
  4855. rc = -ENOMEM;
  4856. goto err_exit;
  4857. }
  4858. /* Initialize local ptrs for common extent processing later. */
  4859. bmask = phba->sli4_hba.xri_bmask;
  4860. ids = phba->sli4_hba.xri_ids;
  4861. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4862. break;
  4863. case LPFC_RSC_TYPE_FCOE_VFI:
  4864. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4865. sizeof(unsigned long),
  4866. GFP_KERNEL);
  4867. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4868. rc = -ENOMEM;
  4869. goto err_exit;
  4870. }
  4871. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4872. sizeof(uint16_t),
  4873. GFP_KERNEL);
  4874. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4875. kfree(phba->sli4_hba.vfi_bmask);
  4876. rc = -ENOMEM;
  4877. goto err_exit;
  4878. }
  4879. /* Initialize local ptrs for common extent processing later. */
  4880. bmask = phba->sli4_hba.vfi_bmask;
  4881. ids = phba->sli4_hba.vfi_ids;
  4882. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4883. break;
  4884. default:
  4885. /* Unsupported Opcode. Fail call. */
  4886. id_array = NULL;
  4887. bmask = NULL;
  4888. ids = NULL;
  4889. ext_blk_list = NULL;
  4890. goto err_exit;
  4891. }
  4892. /*
  4893. * Complete initializing the extent configuration with the
  4894. * allocated ids assigned to this function. The bitmask serves
  4895. * as an index into the array and manages the available ids. The
  4896. * array just stores the ids communicated to the port via the wqes.
  4897. */
  4898. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  4899. if ((i % 2) == 0)
  4900. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  4901. &id_array[k]);
  4902. else
  4903. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  4904. &id_array[k]);
  4905. rsrc_blks = kzalloc(length, GFP_KERNEL);
  4906. if (unlikely(!rsrc_blks)) {
  4907. rc = -ENOMEM;
  4908. kfree(bmask);
  4909. kfree(ids);
  4910. goto err_exit;
  4911. }
  4912. rsrc_blks->rsrc_start = rsrc_id;
  4913. rsrc_blks->rsrc_size = rsrc_size;
  4914. list_add_tail(&rsrc_blks->list, ext_blk_list);
  4915. rsrc_start = rsrc_id;
  4916. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  4917. phba->sli4_hba.scsi_xri_start = rsrc_start +
  4918. lpfc_sli4_get_els_iocb_cnt(phba);
  4919. while (rsrc_id < (rsrc_start + rsrc_size)) {
  4920. ids[j] = rsrc_id;
  4921. rsrc_id++;
  4922. j++;
  4923. }
  4924. /* Entire word processed. Get next word.*/
  4925. if ((i % 2) == 1)
  4926. k++;
  4927. }
  4928. err_exit:
  4929. lpfc_sli4_mbox_cmd_free(phba, mbox);
  4930. return rc;
  4931. }
  4932. /**
  4933. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  4934. * @phba: Pointer to HBA context object.
  4935. * @type: the extent's type.
  4936. *
  4937. * This function deallocates all extents of a particular resource type.
  4938. * SLI4 does not allow for deallocating a particular extent range. It
  4939. * is the caller's responsibility to release all kernel memory resources.
  4940. **/
  4941. static int
  4942. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  4943. {
  4944. int rc;
  4945. uint32_t length, mbox_tmo = 0;
  4946. LPFC_MBOXQ_t *mbox;
  4947. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  4948. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  4949. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4950. if (!mbox)
  4951. return -ENOMEM;
  4952. /*
  4953. * This function sends an embedded mailbox because it only sends the
  4954. * the resource type. All extents of this type are released by the
  4955. * port.
  4956. */
  4957. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  4958. sizeof(struct lpfc_sli4_cfg_mhdr));
  4959. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4960. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  4961. length, LPFC_SLI4_MBX_EMBED);
  4962. /* Send an extents count of 0 - the dealloc doesn't use it. */
  4963. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4964. LPFC_SLI4_MBX_EMBED);
  4965. if (unlikely(rc)) {
  4966. rc = -EIO;
  4967. goto out_free_mbox;
  4968. }
  4969. if (!phba->sli4_hba.intr_enable)
  4970. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4971. else {
  4972. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4973. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4974. }
  4975. if (unlikely(rc)) {
  4976. rc = -EIO;
  4977. goto out_free_mbox;
  4978. }
  4979. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  4980. if (bf_get(lpfc_mbox_hdr_status,
  4981. &dealloc_rsrc->header.cfg_shdr.response)) {
  4982. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4983. "2919 Failed to release resource extents "
  4984. "for type %d - Status 0x%x Add'l Status 0x%x. "
  4985. "Resource memory not released.\n",
  4986. type,
  4987. bf_get(lpfc_mbox_hdr_status,
  4988. &dealloc_rsrc->header.cfg_shdr.response),
  4989. bf_get(lpfc_mbox_hdr_add_status,
  4990. &dealloc_rsrc->header.cfg_shdr.response));
  4991. rc = -EIO;
  4992. goto out_free_mbox;
  4993. }
  4994. /* Release kernel memory resources for the specific type. */
  4995. switch (type) {
  4996. case LPFC_RSC_TYPE_FCOE_VPI:
  4997. kfree(phba->vpi_bmask);
  4998. kfree(phba->vpi_ids);
  4999. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5000. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5001. &phba->lpfc_vpi_blk_list, list) {
  5002. list_del_init(&rsrc_blk->list);
  5003. kfree(rsrc_blk);
  5004. }
  5005. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5006. break;
  5007. case LPFC_RSC_TYPE_FCOE_XRI:
  5008. kfree(phba->sli4_hba.xri_bmask);
  5009. kfree(phba->sli4_hba.xri_ids);
  5010. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5011. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  5012. list_del_init(&rsrc_blk->list);
  5013. kfree(rsrc_blk);
  5014. }
  5015. break;
  5016. case LPFC_RSC_TYPE_FCOE_VFI:
  5017. kfree(phba->sli4_hba.vfi_bmask);
  5018. kfree(phba->sli4_hba.vfi_ids);
  5019. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5020. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5021. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  5022. list_del_init(&rsrc_blk->list);
  5023. kfree(rsrc_blk);
  5024. }
  5025. break;
  5026. case LPFC_RSC_TYPE_FCOE_RPI:
  5027. /* RPI bitmask and physical id array are cleaned up earlier. */
  5028. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5029. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  5030. list_del_init(&rsrc_blk->list);
  5031. kfree(rsrc_blk);
  5032. }
  5033. break;
  5034. default:
  5035. break;
  5036. }
  5037. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5038. out_free_mbox:
  5039. mempool_free(mbox, phba->mbox_mem_pool);
  5040. return rc;
  5041. }
  5042. /**
  5043. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  5044. * @phba: Pointer to HBA context object.
  5045. *
  5046. * This function allocates all SLI4 resource identifiers.
  5047. **/
  5048. int
  5049. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  5050. {
  5051. int i, rc, error = 0;
  5052. uint16_t count, base;
  5053. unsigned long longs;
  5054. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5055. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  5056. if (phba->sli4_hba.extents_in_use) {
  5057. /*
  5058. * The port supports resource extents. The XRI, VPI, VFI, RPI
  5059. * resource extent count must be read and allocated before
  5060. * provisioning the resource id arrays.
  5061. */
  5062. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5063. LPFC_IDX_RSRC_RDY) {
  5064. /*
  5065. * Extent-based resources are set - the driver could
  5066. * be in a port reset. Figure out if any corrective
  5067. * actions need to be taken.
  5068. */
  5069. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5070. LPFC_RSC_TYPE_FCOE_VFI);
  5071. if (rc != 0)
  5072. error++;
  5073. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5074. LPFC_RSC_TYPE_FCOE_VPI);
  5075. if (rc != 0)
  5076. error++;
  5077. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5078. LPFC_RSC_TYPE_FCOE_XRI);
  5079. if (rc != 0)
  5080. error++;
  5081. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5082. LPFC_RSC_TYPE_FCOE_RPI);
  5083. if (rc != 0)
  5084. error++;
  5085. /*
  5086. * It's possible that the number of resources
  5087. * provided to this port instance changed between
  5088. * resets. Detect this condition and reallocate
  5089. * resources. Otherwise, there is no action.
  5090. */
  5091. if (error) {
  5092. lpfc_printf_log(phba, KERN_INFO,
  5093. LOG_MBOX | LOG_INIT,
  5094. "2931 Detected extent resource "
  5095. "change. Reallocating all "
  5096. "extents.\n");
  5097. rc = lpfc_sli4_dealloc_extent(phba,
  5098. LPFC_RSC_TYPE_FCOE_VFI);
  5099. rc = lpfc_sli4_dealloc_extent(phba,
  5100. LPFC_RSC_TYPE_FCOE_VPI);
  5101. rc = lpfc_sli4_dealloc_extent(phba,
  5102. LPFC_RSC_TYPE_FCOE_XRI);
  5103. rc = lpfc_sli4_dealloc_extent(phba,
  5104. LPFC_RSC_TYPE_FCOE_RPI);
  5105. } else
  5106. return 0;
  5107. }
  5108. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5109. if (unlikely(rc))
  5110. goto err_exit;
  5111. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5112. if (unlikely(rc))
  5113. goto err_exit;
  5114. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5115. if (unlikely(rc))
  5116. goto err_exit;
  5117. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5118. if (unlikely(rc))
  5119. goto err_exit;
  5120. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5121. LPFC_IDX_RSRC_RDY);
  5122. return rc;
  5123. } else {
  5124. /*
  5125. * The port does not support resource extents. The XRI, VPI,
  5126. * VFI, RPI resource ids were determined from READ_CONFIG.
  5127. * Just allocate the bitmasks and provision the resource id
  5128. * arrays. If a port reset is active, the resources don't
  5129. * need any action - just exit.
  5130. */
  5131. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5132. LPFC_IDX_RSRC_RDY) {
  5133. lpfc_sli4_dealloc_resource_identifiers(phba);
  5134. lpfc_sli4_remove_rpis(phba);
  5135. }
  5136. /* RPIs. */
  5137. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5138. if (count <= 0) {
  5139. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5140. "3279 Invalid provisioning of "
  5141. "rpi:%d\n", count);
  5142. rc = -EINVAL;
  5143. goto err_exit;
  5144. }
  5145. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5146. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5147. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5148. sizeof(unsigned long),
  5149. GFP_KERNEL);
  5150. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5151. rc = -ENOMEM;
  5152. goto err_exit;
  5153. }
  5154. phba->sli4_hba.rpi_ids = kzalloc(count *
  5155. sizeof(uint16_t),
  5156. GFP_KERNEL);
  5157. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5158. rc = -ENOMEM;
  5159. goto free_rpi_bmask;
  5160. }
  5161. for (i = 0; i < count; i++)
  5162. phba->sli4_hba.rpi_ids[i] = base + i;
  5163. /* VPIs. */
  5164. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5165. if (count <= 0) {
  5166. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5167. "3280 Invalid provisioning of "
  5168. "vpi:%d\n", count);
  5169. rc = -EINVAL;
  5170. goto free_rpi_ids;
  5171. }
  5172. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5173. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5174. phba->vpi_bmask = kzalloc(longs *
  5175. sizeof(unsigned long),
  5176. GFP_KERNEL);
  5177. if (unlikely(!phba->vpi_bmask)) {
  5178. rc = -ENOMEM;
  5179. goto free_rpi_ids;
  5180. }
  5181. phba->vpi_ids = kzalloc(count *
  5182. sizeof(uint16_t),
  5183. GFP_KERNEL);
  5184. if (unlikely(!phba->vpi_ids)) {
  5185. rc = -ENOMEM;
  5186. goto free_vpi_bmask;
  5187. }
  5188. for (i = 0; i < count; i++)
  5189. phba->vpi_ids[i] = base + i;
  5190. /* XRIs. */
  5191. count = phba->sli4_hba.max_cfg_param.max_xri;
  5192. if (count <= 0) {
  5193. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5194. "3281 Invalid provisioning of "
  5195. "xri:%d\n", count);
  5196. rc = -EINVAL;
  5197. goto free_vpi_ids;
  5198. }
  5199. base = phba->sli4_hba.max_cfg_param.xri_base;
  5200. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5201. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5202. sizeof(unsigned long),
  5203. GFP_KERNEL);
  5204. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5205. rc = -ENOMEM;
  5206. goto free_vpi_ids;
  5207. }
  5208. phba->sli4_hba.max_cfg_param.xri_used = 0;
  5209. phba->sli4_hba.xri_ids = kzalloc(count *
  5210. sizeof(uint16_t),
  5211. GFP_KERNEL);
  5212. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5213. rc = -ENOMEM;
  5214. goto free_xri_bmask;
  5215. }
  5216. for (i = 0; i < count; i++)
  5217. phba->sli4_hba.xri_ids[i] = base + i;
  5218. /* VFIs. */
  5219. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5220. if (count <= 0) {
  5221. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5222. "3282 Invalid provisioning of "
  5223. "vfi:%d\n", count);
  5224. rc = -EINVAL;
  5225. goto free_xri_ids;
  5226. }
  5227. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5228. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5229. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5230. sizeof(unsigned long),
  5231. GFP_KERNEL);
  5232. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5233. rc = -ENOMEM;
  5234. goto free_xri_ids;
  5235. }
  5236. phba->sli4_hba.vfi_ids = kzalloc(count *
  5237. sizeof(uint16_t),
  5238. GFP_KERNEL);
  5239. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5240. rc = -ENOMEM;
  5241. goto free_vfi_bmask;
  5242. }
  5243. for (i = 0; i < count; i++)
  5244. phba->sli4_hba.vfi_ids[i] = base + i;
  5245. /*
  5246. * Mark all resources ready. An HBA reset doesn't need
  5247. * to reset the initialization.
  5248. */
  5249. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5250. LPFC_IDX_RSRC_RDY);
  5251. return 0;
  5252. }
  5253. free_vfi_bmask:
  5254. kfree(phba->sli4_hba.vfi_bmask);
  5255. free_xri_ids:
  5256. kfree(phba->sli4_hba.xri_ids);
  5257. free_xri_bmask:
  5258. kfree(phba->sli4_hba.xri_bmask);
  5259. free_vpi_ids:
  5260. kfree(phba->vpi_ids);
  5261. free_vpi_bmask:
  5262. kfree(phba->vpi_bmask);
  5263. free_rpi_ids:
  5264. kfree(phba->sli4_hba.rpi_ids);
  5265. free_rpi_bmask:
  5266. kfree(phba->sli4_hba.rpi_bmask);
  5267. err_exit:
  5268. return rc;
  5269. }
  5270. /**
  5271. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5272. * @phba: Pointer to HBA context object.
  5273. *
  5274. * This function allocates the number of elements for the specified
  5275. * resource type.
  5276. **/
  5277. int
  5278. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5279. {
  5280. if (phba->sli4_hba.extents_in_use) {
  5281. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5282. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5283. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5284. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5285. } else {
  5286. kfree(phba->vpi_bmask);
  5287. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5288. kfree(phba->vpi_ids);
  5289. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5290. kfree(phba->sli4_hba.xri_bmask);
  5291. kfree(phba->sli4_hba.xri_ids);
  5292. kfree(phba->sli4_hba.vfi_bmask);
  5293. kfree(phba->sli4_hba.vfi_ids);
  5294. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5295. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5296. }
  5297. return 0;
  5298. }
  5299. /**
  5300. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5301. * @phba: Pointer to HBA context object.
  5302. * @type: The resource extent type.
  5303. * @extnt_count: buffer to hold port extent count response
  5304. * @extnt_size: buffer to hold port extent size response.
  5305. *
  5306. * This function calls the port to read the host allocated extents
  5307. * for a particular type.
  5308. **/
  5309. int
  5310. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5311. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5312. {
  5313. bool emb;
  5314. int rc = 0;
  5315. uint16_t curr_blks = 0;
  5316. uint32_t req_len, emb_len;
  5317. uint32_t alloc_len, mbox_tmo;
  5318. struct list_head *blk_list_head;
  5319. struct lpfc_rsrc_blks *rsrc_blk;
  5320. LPFC_MBOXQ_t *mbox;
  5321. void *virtaddr = NULL;
  5322. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5323. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5324. union lpfc_sli4_cfg_shdr *shdr;
  5325. switch (type) {
  5326. case LPFC_RSC_TYPE_FCOE_VPI:
  5327. blk_list_head = &phba->lpfc_vpi_blk_list;
  5328. break;
  5329. case LPFC_RSC_TYPE_FCOE_XRI:
  5330. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5331. break;
  5332. case LPFC_RSC_TYPE_FCOE_VFI:
  5333. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5334. break;
  5335. case LPFC_RSC_TYPE_FCOE_RPI:
  5336. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5337. break;
  5338. default:
  5339. return -EIO;
  5340. }
  5341. /* Count the number of extents currently allocatd for this type. */
  5342. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5343. if (curr_blks == 0) {
  5344. /*
  5345. * The GET_ALLOCATED mailbox does not return the size,
  5346. * just the count. The size should be just the size
  5347. * stored in the current allocated block and all sizes
  5348. * for an extent type are the same so set the return
  5349. * value now.
  5350. */
  5351. *extnt_size = rsrc_blk->rsrc_size;
  5352. }
  5353. curr_blks++;
  5354. }
  5355. /* Calculate the total requested length of the dma memory. */
  5356. req_len = curr_blks * sizeof(uint16_t);
  5357. /*
  5358. * Calculate the size of an embedded mailbox. The uint32_t
  5359. * accounts for extents-specific word.
  5360. */
  5361. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5362. sizeof(uint32_t);
  5363. /*
  5364. * Presume the allocation and response will fit into an embedded
  5365. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5366. */
  5367. emb = LPFC_SLI4_MBX_EMBED;
  5368. req_len = emb_len;
  5369. if (req_len > emb_len) {
  5370. req_len = curr_blks * sizeof(uint16_t) +
  5371. sizeof(union lpfc_sli4_cfg_shdr) +
  5372. sizeof(uint32_t);
  5373. emb = LPFC_SLI4_MBX_NEMBED;
  5374. }
  5375. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5376. if (!mbox)
  5377. return -ENOMEM;
  5378. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5379. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5380. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5381. req_len, emb);
  5382. if (alloc_len < req_len) {
  5383. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5384. "2983 Allocated DMA memory size (x%x) is "
  5385. "less than the requested DMA memory "
  5386. "size (x%x)\n", alloc_len, req_len);
  5387. rc = -ENOMEM;
  5388. goto err_exit;
  5389. }
  5390. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5391. if (unlikely(rc)) {
  5392. rc = -EIO;
  5393. goto err_exit;
  5394. }
  5395. if (!phba->sli4_hba.intr_enable)
  5396. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5397. else {
  5398. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5399. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5400. }
  5401. if (unlikely(rc)) {
  5402. rc = -EIO;
  5403. goto err_exit;
  5404. }
  5405. /*
  5406. * Figure out where the response is located. Then get local pointers
  5407. * to the response data. The port does not guarantee to respond to
  5408. * all extents counts request so update the local variable with the
  5409. * allocated count from the port.
  5410. */
  5411. if (emb == LPFC_SLI4_MBX_EMBED) {
  5412. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5413. shdr = &rsrc_ext->header.cfg_shdr;
  5414. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5415. } else {
  5416. virtaddr = mbox->sge_array->addr[0];
  5417. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5418. shdr = &n_rsrc->cfg_shdr;
  5419. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5420. }
  5421. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5422. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5423. "2984 Failed to read allocated resources "
  5424. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5425. type,
  5426. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5427. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5428. rc = -EIO;
  5429. goto err_exit;
  5430. }
  5431. err_exit:
  5432. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5433. return rc;
  5434. }
  5435. /**
  5436. * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
  5437. * @phba: pointer to lpfc hba data structure.
  5438. *
  5439. * This routine walks the list of els buffers that have been allocated and
  5440. * repost them to the port by using SGL block post. This is needed after a
  5441. * pci_function_reset/warm_start or start. It attempts to construct blocks
  5442. * of els buffer sgls which contains contiguous xris and uses the non-embedded
  5443. * SGL block post mailbox commands to post them to the port. For single els
  5444. * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
  5445. * mailbox command for posting.
  5446. *
  5447. * Returns: 0 = success, non-zero failure.
  5448. **/
  5449. static int
  5450. lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
  5451. {
  5452. struct lpfc_sglq *sglq_entry = NULL;
  5453. struct lpfc_sglq *sglq_entry_next = NULL;
  5454. struct lpfc_sglq *sglq_entry_first = NULL;
  5455. int status, post_cnt = 0, num_posted = 0, block_cnt = 0;
  5456. int last_xritag = NO_XRI;
  5457. LIST_HEAD(prep_sgl_list);
  5458. LIST_HEAD(blck_sgl_list);
  5459. LIST_HEAD(allc_sgl_list);
  5460. LIST_HEAD(post_sgl_list);
  5461. LIST_HEAD(free_sgl_list);
  5462. spin_lock_irq(&phba->hbalock);
  5463. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
  5464. spin_unlock_irq(&phba->hbalock);
  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. spin_lock_irq(&phba->hbalock);
  5515. phba->sli4_hba.els_xri_cnt--;
  5516. spin_unlock_irq(&phba->hbalock);
  5517. }
  5518. }
  5519. }
  5520. /* continue until a nembed page worth of sgls */
  5521. if (post_cnt == 0)
  5522. continue;
  5523. /* post the els buffer list sgls as a block */
  5524. status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
  5525. post_cnt);
  5526. if (!status) {
  5527. /* success, put sgl list to posted sgl list */
  5528. list_splice_init(&blck_sgl_list, &post_sgl_list);
  5529. } else {
  5530. /* Failure, put sgl list to free sgl list */
  5531. sglq_entry_first = list_first_entry(&blck_sgl_list,
  5532. struct lpfc_sglq,
  5533. list);
  5534. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5535. "3160 Failed to post els sgl-list, "
  5536. "xritag:x%x-x%x\n",
  5537. sglq_entry_first->sli4_xritag,
  5538. (sglq_entry_first->sli4_xritag +
  5539. post_cnt - 1));
  5540. list_splice_init(&blck_sgl_list, &free_sgl_list);
  5541. spin_lock_irq(&phba->hbalock);
  5542. phba->sli4_hba.els_xri_cnt -= post_cnt;
  5543. spin_unlock_irq(&phba->hbalock);
  5544. }
  5545. /* don't reset xirtag due to hole in xri block */
  5546. if (block_cnt == 0)
  5547. last_xritag = NO_XRI;
  5548. /* reset els sgl post count for next round of posting */
  5549. post_cnt = 0;
  5550. }
  5551. /* free the els sgls failed to post */
  5552. lpfc_free_sgl_list(phba, &free_sgl_list);
  5553. /* push els sgls posted to the availble list */
  5554. if (!list_empty(&post_sgl_list)) {
  5555. spin_lock_irq(&phba->hbalock);
  5556. list_splice_init(&post_sgl_list,
  5557. &phba->sli4_hba.lpfc_sgl_list);
  5558. spin_unlock_irq(&phba->hbalock);
  5559. } else {
  5560. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5561. "3161 Failure to post els sgl to port.\n");
  5562. return -EIO;
  5563. }
  5564. return 0;
  5565. }
  5566. /**
  5567. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5568. * @phba: Pointer to HBA context object.
  5569. *
  5570. * This function is the main SLI4 device intialization PCI function. This
  5571. * function is called by the HBA intialization code, HBA reset code and
  5572. * HBA error attention handler code. Caller is not required to hold any
  5573. * locks.
  5574. **/
  5575. int
  5576. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5577. {
  5578. int rc;
  5579. LPFC_MBOXQ_t *mboxq;
  5580. struct lpfc_mqe *mqe;
  5581. uint8_t *vpd;
  5582. uint32_t vpd_size;
  5583. uint32_t ftr_rsp = 0;
  5584. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5585. struct lpfc_vport *vport = phba->pport;
  5586. struct lpfc_dmabuf *mp;
  5587. /* Perform a PCI function reset to start from clean */
  5588. rc = lpfc_pci_function_reset(phba);
  5589. if (unlikely(rc))
  5590. return -ENODEV;
  5591. /* Check the HBA Host Status Register for readyness */
  5592. rc = lpfc_sli4_post_status_check(phba);
  5593. if (unlikely(rc))
  5594. return -ENODEV;
  5595. else {
  5596. spin_lock_irq(&phba->hbalock);
  5597. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5598. spin_unlock_irq(&phba->hbalock);
  5599. }
  5600. /*
  5601. * Allocate a single mailbox container for initializing the
  5602. * port.
  5603. */
  5604. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5605. if (!mboxq)
  5606. return -ENOMEM;
  5607. /* Issue READ_REV to collect vpd and FW information. */
  5608. vpd_size = SLI4_PAGE_SIZE;
  5609. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5610. if (!vpd) {
  5611. rc = -ENOMEM;
  5612. goto out_free_mbox;
  5613. }
  5614. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5615. if (unlikely(rc)) {
  5616. kfree(vpd);
  5617. goto out_free_mbox;
  5618. }
  5619. mqe = &mboxq->u.mqe;
  5620. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5621. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  5622. phba->hba_flag |= HBA_FCOE_MODE;
  5623. else
  5624. phba->hba_flag &= ~HBA_FCOE_MODE;
  5625. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5626. LPFC_DCBX_CEE_MODE)
  5627. phba->hba_flag |= HBA_FIP_SUPPORT;
  5628. else
  5629. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5630. phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
  5631. if (phba->sli_rev != LPFC_SLI_REV4) {
  5632. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5633. "0376 READ_REV Error. SLI Level %d "
  5634. "FCoE enabled %d\n",
  5635. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5636. rc = -EIO;
  5637. kfree(vpd);
  5638. goto out_free_mbox;
  5639. }
  5640. /*
  5641. * Continue initialization with default values even if driver failed
  5642. * to read FCoE param config regions, only read parameters if the
  5643. * board is FCoE
  5644. */
  5645. if (phba->hba_flag & HBA_FCOE_MODE &&
  5646. lpfc_sli4_read_fcoe_params(phba))
  5647. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5648. "2570 Failed to read FCoE parameters\n");
  5649. /*
  5650. * Retrieve sli4 device physical port name, failure of doing it
  5651. * is considered as non-fatal.
  5652. */
  5653. rc = lpfc_sli4_retrieve_pport_name(phba);
  5654. if (!rc)
  5655. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5656. "3080 Successful retrieving SLI4 device "
  5657. "physical port name: %s.\n", phba->Port);
  5658. /*
  5659. * Evaluate the read rev and vpd data. Populate the driver
  5660. * state with the results. If this routine fails, the failure
  5661. * is not fatal as the driver will use generic values.
  5662. */
  5663. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5664. if (unlikely(!rc)) {
  5665. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5666. "0377 Error %d parsing vpd. "
  5667. "Using defaults.\n", rc);
  5668. rc = 0;
  5669. }
  5670. kfree(vpd);
  5671. /* Save information as VPD data */
  5672. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5673. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5674. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5675. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5676. &mqe->un.read_rev);
  5677. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5678. &mqe->un.read_rev);
  5679. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5680. &mqe->un.read_rev);
  5681. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5682. &mqe->un.read_rev);
  5683. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5684. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5685. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5686. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5687. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5688. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5689. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5690. "(%d):0380 READ_REV Status x%x "
  5691. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5692. mboxq->vport ? mboxq->vport->vpi : 0,
  5693. bf_get(lpfc_mqe_status, mqe),
  5694. phba->vpd.rev.opFwName,
  5695. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5696. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5697. /*
  5698. * Discover the port's supported feature set and match it against the
  5699. * hosts requests.
  5700. */
  5701. lpfc_request_features(phba, mboxq);
  5702. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5703. if (unlikely(rc)) {
  5704. rc = -EIO;
  5705. goto out_free_mbox;
  5706. }
  5707. /*
  5708. * The port must support FCP initiator mode as this is the
  5709. * only mode running in the host.
  5710. */
  5711. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5712. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5713. "0378 No support for fcpi mode.\n");
  5714. ftr_rsp++;
  5715. }
  5716. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5717. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5718. else
  5719. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5720. /*
  5721. * If the port cannot support the host's requested features
  5722. * then turn off the global config parameters to disable the
  5723. * feature in the driver. This is not a fatal error.
  5724. */
  5725. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5726. if (phba->cfg_enable_bg) {
  5727. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5728. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5729. else
  5730. ftr_rsp++;
  5731. }
  5732. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5733. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5734. ftr_rsp++;
  5735. if (ftr_rsp) {
  5736. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5737. "0379 Feature Mismatch Data: x%08x %08x "
  5738. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5739. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5740. phba->cfg_enable_npiv, phba->max_vpi);
  5741. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5742. phba->cfg_enable_bg = 0;
  5743. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5744. phba->cfg_enable_npiv = 0;
  5745. }
  5746. /* These SLI3 features are assumed in SLI4 */
  5747. spin_lock_irq(&phba->hbalock);
  5748. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5749. spin_unlock_irq(&phba->hbalock);
  5750. /*
  5751. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5752. * calls depends on these resources to complete port setup.
  5753. */
  5754. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5755. if (rc) {
  5756. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5757. "2920 Failed to alloc Resource IDs "
  5758. "rc = x%x\n", rc);
  5759. goto out_free_mbox;
  5760. }
  5761. /* Read the port's service parameters. */
  5762. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5763. if (rc) {
  5764. phba->link_state = LPFC_HBA_ERROR;
  5765. rc = -ENOMEM;
  5766. goto out_free_mbox;
  5767. }
  5768. mboxq->vport = vport;
  5769. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5770. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5771. if (rc == MBX_SUCCESS) {
  5772. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5773. rc = 0;
  5774. }
  5775. /*
  5776. * This memory was allocated by the lpfc_read_sparam routine. Release
  5777. * it to the mbuf pool.
  5778. */
  5779. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5780. kfree(mp);
  5781. mboxq->context1 = NULL;
  5782. if (unlikely(rc)) {
  5783. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5784. "0382 READ_SPARAM command failed "
  5785. "status %d, mbxStatus x%x\n",
  5786. rc, bf_get(lpfc_mqe_status, mqe));
  5787. phba->link_state = LPFC_HBA_ERROR;
  5788. rc = -EIO;
  5789. goto out_free_mbox;
  5790. }
  5791. lpfc_update_vport_wwn(vport);
  5792. /* Update the fc_host data structures with new wwn. */
  5793. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5794. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5795. /* update host els and scsi xri-sgl sizes and mappings */
  5796. rc = lpfc_sli4_xri_sgl_update(phba);
  5797. if (unlikely(rc)) {
  5798. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5799. "1400 Failed to update xri-sgl size and "
  5800. "mapping: %d\n", rc);
  5801. goto out_free_mbox;
  5802. }
  5803. /* register the els sgl pool to the port */
  5804. rc = lpfc_sli4_repost_els_sgl_list(phba);
  5805. if (unlikely(rc)) {
  5806. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5807. "0582 Error %d during els sgl post "
  5808. "operation\n", rc);
  5809. rc = -ENODEV;
  5810. goto out_free_mbox;
  5811. }
  5812. /* register the allocated scsi sgl pool to the port */
  5813. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  5814. if (unlikely(rc)) {
  5815. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5816. "0383 Error %d during scsi sgl post "
  5817. "operation\n", rc);
  5818. /* Some Scsi buffers were moved to the abort scsi list */
  5819. /* A pci function reset will repost them */
  5820. rc = -ENODEV;
  5821. goto out_free_mbox;
  5822. }
  5823. /* Post the rpi header region to the device. */
  5824. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  5825. if (unlikely(rc)) {
  5826. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5827. "0393 Error %d during rpi post operation\n",
  5828. rc);
  5829. rc = -ENODEV;
  5830. goto out_free_mbox;
  5831. }
  5832. lpfc_sli4_node_prep(phba);
  5833. /* Create all the SLI4 queues */
  5834. rc = lpfc_sli4_queue_create(phba);
  5835. if (rc) {
  5836. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5837. "3089 Failed to allocate queues\n");
  5838. rc = -ENODEV;
  5839. goto out_stop_timers;
  5840. }
  5841. /* Set up all the queues to the device */
  5842. rc = lpfc_sli4_queue_setup(phba);
  5843. if (unlikely(rc)) {
  5844. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5845. "0381 Error %d during queue setup.\n ", rc);
  5846. goto out_destroy_queue;
  5847. }
  5848. /* Arm the CQs and then EQs on device */
  5849. lpfc_sli4_arm_cqeq_intr(phba);
  5850. /* Indicate device interrupt mode */
  5851. phba->sli4_hba.intr_enable = 1;
  5852. /* Allow asynchronous mailbox command to go through */
  5853. spin_lock_irq(&phba->hbalock);
  5854. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5855. spin_unlock_irq(&phba->hbalock);
  5856. /* Post receive buffers to the device */
  5857. lpfc_sli4_rb_setup(phba);
  5858. /* Reset HBA FCF states after HBA reset */
  5859. phba->fcf.fcf_flag = 0;
  5860. phba->fcf.current_rec.flag = 0;
  5861. /* Start the ELS watchdog timer */
  5862. mod_timer(&vport->els_tmofunc,
  5863. jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
  5864. /* Start heart beat timer */
  5865. mod_timer(&phba->hb_tmofunc,
  5866. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  5867. phba->hb_outstanding = 0;
  5868. phba->last_completion_time = jiffies;
  5869. /* Start error attention (ERATT) polling timer */
  5870. mod_timer(&phba->eratt_poll,
  5871. jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
  5872. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  5873. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  5874. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  5875. if (!rc) {
  5876. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5877. "2829 This device supports "
  5878. "Advanced Error Reporting (AER)\n");
  5879. spin_lock_irq(&phba->hbalock);
  5880. phba->hba_flag |= HBA_AER_ENABLED;
  5881. spin_unlock_irq(&phba->hbalock);
  5882. } else {
  5883. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5884. "2830 This device does not support "
  5885. "Advanced Error Reporting (AER)\n");
  5886. phba->cfg_aer_support = 0;
  5887. }
  5888. rc = 0;
  5889. }
  5890. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  5891. /*
  5892. * The FC Port needs to register FCFI (index 0)
  5893. */
  5894. lpfc_reg_fcfi(phba, mboxq);
  5895. mboxq->vport = phba->pport;
  5896. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5897. if (rc != MBX_SUCCESS)
  5898. goto out_unset_queue;
  5899. rc = 0;
  5900. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  5901. &mboxq->u.mqe.un.reg_fcfi);
  5902. /* Check if the port is configured to be disabled */
  5903. lpfc_sli_read_link_ste(phba);
  5904. }
  5905. /*
  5906. * The port is ready, set the host's link state to LINK_DOWN
  5907. * in preparation for link interrupts.
  5908. */
  5909. spin_lock_irq(&phba->hbalock);
  5910. phba->link_state = LPFC_LINK_DOWN;
  5911. spin_unlock_irq(&phba->hbalock);
  5912. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  5913. (phba->hba_flag & LINK_DISABLED)) {
  5914. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5915. "3103 Adapter Link is disabled.\n");
  5916. lpfc_down_link(phba, mboxq);
  5917. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5918. if (rc != MBX_SUCCESS) {
  5919. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5920. "3104 Adapter failed to issue "
  5921. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  5922. goto out_unset_queue;
  5923. }
  5924. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  5925. /* don't perform init_link on SLI4 FC port loopback test */
  5926. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  5927. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  5928. if (rc)
  5929. goto out_unset_queue;
  5930. }
  5931. }
  5932. mempool_free(mboxq, phba->mbox_mem_pool);
  5933. return rc;
  5934. out_unset_queue:
  5935. /* Unset all the queues set up in this routine when error out */
  5936. lpfc_sli4_queue_unset(phba);
  5937. out_destroy_queue:
  5938. lpfc_sli4_queue_destroy(phba);
  5939. out_stop_timers:
  5940. lpfc_stop_hba_timers(phba);
  5941. out_free_mbox:
  5942. mempool_free(mboxq, phba->mbox_mem_pool);
  5943. return rc;
  5944. }
  5945. /**
  5946. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  5947. * @ptr: context object - pointer to hba structure.
  5948. *
  5949. * This is the callback function for mailbox timer. The mailbox
  5950. * timer is armed when a new mailbox command is issued and the timer
  5951. * is deleted when the mailbox complete. The function is called by
  5952. * the kernel timer code when a mailbox does not complete within
  5953. * expected time. This function wakes up the worker thread to
  5954. * process the mailbox timeout and returns. All the processing is
  5955. * done by the worker thread function lpfc_mbox_timeout_handler.
  5956. **/
  5957. void
  5958. lpfc_mbox_timeout(unsigned long ptr)
  5959. {
  5960. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  5961. unsigned long iflag;
  5962. uint32_t tmo_posted;
  5963. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  5964. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  5965. if (!tmo_posted)
  5966. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  5967. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  5968. if (!tmo_posted)
  5969. lpfc_worker_wake_up(phba);
  5970. return;
  5971. }
  5972. /**
  5973. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  5974. * @phba: Pointer to HBA context object.
  5975. *
  5976. * This function is called from worker thread when a mailbox command times out.
  5977. * The caller is not required to hold any locks. This function will reset the
  5978. * HBA and recover all the pending commands.
  5979. **/
  5980. void
  5981. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  5982. {
  5983. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  5984. MAILBOX_t *mb = &pmbox->u.mb;
  5985. struct lpfc_sli *psli = &phba->sli;
  5986. struct lpfc_sli_ring *pring;
  5987. /* Check the pmbox pointer first. There is a race condition
  5988. * between the mbox timeout handler getting executed in the
  5989. * worklist and the mailbox actually completing. When this
  5990. * race condition occurs, the mbox_active will be NULL.
  5991. */
  5992. spin_lock_irq(&phba->hbalock);
  5993. if (pmbox == NULL) {
  5994. lpfc_printf_log(phba, KERN_WARNING,
  5995. LOG_MBOX | LOG_SLI,
  5996. "0353 Active Mailbox cleared - mailbox timeout "
  5997. "exiting\n");
  5998. spin_unlock_irq(&phba->hbalock);
  5999. return;
  6000. }
  6001. /* Mbox cmd <mbxCommand> timeout */
  6002. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6003. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  6004. mb->mbxCommand,
  6005. phba->pport->port_state,
  6006. phba->sli.sli_flag,
  6007. phba->sli.mbox_active);
  6008. spin_unlock_irq(&phba->hbalock);
  6009. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  6010. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  6011. * it to fail all outstanding SCSI IO.
  6012. */
  6013. spin_lock_irq(&phba->pport->work_port_lock);
  6014. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6015. spin_unlock_irq(&phba->pport->work_port_lock);
  6016. spin_lock_irq(&phba->hbalock);
  6017. phba->link_state = LPFC_LINK_UNKNOWN;
  6018. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  6019. spin_unlock_irq(&phba->hbalock);
  6020. pring = &psli->ring[psli->fcp_ring];
  6021. lpfc_sli_abort_iocb_ring(phba, pring);
  6022. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6023. "0345 Resetting board due to mailbox timeout\n");
  6024. /* Reset the HBA device */
  6025. lpfc_reset_hba(phba);
  6026. }
  6027. /**
  6028. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  6029. * @phba: Pointer to HBA context object.
  6030. * @pmbox: Pointer to mailbox object.
  6031. * @flag: Flag indicating how the mailbox need to be processed.
  6032. *
  6033. * This function is called by discovery code and HBA management code
  6034. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  6035. * function gets the hbalock to protect the data structures.
  6036. * The mailbox command can be submitted in polling mode, in which case
  6037. * this function will wait in a polling loop for the completion of the
  6038. * mailbox.
  6039. * If the mailbox is submitted in no_wait mode (not polling) the
  6040. * function will submit the command and returns immediately without waiting
  6041. * for the mailbox completion. The no_wait is supported only when HBA
  6042. * is in SLI2/SLI3 mode - interrupts are enabled.
  6043. * The SLI interface allows only one mailbox pending at a time. If the
  6044. * mailbox is issued in polling mode and there is already a mailbox
  6045. * pending, then the function will return an error. If the mailbox is issued
  6046. * in NO_WAIT mode and there is a mailbox pending already, the function
  6047. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  6048. * The sli layer owns the mailbox object until the completion of mailbox
  6049. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  6050. * return codes the caller owns the mailbox command after the return of
  6051. * the function.
  6052. **/
  6053. static int
  6054. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  6055. uint32_t flag)
  6056. {
  6057. MAILBOX_t *mbx;
  6058. struct lpfc_sli *psli = &phba->sli;
  6059. uint32_t status, evtctr;
  6060. uint32_t ha_copy, hc_copy;
  6061. int i;
  6062. unsigned long timeout;
  6063. unsigned long drvr_flag = 0;
  6064. uint32_t word0, ldata;
  6065. void __iomem *to_slim;
  6066. int processing_queue = 0;
  6067. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6068. if (!pmbox) {
  6069. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6070. /* processing mbox queue from intr_handler */
  6071. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6072. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6073. return MBX_SUCCESS;
  6074. }
  6075. processing_queue = 1;
  6076. pmbox = lpfc_mbox_get(phba);
  6077. if (!pmbox) {
  6078. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6079. return MBX_SUCCESS;
  6080. }
  6081. }
  6082. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  6083. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  6084. if(!pmbox->vport) {
  6085. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6086. lpfc_printf_log(phba, KERN_ERR,
  6087. LOG_MBOX | LOG_VPORT,
  6088. "1806 Mbox x%x failed. No vport\n",
  6089. pmbox->u.mb.mbxCommand);
  6090. dump_stack();
  6091. goto out_not_finished;
  6092. }
  6093. }
  6094. /* If the PCI channel is in offline state, do not post mbox. */
  6095. if (unlikely(pci_channel_offline(phba->pcidev))) {
  6096. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6097. goto out_not_finished;
  6098. }
  6099. /* If HBA has a deferred error attention, fail the iocb. */
  6100. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  6101. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6102. goto out_not_finished;
  6103. }
  6104. psli = &phba->sli;
  6105. mbx = &pmbox->u.mb;
  6106. status = MBX_SUCCESS;
  6107. if (phba->link_state == LPFC_HBA_ERROR) {
  6108. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6109. /* Mbox command <mbxCommand> cannot issue */
  6110. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6111. "(%d):0311 Mailbox command x%x cannot "
  6112. "issue Data: x%x x%x\n",
  6113. pmbox->vport ? pmbox->vport->vpi : 0,
  6114. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6115. goto out_not_finished;
  6116. }
  6117. if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  6118. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  6119. !(hc_copy & HC_MBINT_ENA)) {
  6120. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6121. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6122. "(%d):2528 Mailbox command x%x cannot "
  6123. "issue Data: x%x x%x\n",
  6124. pmbox->vport ? pmbox->vport->vpi : 0,
  6125. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6126. goto out_not_finished;
  6127. }
  6128. }
  6129. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6130. /* Polling for a mbox command when another one is already active
  6131. * is not allowed in SLI. Also, the driver must have established
  6132. * SLI2 mode to queue and process multiple mbox commands.
  6133. */
  6134. if (flag & MBX_POLL) {
  6135. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6136. /* Mbox command <mbxCommand> cannot issue */
  6137. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6138. "(%d):2529 Mailbox command x%x "
  6139. "cannot issue Data: x%x x%x\n",
  6140. pmbox->vport ? pmbox->vport->vpi : 0,
  6141. pmbox->u.mb.mbxCommand,
  6142. psli->sli_flag, flag);
  6143. goto out_not_finished;
  6144. }
  6145. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6146. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6147. /* Mbox command <mbxCommand> cannot issue */
  6148. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6149. "(%d):2530 Mailbox command x%x "
  6150. "cannot issue Data: x%x x%x\n",
  6151. pmbox->vport ? pmbox->vport->vpi : 0,
  6152. pmbox->u.mb.mbxCommand,
  6153. psli->sli_flag, flag);
  6154. goto out_not_finished;
  6155. }
  6156. /* Another mailbox command is still being processed, queue this
  6157. * command to be processed later.
  6158. */
  6159. lpfc_mbox_put(phba, pmbox);
  6160. /* Mbox cmd issue - BUSY */
  6161. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6162. "(%d):0308 Mbox cmd issue - BUSY Data: "
  6163. "x%x x%x x%x x%x\n",
  6164. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  6165. mbx->mbxCommand, phba->pport->port_state,
  6166. psli->sli_flag, flag);
  6167. psli->slistat.mbox_busy++;
  6168. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6169. if (pmbox->vport) {
  6170. lpfc_debugfs_disc_trc(pmbox->vport,
  6171. LPFC_DISC_TRC_MBOX_VPORT,
  6172. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  6173. (uint32_t)mbx->mbxCommand,
  6174. mbx->un.varWords[0], mbx->un.varWords[1]);
  6175. }
  6176. else {
  6177. lpfc_debugfs_disc_trc(phba->pport,
  6178. LPFC_DISC_TRC_MBOX,
  6179. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  6180. (uint32_t)mbx->mbxCommand,
  6181. mbx->un.varWords[0], mbx->un.varWords[1]);
  6182. }
  6183. return MBX_BUSY;
  6184. }
  6185. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6186. /* If we are not polling, we MUST be in SLI2 mode */
  6187. if (flag != MBX_POLL) {
  6188. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  6189. (mbx->mbxCommand != MBX_KILL_BOARD)) {
  6190. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6191. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6192. /* Mbox command <mbxCommand> cannot issue */
  6193. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6194. "(%d):2531 Mailbox command x%x "
  6195. "cannot issue Data: x%x x%x\n",
  6196. pmbox->vport ? pmbox->vport->vpi : 0,
  6197. pmbox->u.mb.mbxCommand,
  6198. psli->sli_flag, flag);
  6199. goto out_not_finished;
  6200. }
  6201. /* timeout active mbox command */
  6202. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6203. 1000);
  6204. mod_timer(&psli->mbox_tmo, jiffies + timeout);
  6205. }
  6206. /* Mailbox cmd <cmd> issue */
  6207. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6208. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  6209. "x%x\n",
  6210. pmbox->vport ? pmbox->vport->vpi : 0,
  6211. mbx->mbxCommand, phba->pport->port_state,
  6212. psli->sli_flag, flag);
  6213. if (mbx->mbxCommand != MBX_HEARTBEAT) {
  6214. if (pmbox->vport) {
  6215. lpfc_debugfs_disc_trc(pmbox->vport,
  6216. LPFC_DISC_TRC_MBOX_VPORT,
  6217. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6218. (uint32_t)mbx->mbxCommand,
  6219. mbx->un.varWords[0], mbx->un.varWords[1]);
  6220. }
  6221. else {
  6222. lpfc_debugfs_disc_trc(phba->pport,
  6223. LPFC_DISC_TRC_MBOX,
  6224. "MBOX Send: cmd:x%x mb:x%x x%x",
  6225. (uint32_t)mbx->mbxCommand,
  6226. mbx->un.varWords[0], mbx->un.varWords[1]);
  6227. }
  6228. }
  6229. psli->slistat.mbox_cmd++;
  6230. evtctr = psli->slistat.mbox_event;
  6231. /* next set own bit for the adapter and copy over command word */
  6232. mbx->mbxOwner = OWN_CHIP;
  6233. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6234. /* Populate mbox extension offset word. */
  6235. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  6236. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6237. = (uint8_t *)phba->mbox_ext
  6238. - (uint8_t *)phba->mbox;
  6239. }
  6240. /* Copy the mailbox extension data */
  6241. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6242. lpfc_sli_pcimem_bcopy(pmbox->context2,
  6243. (uint8_t *)phba->mbox_ext,
  6244. pmbox->in_ext_byte_len);
  6245. }
  6246. /* Copy command data to host SLIM area */
  6247. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6248. } else {
  6249. /* Populate mbox extension offset word. */
  6250. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  6251. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6252. = MAILBOX_HBA_EXT_OFFSET;
  6253. /* Copy the mailbox extension data */
  6254. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6255. lpfc_memcpy_to_slim(phba->MBslimaddr +
  6256. MAILBOX_HBA_EXT_OFFSET,
  6257. pmbox->context2, pmbox->in_ext_byte_len);
  6258. }
  6259. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6260. /* copy command data into host mbox for cmpl */
  6261. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6262. }
  6263. /* First copy mbox command data to HBA SLIM, skip past first
  6264. word */
  6265. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6266. lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
  6267. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6268. /* Next copy over first word, with mbxOwner set */
  6269. ldata = *((uint32_t *)mbx);
  6270. to_slim = phba->MBslimaddr;
  6271. writel(ldata, to_slim);
  6272. readl(to_slim); /* flush */
  6273. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6274. /* switch over to host mailbox */
  6275. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6276. }
  6277. }
  6278. wmb();
  6279. switch (flag) {
  6280. case MBX_NOWAIT:
  6281. /* Set up reference to mailbox command */
  6282. psli->mbox_active = pmbox;
  6283. /* Interrupt board to do it */
  6284. writel(CA_MBATT, phba->CAregaddr);
  6285. readl(phba->CAregaddr); /* flush */
  6286. /* Don't wait for it to finish, just return */
  6287. break;
  6288. case MBX_POLL:
  6289. /* Set up null reference to mailbox command */
  6290. psli->mbox_active = NULL;
  6291. /* Interrupt board to do it */
  6292. writel(CA_MBATT, phba->CAregaddr);
  6293. readl(phba->CAregaddr); /* flush */
  6294. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6295. /* First read mbox status word */
  6296. word0 = *((uint32_t *)phba->mbox);
  6297. word0 = le32_to_cpu(word0);
  6298. } else {
  6299. /* First read mbox status word */
  6300. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6301. spin_unlock_irqrestore(&phba->hbalock,
  6302. drvr_flag);
  6303. goto out_not_finished;
  6304. }
  6305. }
  6306. /* Read the HBA Host Attention Register */
  6307. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6308. spin_unlock_irqrestore(&phba->hbalock,
  6309. drvr_flag);
  6310. goto out_not_finished;
  6311. }
  6312. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6313. 1000) + jiffies;
  6314. i = 0;
  6315. /* Wait for command to complete */
  6316. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6317. (!(ha_copy & HA_MBATT) &&
  6318. (phba->link_state > LPFC_WARM_START))) {
  6319. if (time_after(jiffies, timeout)) {
  6320. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6321. spin_unlock_irqrestore(&phba->hbalock,
  6322. drvr_flag);
  6323. goto out_not_finished;
  6324. }
  6325. /* Check if we took a mbox interrupt while we were
  6326. polling */
  6327. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6328. && (evtctr != psli->slistat.mbox_event))
  6329. break;
  6330. if (i++ > 10) {
  6331. spin_unlock_irqrestore(&phba->hbalock,
  6332. drvr_flag);
  6333. msleep(1);
  6334. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6335. }
  6336. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6337. /* First copy command data */
  6338. word0 = *((uint32_t *)phba->mbox);
  6339. word0 = le32_to_cpu(word0);
  6340. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6341. MAILBOX_t *slimmb;
  6342. uint32_t slimword0;
  6343. /* Check real SLIM for any errors */
  6344. slimword0 = readl(phba->MBslimaddr);
  6345. slimmb = (MAILBOX_t *) & slimword0;
  6346. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6347. && slimmb->mbxStatus) {
  6348. psli->sli_flag &=
  6349. ~LPFC_SLI_ACTIVE;
  6350. word0 = slimword0;
  6351. }
  6352. }
  6353. } else {
  6354. /* First copy command data */
  6355. word0 = readl(phba->MBslimaddr);
  6356. }
  6357. /* Read the HBA Host Attention Register */
  6358. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6359. spin_unlock_irqrestore(&phba->hbalock,
  6360. drvr_flag);
  6361. goto out_not_finished;
  6362. }
  6363. }
  6364. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6365. /* copy results back to user */
  6366. lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE);
  6367. /* Copy the mailbox extension data */
  6368. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6369. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6370. pmbox->context2,
  6371. pmbox->out_ext_byte_len);
  6372. }
  6373. } else {
  6374. /* First copy command data */
  6375. lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
  6376. MAILBOX_CMD_SIZE);
  6377. /* Copy the mailbox extension data */
  6378. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6379. lpfc_memcpy_from_slim(pmbox->context2,
  6380. phba->MBslimaddr +
  6381. MAILBOX_HBA_EXT_OFFSET,
  6382. pmbox->out_ext_byte_len);
  6383. }
  6384. }
  6385. writel(HA_MBATT, phba->HAregaddr);
  6386. readl(phba->HAregaddr); /* flush */
  6387. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6388. status = mbx->mbxStatus;
  6389. }
  6390. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6391. return status;
  6392. out_not_finished:
  6393. if (processing_queue) {
  6394. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6395. lpfc_mbox_cmpl_put(phba, pmbox);
  6396. }
  6397. return MBX_NOT_FINISHED;
  6398. }
  6399. /**
  6400. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6401. * @phba: Pointer to HBA context object.
  6402. *
  6403. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6404. * the driver internal pending mailbox queue. It will then try to wait out the
  6405. * possible outstanding mailbox command before return.
  6406. *
  6407. * Returns:
  6408. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6409. * the outstanding mailbox command timed out.
  6410. **/
  6411. static int
  6412. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6413. {
  6414. struct lpfc_sli *psli = &phba->sli;
  6415. int rc = 0;
  6416. unsigned long timeout = 0;
  6417. /* Mark the asynchronous mailbox command posting as blocked */
  6418. spin_lock_irq(&phba->hbalock);
  6419. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6420. /* Determine how long we might wait for the active mailbox
  6421. * command to be gracefully completed by firmware.
  6422. */
  6423. if (phba->sli.mbox_active)
  6424. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6425. phba->sli.mbox_active) *
  6426. 1000) + jiffies;
  6427. spin_unlock_irq(&phba->hbalock);
  6428. /* Wait for the outstnading mailbox command to complete */
  6429. while (phba->sli.mbox_active) {
  6430. /* Check active mailbox complete status every 2ms */
  6431. msleep(2);
  6432. if (time_after(jiffies, timeout)) {
  6433. /* Timeout, marked the outstanding cmd not complete */
  6434. rc = 1;
  6435. break;
  6436. }
  6437. }
  6438. /* Can not cleanly block async mailbox command, fails it */
  6439. if (rc) {
  6440. spin_lock_irq(&phba->hbalock);
  6441. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6442. spin_unlock_irq(&phba->hbalock);
  6443. }
  6444. return rc;
  6445. }
  6446. /**
  6447. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6448. * @phba: Pointer to HBA context object.
  6449. *
  6450. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6451. * commands from the driver internal pending mailbox queue. It makes sure
  6452. * that there is no outstanding mailbox command before resuming posting
  6453. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6454. * mailbox command, it will try to wait it out before resuming asynchronous
  6455. * mailbox command posting.
  6456. **/
  6457. static void
  6458. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6459. {
  6460. struct lpfc_sli *psli = &phba->sli;
  6461. spin_lock_irq(&phba->hbalock);
  6462. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6463. /* Asynchronous mailbox posting is not blocked, do nothing */
  6464. spin_unlock_irq(&phba->hbalock);
  6465. return;
  6466. }
  6467. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6468. * successful or timeout, after timing-out the outstanding mailbox
  6469. * command shall always be removed, so just unblock posting async
  6470. * mailbox command and resume
  6471. */
  6472. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6473. spin_unlock_irq(&phba->hbalock);
  6474. /* wake up worker thread to post asynchronlous mailbox command */
  6475. lpfc_worker_wake_up(phba);
  6476. }
  6477. /**
  6478. * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
  6479. * @phba: Pointer to HBA context object.
  6480. * @mboxq: Pointer to mailbox object.
  6481. *
  6482. * The function waits for the bootstrap mailbox register ready bit from
  6483. * port for twice the regular mailbox command timeout value.
  6484. *
  6485. * 0 - no timeout on waiting for bootstrap mailbox register ready.
  6486. * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
  6487. **/
  6488. static int
  6489. lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6490. {
  6491. uint32_t db_ready;
  6492. unsigned long timeout;
  6493. struct lpfc_register bmbx_reg;
  6494. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6495. * 1000) + jiffies;
  6496. do {
  6497. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6498. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6499. if (!db_ready)
  6500. msleep(2);
  6501. if (time_after(jiffies, timeout))
  6502. return MBXERR_ERROR;
  6503. } while (!db_ready);
  6504. return 0;
  6505. }
  6506. /**
  6507. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6508. * @phba: Pointer to HBA context object.
  6509. * @mboxq: Pointer to mailbox object.
  6510. *
  6511. * The function posts a mailbox to the port. The mailbox is expected
  6512. * to be comletely filled in and ready for the port to operate on it.
  6513. * This routine executes a synchronous completion operation on the
  6514. * mailbox by polling for its completion.
  6515. *
  6516. * The caller must not be holding any locks when calling this routine.
  6517. *
  6518. * Returns:
  6519. * MBX_SUCCESS - mailbox posted successfully
  6520. * Any of the MBX error values.
  6521. **/
  6522. static int
  6523. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6524. {
  6525. int rc = MBX_SUCCESS;
  6526. unsigned long iflag;
  6527. uint32_t mcqe_status;
  6528. uint32_t mbx_cmnd;
  6529. struct lpfc_sli *psli = &phba->sli;
  6530. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6531. struct lpfc_bmbx_create *mbox_rgn;
  6532. struct dma_address *dma_address;
  6533. /*
  6534. * Only one mailbox can be active to the bootstrap mailbox region
  6535. * at a time and there is no queueing provided.
  6536. */
  6537. spin_lock_irqsave(&phba->hbalock, iflag);
  6538. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6539. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6540. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6541. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6542. "cannot issue Data: x%x x%x\n",
  6543. mboxq->vport ? mboxq->vport->vpi : 0,
  6544. mboxq->u.mb.mbxCommand,
  6545. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6546. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6547. psli->sli_flag, MBX_POLL);
  6548. return MBXERR_ERROR;
  6549. }
  6550. /* The server grabs the token and owns it until release */
  6551. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6552. phba->sli.mbox_active = mboxq;
  6553. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6554. /* wait for bootstrap mbox register for readyness */
  6555. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6556. if (rc)
  6557. goto exit;
  6558. /*
  6559. * Initialize the bootstrap memory region to avoid stale data areas
  6560. * in the mailbox post. Then copy the caller's mailbox contents to
  6561. * the bmbx mailbox region.
  6562. */
  6563. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6564. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6565. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6566. sizeof(struct lpfc_mqe));
  6567. /* Post the high mailbox dma address to the port and wait for ready. */
  6568. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6569. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6570. /* wait for bootstrap mbox register for hi-address write done */
  6571. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6572. if (rc)
  6573. goto exit;
  6574. /* Post the low mailbox dma address to the port. */
  6575. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6576. /* wait for bootstrap mbox register for low address write done */
  6577. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6578. if (rc)
  6579. goto exit;
  6580. /*
  6581. * Read the CQ to ensure the mailbox has completed.
  6582. * If so, update the mailbox status so that the upper layers
  6583. * can complete the request normally.
  6584. */
  6585. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6586. sizeof(struct lpfc_mqe));
  6587. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6588. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6589. sizeof(struct lpfc_mcqe));
  6590. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6591. /*
  6592. * When the CQE status indicates a failure and the mailbox status
  6593. * indicates success then copy the CQE status into the mailbox status
  6594. * (and prefix it with x4000).
  6595. */
  6596. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6597. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6598. bf_set(lpfc_mqe_status, mb,
  6599. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6600. rc = MBXERR_ERROR;
  6601. } else
  6602. lpfc_sli4_swap_str(phba, mboxq);
  6603. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6604. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6605. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6606. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6607. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6608. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6609. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6610. bf_get(lpfc_mqe_status, mb),
  6611. mb->un.mb_words[0], mb->un.mb_words[1],
  6612. mb->un.mb_words[2], mb->un.mb_words[3],
  6613. mb->un.mb_words[4], mb->un.mb_words[5],
  6614. mb->un.mb_words[6], mb->un.mb_words[7],
  6615. mb->un.mb_words[8], mb->un.mb_words[9],
  6616. mb->un.mb_words[10], mb->un.mb_words[11],
  6617. mb->un.mb_words[12], mboxq->mcqe.word0,
  6618. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6619. mboxq->mcqe.trailer);
  6620. exit:
  6621. /* We are holding the token, no needed for lock when release */
  6622. spin_lock_irqsave(&phba->hbalock, iflag);
  6623. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6624. phba->sli.mbox_active = NULL;
  6625. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6626. return rc;
  6627. }
  6628. /**
  6629. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6630. * @phba: Pointer to HBA context object.
  6631. * @pmbox: Pointer to mailbox object.
  6632. * @flag: Flag indicating how the mailbox need to be processed.
  6633. *
  6634. * This function is called by discovery code and HBA management code to submit
  6635. * a mailbox command to firmware with SLI-4 interface spec.
  6636. *
  6637. * Return codes the caller owns the mailbox command after the return of the
  6638. * function.
  6639. **/
  6640. static int
  6641. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6642. uint32_t flag)
  6643. {
  6644. struct lpfc_sli *psli = &phba->sli;
  6645. unsigned long iflags;
  6646. int rc;
  6647. /* dump from issue mailbox command if setup */
  6648. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6649. rc = lpfc_mbox_dev_check(phba);
  6650. if (unlikely(rc)) {
  6651. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6652. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6653. "cannot issue Data: x%x x%x\n",
  6654. mboxq->vport ? mboxq->vport->vpi : 0,
  6655. mboxq->u.mb.mbxCommand,
  6656. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6657. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6658. psli->sli_flag, flag);
  6659. goto out_not_finished;
  6660. }
  6661. /* Detect polling mode and jump to a handler */
  6662. if (!phba->sli4_hba.intr_enable) {
  6663. if (flag == MBX_POLL)
  6664. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6665. else
  6666. rc = -EIO;
  6667. if (rc != MBX_SUCCESS)
  6668. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6669. "(%d):2541 Mailbox command x%x "
  6670. "(x%x/x%x) failure: "
  6671. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6672. "Data: x%x x%x\n,",
  6673. mboxq->vport ? mboxq->vport->vpi : 0,
  6674. mboxq->u.mb.mbxCommand,
  6675. lpfc_sli_config_mbox_subsys_get(phba,
  6676. mboxq),
  6677. lpfc_sli_config_mbox_opcode_get(phba,
  6678. mboxq),
  6679. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6680. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6681. bf_get(lpfc_mcqe_ext_status,
  6682. &mboxq->mcqe),
  6683. psli->sli_flag, flag);
  6684. return rc;
  6685. } else if (flag == MBX_POLL) {
  6686. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6687. "(%d):2542 Try to issue mailbox command "
  6688. "x%x (x%x/x%x) synchronously ahead of async"
  6689. "mailbox command queue: x%x x%x\n",
  6690. mboxq->vport ? mboxq->vport->vpi : 0,
  6691. mboxq->u.mb.mbxCommand,
  6692. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6693. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6694. psli->sli_flag, flag);
  6695. /* Try to block the asynchronous mailbox posting */
  6696. rc = lpfc_sli4_async_mbox_block(phba);
  6697. if (!rc) {
  6698. /* Successfully blocked, now issue sync mbox cmd */
  6699. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6700. if (rc != MBX_SUCCESS)
  6701. lpfc_printf_log(phba, KERN_WARNING,
  6702. LOG_MBOX | LOG_SLI,
  6703. "(%d):2597 Sync Mailbox command "
  6704. "x%x (x%x/x%x) failure: "
  6705. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6706. "Data: x%x x%x\n,",
  6707. mboxq->vport ? mboxq->vport->vpi : 0,
  6708. mboxq->u.mb.mbxCommand,
  6709. lpfc_sli_config_mbox_subsys_get(phba,
  6710. mboxq),
  6711. lpfc_sli_config_mbox_opcode_get(phba,
  6712. mboxq),
  6713. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6714. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6715. bf_get(lpfc_mcqe_ext_status,
  6716. &mboxq->mcqe),
  6717. psli->sli_flag, flag);
  6718. /* Unblock the async mailbox posting afterward */
  6719. lpfc_sli4_async_mbox_unblock(phba);
  6720. }
  6721. return rc;
  6722. }
  6723. /* Now, interrupt mode asynchrous mailbox command */
  6724. rc = lpfc_mbox_cmd_check(phba, mboxq);
  6725. if (rc) {
  6726. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6727. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  6728. "cannot issue Data: x%x x%x\n",
  6729. mboxq->vport ? mboxq->vport->vpi : 0,
  6730. mboxq->u.mb.mbxCommand,
  6731. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6732. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6733. psli->sli_flag, flag);
  6734. goto out_not_finished;
  6735. }
  6736. /* Put the mailbox command to the driver internal FIFO */
  6737. psli->slistat.mbox_busy++;
  6738. spin_lock_irqsave(&phba->hbalock, iflags);
  6739. lpfc_mbox_put(phba, mboxq);
  6740. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6741. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6742. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  6743. "x%x (x%x/x%x) x%x x%x x%x\n",
  6744. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  6745. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  6746. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6747. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6748. phba->pport->port_state,
  6749. psli->sli_flag, MBX_NOWAIT);
  6750. /* Wake up worker thread to transport mailbox command from head */
  6751. lpfc_worker_wake_up(phba);
  6752. return MBX_BUSY;
  6753. out_not_finished:
  6754. return MBX_NOT_FINISHED;
  6755. }
  6756. /**
  6757. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  6758. * @phba: Pointer to HBA context object.
  6759. *
  6760. * This function is called by worker thread to send a mailbox command to
  6761. * SLI4 HBA firmware.
  6762. *
  6763. **/
  6764. int
  6765. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  6766. {
  6767. struct lpfc_sli *psli = &phba->sli;
  6768. LPFC_MBOXQ_t *mboxq;
  6769. int rc = MBX_SUCCESS;
  6770. unsigned long iflags;
  6771. struct lpfc_mqe *mqe;
  6772. uint32_t mbx_cmnd;
  6773. /* Check interrupt mode before post async mailbox command */
  6774. if (unlikely(!phba->sli4_hba.intr_enable))
  6775. return MBX_NOT_FINISHED;
  6776. /* Check for mailbox command service token */
  6777. spin_lock_irqsave(&phba->hbalock, iflags);
  6778. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6779. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6780. return MBX_NOT_FINISHED;
  6781. }
  6782. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6783. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6784. return MBX_NOT_FINISHED;
  6785. }
  6786. if (unlikely(phba->sli.mbox_active)) {
  6787. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6788. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6789. "0384 There is pending active mailbox cmd\n");
  6790. return MBX_NOT_FINISHED;
  6791. }
  6792. /* Take the mailbox command service token */
  6793. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6794. /* Get the next mailbox command from head of queue */
  6795. mboxq = lpfc_mbox_get(phba);
  6796. /* If no more mailbox command waiting for post, we're done */
  6797. if (!mboxq) {
  6798. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6799. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6800. return MBX_SUCCESS;
  6801. }
  6802. phba->sli.mbox_active = mboxq;
  6803. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6804. /* Check device readiness for posting mailbox command */
  6805. rc = lpfc_mbox_dev_check(phba);
  6806. if (unlikely(rc))
  6807. /* Driver clean routine will clean up pending mailbox */
  6808. goto out_not_finished;
  6809. /* Prepare the mbox command to be posted */
  6810. mqe = &mboxq->u.mqe;
  6811. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  6812. /* Start timer for the mbox_tmo and log some mailbox post messages */
  6813. mod_timer(&psli->mbox_tmo, (jiffies +
  6814. msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
  6815. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6816. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  6817. "x%x x%x\n",
  6818. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6819. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6820. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6821. phba->pport->port_state, psli->sli_flag);
  6822. if (mbx_cmnd != MBX_HEARTBEAT) {
  6823. if (mboxq->vport) {
  6824. lpfc_debugfs_disc_trc(mboxq->vport,
  6825. LPFC_DISC_TRC_MBOX_VPORT,
  6826. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6827. mbx_cmnd, mqe->un.mb_words[0],
  6828. mqe->un.mb_words[1]);
  6829. } else {
  6830. lpfc_debugfs_disc_trc(phba->pport,
  6831. LPFC_DISC_TRC_MBOX,
  6832. "MBOX Send: cmd:x%x mb:x%x x%x",
  6833. mbx_cmnd, mqe->un.mb_words[0],
  6834. mqe->un.mb_words[1]);
  6835. }
  6836. }
  6837. psli->slistat.mbox_cmd++;
  6838. /* Post the mailbox command to the port */
  6839. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  6840. if (rc != MBX_SUCCESS) {
  6841. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6842. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  6843. "cannot issue Data: x%x x%x\n",
  6844. mboxq->vport ? mboxq->vport->vpi : 0,
  6845. mboxq->u.mb.mbxCommand,
  6846. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6847. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6848. psli->sli_flag, MBX_NOWAIT);
  6849. goto out_not_finished;
  6850. }
  6851. return rc;
  6852. out_not_finished:
  6853. spin_lock_irqsave(&phba->hbalock, iflags);
  6854. if (phba->sli.mbox_active) {
  6855. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6856. __lpfc_mbox_cmpl_put(phba, mboxq);
  6857. /* Release the token */
  6858. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6859. phba->sli.mbox_active = NULL;
  6860. }
  6861. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6862. return MBX_NOT_FINISHED;
  6863. }
  6864. /**
  6865. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  6866. * @phba: Pointer to HBA context object.
  6867. * @pmbox: Pointer to mailbox object.
  6868. * @flag: Flag indicating how the mailbox need to be processed.
  6869. *
  6870. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  6871. * the API jump table function pointer from the lpfc_hba struct.
  6872. *
  6873. * Return codes the caller owns the mailbox command after the return of the
  6874. * function.
  6875. **/
  6876. int
  6877. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  6878. {
  6879. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  6880. }
  6881. /**
  6882. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  6883. * @phba: The hba struct for which this call is being executed.
  6884. * @dev_grp: The HBA PCI-Device group number.
  6885. *
  6886. * This routine sets up the mbox interface API function jump table in @phba
  6887. * struct.
  6888. * Returns: 0 - success, -ENODEV - failure.
  6889. **/
  6890. int
  6891. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6892. {
  6893. switch (dev_grp) {
  6894. case LPFC_PCI_DEV_LP:
  6895. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  6896. phba->lpfc_sli_handle_slow_ring_event =
  6897. lpfc_sli_handle_slow_ring_event_s3;
  6898. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  6899. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  6900. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  6901. break;
  6902. case LPFC_PCI_DEV_OC:
  6903. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  6904. phba->lpfc_sli_handle_slow_ring_event =
  6905. lpfc_sli_handle_slow_ring_event_s4;
  6906. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  6907. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  6908. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  6909. break;
  6910. default:
  6911. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6912. "1420 Invalid HBA PCI-device group: 0x%x\n",
  6913. dev_grp);
  6914. return -ENODEV;
  6915. break;
  6916. }
  6917. return 0;
  6918. }
  6919. /**
  6920. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  6921. * @phba: Pointer to HBA context object.
  6922. * @pring: Pointer to driver SLI ring object.
  6923. * @piocb: Pointer to address of newly added command iocb.
  6924. *
  6925. * This function is called with hbalock held to add a command
  6926. * iocb to the txq when SLI layer cannot submit the command iocb
  6927. * to the ring.
  6928. **/
  6929. void
  6930. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6931. struct lpfc_iocbq *piocb)
  6932. {
  6933. /* Insert the caller's iocb in the txq tail for later processing. */
  6934. list_add_tail(&piocb->list, &pring->txq);
  6935. }
  6936. /**
  6937. * lpfc_sli_next_iocb - Get the next iocb in the txq
  6938. * @phba: Pointer to HBA context object.
  6939. * @pring: Pointer to driver SLI ring object.
  6940. * @piocb: Pointer to address of newly added command iocb.
  6941. *
  6942. * This function is called with hbalock held before a new
  6943. * iocb is submitted to the firmware. This function checks
  6944. * txq to flush the iocbs in txq to Firmware before
  6945. * submitting new iocbs to the Firmware.
  6946. * If there are iocbs in the txq which need to be submitted
  6947. * to firmware, lpfc_sli_next_iocb returns the first element
  6948. * of the txq after dequeuing it from txq.
  6949. * If there is no iocb in the txq then the function will return
  6950. * *piocb and *piocb is set to NULL. Caller needs to check
  6951. * *piocb to find if there are more commands in the txq.
  6952. **/
  6953. static struct lpfc_iocbq *
  6954. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6955. struct lpfc_iocbq **piocb)
  6956. {
  6957. struct lpfc_iocbq * nextiocb;
  6958. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  6959. if (!nextiocb) {
  6960. nextiocb = *piocb;
  6961. *piocb = NULL;
  6962. }
  6963. return nextiocb;
  6964. }
  6965. /**
  6966. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  6967. * @phba: Pointer to HBA context object.
  6968. * @ring_number: SLI ring number to issue iocb on.
  6969. * @piocb: Pointer to command iocb.
  6970. * @flag: Flag indicating if this command can be put into txq.
  6971. *
  6972. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  6973. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  6974. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  6975. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  6976. * this function allows only iocbs for posting buffers. This function finds
  6977. * next available slot in the command ring and posts the command to the
  6978. * available slot and writes the port attention register to request HBA start
  6979. * processing new iocb. If there is no slot available in the ring and
  6980. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  6981. * the function returns IOCB_BUSY.
  6982. *
  6983. * This function is called with hbalock held. The function will return success
  6984. * after it successfully submit the iocb to firmware or after adding to the
  6985. * txq.
  6986. **/
  6987. static int
  6988. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  6989. struct lpfc_iocbq *piocb, uint32_t flag)
  6990. {
  6991. struct lpfc_iocbq *nextiocb;
  6992. IOCB_t *iocb;
  6993. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6994. if (piocb->iocb_cmpl && (!piocb->vport) &&
  6995. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  6996. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  6997. lpfc_printf_log(phba, KERN_ERR,
  6998. LOG_SLI | LOG_VPORT,
  6999. "1807 IOCB x%x failed. No vport\n",
  7000. piocb->iocb.ulpCommand);
  7001. dump_stack();
  7002. return IOCB_ERROR;
  7003. }
  7004. /* If the PCI channel is in offline state, do not post iocbs. */
  7005. if (unlikely(pci_channel_offline(phba->pcidev)))
  7006. return IOCB_ERROR;
  7007. /* If HBA has a deferred error attention, fail the iocb. */
  7008. if (unlikely(phba->hba_flag & DEFER_ERATT))
  7009. return IOCB_ERROR;
  7010. /*
  7011. * We should never get an IOCB if we are in a < LINK_DOWN state
  7012. */
  7013. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7014. return IOCB_ERROR;
  7015. /*
  7016. * Check to see if we are blocking IOCB processing because of a
  7017. * outstanding event.
  7018. */
  7019. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  7020. goto iocb_busy;
  7021. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  7022. /*
  7023. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  7024. * can be issued if the link is not up.
  7025. */
  7026. switch (piocb->iocb.ulpCommand) {
  7027. case CMD_GEN_REQUEST64_CR:
  7028. case CMD_GEN_REQUEST64_CX:
  7029. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  7030. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  7031. FC_RCTL_DD_UNSOL_CMD) ||
  7032. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  7033. MENLO_TRANSPORT_TYPE))
  7034. goto iocb_busy;
  7035. break;
  7036. case CMD_QUE_RING_BUF_CN:
  7037. case CMD_QUE_RING_BUF64_CN:
  7038. /*
  7039. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  7040. * completion, iocb_cmpl MUST be 0.
  7041. */
  7042. if (piocb->iocb_cmpl)
  7043. piocb->iocb_cmpl = NULL;
  7044. /*FALLTHROUGH*/
  7045. case CMD_CREATE_XRI_CR:
  7046. case CMD_CLOSE_XRI_CN:
  7047. case CMD_CLOSE_XRI_CX:
  7048. break;
  7049. default:
  7050. goto iocb_busy;
  7051. }
  7052. /*
  7053. * For FCP commands, we must be in a state where we can process link
  7054. * attention events.
  7055. */
  7056. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  7057. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  7058. goto iocb_busy;
  7059. }
  7060. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  7061. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  7062. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  7063. if (iocb)
  7064. lpfc_sli_update_ring(phba, pring);
  7065. else
  7066. lpfc_sli_update_full_ring(phba, pring);
  7067. if (!piocb)
  7068. return IOCB_SUCCESS;
  7069. goto out_busy;
  7070. iocb_busy:
  7071. pring->stats.iocb_cmd_delay++;
  7072. out_busy:
  7073. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7074. __lpfc_sli_ringtx_put(phba, pring, piocb);
  7075. return IOCB_SUCCESS;
  7076. }
  7077. return IOCB_BUSY;
  7078. }
  7079. /**
  7080. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  7081. * @phba: Pointer to HBA context object.
  7082. * @piocb: Pointer to command iocb.
  7083. * @sglq: Pointer to the scatter gather queue object.
  7084. *
  7085. * This routine converts the bpl or bde that is in the IOCB
  7086. * to a sgl list for the sli4 hardware. The physical address
  7087. * of the bpl/bde is converted back to a virtual address.
  7088. * If the IOCB contains a BPL then the list of BDE's is
  7089. * converted to sli4_sge's. If the IOCB contains a single
  7090. * BDE then it is converted to a single sli_sge.
  7091. * The IOCB is still in cpu endianess so the contents of
  7092. * the bpl can be used without byte swapping.
  7093. *
  7094. * Returns valid XRI = Success, NO_XRI = Failure.
  7095. **/
  7096. static uint16_t
  7097. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  7098. struct lpfc_sglq *sglq)
  7099. {
  7100. uint16_t xritag = NO_XRI;
  7101. struct ulp_bde64 *bpl = NULL;
  7102. struct ulp_bde64 bde;
  7103. struct sli4_sge *sgl = NULL;
  7104. struct lpfc_dmabuf *dmabuf;
  7105. IOCB_t *icmd;
  7106. int numBdes = 0;
  7107. int i = 0;
  7108. uint32_t offset = 0; /* accumulated offset in the sg request list */
  7109. int inbound = 0; /* number of sg reply entries inbound from firmware */
  7110. if (!piocbq || !sglq)
  7111. return xritag;
  7112. sgl = (struct sli4_sge *)sglq->sgl;
  7113. icmd = &piocbq->iocb;
  7114. if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  7115. return sglq->sli4_xritag;
  7116. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7117. numBdes = icmd->un.genreq64.bdl.bdeSize /
  7118. sizeof(struct ulp_bde64);
  7119. /* The addrHigh and addrLow fields within the IOCB
  7120. * have not been byteswapped yet so there is no
  7121. * need to swap them back.
  7122. */
  7123. if (piocbq->context3)
  7124. dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
  7125. else
  7126. return xritag;
  7127. bpl = (struct ulp_bde64 *)dmabuf->virt;
  7128. if (!bpl)
  7129. return xritag;
  7130. for (i = 0; i < numBdes; i++) {
  7131. /* Should already be byte swapped. */
  7132. sgl->addr_hi = bpl->addrHigh;
  7133. sgl->addr_lo = bpl->addrLow;
  7134. sgl->word2 = le32_to_cpu(sgl->word2);
  7135. if ((i+1) == numBdes)
  7136. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7137. else
  7138. bf_set(lpfc_sli4_sge_last, sgl, 0);
  7139. /* swap the size field back to the cpu so we
  7140. * can assign it to the sgl.
  7141. */
  7142. bde.tus.w = le32_to_cpu(bpl->tus.w);
  7143. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  7144. /* The offsets in the sgl need to be accumulated
  7145. * separately for the request and reply lists.
  7146. * The request is always first, the reply follows.
  7147. */
  7148. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  7149. /* add up the reply sg entries */
  7150. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  7151. inbound++;
  7152. /* first inbound? reset the offset */
  7153. if (inbound == 1)
  7154. offset = 0;
  7155. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  7156. bf_set(lpfc_sli4_sge_type, sgl,
  7157. LPFC_SGE_TYPE_DATA);
  7158. offset += bde.tus.f.bdeSize;
  7159. }
  7160. sgl->word2 = cpu_to_le32(sgl->word2);
  7161. bpl++;
  7162. sgl++;
  7163. }
  7164. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  7165. /* The addrHigh and addrLow fields of the BDE have not
  7166. * been byteswapped yet so they need to be swapped
  7167. * before putting them in the sgl.
  7168. */
  7169. sgl->addr_hi =
  7170. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  7171. sgl->addr_lo =
  7172. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  7173. sgl->word2 = le32_to_cpu(sgl->word2);
  7174. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7175. sgl->word2 = cpu_to_le32(sgl->word2);
  7176. sgl->sge_len =
  7177. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  7178. }
  7179. return sglq->sli4_xritag;
  7180. }
  7181. /**
  7182. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  7183. * @phba: Pointer to HBA context object.
  7184. *
  7185. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  7186. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  7187. * held.
  7188. *
  7189. * Return: index into SLI4 fast-path FCP queue index.
  7190. **/
  7191. static inline uint32_t
  7192. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  7193. {
  7194. int i;
  7195. if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU)
  7196. i = smp_processor_id();
  7197. else
  7198. i = atomic_add_return(1, &phba->fcp_qidx);
  7199. i = (i % phba->cfg_fcp_io_channel);
  7200. return i;
  7201. }
  7202. /**
  7203. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  7204. * @phba: Pointer to HBA context object.
  7205. * @piocb: Pointer to command iocb.
  7206. * @wqe: Pointer to the work queue entry.
  7207. *
  7208. * This routine converts the iocb command to its Work Queue Entry
  7209. * equivalent. The wqe pointer should not have any fields set when
  7210. * this routine is called because it will memcpy over them.
  7211. * This routine does not set the CQ_ID or the WQEC bits in the
  7212. * wqe.
  7213. *
  7214. * Returns: 0 = Success, IOCB_ERROR = Failure.
  7215. **/
  7216. static int
  7217. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  7218. union lpfc_wqe *wqe)
  7219. {
  7220. uint32_t xmit_len = 0, total_len = 0;
  7221. uint8_t ct = 0;
  7222. uint32_t fip;
  7223. uint32_t abort_tag;
  7224. uint8_t command_type = ELS_COMMAND_NON_FIP;
  7225. uint8_t cmnd;
  7226. uint16_t xritag;
  7227. uint16_t abrt_iotag;
  7228. struct lpfc_iocbq *abrtiocbq;
  7229. struct ulp_bde64 *bpl = NULL;
  7230. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  7231. int numBdes, i;
  7232. struct ulp_bde64 bde;
  7233. struct lpfc_nodelist *ndlp;
  7234. uint32_t *pcmd;
  7235. uint32_t if_type;
  7236. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  7237. /* The fcp commands will set command type */
  7238. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7239. command_type = FCP_COMMAND;
  7240. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  7241. command_type = ELS_COMMAND_FIP;
  7242. else
  7243. command_type = ELS_COMMAND_NON_FIP;
  7244. /* Some of the fields are in the right position already */
  7245. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  7246. abort_tag = (uint32_t) iocbq->iotag;
  7247. xritag = iocbq->sli4_xritag;
  7248. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  7249. /* words0-2 bpl convert bde */
  7250. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7251. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7252. sizeof(struct ulp_bde64);
  7253. bpl = (struct ulp_bde64 *)
  7254. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  7255. if (!bpl)
  7256. return IOCB_ERROR;
  7257. /* Should already be byte swapped. */
  7258. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  7259. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  7260. /* swap the size field back to the cpu so we
  7261. * can assign it to the sgl.
  7262. */
  7263. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  7264. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  7265. total_len = 0;
  7266. for (i = 0; i < numBdes; i++) {
  7267. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7268. total_len += bde.tus.f.bdeSize;
  7269. }
  7270. } else
  7271. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  7272. iocbq->iocb.ulpIoTag = iocbq->iotag;
  7273. cmnd = iocbq->iocb.ulpCommand;
  7274. switch (iocbq->iocb.ulpCommand) {
  7275. case CMD_ELS_REQUEST64_CR:
  7276. if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
  7277. ndlp = iocbq->context_un.ndlp;
  7278. else
  7279. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7280. if (!iocbq->iocb.ulpLe) {
  7281. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7282. "2007 Only Limited Edition cmd Format"
  7283. " supported 0x%x\n",
  7284. iocbq->iocb.ulpCommand);
  7285. return IOCB_ERROR;
  7286. }
  7287. wqe->els_req.payload_len = xmit_len;
  7288. /* Els_reguest64 has a TMO */
  7289. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  7290. iocbq->iocb.ulpTimeout);
  7291. /* Need a VF for word 4 set the vf bit*/
  7292. bf_set(els_req64_vf, &wqe->els_req, 0);
  7293. /* And a VFID for word 12 */
  7294. bf_set(els_req64_vfid, &wqe->els_req, 0);
  7295. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7296. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7297. iocbq->iocb.ulpContext);
  7298. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  7299. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  7300. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7301. if (command_type == ELS_COMMAND_FIP)
  7302. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7303. >> LPFC_FIP_ELS_ID_SHIFT);
  7304. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7305. iocbq->context2)->virt);
  7306. if_type = bf_get(lpfc_sli_intf_if_type,
  7307. &phba->sli4_hba.sli_intf);
  7308. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7309. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7310. *pcmd == ELS_CMD_SCR ||
  7311. *pcmd == ELS_CMD_FDISC ||
  7312. *pcmd == ELS_CMD_LOGO ||
  7313. *pcmd == ELS_CMD_PLOGI)) {
  7314. bf_set(els_req64_sp, &wqe->els_req, 1);
  7315. bf_set(els_req64_sid, &wqe->els_req,
  7316. iocbq->vport->fc_myDID);
  7317. if ((*pcmd == ELS_CMD_FLOGI) &&
  7318. !(phba->fc_topology ==
  7319. LPFC_TOPOLOGY_LOOP))
  7320. bf_set(els_req64_sid, &wqe->els_req, 0);
  7321. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7322. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7323. phba->vpi_ids[iocbq->vport->vpi]);
  7324. } else if (pcmd && iocbq->context1) {
  7325. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7326. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7327. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7328. }
  7329. }
  7330. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7331. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7332. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7333. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7334. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7335. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7336. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7337. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7338. break;
  7339. case CMD_XMIT_SEQUENCE64_CX:
  7340. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7341. iocbq->iocb.un.ulpWord[3]);
  7342. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7343. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7344. /* The entire sequence is transmitted for this IOCB */
  7345. xmit_len = total_len;
  7346. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7347. if (phba->link_flag & LS_LOOPBACK_MODE)
  7348. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  7349. case CMD_XMIT_SEQUENCE64_CR:
  7350. /* word3 iocb=io_tag32 wqe=reserved */
  7351. wqe->xmit_sequence.rsvd3 = 0;
  7352. /* word4 relative_offset memcpy */
  7353. /* word5 r_ctl/df_ctl memcpy */
  7354. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7355. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7356. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7357. LPFC_WQE_IOD_WRITE);
  7358. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7359. LPFC_WQE_LENLOC_WORD12);
  7360. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7361. wqe->xmit_sequence.xmit_len = xmit_len;
  7362. command_type = OTHER_COMMAND;
  7363. break;
  7364. case CMD_XMIT_BCAST64_CN:
  7365. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7366. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7367. /* word4 iocb=rsvd wqe=rsvd */
  7368. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7369. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7370. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7371. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7372. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7373. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7374. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7375. LPFC_WQE_LENLOC_WORD3);
  7376. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7377. break;
  7378. case CMD_FCP_IWRITE64_CR:
  7379. command_type = FCP_COMMAND_DATA_OUT;
  7380. /* word3 iocb=iotag wqe=payload_offset_len */
  7381. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7382. wqe->fcp_iwrite.payload_offset_len =
  7383. xmit_len + sizeof(struct fcp_rsp);
  7384. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7385. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7386. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7387. iocbq->iocb.ulpFCP2Rcvy);
  7388. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7389. /* Always open the exchange */
  7390. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  7391. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7392. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7393. LPFC_WQE_LENLOC_WORD4);
  7394. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  7395. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7396. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7397. break;
  7398. case CMD_FCP_IREAD64_CR:
  7399. /* word3 iocb=iotag wqe=payload_offset_len */
  7400. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7401. wqe->fcp_iread.payload_offset_len =
  7402. xmit_len + sizeof(struct fcp_rsp);
  7403. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7404. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7405. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7406. iocbq->iocb.ulpFCP2Rcvy);
  7407. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7408. /* Always open the exchange */
  7409. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  7410. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7411. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7412. LPFC_WQE_LENLOC_WORD4);
  7413. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  7414. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7415. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7416. break;
  7417. case CMD_FCP_ICMND64_CR:
  7418. /* word3 iocb=IO_TAG wqe=reserved */
  7419. wqe->fcp_icmd.rsrvd3 = 0;
  7420. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7421. /* Always open the exchange */
  7422. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  7423. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7424. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7425. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7426. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7427. LPFC_WQE_LENLOC_NONE);
  7428. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  7429. bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
  7430. iocbq->iocb.ulpFCP2Rcvy);
  7431. break;
  7432. case CMD_GEN_REQUEST64_CR:
  7433. /* For this command calculate the xmit length of the
  7434. * request bde.
  7435. */
  7436. xmit_len = 0;
  7437. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7438. sizeof(struct ulp_bde64);
  7439. for (i = 0; i < numBdes; i++) {
  7440. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7441. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7442. break;
  7443. xmit_len += bde.tus.f.bdeSize;
  7444. }
  7445. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7446. wqe->gen_req.request_payload_len = xmit_len;
  7447. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7448. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7449. /* word6 context tag copied in memcpy */
  7450. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7451. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7452. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7453. "2015 Invalid CT %x command 0x%x\n",
  7454. ct, iocbq->iocb.ulpCommand);
  7455. return IOCB_ERROR;
  7456. }
  7457. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7458. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7459. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7460. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7461. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7462. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7463. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7464. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7465. command_type = OTHER_COMMAND;
  7466. break;
  7467. case CMD_XMIT_ELS_RSP64_CX:
  7468. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7469. /* words0-2 BDE memcpy */
  7470. /* word3 iocb=iotag32 wqe=response_payload_len */
  7471. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7472. /* word4 */
  7473. wqe->xmit_els_rsp.word4 = 0;
  7474. /* word5 iocb=rsvd wge=did */
  7475. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7476. iocbq->iocb.un.xseq64.xmit_els_remoteID);
  7477. if_type = bf_get(lpfc_sli_intf_if_type,
  7478. &phba->sli4_hba.sli_intf);
  7479. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7480. if (iocbq->vport->fc_flag & FC_PT2PT) {
  7481. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7482. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7483. iocbq->vport->fc_myDID);
  7484. if (iocbq->vport->fc_myDID == Fabric_DID) {
  7485. bf_set(wqe_els_did,
  7486. &wqe->xmit_els_rsp.wqe_dest, 0);
  7487. }
  7488. }
  7489. }
  7490. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7491. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7492. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7493. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7494. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7495. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7496. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7497. phba->vpi_ids[iocbq->vport->vpi]);
  7498. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7499. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7500. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7501. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7502. LPFC_WQE_LENLOC_WORD3);
  7503. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7504. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7505. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7506. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7507. iocbq->context2)->virt);
  7508. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7509. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7510. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7511. iocbq->vport->fc_myDID);
  7512. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
  7513. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7514. phba->vpi_ids[phba->pport->vpi]);
  7515. }
  7516. command_type = OTHER_COMMAND;
  7517. break;
  7518. case CMD_CLOSE_XRI_CN:
  7519. case CMD_ABORT_XRI_CN:
  7520. case CMD_ABORT_XRI_CX:
  7521. /* words 0-2 memcpy should be 0 rserved */
  7522. /* port will send abts */
  7523. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7524. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7525. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7526. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7527. } else
  7528. fip = 0;
  7529. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7530. /*
  7531. * The link is down, or the command was ELS_FIP
  7532. * so the fw does not need to send abts
  7533. * on the wire.
  7534. */
  7535. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7536. else
  7537. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7538. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7539. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7540. wqe->abort_cmd.rsrvd5 = 0;
  7541. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7542. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7543. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7544. /*
  7545. * The abort handler will send us CMD_ABORT_XRI_CN or
  7546. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7547. */
  7548. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7549. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7550. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7551. LPFC_WQE_LENLOC_NONE);
  7552. cmnd = CMD_ABORT_XRI_CX;
  7553. command_type = OTHER_COMMAND;
  7554. xritag = 0;
  7555. break;
  7556. case CMD_XMIT_BLS_RSP64_CX:
  7557. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7558. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7559. * we re-construct this WQE here based on information in
  7560. * iocbq from scratch.
  7561. */
  7562. memset(wqe, 0, sizeof(union lpfc_wqe));
  7563. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7564. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7565. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7566. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7567. LPFC_ABTS_UNSOL_INT) {
  7568. /* ABTS sent by initiator to CT exchange, the
  7569. * RX_ID field will be filled with the newly
  7570. * allocated responder XRI.
  7571. */
  7572. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7573. iocbq->sli4_xritag);
  7574. } else {
  7575. /* ABTS sent by responder to CT exchange, the
  7576. * RX_ID field will be filled with the responder
  7577. * RX_ID from ABTS.
  7578. */
  7579. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7580. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7581. }
  7582. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7583. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7584. /* Use CT=VPI */
  7585. bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
  7586. ndlp->nlp_DID);
  7587. bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
  7588. iocbq->iocb.ulpContext);
  7589. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  7590. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7591. phba->vpi_ids[phba->pport->vpi]);
  7592. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7593. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7594. LPFC_WQE_LENLOC_NONE);
  7595. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7596. command_type = OTHER_COMMAND;
  7597. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7598. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7599. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7600. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7601. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7602. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7603. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7604. }
  7605. break;
  7606. case CMD_XRI_ABORTED_CX:
  7607. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7608. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7609. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7610. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7611. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7612. default:
  7613. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7614. "2014 Invalid command 0x%x\n",
  7615. iocbq->iocb.ulpCommand);
  7616. return IOCB_ERROR;
  7617. break;
  7618. }
  7619. if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
  7620. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
  7621. else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
  7622. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
  7623. else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
  7624. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
  7625. iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
  7626. LPFC_IO_DIF_INSERT);
  7627. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7628. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7629. wqe->generic.wqe_com.abort_tag = abort_tag;
  7630. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  7631. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  7632. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  7633. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  7634. return 0;
  7635. }
  7636. /**
  7637. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  7638. * @phba: Pointer to HBA context object.
  7639. * @ring_number: SLI ring number to issue iocb on.
  7640. * @piocb: Pointer to command iocb.
  7641. * @flag: Flag indicating if this command can be put into txq.
  7642. *
  7643. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  7644. * an iocb command to an HBA with SLI-4 interface spec.
  7645. *
  7646. * This function is called with hbalock held. The function will return success
  7647. * after it successfully submit the iocb to firmware or after adding to the
  7648. * txq.
  7649. **/
  7650. static int
  7651. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  7652. struct lpfc_iocbq *piocb, uint32_t flag)
  7653. {
  7654. struct lpfc_sglq *sglq;
  7655. union lpfc_wqe wqe;
  7656. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7657. if (piocb->sli4_xritag == NO_XRI) {
  7658. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  7659. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  7660. sglq = NULL;
  7661. else {
  7662. if (!list_empty(&pring->txq)) {
  7663. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7664. __lpfc_sli_ringtx_put(phba,
  7665. pring, piocb);
  7666. return IOCB_SUCCESS;
  7667. } else {
  7668. return IOCB_BUSY;
  7669. }
  7670. } else {
  7671. sglq = __lpfc_sli_get_sglq(phba, piocb);
  7672. if (!sglq) {
  7673. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7674. __lpfc_sli_ringtx_put(phba,
  7675. pring,
  7676. piocb);
  7677. return IOCB_SUCCESS;
  7678. } else
  7679. return IOCB_BUSY;
  7680. }
  7681. }
  7682. }
  7683. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  7684. /* These IO's already have an XRI and a mapped sgl. */
  7685. sglq = NULL;
  7686. } else {
  7687. /*
  7688. * This is a continuation of a commandi,(CX) so this
  7689. * sglq is on the active list
  7690. */
  7691. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
  7692. if (!sglq)
  7693. return IOCB_ERROR;
  7694. }
  7695. if (sglq) {
  7696. piocb->sli4_lxritag = sglq->sli4_lxritag;
  7697. piocb->sli4_xritag = sglq->sli4_xritag;
  7698. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  7699. return IOCB_ERROR;
  7700. }
  7701. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  7702. return IOCB_ERROR;
  7703. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  7704. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  7705. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  7706. &wqe))
  7707. return IOCB_ERROR;
  7708. } else {
  7709. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  7710. return IOCB_ERROR;
  7711. }
  7712. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  7713. return 0;
  7714. }
  7715. /**
  7716. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  7717. *
  7718. * This routine wraps the actual lockless version for issusing IOCB function
  7719. * pointer from the lpfc_hba struct.
  7720. *
  7721. * Return codes:
  7722. * IOCB_ERROR - Error
  7723. * IOCB_SUCCESS - Success
  7724. * IOCB_BUSY - Busy
  7725. **/
  7726. int
  7727. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7728. struct lpfc_iocbq *piocb, uint32_t flag)
  7729. {
  7730. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7731. }
  7732. /**
  7733. * lpfc_sli_api_table_setup - Set up sli api function jump table
  7734. * @phba: The hba struct for which this call is being executed.
  7735. * @dev_grp: The HBA PCI-Device group number.
  7736. *
  7737. * This routine sets up the SLI interface API function jump table in @phba
  7738. * struct.
  7739. * Returns: 0 - success, -ENODEV - failure.
  7740. **/
  7741. int
  7742. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7743. {
  7744. switch (dev_grp) {
  7745. case LPFC_PCI_DEV_LP:
  7746. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  7747. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  7748. break;
  7749. case LPFC_PCI_DEV_OC:
  7750. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  7751. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  7752. break;
  7753. default:
  7754. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7755. "1419 Invalid HBA PCI-device group: 0x%x\n",
  7756. dev_grp);
  7757. return -ENODEV;
  7758. break;
  7759. }
  7760. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  7761. return 0;
  7762. }
  7763. /**
  7764. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  7765. * @phba: Pointer to HBA context object.
  7766. * @pring: Pointer to driver SLI ring object.
  7767. * @piocb: Pointer to command iocb.
  7768. * @flag: Flag indicating if this command can be put into txq.
  7769. *
  7770. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  7771. * function. This function gets the hbalock and calls
  7772. * __lpfc_sli_issue_iocb function and will return the error returned
  7773. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  7774. * functions which do not hold hbalock.
  7775. **/
  7776. int
  7777. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7778. struct lpfc_iocbq *piocb, uint32_t flag)
  7779. {
  7780. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  7781. struct lpfc_sli_ring *pring;
  7782. struct lpfc_queue *fpeq;
  7783. struct lpfc_eqe *eqe;
  7784. unsigned long iflags;
  7785. int rc, idx;
  7786. if (phba->sli_rev == LPFC_SLI_REV4) {
  7787. if (piocb->iocb_flag & LPFC_IO_FCP) {
  7788. if (unlikely(!phba->sli4_hba.fcp_wq))
  7789. return IOCB_ERROR;
  7790. idx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  7791. piocb->fcp_wqidx = idx;
  7792. ring_number = MAX_SLI3_CONFIGURED_RINGS + idx;
  7793. pring = &phba->sli.ring[ring_number];
  7794. spin_lock_irqsave(&pring->ring_lock, iflags);
  7795. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7796. flag);
  7797. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  7798. if (lpfc_fcp_look_ahead) {
  7799. fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx];
  7800. if (atomic_dec_and_test(&fcp_eq_hdl->
  7801. fcp_eq_in_use)) {
  7802. /* Get associated EQ with this index */
  7803. fpeq = phba->sli4_hba.hba_eq[idx];
  7804. /* Turn off interrupts from this EQ */
  7805. lpfc_sli4_eq_clr_intr(fpeq);
  7806. /*
  7807. * Process all the events on FCP EQ
  7808. */
  7809. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  7810. lpfc_sli4_hba_handle_eqe(phba,
  7811. eqe, idx);
  7812. fpeq->EQ_processed++;
  7813. }
  7814. /* Always clear and re-arm the EQ */
  7815. lpfc_sli4_eq_release(fpeq,
  7816. LPFC_QUEUE_REARM);
  7817. }
  7818. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  7819. }
  7820. } else {
  7821. pring = &phba->sli.ring[ring_number];
  7822. spin_lock_irqsave(&pring->ring_lock, iflags);
  7823. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7824. flag);
  7825. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  7826. }
  7827. } else {
  7828. /* For now, SLI2/3 will still use hbalock */
  7829. spin_lock_irqsave(&phba->hbalock, iflags);
  7830. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7831. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7832. }
  7833. return rc;
  7834. }
  7835. /**
  7836. * lpfc_extra_ring_setup - Extra ring setup function
  7837. * @phba: Pointer to HBA context object.
  7838. *
  7839. * This function is called while driver attaches with the
  7840. * HBA to setup the extra ring. The extra ring is used
  7841. * only when driver needs to support target mode functionality
  7842. * or IP over FC functionalities.
  7843. *
  7844. * This function is called with no lock held.
  7845. **/
  7846. static int
  7847. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  7848. {
  7849. struct lpfc_sli *psli;
  7850. struct lpfc_sli_ring *pring;
  7851. psli = &phba->sli;
  7852. /* Adjust cmd/rsp ring iocb entries more evenly */
  7853. /* Take some away from the FCP ring */
  7854. pring = &psli->ring[psli->fcp_ring];
  7855. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7856. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7857. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7858. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7859. /* and give them to the extra ring */
  7860. pring = &psli->ring[psli->extra_ring];
  7861. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7862. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7863. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7864. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7865. /* Setup default profile for this ring */
  7866. pring->iotag_max = 4096;
  7867. pring->num_mask = 1;
  7868. pring->prt[0].profile = 0; /* Mask 0 */
  7869. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  7870. pring->prt[0].type = phba->cfg_multi_ring_type;
  7871. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  7872. return 0;
  7873. }
  7874. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  7875. * @phba: Pointer to HBA context object.
  7876. * @iocbq: Pointer to iocb object.
  7877. *
  7878. * The async_event handler calls this routine when it receives
  7879. * an ASYNC_STATUS_CN event from the port. The port generates
  7880. * this event when an Abort Sequence request to an rport fails
  7881. * twice in succession. The abort could be originated by the
  7882. * driver or by the port. The ABTS could have been for an ELS
  7883. * or FCP IO. The port only generates this event when an ABTS
  7884. * fails to complete after one retry.
  7885. */
  7886. static void
  7887. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  7888. struct lpfc_iocbq *iocbq)
  7889. {
  7890. struct lpfc_nodelist *ndlp = NULL;
  7891. uint16_t rpi = 0, vpi = 0;
  7892. struct lpfc_vport *vport = NULL;
  7893. /* The rpi in the ulpContext is vport-sensitive. */
  7894. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  7895. rpi = iocbq->iocb.ulpContext;
  7896. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7897. "3092 Port generated ABTS async event "
  7898. "on vpi %d rpi %d status 0x%x\n",
  7899. vpi, rpi, iocbq->iocb.ulpStatus);
  7900. vport = lpfc_find_vport_by_vpid(phba, vpi);
  7901. if (!vport)
  7902. goto err_exit;
  7903. ndlp = lpfc_findnode_rpi(vport, rpi);
  7904. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  7905. goto err_exit;
  7906. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  7907. lpfc_sli_abts_recover_port(vport, ndlp);
  7908. return;
  7909. err_exit:
  7910. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7911. "3095 Event Context not found, no "
  7912. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  7913. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  7914. vpi, rpi);
  7915. }
  7916. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  7917. * @phba: pointer to HBA context object.
  7918. * @ndlp: nodelist pointer for the impacted rport.
  7919. * @axri: pointer to the wcqe containing the failed exchange.
  7920. *
  7921. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  7922. * port. The port generates this event when an abort exchange request to an
  7923. * rport fails twice in succession with no reply. The abort could be originated
  7924. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  7925. */
  7926. void
  7927. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  7928. struct lpfc_nodelist *ndlp,
  7929. struct sli4_wcqe_xri_aborted *axri)
  7930. {
  7931. struct lpfc_vport *vport;
  7932. uint32_t ext_status = 0;
  7933. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  7934. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7935. "3115 Node Context not found, driver "
  7936. "ignoring abts err event\n");
  7937. return;
  7938. }
  7939. vport = ndlp->vport;
  7940. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7941. "3116 Port generated FCP XRI ABORT event on "
  7942. "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
  7943. ndlp->vport->vpi, ndlp->nlp_rpi,
  7944. bf_get(lpfc_wcqe_xa_xri, axri),
  7945. bf_get(lpfc_wcqe_xa_status, axri),
  7946. axri->parameter);
  7947. /*
  7948. * Catch the ABTS protocol failure case. Older OCe FW releases returned
  7949. * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
  7950. * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
  7951. */
  7952. ext_status = axri->parameter & IOERR_PARAM_MASK;
  7953. if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
  7954. ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
  7955. lpfc_sli_abts_recover_port(vport, ndlp);
  7956. }
  7957. /**
  7958. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  7959. * @phba: Pointer to HBA context object.
  7960. * @pring: Pointer to driver SLI ring object.
  7961. * @iocbq: Pointer to iocb object.
  7962. *
  7963. * This function is called by the slow ring event handler
  7964. * function when there is an ASYNC event iocb in the ring.
  7965. * This function is called with no lock held.
  7966. * Currently this function handles only temperature related
  7967. * ASYNC events. The function decodes the temperature sensor
  7968. * event message and posts events for the management applications.
  7969. **/
  7970. static void
  7971. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  7972. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  7973. {
  7974. IOCB_t *icmd;
  7975. uint16_t evt_code;
  7976. struct temp_event temp_event_data;
  7977. struct Scsi_Host *shost;
  7978. uint32_t *iocb_w;
  7979. icmd = &iocbq->iocb;
  7980. evt_code = icmd->un.asyncstat.evt_code;
  7981. switch (evt_code) {
  7982. case ASYNC_TEMP_WARN:
  7983. case ASYNC_TEMP_SAFE:
  7984. temp_event_data.data = (uint32_t) icmd->ulpContext;
  7985. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  7986. if (evt_code == ASYNC_TEMP_WARN) {
  7987. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  7988. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7989. "0347 Adapter is very hot, please take "
  7990. "corrective action. temperature : %d Celsius\n",
  7991. (uint32_t) icmd->ulpContext);
  7992. } else {
  7993. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  7994. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7995. "0340 Adapter temperature is OK now. "
  7996. "temperature : %d Celsius\n",
  7997. (uint32_t) icmd->ulpContext);
  7998. }
  7999. /* Send temperature change event to applications */
  8000. shost = lpfc_shost_from_vport(phba->pport);
  8001. fc_host_post_vendor_event(shost, fc_get_event_number(),
  8002. sizeof(temp_event_data), (char *) &temp_event_data,
  8003. LPFC_NL_VENDOR_ID);
  8004. break;
  8005. case ASYNC_STATUS_CN:
  8006. lpfc_sli_abts_err_handler(phba, iocbq);
  8007. break;
  8008. default:
  8009. iocb_w = (uint32_t *) icmd;
  8010. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8011. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  8012. " evt_code 0x%x\n"
  8013. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  8014. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  8015. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  8016. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  8017. pring->ringno, icmd->un.asyncstat.evt_code,
  8018. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  8019. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  8020. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  8021. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  8022. break;
  8023. }
  8024. }
  8025. /**
  8026. * lpfc_sli_setup - SLI ring setup function
  8027. * @phba: Pointer to HBA context object.
  8028. *
  8029. * lpfc_sli_setup sets up rings of the SLI interface with
  8030. * number of iocbs per ring and iotags. This function is
  8031. * called while driver attach to the HBA and before the
  8032. * interrupts are enabled. So there is no need for locking.
  8033. *
  8034. * This function always returns 0.
  8035. **/
  8036. int
  8037. lpfc_sli_setup(struct lpfc_hba *phba)
  8038. {
  8039. int i, totiocbsize = 0;
  8040. struct lpfc_sli *psli = &phba->sli;
  8041. struct lpfc_sli_ring *pring;
  8042. psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
  8043. if (phba->sli_rev == LPFC_SLI_REV4)
  8044. psli->num_rings += phba->cfg_fcp_io_channel;
  8045. psli->sli_flag = 0;
  8046. psli->fcp_ring = LPFC_FCP_RING;
  8047. psli->next_ring = LPFC_FCP_NEXT_RING;
  8048. psli->extra_ring = LPFC_EXTRA_RING;
  8049. psli->iocbq_lookup = NULL;
  8050. psli->iocbq_lookup_len = 0;
  8051. psli->last_iotag = 0;
  8052. for (i = 0; i < psli->num_rings; i++) {
  8053. pring = &psli->ring[i];
  8054. switch (i) {
  8055. case LPFC_FCP_RING: /* ring 0 - FCP */
  8056. /* numCiocb and numRiocb are used in config_port */
  8057. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  8058. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  8059. pring->sli.sli3.numCiocb +=
  8060. SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8061. pring->sli.sli3.numRiocb +=
  8062. SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8063. pring->sli.sli3.numCiocb +=
  8064. SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8065. pring->sli.sli3.numRiocb +=
  8066. SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8067. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8068. SLI3_IOCB_CMD_SIZE :
  8069. SLI2_IOCB_CMD_SIZE;
  8070. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8071. SLI3_IOCB_RSP_SIZE :
  8072. SLI2_IOCB_RSP_SIZE;
  8073. pring->iotag_ctr = 0;
  8074. pring->iotag_max =
  8075. (phba->cfg_hba_queue_depth * 2);
  8076. pring->fast_iotag = pring->iotag_max;
  8077. pring->num_mask = 0;
  8078. break;
  8079. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  8080. /* numCiocb and numRiocb are used in config_port */
  8081. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  8082. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  8083. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8084. SLI3_IOCB_CMD_SIZE :
  8085. SLI2_IOCB_CMD_SIZE;
  8086. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8087. SLI3_IOCB_RSP_SIZE :
  8088. SLI2_IOCB_RSP_SIZE;
  8089. pring->iotag_max = phba->cfg_hba_queue_depth;
  8090. pring->num_mask = 0;
  8091. break;
  8092. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  8093. /* numCiocb and numRiocb are used in config_port */
  8094. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  8095. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  8096. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8097. SLI3_IOCB_CMD_SIZE :
  8098. SLI2_IOCB_CMD_SIZE;
  8099. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8100. SLI3_IOCB_RSP_SIZE :
  8101. SLI2_IOCB_RSP_SIZE;
  8102. pring->fast_iotag = 0;
  8103. pring->iotag_ctr = 0;
  8104. pring->iotag_max = 4096;
  8105. pring->lpfc_sli_rcv_async_status =
  8106. lpfc_sli_async_event_handler;
  8107. pring->num_mask = LPFC_MAX_RING_MASK;
  8108. pring->prt[0].profile = 0; /* Mask 0 */
  8109. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  8110. pring->prt[0].type = FC_TYPE_ELS;
  8111. pring->prt[0].lpfc_sli_rcv_unsol_event =
  8112. lpfc_els_unsol_event;
  8113. pring->prt[1].profile = 0; /* Mask 1 */
  8114. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  8115. pring->prt[1].type = FC_TYPE_ELS;
  8116. pring->prt[1].lpfc_sli_rcv_unsol_event =
  8117. lpfc_els_unsol_event;
  8118. pring->prt[2].profile = 0; /* Mask 2 */
  8119. /* NameServer Inquiry */
  8120. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  8121. /* NameServer */
  8122. pring->prt[2].type = FC_TYPE_CT;
  8123. pring->prt[2].lpfc_sli_rcv_unsol_event =
  8124. lpfc_ct_unsol_event;
  8125. pring->prt[3].profile = 0; /* Mask 3 */
  8126. /* NameServer response */
  8127. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  8128. /* NameServer */
  8129. pring->prt[3].type = FC_TYPE_CT;
  8130. pring->prt[3].lpfc_sli_rcv_unsol_event =
  8131. lpfc_ct_unsol_event;
  8132. break;
  8133. }
  8134. totiocbsize += (pring->sli.sli3.numCiocb *
  8135. pring->sli.sli3.sizeCiocb) +
  8136. (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
  8137. }
  8138. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  8139. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  8140. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  8141. "SLI2 SLIM Data: x%x x%lx\n",
  8142. phba->brd_no, totiocbsize,
  8143. (unsigned long) MAX_SLIM_IOCB_SIZE);
  8144. }
  8145. if (phba->cfg_multi_ring_support == 2)
  8146. lpfc_extra_ring_setup(phba);
  8147. return 0;
  8148. }
  8149. /**
  8150. * lpfc_sli_queue_setup - Queue initialization function
  8151. * @phba: Pointer to HBA context object.
  8152. *
  8153. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  8154. * ring. This function also initializes ring indices of each ring.
  8155. * This function is called during the initialization of the SLI
  8156. * interface of an HBA.
  8157. * This function is called with no lock held and always returns
  8158. * 1.
  8159. **/
  8160. int
  8161. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  8162. {
  8163. struct lpfc_sli *psli;
  8164. struct lpfc_sli_ring *pring;
  8165. int i;
  8166. psli = &phba->sli;
  8167. spin_lock_irq(&phba->hbalock);
  8168. INIT_LIST_HEAD(&psli->mboxq);
  8169. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  8170. /* Initialize list headers for txq and txcmplq as double linked lists */
  8171. for (i = 0; i < psli->num_rings; i++) {
  8172. pring = &psli->ring[i];
  8173. pring->ringno = i;
  8174. pring->sli.sli3.next_cmdidx = 0;
  8175. pring->sli.sli3.local_getidx = 0;
  8176. pring->sli.sli3.cmdidx = 0;
  8177. INIT_LIST_HEAD(&pring->txq);
  8178. INIT_LIST_HEAD(&pring->txcmplq);
  8179. INIT_LIST_HEAD(&pring->iocb_continueq);
  8180. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  8181. INIT_LIST_HEAD(&pring->postbufq);
  8182. spin_lock_init(&pring->ring_lock);
  8183. }
  8184. spin_unlock_irq(&phba->hbalock);
  8185. return 1;
  8186. }
  8187. /**
  8188. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  8189. * @phba: Pointer to HBA context object.
  8190. *
  8191. * This routine flushes the mailbox command subsystem. It will unconditionally
  8192. * flush all the mailbox commands in the three possible stages in the mailbox
  8193. * command sub-system: pending mailbox command queue; the outstanding mailbox
  8194. * command; and completed mailbox command queue. It is caller's responsibility
  8195. * to make sure that the driver is in the proper state to flush the mailbox
  8196. * command sub-system. Namely, the posting of mailbox commands into the
  8197. * pending mailbox command queue from the various clients must be stopped;
  8198. * either the HBA is in a state that it will never works on the outstanding
  8199. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  8200. * mailbox command has been completed.
  8201. **/
  8202. static void
  8203. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  8204. {
  8205. LIST_HEAD(completions);
  8206. struct lpfc_sli *psli = &phba->sli;
  8207. LPFC_MBOXQ_t *pmb;
  8208. unsigned long iflag;
  8209. /* Flush all the mailbox commands in the mbox system */
  8210. spin_lock_irqsave(&phba->hbalock, iflag);
  8211. /* The pending mailbox command queue */
  8212. list_splice_init(&phba->sli.mboxq, &completions);
  8213. /* The outstanding active mailbox command */
  8214. if (psli->mbox_active) {
  8215. list_add_tail(&psli->mbox_active->list, &completions);
  8216. psli->mbox_active = NULL;
  8217. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8218. }
  8219. /* The completed mailbox command queue */
  8220. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  8221. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8222. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  8223. while (!list_empty(&completions)) {
  8224. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  8225. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8226. if (pmb->mbox_cmpl)
  8227. pmb->mbox_cmpl(phba, pmb);
  8228. }
  8229. }
  8230. /**
  8231. * lpfc_sli_host_down - Vport cleanup function
  8232. * @vport: Pointer to virtual port object.
  8233. *
  8234. * lpfc_sli_host_down is called to clean up the resources
  8235. * associated with a vport before destroying virtual
  8236. * port data structures.
  8237. * This function does following operations:
  8238. * - Free discovery resources associated with this virtual
  8239. * port.
  8240. * - Free iocbs associated with this virtual port in
  8241. * the txq.
  8242. * - Send abort for all iocb commands associated with this
  8243. * vport in txcmplq.
  8244. *
  8245. * This function is called with no lock held and always returns 1.
  8246. **/
  8247. int
  8248. lpfc_sli_host_down(struct lpfc_vport *vport)
  8249. {
  8250. LIST_HEAD(completions);
  8251. struct lpfc_hba *phba = vport->phba;
  8252. struct lpfc_sli *psli = &phba->sli;
  8253. struct lpfc_sli_ring *pring;
  8254. struct lpfc_iocbq *iocb, *next_iocb;
  8255. int i;
  8256. unsigned long flags = 0;
  8257. uint16_t prev_pring_flag;
  8258. lpfc_cleanup_discovery_resources(vport);
  8259. spin_lock_irqsave(&phba->hbalock, flags);
  8260. for (i = 0; i < psli->num_rings; i++) {
  8261. pring = &psli->ring[i];
  8262. prev_pring_flag = pring->flag;
  8263. /* Only slow rings */
  8264. if (pring->ringno == LPFC_ELS_RING) {
  8265. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8266. /* Set the lpfc data pending flag */
  8267. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8268. }
  8269. /*
  8270. * Error everything on the txq since these iocbs have not been
  8271. * given to the FW yet.
  8272. */
  8273. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  8274. if (iocb->vport != vport)
  8275. continue;
  8276. list_move_tail(&iocb->list, &completions);
  8277. }
  8278. /* Next issue ABTS for everything on the txcmplq */
  8279. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  8280. list) {
  8281. if (iocb->vport != vport)
  8282. continue;
  8283. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  8284. }
  8285. pring->flag = prev_pring_flag;
  8286. }
  8287. spin_unlock_irqrestore(&phba->hbalock, flags);
  8288. /* Cancel all the IOCBs from the completions list */
  8289. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8290. IOERR_SLI_DOWN);
  8291. return 1;
  8292. }
  8293. /**
  8294. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  8295. * @phba: Pointer to HBA context object.
  8296. *
  8297. * This function cleans up all iocb, buffers, mailbox commands
  8298. * while shutting down the HBA. This function is called with no
  8299. * lock held and always returns 1.
  8300. * This function does the following to cleanup driver resources:
  8301. * - Free discovery resources for each virtual port
  8302. * - Cleanup any pending fabric iocbs
  8303. * - Iterate through the iocb txq and free each entry
  8304. * in the list.
  8305. * - Free up any buffer posted to the HBA
  8306. * - Free mailbox commands in the mailbox queue.
  8307. **/
  8308. int
  8309. lpfc_sli_hba_down(struct lpfc_hba *phba)
  8310. {
  8311. LIST_HEAD(completions);
  8312. struct lpfc_sli *psli = &phba->sli;
  8313. struct lpfc_sli_ring *pring;
  8314. struct lpfc_dmabuf *buf_ptr;
  8315. unsigned long flags = 0;
  8316. int i;
  8317. /* Shutdown the mailbox command sub-system */
  8318. lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
  8319. lpfc_hba_down_prep(phba);
  8320. lpfc_fabric_abort_hba(phba);
  8321. spin_lock_irqsave(&phba->hbalock, flags);
  8322. for (i = 0; i < psli->num_rings; i++) {
  8323. pring = &psli->ring[i];
  8324. /* Only slow rings */
  8325. if (pring->ringno == LPFC_ELS_RING) {
  8326. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8327. /* Set the lpfc data pending flag */
  8328. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8329. }
  8330. /*
  8331. * Error everything on the txq since these iocbs have not been
  8332. * given to the FW yet.
  8333. */
  8334. list_splice_init(&pring->txq, &completions);
  8335. }
  8336. spin_unlock_irqrestore(&phba->hbalock, flags);
  8337. /* Cancel all the IOCBs from the completions list */
  8338. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8339. IOERR_SLI_DOWN);
  8340. spin_lock_irqsave(&phba->hbalock, flags);
  8341. list_splice_init(&phba->elsbuf, &completions);
  8342. phba->elsbuf_cnt = 0;
  8343. phba->elsbuf_prev_cnt = 0;
  8344. spin_unlock_irqrestore(&phba->hbalock, flags);
  8345. while (!list_empty(&completions)) {
  8346. list_remove_head(&completions, buf_ptr,
  8347. struct lpfc_dmabuf, list);
  8348. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8349. kfree(buf_ptr);
  8350. }
  8351. /* Return any active mbox cmds */
  8352. del_timer_sync(&psli->mbox_tmo);
  8353. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8354. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8355. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8356. return 1;
  8357. }
  8358. /**
  8359. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8360. * @srcp: Source memory pointer.
  8361. * @destp: Destination memory pointer.
  8362. * @cnt: Number of words required to be copied.
  8363. *
  8364. * This function is used for copying data between driver memory
  8365. * and the SLI memory. This function also changes the endianness
  8366. * of each word if native endianness is different from SLI
  8367. * endianness. This function can be called with or without
  8368. * lock.
  8369. **/
  8370. void
  8371. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8372. {
  8373. uint32_t *src = srcp;
  8374. uint32_t *dest = destp;
  8375. uint32_t ldata;
  8376. int i;
  8377. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8378. ldata = *src;
  8379. ldata = le32_to_cpu(ldata);
  8380. *dest = ldata;
  8381. src++;
  8382. dest++;
  8383. }
  8384. }
  8385. /**
  8386. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8387. * @srcp: Source memory pointer.
  8388. * @destp: Destination memory pointer.
  8389. * @cnt: Number of words required to be copied.
  8390. *
  8391. * This function is used for copying data between a data structure
  8392. * with big endian representation to local endianness.
  8393. * This function can be called with or without lock.
  8394. **/
  8395. void
  8396. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8397. {
  8398. uint32_t *src = srcp;
  8399. uint32_t *dest = destp;
  8400. uint32_t ldata;
  8401. int i;
  8402. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8403. ldata = *src;
  8404. ldata = be32_to_cpu(ldata);
  8405. *dest = ldata;
  8406. src++;
  8407. dest++;
  8408. }
  8409. }
  8410. /**
  8411. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8412. * @phba: Pointer to HBA context object.
  8413. * @pring: Pointer to driver SLI ring object.
  8414. * @mp: Pointer to driver buffer object.
  8415. *
  8416. * This function is called with no lock held.
  8417. * It always return zero after adding the buffer to the postbufq
  8418. * buffer list.
  8419. **/
  8420. int
  8421. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8422. struct lpfc_dmabuf *mp)
  8423. {
  8424. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8425. later */
  8426. spin_lock_irq(&phba->hbalock);
  8427. list_add_tail(&mp->list, &pring->postbufq);
  8428. pring->postbufq_cnt++;
  8429. spin_unlock_irq(&phba->hbalock);
  8430. return 0;
  8431. }
  8432. /**
  8433. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8434. * @phba: Pointer to HBA context object.
  8435. *
  8436. * When HBQ is enabled, buffers are searched based on tags. This function
  8437. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8438. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8439. * does not conflict with tags of buffer posted for unsolicited events.
  8440. * The function returns the allocated tag. The function is called with
  8441. * no locks held.
  8442. **/
  8443. uint32_t
  8444. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8445. {
  8446. spin_lock_irq(&phba->hbalock);
  8447. phba->buffer_tag_count++;
  8448. /*
  8449. * Always set the QUE_BUFTAG_BIT to distiguish between
  8450. * a tag assigned by HBQ.
  8451. */
  8452. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8453. spin_unlock_irq(&phba->hbalock);
  8454. return phba->buffer_tag_count;
  8455. }
  8456. /**
  8457. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8458. * @phba: Pointer to HBA context object.
  8459. * @pring: Pointer to driver SLI ring object.
  8460. * @tag: Buffer tag.
  8461. *
  8462. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8463. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8464. * iocb is posted to the response ring with the tag of the buffer.
  8465. * This function searches the pring->postbufq list using the tag
  8466. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8467. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8468. * buffer is returned to the caller else NULL is returned.
  8469. * This function is called with no lock held.
  8470. **/
  8471. struct lpfc_dmabuf *
  8472. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8473. uint32_t tag)
  8474. {
  8475. struct lpfc_dmabuf *mp, *next_mp;
  8476. struct list_head *slp = &pring->postbufq;
  8477. /* Search postbufq, from the beginning, looking for a match on tag */
  8478. spin_lock_irq(&phba->hbalock);
  8479. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8480. if (mp->buffer_tag == tag) {
  8481. list_del_init(&mp->list);
  8482. pring->postbufq_cnt--;
  8483. spin_unlock_irq(&phba->hbalock);
  8484. return mp;
  8485. }
  8486. }
  8487. spin_unlock_irq(&phba->hbalock);
  8488. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8489. "0402 Cannot find virtual addr for buffer tag on "
  8490. "ring %d Data x%lx x%p x%p x%x\n",
  8491. pring->ringno, (unsigned long) tag,
  8492. slp->next, slp->prev, pring->postbufq_cnt);
  8493. return NULL;
  8494. }
  8495. /**
  8496. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8497. * @phba: Pointer to HBA context object.
  8498. * @pring: Pointer to driver SLI ring object.
  8499. * @phys: DMA address of the buffer.
  8500. *
  8501. * This function searches the buffer list using the dma_address
  8502. * of unsolicited event to find the driver's lpfc_dmabuf object
  8503. * corresponding to the dma_address. The function returns the
  8504. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8505. * This function is called by the ct and els unsolicited event
  8506. * handlers to get the buffer associated with the unsolicited
  8507. * event.
  8508. *
  8509. * This function is called with no lock held.
  8510. **/
  8511. struct lpfc_dmabuf *
  8512. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8513. dma_addr_t phys)
  8514. {
  8515. struct lpfc_dmabuf *mp, *next_mp;
  8516. struct list_head *slp = &pring->postbufq;
  8517. /* Search postbufq, from the beginning, looking for a match on phys */
  8518. spin_lock_irq(&phba->hbalock);
  8519. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8520. if (mp->phys == phys) {
  8521. list_del_init(&mp->list);
  8522. pring->postbufq_cnt--;
  8523. spin_unlock_irq(&phba->hbalock);
  8524. return mp;
  8525. }
  8526. }
  8527. spin_unlock_irq(&phba->hbalock);
  8528. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8529. "0410 Cannot find virtual addr for mapped buf on "
  8530. "ring %d Data x%llx x%p x%p x%x\n",
  8531. pring->ringno, (unsigned long long)phys,
  8532. slp->next, slp->prev, pring->postbufq_cnt);
  8533. return NULL;
  8534. }
  8535. /**
  8536. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8537. * @phba: Pointer to HBA context object.
  8538. * @cmdiocb: Pointer to driver command iocb object.
  8539. * @rspiocb: Pointer to driver response iocb object.
  8540. *
  8541. * This function is the completion handler for the abort iocbs for
  8542. * ELS commands. This function is called from the ELS ring event
  8543. * handler with no lock held. This function frees memory resources
  8544. * associated with the abort iocb.
  8545. **/
  8546. static void
  8547. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8548. struct lpfc_iocbq *rspiocb)
  8549. {
  8550. IOCB_t *irsp = &rspiocb->iocb;
  8551. uint16_t abort_iotag, abort_context;
  8552. struct lpfc_iocbq *abort_iocb = NULL;
  8553. if (irsp->ulpStatus) {
  8554. /*
  8555. * Assume that the port already completed and returned, or
  8556. * will return the iocb. Just Log the message.
  8557. */
  8558. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8559. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8560. spin_lock_irq(&phba->hbalock);
  8561. if (phba->sli_rev < LPFC_SLI_REV4) {
  8562. if (abort_iotag != 0 &&
  8563. abort_iotag <= phba->sli.last_iotag)
  8564. abort_iocb =
  8565. phba->sli.iocbq_lookup[abort_iotag];
  8566. } else
  8567. /* For sli4 the abort_tag is the XRI,
  8568. * so the abort routine puts the iotag of the iocb
  8569. * being aborted in the context field of the abort
  8570. * IOCB.
  8571. */
  8572. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8573. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8574. "0327 Cannot abort els iocb %p "
  8575. "with tag %x context %x, abort status %x, "
  8576. "abort code %x\n",
  8577. abort_iocb, abort_iotag, abort_context,
  8578. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8579. spin_unlock_irq(&phba->hbalock);
  8580. }
  8581. lpfc_sli_release_iocbq(phba, cmdiocb);
  8582. return;
  8583. }
  8584. /**
  8585. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  8586. * @phba: Pointer to HBA context object.
  8587. * @cmdiocb: Pointer to driver command iocb object.
  8588. * @rspiocb: Pointer to driver response iocb object.
  8589. *
  8590. * The function is called from SLI ring event handler with no
  8591. * lock held. This function is the completion handler for ELS commands
  8592. * which are aborted. The function frees memory resources used for
  8593. * the aborted ELS commands.
  8594. **/
  8595. static void
  8596. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8597. struct lpfc_iocbq *rspiocb)
  8598. {
  8599. IOCB_t *irsp = &rspiocb->iocb;
  8600. /* ELS cmd tag <ulpIoTag> completes */
  8601. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8602. "0139 Ignoring ELS cmd tag x%x completion Data: "
  8603. "x%x x%x x%x\n",
  8604. irsp->ulpIoTag, irsp->ulpStatus,
  8605. irsp->un.ulpWord[4], irsp->ulpTimeout);
  8606. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  8607. lpfc_ct_free_iocb(phba, cmdiocb);
  8608. else
  8609. lpfc_els_free_iocb(phba, cmdiocb);
  8610. return;
  8611. }
  8612. /**
  8613. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  8614. * @phba: Pointer to HBA context object.
  8615. * @pring: Pointer to driver SLI ring object.
  8616. * @cmdiocb: Pointer to driver command iocb object.
  8617. *
  8618. * This function issues an abort iocb for the provided command iocb down to
  8619. * the port. Other than the case the outstanding command iocb is an abort
  8620. * request, this function issues abort out unconditionally. This function is
  8621. * called with hbalock held. The function returns 0 when it fails due to
  8622. * memory allocation failure or when the command iocb is an abort request.
  8623. **/
  8624. static int
  8625. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8626. struct lpfc_iocbq *cmdiocb)
  8627. {
  8628. struct lpfc_vport *vport = cmdiocb->vport;
  8629. struct lpfc_iocbq *abtsiocbp;
  8630. IOCB_t *icmd = NULL;
  8631. IOCB_t *iabt = NULL;
  8632. int retval;
  8633. unsigned long iflags;
  8634. /*
  8635. * There are certain command types we don't want to abort. And we
  8636. * don't want to abort commands that are already in the process of
  8637. * being aborted.
  8638. */
  8639. icmd = &cmdiocb->iocb;
  8640. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8641. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8642. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8643. return 0;
  8644. /* issue ABTS for this IOCB based on iotag */
  8645. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  8646. if (abtsiocbp == NULL)
  8647. return 0;
  8648. /* This signals the response to set the correct status
  8649. * before calling the completion handler
  8650. */
  8651. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  8652. iabt = &abtsiocbp->iocb;
  8653. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  8654. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  8655. if (phba->sli_rev == LPFC_SLI_REV4) {
  8656. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  8657. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  8658. }
  8659. else
  8660. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  8661. iabt->ulpLe = 1;
  8662. iabt->ulpClass = icmd->ulpClass;
  8663. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8664. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  8665. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  8666. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  8667. if (phba->link_state >= LPFC_LINK_UP)
  8668. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  8669. else
  8670. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  8671. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  8672. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  8673. "0339 Abort xri x%x, original iotag x%x, "
  8674. "abort cmd iotag x%x\n",
  8675. iabt->un.acxri.abortIoTag,
  8676. iabt->un.acxri.abortContextTag,
  8677. abtsiocbp->iotag);
  8678. if (phba->sli_rev == LPFC_SLI_REV4) {
  8679. /* Note: both hbalock and ring_lock need to be set here */
  8680. spin_lock_irqsave(&pring->ring_lock, iflags);
  8681. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  8682. abtsiocbp, 0);
  8683. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  8684. } else {
  8685. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  8686. abtsiocbp, 0);
  8687. }
  8688. if (retval)
  8689. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  8690. /*
  8691. * Caller to this routine should check for IOCB_ERROR
  8692. * and handle it properly. This routine no longer removes
  8693. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8694. */
  8695. return retval;
  8696. }
  8697. /**
  8698. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  8699. * @phba: Pointer to HBA context object.
  8700. * @pring: Pointer to driver SLI ring object.
  8701. * @cmdiocb: Pointer to driver command iocb object.
  8702. *
  8703. * This function issues an abort iocb for the provided command iocb. In case
  8704. * of unloading, the abort iocb will not be issued to commands on the ELS
  8705. * ring. Instead, the callback function shall be changed to those commands
  8706. * so that nothing happens when them finishes. This function is called with
  8707. * hbalock held. The function returns 0 when the command iocb is an abort
  8708. * request.
  8709. **/
  8710. int
  8711. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8712. struct lpfc_iocbq *cmdiocb)
  8713. {
  8714. struct lpfc_vport *vport = cmdiocb->vport;
  8715. int retval = IOCB_ERROR;
  8716. IOCB_t *icmd = NULL;
  8717. /*
  8718. * There are certain command types we don't want to abort. And we
  8719. * don't want to abort commands that are already in the process of
  8720. * being aborted.
  8721. */
  8722. icmd = &cmdiocb->iocb;
  8723. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8724. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8725. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8726. return 0;
  8727. /*
  8728. * If we're unloading, don't abort iocb on the ELS ring, but change
  8729. * the callback so that nothing happens when it finishes.
  8730. */
  8731. if ((vport->load_flag & FC_UNLOADING) &&
  8732. (pring->ringno == LPFC_ELS_RING)) {
  8733. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  8734. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  8735. else
  8736. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  8737. goto abort_iotag_exit;
  8738. }
  8739. /* Now, we try to issue the abort to the cmdiocb out */
  8740. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  8741. abort_iotag_exit:
  8742. /*
  8743. * Caller to this routine should check for IOCB_ERROR
  8744. * and handle it properly. This routine no longer removes
  8745. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8746. */
  8747. return retval;
  8748. }
  8749. /**
  8750. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  8751. * @phba: Pointer to HBA context object.
  8752. * @pring: Pointer to driver SLI ring object.
  8753. *
  8754. * This function aborts all iocbs in the given ring and frees all the iocb
  8755. * objects in txq. This function issues abort iocbs unconditionally for all
  8756. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  8757. * to complete before the return of this function. The caller is not required
  8758. * to hold any locks.
  8759. **/
  8760. static void
  8761. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  8762. {
  8763. LIST_HEAD(completions);
  8764. struct lpfc_iocbq *iocb, *next_iocb;
  8765. if (pring->ringno == LPFC_ELS_RING)
  8766. lpfc_fabric_abort_hba(phba);
  8767. spin_lock_irq(&phba->hbalock);
  8768. /* Take off all the iocbs on txq for cancelling */
  8769. list_splice_init(&pring->txq, &completions);
  8770. pring->txq_cnt = 0;
  8771. /* Next issue ABTS for everything on the txcmplq */
  8772. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  8773. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  8774. spin_unlock_irq(&phba->hbalock);
  8775. /* Cancel all the IOCBs from the completions list */
  8776. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8777. IOERR_SLI_ABORTED);
  8778. }
  8779. /**
  8780. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  8781. * @phba: pointer to lpfc HBA data structure.
  8782. *
  8783. * This routine will abort all pending and outstanding iocbs to an HBA.
  8784. **/
  8785. void
  8786. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  8787. {
  8788. struct lpfc_sli *psli = &phba->sli;
  8789. struct lpfc_sli_ring *pring;
  8790. int i;
  8791. for (i = 0; i < psli->num_rings; i++) {
  8792. pring = &psli->ring[i];
  8793. lpfc_sli_iocb_ring_abort(phba, pring);
  8794. }
  8795. }
  8796. /**
  8797. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  8798. * @iocbq: Pointer to driver iocb object.
  8799. * @vport: Pointer to driver virtual port object.
  8800. * @tgt_id: SCSI ID of the target.
  8801. * @lun_id: LUN ID of the scsi device.
  8802. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  8803. *
  8804. * This function acts as an iocb filter for functions which abort or count
  8805. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  8806. * 0 if the filtering criteria is met for the given iocb and will return
  8807. * 1 if the filtering criteria is not met.
  8808. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  8809. * given iocb is for the SCSI device specified by vport, tgt_id and
  8810. * lun_id parameter.
  8811. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  8812. * given iocb is for the SCSI target specified by vport and tgt_id
  8813. * parameters.
  8814. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  8815. * given iocb is for the SCSI host associated with the given vport.
  8816. * This function is called with no locks held.
  8817. **/
  8818. static int
  8819. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  8820. uint16_t tgt_id, uint64_t lun_id,
  8821. lpfc_ctx_cmd ctx_cmd)
  8822. {
  8823. struct lpfc_scsi_buf *lpfc_cmd;
  8824. int rc = 1;
  8825. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  8826. return rc;
  8827. if (iocbq->vport != vport)
  8828. return rc;
  8829. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  8830. if (lpfc_cmd->pCmd == NULL)
  8831. return rc;
  8832. switch (ctx_cmd) {
  8833. case LPFC_CTX_LUN:
  8834. if ((lpfc_cmd->rdata->pnode) &&
  8835. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  8836. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  8837. rc = 0;
  8838. break;
  8839. case LPFC_CTX_TGT:
  8840. if ((lpfc_cmd->rdata->pnode) &&
  8841. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  8842. rc = 0;
  8843. break;
  8844. case LPFC_CTX_HOST:
  8845. rc = 0;
  8846. break;
  8847. default:
  8848. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  8849. __func__, ctx_cmd);
  8850. break;
  8851. }
  8852. return rc;
  8853. }
  8854. /**
  8855. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  8856. * @vport: Pointer to virtual port.
  8857. * @tgt_id: SCSI ID of the target.
  8858. * @lun_id: LUN ID of the scsi device.
  8859. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8860. *
  8861. * This function returns number of FCP commands pending for the vport.
  8862. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  8863. * commands pending on the vport associated with SCSI device specified
  8864. * by tgt_id and lun_id parameters.
  8865. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  8866. * commands pending on the vport associated with SCSI target specified
  8867. * by tgt_id parameter.
  8868. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  8869. * commands pending on the vport.
  8870. * This function returns the number of iocbs which satisfy the filter.
  8871. * This function is called without any lock held.
  8872. **/
  8873. int
  8874. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  8875. lpfc_ctx_cmd ctx_cmd)
  8876. {
  8877. struct lpfc_hba *phba = vport->phba;
  8878. struct lpfc_iocbq *iocbq;
  8879. int sum, i;
  8880. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  8881. iocbq = phba->sli.iocbq_lookup[i];
  8882. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  8883. ctx_cmd) == 0)
  8884. sum++;
  8885. }
  8886. return sum;
  8887. }
  8888. /**
  8889. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  8890. * @phba: Pointer to HBA context object
  8891. * @cmdiocb: Pointer to command iocb object.
  8892. * @rspiocb: Pointer to response iocb object.
  8893. *
  8894. * This function is called when an aborted FCP iocb completes. This
  8895. * function is called by the ring event handler with no lock held.
  8896. * This function frees the iocb.
  8897. **/
  8898. void
  8899. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8900. struct lpfc_iocbq *rspiocb)
  8901. {
  8902. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8903. "3096 ABORT_XRI_CN completing on xri x%x "
  8904. "original iotag x%x, abort cmd iotag x%x "
  8905. "status 0x%x, reason 0x%x\n",
  8906. cmdiocb->iocb.un.acxri.abortContextTag,
  8907. cmdiocb->iocb.un.acxri.abortIoTag,
  8908. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  8909. rspiocb->iocb.un.ulpWord[4]);
  8910. lpfc_sli_release_iocbq(phba, cmdiocb);
  8911. return;
  8912. }
  8913. /**
  8914. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  8915. * @vport: Pointer to virtual port.
  8916. * @pring: Pointer to driver SLI ring object.
  8917. * @tgt_id: SCSI ID of the target.
  8918. * @lun_id: LUN ID of the scsi device.
  8919. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8920. *
  8921. * This function sends an abort command for every SCSI command
  8922. * associated with the given virtual port pending on the ring
  8923. * filtered by lpfc_sli_validate_fcp_iocb function.
  8924. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  8925. * FCP iocbs associated with lun specified by tgt_id and lun_id
  8926. * parameters
  8927. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  8928. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  8929. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  8930. * FCP iocbs associated with virtual port.
  8931. * This function returns number of iocbs it failed to abort.
  8932. * This function is called with no locks held.
  8933. **/
  8934. int
  8935. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  8936. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  8937. {
  8938. struct lpfc_hba *phba = vport->phba;
  8939. struct lpfc_iocbq *iocbq;
  8940. struct lpfc_iocbq *abtsiocb;
  8941. IOCB_t *cmd = NULL;
  8942. int errcnt = 0, ret_val = 0;
  8943. int i;
  8944. for (i = 1; i <= phba->sli.last_iotag; i++) {
  8945. iocbq = phba->sli.iocbq_lookup[i];
  8946. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  8947. abort_cmd) != 0)
  8948. continue;
  8949. /* issue ABTS for this IOCB based on iotag */
  8950. abtsiocb = lpfc_sli_get_iocbq(phba);
  8951. if (abtsiocb == NULL) {
  8952. errcnt++;
  8953. continue;
  8954. }
  8955. cmd = &iocbq->iocb;
  8956. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  8957. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  8958. if (phba->sli_rev == LPFC_SLI_REV4)
  8959. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  8960. else
  8961. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  8962. abtsiocb->iocb.ulpLe = 1;
  8963. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  8964. abtsiocb->vport = phba->pport;
  8965. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8966. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  8967. if (iocbq->iocb_flag & LPFC_IO_FCP)
  8968. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  8969. if (lpfc_is_link_up(phba))
  8970. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  8971. else
  8972. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  8973. /* Setup callback routine and issue the command. */
  8974. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  8975. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  8976. abtsiocb, 0);
  8977. if (ret_val == IOCB_ERROR) {
  8978. lpfc_sli_release_iocbq(phba, abtsiocb);
  8979. errcnt++;
  8980. continue;
  8981. }
  8982. }
  8983. return errcnt;
  8984. }
  8985. /**
  8986. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  8987. * @phba: Pointer to HBA context object.
  8988. * @cmdiocbq: Pointer to command iocb.
  8989. * @rspiocbq: Pointer to response iocb.
  8990. *
  8991. * This function is the completion handler for iocbs issued using
  8992. * lpfc_sli_issue_iocb_wait function. This function is called by the
  8993. * ring event handler function without any lock held. This function
  8994. * can be called from both worker thread context and interrupt
  8995. * context. This function also can be called from other thread which
  8996. * cleans up the SLI layer objects.
  8997. * This function copy the contents of the response iocb to the
  8998. * response iocb memory object provided by the caller of
  8999. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  9000. * sleeps for the iocb completion.
  9001. **/
  9002. static void
  9003. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  9004. struct lpfc_iocbq *cmdiocbq,
  9005. struct lpfc_iocbq *rspiocbq)
  9006. {
  9007. wait_queue_head_t *pdone_q;
  9008. unsigned long iflags;
  9009. struct lpfc_scsi_buf *lpfc_cmd;
  9010. spin_lock_irqsave(&phba->hbalock, iflags);
  9011. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  9012. if (cmdiocbq->context2 && rspiocbq)
  9013. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  9014. &rspiocbq->iocb, sizeof(IOCB_t));
  9015. /* Set the exchange busy flag for task management commands */
  9016. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  9017. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  9018. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  9019. cur_iocbq);
  9020. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  9021. }
  9022. pdone_q = cmdiocbq->context_un.wait_queue;
  9023. if (pdone_q)
  9024. wake_up(pdone_q);
  9025. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9026. return;
  9027. }
  9028. /**
  9029. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  9030. * @phba: Pointer to HBA context object..
  9031. * @piocbq: Pointer to command iocb.
  9032. * @flag: Flag to test.
  9033. *
  9034. * This routine grabs the hbalock and then test the iocb_flag to
  9035. * see if the passed in flag is set.
  9036. * Returns:
  9037. * 1 if flag is set.
  9038. * 0 if flag is not set.
  9039. **/
  9040. static int
  9041. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  9042. struct lpfc_iocbq *piocbq, uint32_t flag)
  9043. {
  9044. unsigned long iflags;
  9045. int ret;
  9046. spin_lock_irqsave(&phba->hbalock, iflags);
  9047. ret = piocbq->iocb_flag & flag;
  9048. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9049. return ret;
  9050. }
  9051. /**
  9052. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  9053. * @phba: Pointer to HBA context object..
  9054. * @pring: Pointer to sli ring.
  9055. * @piocb: Pointer to command iocb.
  9056. * @prspiocbq: Pointer to response iocb.
  9057. * @timeout: Timeout in number of seconds.
  9058. *
  9059. * This function issues the iocb to firmware and waits for the
  9060. * iocb to complete. If the iocb command is not
  9061. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  9062. * Caller should not free the iocb resources if this function
  9063. * returns IOCB_TIMEDOUT.
  9064. * The function waits for the iocb completion using an
  9065. * non-interruptible wait.
  9066. * This function will sleep while waiting for iocb completion.
  9067. * So, this function should not be called from any context which
  9068. * does not allow sleeping. Due to the same reason, this function
  9069. * cannot be called with interrupt disabled.
  9070. * This function assumes that the iocb completions occur while
  9071. * this function sleep. So, this function cannot be called from
  9072. * the thread which process iocb completion for this ring.
  9073. * This function clears the iocb_flag of the iocb object before
  9074. * issuing the iocb and the iocb completion handler sets this
  9075. * flag and wakes this thread when the iocb completes.
  9076. * The contents of the response iocb will be copied to prspiocbq
  9077. * by the completion handler when the command completes.
  9078. * This function returns IOCB_SUCCESS when success.
  9079. * This function is called with no lock held.
  9080. **/
  9081. int
  9082. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  9083. uint32_t ring_number,
  9084. struct lpfc_iocbq *piocb,
  9085. struct lpfc_iocbq *prspiocbq,
  9086. uint32_t timeout)
  9087. {
  9088. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9089. long timeleft, timeout_req = 0;
  9090. int retval = IOCB_SUCCESS;
  9091. uint32_t creg_val;
  9092. struct lpfc_iocbq *iocb;
  9093. int txq_cnt = 0;
  9094. int txcmplq_cnt = 0;
  9095. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9096. /*
  9097. * If the caller has provided a response iocbq buffer, then context2
  9098. * is NULL or its an error.
  9099. */
  9100. if (prspiocbq) {
  9101. if (piocb->context2)
  9102. return IOCB_ERROR;
  9103. piocb->context2 = prspiocbq;
  9104. }
  9105. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  9106. piocb->context_un.wait_queue = &done_q;
  9107. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  9108. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9109. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9110. return IOCB_ERROR;
  9111. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  9112. writel(creg_val, phba->HCregaddr);
  9113. readl(phba->HCregaddr); /* flush */
  9114. }
  9115. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  9116. SLI_IOCB_RET_IOCB);
  9117. if (retval == IOCB_SUCCESS) {
  9118. timeout_req = msecs_to_jiffies(timeout * 1000);
  9119. timeleft = wait_event_timeout(done_q,
  9120. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  9121. timeout_req);
  9122. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  9123. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9124. "0331 IOCB wake signaled\n");
  9125. } else if (timeleft == 0) {
  9126. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9127. "0338 IOCB wait timeout error - no "
  9128. "wake response Data x%x\n", timeout);
  9129. retval = IOCB_TIMEDOUT;
  9130. } else {
  9131. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9132. "0330 IOCB wake NOT set, "
  9133. "Data x%x x%lx\n",
  9134. timeout, (timeleft / jiffies));
  9135. retval = IOCB_TIMEDOUT;
  9136. }
  9137. } else if (retval == IOCB_BUSY) {
  9138. if (phba->cfg_log_verbose & LOG_SLI) {
  9139. list_for_each_entry(iocb, &pring->txq, list) {
  9140. txq_cnt++;
  9141. }
  9142. list_for_each_entry(iocb, &pring->txcmplq, list) {
  9143. txcmplq_cnt++;
  9144. }
  9145. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9146. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  9147. phba->iocb_cnt, txq_cnt, txcmplq_cnt);
  9148. }
  9149. return retval;
  9150. } else {
  9151. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9152. "0332 IOCB wait issue failed, Data x%x\n",
  9153. retval);
  9154. retval = IOCB_ERROR;
  9155. }
  9156. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9157. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9158. return IOCB_ERROR;
  9159. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  9160. writel(creg_val, phba->HCregaddr);
  9161. readl(phba->HCregaddr); /* flush */
  9162. }
  9163. if (prspiocbq)
  9164. piocb->context2 = NULL;
  9165. piocb->context_un.wait_queue = NULL;
  9166. piocb->iocb_cmpl = NULL;
  9167. return retval;
  9168. }
  9169. /**
  9170. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  9171. * @phba: Pointer to HBA context object.
  9172. * @pmboxq: Pointer to driver mailbox object.
  9173. * @timeout: Timeout in number of seconds.
  9174. *
  9175. * This function issues the mailbox to firmware and waits for the
  9176. * mailbox command to complete. If the mailbox command is not
  9177. * completed within timeout seconds, it returns MBX_TIMEOUT.
  9178. * The function waits for the mailbox completion using an
  9179. * interruptible wait. If the thread is woken up due to a
  9180. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  9181. * should not free the mailbox resources, if this function returns
  9182. * MBX_TIMEOUT.
  9183. * This function will sleep while waiting for mailbox completion.
  9184. * So, this function should not be called from any context which
  9185. * does not allow sleeping. Due to the same reason, this function
  9186. * cannot be called with interrupt disabled.
  9187. * This function assumes that the mailbox completion occurs while
  9188. * this function sleep. So, this function cannot be called from
  9189. * the worker thread which processes mailbox completion.
  9190. * This function is called in the context of HBA management
  9191. * applications.
  9192. * This function returns MBX_SUCCESS when successful.
  9193. * This function is called with no lock held.
  9194. **/
  9195. int
  9196. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  9197. uint32_t timeout)
  9198. {
  9199. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9200. int retval;
  9201. unsigned long flag;
  9202. /* The caller must leave context1 empty. */
  9203. if (pmboxq->context1)
  9204. return MBX_NOT_FINISHED;
  9205. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  9206. /* setup wake call as IOCB callback */
  9207. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  9208. /* setup context field to pass wait_queue pointer to wake function */
  9209. pmboxq->context1 = &done_q;
  9210. /* now issue the command */
  9211. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  9212. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  9213. wait_event_interruptible_timeout(done_q,
  9214. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  9215. msecs_to_jiffies(timeout * 1000));
  9216. spin_lock_irqsave(&phba->hbalock, flag);
  9217. pmboxq->context1 = NULL;
  9218. /*
  9219. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  9220. * else do not free the resources.
  9221. */
  9222. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  9223. retval = MBX_SUCCESS;
  9224. lpfc_sli4_swap_str(phba, pmboxq);
  9225. } else {
  9226. retval = MBX_TIMEOUT;
  9227. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9228. }
  9229. spin_unlock_irqrestore(&phba->hbalock, flag);
  9230. }
  9231. return retval;
  9232. }
  9233. /**
  9234. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  9235. * @phba: Pointer to HBA context.
  9236. *
  9237. * This function is called to shutdown the driver's mailbox sub-system.
  9238. * It first marks the mailbox sub-system is in a block state to prevent
  9239. * the asynchronous mailbox command from issued off the pending mailbox
  9240. * command queue. If the mailbox command sub-system shutdown is due to
  9241. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  9242. * the mailbox sub-system flush routine to forcefully bring down the
  9243. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  9244. * as with offline or HBA function reset), this routine will wait for the
  9245. * outstanding mailbox command to complete before invoking the mailbox
  9246. * sub-system flush routine to gracefully bring down mailbox sub-system.
  9247. **/
  9248. void
  9249. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
  9250. {
  9251. struct lpfc_sli *psli = &phba->sli;
  9252. unsigned long timeout;
  9253. if (mbx_action == LPFC_MBX_NO_WAIT) {
  9254. /* delay 100ms for port state */
  9255. msleep(100);
  9256. lpfc_sli_mbox_sys_flush(phba);
  9257. return;
  9258. }
  9259. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  9260. spin_lock_irq(&phba->hbalock);
  9261. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  9262. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  9263. /* Determine how long we might wait for the active mailbox
  9264. * command to be gracefully completed by firmware.
  9265. */
  9266. if (phba->sli.mbox_active)
  9267. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  9268. phba->sli.mbox_active) *
  9269. 1000) + jiffies;
  9270. spin_unlock_irq(&phba->hbalock);
  9271. while (phba->sli.mbox_active) {
  9272. /* Check active mailbox complete status every 2ms */
  9273. msleep(2);
  9274. if (time_after(jiffies, timeout))
  9275. /* Timeout, let the mailbox flush routine to
  9276. * forcefully release active mailbox command
  9277. */
  9278. break;
  9279. }
  9280. } else
  9281. spin_unlock_irq(&phba->hbalock);
  9282. lpfc_sli_mbox_sys_flush(phba);
  9283. }
  9284. /**
  9285. * lpfc_sli_eratt_read - read sli-3 error attention events
  9286. * @phba: Pointer to HBA context.
  9287. *
  9288. * This function is called to read the SLI3 device error attention registers
  9289. * for possible error attention events. The caller must hold the hostlock
  9290. * with spin_lock_irq().
  9291. *
  9292. * This function returns 1 when there is Error Attention in the Host Attention
  9293. * Register and returns 0 otherwise.
  9294. **/
  9295. static int
  9296. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  9297. {
  9298. uint32_t ha_copy;
  9299. /* Read chip Host Attention (HA) register */
  9300. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9301. goto unplug_err;
  9302. if (ha_copy & HA_ERATT) {
  9303. /* Read host status register to retrieve error event */
  9304. if (lpfc_sli_read_hs(phba))
  9305. goto unplug_err;
  9306. /* Check if there is a deferred error condition is active */
  9307. if ((HS_FFER1 & phba->work_hs) &&
  9308. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9309. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  9310. phba->hba_flag |= DEFER_ERATT;
  9311. /* Clear all interrupt enable conditions */
  9312. writel(0, phba->HCregaddr);
  9313. readl(phba->HCregaddr);
  9314. }
  9315. /* Set the driver HA work bitmap */
  9316. phba->work_ha |= HA_ERATT;
  9317. /* Indicate polling handles this ERATT */
  9318. phba->hba_flag |= HBA_ERATT_HANDLED;
  9319. return 1;
  9320. }
  9321. return 0;
  9322. unplug_err:
  9323. /* Set the driver HS work bitmap */
  9324. phba->work_hs |= UNPLUG_ERR;
  9325. /* Set the driver HA work bitmap */
  9326. phba->work_ha |= HA_ERATT;
  9327. /* Indicate polling handles this ERATT */
  9328. phba->hba_flag |= HBA_ERATT_HANDLED;
  9329. return 1;
  9330. }
  9331. /**
  9332. * lpfc_sli4_eratt_read - read sli-4 error attention events
  9333. * @phba: Pointer to HBA context.
  9334. *
  9335. * This function is called to read the SLI4 device error attention registers
  9336. * for possible error attention events. The caller must hold the hostlock
  9337. * with spin_lock_irq().
  9338. *
  9339. * This function returns 1 when there is Error Attention in the Host Attention
  9340. * Register and returns 0 otherwise.
  9341. **/
  9342. static int
  9343. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  9344. {
  9345. uint32_t uerr_sta_hi, uerr_sta_lo;
  9346. uint32_t if_type, portsmphr;
  9347. struct lpfc_register portstat_reg;
  9348. /*
  9349. * For now, use the SLI4 device internal unrecoverable error
  9350. * registers for error attention. This can be changed later.
  9351. */
  9352. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9353. switch (if_type) {
  9354. case LPFC_SLI_INTF_IF_TYPE_0:
  9355. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  9356. &uerr_sta_lo) ||
  9357. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  9358. &uerr_sta_hi)) {
  9359. phba->work_hs |= UNPLUG_ERR;
  9360. phba->work_ha |= HA_ERATT;
  9361. phba->hba_flag |= HBA_ERATT_HANDLED;
  9362. return 1;
  9363. }
  9364. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  9365. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  9366. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9367. "1423 HBA Unrecoverable error: "
  9368. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9369. "ue_mask_lo_reg=0x%x, "
  9370. "ue_mask_hi_reg=0x%x\n",
  9371. uerr_sta_lo, uerr_sta_hi,
  9372. phba->sli4_hba.ue_mask_lo,
  9373. phba->sli4_hba.ue_mask_hi);
  9374. phba->work_status[0] = uerr_sta_lo;
  9375. phba->work_status[1] = uerr_sta_hi;
  9376. phba->work_ha |= HA_ERATT;
  9377. phba->hba_flag |= HBA_ERATT_HANDLED;
  9378. return 1;
  9379. }
  9380. break;
  9381. case LPFC_SLI_INTF_IF_TYPE_2:
  9382. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9383. &portstat_reg.word0) ||
  9384. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9385. &portsmphr)){
  9386. phba->work_hs |= UNPLUG_ERR;
  9387. phba->work_ha |= HA_ERATT;
  9388. phba->hba_flag |= HBA_ERATT_HANDLED;
  9389. return 1;
  9390. }
  9391. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9392. phba->work_status[0] =
  9393. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9394. phba->work_status[1] =
  9395. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9396. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9397. "2885 Port Status Event: "
  9398. "port status reg 0x%x, "
  9399. "port smphr reg 0x%x, "
  9400. "error 1=0x%x, error 2=0x%x\n",
  9401. portstat_reg.word0,
  9402. portsmphr,
  9403. phba->work_status[0],
  9404. phba->work_status[1]);
  9405. phba->work_ha |= HA_ERATT;
  9406. phba->hba_flag |= HBA_ERATT_HANDLED;
  9407. return 1;
  9408. }
  9409. break;
  9410. case LPFC_SLI_INTF_IF_TYPE_1:
  9411. default:
  9412. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9413. "2886 HBA Error Attention on unsupported "
  9414. "if type %d.", if_type);
  9415. return 1;
  9416. }
  9417. return 0;
  9418. }
  9419. /**
  9420. * lpfc_sli_check_eratt - check error attention events
  9421. * @phba: Pointer to HBA context.
  9422. *
  9423. * This function is called from timer soft interrupt context to check HBA's
  9424. * error attention register bit for error attention events.
  9425. *
  9426. * This function returns 1 when there is Error Attention in the Host Attention
  9427. * Register and returns 0 otherwise.
  9428. **/
  9429. int
  9430. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9431. {
  9432. uint32_t ha_copy;
  9433. /* If somebody is waiting to handle an eratt, don't process it
  9434. * here. The brdkill function will do this.
  9435. */
  9436. if (phba->link_flag & LS_IGNORE_ERATT)
  9437. return 0;
  9438. /* Check if interrupt handler handles this ERATT */
  9439. spin_lock_irq(&phba->hbalock);
  9440. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  9441. /* Interrupt handler has handled ERATT */
  9442. spin_unlock_irq(&phba->hbalock);
  9443. return 0;
  9444. }
  9445. /*
  9446. * If there is deferred error attention, do not check for error
  9447. * attention
  9448. */
  9449. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9450. spin_unlock_irq(&phba->hbalock);
  9451. return 0;
  9452. }
  9453. /* If PCI channel is offline, don't process it */
  9454. if (unlikely(pci_channel_offline(phba->pcidev))) {
  9455. spin_unlock_irq(&phba->hbalock);
  9456. return 0;
  9457. }
  9458. switch (phba->sli_rev) {
  9459. case LPFC_SLI_REV2:
  9460. case LPFC_SLI_REV3:
  9461. /* Read chip Host Attention (HA) register */
  9462. ha_copy = lpfc_sli_eratt_read(phba);
  9463. break;
  9464. case LPFC_SLI_REV4:
  9465. /* Read device Uncoverable Error (UERR) registers */
  9466. ha_copy = lpfc_sli4_eratt_read(phba);
  9467. break;
  9468. default:
  9469. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9470. "0299 Invalid SLI revision (%d)\n",
  9471. phba->sli_rev);
  9472. ha_copy = 0;
  9473. break;
  9474. }
  9475. spin_unlock_irq(&phba->hbalock);
  9476. return ha_copy;
  9477. }
  9478. /**
  9479. * lpfc_intr_state_check - Check device state for interrupt handling
  9480. * @phba: Pointer to HBA context.
  9481. *
  9482. * This inline routine checks whether a device or its PCI slot is in a state
  9483. * that the interrupt should be handled.
  9484. *
  9485. * This function returns 0 if the device or the PCI slot is in a state that
  9486. * interrupt should be handled, otherwise -EIO.
  9487. */
  9488. static inline int
  9489. lpfc_intr_state_check(struct lpfc_hba *phba)
  9490. {
  9491. /* If the pci channel is offline, ignore all the interrupts */
  9492. if (unlikely(pci_channel_offline(phba->pcidev)))
  9493. return -EIO;
  9494. /* Update device level interrupt statistics */
  9495. phba->sli.slistat.sli_intr++;
  9496. /* Ignore all interrupts during initialization. */
  9497. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  9498. return -EIO;
  9499. return 0;
  9500. }
  9501. /**
  9502. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  9503. * @irq: Interrupt number.
  9504. * @dev_id: The device context pointer.
  9505. *
  9506. * This function is directly called from the PCI layer as an interrupt
  9507. * service routine when device with SLI-3 interface spec is enabled with
  9508. * MSI-X multi-message interrupt mode and there are slow-path events in
  9509. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9510. * interrupt mode, this function is called as part of the device-level
  9511. * interrupt handler. When the PCI slot is in error recovery or the HBA
  9512. * is undergoing initialization, the interrupt handler will not process
  9513. * the interrupt. The link attention and ELS ring attention events are
  9514. * handled by the worker thread. The interrupt handler signals the worker
  9515. * thread and returns for these events. This function is called without
  9516. * any lock held. It gets the hbalock to access and update SLI data
  9517. * structures.
  9518. *
  9519. * This function returns IRQ_HANDLED when interrupt is handled else it
  9520. * returns IRQ_NONE.
  9521. **/
  9522. irqreturn_t
  9523. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  9524. {
  9525. struct lpfc_hba *phba;
  9526. uint32_t ha_copy, hc_copy;
  9527. uint32_t work_ha_copy;
  9528. unsigned long status;
  9529. unsigned long iflag;
  9530. uint32_t control;
  9531. MAILBOX_t *mbox, *pmbox;
  9532. struct lpfc_vport *vport;
  9533. struct lpfc_nodelist *ndlp;
  9534. struct lpfc_dmabuf *mp;
  9535. LPFC_MBOXQ_t *pmb;
  9536. int rc;
  9537. /*
  9538. * Get the driver's phba structure from the dev_id and
  9539. * assume the HBA is not interrupting.
  9540. */
  9541. phba = (struct lpfc_hba *)dev_id;
  9542. if (unlikely(!phba))
  9543. return IRQ_NONE;
  9544. /*
  9545. * Stuff needs to be attented to when this function is invoked as an
  9546. * individual interrupt handler in MSI-X multi-message interrupt mode
  9547. */
  9548. if (phba->intr_type == MSIX) {
  9549. /* Check device state for handling interrupt */
  9550. if (lpfc_intr_state_check(phba))
  9551. return IRQ_NONE;
  9552. /* Need to read HA REG for slow-path events */
  9553. spin_lock_irqsave(&phba->hbalock, iflag);
  9554. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9555. goto unplug_error;
  9556. /* If somebody is waiting to handle an eratt don't process it
  9557. * here. The brdkill function will do this.
  9558. */
  9559. if (phba->link_flag & LS_IGNORE_ERATT)
  9560. ha_copy &= ~HA_ERATT;
  9561. /* Check the need for handling ERATT in interrupt handler */
  9562. if (ha_copy & HA_ERATT) {
  9563. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9564. /* ERATT polling has handled ERATT */
  9565. ha_copy &= ~HA_ERATT;
  9566. else
  9567. /* Indicate interrupt handler handles ERATT */
  9568. phba->hba_flag |= HBA_ERATT_HANDLED;
  9569. }
  9570. /*
  9571. * If there is deferred error attention, do not check for any
  9572. * interrupt.
  9573. */
  9574. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9575. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9576. return IRQ_NONE;
  9577. }
  9578. /* Clear up only attention source related to slow-path */
  9579. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  9580. goto unplug_error;
  9581. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  9582. HC_LAINT_ENA | HC_ERINT_ENA),
  9583. phba->HCregaddr);
  9584. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  9585. phba->HAregaddr);
  9586. writel(hc_copy, phba->HCregaddr);
  9587. readl(phba->HAregaddr); /* flush */
  9588. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9589. } else
  9590. ha_copy = phba->ha_copy;
  9591. work_ha_copy = ha_copy & phba->work_ha_mask;
  9592. if (work_ha_copy) {
  9593. if (work_ha_copy & HA_LATT) {
  9594. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  9595. /*
  9596. * Turn off Link Attention interrupts
  9597. * until CLEAR_LA done
  9598. */
  9599. spin_lock_irqsave(&phba->hbalock, iflag);
  9600. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  9601. if (lpfc_readl(phba->HCregaddr, &control))
  9602. goto unplug_error;
  9603. control &= ~HC_LAINT_ENA;
  9604. writel(control, phba->HCregaddr);
  9605. readl(phba->HCregaddr); /* flush */
  9606. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9607. }
  9608. else
  9609. work_ha_copy &= ~HA_LATT;
  9610. }
  9611. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  9612. /*
  9613. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  9614. * the only slow ring.
  9615. */
  9616. status = (work_ha_copy &
  9617. (HA_RXMASK << (4*LPFC_ELS_RING)));
  9618. status >>= (4*LPFC_ELS_RING);
  9619. if (status & HA_RXMASK) {
  9620. spin_lock_irqsave(&phba->hbalock, iflag);
  9621. if (lpfc_readl(phba->HCregaddr, &control))
  9622. goto unplug_error;
  9623. lpfc_debugfs_slow_ring_trc(phba,
  9624. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  9625. control, status,
  9626. (uint32_t)phba->sli.slistat.sli_intr);
  9627. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  9628. lpfc_debugfs_slow_ring_trc(phba,
  9629. "ISR Disable ring:"
  9630. "pwork:x%x hawork:x%x wait:x%x",
  9631. phba->work_ha, work_ha_copy,
  9632. (uint32_t)((unsigned long)
  9633. &phba->work_waitq));
  9634. control &=
  9635. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  9636. writel(control, phba->HCregaddr);
  9637. readl(phba->HCregaddr); /* flush */
  9638. }
  9639. else {
  9640. lpfc_debugfs_slow_ring_trc(phba,
  9641. "ISR slow ring: pwork:"
  9642. "x%x hawork:x%x wait:x%x",
  9643. phba->work_ha, work_ha_copy,
  9644. (uint32_t)((unsigned long)
  9645. &phba->work_waitq));
  9646. }
  9647. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9648. }
  9649. }
  9650. spin_lock_irqsave(&phba->hbalock, iflag);
  9651. if (work_ha_copy & HA_ERATT) {
  9652. if (lpfc_sli_read_hs(phba))
  9653. goto unplug_error;
  9654. /*
  9655. * Check if there is a deferred error condition
  9656. * is active
  9657. */
  9658. if ((HS_FFER1 & phba->work_hs) &&
  9659. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9660. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  9661. phba->work_hs)) {
  9662. phba->hba_flag |= DEFER_ERATT;
  9663. /* Clear all interrupt enable conditions */
  9664. writel(0, phba->HCregaddr);
  9665. readl(phba->HCregaddr);
  9666. }
  9667. }
  9668. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  9669. pmb = phba->sli.mbox_active;
  9670. pmbox = &pmb->u.mb;
  9671. mbox = phba->mbox;
  9672. vport = pmb->vport;
  9673. /* First check out the status word */
  9674. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  9675. if (pmbox->mbxOwner != OWN_HOST) {
  9676. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9677. /*
  9678. * Stray Mailbox Interrupt, mbxCommand <cmd>
  9679. * mbxStatus <status>
  9680. */
  9681. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9682. LOG_SLI,
  9683. "(%d):0304 Stray Mailbox "
  9684. "Interrupt mbxCommand x%x "
  9685. "mbxStatus x%x\n",
  9686. (vport ? vport->vpi : 0),
  9687. pmbox->mbxCommand,
  9688. pmbox->mbxStatus);
  9689. /* clear mailbox attention bit */
  9690. work_ha_copy &= ~HA_MBATT;
  9691. } else {
  9692. phba->sli.mbox_active = NULL;
  9693. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9694. phba->last_completion_time = jiffies;
  9695. del_timer(&phba->sli.mbox_tmo);
  9696. if (pmb->mbox_cmpl) {
  9697. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  9698. MAILBOX_CMD_SIZE);
  9699. if (pmb->out_ext_byte_len &&
  9700. pmb->context2)
  9701. lpfc_sli_pcimem_bcopy(
  9702. phba->mbox_ext,
  9703. pmb->context2,
  9704. pmb->out_ext_byte_len);
  9705. }
  9706. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  9707. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  9708. lpfc_debugfs_disc_trc(vport,
  9709. LPFC_DISC_TRC_MBOX_VPORT,
  9710. "MBOX dflt rpi: : "
  9711. "status:x%x rpi:x%x",
  9712. (uint32_t)pmbox->mbxStatus,
  9713. pmbox->un.varWords[0], 0);
  9714. if (!pmbox->mbxStatus) {
  9715. mp = (struct lpfc_dmabuf *)
  9716. (pmb->context1);
  9717. ndlp = (struct lpfc_nodelist *)
  9718. pmb->context2;
  9719. /* Reg_LOGIN of dflt RPI was
  9720. * successful. new lets get
  9721. * rid of the RPI using the
  9722. * same mbox buffer.
  9723. */
  9724. lpfc_unreg_login(phba,
  9725. vport->vpi,
  9726. pmbox->un.varWords[0],
  9727. pmb);
  9728. pmb->mbox_cmpl =
  9729. lpfc_mbx_cmpl_dflt_rpi;
  9730. pmb->context1 = mp;
  9731. pmb->context2 = ndlp;
  9732. pmb->vport = vport;
  9733. rc = lpfc_sli_issue_mbox(phba,
  9734. pmb,
  9735. MBX_NOWAIT);
  9736. if (rc != MBX_BUSY)
  9737. lpfc_printf_log(phba,
  9738. KERN_ERR,
  9739. LOG_MBOX | LOG_SLI,
  9740. "0350 rc should have"
  9741. "been MBX_BUSY\n");
  9742. if (rc != MBX_NOT_FINISHED)
  9743. goto send_current_mbox;
  9744. }
  9745. }
  9746. spin_lock_irqsave(
  9747. &phba->pport->work_port_lock,
  9748. iflag);
  9749. phba->pport->work_port_events &=
  9750. ~WORKER_MBOX_TMO;
  9751. spin_unlock_irqrestore(
  9752. &phba->pport->work_port_lock,
  9753. iflag);
  9754. lpfc_mbox_cmpl_put(phba, pmb);
  9755. }
  9756. } else
  9757. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9758. if ((work_ha_copy & HA_MBATT) &&
  9759. (phba->sli.mbox_active == NULL)) {
  9760. send_current_mbox:
  9761. /* Process next mailbox command if there is one */
  9762. do {
  9763. rc = lpfc_sli_issue_mbox(phba, NULL,
  9764. MBX_NOWAIT);
  9765. } while (rc == MBX_NOT_FINISHED);
  9766. if (rc != MBX_SUCCESS)
  9767. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9768. LOG_SLI, "0349 rc should be "
  9769. "MBX_SUCCESS\n");
  9770. }
  9771. spin_lock_irqsave(&phba->hbalock, iflag);
  9772. phba->work_ha |= work_ha_copy;
  9773. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9774. lpfc_worker_wake_up(phba);
  9775. }
  9776. return IRQ_HANDLED;
  9777. unplug_error:
  9778. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9779. return IRQ_HANDLED;
  9780. } /* lpfc_sli_sp_intr_handler */
  9781. /**
  9782. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  9783. * @irq: Interrupt number.
  9784. * @dev_id: The device context pointer.
  9785. *
  9786. * This function is directly called from the PCI layer as an interrupt
  9787. * service routine when device with SLI-3 interface spec is enabled with
  9788. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9789. * ring event in the HBA. However, when the device is enabled with either
  9790. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9791. * device-level interrupt handler. When the PCI slot is in error recovery
  9792. * or the HBA is undergoing initialization, the interrupt handler will not
  9793. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9794. * the intrrupt context. This function is called without any lock held.
  9795. * It gets the hbalock to access and update SLI data structures.
  9796. *
  9797. * This function returns IRQ_HANDLED when interrupt is handled else it
  9798. * returns IRQ_NONE.
  9799. **/
  9800. irqreturn_t
  9801. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  9802. {
  9803. struct lpfc_hba *phba;
  9804. uint32_t ha_copy;
  9805. unsigned long status;
  9806. unsigned long iflag;
  9807. /* Get the driver's phba structure from the dev_id and
  9808. * assume the HBA is not interrupting.
  9809. */
  9810. phba = (struct lpfc_hba *) dev_id;
  9811. if (unlikely(!phba))
  9812. return IRQ_NONE;
  9813. /*
  9814. * Stuff needs to be attented to when this function is invoked as an
  9815. * individual interrupt handler in MSI-X multi-message interrupt mode
  9816. */
  9817. if (phba->intr_type == MSIX) {
  9818. /* Check device state for handling interrupt */
  9819. if (lpfc_intr_state_check(phba))
  9820. return IRQ_NONE;
  9821. /* Need to read HA REG for FCP ring and other ring events */
  9822. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9823. return IRQ_HANDLED;
  9824. /* Clear up only attention source related to fast-path */
  9825. spin_lock_irqsave(&phba->hbalock, iflag);
  9826. /*
  9827. * If there is deferred error attention, do not check for
  9828. * any interrupt.
  9829. */
  9830. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9831. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9832. return IRQ_NONE;
  9833. }
  9834. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  9835. phba->HAregaddr);
  9836. readl(phba->HAregaddr); /* flush */
  9837. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9838. } else
  9839. ha_copy = phba->ha_copy;
  9840. /*
  9841. * Process all events on FCP ring. Take the optimized path for FCP IO.
  9842. */
  9843. ha_copy &= ~(phba->work_ha_mask);
  9844. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9845. status >>= (4*LPFC_FCP_RING);
  9846. if (status & HA_RXMASK)
  9847. lpfc_sli_handle_fast_ring_event(phba,
  9848. &phba->sli.ring[LPFC_FCP_RING],
  9849. status);
  9850. if (phba->cfg_multi_ring_support == 2) {
  9851. /*
  9852. * Process all events on extra ring. Take the optimized path
  9853. * for extra ring IO.
  9854. */
  9855. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9856. status >>= (4*LPFC_EXTRA_RING);
  9857. if (status & HA_RXMASK) {
  9858. lpfc_sli_handle_fast_ring_event(phba,
  9859. &phba->sli.ring[LPFC_EXTRA_RING],
  9860. status);
  9861. }
  9862. }
  9863. return IRQ_HANDLED;
  9864. } /* lpfc_sli_fp_intr_handler */
  9865. /**
  9866. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  9867. * @irq: Interrupt number.
  9868. * @dev_id: The device context pointer.
  9869. *
  9870. * This function is the HBA device-level interrupt handler to device with
  9871. * SLI-3 interface spec, called from the PCI layer when either MSI or
  9872. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  9873. * requires driver attention. This function invokes the slow-path interrupt
  9874. * attention handling function and fast-path interrupt attention handling
  9875. * function in turn to process the relevant HBA attention events. This
  9876. * function is called without any lock held. It gets the hbalock to access
  9877. * and update SLI data structures.
  9878. *
  9879. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9880. * returns IRQ_NONE.
  9881. **/
  9882. irqreturn_t
  9883. lpfc_sli_intr_handler(int irq, void *dev_id)
  9884. {
  9885. struct lpfc_hba *phba;
  9886. irqreturn_t sp_irq_rc, fp_irq_rc;
  9887. unsigned long status1, status2;
  9888. uint32_t hc_copy;
  9889. /*
  9890. * Get the driver's phba structure from the dev_id and
  9891. * assume the HBA is not interrupting.
  9892. */
  9893. phba = (struct lpfc_hba *) dev_id;
  9894. if (unlikely(!phba))
  9895. return IRQ_NONE;
  9896. /* Check device state for handling interrupt */
  9897. if (lpfc_intr_state_check(phba))
  9898. return IRQ_NONE;
  9899. spin_lock(&phba->hbalock);
  9900. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  9901. spin_unlock(&phba->hbalock);
  9902. return IRQ_HANDLED;
  9903. }
  9904. if (unlikely(!phba->ha_copy)) {
  9905. spin_unlock(&phba->hbalock);
  9906. return IRQ_NONE;
  9907. } else if (phba->ha_copy & HA_ERATT) {
  9908. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9909. /* ERATT polling has handled ERATT */
  9910. phba->ha_copy &= ~HA_ERATT;
  9911. else
  9912. /* Indicate interrupt handler handles ERATT */
  9913. phba->hba_flag |= HBA_ERATT_HANDLED;
  9914. }
  9915. /*
  9916. * If there is deferred error attention, do not check for any interrupt.
  9917. */
  9918. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9919. spin_unlock(&phba->hbalock);
  9920. return IRQ_NONE;
  9921. }
  9922. /* Clear attention sources except link and error attentions */
  9923. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  9924. spin_unlock(&phba->hbalock);
  9925. return IRQ_HANDLED;
  9926. }
  9927. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  9928. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  9929. phba->HCregaddr);
  9930. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  9931. writel(hc_copy, phba->HCregaddr);
  9932. readl(phba->HAregaddr); /* flush */
  9933. spin_unlock(&phba->hbalock);
  9934. /*
  9935. * Invokes slow-path host attention interrupt handling as appropriate.
  9936. */
  9937. /* status of events with mailbox and link attention */
  9938. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  9939. /* status of events with ELS ring */
  9940. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  9941. status2 >>= (4*LPFC_ELS_RING);
  9942. if (status1 || (status2 & HA_RXMASK))
  9943. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  9944. else
  9945. sp_irq_rc = IRQ_NONE;
  9946. /*
  9947. * Invoke fast-path host attention interrupt handling as appropriate.
  9948. */
  9949. /* status of events with FCP ring */
  9950. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9951. status1 >>= (4*LPFC_FCP_RING);
  9952. /* status of events with extra ring */
  9953. if (phba->cfg_multi_ring_support == 2) {
  9954. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9955. status2 >>= (4*LPFC_EXTRA_RING);
  9956. } else
  9957. status2 = 0;
  9958. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  9959. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  9960. else
  9961. fp_irq_rc = IRQ_NONE;
  9962. /* Return device-level interrupt handling status */
  9963. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  9964. } /* lpfc_sli_intr_handler */
  9965. /**
  9966. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  9967. * @phba: pointer to lpfc hba data structure.
  9968. *
  9969. * This routine is invoked by the worker thread to process all the pending
  9970. * SLI4 FCP abort XRI events.
  9971. **/
  9972. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  9973. {
  9974. struct lpfc_cq_event *cq_event;
  9975. /* First, declare the fcp xri abort event has been handled */
  9976. spin_lock_irq(&phba->hbalock);
  9977. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  9978. spin_unlock_irq(&phba->hbalock);
  9979. /* Now, handle all the fcp xri abort events */
  9980. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  9981. /* Get the first event from the head of the event queue */
  9982. spin_lock_irq(&phba->hbalock);
  9983. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  9984. cq_event, struct lpfc_cq_event, list);
  9985. spin_unlock_irq(&phba->hbalock);
  9986. /* Notify aborted XRI for FCP work queue */
  9987. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9988. /* Free the event processed back to the free pool */
  9989. lpfc_sli4_cq_event_release(phba, cq_event);
  9990. }
  9991. }
  9992. /**
  9993. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  9994. * @phba: pointer to lpfc hba data structure.
  9995. *
  9996. * This routine is invoked by the worker thread to process all the pending
  9997. * SLI4 els abort xri events.
  9998. **/
  9999. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  10000. {
  10001. struct lpfc_cq_event *cq_event;
  10002. /* First, declare the els xri abort event has been handled */
  10003. spin_lock_irq(&phba->hbalock);
  10004. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  10005. spin_unlock_irq(&phba->hbalock);
  10006. /* Now, handle all the els xri abort events */
  10007. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  10008. /* Get the first event from the head of the event queue */
  10009. spin_lock_irq(&phba->hbalock);
  10010. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  10011. cq_event, struct lpfc_cq_event, list);
  10012. spin_unlock_irq(&phba->hbalock);
  10013. /* Notify aborted XRI for ELS work queue */
  10014. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  10015. /* Free the event processed back to the free pool */
  10016. lpfc_sli4_cq_event_release(phba, cq_event);
  10017. }
  10018. }
  10019. /**
  10020. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  10021. * @phba: pointer to lpfc hba data structure
  10022. * @pIocbIn: pointer to the rspiocbq
  10023. * @pIocbOut: pointer to the cmdiocbq
  10024. * @wcqe: pointer to the complete wcqe
  10025. *
  10026. * This routine transfers the fields of a command iocbq to a response iocbq
  10027. * by copying all the IOCB fields from command iocbq and transferring the
  10028. * completion status information from the complete wcqe.
  10029. **/
  10030. static void
  10031. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  10032. struct lpfc_iocbq *pIocbIn,
  10033. struct lpfc_iocbq *pIocbOut,
  10034. struct lpfc_wcqe_complete *wcqe)
  10035. {
  10036. unsigned long iflags;
  10037. uint32_t status;
  10038. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  10039. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  10040. sizeof(struct lpfc_iocbq) - offset);
  10041. /* Map WCQE parameters into irspiocb parameters */
  10042. status = bf_get(lpfc_wcqe_c_status, wcqe);
  10043. pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
  10044. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  10045. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  10046. pIocbIn->iocb.un.fcpi.fcpi_parm =
  10047. pIocbOut->iocb.un.fcpi.fcpi_parm -
  10048. wcqe->total_data_placed;
  10049. else
  10050. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10051. else {
  10052. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10053. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  10054. }
  10055. /* Convert BG errors for completion status */
  10056. if (status == CQE_STATUS_DI_ERROR) {
  10057. pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  10058. if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
  10059. pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
  10060. else
  10061. pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
  10062. pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
  10063. if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
  10064. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10065. BGS_GUARD_ERR_MASK;
  10066. if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
  10067. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10068. BGS_APPTAG_ERR_MASK;
  10069. if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
  10070. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10071. BGS_REFTAG_ERR_MASK;
  10072. /* Check to see if there was any good data before the error */
  10073. if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
  10074. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10075. BGS_HI_WATER_MARK_PRESENT_MASK;
  10076. pIocbIn->iocb.unsli3.sli3_bg.bghm =
  10077. wcqe->total_data_placed;
  10078. }
  10079. /*
  10080. * Set ALL the error bits to indicate we don't know what
  10081. * type of error it is.
  10082. */
  10083. if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
  10084. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10085. (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
  10086. BGS_GUARD_ERR_MASK);
  10087. }
  10088. /* Pick up HBA exchange busy condition */
  10089. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  10090. spin_lock_irqsave(&phba->hbalock, iflags);
  10091. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  10092. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10093. }
  10094. }
  10095. /**
  10096. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  10097. * @phba: Pointer to HBA context object.
  10098. * @wcqe: Pointer to work-queue completion queue entry.
  10099. *
  10100. * This routine handles an ELS work-queue completion event and construct
  10101. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  10102. * discovery engine to handle.
  10103. *
  10104. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  10105. **/
  10106. static struct lpfc_iocbq *
  10107. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  10108. struct lpfc_iocbq *irspiocbq)
  10109. {
  10110. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  10111. struct lpfc_iocbq *cmdiocbq;
  10112. struct lpfc_wcqe_complete *wcqe;
  10113. unsigned long iflags;
  10114. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  10115. spin_lock_irqsave(&pring->ring_lock, iflags);
  10116. pring->stats.iocb_event++;
  10117. /* Look up the ELS command IOCB and create pseudo response IOCB */
  10118. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10119. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10120. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10121. if (unlikely(!cmdiocbq)) {
  10122. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10123. "0386 ELS complete with no corresponding "
  10124. "cmdiocb: iotag (%d)\n",
  10125. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10126. lpfc_sli_release_iocbq(phba, irspiocbq);
  10127. return NULL;
  10128. }
  10129. /* Fake the irspiocbq and copy necessary response information */
  10130. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  10131. return irspiocbq;
  10132. }
  10133. /**
  10134. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  10135. * @phba: Pointer to HBA context object.
  10136. * @cqe: Pointer to mailbox completion queue entry.
  10137. *
  10138. * This routine process a mailbox completion queue entry with asynchrous
  10139. * event.
  10140. *
  10141. * Return: true if work posted to worker thread, otherwise false.
  10142. **/
  10143. static bool
  10144. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10145. {
  10146. struct lpfc_cq_event *cq_event;
  10147. unsigned long iflags;
  10148. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  10149. "0392 Async Event: word0:x%x, word1:x%x, "
  10150. "word2:x%x, word3:x%x\n", mcqe->word0,
  10151. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  10152. /* Allocate a new internal CQ_EVENT entry */
  10153. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10154. if (!cq_event) {
  10155. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10156. "0394 Failed to allocate CQ_EVENT entry\n");
  10157. return false;
  10158. }
  10159. /* Move the CQE into an asynchronous event entry */
  10160. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  10161. spin_lock_irqsave(&phba->hbalock, iflags);
  10162. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  10163. /* Set the async event flag */
  10164. phba->hba_flag |= ASYNC_EVENT;
  10165. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10166. return true;
  10167. }
  10168. /**
  10169. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  10170. * @phba: Pointer to HBA context object.
  10171. * @cqe: Pointer to mailbox completion queue entry.
  10172. *
  10173. * This routine process a mailbox completion queue entry with mailbox
  10174. * completion event.
  10175. *
  10176. * Return: true if work posted to worker thread, otherwise false.
  10177. **/
  10178. static bool
  10179. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10180. {
  10181. uint32_t mcqe_status;
  10182. MAILBOX_t *mbox, *pmbox;
  10183. struct lpfc_mqe *mqe;
  10184. struct lpfc_vport *vport;
  10185. struct lpfc_nodelist *ndlp;
  10186. struct lpfc_dmabuf *mp;
  10187. unsigned long iflags;
  10188. LPFC_MBOXQ_t *pmb;
  10189. bool workposted = false;
  10190. int rc;
  10191. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  10192. if (!bf_get(lpfc_trailer_completed, mcqe))
  10193. goto out_no_mqe_complete;
  10194. /* Get the reference to the active mbox command */
  10195. spin_lock_irqsave(&phba->hbalock, iflags);
  10196. pmb = phba->sli.mbox_active;
  10197. if (unlikely(!pmb)) {
  10198. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10199. "1832 No pending MBOX command to handle\n");
  10200. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10201. goto out_no_mqe_complete;
  10202. }
  10203. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10204. mqe = &pmb->u.mqe;
  10205. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  10206. mbox = phba->mbox;
  10207. vport = pmb->vport;
  10208. /* Reset heartbeat timer */
  10209. phba->last_completion_time = jiffies;
  10210. del_timer(&phba->sli.mbox_tmo);
  10211. /* Move mbox data to caller's mailbox region, do endian swapping */
  10212. if (pmb->mbox_cmpl && mbox)
  10213. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  10214. /*
  10215. * For mcqe errors, conditionally move a modified error code to
  10216. * the mbox so that the error will not be missed.
  10217. */
  10218. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  10219. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  10220. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  10221. bf_set(lpfc_mqe_status, mqe,
  10222. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  10223. }
  10224. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10225. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10226. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  10227. "MBOX dflt rpi: status:x%x rpi:x%x",
  10228. mcqe_status,
  10229. pmbox->un.varWords[0], 0);
  10230. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  10231. mp = (struct lpfc_dmabuf *)(pmb->context1);
  10232. ndlp = (struct lpfc_nodelist *)pmb->context2;
  10233. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  10234. * RID of the PPI using the same mbox buffer.
  10235. */
  10236. lpfc_unreg_login(phba, vport->vpi,
  10237. pmbox->un.varWords[0], pmb);
  10238. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  10239. pmb->context1 = mp;
  10240. pmb->context2 = ndlp;
  10241. pmb->vport = vport;
  10242. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  10243. if (rc != MBX_BUSY)
  10244. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10245. LOG_SLI, "0385 rc should "
  10246. "have been MBX_BUSY\n");
  10247. if (rc != MBX_NOT_FINISHED)
  10248. goto send_current_mbox;
  10249. }
  10250. }
  10251. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  10252. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  10253. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  10254. /* There is mailbox completion work to do */
  10255. spin_lock_irqsave(&phba->hbalock, iflags);
  10256. __lpfc_mbox_cmpl_put(phba, pmb);
  10257. phba->work_ha |= HA_MBATT;
  10258. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10259. workposted = true;
  10260. send_current_mbox:
  10261. spin_lock_irqsave(&phba->hbalock, iflags);
  10262. /* Release the mailbox command posting token */
  10263. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  10264. /* Setting active mailbox pointer need to be in sync to flag clear */
  10265. phba->sli.mbox_active = NULL;
  10266. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10267. /* Wake up worker thread to post the next pending mailbox command */
  10268. lpfc_worker_wake_up(phba);
  10269. out_no_mqe_complete:
  10270. if (bf_get(lpfc_trailer_consumed, mcqe))
  10271. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  10272. return workposted;
  10273. }
  10274. /**
  10275. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  10276. * @phba: Pointer to HBA context object.
  10277. * @cqe: Pointer to mailbox completion queue entry.
  10278. *
  10279. * This routine process a mailbox completion queue entry, it invokes the
  10280. * proper mailbox complete handling or asynchrous event handling routine
  10281. * according to the MCQE's async bit.
  10282. *
  10283. * Return: true if work posted to worker thread, otherwise false.
  10284. **/
  10285. static bool
  10286. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  10287. {
  10288. struct lpfc_mcqe mcqe;
  10289. bool workposted;
  10290. /* Copy the mailbox MCQE and convert endian order as needed */
  10291. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  10292. /* Invoke the proper event handling routine */
  10293. if (!bf_get(lpfc_trailer_async, &mcqe))
  10294. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  10295. else
  10296. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  10297. return workposted;
  10298. }
  10299. /**
  10300. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  10301. * @phba: Pointer to HBA context object.
  10302. * @cq: Pointer to associated CQ
  10303. * @wcqe: Pointer to work-queue completion queue entry.
  10304. *
  10305. * This routine handles an ELS work-queue completion event.
  10306. *
  10307. * Return: true if work posted to worker thread, otherwise false.
  10308. **/
  10309. static bool
  10310. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10311. struct lpfc_wcqe_complete *wcqe)
  10312. {
  10313. struct lpfc_iocbq *irspiocbq;
  10314. unsigned long iflags;
  10315. struct lpfc_sli_ring *pring = cq->pring;
  10316. int txq_cnt = 0;
  10317. int txcmplq_cnt = 0;
  10318. int fcp_txcmplq_cnt = 0;
  10319. /* Get an irspiocbq for later ELS response processing use */
  10320. irspiocbq = lpfc_sli_get_iocbq(phba);
  10321. if (!irspiocbq) {
  10322. if (!list_empty(&pring->txq))
  10323. txq_cnt++;
  10324. if (!list_empty(&pring->txcmplq))
  10325. txcmplq_cnt++;
  10326. if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq))
  10327. fcp_txcmplq_cnt++;
  10328. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10329. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  10330. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  10331. txq_cnt, phba->iocb_cnt,
  10332. fcp_txcmplq_cnt,
  10333. txcmplq_cnt);
  10334. return false;
  10335. }
  10336. /* Save off the slow-path queue event for work thread to process */
  10337. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  10338. spin_lock_irqsave(&phba->hbalock, iflags);
  10339. list_add_tail(&irspiocbq->cq_event.list,
  10340. &phba->sli4_hba.sp_queue_event);
  10341. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10342. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10343. return true;
  10344. }
  10345. /**
  10346. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  10347. * @phba: Pointer to HBA context object.
  10348. * @wcqe: Pointer to work-queue completion queue entry.
  10349. *
  10350. * This routine handles slow-path WQ entry comsumed event by invoking the
  10351. * proper WQ release routine to the slow-path WQ.
  10352. **/
  10353. static void
  10354. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  10355. struct lpfc_wcqe_release *wcqe)
  10356. {
  10357. /* sanity check on queue memory */
  10358. if (unlikely(!phba->sli4_hba.els_wq))
  10359. return;
  10360. /* Check for the slow-path ELS work queue */
  10361. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  10362. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  10363. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10364. else
  10365. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10366. "2579 Slow-path wqe consume event carries "
  10367. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  10368. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  10369. phba->sli4_hba.els_wq->queue_id);
  10370. }
  10371. /**
  10372. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  10373. * @phba: Pointer to HBA context object.
  10374. * @cq: Pointer to a WQ completion queue.
  10375. * @wcqe: Pointer to work-queue completion queue entry.
  10376. *
  10377. * This routine handles an XRI abort event.
  10378. *
  10379. * Return: true if work posted to worker thread, otherwise false.
  10380. **/
  10381. static bool
  10382. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  10383. struct lpfc_queue *cq,
  10384. struct sli4_wcqe_xri_aborted *wcqe)
  10385. {
  10386. bool workposted = false;
  10387. struct lpfc_cq_event *cq_event;
  10388. unsigned long iflags;
  10389. /* Allocate a new internal CQ_EVENT entry */
  10390. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10391. if (!cq_event) {
  10392. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10393. "0602 Failed to allocate CQ_EVENT entry\n");
  10394. return false;
  10395. }
  10396. /* Move the CQE into the proper xri abort event list */
  10397. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  10398. switch (cq->subtype) {
  10399. case LPFC_FCP:
  10400. spin_lock_irqsave(&phba->hbalock, iflags);
  10401. list_add_tail(&cq_event->list,
  10402. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  10403. /* Set the fcp xri abort event flag */
  10404. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  10405. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10406. workposted = true;
  10407. break;
  10408. case LPFC_ELS:
  10409. spin_lock_irqsave(&phba->hbalock, iflags);
  10410. list_add_tail(&cq_event->list,
  10411. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  10412. /* Set the els xri abort event flag */
  10413. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  10414. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10415. workposted = true;
  10416. break;
  10417. default:
  10418. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10419. "0603 Invalid work queue CQE subtype (x%x)\n",
  10420. cq->subtype);
  10421. workposted = false;
  10422. break;
  10423. }
  10424. return workposted;
  10425. }
  10426. /**
  10427. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  10428. * @phba: Pointer to HBA context object.
  10429. * @rcqe: Pointer to receive-queue completion queue entry.
  10430. *
  10431. * This routine process a receive-queue completion queue entry.
  10432. *
  10433. * Return: true if work posted to worker thread, otherwise false.
  10434. **/
  10435. static bool
  10436. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  10437. {
  10438. bool workposted = false;
  10439. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  10440. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  10441. struct hbq_dmabuf *dma_buf;
  10442. uint32_t status, rq_id;
  10443. unsigned long iflags;
  10444. /* sanity check on queue memory */
  10445. if (unlikely(!hrq) || unlikely(!drq))
  10446. return workposted;
  10447. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  10448. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  10449. else
  10450. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  10451. if (rq_id != hrq->queue_id)
  10452. goto out;
  10453. status = bf_get(lpfc_rcqe_status, rcqe);
  10454. switch (status) {
  10455. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  10456. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10457. "2537 Receive Frame Truncated!!\n");
  10458. hrq->RQ_buf_trunc++;
  10459. case FC_STATUS_RQ_SUCCESS:
  10460. lpfc_sli4_rq_release(hrq, drq);
  10461. spin_lock_irqsave(&phba->hbalock, iflags);
  10462. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  10463. if (!dma_buf) {
  10464. hrq->RQ_no_buf_found++;
  10465. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10466. goto out;
  10467. }
  10468. hrq->RQ_rcv_buf++;
  10469. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  10470. /* save off the frame for the word thread to process */
  10471. list_add_tail(&dma_buf->cq_event.list,
  10472. &phba->sli4_hba.sp_queue_event);
  10473. /* Frame received */
  10474. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10475. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10476. workposted = true;
  10477. break;
  10478. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  10479. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  10480. hrq->RQ_no_posted_buf++;
  10481. /* Post more buffers if possible */
  10482. spin_lock_irqsave(&phba->hbalock, iflags);
  10483. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  10484. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10485. workposted = true;
  10486. break;
  10487. }
  10488. out:
  10489. return workposted;
  10490. }
  10491. /**
  10492. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  10493. * @phba: Pointer to HBA context object.
  10494. * @cq: Pointer to the completion queue.
  10495. * @wcqe: Pointer to a completion queue entry.
  10496. *
  10497. * This routine process a slow-path work-queue or receive queue completion queue
  10498. * entry.
  10499. *
  10500. * Return: true if work posted to worker thread, otherwise false.
  10501. **/
  10502. static bool
  10503. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10504. struct lpfc_cqe *cqe)
  10505. {
  10506. struct lpfc_cqe cqevt;
  10507. bool workposted = false;
  10508. /* Copy the work queue CQE and convert endian order if needed */
  10509. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  10510. /* Check and process for different type of WCQE and dispatch */
  10511. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  10512. case CQE_CODE_COMPL_WQE:
  10513. /* Process the WQ/RQ complete event */
  10514. phba->last_completion_time = jiffies;
  10515. workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
  10516. (struct lpfc_wcqe_complete *)&cqevt);
  10517. break;
  10518. case CQE_CODE_RELEASE_WQE:
  10519. /* Process the WQ release event */
  10520. lpfc_sli4_sp_handle_rel_wcqe(phba,
  10521. (struct lpfc_wcqe_release *)&cqevt);
  10522. break;
  10523. case CQE_CODE_XRI_ABORTED:
  10524. /* Process the WQ XRI abort event */
  10525. phba->last_completion_time = jiffies;
  10526. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10527. (struct sli4_wcqe_xri_aborted *)&cqevt);
  10528. break;
  10529. case CQE_CODE_RECEIVE:
  10530. case CQE_CODE_RECEIVE_V1:
  10531. /* Process the RQ event */
  10532. phba->last_completion_time = jiffies;
  10533. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  10534. (struct lpfc_rcqe *)&cqevt);
  10535. break;
  10536. default:
  10537. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10538. "0388 Not a valid WCQE code: x%x\n",
  10539. bf_get(lpfc_cqe_code, &cqevt));
  10540. break;
  10541. }
  10542. return workposted;
  10543. }
  10544. /**
  10545. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  10546. * @phba: Pointer to HBA context object.
  10547. * @eqe: Pointer to fast-path event queue entry.
  10548. *
  10549. * This routine process a event queue entry from the slow-path event queue.
  10550. * It will check the MajorCode and MinorCode to determine this is for a
  10551. * completion event on a completion queue, if not, an error shall be logged
  10552. * and just return. Otherwise, it will get to the corresponding completion
  10553. * queue and process all the entries on that completion queue, rearm the
  10554. * completion queue, and then return.
  10555. *
  10556. **/
  10557. static void
  10558. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10559. struct lpfc_queue *speq)
  10560. {
  10561. struct lpfc_queue *cq = NULL, *childq;
  10562. struct lpfc_cqe *cqe;
  10563. bool workposted = false;
  10564. int ecount = 0;
  10565. uint16_t cqid;
  10566. /* Get the reference to the corresponding CQ */
  10567. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10568. list_for_each_entry(childq, &speq->child_list, list) {
  10569. if (childq->queue_id == cqid) {
  10570. cq = childq;
  10571. break;
  10572. }
  10573. }
  10574. if (unlikely(!cq)) {
  10575. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10576. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10577. "0365 Slow-path CQ identifier "
  10578. "(%d) does not exist\n", cqid);
  10579. return;
  10580. }
  10581. /* Process all the entries to the CQ */
  10582. switch (cq->type) {
  10583. case LPFC_MCQ:
  10584. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10585. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  10586. if (!(++ecount % cq->entry_repost))
  10587. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10588. cq->CQ_mbox++;
  10589. }
  10590. break;
  10591. case LPFC_WCQ:
  10592. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10593. if (cq->subtype == LPFC_FCP)
  10594. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  10595. cqe);
  10596. else
  10597. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  10598. cqe);
  10599. if (!(++ecount % cq->entry_repost))
  10600. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10601. }
  10602. /* Track the max number of CQEs processed in 1 EQ */
  10603. if (ecount > cq->CQ_max_cqe)
  10604. cq->CQ_max_cqe = ecount;
  10605. break;
  10606. default:
  10607. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10608. "0370 Invalid completion queue type (%d)\n",
  10609. cq->type);
  10610. return;
  10611. }
  10612. /* Catch the no cq entry condition, log an error */
  10613. if (unlikely(ecount == 0))
  10614. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10615. "0371 No entry from the CQ: identifier "
  10616. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  10617. /* In any case, flash and re-arm the RCQ */
  10618. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10619. /* wake up worker thread if there are works to be done */
  10620. if (workposted)
  10621. lpfc_worker_wake_up(phba);
  10622. }
  10623. /**
  10624. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  10625. * @phba: Pointer to HBA context object.
  10626. * @cq: Pointer to associated CQ
  10627. * @wcqe: Pointer to work-queue completion queue entry.
  10628. *
  10629. * This routine process a fast-path work queue completion entry from fast-path
  10630. * event queue for FCP command response completion.
  10631. **/
  10632. static void
  10633. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10634. struct lpfc_wcqe_complete *wcqe)
  10635. {
  10636. struct lpfc_sli_ring *pring = cq->pring;
  10637. struct lpfc_iocbq *cmdiocbq;
  10638. struct lpfc_iocbq irspiocbq;
  10639. unsigned long iflags;
  10640. /* Check for response status */
  10641. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  10642. /* If resource errors reported from HBA, reduce queue
  10643. * depth of the SCSI device.
  10644. */
  10645. if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
  10646. IOSTAT_LOCAL_REJECT)) &&
  10647. ((wcqe->parameter & IOERR_PARAM_MASK) ==
  10648. IOERR_NO_RESOURCES))
  10649. phba->lpfc_rampdown_queue_depth(phba);
  10650. /* Log the error status */
  10651. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10652. "0373 FCP complete error: status=x%x, "
  10653. "hw_status=x%x, total_data_specified=%d, "
  10654. "parameter=x%x, word3=x%x\n",
  10655. bf_get(lpfc_wcqe_c_status, wcqe),
  10656. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  10657. wcqe->total_data_placed, wcqe->parameter,
  10658. wcqe->word3);
  10659. }
  10660. /* Look up the FCP command IOCB and create pseudo response IOCB */
  10661. spin_lock_irqsave(&pring->ring_lock, iflags);
  10662. pring->stats.iocb_event++;
  10663. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10664. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10665. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10666. if (unlikely(!cmdiocbq)) {
  10667. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10668. "0374 FCP complete with no corresponding "
  10669. "cmdiocb: iotag (%d)\n",
  10670. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10671. return;
  10672. }
  10673. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  10674. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10675. "0375 FCP cmdiocb not callback function "
  10676. "iotag: (%d)\n",
  10677. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10678. return;
  10679. }
  10680. /* Fake the irspiocb and copy necessary response information */
  10681. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  10682. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  10683. spin_lock_irqsave(&phba->hbalock, iflags);
  10684. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  10685. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10686. }
  10687. /* Pass the cmd_iocb and the rsp state to the upper layer */
  10688. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  10689. }
  10690. /**
  10691. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  10692. * @phba: Pointer to HBA context object.
  10693. * @cq: Pointer to completion queue.
  10694. * @wcqe: Pointer to work-queue completion queue entry.
  10695. *
  10696. * This routine handles an fast-path WQ entry comsumed event by invoking the
  10697. * proper WQ release routine to the slow-path WQ.
  10698. **/
  10699. static void
  10700. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10701. struct lpfc_wcqe_release *wcqe)
  10702. {
  10703. struct lpfc_queue *childwq;
  10704. bool wqid_matched = false;
  10705. uint16_t fcp_wqid;
  10706. /* Check for fast-path FCP work queue release */
  10707. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  10708. list_for_each_entry(childwq, &cq->child_list, list) {
  10709. if (childwq->queue_id == fcp_wqid) {
  10710. lpfc_sli4_wq_release(childwq,
  10711. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10712. wqid_matched = true;
  10713. break;
  10714. }
  10715. }
  10716. /* Report warning log message if no match found */
  10717. if (wqid_matched != true)
  10718. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10719. "2580 Fast-path wqe consume event carries "
  10720. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  10721. }
  10722. /**
  10723. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  10724. * @cq: Pointer to the completion queue.
  10725. * @eqe: Pointer to fast-path completion queue entry.
  10726. *
  10727. * This routine process a fast-path work queue completion entry from fast-path
  10728. * event queue for FCP command response completion.
  10729. **/
  10730. static int
  10731. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10732. struct lpfc_cqe *cqe)
  10733. {
  10734. struct lpfc_wcqe_release wcqe;
  10735. bool workposted = false;
  10736. /* Copy the work queue CQE and convert endian order if needed */
  10737. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  10738. /* Check and process for different type of WCQE and dispatch */
  10739. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  10740. case CQE_CODE_COMPL_WQE:
  10741. cq->CQ_wq++;
  10742. /* Process the WQ complete event */
  10743. phba->last_completion_time = jiffies;
  10744. lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
  10745. (struct lpfc_wcqe_complete *)&wcqe);
  10746. break;
  10747. case CQE_CODE_RELEASE_WQE:
  10748. cq->CQ_release_wqe++;
  10749. /* Process the WQ release event */
  10750. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  10751. (struct lpfc_wcqe_release *)&wcqe);
  10752. break;
  10753. case CQE_CODE_XRI_ABORTED:
  10754. cq->CQ_xri_aborted++;
  10755. /* Process the WQ XRI abort event */
  10756. phba->last_completion_time = jiffies;
  10757. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10758. (struct sli4_wcqe_xri_aborted *)&wcqe);
  10759. break;
  10760. default:
  10761. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10762. "0144 Not a valid WCQE code: x%x\n",
  10763. bf_get(lpfc_wcqe_c_code, &wcqe));
  10764. break;
  10765. }
  10766. return workposted;
  10767. }
  10768. /**
  10769. * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
  10770. * @phba: Pointer to HBA context object.
  10771. * @eqe: Pointer to fast-path event queue entry.
  10772. *
  10773. * This routine process a event queue entry from the fast-path event queue.
  10774. * It will check the MajorCode and MinorCode to determine this is for a
  10775. * completion event on a completion queue, if not, an error shall be logged
  10776. * and just return. Otherwise, it will get to the corresponding completion
  10777. * queue and process all the entries on the completion queue, rearm the
  10778. * completion queue, and then return.
  10779. **/
  10780. static void
  10781. lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10782. uint32_t qidx)
  10783. {
  10784. struct lpfc_queue *cq;
  10785. struct lpfc_cqe *cqe;
  10786. bool workposted = false;
  10787. uint16_t cqid;
  10788. int ecount = 0;
  10789. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  10790. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10791. "0366 Not a valid completion "
  10792. "event: majorcode=x%x, minorcode=x%x\n",
  10793. bf_get_le32(lpfc_eqe_major_code, eqe),
  10794. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10795. return;
  10796. }
  10797. /* Get the reference to the corresponding CQ */
  10798. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10799. /* Check if this is a Slow path event */
  10800. if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) {
  10801. lpfc_sli4_sp_handle_eqe(phba, eqe,
  10802. phba->sli4_hba.hba_eq[qidx]);
  10803. return;
  10804. }
  10805. if (unlikely(!phba->sli4_hba.fcp_cq)) {
  10806. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10807. "3146 Fast-path completion queues "
  10808. "does not exist\n");
  10809. return;
  10810. }
  10811. cq = phba->sli4_hba.fcp_cq[qidx];
  10812. if (unlikely(!cq)) {
  10813. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10814. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10815. "0367 Fast-path completion queue "
  10816. "(%d) does not exist\n", qidx);
  10817. return;
  10818. }
  10819. if (unlikely(cqid != cq->queue_id)) {
  10820. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10821. "0368 Miss-matched fast-path completion "
  10822. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  10823. cqid, cq->queue_id);
  10824. return;
  10825. }
  10826. /* Process all the entries to the CQ */
  10827. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10828. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  10829. if (!(++ecount % cq->entry_repost))
  10830. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10831. }
  10832. /* Track the max number of CQEs processed in 1 EQ */
  10833. if (ecount > cq->CQ_max_cqe)
  10834. cq->CQ_max_cqe = ecount;
  10835. /* Catch the no cq entry condition */
  10836. if (unlikely(ecount == 0))
  10837. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10838. "0369 No entry from fast-path completion "
  10839. "queue fcpcqid=%d\n", cq->queue_id);
  10840. /* In any case, flash and re-arm the CQ */
  10841. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10842. /* wake up worker thread if there are works to be done */
  10843. if (workposted)
  10844. lpfc_worker_wake_up(phba);
  10845. }
  10846. static void
  10847. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10848. {
  10849. struct lpfc_eqe *eqe;
  10850. /* walk all the EQ entries and drop on the floor */
  10851. while ((eqe = lpfc_sli4_eq_get(eq)))
  10852. ;
  10853. /* Clear and re-arm the EQ */
  10854. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  10855. }
  10856. /**
  10857. * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
  10858. * @irq: Interrupt number.
  10859. * @dev_id: The device context pointer.
  10860. *
  10861. * This function is directly called from the PCI layer as an interrupt
  10862. * service routine when device with SLI-4 interface spec is enabled with
  10863. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10864. * ring event in the HBA. However, when the device is enabled with either
  10865. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10866. * device-level interrupt handler. When the PCI slot is in error recovery
  10867. * or the HBA is undergoing initialization, the interrupt handler will not
  10868. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10869. * the intrrupt context. This function is called without any lock held.
  10870. * It gets the hbalock to access and update SLI data structures. Note that,
  10871. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  10872. * equal to that of FCP CQ index.
  10873. *
  10874. * The link attention and ELS ring attention events are handled
  10875. * by the worker thread. The interrupt handler signals the worker thread
  10876. * and returns for these events. This function is called without any lock
  10877. * held. It gets the hbalock to access and update SLI data structures.
  10878. *
  10879. * This function returns IRQ_HANDLED when interrupt is handled else it
  10880. * returns IRQ_NONE.
  10881. **/
  10882. irqreturn_t
  10883. lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
  10884. {
  10885. struct lpfc_hba *phba;
  10886. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  10887. struct lpfc_queue *fpeq;
  10888. struct lpfc_eqe *eqe;
  10889. unsigned long iflag;
  10890. int ecount = 0;
  10891. int fcp_eqidx;
  10892. /* Get the driver's phba structure from the dev_id */
  10893. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  10894. phba = fcp_eq_hdl->phba;
  10895. fcp_eqidx = fcp_eq_hdl->idx;
  10896. if (unlikely(!phba))
  10897. return IRQ_NONE;
  10898. if (unlikely(!phba->sli4_hba.hba_eq))
  10899. return IRQ_NONE;
  10900. /* Get to the EQ struct associated with this vector */
  10901. fpeq = phba->sli4_hba.hba_eq[fcp_eqidx];
  10902. if (unlikely(!fpeq))
  10903. return IRQ_NONE;
  10904. if (lpfc_fcp_look_ahead) {
  10905. if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use))
  10906. lpfc_sli4_eq_clr_intr(fpeq);
  10907. else {
  10908. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10909. return IRQ_NONE;
  10910. }
  10911. }
  10912. /* Check device state for handling interrupt */
  10913. if (unlikely(lpfc_intr_state_check(phba))) {
  10914. fpeq->EQ_badstate++;
  10915. /* Check again for link_state with lock held */
  10916. spin_lock_irqsave(&phba->hbalock, iflag);
  10917. if (phba->link_state < LPFC_LINK_DOWN)
  10918. /* Flush, clear interrupt, and rearm the EQ */
  10919. lpfc_sli4_eq_flush(phba, fpeq);
  10920. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10921. if (lpfc_fcp_look_ahead)
  10922. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10923. return IRQ_NONE;
  10924. }
  10925. /*
  10926. * Process all the event on FCP fast-path EQ
  10927. */
  10928. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  10929. lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx);
  10930. if (!(++ecount % fpeq->entry_repost))
  10931. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  10932. fpeq->EQ_processed++;
  10933. }
  10934. /* Track the max number of EQEs processed in 1 intr */
  10935. if (ecount > fpeq->EQ_max_eqe)
  10936. fpeq->EQ_max_eqe = ecount;
  10937. /* Always clear and re-arm the fast-path EQ */
  10938. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  10939. if (unlikely(ecount == 0)) {
  10940. fpeq->EQ_no_entry++;
  10941. if (lpfc_fcp_look_ahead) {
  10942. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10943. return IRQ_NONE;
  10944. }
  10945. if (phba->intr_type == MSIX)
  10946. /* MSI-X treated interrupt served as no EQ share INT */
  10947. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10948. "0358 MSI-X interrupt with no EQE\n");
  10949. else
  10950. /* Non MSI-X treated on interrupt as EQ share INT */
  10951. return IRQ_NONE;
  10952. }
  10953. if (lpfc_fcp_look_ahead)
  10954. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10955. return IRQ_HANDLED;
  10956. } /* lpfc_sli4_fp_intr_handler */
  10957. /**
  10958. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  10959. * @irq: Interrupt number.
  10960. * @dev_id: The device context pointer.
  10961. *
  10962. * This function is the device-level interrupt handler to device with SLI-4
  10963. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  10964. * interrupt mode is enabled and there is an event in the HBA which requires
  10965. * driver attention. This function invokes the slow-path interrupt attention
  10966. * handling function and fast-path interrupt attention handling function in
  10967. * turn to process the relevant HBA attention events. This function is called
  10968. * without any lock held. It gets the hbalock to access and update SLI data
  10969. * structures.
  10970. *
  10971. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10972. * returns IRQ_NONE.
  10973. **/
  10974. irqreturn_t
  10975. lpfc_sli4_intr_handler(int irq, void *dev_id)
  10976. {
  10977. struct lpfc_hba *phba;
  10978. irqreturn_t hba_irq_rc;
  10979. bool hba_handled = false;
  10980. int fcp_eqidx;
  10981. /* Get the driver's phba structure from the dev_id */
  10982. phba = (struct lpfc_hba *)dev_id;
  10983. if (unlikely(!phba))
  10984. return IRQ_NONE;
  10985. /*
  10986. * Invoke fast-path host attention interrupt handling as appropriate.
  10987. */
  10988. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
  10989. hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
  10990. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  10991. if (hba_irq_rc == IRQ_HANDLED)
  10992. hba_handled |= true;
  10993. }
  10994. return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
  10995. } /* lpfc_sli4_intr_handler */
  10996. /**
  10997. * lpfc_sli4_queue_free - free a queue structure and associated memory
  10998. * @queue: The queue structure to free.
  10999. *
  11000. * This function frees a queue structure and the DMAable memory used for
  11001. * the host resident queue. This function must be called after destroying the
  11002. * queue on the HBA.
  11003. **/
  11004. void
  11005. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  11006. {
  11007. struct lpfc_dmabuf *dmabuf;
  11008. if (!queue)
  11009. return;
  11010. while (!list_empty(&queue->page_list)) {
  11011. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  11012. list);
  11013. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  11014. dmabuf->virt, dmabuf->phys);
  11015. kfree(dmabuf);
  11016. }
  11017. kfree(queue);
  11018. return;
  11019. }
  11020. /**
  11021. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  11022. * @phba: The HBA that this queue is being created on.
  11023. * @entry_size: The size of each queue entry for this queue.
  11024. * @entry count: The number of entries that this queue will handle.
  11025. *
  11026. * This function allocates a queue structure and the DMAable memory used for
  11027. * the host resident queue. This function must be called before creating the
  11028. * queue on the HBA.
  11029. **/
  11030. struct lpfc_queue *
  11031. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  11032. uint32_t entry_count)
  11033. {
  11034. struct lpfc_queue *queue;
  11035. struct lpfc_dmabuf *dmabuf;
  11036. int x, total_qe_count;
  11037. void *dma_pointer;
  11038. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11039. if (!phba->sli4_hba.pc_sli4_params.supported)
  11040. hw_page_size = SLI4_PAGE_SIZE;
  11041. queue = kzalloc(sizeof(struct lpfc_queue) +
  11042. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  11043. if (!queue)
  11044. return NULL;
  11045. queue->page_count = (ALIGN(entry_size * entry_count,
  11046. hw_page_size))/hw_page_size;
  11047. INIT_LIST_HEAD(&queue->list);
  11048. INIT_LIST_HEAD(&queue->page_list);
  11049. INIT_LIST_HEAD(&queue->child_list);
  11050. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  11051. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  11052. if (!dmabuf)
  11053. goto out_fail;
  11054. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  11055. hw_page_size, &dmabuf->phys,
  11056. GFP_KERNEL);
  11057. if (!dmabuf->virt) {
  11058. kfree(dmabuf);
  11059. goto out_fail;
  11060. }
  11061. memset(dmabuf->virt, 0, hw_page_size);
  11062. dmabuf->buffer_tag = x;
  11063. list_add_tail(&dmabuf->list, &queue->page_list);
  11064. /* initialize queue's entry array */
  11065. dma_pointer = dmabuf->virt;
  11066. for (; total_qe_count < entry_count &&
  11067. dma_pointer < (hw_page_size + dmabuf->virt);
  11068. total_qe_count++, dma_pointer += entry_size) {
  11069. queue->qe[total_qe_count].address = dma_pointer;
  11070. }
  11071. }
  11072. queue->entry_size = entry_size;
  11073. queue->entry_count = entry_count;
  11074. /*
  11075. * entry_repost is calculated based on the number of entries in the
  11076. * queue. This works out except for RQs. If buffers are NOT initially
  11077. * posted for every RQE, entry_repost should be adjusted accordingly.
  11078. */
  11079. queue->entry_repost = (entry_count >> 3);
  11080. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  11081. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  11082. queue->phba = phba;
  11083. return queue;
  11084. out_fail:
  11085. lpfc_sli4_queue_free(queue);
  11086. return NULL;
  11087. }
  11088. /**
  11089. * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
  11090. * @phba: HBA structure that indicates port to create a queue on.
  11091. * @pci_barset: PCI BAR set flag.
  11092. *
  11093. * This function shall perform iomap of the specified PCI BAR address to host
  11094. * memory address if not already done so and return it. The returned host
  11095. * memory address can be NULL.
  11096. */
  11097. static void __iomem *
  11098. lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
  11099. {
  11100. struct pci_dev *pdev;
  11101. unsigned long bar_map, bar_map_len;
  11102. if (!phba->pcidev)
  11103. return NULL;
  11104. else
  11105. pdev = phba->pcidev;
  11106. switch (pci_barset) {
  11107. case WQ_PCI_BAR_0_AND_1:
  11108. if (!phba->pci_bar0_memmap_p) {
  11109. bar_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
  11110. bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
  11111. phba->pci_bar0_memmap_p = ioremap(bar_map, bar_map_len);
  11112. }
  11113. return phba->pci_bar0_memmap_p;
  11114. case WQ_PCI_BAR_2_AND_3:
  11115. if (!phba->pci_bar2_memmap_p) {
  11116. bar_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
  11117. bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
  11118. phba->pci_bar2_memmap_p = ioremap(bar_map, bar_map_len);
  11119. }
  11120. return phba->pci_bar2_memmap_p;
  11121. case WQ_PCI_BAR_4_AND_5:
  11122. if (!phba->pci_bar4_memmap_p) {
  11123. bar_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
  11124. bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
  11125. phba->pci_bar4_memmap_p = ioremap(bar_map, bar_map_len);
  11126. }
  11127. return phba->pci_bar4_memmap_p;
  11128. default:
  11129. break;
  11130. }
  11131. return NULL;
  11132. }
  11133. /**
  11134. * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
  11135. * @phba: HBA structure that indicates port to create a queue on.
  11136. * @startq: The starting FCP EQ to modify
  11137. *
  11138. * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
  11139. *
  11140. * The @phba struct is used to send mailbox command to HBA. The @startq
  11141. * is used to get the starting FCP EQ to change.
  11142. * This function is asynchronous and will wait for the mailbox
  11143. * command to finish before continuing.
  11144. *
  11145. * On success this function will return a zero. If unable to allocate enough
  11146. * memory this function will return -ENOMEM. If the queue create mailbox command
  11147. * fails this function will return -ENXIO.
  11148. **/
  11149. uint32_t
  11150. lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq)
  11151. {
  11152. struct lpfc_mbx_modify_eq_delay *eq_delay;
  11153. LPFC_MBOXQ_t *mbox;
  11154. struct lpfc_queue *eq;
  11155. int cnt, rc, length, status = 0;
  11156. uint32_t shdr_status, shdr_add_status;
  11157. uint32_t result;
  11158. int fcp_eqidx;
  11159. union lpfc_sli4_cfg_shdr *shdr;
  11160. uint16_t dmult;
  11161. if (startq >= phba->cfg_fcp_io_channel)
  11162. return 0;
  11163. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11164. if (!mbox)
  11165. return -ENOMEM;
  11166. length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
  11167. sizeof(struct lpfc_sli4_cfg_mhdr));
  11168. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11169. LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
  11170. length, LPFC_SLI4_MBX_EMBED);
  11171. eq_delay = &mbox->u.mqe.un.eq_delay;
  11172. /* Calculate delay multiper from maximum interrupt per second */
  11173. result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel;
  11174. if (result > LPFC_DMULT_CONST)
  11175. dmult = 0;
  11176. else
  11177. dmult = LPFC_DMULT_CONST/result - 1;
  11178. cnt = 0;
  11179. for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel;
  11180. fcp_eqidx++) {
  11181. eq = phba->sli4_hba.hba_eq[fcp_eqidx];
  11182. if (!eq)
  11183. continue;
  11184. eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
  11185. eq_delay->u.request.eq[cnt].phase = 0;
  11186. eq_delay->u.request.eq[cnt].delay_multi = dmult;
  11187. cnt++;
  11188. if (cnt >= LPFC_MAX_EQ_DELAY)
  11189. break;
  11190. }
  11191. eq_delay->u.request.num_eq = cnt;
  11192. mbox->vport = phba->pport;
  11193. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11194. mbox->context1 = NULL;
  11195. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11196. shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
  11197. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11198. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11199. if (shdr_status || shdr_add_status || rc) {
  11200. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11201. "2512 MODIFY_EQ_DELAY mailbox failed with "
  11202. "status x%x add_status x%x, mbx status x%x\n",
  11203. shdr_status, shdr_add_status, rc);
  11204. status = -ENXIO;
  11205. }
  11206. mempool_free(mbox, phba->mbox_mem_pool);
  11207. return status;
  11208. }
  11209. /**
  11210. * lpfc_eq_create - Create an Event Queue on the HBA
  11211. * @phba: HBA structure that indicates port to create a queue on.
  11212. * @eq: The queue structure to use to create the event queue.
  11213. * @imax: The maximum interrupt per second limit.
  11214. *
  11215. * This function creates an event queue, as detailed in @eq, on a port,
  11216. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  11217. *
  11218. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  11219. * is used to get the entry count and entry size that are necessary to
  11220. * determine the number of pages to allocate and use for this queue. This
  11221. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  11222. * event queue. This function is asynchronous and will wait for the mailbox
  11223. * command to finish before continuing.
  11224. *
  11225. * On success this function will return a zero. If unable to allocate enough
  11226. * memory this function will return -ENOMEM. If the queue create mailbox command
  11227. * fails this function will return -ENXIO.
  11228. **/
  11229. uint32_t
  11230. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
  11231. {
  11232. struct lpfc_mbx_eq_create *eq_create;
  11233. LPFC_MBOXQ_t *mbox;
  11234. int rc, length, status = 0;
  11235. struct lpfc_dmabuf *dmabuf;
  11236. uint32_t shdr_status, shdr_add_status;
  11237. union lpfc_sli4_cfg_shdr *shdr;
  11238. uint16_t dmult;
  11239. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11240. /* sanity check on queue memory */
  11241. if (!eq)
  11242. return -ENODEV;
  11243. if (!phba->sli4_hba.pc_sli4_params.supported)
  11244. hw_page_size = SLI4_PAGE_SIZE;
  11245. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11246. if (!mbox)
  11247. return -ENOMEM;
  11248. length = (sizeof(struct lpfc_mbx_eq_create) -
  11249. sizeof(struct lpfc_sli4_cfg_mhdr));
  11250. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11251. LPFC_MBOX_OPCODE_EQ_CREATE,
  11252. length, LPFC_SLI4_MBX_EMBED);
  11253. eq_create = &mbox->u.mqe.un.eq_create;
  11254. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  11255. eq->page_count);
  11256. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  11257. LPFC_EQE_SIZE);
  11258. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  11259. /* Calculate delay multiper from maximum interrupt per second */
  11260. if (imax > LPFC_DMULT_CONST)
  11261. dmult = 0;
  11262. else
  11263. dmult = LPFC_DMULT_CONST/imax - 1;
  11264. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  11265. dmult);
  11266. switch (eq->entry_count) {
  11267. default:
  11268. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11269. "0360 Unsupported EQ count. (%d)\n",
  11270. eq->entry_count);
  11271. if (eq->entry_count < 256)
  11272. return -EINVAL;
  11273. /* otherwise default to smallest count (drop through) */
  11274. case 256:
  11275. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11276. LPFC_EQ_CNT_256);
  11277. break;
  11278. case 512:
  11279. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11280. LPFC_EQ_CNT_512);
  11281. break;
  11282. case 1024:
  11283. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11284. LPFC_EQ_CNT_1024);
  11285. break;
  11286. case 2048:
  11287. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11288. LPFC_EQ_CNT_2048);
  11289. break;
  11290. case 4096:
  11291. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11292. LPFC_EQ_CNT_4096);
  11293. break;
  11294. }
  11295. list_for_each_entry(dmabuf, &eq->page_list, list) {
  11296. memset(dmabuf->virt, 0, hw_page_size);
  11297. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11298. putPaddrLow(dmabuf->phys);
  11299. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11300. putPaddrHigh(dmabuf->phys);
  11301. }
  11302. mbox->vport = phba->pport;
  11303. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11304. mbox->context1 = NULL;
  11305. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11306. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  11307. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11308. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11309. if (shdr_status || shdr_add_status || rc) {
  11310. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11311. "2500 EQ_CREATE mailbox failed with "
  11312. "status x%x add_status x%x, mbx status x%x\n",
  11313. shdr_status, shdr_add_status, rc);
  11314. status = -ENXIO;
  11315. }
  11316. eq->type = LPFC_EQ;
  11317. eq->subtype = LPFC_NONE;
  11318. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  11319. if (eq->queue_id == 0xFFFF)
  11320. status = -ENXIO;
  11321. eq->host_index = 0;
  11322. eq->hba_index = 0;
  11323. mempool_free(mbox, phba->mbox_mem_pool);
  11324. return status;
  11325. }
  11326. /**
  11327. * lpfc_cq_create - Create a Completion Queue on the HBA
  11328. * @phba: HBA structure that indicates port to create a queue on.
  11329. * @cq: The queue structure to use to create the completion queue.
  11330. * @eq: The event queue to bind this completion queue to.
  11331. *
  11332. * This function creates a completion queue, as detailed in @wq, on a port,
  11333. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  11334. *
  11335. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11336. * is used to get the entry count and entry size that are necessary to
  11337. * determine the number of pages to allocate and use for this queue. The @eq
  11338. * is used to indicate which event queue to bind this completion queue to. This
  11339. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  11340. * completion queue. This function is asynchronous and will wait for the mailbox
  11341. * command to finish before continuing.
  11342. *
  11343. * On success this function will return a zero. If unable to allocate enough
  11344. * memory this function will return -ENOMEM. If the queue create mailbox command
  11345. * fails this function will return -ENXIO.
  11346. **/
  11347. uint32_t
  11348. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11349. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  11350. {
  11351. struct lpfc_mbx_cq_create *cq_create;
  11352. struct lpfc_dmabuf *dmabuf;
  11353. LPFC_MBOXQ_t *mbox;
  11354. int rc, length, status = 0;
  11355. uint32_t shdr_status, shdr_add_status;
  11356. union lpfc_sli4_cfg_shdr *shdr;
  11357. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11358. /* sanity check on queue memory */
  11359. if (!cq || !eq)
  11360. return -ENODEV;
  11361. if (!phba->sli4_hba.pc_sli4_params.supported)
  11362. hw_page_size = SLI4_PAGE_SIZE;
  11363. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11364. if (!mbox)
  11365. return -ENOMEM;
  11366. length = (sizeof(struct lpfc_mbx_cq_create) -
  11367. sizeof(struct lpfc_sli4_cfg_mhdr));
  11368. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11369. LPFC_MBOX_OPCODE_CQ_CREATE,
  11370. length, LPFC_SLI4_MBX_EMBED);
  11371. cq_create = &mbox->u.mqe.un.cq_create;
  11372. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  11373. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  11374. cq->page_count);
  11375. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  11376. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  11377. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11378. phba->sli4_hba.pc_sli4_params.cqv);
  11379. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  11380. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  11381. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  11382. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  11383. eq->queue_id);
  11384. } else {
  11385. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  11386. eq->queue_id);
  11387. }
  11388. switch (cq->entry_count) {
  11389. default:
  11390. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11391. "0361 Unsupported CQ count. (%d)\n",
  11392. cq->entry_count);
  11393. if (cq->entry_count < 256) {
  11394. status = -EINVAL;
  11395. goto out;
  11396. }
  11397. /* otherwise default to smallest count (drop through) */
  11398. case 256:
  11399. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11400. LPFC_CQ_CNT_256);
  11401. break;
  11402. case 512:
  11403. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11404. LPFC_CQ_CNT_512);
  11405. break;
  11406. case 1024:
  11407. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11408. LPFC_CQ_CNT_1024);
  11409. break;
  11410. }
  11411. list_for_each_entry(dmabuf, &cq->page_list, list) {
  11412. memset(dmabuf->virt, 0, hw_page_size);
  11413. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11414. putPaddrLow(dmabuf->phys);
  11415. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11416. putPaddrHigh(dmabuf->phys);
  11417. }
  11418. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11419. /* The IOCTL status is embedded in the mailbox subheader. */
  11420. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11421. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11422. if (shdr_status || shdr_add_status || rc) {
  11423. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11424. "2501 CQ_CREATE mailbox failed with "
  11425. "status x%x add_status x%x, mbx status x%x\n",
  11426. shdr_status, shdr_add_status, rc);
  11427. status = -ENXIO;
  11428. goto out;
  11429. }
  11430. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11431. if (cq->queue_id == 0xFFFF) {
  11432. status = -ENXIO;
  11433. goto out;
  11434. }
  11435. /* link the cq onto the parent eq child list */
  11436. list_add_tail(&cq->list, &eq->child_list);
  11437. /* Set up completion queue's type and subtype */
  11438. cq->type = type;
  11439. cq->subtype = subtype;
  11440. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11441. cq->assoc_qid = eq->queue_id;
  11442. cq->host_index = 0;
  11443. cq->hba_index = 0;
  11444. out:
  11445. mempool_free(mbox, phba->mbox_mem_pool);
  11446. return status;
  11447. }
  11448. /**
  11449. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  11450. * @phba: HBA structure that indicates port to create a queue on.
  11451. * @mq: The queue structure to use to create the mailbox queue.
  11452. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  11453. * @cq: The completion queue to associate with this cq.
  11454. *
  11455. * This function provides failback (fb) functionality when the
  11456. * mq_create_ext fails on older FW generations. It's purpose is identical
  11457. * to mq_create_ext otherwise.
  11458. *
  11459. * This routine cannot fail as all attributes were previously accessed and
  11460. * initialized in mq_create_ext.
  11461. **/
  11462. static void
  11463. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11464. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  11465. {
  11466. struct lpfc_mbx_mq_create *mq_create;
  11467. struct lpfc_dmabuf *dmabuf;
  11468. int length;
  11469. length = (sizeof(struct lpfc_mbx_mq_create) -
  11470. sizeof(struct lpfc_sli4_cfg_mhdr));
  11471. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11472. LPFC_MBOX_OPCODE_MQ_CREATE,
  11473. length, LPFC_SLI4_MBX_EMBED);
  11474. mq_create = &mbox->u.mqe.un.mq_create;
  11475. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  11476. mq->page_count);
  11477. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  11478. cq->queue_id);
  11479. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  11480. switch (mq->entry_count) {
  11481. case 16:
  11482. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11483. LPFC_MQ_RING_SIZE_16);
  11484. break;
  11485. case 32:
  11486. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11487. LPFC_MQ_RING_SIZE_32);
  11488. break;
  11489. case 64:
  11490. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11491. LPFC_MQ_RING_SIZE_64);
  11492. break;
  11493. case 128:
  11494. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11495. LPFC_MQ_RING_SIZE_128);
  11496. break;
  11497. }
  11498. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11499. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11500. putPaddrLow(dmabuf->phys);
  11501. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11502. putPaddrHigh(dmabuf->phys);
  11503. }
  11504. }
  11505. /**
  11506. * lpfc_mq_create - Create a mailbox Queue on the HBA
  11507. * @phba: HBA structure that indicates port to create a queue on.
  11508. * @mq: The queue structure to use to create the mailbox queue.
  11509. * @cq: The completion queue to associate with this cq.
  11510. * @subtype: The queue's subtype.
  11511. *
  11512. * This function creates a mailbox queue, as detailed in @mq, on a port,
  11513. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  11514. *
  11515. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11516. * is used to get the entry count and entry size that are necessary to
  11517. * determine the number of pages to allocate and use for this queue. This
  11518. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  11519. * mailbox queue. This function is asynchronous and will wait for the mailbox
  11520. * command to finish before continuing.
  11521. *
  11522. * On success this function will return a zero. If unable to allocate enough
  11523. * memory this function will return -ENOMEM. If the queue create mailbox command
  11524. * fails this function will return -ENXIO.
  11525. **/
  11526. int32_t
  11527. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11528. struct lpfc_queue *cq, uint32_t subtype)
  11529. {
  11530. struct lpfc_mbx_mq_create *mq_create;
  11531. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  11532. struct lpfc_dmabuf *dmabuf;
  11533. LPFC_MBOXQ_t *mbox;
  11534. int rc, length, status = 0;
  11535. uint32_t shdr_status, shdr_add_status;
  11536. union lpfc_sli4_cfg_shdr *shdr;
  11537. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11538. /* sanity check on queue memory */
  11539. if (!mq || !cq)
  11540. return -ENODEV;
  11541. if (!phba->sli4_hba.pc_sli4_params.supported)
  11542. hw_page_size = SLI4_PAGE_SIZE;
  11543. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11544. if (!mbox)
  11545. return -ENOMEM;
  11546. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  11547. sizeof(struct lpfc_sli4_cfg_mhdr));
  11548. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11549. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  11550. length, LPFC_SLI4_MBX_EMBED);
  11551. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  11552. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  11553. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  11554. &mq_create_ext->u.request, mq->page_count);
  11555. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  11556. &mq_create_ext->u.request, 1);
  11557. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  11558. &mq_create_ext->u.request, 1);
  11559. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  11560. &mq_create_ext->u.request, 1);
  11561. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  11562. &mq_create_ext->u.request, 1);
  11563. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  11564. &mq_create_ext->u.request, 1);
  11565. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  11566. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11567. phba->sli4_hba.pc_sli4_params.mqv);
  11568. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  11569. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  11570. cq->queue_id);
  11571. else
  11572. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  11573. cq->queue_id);
  11574. switch (mq->entry_count) {
  11575. default:
  11576. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11577. "0362 Unsupported MQ count. (%d)\n",
  11578. mq->entry_count);
  11579. if (mq->entry_count < 16) {
  11580. status = -EINVAL;
  11581. goto out;
  11582. }
  11583. /* otherwise default to smallest count (drop through) */
  11584. case 16:
  11585. bf_set(lpfc_mq_context_ring_size,
  11586. &mq_create_ext->u.request.context,
  11587. LPFC_MQ_RING_SIZE_16);
  11588. break;
  11589. case 32:
  11590. bf_set(lpfc_mq_context_ring_size,
  11591. &mq_create_ext->u.request.context,
  11592. LPFC_MQ_RING_SIZE_32);
  11593. break;
  11594. case 64:
  11595. bf_set(lpfc_mq_context_ring_size,
  11596. &mq_create_ext->u.request.context,
  11597. LPFC_MQ_RING_SIZE_64);
  11598. break;
  11599. case 128:
  11600. bf_set(lpfc_mq_context_ring_size,
  11601. &mq_create_ext->u.request.context,
  11602. LPFC_MQ_RING_SIZE_128);
  11603. break;
  11604. }
  11605. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11606. memset(dmabuf->virt, 0, hw_page_size);
  11607. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  11608. putPaddrLow(dmabuf->phys);
  11609. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  11610. putPaddrHigh(dmabuf->phys);
  11611. }
  11612. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11613. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11614. &mq_create_ext->u.response);
  11615. if (rc != MBX_SUCCESS) {
  11616. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11617. "2795 MQ_CREATE_EXT failed with "
  11618. "status x%x. Failback to MQ_CREATE.\n",
  11619. rc);
  11620. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  11621. mq_create = &mbox->u.mqe.un.mq_create;
  11622. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11623. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  11624. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11625. &mq_create->u.response);
  11626. }
  11627. /* The IOCTL status is embedded in the mailbox subheader. */
  11628. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11629. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11630. if (shdr_status || shdr_add_status || rc) {
  11631. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11632. "2502 MQ_CREATE mailbox failed with "
  11633. "status x%x add_status x%x, mbx status x%x\n",
  11634. shdr_status, shdr_add_status, rc);
  11635. status = -ENXIO;
  11636. goto out;
  11637. }
  11638. if (mq->queue_id == 0xFFFF) {
  11639. status = -ENXIO;
  11640. goto out;
  11641. }
  11642. mq->type = LPFC_MQ;
  11643. mq->assoc_qid = cq->queue_id;
  11644. mq->subtype = subtype;
  11645. mq->host_index = 0;
  11646. mq->hba_index = 0;
  11647. /* link the mq onto the parent cq child list */
  11648. list_add_tail(&mq->list, &cq->child_list);
  11649. out:
  11650. mempool_free(mbox, phba->mbox_mem_pool);
  11651. return status;
  11652. }
  11653. /**
  11654. * lpfc_wq_create - Create a Work Queue on the HBA
  11655. * @phba: HBA structure that indicates port to create a queue on.
  11656. * @wq: The queue structure to use to create the work queue.
  11657. * @cq: The completion queue to bind this work queue to.
  11658. * @subtype: The subtype of the work queue indicating its functionality.
  11659. *
  11660. * This function creates a work queue, as detailed in @wq, on a port, described
  11661. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  11662. *
  11663. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  11664. * is used to get the entry count and entry size that are necessary to
  11665. * determine the number of pages to allocate and use for this queue. The @cq
  11666. * is used to indicate which completion queue to bind this work queue to. This
  11667. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  11668. * work queue. This function is asynchronous and will wait for the mailbox
  11669. * command to finish before continuing.
  11670. *
  11671. * On success this function will return a zero. If unable to allocate enough
  11672. * memory this function will return -ENOMEM. If the queue create mailbox command
  11673. * fails this function will return -ENXIO.
  11674. **/
  11675. uint32_t
  11676. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  11677. struct lpfc_queue *cq, uint32_t subtype)
  11678. {
  11679. struct lpfc_mbx_wq_create *wq_create;
  11680. struct lpfc_dmabuf *dmabuf;
  11681. LPFC_MBOXQ_t *mbox;
  11682. int rc, length, status = 0;
  11683. uint32_t shdr_status, shdr_add_status;
  11684. union lpfc_sli4_cfg_shdr *shdr;
  11685. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11686. struct dma_address *page;
  11687. void __iomem *bar_memmap_p;
  11688. uint32_t db_offset;
  11689. uint16_t pci_barset;
  11690. /* sanity check on queue memory */
  11691. if (!wq || !cq)
  11692. return -ENODEV;
  11693. if (!phba->sli4_hba.pc_sli4_params.supported)
  11694. hw_page_size = SLI4_PAGE_SIZE;
  11695. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11696. if (!mbox)
  11697. return -ENOMEM;
  11698. length = (sizeof(struct lpfc_mbx_wq_create) -
  11699. sizeof(struct lpfc_sli4_cfg_mhdr));
  11700. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11701. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  11702. length, LPFC_SLI4_MBX_EMBED);
  11703. wq_create = &mbox->u.mqe.un.wq_create;
  11704. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  11705. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  11706. wq->page_count);
  11707. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  11708. cq->queue_id);
  11709. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11710. phba->sli4_hba.pc_sli4_params.wqv);
  11711. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  11712. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  11713. wq->entry_count);
  11714. switch (wq->entry_size) {
  11715. default:
  11716. case 64:
  11717. bf_set(lpfc_mbx_wq_create_wqe_size,
  11718. &wq_create->u.request_1,
  11719. LPFC_WQ_WQE_SIZE_64);
  11720. break;
  11721. case 128:
  11722. bf_set(lpfc_mbx_wq_create_wqe_size,
  11723. &wq_create->u.request_1,
  11724. LPFC_WQ_WQE_SIZE_128);
  11725. break;
  11726. }
  11727. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  11728. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11729. page = wq_create->u.request_1.page;
  11730. } else {
  11731. page = wq_create->u.request.page;
  11732. }
  11733. list_for_each_entry(dmabuf, &wq->page_list, list) {
  11734. memset(dmabuf->virt, 0, hw_page_size);
  11735. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  11736. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  11737. }
  11738. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  11739. bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
  11740. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11741. /* The IOCTL status is embedded in the mailbox subheader. */
  11742. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11743. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11744. if (shdr_status || shdr_add_status || rc) {
  11745. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11746. "2503 WQ_CREATE mailbox failed with "
  11747. "status x%x add_status x%x, mbx status x%x\n",
  11748. shdr_status, shdr_add_status, rc);
  11749. status = -ENXIO;
  11750. goto out;
  11751. }
  11752. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  11753. if (wq->queue_id == 0xFFFF) {
  11754. status = -ENXIO;
  11755. goto out;
  11756. }
  11757. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  11758. wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
  11759. &wq_create->u.response);
  11760. if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
  11761. (wq->db_format != LPFC_DB_RING_FORMAT)) {
  11762. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11763. "3265 WQ[%d] doorbell format not "
  11764. "supported: x%x\n", wq->queue_id,
  11765. wq->db_format);
  11766. status = -EINVAL;
  11767. goto out;
  11768. }
  11769. pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
  11770. &wq_create->u.response);
  11771. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  11772. if (!bar_memmap_p) {
  11773. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11774. "3263 WQ[%d] failed to memmap pci "
  11775. "barset:x%x\n", wq->queue_id,
  11776. pci_barset);
  11777. status = -ENOMEM;
  11778. goto out;
  11779. }
  11780. db_offset = wq_create->u.response.doorbell_offset;
  11781. if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
  11782. (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
  11783. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11784. "3252 WQ[%d] doorbell offset not "
  11785. "supported: x%x\n", wq->queue_id,
  11786. db_offset);
  11787. status = -EINVAL;
  11788. goto out;
  11789. }
  11790. wq->db_regaddr = bar_memmap_p + db_offset;
  11791. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11792. "3264 WQ[%d]: barset:x%x, offset:x%x\n",
  11793. wq->queue_id, pci_barset, db_offset);
  11794. } else {
  11795. wq->db_format = LPFC_DB_LIST_FORMAT;
  11796. wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
  11797. }
  11798. wq->type = LPFC_WQ;
  11799. wq->assoc_qid = cq->queue_id;
  11800. wq->subtype = subtype;
  11801. wq->host_index = 0;
  11802. wq->hba_index = 0;
  11803. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  11804. /* link the wq onto the parent cq child list */
  11805. list_add_tail(&wq->list, &cq->child_list);
  11806. out:
  11807. mempool_free(mbox, phba->mbox_mem_pool);
  11808. return status;
  11809. }
  11810. /**
  11811. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  11812. * @phba: HBA structure that indicates port to create a queue on.
  11813. * @rq: The queue structure to use for the receive queue.
  11814. * @qno: The associated HBQ number
  11815. *
  11816. *
  11817. * For SLI4 we need to adjust the RQ repost value based on
  11818. * the number of buffers that are initially posted to the RQ.
  11819. */
  11820. void
  11821. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  11822. {
  11823. uint32_t cnt;
  11824. /* sanity check on queue memory */
  11825. if (!rq)
  11826. return;
  11827. cnt = lpfc_hbq_defs[qno]->entry_count;
  11828. /* Recalc repost for RQs based on buffers initially posted */
  11829. cnt = (cnt >> 3);
  11830. if (cnt < LPFC_QUEUE_MIN_REPOST)
  11831. cnt = LPFC_QUEUE_MIN_REPOST;
  11832. rq->entry_repost = cnt;
  11833. }
  11834. /**
  11835. * lpfc_rq_create - Create a Receive Queue on the HBA
  11836. * @phba: HBA structure that indicates port to create a queue on.
  11837. * @hrq: The queue structure to use to create the header receive queue.
  11838. * @drq: The queue structure to use to create the data receive queue.
  11839. * @cq: The completion queue to bind this work queue to.
  11840. *
  11841. * This function creates a receive buffer queue pair , as detailed in @hrq and
  11842. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  11843. * to the HBA.
  11844. *
  11845. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  11846. * struct is used to get the entry count that is necessary to determine the
  11847. * number of pages to use for this queue. The @cq is used to indicate which
  11848. * completion queue to bind received buffers that are posted to these queues to.
  11849. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  11850. * receive queue pair. This function is asynchronous and will wait for the
  11851. * mailbox command to finish before continuing.
  11852. *
  11853. * On success this function will return a zero. If unable to allocate enough
  11854. * memory this function will return -ENOMEM. If the queue create mailbox command
  11855. * fails this function will return -ENXIO.
  11856. **/
  11857. uint32_t
  11858. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11859. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  11860. {
  11861. struct lpfc_mbx_rq_create *rq_create;
  11862. struct lpfc_dmabuf *dmabuf;
  11863. LPFC_MBOXQ_t *mbox;
  11864. int rc, length, status = 0;
  11865. uint32_t shdr_status, shdr_add_status;
  11866. union lpfc_sli4_cfg_shdr *shdr;
  11867. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11868. void __iomem *bar_memmap_p;
  11869. uint32_t db_offset;
  11870. uint16_t pci_barset;
  11871. /* sanity check on queue memory */
  11872. if (!hrq || !drq || !cq)
  11873. return -ENODEV;
  11874. if (!phba->sli4_hba.pc_sli4_params.supported)
  11875. hw_page_size = SLI4_PAGE_SIZE;
  11876. if (hrq->entry_count != drq->entry_count)
  11877. return -EINVAL;
  11878. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11879. if (!mbox)
  11880. return -ENOMEM;
  11881. length = (sizeof(struct lpfc_mbx_rq_create) -
  11882. sizeof(struct lpfc_sli4_cfg_mhdr));
  11883. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11884. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11885. length, LPFC_SLI4_MBX_EMBED);
  11886. rq_create = &mbox->u.mqe.un.rq_create;
  11887. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11888. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11889. phba->sli4_hba.pc_sli4_params.rqv);
  11890. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11891. bf_set(lpfc_rq_context_rqe_count_1,
  11892. &rq_create->u.request.context,
  11893. hrq->entry_count);
  11894. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  11895. bf_set(lpfc_rq_context_rqe_size,
  11896. &rq_create->u.request.context,
  11897. LPFC_RQE_SIZE_8);
  11898. bf_set(lpfc_rq_context_page_size,
  11899. &rq_create->u.request.context,
  11900. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11901. } else {
  11902. switch (hrq->entry_count) {
  11903. default:
  11904. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11905. "2535 Unsupported RQ count. (%d)\n",
  11906. hrq->entry_count);
  11907. if (hrq->entry_count < 512) {
  11908. status = -EINVAL;
  11909. goto out;
  11910. }
  11911. /* otherwise default to smallest count (drop through) */
  11912. case 512:
  11913. bf_set(lpfc_rq_context_rqe_count,
  11914. &rq_create->u.request.context,
  11915. LPFC_RQ_RING_SIZE_512);
  11916. break;
  11917. case 1024:
  11918. bf_set(lpfc_rq_context_rqe_count,
  11919. &rq_create->u.request.context,
  11920. LPFC_RQ_RING_SIZE_1024);
  11921. break;
  11922. case 2048:
  11923. bf_set(lpfc_rq_context_rqe_count,
  11924. &rq_create->u.request.context,
  11925. LPFC_RQ_RING_SIZE_2048);
  11926. break;
  11927. case 4096:
  11928. bf_set(lpfc_rq_context_rqe_count,
  11929. &rq_create->u.request.context,
  11930. LPFC_RQ_RING_SIZE_4096);
  11931. break;
  11932. }
  11933. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11934. LPFC_HDR_BUF_SIZE);
  11935. }
  11936. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11937. cq->queue_id);
  11938. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11939. hrq->page_count);
  11940. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  11941. memset(dmabuf->virt, 0, hw_page_size);
  11942. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11943. putPaddrLow(dmabuf->phys);
  11944. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11945. putPaddrHigh(dmabuf->phys);
  11946. }
  11947. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  11948. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  11949. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11950. /* The IOCTL status is embedded in the mailbox subheader. */
  11951. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11952. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11953. if (shdr_status || shdr_add_status || rc) {
  11954. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11955. "2504 RQ_CREATE mailbox failed with "
  11956. "status x%x add_status x%x, mbx status x%x\n",
  11957. shdr_status, shdr_add_status, rc);
  11958. status = -ENXIO;
  11959. goto out;
  11960. }
  11961. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11962. if (hrq->queue_id == 0xFFFF) {
  11963. status = -ENXIO;
  11964. goto out;
  11965. }
  11966. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  11967. hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
  11968. &rq_create->u.response);
  11969. if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
  11970. (hrq->db_format != LPFC_DB_RING_FORMAT)) {
  11971. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11972. "3262 RQ [%d] doorbell format not "
  11973. "supported: x%x\n", hrq->queue_id,
  11974. hrq->db_format);
  11975. status = -EINVAL;
  11976. goto out;
  11977. }
  11978. pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
  11979. &rq_create->u.response);
  11980. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  11981. if (!bar_memmap_p) {
  11982. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11983. "3269 RQ[%d] failed to memmap pci "
  11984. "barset:x%x\n", hrq->queue_id,
  11985. pci_barset);
  11986. status = -ENOMEM;
  11987. goto out;
  11988. }
  11989. db_offset = rq_create->u.response.doorbell_offset;
  11990. if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
  11991. (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
  11992. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11993. "3270 RQ[%d] doorbell offset not "
  11994. "supported: x%x\n", hrq->queue_id,
  11995. db_offset);
  11996. status = -EINVAL;
  11997. goto out;
  11998. }
  11999. hrq->db_regaddr = bar_memmap_p + db_offset;
  12000. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12001. "3266 RQ[qid:%d]: barset:x%x, offset:x%x\n",
  12002. hrq->queue_id, pci_barset, db_offset);
  12003. } else {
  12004. hrq->db_format = LPFC_DB_RING_FORMAT;
  12005. hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
  12006. }
  12007. hrq->type = LPFC_HRQ;
  12008. hrq->assoc_qid = cq->queue_id;
  12009. hrq->subtype = subtype;
  12010. hrq->host_index = 0;
  12011. hrq->hba_index = 0;
  12012. /* now create the data queue */
  12013. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12014. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  12015. length, LPFC_SLI4_MBX_EMBED);
  12016. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12017. phba->sli4_hba.pc_sli4_params.rqv);
  12018. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  12019. bf_set(lpfc_rq_context_rqe_count_1,
  12020. &rq_create->u.request.context, hrq->entry_count);
  12021. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  12022. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  12023. LPFC_RQE_SIZE_8);
  12024. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  12025. (PAGE_SIZE/SLI4_PAGE_SIZE));
  12026. } else {
  12027. switch (drq->entry_count) {
  12028. default:
  12029. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12030. "2536 Unsupported RQ count. (%d)\n",
  12031. drq->entry_count);
  12032. if (drq->entry_count < 512) {
  12033. status = -EINVAL;
  12034. goto out;
  12035. }
  12036. /* otherwise default to smallest count (drop through) */
  12037. case 512:
  12038. bf_set(lpfc_rq_context_rqe_count,
  12039. &rq_create->u.request.context,
  12040. LPFC_RQ_RING_SIZE_512);
  12041. break;
  12042. case 1024:
  12043. bf_set(lpfc_rq_context_rqe_count,
  12044. &rq_create->u.request.context,
  12045. LPFC_RQ_RING_SIZE_1024);
  12046. break;
  12047. case 2048:
  12048. bf_set(lpfc_rq_context_rqe_count,
  12049. &rq_create->u.request.context,
  12050. LPFC_RQ_RING_SIZE_2048);
  12051. break;
  12052. case 4096:
  12053. bf_set(lpfc_rq_context_rqe_count,
  12054. &rq_create->u.request.context,
  12055. LPFC_RQ_RING_SIZE_4096);
  12056. break;
  12057. }
  12058. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  12059. LPFC_DATA_BUF_SIZE);
  12060. }
  12061. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  12062. cq->queue_id);
  12063. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  12064. drq->page_count);
  12065. list_for_each_entry(dmabuf, &drq->page_list, list) {
  12066. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12067. putPaddrLow(dmabuf->phys);
  12068. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12069. putPaddrHigh(dmabuf->phys);
  12070. }
  12071. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12072. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  12073. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12074. /* The IOCTL status is embedded in the mailbox subheader. */
  12075. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  12076. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12077. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12078. if (shdr_status || shdr_add_status || rc) {
  12079. status = -ENXIO;
  12080. goto out;
  12081. }
  12082. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  12083. if (drq->queue_id == 0xFFFF) {
  12084. status = -ENXIO;
  12085. goto out;
  12086. }
  12087. drq->type = LPFC_DRQ;
  12088. drq->assoc_qid = cq->queue_id;
  12089. drq->subtype = subtype;
  12090. drq->host_index = 0;
  12091. drq->hba_index = 0;
  12092. /* link the header and data RQs onto the parent cq child list */
  12093. list_add_tail(&hrq->list, &cq->child_list);
  12094. list_add_tail(&drq->list, &cq->child_list);
  12095. out:
  12096. mempool_free(mbox, phba->mbox_mem_pool);
  12097. return status;
  12098. }
  12099. /**
  12100. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  12101. * @eq: The queue structure associated with the queue to destroy.
  12102. *
  12103. * This function destroys a queue, as detailed in @eq by sending an mailbox
  12104. * command, specific to the type of queue, to the HBA.
  12105. *
  12106. * The @eq struct is used to get the queue ID of the queue to destroy.
  12107. *
  12108. * On success this function will return a zero. If the queue destroy mailbox
  12109. * command fails this function will return -ENXIO.
  12110. **/
  12111. uint32_t
  12112. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  12113. {
  12114. LPFC_MBOXQ_t *mbox;
  12115. int rc, length, status = 0;
  12116. uint32_t shdr_status, shdr_add_status;
  12117. union lpfc_sli4_cfg_shdr *shdr;
  12118. /* sanity check on queue memory */
  12119. if (!eq)
  12120. return -ENODEV;
  12121. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  12122. if (!mbox)
  12123. return -ENOMEM;
  12124. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  12125. sizeof(struct lpfc_sli4_cfg_mhdr));
  12126. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12127. LPFC_MBOX_OPCODE_EQ_DESTROY,
  12128. length, LPFC_SLI4_MBX_EMBED);
  12129. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  12130. eq->queue_id);
  12131. mbox->vport = eq->phba->pport;
  12132. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12133. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  12134. /* The IOCTL status is embedded in the mailbox subheader. */
  12135. shdr = (union lpfc_sli4_cfg_shdr *)
  12136. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  12137. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12138. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12139. if (shdr_status || shdr_add_status || rc) {
  12140. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12141. "2505 EQ_DESTROY mailbox failed with "
  12142. "status x%x add_status x%x, mbx status x%x\n",
  12143. shdr_status, shdr_add_status, rc);
  12144. status = -ENXIO;
  12145. }
  12146. /* Remove eq from any list */
  12147. list_del_init(&eq->list);
  12148. mempool_free(mbox, eq->phba->mbox_mem_pool);
  12149. return status;
  12150. }
  12151. /**
  12152. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  12153. * @cq: The queue structure associated with the queue to destroy.
  12154. *
  12155. * This function destroys a queue, as detailed in @cq by sending an mailbox
  12156. * command, specific to the type of queue, to the HBA.
  12157. *
  12158. * The @cq struct is used to get the queue ID of the queue to destroy.
  12159. *
  12160. * On success this function will return a zero. If the queue destroy mailbox
  12161. * command fails this function will return -ENXIO.
  12162. **/
  12163. uint32_t
  12164. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  12165. {
  12166. LPFC_MBOXQ_t *mbox;
  12167. int rc, length, status = 0;
  12168. uint32_t shdr_status, shdr_add_status;
  12169. union lpfc_sli4_cfg_shdr *shdr;
  12170. /* sanity check on queue memory */
  12171. if (!cq)
  12172. return -ENODEV;
  12173. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  12174. if (!mbox)
  12175. return -ENOMEM;
  12176. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  12177. sizeof(struct lpfc_sli4_cfg_mhdr));
  12178. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12179. LPFC_MBOX_OPCODE_CQ_DESTROY,
  12180. length, LPFC_SLI4_MBX_EMBED);
  12181. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  12182. cq->queue_id);
  12183. mbox->vport = cq->phba->pport;
  12184. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12185. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  12186. /* The IOCTL status is embedded in the mailbox subheader. */
  12187. shdr = (union lpfc_sli4_cfg_shdr *)
  12188. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  12189. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12190. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12191. if (shdr_status || shdr_add_status || rc) {
  12192. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12193. "2506 CQ_DESTROY mailbox failed with "
  12194. "status x%x add_status x%x, mbx status x%x\n",
  12195. shdr_status, shdr_add_status, rc);
  12196. status = -ENXIO;
  12197. }
  12198. /* Remove cq from any list */
  12199. list_del_init(&cq->list);
  12200. mempool_free(mbox, cq->phba->mbox_mem_pool);
  12201. return status;
  12202. }
  12203. /**
  12204. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  12205. * @qm: The queue structure associated with the queue to destroy.
  12206. *
  12207. * This function destroys a queue, as detailed in @mq by sending an mailbox
  12208. * command, specific to the type of queue, to the HBA.
  12209. *
  12210. * The @mq struct is used to get the queue ID of the queue to destroy.
  12211. *
  12212. * On success this function will return a zero. If the queue destroy mailbox
  12213. * command fails this function will return -ENXIO.
  12214. **/
  12215. uint32_t
  12216. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  12217. {
  12218. LPFC_MBOXQ_t *mbox;
  12219. int rc, length, status = 0;
  12220. uint32_t shdr_status, shdr_add_status;
  12221. union lpfc_sli4_cfg_shdr *shdr;
  12222. /* sanity check on queue memory */
  12223. if (!mq)
  12224. return -ENODEV;
  12225. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  12226. if (!mbox)
  12227. return -ENOMEM;
  12228. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  12229. sizeof(struct lpfc_sli4_cfg_mhdr));
  12230. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12231. LPFC_MBOX_OPCODE_MQ_DESTROY,
  12232. length, LPFC_SLI4_MBX_EMBED);
  12233. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  12234. mq->queue_id);
  12235. mbox->vport = mq->phba->pport;
  12236. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12237. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  12238. /* The IOCTL status is embedded in the mailbox subheader. */
  12239. shdr = (union lpfc_sli4_cfg_shdr *)
  12240. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  12241. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12242. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12243. if (shdr_status || shdr_add_status || rc) {
  12244. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12245. "2507 MQ_DESTROY mailbox failed with "
  12246. "status x%x add_status x%x, mbx status x%x\n",
  12247. shdr_status, shdr_add_status, rc);
  12248. status = -ENXIO;
  12249. }
  12250. /* Remove mq from any list */
  12251. list_del_init(&mq->list);
  12252. mempool_free(mbox, mq->phba->mbox_mem_pool);
  12253. return status;
  12254. }
  12255. /**
  12256. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  12257. * @wq: The queue structure associated with the queue to destroy.
  12258. *
  12259. * This function destroys a queue, as detailed in @wq by sending an mailbox
  12260. * command, specific to the type of queue, to the HBA.
  12261. *
  12262. * The @wq struct is used to get the queue ID of the queue to destroy.
  12263. *
  12264. * On success this function will return a zero. If the queue destroy mailbox
  12265. * command fails this function will return -ENXIO.
  12266. **/
  12267. uint32_t
  12268. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  12269. {
  12270. LPFC_MBOXQ_t *mbox;
  12271. int rc, length, status = 0;
  12272. uint32_t shdr_status, shdr_add_status;
  12273. union lpfc_sli4_cfg_shdr *shdr;
  12274. /* sanity check on queue memory */
  12275. if (!wq)
  12276. return -ENODEV;
  12277. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  12278. if (!mbox)
  12279. return -ENOMEM;
  12280. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  12281. sizeof(struct lpfc_sli4_cfg_mhdr));
  12282. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12283. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  12284. length, LPFC_SLI4_MBX_EMBED);
  12285. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  12286. wq->queue_id);
  12287. mbox->vport = wq->phba->pport;
  12288. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12289. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  12290. shdr = (union lpfc_sli4_cfg_shdr *)
  12291. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  12292. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12293. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12294. if (shdr_status || shdr_add_status || rc) {
  12295. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12296. "2508 WQ_DESTROY mailbox failed with "
  12297. "status x%x add_status x%x, mbx status x%x\n",
  12298. shdr_status, shdr_add_status, rc);
  12299. status = -ENXIO;
  12300. }
  12301. /* Remove wq from any list */
  12302. list_del_init(&wq->list);
  12303. mempool_free(mbox, wq->phba->mbox_mem_pool);
  12304. return status;
  12305. }
  12306. /**
  12307. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  12308. * @rq: The queue structure associated with the queue to destroy.
  12309. *
  12310. * This function destroys a queue, as detailed in @rq by sending an mailbox
  12311. * command, specific to the type of queue, to the HBA.
  12312. *
  12313. * The @rq struct is used to get the queue ID of the queue to destroy.
  12314. *
  12315. * On success this function will return a zero. If the queue destroy mailbox
  12316. * command fails this function will return -ENXIO.
  12317. **/
  12318. uint32_t
  12319. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  12320. struct lpfc_queue *drq)
  12321. {
  12322. LPFC_MBOXQ_t *mbox;
  12323. int rc, length, status = 0;
  12324. uint32_t shdr_status, shdr_add_status;
  12325. union lpfc_sli4_cfg_shdr *shdr;
  12326. /* sanity check on queue memory */
  12327. if (!hrq || !drq)
  12328. return -ENODEV;
  12329. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  12330. if (!mbox)
  12331. return -ENOMEM;
  12332. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  12333. sizeof(struct lpfc_sli4_cfg_mhdr));
  12334. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12335. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  12336. length, LPFC_SLI4_MBX_EMBED);
  12337. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12338. hrq->queue_id);
  12339. mbox->vport = hrq->phba->pport;
  12340. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12341. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  12342. /* The IOCTL status is embedded in the mailbox subheader. */
  12343. shdr = (union lpfc_sli4_cfg_shdr *)
  12344. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12345. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12346. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12347. if (shdr_status || shdr_add_status || rc) {
  12348. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12349. "2509 RQ_DESTROY mailbox failed with "
  12350. "status x%x add_status x%x, mbx status x%x\n",
  12351. shdr_status, shdr_add_status, rc);
  12352. if (rc != MBX_TIMEOUT)
  12353. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12354. return -ENXIO;
  12355. }
  12356. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12357. drq->queue_id);
  12358. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  12359. shdr = (union lpfc_sli4_cfg_shdr *)
  12360. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12361. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12362. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12363. if (shdr_status || shdr_add_status || rc) {
  12364. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12365. "2510 RQ_DESTROY mailbox failed with "
  12366. "status x%x add_status x%x, mbx status x%x\n",
  12367. shdr_status, shdr_add_status, rc);
  12368. status = -ENXIO;
  12369. }
  12370. list_del_init(&hrq->list);
  12371. list_del_init(&drq->list);
  12372. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12373. return status;
  12374. }
  12375. /**
  12376. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  12377. * @phba: The virtual port for which this call being executed.
  12378. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  12379. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  12380. * @xritag: the xritag that ties this io to the SGL pages.
  12381. *
  12382. * This routine will post the sgl pages for the IO that has the xritag
  12383. * that is in the iocbq structure. The xritag is assigned during iocbq
  12384. * creation and persists for as long as the driver is loaded.
  12385. * if the caller has fewer than 256 scatter gather segments to map then
  12386. * pdma_phys_addr1 should be 0.
  12387. * If the caller needs to map more than 256 scatter gather segment then
  12388. * pdma_phys_addr1 should be a valid physical address.
  12389. * physical address for SGLs must be 64 byte aligned.
  12390. * If you are going to map 2 SGL's then the first one must have 256 entries
  12391. * the second sgl can have between 1 and 256 entries.
  12392. *
  12393. * Return codes:
  12394. * 0 - Success
  12395. * -ENXIO, -ENOMEM - Failure
  12396. **/
  12397. int
  12398. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  12399. dma_addr_t pdma_phys_addr0,
  12400. dma_addr_t pdma_phys_addr1,
  12401. uint16_t xritag)
  12402. {
  12403. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  12404. LPFC_MBOXQ_t *mbox;
  12405. int rc;
  12406. uint32_t shdr_status, shdr_add_status;
  12407. uint32_t mbox_tmo;
  12408. union lpfc_sli4_cfg_shdr *shdr;
  12409. if (xritag == NO_XRI) {
  12410. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12411. "0364 Invalid param:\n");
  12412. return -EINVAL;
  12413. }
  12414. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12415. if (!mbox)
  12416. return -ENOMEM;
  12417. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12418. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  12419. sizeof(struct lpfc_mbx_post_sgl_pages) -
  12420. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  12421. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  12422. &mbox->u.mqe.un.post_sgl_pages;
  12423. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  12424. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  12425. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  12426. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  12427. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  12428. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  12429. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  12430. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  12431. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  12432. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  12433. if (!phba->sli4_hba.intr_enable)
  12434. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12435. else {
  12436. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12437. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12438. }
  12439. /* The IOCTL status is embedded in the mailbox subheader. */
  12440. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  12441. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12442. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12443. if (rc != MBX_TIMEOUT)
  12444. mempool_free(mbox, phba->mbox_mem_pool);
  12445. if (shdr_status || shdr_add_status || rc) {
  12446. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12447. "2511 POST_SGL mailbox failed with "
  12448. "status x%x add_status x%x, mbx status x%x\n",
  12449. shdr_status, shdr_add_status, rc);
  12450. rc = -ENXIO;
  12451. }
  12452. return 0;
  12453. }
  12454. /**
  12455. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  12456. * @phba: pointer to lpfc hba data structure.
  12457. *
  12458. * This routine is invoked to post rpi header templates to the
  12459. * HBA consistent with the SLI-4 interface spec. This routine
  12460. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  12461. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  12462. *
  12463. * Returns
  12464. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  12465. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  12466. **/
  12467. uint16_t
  12468. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  12469. {
  12470. unsigned long xri;
  12471. /*
  12472. * Fetch the next logical xri. Because this index is logical,
  12473. * the driver starts at 0 each time.
  12474. */
  12475. spin_lock_irq(&phba->hbalock);
  12476. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  12477. phba->sli4_hba.max_cfg_param.max_xri, 0);
  12478. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  12479. spin_unlock_irq(&phba->hbalock);
  12480. return NO_XRI;
  12481. } else {
  12482. set_bit(xri, phba->sli4_hba.xri_bmask);
  12483. phba->sli4_hba.max_cfg_param.xri_used++;
  12484. }
  12485. spin_unlock_irq(&phba->hbalock);
  12486. return xri;
  12487. }
  12488. /**
  12489. * lpfc_sli4_free_xri - Release an xri for reuse.
  12490. * @phba: pointer to lpfc hba data structure.
  12491. *
  12492. * This routine is invoked to release an xri to the pool of
  12493. * available rpis maintained by the driver.
  12494. **/
  12495. void
  12496. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12497. {
  12498. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  12499. phba->sli4_hba.max_cfg_param.xri_used--;
  12500. }
  12501. }
  12502. /**
  12503. * lpfc_sli4_free_xri - Release an xri for reuse.
  12504. * @phba: pointer to lpfc hba data structure.
  12505. *
  12506. * This routine is invoked to release an xri to the pool of
  12507. * available rpis maintained by the driver.
  12508. **/
  12509. void
  12510. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12511. {
  12512. spin_lock_irq(&phba->hbalock);
  12513. __lpfc_sli4_free_xri(phba, xri);
  12514. spin_unlock_irq(&phba->hbalock);
  12515. }
  12516. /**
  12517. * lpfc_sli4_next_xritag - Get an xritag for the io
  12518. * @phba: Pointer to HBA context object.
  12519. *
  12520. * This function gets an xritag for the iocb. If there is no unused xritag
  12521. * it will return 0xffff.
  12522. * The function returns the allocated xritag if successful, else returns zero.
  12523. * Zero is not a valid xritag.
  12524. * The caller is not required to hold any lock.
  12525. **/
  12526. uint16_t
  12527. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  12528. {
  12529. uint16_t xri_index;
  12530. xri_index = lpfc_sli4_alloc_xri(phba);
  12531. if (xri_index == NO_XRI)
  12532. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  12533. "2004 Failed to allocate XRI.last XRITAG is %d"
  12534. " Max XRI is %d, Used XRI is %d\n",
  12535. xri_index,
  12536. phba->sli4_hba.max_cfg_param.max_xri,
  12537. phba->sli4_hba.max_cfg_param.xri_used);
  12538. return xri_index;
  12539. }
  12540. /**
  12541. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  12542. * @phba: pointer to lpfc hba data structure.
  12543. * @post_sgl_list: pointer to els sgl entry list.
  12544. * @count: number of els sgl entries on the list.
  12545. *
  12546. * This routine is invoked to post a block of driver's sgl pages to the
  12547. * HBA using non-embedded mailbox command. No Lock is held. This routine
  12548. * is only called when the driver is loading and after all IO has been
  12549. * stopped.
  12550. **/
  12551. static int
  12552. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
  12553. struct list_head *post_sgl_list,
  12554. int post_cnt)
  12555. {
  12556. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  12557. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12558. struct sgl_page_pairs *sgl_pg_pairs;
  12559. void *viraddr;
  12560. LPFC_MBOXQ_t *mbox;
  12561. uint32_t reqlen, alloclen, pg_pairs;
  12562. uint32_t mbox_tmo;
  12563. uint16_t xritag_start = 0;
  12564. int rc = 0;
  12565. uint32_t shdr_status, shdr_add_status;
  12566. union lpfc_sli4_cfg_shdr *shdr;
  12567. reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
  12568. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12569. if (reqlen > SLI4_PAGE_SIZE) {
  12570. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12571. "2559 Block sgl registration required DMA "
  12572. "size (%d) great than a page\n", reqlen);
  12573. return -ENOMEM;
  12574. }
  12575. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12576. if (!mbox)
  12577. return -ENOMEM;
  12578. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12579. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12580. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12581. LPFC_SLI4_MBX_NEMBED);
  12582. if (alloclen < reqlen) {
  12583. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12584. "0285 Allocated DMA memory size (%d) is "
  12585. "less than the requested DMA memory "
  12586. "size (%d)\n", alloclen, reqlen);
  12587. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12588. return -ENOMEM;
  12589. }
  12590. /* Set up the SGL pages in the non-embedded DMA pages */
  12591. viraddr = mbox->sge_array->addr[0];
  12592. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12593. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12594. pg_pairs = 0;
  12595. list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
  12596. /* Set up the sge entry */
  12597. sgl_pg_pairs->sgl_pg0_addr_lo =
  12598. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  12599. sgl_pg_pairs->sgl_pg0_addr_hi =
  12600. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  12601. sgl_pg_pairs->sgl_pg1_addr_lo =
  12602. cpu_to_le32(putPaddrLow(0));
  12603. sgl_pg_pairs->sgl_pg1_addr_hi =
  12604. cpu_to_le32(putPaddrHigh(0));
  12605. /* Keep the first xritag on the list */
  12606. if (pg_pairs == 0)
  12607. xritag_start = sglq_entry->sli4_xritag;
  12608. sgl_pg_pairs++;
  12609. pg_pairs++;
  12610. }
  12611. /* Complete initialization and perform endian conversion. */
  12612. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12613. bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
  12614. sgl->word0 = cpu_to_le32(sgl->word0);
  12615. if (!phba->sli4_hba.intr_enable)
  12616. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12617. else {
  12618. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12619. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12620. }
  12621. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12622. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12623. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12624. if (rc != MBX_TIMEOUT)
  12625. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12626. if (shdr_status || shdr_add_status || rc) {
  12627. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12628. "2513 POST_SGL_BLOCK mailbox command failed "
  12629. "status x%x add_status x%x mbx status x%x\n",
  12630. shdr_status, shdr_add_status, rc);
  12631. rc = -ENXIO;
  12632. }
  12633. return rc;
  12634. }
  12635. /**
  12636. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  12637. * @phba: pointer to lpfc hba data structure.
  12638. * @sblist: pointer to scsi buffer list.
  12639. * @count: number of scsi buffers on the list.
  12640. *
  12641. * This routine is invoked to post a block of @count scsi sgl pages from a
  12642. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  12643. * No Lock is held.
  12644. *
  12645. **/
  12646. int
  12647. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
  12648. struct list_head *sblist,
  12649. int count)
  12650. {
  12651. struct lpfc_scsi_buf *psb;
  12652. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12653. struct sgl_page_pairs *sgl_pg_pairs;
  12654. void *viraddr;
  12655. LPFC_MBOXQ_t *mbox;
  12656. uint32_t reqlen, alloclen, pg_pairs;
  12657. uint32_t mbox_tmo;
  12658. uint16_t xritag_start = 0;
  12659. int rc = 0;
  12660. uint32_t shdr_status, shdr_add_status;
  12661. dma_addr_t pdma_phys_bpl1;
  12662. union lpfc_sli4_cfg_shdr *shdr;
  12663. /* Calculate the requested length of the dma memory */
  12664. reqlen = count * sizeof(struct sgl_page_pairs) +
  12665. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12666. if (reqlen > SLI4_PAGE_SIZE) {
  12667. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12668. "0217 Block sgl registration required DMA "
  12669. "size (%d) great than a page\n", reqlen);
  12670. return -ENOMEM;
  12671. }
  12672. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12673. if (!mbox) {
  12674. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12675. "0283 Failed to allocate mbox cmd memory\n");
  12676. return -ENOMEM;
  12677. }
  12678. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12679. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12680. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12681. LPFC_SLI4_MBX_NEMBED);
  12682. if (alloclen < reqlen) {
  12683. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12684. "2561 Allocated DMA memory size (%d) is "
  12685. "less than the requested DMA memory "
  12686. "size (%d)\n", alloclen, reqlen);
  12687. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12688. return -ENOMEM;
  12689. }
  12690. /* Get the first SGE entry from the non-embedded DMA memory */
  12691. viraddr = mbox->sge_array->addr[0];
  12692. /* Set up the SGL pages in the non-embedded DMA pages */
  12693. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12694. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12695. pg_pairs = 0;
  12696. list_for_each_entry(psb, sblist, list) {
  12697. /* Set up the sge entry */
  12698. sgl_pg_pairs->sgl_pg0_addr_lo =
  12699. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  12700. sgl_pg_pairs->sgl_pg0_addr_hi =
  12701. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  12702. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  12703. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  12704. else
  12705. pdma_phys_bpl1 = 0;
  12706. sgl_pg_pairs->sgl_pg1_addr_lo =
  12707. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  12708. sgl_pg_pairs->sgl_pg1_addr_hi =
  12709. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  12710. /* Keep the first xritag on the list */
  12711. if (pg_pairs == 0)
  12712. xritag_start = psb->cur_iocbq.sli4_xritag;
  12713. sgl_pg_pairs++;
  12714. pg_pairs++;
  12715. }
  12716. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12717. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  12718. /* Perform endian conversion if necessary */
  12719. sgl->word0 = cpu_to_le32(sgl->word0);
  12720. if (!phba->sli4_hba.intr_enable)
  12721. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12722. else {
  12723. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12724. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12725. }
  12726. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12727. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12728. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12729. if (rc != MBX_TIMEOUT)
  12730. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12731. if (shdr_status || shdr_add_status || rc) {
  12732. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12733. "2564 POST_SGL_BLOCK mailbox command failed "
  12734. "status x%x add_status x%x mbx status x%x\n",
  12735. shdr_status, shdr_add_status, rc);
  12736. rc = -ENXIO;
  12737. }
  12738. return rc;
  12739. }
  12740. /**
  12741. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  12742. * @phba: pointer to lpfc_hba struct that the frame was received on
  12743. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12744. *
  12745. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  12746. * valid type of frame that the LPFC driver will handle. This function will
  12747. * return a zero if the frame is a valid frame or a non zero value when the
  12748. * frame does not pass the check.
  12749. **/
  12750. static int
  12751. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  12752. {
  12753. /* make rctl_names static to save stack space */
  12754. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  12755. char *type_names[] = FC_TYPE_NAMES_INIT;
  12756. struct fc_vft_header *fc_vft_hdr;
  12757. uint32_t *header = (uint32_t *) fc_hdr;
  12758. switch (fc_hdr->fh_r_ctl) {
  12759. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  12760. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  12761. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  12762. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  12763. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  12764. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  12765. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  12766. case FC_RCTL_DD_CMD_STATUS: /* command status */
  12767. case FC_RCTL_ELS_REQ: /* extended link services request */
  12768. case FC_RCTL_ELS_REP: /* extended link services reply */
  12769. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  12770. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  12771. case FC_RCTL_BA_NOP: /* basic link service NOP */
  12772. case FC_RCTL_BA_ABTS: /* basic link service abort */
  12773. case FC_RCTL_BA_RMC: /* remove connection */
  12774. case FC_RCTL_BA_ACC: /* basic accept */
  12775. case FC_RCTL_BA_RJT: /* basic reject */
  12776. case FC_RCTL_BA_PRMT:
  12777. case FC_RCTL_ACK_1: /* acknowledge_1 */
  12778. case FC_RCTL_ACK_0: /* acknowledge_0 */
  12779. case FC_RCTL_P_RJT: /* port reject */
  12780. case FC_RCTL_F_RJT: /* fabric reject */
  12781. case FC_RCTL_P_BSY: /* port busy */
  12782. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  12783. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  12784. case FC_RCTL_LCR: /* link credit reset */
  12785. case FC_RCTL_END: /* end */
  12786. break;
  12787. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  12788. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12789. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  12790. return lpfc_fc_frame_check(phba, fc_hdr);
  12791. default:
  12792. goto drop;
  12793. }
  12794. switch (fc_hdr->fh_type) {
  12795. case FC_TYPE_BLS:
  12796. case FC_TYPE_ELS:
  12797. case FC_TYPE_FCP:
  12798. case FC_TYPE_CT:
  12799. break;
  12800. case FC_TYPE_IP:
  12801. case FC_TYPE_ILS:
  12802. default:
  12803. goto drop;
  12804. }
  12805. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12806. "2538 Received frame rctl:%s type:%s "
  12807. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  12808. rctl_names[fc_hdr->fh_r_ctl],
  12809. type_names[fc_hdr->fh_type],
  12810. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  12811. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  12812. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  12813. return 0;
  12814. drop:
  12815. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12816. "2539 Dropped frame rctl:%s type:%s\n",
  12817. rctl_names[fc_hdr->fh_r_ctl],
  12818. type_names[fc_hdr->fh_type]);
  12819. return 1;
  12820. }
  12821. /**
  12822. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  12823. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12824. *
  12825. * This function processes the FC header to retrieve the VFI from the VF
  12826. * header, if one exists. This function will return the VFI if one exists
  12827. * or 0 if no VSAN Header exists.
  12828. **/
  12829. static uint32_t
  12830. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  12831. {
  12832. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12833. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  12834. return 0;
  12835. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  12836. }
  12837. /**
  12838. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  12839. * @phba: Pointer to the HBA structure to search for the vport on
  12840. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12841. * @fcfi: The FC Fabric ID that the frame came from
  12842. *
  12843. * This function searches the @phba for a vport that matches the content of the
  12844. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  12845. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  12846. * returns the matching vport pointer or NULL if unable to match frame to a
  12847. * vport.
  12848. **/
  12849. static struct lpfc_vport *
  12850. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  12851. uint16_t fcfi)
  12852. {
  12853. struct lpfc_vport **vports;
  12854. struct lpfc_vport *vport = NULL;
  12855. int i;
  12856. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  12857. fc_hdr->fh_d_id[1] << 8 |
  12858. fc_hdr->fh_d_id[2]);
  12859. if (did == Fabric_DID)
  12860. return phba->pport;
  12861. if ((phba->pport->fc_flag & FC_PT2PT) &&
  12862. !(phba->link_state == LPFC_HBA_READY))
  12863. return phba->pport;
  12864. vports = lpfc_create_vport_work_array(phba);
  12865. if (vports != NULL)
  12866. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  12867. if (phba->fcf.fcfi == fcfi &&
  12868. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  12869. vports[i]->fc_myDID == did) {
  12870. vport = vports[i];
  12871. break;
  12872. }
  12873. }
  12874. lpfc_destroy_vport_work_array(phba, vports);
  12875. return vport;
  12876. }
  12877. /**
  12878. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  12879. * @vport: The vport to work on.
  12880. *
  12881. * This function updates the receive sequence time stamp for this vport. The
  12882. * receive sequence time stamp indicates the time that the last frame of the
  12883. * the sequence that has been idle for the longest amount of time was received.
  12884. * the driver uses this time stamp to indicate if any received sequences have
  12885. * timed out.
  12886. **/
  12887. void
  12888. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  12889. {
  12890. struct lpfc_dmabuf *h_buf;
  12891. struct hbq_dmabuf *dmabuf = NULL;
  12892. /* get the oldest sequence on the rcv list */
  12893. h_buf = list_get_first(&vport->rcv_buffer_list,
  12894. struct lpfc_dmabuf, list);
  12895. if (!h_buf)
  12896. return;
  12897. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12898. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  12899. }
  12900. /**
  12901. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  12902. * @vport: The vport that the received sequences were sent to.
  12903. *
  12904. * This function cleans up all outstanding received sequences. This is called
  12905. * by the driver when a link event or user action invalidates all the received
  12906. * sequences.
  12907. **/
  12908. void
  12909. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  12910. {
  12911. struct lpfc_dmabuf *h_buf, *hnext;
  12912. struct lpfc_dmabuf *d_buf, *dnext;
  12913. struct hbq_dmabuf *dmabuf = NULL;
  12914. /* start with the oldest sequence on the rcv list */
  12915. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12916. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12917. list_del_init(&dmabuf->hbuf.list);
  12918. list_for_each_entry_safe(d_buf, dnext,
  12919. &dmabuf->dbuf.list, list) {
  12920. list_del_init(&d_buf->list);
  12921. lpfc_in_buf_free(vport->phba, d_buf);
  12922. }
  12923. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12924. }
  12925. }
  12926. /**
  12927. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  12928. * @vport: The vport that the received sequences were sent to.
  12929. *
  12930. * This function determines whether any received sequences have timed out by
  12931. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  12932. * indicates that there is at least one timed out sequence this routine will
  12933. * go through the received sequences one at a time from most inactive to most
  12934. * active to determine which ones need to be cleaned up. Once it has determined
  12935. * that a sequence needs to be cleaned up it will simply free up the resources
  12936. * without sending an abort.
  12937. **/
  12938. void
  12939. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  12940. {
  12941. struct lpfc_dmabuf *h_buf, *hnext;
  12942. struct lpfc_dmabuf *d_buf, *dnext;
  12943. struct hbq_dmabuf *dmabuf = NULL;
  12944. unsigned long timeout;
  12945. int abort_count = 0;
  12946. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12947. vport->rcv_buffer_time_stamp);
  12948. if (list_empty(&vport->rcv_buffer_list) ||
  12949. time_before(jiffies, timeout))
  12950. return;
  12951. /* start with the oldest sequence on the rcv list */
  12952. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12953. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12954. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12955. dmabuf->time_stamp);
  12956. if (time_before(jiffies, timeout))
  12957. break;
  12958. abort_count++;
  12959. list_del_init(&dmabuf->hbuf.list);
  12960. list_for_each_entry_safe(d_buf, dnext,
  12961. &dmabuf->dbuf.list, list) {
  12962. list_del_init(&d_buf->list);
  12963. lpfc_in_buf_free(vport->phba, d_buf);
  12964. }
  12965. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12966. }
  12967. if (abort_count)
  12968. lpfc_update_rcv_time_stamp(vport);
  12969. }
  12970. /**
  12971. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  12972. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  12973. *
  12974. * This function searches through the existing incomplete sequences that have
  12975. * been sent to this @vport. If the frame matches one of the incomplete
  12976. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  12977. * make up that sequence. If no sequence is found that matches this frame then
  12978. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  12979. * This function returns a pointer to the first dmabuf in the sequence list that
  12980. * the frame was linked to.
  12981. **/
  12982. static struct hbq_dmabuf *
  12983. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  12984. {
  12985. struct fc_frame_header *new_hdr;
  12986. struct fc_frame_header *temp_hdr;
  12987. struct lpfc_dmabuf *d_buf;
  12988. struct lpfc_dmabuf *h_buf;
  12989. struct hbq_dmabuf *seq_dmabuf = NULL;
  12990. struct hbq_dmabuf *temp_dmabuf = NULL;
  12991. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12992. dmabuf->time_stamp = jiffies;
  12993. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12994. /* Use the hdr_buf to find the sequence that this frame belongs to */
  12995. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12996. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12997. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12998. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12999. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  13000. continue;
  13001. /* found a pending sequence that matches this frame */
  13002. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13003. break;
  13004. }
  13005. if (!seq_dmabuf) {
  13006. /*
  13007. * This indicates first frame received for this sequence.
  13008. * Queue the buffer on the vport's rcv_buffer_list.
  13009. */
  13010. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13011. lpfc_update_rcv_time_stamp(vport);
  13012. return dmabuf;
  13013. }
  13014. temp_hdr = seq_dmabuf->hbuf.virt;
  13015. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  13016. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13017. list_del_init(&seq_dmabuf->hbuf.list);
  13018. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13019. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13020. lpfc_update_rcv_time_stamp(vport);
  13021. return dmabuf;
  13022. }
  13023. /* move this sequence to the tail to indicate a young sequence */
  13024. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13025. seq_dmabuf->time_stamp = jiffies;
  13026. lpfc_update_rcv_time_stamp(vport);
  13027. if (list_empty(&seq_dmabuf->dbuf.list)) {
  13028. temp_hdr = dmabuf->hbuf.virt;
  13029. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13030. return seq_dmabuf;
  13031. }
  13032. /* find the correct place in the sequence to insert this frame */
  13033. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  13034. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13035. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  13036. /*
  13037. * If the frame's sequence count is greater than the frame on
  13038. * the list then insert the frame right after this frame
  13039. */
  13040. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  13041. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13042. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  13043. return seq_dmabuf;
  13044. }
  13045. }
  13046. return NULL;
  13047. }
  13048. /**
  13049. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  13050. * @vport: pointer to a vitural port
  13051. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13052. *
  13053. * This function tries to abort from the partially assembed sequence, described
  13054. * by the information from basic abbort @dmabuf. It checks to see whether such
  13055. * partially assembled sequence held by the driver. If so, it shall free up all
  13056. * the frames from the partially assembled sequence.
  13057. *
  13058. * Return
  13059. * true -- if there is matching partially assembled sequence present and all
  13060. * the frames freed with the sequence;
  13061. * false -- if there is no matching partially assembled sequence present so
  13062. * nothing got aborted in the lower layer driver
  13063. **/
  13064. static bool
  13065. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  13066. struct hbq_dmabuf *dmabuf)
  13067. {
  13068. struct fc_frame_header *new_hdr;
  13069. struct fc_frame_header *temp_hdr;
  13070. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  13071. struct hbq_dmabuf *seq_dmabuf = NULL;
  13072. /* Use the hdr_buf to find the sequence that matches this frame */
  13073. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  13074. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  13075. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13076. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  13077. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  13078. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  13079. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  13080. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  13081. continue;
  13082. /* found a pending sequence that matches this frame */
  13083. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13084. break;
  13085. }
  13086. /* Free up all the frames from the partially assembled sequence */
  13087. if (seq_dmabuf) {
  13088. list_for_each_entry_safe(d_buf, n_buf,
  13089. &seq_dmabuf->dbuf.list, list) {
  13090. list_del_init(&d_buf->list);
  13091. lpfc_in_buf_free(vport->phba, d_buf);
  13092. }
  13093. return true;
  13094. }
  13095. return false;
  13096. }
  13097. /**
  13098. * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
  13099. * @vport: pointer to a vitural port
  13100. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13101. *
  13102. * This function tries to abort from the assembed sequence from upper level
  13103. * protocol, described by the information from basic abbort @dmabuf. It
  13104. * checks to see whether such pending context exists at upper level protocol.
  13105. * If so, it shall clean up the pending context.
  13106. *
  13107. * Return
  13108. * true -- if there is matching pending context of the sequence cleaned
  13109. * at ulp;
  13110. * false -- if there is no matching pending context of the sequence present
  13111. * at ulp.
  13112. **/
  13113. static bool
  13114. lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  13115. {
  13116. struct lpfc_hba *phba = vport->phba;
  13117. int handled;
  13118. /* Accepting abort at ulp with SLI4 only */
  13119. if (phba->sli_rev < LPFC_SLI_REV4)
  13120. return false;
  13121. /* Register all caring upper level protocols to attend abort */
  13122. handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
  13123. if (handled)
  13124. return true;
  13125. return false;
  13126. }
  13127. /**
  13128. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  13129. * @phba: Pointer to HBA context object.
  13130. * @cmd_iocbq: pointer to the command iocbq structure.
  13131. * @rsp_iocbq: pointer to the response iocbq structure.
  13132. *
  13133. * This function handles the sequence abort response iocb command complete
  13134. * event. It properly releases the memory allocated to the sequence abort
  13135. * accept iocb.
  13136. **/
  13137. static void
  13138. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  13139. struct lpfc_iocbq *cmd_iocbq,
  13140. struct lpfc_iocbq *rsp_iocbq)
  13141. {
  13142. struct lpfc_nodelist *ndlp;
  13143. if (cmd_iocbq) {
  13144. ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
  13145. lpfc_nlp_put(ndlp);
  13146. lpfc_nlp_not_used(ndlp);
  13147. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  13148. }
  13149. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  13150. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  13151. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13152. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  13153. rsp_iocbq->iocb.ulpStatus,
  13154. rsp_iocbq->iocb.un.ulpWord[4]);
  13155. }
  13156. /**
  13157. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  13158. * @phba: Pointer to HBA context object.
  13159. * @xri: xri id in transaction.
  13160. *
  13161. * This function validates the xri maps to the known range of XRIs allocated an
  13162. * used by the driver.
  13163. **/
  13164. uint16_t
  13165. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  13166. uint16_t xri)
  13167. {
  13168. int i;
  13169. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  13170. if (xri == phba->sli4_hba.xri_ids[i])
  13171. return i;
  13172. }
  13173. return NO_XRI;
  13174. }
  13175. /**
  13176. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  13177. * @phba: Pointer to HBA context object.
  13178. * @fc_hdr: pointer to a FC frame header.
  13179. *
  13180. * This function sends a basic response to a previous unsol sequence abort
  13181. * event after aborting the sequence handling.
  13182. **/
  13183. static void
  13184. lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
  13185. struct fc_frame_header *fc_hdr, bool aborted)
  13186. {
  13187. struct lpfc_hba *phba = vport->phba;
  13188. struct lpfc_iocbq *ctiocb = NULL;
  13189. struct lpfc_nodelist *ndlp;
  13190. uint16_t oxid, rxid, xri, lxri;
  13191. uint32_t sid, fctl;
  13192. IOCB_t *icmd;
  13193. int rc;
  13194. if (!lpfc_is_link_up(phba))
  13195. return;
  13196. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13197. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  13198. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  13199. ndlp = lpfc_findnode_did(vport, sid);
  13200. if (!ndlp) {
  13201. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  13202. if (!ndlp) {
  13203. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13204. "1268 Failed to allocate ndlp for "
  13205. "oxid:x%x SID:x%x\n", oxid, sid);
  13206. return;
  13207. }
  13208. lpfc_nlp_init(vport, ndlp, sid);
  13209. /* Put ndlp onto pport node list */
  13210. lpfc_enqueue_node(vport, ndlp);
  13211. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  13212. /* re-setup ndlp without removing from node list */
  13213. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  13214. if (!ndlp) {
  13215. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13216. "3275 Failed to active ndlp found "
  13217. "for oxid:x%x SID:x%x\n", oxid, sid);
  13218. return;
  13219. }
  13220. }
  13221. /* Allocate buffer for rsp iocb */
  13222. ctiocb = lpfc_sli_get_iocbq(phba);
  13223. if (!ctiocb)
  13224. return;
  13225. /* Extract the F_CTL field from FC_HDR */
  13226. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  13227. icmd = &ctiocb->iocb;
  13228. icmd->un.xseq64.bdl.bdeSize = 0;
  13229. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  13230. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  13231. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  13232. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  13233. /* Fill in the rest of iocb fields */
  13234. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  13235. icmd->ulpBdeCount = 0;
  13236. icmd->ulpLe = 1;
  13237. icmd->ulpClass = CLASS3;
  13238. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  13239. ctiocb->context1 = lpfc_nlp_get(ndlp);
  13240. ctiocb->iocb_cmpl = NULL;
  13241. ctiocb->vport = phba->pport;
  13242. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  13243. ctiocb->sli4_lxritag = NO_XRI;
  13244. ctiocb->sli4_xritag = NO_XRI;
  13245. if (fctl & FC_FC_EX_CTX)
  13246. /* Exchange responder sent the abort so we
  13247. * own the oxid.
  13248. */
  13249. xri = oxid;
  13250. else
  13251. xri = rxid;
  13252. lxri = lpfc_sli4_xri_inrange(phba, xri);
  13253. if (lxri != NO_XRI)
  13254. lpfc_set_rrq_active(phba, ndlp, lxri,
  13255. (xri == oxid) ? rxid : oxid, 0);
  13256. /* For BA_ABTS from exchange responder, if the logical xri with
  13257. * the oxid maps to the FCP XRI range, the port no longer has
  13258. * that exchange context, send a BLS_RJT. Override the IOCB for
  13259. * a BA_RJT.
  13260. */
  13261. if ((fctl & FC_FC_EX_CTX) &&
  13262. (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) {
  13263. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  13264. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  13265. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  13266. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  13267. }
  13268. /* If BA_ABTS failed to abort a partially assembled receive sequence,
  13269. * the driver no longer has that exchange, send a BLS_RJT. Override
  13270. * the IOCB for a BA_RJT.
  13271. */
  13272. if (aborted == false) {
  13273. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  13274. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  13275. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  13276. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  13277. }
  13278. if (fctl & FC_FC_EX_CTX) {
  13279. /* ABTS sent by responder to CT exchange, construction
  13280. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  13281. * field and RX_ID from ABTS for RX_ID field.
  13282. */
  13283. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  13284. } else {
  13285. /* ABTS sent by initiator to CT exchange, construction
  13286. * of BA_ACC will need to allocate a new XRI as for the
  13287. * XRI_TAG field.
  13288. */
  13289. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  13290. }
  13291. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  13292. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  13293. /* Xmit CT abts response on exchange <xid> */
  13294. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  13295. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  13296. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  13297. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  13298. if (rc == IOCB_ERROR) {
  13299. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  13300. "2925 Failed to issue CT ABTS RSP x%x on "
  13301. "xri x%x, Data x%x\n",
  13302. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  13303. phba->link_state);
  13304. lpfc_nlp_put(ndlp);
  13305. ctiocb->context1 = NULL;
  13306. lpfc_sli_release_iocbq(phba, ctiocb);
  13307. }
  13308. }
  13309. /**
  13310. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  13311. * @vport: Pointer to the vport on which this sequence was received
  13312. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13313. *
  13314. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  13315. * receive sequence is only partially assembed by the driver, it shall abort
  13316. * the partially assembled frames for the sequence. Otherwise, if the
  13317. * unsolicited receive sequence has been completely assembled and passed to
  13318. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  13319. * unsolicited sequence has been aborted. After that, it will issue a basic
  13320. * accept to accept the abort.
  13321. **/
  13322. void
  13323. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  13324. struct hbq_dmabuf *dmabuf)
  13325. {
  13326. struct lpfc_hba *phba = vport->phba;
  13327. struct fc_frame_header fc_hdr;
  13328. uint32_t fctl;
  13329. bool aborted;
  13330. /* Make a copy of fc_hdr before the dmabuf being released */
  13331. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  13332. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  13333. if (fctl & FC_FC_EX_CTX) {
  13334. /* ABTS by responder to exchange, no cleanup needed */
  13335. aborted = true;
  13336. } else {
  13337. /* ABTS by initiator to exchange, need to do cleanup */
  13338. aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  13339. if (aborted == false)
  13340. aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
  13341. }
  13342. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13343. /* Respond with BA_ACC or BA_RJT accordingly */
  13344. lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
  13345. }
  13346. /**
  13347. * lpfc_seq_complete - Indicates if a sequence is complete
  13348. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13349. *
  13350. * This function checks the sequence, starting with the frame described by
  13351. * @dmabuf, to see if all the frames associated with this sequence are present.
  13352. * the frames associated with this sequence are linked to the @dmabuf using the
  13353. * dbuf list. This function looks for two major things. 1) That the first frame
  13354. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  13355. * set. 3) That there are no holes in the sequence count. The function will
  13356. * return 1 when the sequence is complete, otherwise it will return 0.
  13357. **/
  13358. static int
  13359. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  13360. {
  13361. struct fc_frame_header *hdr;
  13362. struct lpfc_dmabuf *d_buf;
  13363. struct hbq_dmabuf *seq_dmabuf;
  13364. uint32_t fctl;
  13365. int seq_count = 0;
  13366. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13367. /* make sure first fame of sequence has a sequence count of zero */
  13368. if (hdr->fh_seq_cnt != seq_count)
  13369. return 0;
  13370. fctl = (hdr->fh_f_ctl[0] << 16 |
  13371. hdr->fh_f_ctl[1] << 8 |
  13372. hdr->fh_f_ctl[2]);
  13373. /* If last frame of sequence we can return success. */
  13374. if (fctl & FC_FC_END_SEQ)
  13375. return 1;
  13376. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  13377. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13378. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13379. /* If there is a hole in the sequence count then fail. */
  13380. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  13381. return 0;
  13382. fctl = (hdr->fh_f_ctl[0] << 16 |
  13383. hdr->fh_f_ctl[1] << 8 |
  13384. hdr->fh_f_ctl[2]);
  13385. /* If last frame of sequence we can return success. */
  13386. if (fctl & FC_FC_END_SEQ)
  13387. return 1;
  13388. }
  13389. return 0;
  13390. }
  13391. /**
  13392. * lpfc_prep_seq - Prep sequence for ULP processing
  13393. * @vport: Pointer to the vport on which this sequence was received
  13394. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13395. *
  13396. * This function takes a sequence, described by a list of frames, and creates
  13397. * a list of iocbq structures to describe the sequence. This iocbq list will be
  13398. * used to issue to the generic unsolicited sequence handler. This routine
  13399. * returns a pointer to the first iocbq in the list. If the function is unable
  13400. * to allocate an iocbq then it throw out the received frames that were not
  13401. * able to be described and return a pointer to the first iocbq. If unable to
  13402. * allocate any iocbqs (including the first) this function will return NULL.
  13403. **/
  13404. static struct lpfc_iocbq *
  13405. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  13406. {
  13407. struct hbq_dmabuf *hbq_buf;
  13408. struct lpfc_dmabuf *d_buf, *n_buf;
  13409. struct lpfc_iocbq *first_iocbq, *iocbq;
  13410. struct fc_frame_header *fc_hdr;
  13411. uint32_t sid;
  13412. uint32_t len, tot_len;
  13413. struct ulp_bde64 *pbde;
  13414. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13415. /* remove from receive buffer list */
  13416. list_del_init(&seq_dmabuf->hbuf.list);
  13417. lpfc_update_rcv_time_stamp(vport);
  13418. /* get the Remote Port's SID */
  13419. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13420. tot_len = 0;
  13421. /* Get an iocbq struct to fill in. */
  13422. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  13423. if (first_iocbq) {
  13424. /* Initialize the first IOCB. */
  13425. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  13426. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  13427. /* Check FC Header to see what TYPE of frame we are rcv'ing */
  13428. if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
  13429. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
  13430. first_iocbq->iocb.un.rcvels.parmRo =
  13431. sli4_did_from_fc_hdr(fc_hdr);
  13432. first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
  13433. } else
  13434. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  13435. first_iocbq->iocb.ulpContext = NO_XRI;
  13436. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  13437. be16_to_cpu(fc_hdr->fh_ox_id);
  13438. /* iocbq is prepped for internal consumption. Physical vpi. */
  13439. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  13440. vport->phba->vpi_ids[vport->vpi];
  13441. /* put the first buffer into the first IOCBq */
  13442. first_iocbq->context2 = &seq_dmabuf->dbuf;
  13443. first_iocbq->context3 = NULL;
  13444. first_iocbq->iocb.ulpBdeCount = 1;
  13445. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13446. LPFC_DATA_BUF_SIZE;
  13447. first_iocbq->iocb.un.rcvels.remoteID = sid;
  13448. tot_len = bf_get(lpfc_rcqe_length,
  13449. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  13450. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13451. }
  13452. iocbq = first_iocbq;
  13453. /*
  13454. * Each IOCBq can have two Buffers assigned, so go through the list
  13455. * of buffers for this sequence and save two buffers in each IOCBq
  13456. */
  13457. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  13458. if (!iocbq) {
  13459. lpfc_in_buf_free(vport->phba, d_buf);
  13460. continue;
  13461. }
  13462. if (!iocbq->context3) {
  13463. iocbq->context3 = d_buf;
  13464. iocbq->iocb.ulpBdeCount++;
  13465. pbde = (struct ulp_bde64 *)
  13466. &iocbq->iocb.unsli3.sli3Words[4];
  13467. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  13468. /* We need to get the size out of the right CQE */
  13469. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13470. len = bf_get(lpfc_rcqe_length,
  13471. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13472. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  13473. tot_len += len;
  13474. } else {
  13475. iocbq = lpfc_sli_get_iocbq(vport->phba);
  13476. if (!iocbq) {
  13477. if (first_iocbq) {
  13478. first_iocbq->iocb.ulpStatus =
  13479. IOSTAT_FCP_RSP_ERROR;
  13480. first_iocbq->iocb.un.ulpWord[4] =
  13481. IOERR_NO_RESOURCES;
  13482. }
  13483. lpfc_in_buf_free(vport->phba, d_buf);
  13484. continue;
  13485. }
  13486. iocbq->context2 = d_buf;
  13487. iocbq->context3 = NULL;
  13488. iocbq->iocb.ulpBdeCount = 1;
  13489. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13490. LPFC_DATA_BUF_SIZE;
  13491. /* We need to get the size out of the right CQE */
  13492. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13493. len = bf_get(lpfc_rcqe_length,
  13494. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13495. tot_len += len;
  13496. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13497. iocbq->iocb.un.rcvels.remoteID = sid;
  13498. list_add_tail(&iocbq->list, &first_iocbq->list);
  13499. }
  13500. }
  13501. return first_iocbq;
  13502. }
  13503. static void
  13504. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  13505. struct hbq_dmabuf *seq_dmabuf)
  13506. {
  13507. struct fc_frame_header *fc_hdr;
  13508. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  13509. struct lpfc_hba *phba = vport->phba;
  13510. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13511. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  13512. if (!iocbq) {
  13513. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13514. "2707 Ring %d handler: Failed to allocate "
  13515. "iocb Rctl x%x Type x%x received\n",
  13516. LPFC_ELS_RING,
  13517. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13518. return;
  13519. }
  13520. if (!lpfc_complete_unsol_iocb(phba,
  13521. &phba->sli.ring[LPFC_ELS_RING],
  13522. iocbq, fc_hdr->fh_r_ctl,
  13523. fc_hdr->fh_type))
  13524. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13525. "2540 Ring %d handler: unexpected Rctl "
  13526. "x%x Type x%x received\n",
  13527. LPFC_ELS_RING,
  13528. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13529. /* Free iocb created in lpfc_prep_seq */
  13530. list_for_each_entry_safe(curr_iocb, next_iocb,
  13531. &iocbq->list, list) {
  13532. list_del_init(&curr_iocb->list);
  13533. lpfc_sli_release_iocbq(phba, curr_iocb);
  13534. }
  13535. lpfc_sli_release_iocbq(phba, iocbq);
  13536. }
  13537. /**
  13538. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  13539. * @phba: Pointer to HBA context object.
  13540. *
  13541. * This function is called with no lock held. This function processes all
  13542. * the received buffers and gives it to upper layers when a received buffer
  13543. * indicates that it is the final frame in the sequence. The interrupt
  13544. * service routine processes received buffers at interrupt contexts and adds
  13545. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  13546. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  13547. * appropriate receive function when the final frame in a sequence is received.
  13548. **/
  13549. void
  13550. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  13551. struct hbq_dmabuf *dmabuf)
  13552. {
  13553. struct hbq_dmabuf *seq_dmabuf;
  13554. struct fc_frame_header *fc_hdr;
  13555. struct lpfc_vport *vport;
  13556. uint32_t fcfi;
  13557. uint32_t did;
  13558. /* Process each received buffer */
  13559. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13560. /* check to see if this a valid type of frame */
  13561. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  13562. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13563. return;
  13564. }
  13565. if ((bf_get(lpfc_cqe_code,
  13566. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  13567. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  13568. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13569. else
  13570. fcfi = bf_get(lpfc_rcqe_fcf_id,
  13571. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13572. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  13573. if (!vport) {
  13574. /* throw out the frame */
  13575. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13576. return;
  13577. }
  13578. /* d_id this frame is directed to */
  13579. did = sli4_did_from_fc_hdr(fc_hdr);
  13580. /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
  13581. if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
  13582. (did != Fabric_DID)) {
  13583. /*
  13584. * Throw out the frame if we are not pt2pt.
  13585. * The pt2pt protocol allows for discovery frames
  13586. * to be received without a registered VPI.
  13587. */
  13588. if (!(vport->fc_flag & FC_PT2PT) ||
  13589. (phba->link_state == LPFC_HBA_READY)) {
  13590. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13591. return;
  13592. }
  13593. }
  13594. /* Handle the basic abort sequence (BA_ABTS) event */
  13595. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  13596. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  13597. return;
  13598. }
  13599. /* Link this frame */
  13600. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  13601. if (!seq_dmabuf) {
  13602. /* unable to add frame to vport - throw it out */
  13603. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13604. return;
  13605. }
  13606. /* If not last frame in sequence continue processing frames. */
  13607. if (!lpfc_seq_complete(seq_dmabuf))
  13608. return;
  13609. /* Send the complete sequence to the upper layer protocol */
  13610. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  13611. }
  13612. /**
  13613. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  13614. * @phba: pointer to lpfc hba data structure.
  13615. *
  13616. * This routine is invoked to post rpi header templates to the
  13617. * HBA consistent with the SLI-4 interface spec. This routine
  13618. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13619. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13620. *
  13621. * This routine does not require any locks. It's usage is expected
  13622. * to be driver load or reset recovery when the driver is
  13623. * sequential.
  13624. *
  13625. * Return codes
  13626. * 0 - successful
  13627. * -EIO - The mailbox failed to complete successfully.
  13628. * When this error occurs, the driver is not guaranteed
  13629. * to have any rpi regions posted to the device and
  13630. * must either attempt to repost the regions or take a
  13631. * fatal error.
  13632. **/
  13633. int
  13634. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  13635. {
  13636. struct lpfc_rpi_hdr *rpi_page;
  13637. uint32_t rc = 0;
  13638. uint16_t lrpi = 0;
  13639. /* SLI4 ports that support extents do not require RPI headers. */
  13640. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13641. goto exit;
  13642. if (phba->sli4_hba.extents_in_use)
  13643. return -EIO;
  13644. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  13645. /*
  13646. * Assign the rpi headers a physical rpi only if the driver
  13647. * has not initialized those resources. A port reset only
  13648. * needs the headers posted.
  13649. */
  13650. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  13651. LPFC_RPI_RSRC_RDY)
  13652. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13653. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  13654. if (rc != MBX_SUCCESS) {
  13655. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13656. "2008 Error %d posting all rpi "
  13657. "headers\n", rc);
  13658. rc = -EIO;
  13659. break;
  13660. }
  13661. }
  13662. exit:
  13663. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  13664. LPFC_RPI_RSRC_RDY);
  13665. return rc;
  13666. }
  13667. /**
  13668. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  13669. * @phba: pointer to lpfc hba data structure.
  13670. * @rpi_page: pointer to the rpi memory region.
  13671. *
  13672. * This routine is invoked to post a single rpi header to the
  13673. * HBA consistent with the SLI-4 interface spec. This memory region
  13674. * maps up to 64 rpi context regions.
  13675. *
  13676. * Return codes
  13677. * 0 - successful
  13678. * -ENOMEM - No available memory
  13679. * -EIO - The mailbox failed to complete successfully.
  13680. **/
  13681. int
  13682. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  13683. {
  13684. LPFC_MBOXQ_t *mboxq;
  13685. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  13686. uint32_t rc = 0;
  13687. uint32_t shdr_status, shdr_add_status;
  13688. union lpfc_sli4_cfg_shdr *shdr;
  13689. /* SLI4 ports that support extents do not require RPI headers. */
  13690. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13691. return rc;
  13692. if (phba->sli4_hba.extents_in_use)
  13693. return -EIO;
  13694. /* The port is notified of the header region via a mailbox command. */
  13695. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13696. if (!mboxq) {
  13697. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13698. "2001 Unable to allocate memory for issuing "
  13699. "SLI_CONFIG_SPECIAL mailbox command\n");
  13700. return -ENOMEM;
  13701. }
  13702. /* Post all rpi memory regions to the port. */
  13703. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  13704. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13705. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  13706. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  13707. sizeof(struct lpfc_sli4_cfg_mhdr),
  13708. LPFC_SLI4_MBX_EMBED);
  13709. /* Post the physical rpi to the port for this rpi header. */
  13710. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  13711. rpi_page->start_rpi);
  13712. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  13713. hdr_tmpl, rpi_page->page_count);
  13714. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  13715. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  13716. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  13717. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  13718. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13719. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13720. if (rc != MBX_TIMEOUT)
  13721. mempool_free(mboxq, phba->mbox_mem_pool);
  13722. if (shdr_status || shdr_add_status || rc) {
  13723. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13724. "2514 POST_RPI_HDR mailbox failed with "
  13725. "status x%x add_status x%x, mbx status x%x\n",
  13726. shdr_status, shdr_add_status, rc);
  13727. rc = -ENXIO;
  13728. }
  13729. return rc;
  13730. }
  13731. /**
  13732. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  13733. * @phba: pointer to lpfc hba data structure.
  13734. *
  13735. * This routine is invoked to post rpi header templates to the
  13736. * HBA consistent with the SLI-4 interface spec. This routine
  13737. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13738. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13739. *
  13740. * Returns
  13741. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13742. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13743. **/
  13744. int
  13745. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  13746. {
  13747. unsigned long rpi;
  13748. uint16_t max_rpi, rpi_limit;
  13749. uint16_t rpi_remaining, lrpi = 0;
  13750. struct lpfc_rpi_hdr *rpi_hdr;
  13751. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  13752. rpi_limit = phba->sli4_hba.next_rpi;
  13753. /*
  13754. * Fetch the next logical rpi. Because this index is logical,
  13755. * the driver starts at 0 each time.
  13756. */
  13757. spin_lock_irq(&phba->hbalock);
  13758. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  13759. if (rpi >= rpi_limit)
  13760. rpi = LPFC_RPI_ALLOC_ERROR;
  13761. else {
  13762. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  13763. phba->sli4_hba.max_cfg_param.rpi_used++;
  13764. phba->sli4_hba.rpi_count++;
  13765. }
  13766. /*
  13767. * Don't try to allocate more rpi header regions if the device limit
  13768. * has been exhausted.
  13769. */
  13770. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  13771. (phba->sli4_hba.rpi_count >= max_rpi)) {
  13772. spin_unlock_irq(&phba->hbalock);
  13773. return rpi;
  13774. }
  13775. /*
  13776. * RPI header postings are not required for SLI4 ports capable of
  13777. * extents.
  13778. */
  13779. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  13780. spin_unlock_irq(&phba->hbalock);
  13781. return rpi;
  13782. }
  13783. /*
  13784. * If the driver is running low on rpi resources, allocate another
  13785. * page now. Note that the next_rpi value is used because
  13786. * it represents how many are actually in use whereas max_rpi notes
  13787. * how many are supported max by the device.
  13788. */
  13789. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  13790. spin_unlock_irq(&phba->hbalock);
  13791. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  13792. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  13793. if (!rpi_hdr) {
  13794. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13795. "2002 Error Could not grow rpi "
  13796. "count\n");
  13797. } else {
  13798. lrpi = rpi_hdr->start_rpi;
  13799. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13800. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  13801. }
  13802. }
  13803. return rpi;
  13804. }
  13805. /**
  13806. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13807. * @phba: pointer to lpfc hba data structure.
  13808. *
  13809. * This routine is invoked to release an rpi to the pool of
  13810. * available rpis maintained by the driver.
  13811. **/
  13812. void
  13813. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13814. {
  13815. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  13816. phba->sli4_hba.rpi_count--;
  13817. phba->sli4_hba.max_cfg_param.rpi_used--;
  13818. }
  13819. }
  13820. /**
  13821. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13822. * @phba: pointer to lpfc hba data structure.
  13823. *
  13824. * This routine is invoked to release an rpi to the pool of
  13825. * available rpis maintained by the driver.
  13826. **/
  13827. void
  13828. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13829. {
  13830. spin_lock_irq(&phba->hbalock);
  13831. __lpfc_sli4_free_rpi(phba, rpi);
  13832. spin_unlock_irq(&phba->hbalock);
  13833. }
  13834. /**
  13835. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  13836. * @phba: pointer to lpfc hba data structure.
  13837. *
  13838. * This routine is invoked to remove the memory region that
  13839. * provided rpi via a bitmask.
  13840. **/
  13841. void
  13842. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  13843. {
  13844. kfree(phba->sli4_hba.rpi_bmask);
  13845. kfree(phba->sli4_hba.rpi_ids);
  13846. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  13847. }
  13848. /**
  13849. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  13850. * @phba: pointer to lpfc hba data structure.
  13851. *
  13852. * This routine is invoked to remove the memory region that
  13853. * provided rpi via a bitmask.
  13854. **/
  13855. int
  13856. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  13857. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  13858. {
  13859. LPFC_MBOXQ_t *mboxq;
  13860. struct lpfc_hba *phba = ndlp->phba;
  13861. int rc;
  13862. /* The port is notified of the header region via a mailbox command. */
  13863. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13864. if (!mboxq)
  13865. return -ENOMEM;
  13866. /* Post all rpi memory regions to the port. */
  13867. lpfc_resume_rpi(mboxq, ndlp);
  13868. if (cmpl) {
  13869. mboxq->mbox_cmpl = cmpl;
  13870. mboxq->context1 = arg;
  13871. mboxq->context2 = ndlp;
  13872. } else
  13873. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13874. mboxq->vport = ndlp->vport;
  13875. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13876. if (rc == MBX_NOT_FINISHED) {
  13877. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13878. "2010 Resume RPI Mailbox failed "
  13879. "status %d, mbxStatus x%x\n", rc,
  13880. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13881. mempool_free(mboxq, phba->mbox_mem_pool);
  13882. return -EIO;
  13883. }
  13884. return 0;
  13885. }
  13886. /**
  13887. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  13888. * @vport: Pointer to the vport for which the vpi is being initialized
  13889. *
  13890. * This routine is invoked to activate a vpi with the port.
  13891. *
  13892. * Returns:
  13893. * 0 success
  13894. * -Evalue otherwise
  13895. **/
  13896. int
  13897. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  13898. {
  13899. LPFC_MBOXQ_t *mboxq;
  13900. int rc = 0;
  13901. int retval = MBX_SUCCESS;
  13902. uint32_t mbox_tmo;
  13903. struct lpfc_hba *phba = vport->phba;
  13904. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13905. if (!mboxq)
  13906. return -ENOMEM;
  13907. lpfc_init_vpi(phba, mboxq, vport->vpi);
  13908. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  13909. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  13910. if (rc != MBX_SUCCESS) {
  13911. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  13912. "2022 INIT VPI Mailbox failed "
  13913. "status %d, mbxStatus x%x\n", rc,
  13914. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13915. retval = -EIO;
  13916. }
  13917. if (rc != MBX_TIMEOUT)
  13918. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  13919. return retval;
  13920. }
  13921. /**
  13922. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  13923. * @phba: pointer to lpfc hba data structure.
  13924. * @mboxq: Pointer to mailbox object.
  13925. *
  13926. * This routine is invoked to manually add a single FCF record. The caller
  13927. * must pass a completely initialized FCF_Record. This routine takes
  13928. * care of the nonembedded mailbox operations.
  13929. **/
  13930. static void
  13931. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  13932. {
  13933. void *virt_addr;
  13934. union lpfc_sli4_cfg_shdr *shdr;
  13935. uint32_t shdr_status, shdr_add_status;
  13936. virt_addr = mboxq->sge_array->addr[0];
  13937. /* The IOCTL status is embedded in the mailbox subheader. */
  13938. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  13939. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13940. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13941. if ((shdr_status || shdr_add_status) &&
  13942. (shdr_status != STATUS_FCF_IN_USE))
  13943. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13944. "2558 ADD_FCF_RECORD mailbox failed with "
  13945. "status x%x add_status x%x\n",
  13946. shdr_status, shdr_add_status);
  13947. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13948. }
  13949. /**
  13950. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  13951. * @phba: pointer to lpfc hba data structure.
  13952. * @fcf_record: pointer to the initialized fcf record to add.
  13953. *
  13954. * This routine is invoked to manually add a single FCF record. The caller
  13955. * must pass a completely initialized FCF_Record. This routine takes
  13956. * care of the nonembedded mailbox operations.
  13957. **/
  13958. int
  13959. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  13960. {
  13961. int rc = 0;
  13962. LPFC_MBOXQ_t *mboxq;
  13963. uint8_t *bytep;
  13964. void *virt_addr;
  13965. dma_addr_t phys_addr;
  13966. struct lpfc_mbx_sge sge;
  13967. uint32_t alloc_len, req_len;
  13968. uint32_t fcfindex;
  13969. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13970. if (!mboxq) {
  13971. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13972. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  13973. return -ENOMEM;
  13974. }
  13975. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  13976. sizeof(uint32_t);
  13977. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13978. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13979. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  13980. req_len, LPFC_SLI4_MBX_NEMBED);
  13981. if (alloc_len < req_len) {
  13982. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13983. "2523 Allocated DMA memory size (x%x) is "
  13984. "less than the requested DMA memory "
  13985. "size (x%x)\n", alloc_len, req_len);
  13986. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13987. return -ENOMEM;
  13988. }
  13989. /*
  13990. * Get the first SGE entry from the non-embedded DMA memory. This
  13991. * routine only uses a single SGE.
  13992. */
  13993. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  13994. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  13995. virt_addr = mboxq->sge_array->addr[0];
  13996. /*
  13997. * Configure the FCF record for FCFI 0. This is the driver's
  13998. * hardcoded default and gets used in nonFIP mode.
  13999. */
  14000. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  14001. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  14002. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  14003. /*
  14004. * Copy the fcf_index and the FCF Record Data. The data starts after
  14005. * the FCoE header plus word10. The data copy needs to be endian
  14006. * correct.
  14007. */
  14008. bytep += sizeof(uint32_t);
  14009. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  14010. mboxq->vport = phba->pport;
  14011. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  14012. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14013. if (rc == MBX_NOT_FINISHED) {
  14014. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14015. "2515 ADD_FCF_RECORD mailbox failed with "
  14016. "status 0x%x\n", rc);
  14017. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14018. rc = -EIO;
  14019. } else
  14020. rc = 0;
  14021. return rc;
  14022. }
  14023. /**
  14024. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  14025. * @phba: pointer to lpfc hba data structure.
  14026. * @fcf_record: pointer to the fcf record to write the default data.
  14027. * @fcf_index: FCF table entry index.
  14028. *
  14029. * This routine is invoked to build the driver's default FCF record. The
  14030. * values used are hardcoded. This routine handles memory initialization.
  14031. *
  14032. **/
  14033. void
  14034. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  14035. struct fcf_record *fcf_record,
  14036. uint16_t fcf_index)
  14037. {
  14038. memset(fcf_record, 0, sizeof(struct fcf_record));
  14039. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  14040. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  14041. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  14042. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  14043. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  14044. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  14045. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  14046. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  14047. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  14048. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  14049. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  14050. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  14051. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  14052. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  14053. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  14054. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  14055. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  14056. /* Set the VLAN bit map */
  14057. if (phba->valid_vlan) {
  14058. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  14059. = 1 << (phba->vlan_id % 8);
  14060. }
  14061. }
  14062. /**
  14063. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  14064. * @phba: pointer to lpfc hba data structure.
  14065. * @fcf_index: FCF table entry offset.
  14066. *
  14067. * This routine is invoked to scan the entire FCF table by reading FCF
  14068. * record and processing it one at a time starting from the @fcf_index
  14069. * for initial FCF discovery or fast FCF failover rediscovery.
  14070. *
  14071. * Return 0 if the mailbox command is submitted successfully, none 0
  14072. * otherwise.
  14073. **/
  14074. int
  14075. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14076. {
  14077. int rc = 0, error;
  14078. LPFC_MBOXQ_t *mboxq;
  14079. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  14080. phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
  14081. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14082. if (!mboxq) {
  14083. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14084. "2000 Failed to allocate mbox for "
  14085. "READ_FCF cmd\n");
  14086. error = -ENOMEM;
  14087. goto fail_fcf_scan;
  14088. }
  14089. /* Construct the read FCF record mailbox command */
  14090. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14091. if (rc) {
  14092. error = -EINVAL;
  14093. goto fail_fcf_scan;
  14094. }
  14095. /* Issue the mailbox command asynchronously */
  14096. mboxq->vport = phba->pport;
  14097. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  14098. spin_lock_irq(&phba->hbalock);
  14099. phba->hba_flag |= FCF_TS_INPROG;
  14100. spin_unlock_irq(&phba->hbalock);
  14101. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14102. if (rc == MBX_NOT_FINISHED)
  14103. error = -EIO;
  14104. else {
  14105. /* Reset eligible FCF count for new scan */
  14106. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  14107. phba->fcf.eligible_fcf_cnt = 0;
  14108. error = 0;
  14109. }
  14110. fail_fcf_scan:
  14111. if (error) {
  14112. if (mboxq)
  14113. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14114. /* FCF scan failed, clear FCF_TS_INPROG flag */
  14115. spin_lock_irq(&phba->hbalock);
  14116. phba->hba_flag &= ~FCF_TS_INPROG;
  14117. spin_unlock_irq(&phba->hbalock);
  14118. }
  14119. return error;
  14120. }
  14121. /**
  14122. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  14123. * @phba: pointer to lpfc hba data structure.
  14124. * @fcf_index: FCF table entry offset.
  14125. *
  14126. * This routine is invoked to read an FCF record indicated by @fcf_index
  14127. * and to use it for FLOGI roundrobin FCF failover.
  14128. *
  14129. * Return 0 if the mailbox command is submitted successfully, none 0
  14130. * otherwise.
  14131. **/
  14132. int
  14133. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14134. {
  14135. int rc = 0, error;
  14136. LPFC_MBOXQ_t *mboxq;
  14137. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14138. if (!mboxq) {
  14139. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14140. "2763 Failed to allocate mbox for "
  14141. "READ_FCF cmd\n");
  14142. error = -ENOMEM;
  14143. goto fail_fcf_read;
  14144. }
  14145. /* Construct the read FCF record mailbox command */
  14146. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14147. if (rc) {
  14148. error = -EINVAL;
  14149. goto fail_fcf_read;
  14150. }
  14151. /* Issue the mailbox command asynchronously */
  14152. mboxq->vport = phba->pport;
  14153. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  14154. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14155. if (rc == MBX_NOT_FINISHED)
  14156. error = -EIO;
  14157. else
  14158. error = 0;
  14159. fail_fcf_read:
  14160. if (error && mboxq)
  14161. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14162. return error;
  14163. }
  14164. /**
  14165. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  14166. * @phba: pointer to lpfc hba data structure.
  14167. * @fcf_index: FCF table entry offset.
  14168. *
  14169. * This routine is invoked to read an FCF record indicated by @fcf_index to
  14170. * determine whether it's eligible for FLOGI roundrobin failover list.
  14171. *
  14172. * Return 0 if the mailbox command is submitted successfully, none 0
  14173. * otherwise.
  14174. **/
  14175. int
  14176. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14177. {
  14178. int rc = 0, error;
  14179. LPFC_MBOXQ_t *mboxq;
  14180. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14181. if (!mboxq) {
  14182. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14183. "2758 Failed to allocate mbox for "
  14184. "READ_FCF cmd\n");
  14185. error = -ENOMEM;
  14186. goto fail_fcf_read;
  14187. }
  14188. /* Construct the read FCF record mailbox command */
  14189. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14190. if (rc) {
  14191. error = -EINVAL;
  14192. goto fail_fcf_read;
  14193. }
  14194. /* Issue the mailbox command asynchronously */
  14195. mboxq->vport = phba->pport;
  14196. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  14197. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14198. if (rc == MBX_NOT_FINISHED)
  14199. error = -EIO;
  14200. else
  14201. error = 0;
  14202. fail_fcf_read:
  14203. if (error && mboxq)
  14204. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14205. return error;
  14206. }
  14207. /**
  14208. * lpfc_check_next_fcf_pri
  14209. * phba pointer to the lpfc_hba struct for this port.
  14210. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  14211. * routine when the rr_bmask is empty. The FCF indecies are put into the
  14212. * rr_bmask based on their priority level. Starting from the highest priority
  14213. * to the lowest. The most likely FCF candidate will be in the highest
  14214. * priority group. When this routine is called it searches the fcf_pri list for
  14215. * next lowest priority group and repopulates the rr_bmask with only those
  14216. * fcf_indexes.
  14217. * returns:
  14218. * 1=success 0=failure
  14219. **/
  14220. int
  14221. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  14222. {
  14223. uint16_t next_fcf_pri;
  14224. uint16_t last_index;
  14225. struct lpfc_fcf_pri *fcf_pri;
  14226. int rc;
  14227. int ret = 0;
  14228. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  14229. LPFC_SLI4_FCF_TBL_INDX_MAX);
  14230. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14231. "3060 Last IDX %d\n", last_index);
  14232. /* Verify the priority list has 2 or more entries */
  14233. spin_lock_irq(&phba->hbalock);
  14234. if (list_empty(&phba->fcf.fcf_pri_list) ||
  14235. list_is_singular(&phba->fcf.fcf_pri_list)) {
  14236. spin_unlock_irq(&phba->hbalock);
  14237. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14238. "3061 Last IDX %d\n", last_index);
  14239. return 0; /* Empty rr list */
  14240. }
  14241. spin_unlock_irq(&phba->hbalock);
  14242. next_fcf_pri = 0;
  14243. /*
  14244. * Clear the rr_bmask and set all of the bits that are at this
  14245. * priority.
  14246. */
  14247. memset(phba->fcf.fcf_rr_bmask, 0,
  14248. sizeof(*phba->fcf.fcf_rr_bmask));
  14249. spin_lock_irq(&phba->hbalock);
  14250. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14251. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  14252. continue;
  14253. /*
  14254. * the 1st priority that has not FLOGI failed
  14255. * will be the highest.
  14256. */
  14257. if (!next_fcf_pri)
  14258. next_fcf_pri = fcf_pri->fcf_rec.priority;
  14259. spin_unlock_irq(&phba->hbalock);
  14260. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  14261. rc = lpfc_sli4_fcf_rr_index_set(phba,
  14262. fcf_pri->fcf_rec.fcf_index);
  14263. if (rc)
  14264. return 0;
  14265. }
  14266. spin_lock_irq(&phba->hbalock);
  14267. }
  14268. /*
  14269. * if next_fcf_pri was not set above and the list is not empty then
  14270. * we have failed flogis on all of them. So reset flogi failed
  14271. * and start at the beginning.
  14272. */
  14273. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  14274. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14275. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  14276. /*
  14277. * the 1st priority that has not FLOGI failed
  14278. * will be the highest.
  14279. */
  14280. if (!next_fcf_pri)
  14281. next_fcf_pri = fcf_pri->fcf_rec.priority;
  14282. spin_unlock_irq(&phba->hbalock);
  14283. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  14284. rc = lpfc_sli4_fcf_rr_index_set(phba,
  14285. fcf_pri->fcf_rec.fcf_index);
  14286. if (rc)
  14287. return 0;
  14288. }
  14289. spin_lock_irq(&phba->hbalock);
  14290. }
  14291. } else
  14292. ret = 1;
  14293. spin_unlock_irq(&phba->hbalock);
  14294. return ret;
  14295. }
  14296. /**
  14297. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  14298. * @phba: pointer to lpfc hba data structure.
  14299. *
  14300. * This routine is to get the next eligible FCF record index in a round
  14301. * robin fashion. If the next eligible FCF record index equals to the
  14302. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  14303. * shall be returned, otherwise, the next eligible FCF record's index
  14304. * shall be returned.
  14305. **/
  14306. uint16_t
  14307. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  14308. {
  14309. uint16_t next_fcf_index;
  14310. initial_priority:
  14311. /* Search start from next bit of currently registered FCF index */
  14312. next_fcf_index = phba->fcf.current_rec.fcf_indx;
  14313. next_priority:
  14314. /* Determine the next fcf index to check */
  14315. next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
  14316. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14317. LPFC_SLI4_FCF_TBL_INDX_MAX,
  14318. next_fcf_index);
  14319. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  14320. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14321. /*
  14322. * If we have wrapped then we need to clear the bits that
  14323. * have been tested so that we can detect when we should
  14324. * change the priority level.
  14325. */
  14326. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14327. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  14328. }
  14329. /* Check roundrobin failover list empty condition */
  14330. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  14331. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  14332. /*
  14333. * If next fcf index is not found check if there are lower
  14334. * Priority level fcf's in the fcf_priority list.
  14335. * Set up the rr_bmask with all of the avaiable fcf bits
  14336. * at that level and continue the selection process.
  14337. */
  14338. if (lpfc_check_next_fcf_pri_level(phba))
  14339. goto initial_priority;
  14340. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14341. "2844 No roundrobin failover FCF available\n");
  14342. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  14343. return LPFC_FCOE_FCF_NEXT_NONE;
  14344. else {
  14345. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14346. "3063 Only FCF available idx %d, flag %x\n",
  14347. next_fcf_index,
  14348. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  14349. return next_fcf_index;
  14350. }
  14351. }
  14352. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  14353. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  14354. LPFC_FCF_FLOGI_FAILED)
  14355. goto next_priority;
  14356. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14357. "2845 Get next roundrobin failover FCF (x%x)\n",
  14358. next_fcf_index);
  14359. return next_fcf_index;
  14360. }
  14361. /**
  14362. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  14363. * @phba: pointer to lpfc hba data structure.
  14364. *
  14365. * This routine sets the FCF record index in to the eligible bmask for
  14366. * roundrobin failover search. It checks to make sure that the index
  14367. * does not go beyond the range of the driver allocated bmask dimension
  14368. * before setting the bit.
  14369. *
  14370. * Returns 0 if the index bit successfully set, otherwise, it returns
  14371. * -EINVAL.
  14372. **/
  14373. int
  14374. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  14375. {
  14376. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14377. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14378. "2610 FCF (x%x) reached driver's book "
  14379. "keeping dimension:x%x\n",
  14380. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14381. return -EINVAL;
  14382. }
  14383. /* Set the eligible FCF record index bmask */
  14384. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14385. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14386. "2790 Set FCF (x%x) to roundrobin FCF failover "
  14387. "bmask\n", fcf_index);
  14388. return 0;
  14389. }
  14390. /**
  14391. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  14392. * @phba: pointer to lpfc hba data structure.
  14393. *
  14394. * This routine clears the FCF record index from the eligible bmask for
  14395. * roundrobin failover search. It checks to make sure that the index
  14396. * does not go beyond the range of the driver allocated bmask dimension
  14397. * before clearing the bit.
  14398. **/
  14399. void
  14400. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  14401. {
  14402. struct lpfc_fcf_pri *fcf_pri;
  14403. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14404. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14405. "2762 FCF (x%x) reached driver's book "
  14406. "keeping dimension:x%x\n",
  14407. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14408. return;
  14409. }
  14410. /* Clear the eligible FCF record index bmask */
  14411. spin_lock_irq(&phba->hbalock);
  14412. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14413. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  14414. list_del_init(&fcf_pri->list);
  14415. break;
  14416. }
  14417. }
  14418. spin_unlock_irq(&phba->hbalock);
  14419. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14420. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14421. "2791 Clear FCF (x%x) from roundrobin failover "
  14422. "bmask\n", fcf_index);
  14423. }
  14424. /**
  14425. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  14426. * @phba: pointer to lpfc hba data structure.
  14427. *
  14428. * This routine is the completion routine for the rediscover FCF table mailbox
  14429. * command. If the mailbox command returned failure, it will try to stop the
  14430. * FCF rediscover wait timer.
  14431. **/
  14432. void
  14433. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  14434. {
  14435. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14436. uint32_t shdr_status, shdr_add_status;
  14437. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14438. shdr_status = bf_get(lpfc_mbox_hdr_status,
  14439. &redisc_fcf->header.cfg_shdr.response);
  14440. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  14441. &redisc_fcf->header.cfg_shdr.response);
  14442. if (shdr_status || shdr_add_status) {
  14443. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14444. "2746 Requesting for FCF rediscovery failed "
  14445. "status x%x add_status x%x\n",
  14446. shdr_status, shdr_add_status);
  14447. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  14448. spin_lock_irq(&phba->hbalock);
  14449. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  14450. spin_unlock_irq(&phba->hbalock);
  14451. /*
  14452. * CVL event triggered FCF rediscover request failed,
  14453. * last resort to re-try current registered FCF entry.
  14454. */
  14455. lpfc_retry_pport_discovery(phba);
  14456. } else {
  14457. spin_lock_irq(&phba->hbalock);
  14458. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  14459. spin_unlock_irq(&phba->hbalock);
  14460. /*
  14461. * DEAD FCF event triggered FCF rediscover request
  14462. * failed, last resort to fail over as a link down
  14463. * to FCF registration.
  14464. */
  14465. lpfc_sli4_fcf_dead_failthrough(phba);
  14466. }
  14467. } else {
  14468. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14469. "2775 Start FCF rediscover quiescent timer\n");
  14470. /*
  14471. * Start FCF rediscovery wait timer for pending FCF
  14472. * before rescan FCF record table.
  14473. */
  14474. lpfc_fcf_redisc_wait_start_timer(phba);
  14475. }
  14476. mempool_free(mbox, phba->mbox_mem_pool);
  14477. }
  14478. /**
  14479. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  14480. * @phba: pointer to lpfc hba data structure.
  14481. *
  14482. * This routine is invoked to request for rediscovery of the entire FCF table
  14483. * by the port.
  14484. **/
  14485. int
  14486. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  14487. {
  14488. LPFC_MBOXQ_t *mbox;
  14489. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14490. int rc, length;
  14491. /* Cancel retry delay timers to all vports before FCF rediscover */
  14492. lpfc_cancel_all_vport_retry_delay_timer(phba);
  14493. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14494. if (!mbox) {
  14495. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14496. "2745 Failed to allocate mbox for "
  14497. "requesting FCF rediscover.\n");
  14498. return -ENOMEM;
  14499. }
  14500. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  14501. sizeof(struct lpfc_sli4_cfg_mhdr));
  14502. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  14503. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  14504. length, LPFC_SLI4_MBX_EMBED);
  14505. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14506. /* Set count to 0 for invalidating the entire FCF database */
  14507. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  14508. /* Issue the mailbox command asynchronously */
  14509. mbox->vport = phba->pport;
  14510. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  14511. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  14512. if (rc == MBX_NOT_FINISHED) {
  14513. mempool_free(mbox, phba->mbox_mem_pool);
  14514. return -EIO;
  14515. }
  14516. return 0;
  14517. }
  14518. /**
  14519. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  14520. * @phba: pointer to lpfc hba data structure.
  14521. *
  14522. * This function is the failover routine as a last resort to the FCF DEAD
  14523. * event when driver failed to perform fast FCF failover.
  14524. **/
  14525. void
  14526. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  14527. {
  14528. uint32_t link_state;
  14529. /*
  14530. * Last resort as FCF DEAD event failover will treat this as
  14531. * a link down, but save the link state because we don't want
  14532. * it to be changed to Link Down unless it is already down.
  14533. */
  14534. link_state = phba->link_state;
  14535. lpfc_linkdown(phba);
  14536. phba->link_state = link_state;
  14537. /* Unregister FCF if no devices connected to it */
  14538. lpfc_unregister_unused_fcf(phba);
  14539. }
  14540. /**
  14541. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  14542. * @phba: pointer to lpfc hba data structure.
  14543. * @rgn23_data: pointer to configure region 23 data.
  14544. *
  14545. * This function gets SLI3 port configure region 23 data through memory dump
  14546. * mailbox command. When it successfully retrieves data, the size of the data
  14547. * will be returned, otherwise, 0 will be returned.
  14548. **/
  14549. static uint32_t
  14550. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14551. {
  14552. LPFC_MBOXQ_t *pmb = NULL;
  14553. MAILBOX_t *mb;
  14554. uint32_t offset = 0;
  14555. int rc;
  14556. if (!rgn23_data)
  14557. return 0;
  14558. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14559. if (!pmb) {
  14560. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14561. "2600 failed to allocate mailbox memory\n");
  14562. return 0;
  14563. }
  14564. mb = &pmb->u.mb;
  14565. do {
  14566. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  14567. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  14568. if (rc != MBX_SUCCESS) {
  14569. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  14570. "2601 failed to read config "
  14571. "region 23, rc 0x%x Status 0x%x\n",
  14572. rc, mb->mbxStatus);
  14573. mb->un.varDmp.word_cnt = 0;
  14574. }
  14575. /*
  14576. * dump mem may return a zero when finished or we got a
  14577. * mailbox error, either way we are done.
  14578. */
  14579. if (mb->un.varDmp.word_cnt == 0)
  14580. break;
  14581. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  14582. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  14583. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  14584. rgn23_data + offset,
  14585. mb->un.varDmp.word_cnt);
  14586. offset += mb->un.varDmp.word_cnt;
  14587. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  14588. mempool_free(pmb, phba->mbox_mem_pool);
  14589. return offset;
  14590. }
  14591. /**
  14592. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  14593. * @phba: pointer to lpfc hba data structure.
  14594. * @rgn23_data: pointer to configure region 23 data.
  14595. *
  14596. * This function gets SLI4 port configure region 23 data through memory dump
  14597. * mailbox command. When it successfully retrieves data, the size of the data
  14598. * will be returned, otherwise, 0 will be returned.
  14599. **/
  14600. static uint32_t
  14601. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14602. {
  14603. LPFC_MBOXQ_t *mboxq = NULL;
  14604. struct lpfc_dmabuf *mp = NULL;
  14605. struct lpfc_mqe *mqe;
  14606. uint32_t data_length = 0;
  14607. int rc;
  14608. if (!rgn23_data)
  14609. return 0;
  14610. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14611. if (!mboxq) {
  14612. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14613. "3105 failed to allocate mailbox memory\n");
  14614. return 0;
  14615. }
  14616. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  14617. goto out;
  14618. mqe = &mboxq->u.mqe;
  14619. mp = (struct lpfc_dmabuf *) mboxq->context1;
  14620. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14621. if (rc)
  14622. goto out;
  14623. data_length = mqe->un.mb_words[5];
  14624. if (data_length == 0)
  14625. goto out;
  14626. if (data_length > DMP_RGN23_SIZE) {
  14627. data_length = 0;
  14628. goto out;
  14629. }
  14630. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  14631. out:
  14632. mempool_free(mboxq, phba->mbox_mem_pool);
  14633. if (mp) {
  14634. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14635. kfree(mp);
  14636. }
  14637. return data_length;
  14638. }
  14639. /**
  14640. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  14641. * @phba: pointer to lpfc hba data structure.
  14642. *
  14643. * This function read region 23 and parse TLV for port status to
  14644. * decide if the user disaled the port. If the TLV indicates the
  14645. * port is disabled, the hba_flag is set accordingly.
  14646. **/
  14647. void
  14648. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  14649. {
  14650. uint8_t *rgn23_data = NULL;
  14651. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  14652. uint32_t offset = 0;
  14653. /* Get adapter Region 23 data */
  14654. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  14655. if (!rgn23_data)
  14656. goto out;
  14657. if (phba->sli_rev < LPFC_SLI_REV4)
  14658. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  14659. else {
  14660. if_type = bf_get(lpfc_sli_intf_if_type,
  14661. &phba->sli4_hba.sli_intf);
  14662. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  14663. goto out;
  14664. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  14665. }
  14666. if (!data_size)
  14667. goto out;
  14668. /* Check the region signature first */
  14669. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  14670. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14671. "2619 Config region 23 has bad signature\n");
  14672. goto out;
  14673. }
  14674. offset += 4;
  14675. /* Check the data structure version */
  14676. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  14677. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14678. "2620 Config region 23 has bad version\n");
  14679. goto out;
  14680. }
  14681. offset += 4;
  14682. /* Parse TLV entries in the region */
  14683. while (offset < data_size) {
  14684. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  14685. break;
  14686. /*
  14687. * If the TLV is not driver specific TLV or driver id is
  14688. * not linux driver id, skip the record.
  14689. */
  14690. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  14691. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  14692. (rgn23_data[offset + 3] != 0)) {
  14693. offset += rgn23_data[offset + 1] * 4 + 4;
  14694. continue;
  14695. }
  14696. /* Driver found a driver specific TLV in the config region */
  14697. sub_tlv_len = rgn23_data[offset + 1] * 4;
  14698. offset += 4;
  14699. tlv_offset = 0;
  14700. /*
  14701. * Search for configured port state sub-TLV.
  14702. */
  14703. while ((offset < data_size) &&
  14704. (tlv_offset < sub_tlv_len)) {
  14705. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  14706. offset += 4;
  14707. tlv_offset += 4;
  14708. break;
  14709. }
  14710. if (rgn23_data[offset] != PORT_STE_TYPE) {
  14711. offset += rgn23_data[offset + 1] * 4 + 4;
  14712. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  14713. continue;
  14714. }
  14715. /* This HBA contains PORT_STE configured */
  14716. if (!rgn23_data[offset + 2])
  14717. phba->hba_flag |= LINK_DISABLED;
  14718. goto out;
  14719. }
  14720. }
  14721. out:
  14722. kfree(rgn23_data);
  14723. return;
  14724. }
  14725. /**
  14726. * lpfc_wr_object - write an object to the firmware
  14727. * @phba: HBA structure that indicates port to create a queue on.
  14728. * @dmabuf_list: list of dmabufs to write to the port.
  14729. * @size: the total byte value of the objects to write to the port.
  14730. * @offset: the current offset to be used to start the transfer.
  14731. *
  14732. * This routine will create a wr_object mailbox command to send to the port.
  14733. * the mailbox command will be constructed using the dma buffers described in
  14734. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  14735. * BDEs that the imbedded mailbox can support. The @offset variable will be
  14736. * used to indicate the starting offset of the transfer and will also return
  14737. * the offset after the write object mailbox has completed. @size is used to
  14738. * determine the end of the object and whether the eof bit should be set.
  14739. *
  14740. * Return 0 is successful and offset will contain the the new offset to use
  14741. * for the next write.
  14742. * Return negative value for error cases.
  14743. **/
  14744. int
  14745. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  14746. uint32_t size, uint32_t *offset)
  14747. {
  14748. struct lpfc_mbx_wr_object *wr_object;
  14749. LPFC_MBOXQ_t *mbox;
  14750. int rc = 0, i = 0;
  14751. uint32_t shdr_status, shdr_add_status;
  14752. uint32_t mbox_tmo;
  14753. union lpfc_sli4_cfg_shdr *shdr;
  14754. struct lpfc_dmabuf *dmabuf;
  14755. uint32_t written = 0;
  14756. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14757. if (!mbox)
  14758. return -ENOMEM;
  14759. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14760. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  14761. sizeof(struct lpfc_mbx_wr_object) -
  14762. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  14763. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  14764. wr_object->u.request.write_offset = *offset;
  14765. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  14766. wr_object->u.request.object_name[0] =
  14767. cpu_to_le32(wr_object->u.request.object_name[0]);
  14768. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  14769. list_for_each_entry(dmabuf, dmabuf_list, list) {
  14770. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  14771. break;
  14772. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  14773. wr_object->u.request.bde[i].addrHigh =
  14774. putPaddrHigh(dmabuf->phys);
  14775. if (written + SLI4_PAGE_SIZE >= size) {
  14776. wr_object->u.request.bde[i].tus.f.bdeSize =
  14777. (size - written);
  14778. written += (size - written);
  14779. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  14780. } else {
  14781. wr_object->u.request.bde[i].tus.f.bdeSize =
  14782. SLI4_PAGE_SIZE;
  14783. written += SLI4_PAGE_SIZE;
  14784. }
  14785. i++;
  14786. }
  14787. wr_object->u.request.bde_count = i;
  14788. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  14789. if (!phba->sli4_hba.intr_enable)
  14790. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14791. else {
  14792. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  14793. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  14794. }
  14795. /* The IOCTL status is embedded in the mailbox subheader. */
  14796. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  14797. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14798. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14799. if (rc != MBX_TIMEOUT)
  14800. mempool_free(mbox, phba->mbox_mem_pool);
  14801. if (shdr_status || shdr_add_status || rc) {
  14802. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14803. "3025 Write Object mailbox failed with "
  14804. "status x%x add_status x%x, mbx status x%x\n",
  14805. shdr_status, shdr_add_status, rc);
  14806. rc = -ENXIO;
  14807. } else
  14808. *offset += wr_object->u.response.actual_write_length;
  14809. return rc;
  14810. }
  14811. /**
  14812. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  14813. * @vport: pointer to vport data structure.
  14814. *
  14815. * This function iterate through the mailboxq and clean up all REG_LOGIN
  14816. * and REG_VPI mailbox commands associated with the vport. This function
  14817. * is called when driver want to restart discovery of the vport due to
  14818. * a Clear Virtual Link event.
  14819. **/
  14820. void
  14821. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  14822. {
  14823. struct lpfc_hba *phba = vport->phba;
  14824. LPFC_MBOXQ_t *mb, *nextmb;
  14825. struct lpfc_dmabuf *mp;
  14826. struct lpfc_nodelist *ndlp;
  14827. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  14828. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  14829. LIST_HEAD(mbox_cmd_list);
  14830. uint8_t restart_loop;
  14831. /* Clean up internally queued mailbox commands with the vport */
  14832. spin_lock_irq(&phba->hbalock);
  14833. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  14834. if (mb->vport != vport)
  14835. continue;
  14836. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14837. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14838. continue;
  14839. list_del(&mb->list);
  14840. list_add_tail(&mb->list, &mbox_cmd_list);
  14841. }
  14842. /* Clean up active mailbox command with the vport */
  14843. mb = phba->sli.mbox_active;
  14844. if (mb && (mb->vport == vport)) {
  14845. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  14846. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  14847. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14848. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14849. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  14850. /* Put reference count for delayed processing */
  14851. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  14852. /* Unregister the RPI when mailbox complete */
  14853. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14854. }
  14855. }
  14856. /* Cleanup any mailbox completions which are not yet processed */
  14857. do {
  14858. restart_loop = 0;
  14859. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  14860. /*
  14861. * If this mailox is already processed or it is
  14862. * for another vport ignore it.
  14863. */
  14864. if ((mb->vport != vport) ||
  14865. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  14866. continue;
  14867. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14868. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14869. continue;
  14870. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14871. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14872. ndlp = (struct lpfc_nodelist *)mb->context2;
  14873. /* Unregister the RPI when mailbox complete */
  14874. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14875. restart_loop = 1;
  14876. spin_unlock_irq(&phba->hbalock);
  14877. spin_lock(shost->host_lock);
  14878. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14879. spin_unlock(shost->host_lock);
  14880. spin_lock_irq(&phba->hbalock);
  14881. break;
  14882. }
  14883. }
  14884. } while (restart_loop);
  14885. spin_unlock_irq(&phba->hbalock);
  14886. /* Release the cleaned-up mailbox commands */
  14887. while (!list_empty(&mbox_cmd_list)) {
  14888. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  14889. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14890. mp = (struct lpfc_dmabuf *) (mb->context1);
  14891. if (mp) {
  14892. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14893. kfree(mp);
  14894. }
  14895. ndlp = (struct lpfc_nodelist *) mb->context2;
  14896. mb->context2 = NULL;
  14897. if (ndlp) {
  14898. spin_lock(shost->host_lock);
  14899. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14900. spin_unlock(shost->host_lock);
  14901. lpfc_nlp_put(ndlp);
  14902. }
  14903. }
  14904. mempool_free(mb, phba->mbox_mem_pool);
  14905. }
  14906. /* Release the ndlp with the cleaned-up active mailbox command */
  14907. if (act_mbx_ndlp) {
  14908. spin_lock(shost->host_lock);
  14909. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14910. spin_unlock(shost->host_lock);
  14911. lpfc_nlp_put(act_mbx_ndlp);
  14912. }
  14913. }
  14914. /**
  14915. * lpfc_drain_txq - Drain the txq
  14916. * @phba: Pointer to HBA context object.
  14917. *
  14918. * This function attempt to submit IOCBs on the txq
  14919. * to the adapter. For SLI4 adapters, the txq contains
  14920. * ELS IOCBs that have been deferred because the there
  14921. * are no SGLs. This congestion can occur with large
  14922. * vport counts during node discovery.
  14923. **/
  14924. uint32_t
  14925. lpfc_drain_txq(struct lpfc_hba *phba)
  14926. {
  14927. LIST_HEAD(completions);
  14928. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  14929. struct lpfc_iocbq *piocbq = 0;
  14930. unsigned long iflags = 0;
  14931. char *fail_msg = NULL;
  14932. struct lpfc_sglq *sglq;
  14933. union lpfc_wqe wqe;
  14934. int txq_cnt = 0;
  14935. spin_lock_irqsave(&phba->hbalock, iflags);
  14936. list_for_each_entry(piocbq, &pring->txq, list) {
  14937. txq_cnt++;
  14938. }
  14939. if (txq_cnt > pring->txq_max)
  14940. pring->txq_max = txq_cnt;
  14941. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14942. while (!list_empty(&pring->txq)) {
  14943. spin_lock_irqsave(&phba->hbalock, iflags);
  14944. piocbq = lpfc_sli_ringtx_get(phba, pring);
  14945. if (!piocbq) {
  14946. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14947. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14948. "2823 txq empty and txq_cnt is %d\n ",
  14949. txq_cnt);
  14950. break;
  14951. }
  14952. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  14953. if (!sglq) {
  14954. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  14955. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14956. break;
  14957. }
  14958. txq_cnt--;
  14959. /* The xri and iocb resources secured,
  14960. * attempt to issue request
  14961. */
  14962. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  14963. piocbq->sli4_xritag = sglq->sli4_xritag;
  14964. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  14965. fail_msg = "to convert bpl to sgl";
  14966. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  14967. fail_msg = "to convert iocb to wqe";
  14968. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  14969. fail_msg = " - Wq is full";
  14970. else
  14971. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  14972. if (fail_msg) {
  14973. /* Failed means we can't issue and need to cancel */
  14974. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14975. "2822 IOCB failed %s iotag 0x%x "
  14976. "xri 0x%x\n",
  14977. fail_msg,
  14978. piocbq->iotag, piocbq->sli4_xritag);
  14979. list_add_tail(&piocbq->list, &completions);
  14980. }
  14981. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14982. }
  14983. /* Cancel all the IOCBs that cannot be issued */
  14984. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  14985. IOERR_SLI_ABORTED);
  14986. return txq_cnt;
  14987. }