lpfc_sli.c 486 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2012 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *,
  63. struct lpfc_cqe *);
  64. static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *,
  65. int);
  66. static IOCB_t *
  67. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  68. {
  69. return &iocbq->iocb;
  70. }
  71. /**
  72. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  73. * @q: The Work Queue to operate on.
  74. * @wqe: The work Queue Entry to put on the Work queue.
  75. *
  76. * This routine will copy the contents of @wqe to the next available entry on
  77. * the @q. This function will then ring the Work Queue Doorbell to signal the
  78. * HBA to start processing the Work Queue Entry. This function returns 0 if
  79. * successful. If no entries are available on @q then this function will return
  80. * -ENOMEM.
  81. * The caller is expected to hold the hbalock when calling this routine.
  82. **/
  83. static uint32_t
  84. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  85. {
  86. union lpfc_wqe *temp_wqe;
  87. struct lpfc_register doorbell;
  88. uint32_t host_index;
  89. /* sanity check on queue memory */
  90. if (unlikely(!q))
  91. return -ENOMEM;
  92. temp_wqe = q->qe[q->host_index].wqe;
  93. /* If the host has not yet processed the next entry then we are done */
  94. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  95. return -ENOMEM;
  96. /* set consumption flag every once in a while */
  97. if (!((q->host_index + 1) % q->entry_repost))
  98. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  99. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  100. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  101. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  102. /* Update the host index before invoking device */
  103. host_index = q->host_index;
  104. q->host_index = ((q->host_index + 1) % q->entry_count);
  105. /* Ring Doorbell */
  106. doorbell.word0 = 0;
  107. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  108. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  109. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  110. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  111. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  112. return 0;
  113. }
  114. /**
  115. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  116. * @q: The Work Queue to operate on.
  117. * @index: The index to advance the hba index to.
  118. *
  119. * This routine will update the HBA index of a queue to reflect consumption of
  120. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  121. * an entry the host calls this function to update the queue's internal
  122. * pointers. This routine returns the number of entries that were consumed by
  123. * the HBA.
  124. **/
  125. static uint32_t
  126. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  127. {
  128. uint32_t released = 0;
  129. /* sanity check on queue memory */
  130. if (unlikely(!q))
  131. return 0;
  132. if (q->hba_index == index)
  133. return 0;
  134. do {
  135. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  136. released++;
  137. } while (q->hba_index != index);
  138. return released;
  139. }
  140. /**
  141. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  142. * @q: The Mailbox Queue to operate on.
  143. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  144. *
  145. * This routine will copy the contents of @mqe to the next available entry on
  146. * the @q. This function will then ring the Work Queue Doorbell to signal the
  147. * HBA to start processing the Work Queue Entry. This function returns 0 if
  148. * successful. If no entries are available on @q then this function will return
  149. * -ENOMEM.
  150. * The caller is expected to hold the hbalock when calling this routine.
  151. **/
  152. static uint32_t
  153. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  154. {
  155. struct lpfc_mqe *temp_mqe;
  156. struct lpfc_register doorbell;
  157. uint32_t host_index;
  158. /* sanity check on queue memory */
  159. if (unlikely(!q))
  160. return -ENOMEM;
  161. temp_mqe = q->qe[q->host_index].mqe;
  162. /* If the host has not yet processed the next entry then we are done */
  163. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  164. return -ENOMEM;
  165. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  166. /* Save off the mailbox pointer for completion */
  167. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  168. /* Update the host index before invoking device */
  169. host_index = q->host_index;
  170. q->host_index = ((q->host_index + 1) % q->entry_count);
  171. /* Ring Doorbell */
  172. doorbell.word0 = 0;
  173. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  174. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  175. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  176. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  177. return 0;
  178. }
  179. /**
  180. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  181. * @q: The Mailbox Queue to operate on.
  182. *
  183. * This routine will update the HBA index of a queue to reflect consumption of
  184. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  185. * an entry the host calls this function to update the queue's internal
  186. * pointers. This routine returns the number of entries that were consumed by
  187. * the HBA.
  188. **/
  189. static uint32_t
  190. lpfc_sli4_mq_release(struct lpfc_queue *q)
  191. {
  192. /* sanity check on queue memory */
  193. if (unlikely(!q))
  194. return 0;
  195. /* Clear the mailbox pointer for completion */
  196. q->phba->mbox = NULL;
  197. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  198. return 1;
  199. }
  200. /**
  201. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  202. * @q: The Event Queue to get the first valid EQE from
  203. *
  204. * This routine will get the first valid Event Queue Entry from @q, update
  205. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  206. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  207. * processed, but not popped back to the HBA then this routine will return NULL.
  208. **/
  209. static struct lpfc_eqe *
  210. lpfc_sli4_eq_get(struct lpfc_queue *q)
  211. {
  212. struct lpfc_eqe *eqe;
  213. /* sanity check on queue memory */
  214. if (unlikely(!q))
  215. return NULL;
  216. eqe = q->qe[q->hba_index].eqe;
  217. /* If the next EQE is not valid then we are done */
  218. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  219. return NULL;
  220. /* If the host has not yet processed the next entry then we are done */
  221. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  222. return NULL;
  223. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  224. return eqe;
  225. }
  226. /**
  227. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  228. * @q: The Event Queue that the host has completed processing for.
  229. * @arm: Indicates whether the host wants to arms this CQ.
  230. *
  231. * This routine will mark all Event Queue Entries on @q, from the last
  232. * known completed entry to the last entry that was processed, as completed
  233. * by clearing the valid bit for each completion queue entry. Then it will
  234. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  235. * The internal host index in the @q will be updated by this routine to indicate
  236. * that the host has finished processing the entries. The @arm parameter
  237. * indicates that the queue should be rearmed when ringing the doorbell.
  238. *
  239. * This function will return the number of EQEs that were popped.
  240. **/
  241. uint32_t
  242. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  243. {
  244. uint32_t released = 0;
  245. struct lpfc_eqe *temp_eqe;
  246. struct lpfc_register doorbell;
  247. /* sanity check on queue memory */
  248. if (unlikely(!q))
  249. return 0;
  250. /* while there are valid entries */
  251. while (q->hba_index != q->host_index) {
  252. temp_eqe = q->qe[q->host_index].eqe;
  253. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  254. released++;
  255. q->host_index = ((q->host_index + 1) % q->entry_count);
  256. }
  257. if (unlikely(released == 0 && !arm))
  258. return 0;
  259. /* ring doorbell for number popped */
  260. doorbell.word0 = 0;
  261. if (arm) {
  262. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  263. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  264. }
  265. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  266. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  267. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  268. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  269. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  270. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  271. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  272. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  273. readl(q->phba->sli4_hba.EQCQDBregaddr);
  274. return released;
  275. }
  276. /**
  277. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  278. * @q: The Completion Queue to get the first valid CQE from
  279. *
  280. * This routine will get the first valid Completion Queue Entry from @q, update
  281. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  282. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  283. * processed, but not popped back to the HBA then this routine will return NULL.
  284. **/
  285. static struct lpfc_cqe *
  286. lpfc_sli4_cq_get(struct lpfc_queue *q)
  287. {
  288. struct lpfc_cqe *cqe;
  289. /* sanity check on queue memory */
  290. if (unlikely(!q))
  291. return NULL;
  292. /* If the next CQE is not valid then we are done */
  293. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  294. return NULL;
  295. /* If the host has not yet processed the next entry then we are done */
  296. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  297. return NULL;
  298. cqe = q->qe[q->hba_index].cqe;
  299. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  300. return cqe;
  301. }
  302. /**
  303. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  304. * @q: The Completion Queue that the host has completed processing for.
  305. * @arm: Indicates whether the host wants to arms this CQ.
  306. *
  307. * This routine will mark all Completion queue entries on @q, from the last
  308. * known completed entry to the last entry that was processed, as completed
  309. * by clearing the valid bit for each completion queue entry. Then it will
  310. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  311. * The internal host index in the @q will be updated by this routine to indicate
  312. * that the host has finished processing the entries. The @arm parameter
  313. * indicates that the queue should be rearmed when ringing the doorbell.
  314. *
  315. * This function will return the number of CQEs that were released.
  316. **/
  317. uint32_t
  318. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  319. {
  320. uint32_t released = 0;
  321. struct lpfc_cqe *temp_qe;
  322. struct lpfc_register doorbell;
  323. /* sanity check on queue memory */
  324. if (unlikely(!q))
  325. return 0;
  326. /* while there are valid entries */
  327. while (q->hba_index != q->host_index) {
  328. temp_qe = q->qe[q->host_index].cqe;
  329. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  330. released++;
  331. q->host_index = ((q->host_index + 1) % q->entry_count);
  332. }
  333. if (unlikely(released == 0 && !arm))
  334. return 0;
  335. /* ring doorbell for number popped */
  336. doorbell.word0 = 0;
  337. if (arm)
  338. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  339. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  340. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  341. bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
  342. (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
  343. bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
  344. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  345. return released;
  346. }
  347. /**
  348. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  349. * @q: The Header Receive Queue to operate on.
  350. * @wqe: The Receive Queue Entry to put on the Receive queue.
  351. *
  352. * This routine will copy the contents of @wqe to the next available entry on
  353. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  354. * HBA to start processing the Receive Queue Entry. This function returns the
  355. * index that the rqe was copied to if successful. If no entries are available
  356. * on @q then this function will return -ENOMEM.
  357. * The caller is expected to hold the hbalock when calling this routine.
  358. **/
  359. static int
  360. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  361. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  362. {
  363. struct lpfc_rqe *temp_hrqe;
  364. struct lpfc_rqe *temp_drqe;
  365. struct lpfc_register doorbell;
  366. int put_index = hq->host_index;
  367. /* sanity check on queue memory */
  368. if (unlikely(!hq) || unlikely(!dq))
  369. return -ENOMEM;
  370. temp_hrqe = hq->qe[hq->host_index].rqe;
  371. temp_drqe = dq->qe[dq->host_index].rqe;
  372. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  373. return -EINVAL;
  374. if (hq->host_index != dq->host_index)
  375. return -EINVAL;
  376. /* If the host has not yet processed the next entry then we are done */
  377. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  378. return -EBUSY;
  379. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  380. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  381. /* Update the host index to point to the next slot */
  382. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  383. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  384. /* Ring The Header Receive Queue Doorbell */
  385. if (!(hq->host_index % hq->entry_repost)) {
  386. doorbell.word0 = 0;
  387. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  388. hq->entry_repost);
  389. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  390. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  391. }
  392. return put_index;
  393. }
  394. /**
  395. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  396. * @q: The Header Receive Queue to operate on.
  397. *
  398. * This routine will update the HBA index of a queue to reflect consumption of
  399. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  400. * consumed an entry the host calls this function to update the queue's
  401. * internal pointers. This routine returns the number of entries that were
  402. * consumed by the HBA.
  403. **/
  404. static uint32_t
  405. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  406. {
  407. /* sanity check on queue memory */
  408. if (unlikely(!hq) || unlikely(!dq))
  409. return 0;
  410. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  411. return 0;
  412. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  413. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  414. return 1;
  415. }
  416. /**
  417. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  418. * @phba: Pointer to HBA context object.
  419. * @pring: Pointer to driver SLI ring object.
  420. *
  421. * This function returns pointer to next command iocb entry
  422. * in the command ring. The caller must hold hbalock to prevent
  423. * other threads consume the next command iocb.
  424. * SLI-2/SLI-3 provide different sized iocbs.
  425. **/
  426. static inline IOCB_t *
  427. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  428. {
  429. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  430. pring->cmdidx * phba->iocb_cmd_size);
  431. }
  432. /**
  433. * lpfc_resp_iocb - Get next response iocb entry in the ring
  434. * @phba: Pointer to HBA context object.
  435. * @pring: Pointer to driver SLI ring object.
  436. *
  437. * This function returns pointer to next response iocb entry
  438. * in the response ring. The caller must hold hbalock to make sure
  439. * that no other thread consume the next response iocb.
  440. * SLI-2/SLI-3 provide different sized iocbs.
  441. **/
  442. static inline IOCB_t *
  443. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  444. {
  445. return (IOCB_t *) (((char *) pring->rspringaddr) +
  446. pring->rspidx * phba->iocb_rsp_size);
  447. }
  448. /**
  449. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  450. * @phba: Pointer to HBA context object.
  451. *
  452. * This function is called with hbalock held. This function
  453. * allocates a new driver iocb object from the iocb pool. If the
  454. * allocation is successful, it returns pointer to the newly
  455. * allocated iocb object else it returns NULL.
  456. **/
  457. struct lpfc_iocbq *
  458. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  459. {
  460. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  461. struct lpfc_iocbq * iocbq = NULL;
  462. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  463. if (iocbq)
  464. phba->iocb_cnt++;
  465. if (phba->iocb_cnt > phba->iocb_max)
  466. phba->iocb_max = phba->iocb_cnt;
  467. return iocbq;
  468. }
  469. /**
  470. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  471. * @phba: Pointer to HBA context object.
  472. * @xritag: XRI value.
  473. *
  474. * This function clears the sglq pointer from the array of acive
  475. * sglq's. The xritag that is passed in is used to index into the
  476. * array. Before the xritag can be used it needs to be adjusted
  477. * by subtracting the xribase.
  478. *
  479. * Returns sglq ponter = success, NULL = Failure.
  480. **/
  481. static struct lpfc_sglq *
  482. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  483. {
  484. struct lpfc_sglq *sglq;
  485. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  486. phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
  487. return sglq;
  488. }
  489. /**
  490. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  491. * @phba: Pointer to HBA context object.
  492. * @xritag: XRI value.
  493. *
  494. * This function returns the sglq pointer from the array of acive
  495. * sglq's. The xritag that is passed in is used to index into the
  496. * array. Before the xritag can be used it needs to be adjusted
  497. * by subtracting the xribase.
  498. *
  499. * Returns sglq ponter = success, NULL = Failure.
  500. **/
  501. struct lpfc_sglq *
  502. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  503. {
  504. struct lpfc_sglq *sglq;
  505. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  506. return sglq;
  507. }
  508. /**
  509. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  510. * @phba: Pointer to HBA context object.
  511. * @xritag: xri used in this exchange.
  512. * @rrq: The RRQ to be cleared.
  513. *
  514. **/
  515. void
  516. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  517. uint16_t xritag,
  518. struct lpfc_node_rrq *rrq)
  519. {
  520. struct lpfc_nodelist *ndlp = NULL;
  521. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  522. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  523. /* The target DID could have been swapped (cable swap)
  524. * we should use the ndlp from the findnode if it is
  525. * available.
  526. */
  527. if ((!ndlp) && rrq->ndlp)
  528. ndlp = rrq->ndlp;
  529. if (!ndlp)
  530. goto out;
  531. if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) {
  532. rrq->send_rrq = 0;
  533. rrq->xritag = 0;
  534. rrq->rrq_stop_time = 0;
  535. }
  536. out:
  537. mempool_free(rrq, phba->rrq_pool);
  538. }
  539. /**
  540. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  541. * @phba: Pointer to HBA context object.
  542. *
  543. * This function is called with hbalock held. This function
  544. * Checks if stop_time (ratov from setting rrq active) has
  545. * been reached, if it has and the send_rrq flag is set then
  546. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  547. * then it will just call the routine to clear the rrq and
  548. * free the rrq resource.
  549. * The timer is set to the next rrq that is going to expire before
  550. * leaving the routine.
  551. *
  552. **/
  553. void
  554. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  555. {
  556. struct lpfc_node_rrq *rrq;
  557. struct lpfc_node_rrq *nextrrq;
  558. unsigned long next_time;
  559. unsigned long iflags;
  560. LIST_HEAD(send_rrq);
  561. spin_lock_irqsave(&phba->hbalock, iflags);
  562. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  563. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  564. list_for_each_entry_safe(rrq, nextrrq,
  565. &phba->active_rrq_list, list) {
  566. if (time_after(jiffies, rrq->rrq_stop_time))
  567. list_move(&rrq->list, &send_rrq);
  568. else if (time_before(rrq->rrq_stop_time, next_time))
  569. next_time = rrq->rrq_stop_time;
  570. }
  571. spin_unlock_irqrestore(&phba->hbalock, iflags);
  572. if (!list_empty(&phba->active_rrq_list))
  573. mod_timer(&phba->rrq_tmr, next_time);
  574. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  575. list_del(&rrq->list);
  576. if (!rrq->send_rrq)
  577. /* this call will free the rrq */
  578. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  579. else if (lpfc_send_rrq(phba, rrq)) {
  580. /* if we send the rrq then the completion handler
  581. * will clear the bit in the xribitmap.
  582. */
  583. lpfc_clr_rrq_active(phba, rrq->xritag,
  584. rrq);
  585. }
  586. }
  587. }
  588. /**
  589. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  590. * @vport: Pointer to vport context object.
  591. * @xri: The xri used in the exchange.
  592. * @did: The targets DID for this exchange.
  593. *
  594. * returns NULL = rrq not found in the phba->active_rrq_list.
  595. * rrq = rrq for this xri and target.
  596. **/
  597. struct lpfc_node_rrq *
  598. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  599. {
  600. struct lpfc_hba *phba = vport->phba;
  601. struct lpfc_node_rrq *rrq;
  602. struct lpfc_node_rrq *nextrrq;
  603. unsigned long iflags;
  604. if (phba->sli_rev != LPFC_SLI_REV4)
  605. return NULL;
  606. spin_lock_irqsave(&phba->hbalock, iflags);
  607. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  608. if (rrq->vport == vport && rrq->xritag == xri &&
  609. rrq->nlp_DID == did){
  610. list_del(&rrq->list);
  611. spin_unlock_irqrestore(&phba->hbalock, iflags);
  612. return rrq;
  613. }
  614. }
  615. spin_unlock_irqrestore(&phba->hbalock, iflags);
  616. return NULL;
  617. }
  618. /**
  619. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  620. * @vport: Pointer to vport context object.
  621. * @ndlp: Pointer to the lpfc_node_list structure.
  622. * If ndlp is NULL Remove all active RRQs for this vport from the
  623. * phba->active_rrq_list and clear the rrq.
  624. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  625. **/
  626. void
  627. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  628. {
  629. struct lpfc_hba *phba = vport->phba;
  630. struct lpfc_node_rrq *rrq;
  631. struct lpfc_node_rrq *nextrrq;
  632. unsigned long iflags;
  633. LIST_HEAD(rrq_list);
  634. if (phba->sli_rev != LPFC_SLI_REV4)
  635. return;
  636. if (!ndlp) {
  637. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  638. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  639. }
  640. spin_lock_irqsave(&phba->hbalock, iflags);
  641. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  642. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  643. list_move(&rrq->list, &rrq_list);
  644. spin_unlock_irqrestore(&phba->hbalock, iflags);
  645. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  646. list_del(&rrq->list);
  647. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  648. }
  649. }
  650. /**
  651. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  652. * @phba: Pointer to HBA context object.
  653. *
  654. * Remove all rrqs from the phba->active_rrq_list and free them by
  655. * calling __lpfc_clr_active_rrq
  656. *
  657. **/
  658. void
  659. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  660. {
  661. struct lpfc_node_rrq *rrq;
  662. struct lpfc_node_rrq *nextrrq;
  663. unsigned long next_time;
  664. unsigned long iflags;
  665. LIST_HEAD(rrq_list);
  666. if (phba->sli_rev != LPFC_SLI_REV4)
  667. return;
  668. spin_lock_irqsave(&phba->hbalock, iflags);
  669. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  670. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  671. list_splice_init(&phba->active_rrq_list, &rrq_list);
  672. spin_unlock_irqrestore(&phba->hbalock, iflags);
  673. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  674. list_del(&rrq->list);
  675. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  676. }
  677. if (!list_empty(&phba->active_rrq_list))
  678. mod_timer(&phba->rrq_tmr, next_time);
  679. }
  680. /**
  681. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  682. * @phba: Pointer to HBA context object.
  683. * @ndlp: Targets nodelist pointer for this exchange.
  684. * @xritag the xri in the bitmap to test.
  685. *
  686. * This function is called with hbalock held. This function
  687. * returns 0 = rrq not active for this xri
  688. * 1 = rrq is valid for this xri.
  689. **/
  690. int
  691. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  692. uint16_t xritag)
  693. {
  694. if (!ndlp)
  695. return 0;
  696. if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  697. return 1;
  698. else
  699. return 0;
  700. }
  701. /**
  702. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  703. * @phba: Pointer to HBA context object.
  704. * @ndlp: nodelist pointer for this target.
  705. * @xritag: xri used in this exchange.
  706. * @rxid: Remote Exchange ID.
  707. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  708. *
  709. * This function takes the hbalock.
  710. * The active bit is always set in the active rrq xri_bitmap even
  711. * if there is no slot avaiable for the other rrq information.
  712. *
  713. * returns 0 rrq actived for this xri
  714. * < 0 No memory or invalid ndlp.
  715. **/
  716. int
  717. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  718. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  719. {
  720. unsigned long iflags;
  721. struct lpfc_node_rrq *rrq;
  722. int empty;
  723. if (!ndlp)
  724. return -EINVAL;
  725. if (!phba->cfg_enable_rrq)
  726. return -EINVAL;
  727. spin_lock_irqsave(&phba->hbalock, iflags);
  728. if (phba->pport->load_flag & FC_UNLOADING) {
  729. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  730. goto out;
  731. }
  732. /*
  733. * set the active bit even if there is no mem available.
  734. */
  735. if (NLP_CHK_FREE_REQ(ndlp))
  736. goto out;
  737. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  738. goto out;
  739. if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  740. goto out;
  741. spin_unlock_irqrestore(&phba->hbalock, iflags);
  742. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  743. if (!rrq) {
  744. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  745. "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
  746. " DID:0x%x Send:%d\n",
  747. xritag, rxid, ndlp->nlp_DID, send_rrq);
  748. return -EINVAL;
  749. }
  750. rrq->send_rrq = send_rrq;
  751. rrq->xritag = xritag;
  752. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  753. rrq->ndlp = ndlp;
  754. rrq->nlp_DID = ndlp->nlp_DID;
  755. rrq->vport = ndlp->vport;
  756. rrq->rxid = rxid;
  757. rrq->send_rrq = send_rrq;
  758. spin_lock_irqsave(&phba->hbalock, iflags);
  759. empty = list_empty(&phba->active_rrq_list);
  760. list_add_tail(&rrq->list, &phba->active_rrq_list);
  761. phba->hba_flag |= HBA_RRQ_ACTIVE;
  762. if (empty)
  763. lpfc_worker_wake_up(phba);
  764. spin_unlock_irqrestore(&phba->hbalock, iflags);
  765. return 0;
  766. out:
  767. spin_unlock_irqrestore(&phba->hbalock, iflags);
  768. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  769. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  770. " DID:0x%x Send:%d\n",
  771. xritag, rxid, ndlp->nlp_DID, send_rrq);
  772. return -EINVAL;
  773. }
  774. /**
  775. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  776. * @phba: Pointer to HBA context object.
  777. * @piocb: Pointer to the iocbq.
  778. *
  779. * This function is called with hbalock held. This function
  780. * gets a new driver sglq object from the sglq list. If the
  781. * list is not empty then it is successful, it returns pointer to the newly
  782. * allocated sglq object else it returns NULL.
  783. **/
  784. static struct lpfc_sglq *
  785. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  786. {
  787. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  788. struct lpfc_sglq *sglq = NULL;
  789. struct lpfc_sglq *start_sglq = NULL;
  790. struct lpfc_scsi_buf *lpfc_cmd;
  791. struct lpfc_nodelist *ndlp;
  792. int found = 0;
  793. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  794. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  795. ndlp = lpfc_cmd->rdata->pnode;
  796. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  797. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  798. ndlp = piocbq->context_un.ndlp;
  799. else
  800. ndlp = piocbq->context1;
  801. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  802. start_sglq = sglq;
  803. while (!found) {
  804. if (!sglq)
  805. return NULL;
  806. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
  807. /* This xri has an rrq outstanding for this DID.
  808. * put it back in the list and get another xri.
  809. */
  810. list_add_tail(&sglq->list, lpfc_sgl_list);
  811. sglq = NULL;
  812. list_remove_head(lpfc_sgl_list, sglq,
  813. struct lpfc_sglq, list);
  814. if (sglq == start_sglq) {
  815. sglq = NULL;
  816. break;
  817. } else
  818. continue;
  819. }
  820. sglq->ndlp = ndlp;
  821. found = 1;
  822. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  823. sglq->state = SGL_ALLOCATED;
  824. }
  825. return sglq;
  826. }
  827. /**
  828. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  829. * @phba: Pointer to HBA context object.
  830. *
  831. * This function is called with no lock held. This function
  832. * allocates a new driver iocb object from the iocb pool. If the
  833. * allocation is successful, it returns pointer to the newly
  834. * allocated iocb object else it returns NULL.
  835. **/
  836. struct lpfc_iocbq *
  837. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  838. {
  839. struct lpfc_iocbq * iocbq = NULL;
  840. unsigned long iflags;
  841. spin_lock_irqsave(&phba->hbalock, iflags);
  842. iocbq = __lpfc_sli_get_iocbq(phba);
  843. spin_unlock_irqrestore(&phba->hbalock, iflags);
  844. return iocbq;
  845. }
  846. /**
  847. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  848. * @phba: Pointer to HBA context object.
  849. * @iocbq: Pointer to driver iocb object.
  850. *
  851. * This function is called with hbalock held to release driver
  852. * iocb object to the iocb pool. The iotag in the iocb object
  853. * does not change for each use of the iocb object. This function
  854. * clears all other fields of the iocb object when it is freed.
  855. * The sqlq structure that holds the xritag and phys and virtual
  856. * mappings for the scatter gather list is retrieved from the
  857. * active array of sglq. The get of the sglq pointer also clears
  858. * the entry in the array. If the status of the IO indiactes that
  859. * this IO was aborted then the sglq entry it put on the
  860. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  861. * IO has good status or fails for any other reason then the sglq
  862. * entry is added to the free list (lpfc_sgl_list).
  863. **/
  864. static void
  865. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  866. {
  867. struct lpfc_sglq *sglq;
  868. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  869. unsigned long iflag = 0;
  870. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  871. if (iocbq->sli4_xritag == NO_XRI)
  872. sglq = NULL;
  873. else
  874. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  875. if (sglq) {
  876. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  877. (sglq->state != SGL_XRI_ABORTED)) {
  878. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  879. iflag);
  880. list_add(&sglq->list,
  881. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  882. spin_unlock_irqrestore(
  883. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  884. } else {
  885. sglq->state = SGL_FREED;
  886. sglq->ndlp = NULL;
  887. list_add_tail(&sglq->list,
  888. &phba->sli4_hba.lpfc_sgl_list);
  889. /* Check if TXQ queue needs to be serviced */
  890. if (pring->txq_cnt)
  891. lpfc_worker_wake_up(phba);
  892. }
  893. }
  894. /*
  895. * Clean all volatile data fields, preserve iotag and node struct.
  896. */
  897. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  898. iocbq->sli4_lxritag = NO_XRI;
  899. iocbq->sli4_xritag = NO_XRI;
  900. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  901. }
  902. /**
  903. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  904. * @phba: Pointer to HBA context object.
  905. * @iocbq: Pointer to driver iocb object.
  906. *
  907. * This function is called with hbalock held to release driver
  908. * iocb object to the iocb pool. The iotag in the iocb object
  909. * does not change for each use of the iocb object. This function
  910. * clears all other fields of the iocb object when it is freed.
  911. **/
  912. static void
  913. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  914. {
  915. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  916. /*
  917. * Clean all volatile data fields, preserve iotag and node struct.
  918. */
  919. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  920. iocbq->sli4_xritag = NO_XRI;
  921. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  922. }
  923. /**
  924. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  925. * @phba: Pointer to HBA context object.
  926. * @iocbq: Pointer to driver iocb object.
  927. *
  928. * This function is called with hbalock held to release driver
  929. * iocb object to the iocb pool. The iotag in the iocb object
  930. * does not change for each use of the iocb object. This function
  931. * clears all other fields of the iocb object when it is freed.
  932. **/
  933. static void
  934. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  935. {
  936. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  937. phba->iocb_cnt--;
  938. }
  939. /**
  940. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  941. * @phba: Pointer to HBA context object.
  942. * @iocbq: Pointer to driver iocb object.
  943. *
  944. * This function is called with no lock held to release the iocb to
  945. * iocb pool.
  946. **/
  947. void
  948. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  949. {
  950. unsigned long iflags;
  951. /*
  952. * Clean all volatile data fields, preserve iotag and node struct.
  953. */
  954. spin_lock_irqsave(&phba->hbalock, iflags);
  955. __lpfc_sli_release_iocbq(phba, iocbq);
  956. spin_unlock_irqrestore(&phba->hbalock, iflags);
  957. }
  958. /**
  959. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  960. * @phba: Pointer to HBA context object.
  961. * @iocblist: List of IOCBs.
  962. * @ulpstatus: ULP status in IOCB command field.
  963. * @ulpWord4: ULP word-4 in IOCB command field.
  964. *
  965. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  966. * on the list by invoking the complete callback function associated with the
  967. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  968. * fields.
  969. **/
  970. void
  971. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  972. uint32_t ulpstatus, uint32_t ulpWord4)
  973. {
  974. struct lpfc_iocbq *piocb;
  975. while (!list_empty(iocblist)) {
  976. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  977. if (!piocb->iocb_cmpl)
  978. lpfc_sli_release_iocbq(phba, piocb);
  979. else {
  980. piocb->iocb.ulpStatus = ulpstatus;
  981. piocb->iocb.un.ulpWord[4] = ulpWord4;
  982. (piocb->iocb_cmpl) (phba, piocb, piocb);
  983. }
  984. }
  985. return;
  986. }
  987. /**
  988. * lpfc_sli_iocb_cmd_type - Get the iocb type
  989. * @iocb_cmnd: iocb command code.
  990. *
  991. * This function is called by ring event handler function to get the iocb type.
  992. * This function translates the iocb command to an iocb command type used to
  993. * decide the final disposition of each completed IOCB.
  994. * The function returns
  995. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  996. * LPFC_SOL_IOCB if it is a solicited iocb completion
  997. * LPFC_ABORT_IOCB if it is an abort iocb
  998. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  999. *
  1000. * The caller is not required to hold any lock.
  1001. **/
  1002. static lpfc_iocb_type
  1003. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1004. {
  1005. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1006. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1007. return 0;
  1008. switch (iocb_cmnd) {
  1009. case CMD_XMIT_SEQUENCE_CR:
  1010. case CMD_XMIT_SEQUENCE_CX:
  1011. case CMD_XMIT_BCAST_CN:
  1012. case CMD_XMIT_BCAST_CX:
  1013. case CMD_ELS_REQUEST_CR:
  1014. case CMD_ELS_REQUEST_CX:
  1015. case CMD_CREATE_XRI_CR:
  1016. case CMD_CREATE_XRI_CX:
  1017. case CMD_GET_RPI_CN:
  1018. case CMD_XMIT_ELS_RSP_CX:
  1019. case CMD_GET_RPI_CR:
  1020. case CMD_FCP_IWRITE_CR:
  1021. case CMD_FCP_IWRITE_CX:
  1022. case CMD_FCP_IREAD_CR:
  1023. case CMD_FCP_IREAD_CX:
  1024. case CMD_FCP_ICMND_CR:
  1025. case CMD_FCP_ICMND_CX:
  1026. case CMD_FCP_TSEND_CX:
  1027. case CMD_FCP_TRSP_CX:
  1028. case CMD_FCP_TRECEIVE_CX:
  1029. case CMD_FCP_AUTO_TRSP_CX:
  1030. case CMD_ADAPTER_MSG:
  1031. case CMD_ADAPTER_DUMP:
  1032. case CMD_XMIT_SEQUENCE64_CR:
  1033. case CMD_XMIT_SEQUENCE64_CX:
  1034. case CMD_XMIT_BCAST64_CN:
  1035. case CMD_XMIT_BCAST64_CX:
  1036. case CMD_ELS_REQUEST64_CR:
  1037. case CMD_ELS_REQUEST64_CX:
  1038. case CMD_FCP_IWRITE64_CR:
  1039. case CMD_FCP_IWRITE64_CX:
  1040. case CMD_FCP_IREAD64_CR:
  1041. case CMD_FCP_IREAD64_CX:
  1042. case CMD_FCP_ICMND64_CR:
  1043. case CMD_FCP_ICMND64_CX:
  1044. case CMD_FCP_TSEND64_CX:
  1045. case CMD_FCP_TRSP64_CX:
  1046. case CMD_FCP_TRECEIVE64_CX:
  1047. case CMD_GEN_REQUEST64_CR:
  1048. case CMD_GEN_REQUEST64_CX:
  1049. case CMD_XMIT_ELS_RSP64_CX:
  1050. case DSSCMD_IWRITE64_CR:
  1051. case DSSCMD_IWRITE64_CX:
  1052. case DSSCMD_IREAD64_CR:
  1053. case DSSCMD_IREAD64_CX:
  1054. type = LPFC_SOL_IOCB;
  1055. break;
  1056. case CMD_ABORT_XRI_CN:
  1057. case CMD_ABORT_XRI_CX:
  1058. case CMD_CLOSE_XRI_CN:
  1059. case CMD_CLOSE_XRI_CX:
  1060. case CMD_XRI_ABORTED_CX:
  1061. case CMD_ABORT_MXRI64_CN:
  1062. case CMD_XMIT_BLS_RSP64_CX:
  1063. type = LPFC_ABORT_IOCB;
  1064. break;
  1065. case CMD_RCV_SEQUENCE_CX:
  1066. case CMD_RCV_ELS_REQ_CX:
  1067. case CMD_RCV_SEQUENCE64_CX:
  1068. case CMD_RCV_ELS_REQ64_CX:
  1069. case CMD_ASYNC_STATUS:
  1070. case CMD_IOCB_RCV_SEQ64_CX:
  1071. case CMD_IOCB_RCV_ELS64_CX:
  1072. case CMD_IOCB_RCV_CONT64_CX:
  1073. case CMD_IOCB_RET_XRI64_CX:
  1074. type = LPFC_UNSOL_IOCB;
  1075. break;
  1076. case CMD_IOCB_XMIT_MSEQ64_CR:
  1077. case CMD_IOCB_XMIT_MSEQ64_CX:
  1078. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1079. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1080. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1081. case CMD_IOCB_ABORT_EXTENDED_CN:
  1082. case CMD_IOCB_RET_HBQE64_CN:
  1083. case CMD_IOCB_FCP_IBIDIR64_CR:
  1084. case CMD_IOCB_FCP_IBIDIR64_CX:
  1085. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1086. case CMD_IOCB_LOGENTRY_CN:
  1087. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1088. printk("%s - Unhandled SLI-3 Command x%x\n",
  1089. __func__, iocb_cmnd);
  1090. type = LPFC_UNKNOWN_IOCB;
  1091. break;
  1092. default:
  1093. type = LPFC_UNKNOWN_IOCB;
  1094. break;
  1095. }
  1096. return type;
  1097. }
  1098. /**
  1099. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1100. * @phba: Pointer to HBA context object.
  1101. *
  1102. * This function is called from SLI initialization code
  1103. * to configure every ring of the HBA's SLI interface. The
  1104. * caller is not required to hold any lock. This function issues
  1105. * a config_ring mailbox command for each ring.
  1106. * This function returns zero if successful else returns a negative
  1107. * error code.
  1108. **/
  1109. static int
  1110. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1111. {
  1112. struct lpfc_sli *psli = &phba->sli;
  1113. LPFC_MBOXQ_t *pmb;
  1114. MAILBOX_t *pmbox;
  1115. int i, rc, ret = 0;
  1116. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1117. if (!pmb)
  1118. return -ENOMEM;
  1119. pmbox = &pmb->u.mb;
  1120. phba->link_state = LPFC_INIT_MBX_CMDS;
  1121. for (i = 0; i < psli->num_rings; i++) {
  1122. lpfc_config_ring(phba, i, pmb);
  1123. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1124. if (rc != MBX_SUCCESS) {
  1125. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1126. "0446 Adapter failed to init (%d), "
  1127. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1128. "ring %d\n",
  1129. rc, pmbox->mbxCommand,
  1130. pmbox->mbxStatus, i);
  1131. phba->link_state = LPFC_HBA_ERROR;
  1132. ret = -ENXIO;
  1133. break;
  1134. }
  1135. }
  1136. mempool_free(pmb, phba->mbox_mem_pool);
  1137. return ret;
  1138. }
  1139. /**
  1140. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1141. * @phba: Pointer to HBA context object.
  1142. * @pring: Pointer to driver SLI ring object.
  1143. * @piocb: Pointer to the driver iocb object.
  1144. *
  1145. * This function is called with hbalock held. The function adds the
  1146. * new iocb to txcmplq of the given ring. This function always returns
  1147. * 0. If this function is called for ELS ring, this function checks if
  1148. * there is a vport associated with the ELS command. This function also
  1149. * starts els_tmofunc timer if this is an ELS command.
  1150. **/
  1151. static int
  1152. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1153. struct lpfc_iocbq *piocb)
  1154. {
  1155. list_add_tail(&piocb->list, &pring->txcmplq);
  1156. piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
  1157. pring->txcmplq_cnt++;
  1158. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1159. pring->txcmplq_max = pring->txcmplq_cnt;
  1160. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1161. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1162. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1163. if (!piocb->vport)
  1164. BUG();
  1165. else
  1166. mod_timer(&piocb->vport->els_tmofunc,
  1167. jiffies + HZ * (phba->fc_ratov << 1));
  1168. }
  1169. return 0;
  1170. }
  1171. /**
  1172. * lpfc_sli_ringtx_get - Get first element of the txq
  1173. * @phba: Pointer to HBA context object.
  1174. * @pring: Pointer to driver SLI ring object.
  1175. *
  1176. * This function is called with hbalock held to get next
  1177. * iocb in txq of the given ring. If there is any iocb in
  1178. * the txq, the function returns first iocb in the list after
  1179. * removing the iocb from the list, else it returns NULL.
  1180. **/
  1181. struct lpfc_iocbq *
  1182. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1183. {
  1184. struct lpfc_iocbq *cmd_iocb;
  1185. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1186. if (cmd_iocb != NULL)
  1187. pring->txq_cnt--;
  1188. return cmd_iocb;
  1189. }
  1190. /**
  1191. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1192. * @phba: Pointer to HBA context object.
  1193. * @pring: Pointer to driver SLI ring object.
  1194. *
  1195. * This function is called with hbalock held and the caller must post the
  1196. * iocb without releasing the lock. If the caller releases the lock,
  1197. * iocb slot returned by the function is not guaranteed to be available.
  1198. * The function returns pointer to the next available iocb slot if there
  1199. * is available slot in the ring, else it returns NULL.
  1200. * If the get index of the ring is ahead of the put index, the function
  1201. * will post an error attention event to the worker thread to take the
  1202. * HBA to offline state.
  1203. **/
  1204. static IOCB_t *
  1205. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1206. {
  1207. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1208. uint32_t max_cmd_idx = pring->numCiocb;
  1209. if ((pring->next_cmdidx == pring->cmdidx) &&
  1210. (++pring->next_cmdidx >= max_cmd_idx))
  1211. pring->next_cmdidx = 0;
  1212. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1213. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1214. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1215. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1216. "0315 Ring %d issue: portCmdGet %d "
  1217. "is bigger than cmd ring %d\n",
  1218. pring->ringno,
  1219. pring->local_getidx, max_cmd_idx);
  1220. phba->link_state = LPFC_HBA_ERROR;
  1221. /*
  1222. * All error attention handlers are posted to
  1223. * worker thread
  1224. */
  1225. phba->work_ha |= HA_ERATT;
  1226. phba->work_hs = HS_FFER3;
  1227. lpfc_worker_wake_up(phba);
  1228. return NULL;
  1229. }
  1230. if (pring->local_getidx == pring->next_cmdidx)
  1231. return NULL;
  1232. }
  1233. return lpfc_cmd_iocb(phba, pring);
  1234. }
  1235. /**
  1236. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1237. * @phba: Pointer to HBA context object.
  1238. * @iocbq: Pointer to driver iocb object.
  1239. *
  1240. * This function gets an iotag for the iocb. If there is no unused iotag and
  1241. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1242. * array and assigns a new iotag.
  1243. * The function returns the allocated iotag if successful, else returns zero.
  1244. * Zero is not a valid iotag.
  1245. * The caller is not required to hold any lock.
  1246. **/
  1247. uint16_t
  1248. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1249. {
  1250. struct lpfc_iocbq **new_arr;
  1251. struct lpfc_iocbq **old_arr;
  1252. size_t new_len;
  1253. struct lpfc_sli *psli = &phba->sli;
  1254. uint16_t iotag;
  1255. spin_lock_irq(&phba->hbalock);
  1256. iotag = psli->last_iotag;
  1257. if(++iotag < psli->iocbq_lookup_len) {
  1258. psli->last_iotag = iotag;
  1259. psli->iocbq_lookup[iotag] = iocbq;
  1260. spin_unlock_irq(&phba->hbalock);
  1261. iocbq->iotag = iotag;
  1262. return iotag;
  1263. } else if (psli->iocbq_lookup_len < (0xffff
  1264. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1265. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1266. spin_unlock_irq(&phba->hbalock);
  1267. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1268. GFP_KERNEL);
  1269. if (new_arr) {
  1270. spin_lock_irq(&phba->hbalock);
  1271. old_arr = psli->iocbq_lookup;
  1272. if (new_len <= psli->iocbq_lookup_len) {
  1273. /* highly unprobable case */
  1274. kfree(new_arr);
  1275. iotag = psli->last_iotag;
  1276. if(++iotag < psli->iocbq_lookup_len) {
  1277. psli->last_iotag = iotag;
  1278. psli->iocbq_lookup[iotag] = iocbq;
  1279. spin_unlock_irq(&phba->hbalock);
  1280. iocbq->iotag = iotag;
  1281. return iotag;
  1282. }
  1283. spin_unlock_irq(&phba->hbalock);
  1284. return 0;
  1285. }
  1286. if (psli->iocbq_lookup)
  1287. memcpy(new_arr, old_arr,
  1288. ((psli->last_iotag + 1) *
  1289. sizeof (struct lpfc_iocbq *)));
  1290. psli->iocbq_lookup = new_arr;
  1291. psli->iocbq_lookup_len = new_len;
  1292. psli->last_iotag = iotag;
  1293. psli->iocbq_lookup[iotag] = iocbq;
  1294. spin_unlock_irq(&phba->hbalock);
  1295. iocbq->iotag = iotag;
  1296. kfree(old_arr);
  1297. return iotag;
  1298. }
  1299. } else
  1300. spin_unlock_irq(&phba->hbalock);
  1301. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1302. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1303. psli->last_iotag);
  1304. return 0;
  1305. }
  1306. /**
  1307. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1308. * @phba: Pointer to HBA context object.
  1309. * @pring: Pointer to driver SLI ring object.
  1310. * @iocb: Pointer to iocb slot in the ring.
  1311. * @nextiocb: Pointer to driver iocb object which need to be
  1312. * posted to firmware.
  1313. *
  1314. * This function is called with hbalock held to post a new iocb to
  1315. * the firmware. This function copies the new iocb to ring iocb slot and
  1316. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1317. * a completion call back for this iocb else the function will free the
  1318. * iocb object.
  1319. **/
  1320. static void
  1321. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1322. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1323. {
  1324. /*
  1325. * Set up an iotag
  1326. */
  1327. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1328. if (pring->ringno == LPFC_ELS_RING) {
  1329. lpfc_debugfs_slow_ring_trc(phba,
  1330. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1331. *(((uint32_t *) &nextiocb->iocb) + 4),
  1332. *(((uint32_t *) &nextiocb->iocb) + 6),
  1333. *(((uint32_t *) &nextiocb->iocb) + 7));
  1334. }
  1335. /*
  1336. * Issue iocb command to adapter
  1337. */
  1338. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1339. wmb();
  1340. pring->stats.iocb_cmd++;
  1341. /*
  1342. * If there is no completion routine to call, we can release the
  1343. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1344. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1345. */
  1346. if (nextiocb->iocb_cmpl)
  1347. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1348. else
  1349. __lpfc_sli_release_iocbq(phba, nextiocb);
  1350. /*
  1351. * Let the HBA know what IOCB slot will be the next one the
  1352. * driver will put a command into.
  1353. */
  1354. pring->cmdidx = pring->next_cmdidx;
  1355. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1356. }
  1357. /**
  1358. * lpfc_sli_update_full_ring - Update the chip attention register
  1359. * @phba: Pointer to HBA context object.
  1360. * @pring: Pointer to driver SLI ring object.
  1361. *
  1362. * The caller is not required to hold any lock for calling this function.
  1363. * This function updates the chip attention bits for the ring to inform firmware
  1364. * that there are pending work to be done for this ring and requests an
  1365. * interrupt when there is space available in the ring. This function is
  1366. * called when the driver is unable to post more iocbs to the ring due
  1367. * to unavailability of space in the ring.
  1368. **/
  1369. static void
  1370. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1371. {
  1372. int ringno = pring->ringno;
  1373. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1374. wmb();
  1375. /*
  1376. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1377. * The HBA will tell us when an IOCB entry is available.
  1378. */
  1379. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1380. readl(phba->CAregaddr); /* flush */
  1381. pring->stats.iocb_cmd_full++;
  1382. }
  1383. /**
  1384. * lpfc_sli_update_ring - Update chip attention register
  1385. * @phba: Pointer to HBA context object.
  1386. * @pring: Pointer to driver SLI ring object.
  1387. *
  1388. * This function updates the chip attention register bit for the
  1389. * given ring to inform HBA that there is more work to be done
  1390. * in this ring. The caller is not required to hold any lock.
  1391. **/
  1392. static void
  1393. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1394. {
  1395. int ringno = pring->ringno;
  1396. /*
  1397. * Tell the HBA that there is work to do in this ring.
  1398. */
  1399. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1400. wmb();
  1401. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1402. readl(phba->CAregaddr); /* flush */
  1403. }
  1404. }
  1405. /**
  1406. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1407. * @phba: Pointer to HBA context object.
  1408. * @pring: Pointer to driver SLI ring object.
  1409. *
  1410. * This function is called with hbalock held to post pending iocbs
  1411. * in the txq to the firmware. This function is called when driver
  1412. * detects space available in the ring.
  1413. **/
  1414. static void
  1415. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1416. {
  1417. IOCB_t *iocb;
  1418. struct lpfc_iocbq *nextiocb;
  1419. /*
  1420. * Check to see if:
  1421. * (a) there is anything on the txq to send
  1422. * (b) link is up
  1423. * (c) link attention events can be processed (fcp ring only)
  1424. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1425. */
  1426. if (pring->txq_cnt &&
  1427. lpfc_is_link_up(phba) &&
  1428. (pring->ringno != phba->sli.fcp_ring ||
  1429. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1430. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1431. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1432. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1433. if (iocb)
  1434. lpfc_sli_update_ring(phba, pring);
  1435. else
  1436. lpfc_sli_update_full_ring(phba, pring);
  1437. }
  1438. return;
  1439. }
  1440. /**
  1441. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1442. * @phba: Pointer to HBA context object.
  1443. * @hbqno: HBQ number.
  1444. *
  1445. * This function is called with hbalock held to get the next
  1446. * available slot for the given HBQ. If there is free slot
  1447. * available for the HBQ it will return pointer to the next available
  1448. * HBQ entry else it will return NULL.
  1449. **/
  1450. static struct lpfc_hbq_entry *
  1451. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1452. {
  1453. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1454. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1455. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1456. hbqp->next_hbqPutIdx = 0;
  1457. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1458. uint32_t raw_index = phba->hbq_get[hbqno];
  1459. uint32_t getidx = le32_to_cpu(raw_index);
  1460. hbqp->local_hbqGetIdx = getidx;
  1461. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1462. lpfc_printf_log(phba, KERN_ERR,
  1463. LOG_SLI | LOG_VPORT,
  1464. "1802 HBQ %d: local_hbqGetIdx "
  1465. "%u is > than hbqp->entry_count %u\n",
  1466. hbqno, hbqp->local_hbqGetIdx,
  1467. hbqp->entry_count);
  1468. phba->link_state = LPFC_HBA_ERROR;
  1469. return NULL;
  1470. }
  1471. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1472. return NULL;
  1473. }
  1474. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1475. hbqp->hbqPutIdx;
  1476. }
  1477. /**
  1478. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1479. * @phba: Pointer to HBA context object.
  1480. *
  1481. * This function is called with no lock held to free all the
  1482. * hbq buffers while uninitializing the SLI interface. It also
  1483. * frees the HBQ buffers returned by the firmware but not yet
  1484. * processed by the upper layers.
  1485. **/
  1486. void
  1487. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1488. {
  1489. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1490. struct hbq_dmabuf *hbq_buf;
  1491. unsigned long flags;
  1492. int i, hbq_count;
  1493. uint32_t hbqno;
  1494. hbq_count = lpfc_sli_hbq_count();
  1495. /* Return all memory used by all HBQs */
  1496. spin_lock_irqsave(&phba->hbalock, flags);
  1497. for (i = 0; i < hbq_count; ++i) {
  1498. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1499. &phba->hbqs[i].hbq_buffer_list, list) {
  1500. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1501. list_del(&hbq_buf->dbuf.list);
  1502. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1503. }
  1504. phba->hbqs[i].buffer_count = 0;
  1505. }
  1506. /* Return all HBQ buffer that are in-fly */
  1507. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1508. list) {
  1509. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1510. list_del(&hbq_buf->dbuf.list);
  1511. if (hbq_buf->tag == -1) {
  1512. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1513. (phba, hbq_buf);
  1514. } else {
  1515. hbqno = hbq_buf->tag >> 16;
  1516. if (hbqno >= LPFC_MAX_HBQS)
  1517. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1518. (phba, hbq_buf);
  1519. else
  1520. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1521. hbq_buf);
  1522. }
  1523. }
  1524. /* Mark the HBQs not in use */
  1525. phba->hbq_in_use = 0;
  1526. spin_unlock_irqrestore(&phba->hbalock, flags);
  1527. }
  1528. /**
  1529. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1530. * @phba: Pointer to HBA context object.
  1531. * @hbqno: HBQ number.
  1532. * @hbq_buf: Pointer to HBQ buffer.
  1533. *
  1534. * This function is called with the hbalock held to post a
  1535. * hbq buffer to the firmware. If the function finds an empty
  1536. * slot in the HBQ, it will post the buffer. The function will return
  1537. * pointer to the hbq entry if it successfully post the buffer
  1538. * else it will return NULL.
  1539. **/
  1540. static int
  1541. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1542. struct hbq_dmabuf *hbq_buf)
  1543. {
  1544. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1545. }
  1546. /**
  1547. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1548. * @phba: Pointer to HBA context object.
  1549. * @hbqno: HBQ number.
  1550. * @hbq_buf: Pointer to HBQ buffer.
  1551. *
  1552. * This function is called with the hbalock held to post a hbq buffer to the
  1553. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1554. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1555. * it successfully post the buffer else it will return an error.
  1556. **/
  1557. static int
  1558. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1559. struct hbq_dmabuf *hbq_buf)
  1560. {
  1561. struct lpfc_hbq_entry *hbqe;
  1562. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1563. /* Get next HBQ entry slot to use */
  1564. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1565. if (hbqe) {
  1566. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1567. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1568. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1569. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1570. hbqe->bde.tus.f.bdeFlags = 0;
  1571. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1572. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1573. /* Sync SLIM */
  1574. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1575. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1576. /* flush */
  1577. readl(phba->hbq_put + hbqno);
  1578. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1579. return 0;
  1580. } else
  1581. return -ENOMEM;
  1582. }
  1583. /**
  1584. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1585. * @phba: Pointer to HBA context object.
  1586. * @hbqno: HBQ number.
  1587. * @hbq_buf: Pointer to HBQ buffer.
  1588. *
  1589. * This function is called with the hbalock held to post an RQE to the SLI4
  1590. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1591. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1592. **/
  1593. static int
  1594. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1595. struct hbq_dmabuf *hbq_buf)
  1596. {
  1597. int rc;
  1598. struct lpfc_rqe hrqe;
  1599. struct lpfc_rqe drqe;
  1600. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1601. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1602. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1603. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1604. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1605. &hrqe, &drqe);
  1606. if (rc < 0)
  1607. return rc;
  1608. hbq_buf->tag = rc;
  1609. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1610. return 0;
  1611. }
  1612. /* HBQ for ELS and CT traffic. */
  1613. static struct lpfc_hbq_init lpfc_els_hbq = {
  1614. .rn = 1,
  1615. .entry_count = 256,
  1616. .mask_count = 0,
  1617. .profile = 0,
  1618. .ring_mask = (1 << LPFC_ELS_RING),
  1619. .buffer_count = 0,
  1620. .init_count = 40,
  1621. .add_count = 40,
  1622. };
  1623. /* HBQ for the extra ring if needed */
  1624. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1625. .rn = 1,
  1626. .entry_count = 200,
  1627. .mask_count = 0,
  1628. .profile = 0,
  1629. .ring_mask = (1 << LPFC_EXTRA_RING),
  1630. .buffer_count = 0,
  1631. .init_count = 0,
  1632. .add_count = 5,
  1633. };
  1634. /* Array of HBQs */
  1635. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1636. &lpfc_els_hbq,
  1637. &lpfc_extra_hbq,
  1638. };
  1639. /**
  1640. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1641. * @phba: Pointer to HBA context object.
  1642. * @hbqno: HBQ number.
  1643. * @count: Number of HBQ buffers to be posted.
  1644. *
  1645. * This function is called with no lock held to post more hbq buffers to the
  1646. * given HBQ. The function returns the number of HBQ buffers successfully
  1647. * posted.
  1648. **/
  1649. static int
  1650. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1651. {
  1652. uint32_t i, posted = 0;
  1653. unsigned long flags;
  1654. struct hbq_dmabuf *hbq_buffer;
  1655. LIST_HEAD(hbq_buf_list);
  1656. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1657. return 0;
  1658. if ((phba->hbqs[hbqno].buffer_count + count) >
  1659. lpfc_hbq_defs[hbqno]->entry_count)
  1660. count = lpfc_hbq_defs[hbqno]->entry_count -
  1661. phba->hbqs[hbqno].buffer_count;
  1662. if (!count)
  1663. return 0;
  1664. /* Allocate HBQ entries */
  1665. for (i = 0; i < count; i++) {
  1666. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1667. if (!hbq_buffer)
  1668. break;
  1669. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1670. }
  1671. /* Check whether HBQ is still in use */
  1672. spin_lock_irqsave(&phba->hbalock, flags);
  1673. if (!phba->hbq_in_use)
  1674. goto err;
  1675. while (!list_empty(&hbq_buf_list)) {
  1676. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1677. dbuf.list);
  1678. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1679. (hbqno << 16));
  1680. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1681. phba->hbqs[hbqno].buffer_count++;
  1682. posted++;
  1683. } else
  1684. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1685. }
  1686. spin_unlock_irqrestore(&phba->hbalock, flags);
  1687. return posted;
  1688. err:
  1689. spin_unlock_irqrestore(&phba->hbalock, flags);
  1690. while (!list_empty(&hbq_buf_list)) {
  1691. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1692. dbuf.list);
  1693. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1694. }
  1695. return 0;
  1696. }
  1697. /**
  1698. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1699. * @phba: Pointer to HBA context object.
  1700. * @qno: HBQ number.
  1701. *
  1702. * This function posts more buffers to the HBQ. This function
  1703. * is called with no lock held. The function returns the number of HBQ entries
  1704. * successfully allocated.
  1705. **/
  1706. int
  1707. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1708. {
  1709. if (phba->sli_rev == LPFC_SLI_REV4)
  1710. return 0;
  1711. else
  1712. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1713. lpfc_hbq_defs[qno]->add_count);
  1714. }
  1715. /**
  1716. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1717. * @phba: Pointer to HBA context object.
  1718. * @qno: HBQ queue number.
  1719. *
  1720. * This function is called from SLI initialization code path with
  1721. * no lock held to post initial HBQ buffers to firmware. The
  1722. * function returns the number of HBQ entries successfully allocated.
  1723. **/
  1724. static int
  1725. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1726. {
  1727. if (phba->sli_rev == LPFC_SLI_REV4)
  1728. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1729. lpfc_hbq_defs[qno]->entry_count);
  1730. else
  1731. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1732. lpfc_hbq_defs[qno]->init_count);
  1733. }
  1734. /**
  1735. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1736. * @phba: Pointer to HBA context object.
  1737. * @hbqno: HBQ number.
  1738. *
  1739. * This function removes the first hbq buffer on an hbq list and returns a
  1740. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1741. **/
  1742. static struct hbq_dmabuf *
  1743. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1744. {
  1745. struct lpfc_dmabuf *d_buf;
  1746. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1747. if (!d_buf)
  1748. return NULL;
  1749. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1750. }
  1751. /**
  1752. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1753. * @phba: Pointer to HBA context object.
  1754. * @tag: Tag of the hbq buffer.
  1755. *
  1756. * This function is called with hbalock held. This function searches
  1757. * for the hbq buffer associated with the given tag in the hbq buffer
  1758. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1759. * it returns NULL.
  1760. **/
  1761. static struct hbq_dmabuf *
  1762. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1763. {
  1764. struct lpfc_dmabuf *d_buf;
  1765. struct hbq_dmabuf *hbq_buf;
  1766. uint32_t hbqno;
  1767. hbqno = tag >> 16;
  1768. if (hbqno >= LPFC_MAX_HBQS)
  1769. return NULL;
  1770. spin_lock_irq(&phba->hbalock);
  1771. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1772. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1773. if (hbq_buf->tag == tag) {
  1774. spin_unlock_irq(&phba->hbalock);
  1775. return hbq_buf;
  1776. }
  1777. }
  1778. spin_unlock_irq(&phba->hbalock);
  1779. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1780. "1803 Bad hbq tag. Data: x%x x%x\n",
  1781. tag, phba->hbqs[tag >> 16].buffer_count);
  1782. return NULL;
  1783. }
  1784. /**
  1785. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1786. * @phba: Pointer to HBA context object.
  1787. * @hbq_buffer: Pointer to HBQ buffer.
  1788. *
  1789. * This function is called with hbalock. This function gives back
  1790. * the hbq buffer to firmware. If the HBQ does not have space to
  1791. * post the buffer, it will free the buffer.
  1792. **/
  1793. void
  1794. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1795. {
  1796. uint32_t hbqno;
  1797. if (hbq_buffer) {
  1798. hbqno = hbq_buffer->tag >> 16;
  1799. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1800. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1801. }
  1802. }
  1803. /**
  1804. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1805. * @mbxCommand: mailbox command code.
  1806. *
  1807. * This function is called by the mailbox event handler function to verify
  1808. * that the completed mailbox command is a legitimate mailbox command. If the
  1809. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1810. * and the mailbox event handler will take the HBA offline.
  1811. **/
  1812. static int
  1813. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1814. {
  1815. uint8_t ret;
  1816. switch (mbxCommand) {
  1817. case MBX_LOAD_SM:
  1818. case MBX_READ_NV:
  1819. case MBX_WRITE_NV:
  1820. case MBX_WRITE_VPARMS:
  1821. case MBX_RUN_BIU_DIAG:
  1822. case MBX_INIT_LINK:
  1823. case MBX_DOWN_LINK:
  1824. case MBX_CONFIG_LINK:
  1825. case MBX_CONFIG_RING:
  1826. case MBX_RESET_RING:
  1827. case MBX_READ_CONFIG:
  1828. case MBX_READ_RCONFIG:
  1829. case MBX_READ_SPARM:
  1830. case MBX_READ_STATUS:
  1831. case MBX_READ_RPI:
  1832. case MBX_READ_XRI:
  1833. case MBX_READ_REV:
  1834. case MBX_READ_LNK_STAT:
  1835. case MBX_REG_LOGIN:
  1836. case MBX_UNREG_LOGIN:
  1837. case MBX_CLEAR_LA:
  1838. case MBX_DUMP_MEMORY:
  1839. case MBX_DUMP_CONTEXT:
  1840. case MBX_RUN_DIAGS:
  1841. case MBX_RESTART:
  1842. case MBX_UPDATE_CFG:
  1843. case MBX_DOWN_LOAD:
  1844. case MBX_DEL_LD_ENTRY:
  1845. case MBX_RUN_PROGRAM:
  1846. case MBX_SET_MASK:
  1847. case MBX_SET_VARIABLE:
  1848. case MBX_UNREG_D_ID:
  1849. case MBX_KILL_BOARD:
  1850. case MBX_CONFIG_FARP:
  1851. case MBX_BEACON:
  1852. case MBX_LOAD_AREA:
  1853. case MBX_RUN_BIU_DIAG64:
  1854. case MBX_CONFIG_PORT:
  1855. case MBX_READ_SPARM64:
  1856. case MBX_READ_RPI64:
  1857. case MBX_REG_LOGIN64:
  1858. case MBX_READ_TOPOLOGY:
  1859. case MBX_WRITE_WWN:
  1860. case MBX_SET_DEBUG:
  1861. case MBX_LOAD_EXP_ROM:
  1862. case MBX_ASYNCEVT_ENABLE:
  1863. case MBX_REG_VPI:
  1864. case MBX_UNREG_VPI:
  1865. case MBX_HEARTBEAT:
  1866. case MBX_PORT_CAPABILITIES:
  1867. case MBX_PORT_IOV_CONTROL:
  1868. case MBX_SLI4_CONFIG:
  1869. case MBX_SLI4_REQ_FTRS:
  1870. case MBX_REG_FCFI:
  1871. case MBX_UNREG_FCFI:
  1872. case MBX_REG_VFI:
  1873. case MBX_UNREG_VFI:
  1874. case MBX_INIT_VPI:
  1875. case MBX_INIT_VFI:
  1876. case MBX_RESUME_RPI:
  1877. case MBX_READ_EVENT_LOG_STATUS:
  1878. case MBX_READ_EVENT_LOG:
  1879. case MBX_SECURITY_MGMT:
  1880. case MBX_AUTH_PORT:
  1881. ret = mbxCommand;
  1882. break;
  1883. default:
  1884. ret = MBX_SHUTDOWN;
  1885. break;
  1886. }
  1887. return ret;
  1888. }
  1889. /**
  1890. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1891. * @phba: Pointer to HBA context object.
  1892. * @pmboxq: Pointer to mailbox command.
  1893. *
  1894. * This is completion handler function for mailbox commands issued from
  1895. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1896. * mailbox event handler function with no lock held. This function
  1897. * will wake up thread waiting on the wait queue pointed by context1
  1898. * of the mailbox.
  1899. **/
  1900. void
  1901. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1902. {
  1903. wait_queue_head_t *pdone_q;
  1904. unsigned long drvr_flag;
  1905. /*
  1906. * If pdone_q is empty, the driver thread gave up waiting and
  1907. * continued running.
  1908. */
  1909. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1910. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1911. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1912. if (pdone_q)
  1913. wake_up_interruptible(pdone_q);
  1914. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1915. return;
  1916. }
  1917. /**
  1918. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1919. * @phba: Pointer to HBA context object.
  1920. * @pmb: Pointer to mailbox object.
  1921. *
  1922. * This function is the default mailbox completion handler. It
  1923. * frees the memory resources associated with the completed mailbox
  1924. * command. If the completed command is a REG_LOGIN mailbox command,
  1925. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1926. **/
  1927. void
  1928. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1929. {
  1930. struct lpfc_vport *vport = pmb->vport;
  1931. struct lpfc_dmabuf *mp;
  1932. struct lpfc_nodelist *ndlp;
  1933. struct Scsi_Host *shost;
  1934. uint16_t rpi, vpi;
  1935. int rc;
  1936. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1937. if (mp) {
  1938. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1939. kfree(mp);
  1940. }
  1941. /*
  1942. * If a REG_LOGIN succeeded after node is destroyed or node
  1943. * is in re-discovery driver need to cleanup the RPI.
  1944. */
  1945. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1946. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1947. !pmb->u.mb.mbxStatus) {
  1948. rpi = pmb->u.mb.un.varWords[0];
  1949. vpi = pmb->u.mb.un.varRegLogin.vpi;
  1950. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1951. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1952. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1953. if (rc != MBX_NOT_FINISHED)
  1954. return;
  1955. }
  1956. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1957. !(phba->pport->load_flag & FC_UNLOADING) &&
  1958. !pmb->u.mb.mbxStatus) {
  1959. shost = lpfc_shost_from_vport(vport);
  1960. spin_lock_irq(shost->host_lock);
  1961. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1962. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1963. spin_unlock_irq(shost->host_lock);
  1964. }
  1965. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1966. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1967. lpfc_nlp_put(ndlp);
  1968. pmb->context2 = NULL;
  1969. }
  1970. /* Check security permission status on INIT_LINK mailbox command */
  1971. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1972. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1973. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1974. "2860 SLI authentication is required "
  1975. "for INIT_LINK but has not done yet\n");
  1976. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1977. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1978. else
  1979. mempool_free(pmb, phba->mbox_mem_pool);
  1980. }
  1981. /**
  1982. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1983. * @phba: Pointer to HBA context object.
  1984. *
  1985. * This function is called with no lock held. This function processes all
  1986. * the completed mailbox commands and gives it to upper layers. The interrupt
  1987. * service routine processes mailbox completion interrupt and adds completed
  1988. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1989. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1990. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1991. * function returns the mailbox commands to the upper layer by calling the
  1992. * completion handler function of each mailbox.
  1993. **/
  1994. int
  1995. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1996. {
  1997. MAILBOX_t *pmbox;
  1998. LPFC_MBOXQ_t *pmb;
  1999. int rc;
  2000. LIST_HEAD(cmplq);
  2001. phba->sli.slistat.mbox_event++;
  2002. /* Get all completed mailboxe buffers into the cmplq */
  2003. spin_lock_irq(&phba->hbalock);
  2004. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2005. spin_unlock_irq(&phba->hbalock);
  2006. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2007. do {
  2008. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2009. if (pmb == NULL)
  2010. break;
  2011. pmbox = &pmb->u.mb;
  2012. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2013. if (pmb->vport) {
  2014. lpfc_debugfs_disc_trc(pmb->vport,
  2015. LPFC_DISC_TRC_MBOX_VPORT,
  2016. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2017. (uint32_t)pmbox->mbxCommand,
  2018. pmbox->un.varWords[0],
  2019. pmbox->un.varWords[1]);
  2020. }
  2021. else {
  2022. lpfc_debugfs_disc_trc(phba->pport,
  2023. LPFC_DISC_TRC_MBOX,
  2024. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2025. (uint32_t)pmbox->mbxCommand,
  2026. pmbox->un.varWords[0],
  2027. pmbox->un.varWords[1]);
  2028. }
  2029. }
  2030. /*
  2031. * It is a fatal error if unknown mbox command completion.
  2032. */
  2033. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2034. MBX_SHUTDOWN) {
  2035. /* Unknown mailbox command compl */
  2036. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2037. "(%d):0323 Unknown Mailbox command "
  2038. "x%x (x%x/x%x) Cmpl\n",
  2039. pmb->vport ? pmb->vport->vpi : 0,
  2040. pmbox->mbxCommand,
  2041. lpfc_sli_config_mbox_subsys_get(phba,
  2042. pmb),
  2043. lpfc_sli_config_mbox_opcode_get(phba,
  2044. pmb));
  2045. phba->link_state = LPFC_HBA_ERROR;
  2046. phba->work_hs = HS_FFER3;
  2047. lpfc_handle_eratt(phba);
  2048. continue;
  2049. }
  2050. if (pmbox->mbxStatus) {
  2051. phba->sli.slistat.mbox_stat_err++;
  2052. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2053. /* Mbox cmd cmpl error - RETRYing */
  2054. lpfc_printf_log(phba, KERN_INFO,
  2055. LOG_MBOX | LOG_SLI,
  2056. "(%d):0305 Mbox cmd cmpl "
  2057. "error - RETRYing Data: x%x "
  2058. "(x%x/x%x) x%x x%x x%x\n",
  2059. pmb->vport ? pmb->vport->vpi : 0,
  2060. pmbox->mbxCommand,
  2061. lpfc_sli_config_mbox_subsys_get(phba,
  2062. pmb),
  2063. lpfc_sli_config_mbox_opcode_get(phba,
  2064. pmb),
  2065. pmbox->mbxStatus,
  2066. pmbox->un.varWords[0],
  2067. pmb->vport->port_state);
  2068. pmbox->mbxStatus = 0;
  2069. pmbox->mbxOwner = OWN_HOST;
  2070. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2071. if (rc != MBX_NOT_FINISHED)
  2072. continue;
  2073. }
  2074. }
  2075. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2076. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2077. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
  2078. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2079. pmb->vport ? pmb->vport->vpi : 0,
  2080. pmbox->mbxCommand,
  2081. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2082. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2083. pmb->mbox_cmpl,
  2084. *((uint32_t *) pmbox),
  2085. pmbox->un.varWords[0],
  2086. pmbox->un.varWords[1],
  2087. pmbox->un.varWords[2],
  2088. pmbox->un.varWords[3],
  2089. pmbox->un.varWords[4],
  2090. pmbox->un.varWords[5],
  2091. pmbox->un.varWords[6],
  2092. pmbox->un.varWords[7]);
  2093. if (pmb->mbox_cmpl)
  2094. pmb->mbox_cmpl(phba,pmb);
  2095. } while (1);
  2096. return 0;
  2097. }
  2098. /**
  2099. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2100. * @phba: Pointer to HBA context object.
  2101. * @pring: Pointer to driver SLI ring object.
  2102. * @tag: buffer tag.
  2103. *
  2104. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2105. * is set in the tag the buffer is posted for a particular exchange,
  2106. * the function will return the buffer without replacing the buffer.
  2107. * If the buffer is for unsolicited ELS or CT traffic, this function
  2108. * returns the buffer and also posts another buffer to the firmware.
  2109. **/
  2110. static struct lpfc_dmabuf *
  2111. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2112. struct lpfc_sli_ring *pring,
  2113. uint32_t tag)
  2114. {
  2115. struct hbq_dmabuf *hbq_entry;
  2116. if (tag & QUE_BUFTAG_BIT)
  2117. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2118. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2119. if (!hbq_entry)
  2120. return NULL;
  2121. return &hbq_entry->dbuf;
  2122. }
  2123. /**
  2124. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2125. * @phba: Pointer to HBA context object.
  2126. * @pring: Pointer to driver SLI ring object.
  2127. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2128. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2129. * @fch_type: the type for the first frame of the sequence.
  2130. *
  2131. * This function is called with no lock held. This function uses the r_ctl and
  2132. * type of the received sequence to find the correct callback function to call
  2133. * to process the sequence.
  2134. **/
  2135. static int
  2136. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2137. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2138. uint32_t fch_type)
  2139. {
  2140. int i;
  2141. /* unSolicited Responses */
  2142. if (pring->prt[0].profile) {
  2143. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2144. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2145. saveq);
  2146. return 1;
  2147. }
  2148. /* We must search, based on rctl / type
  2149. for the right routine */
  2150. for (i = 0; i < pring->num_mask; i++) {
  2151. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2152. (pring->prt[i].type == fch_type)) {
  2153. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2154. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2155. (phba, pring, saveq);
  2156. return 1;
  2157. }
  2158. }
  2159. return 0;
  2160. }
  2161. /**
  2162. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2163. * @phba: Pointer to HBA context object.
  2164. * @pring: Pointer to driver SLI ring object.
  2165. * @saveq: Pointer to the unsolicited iocb.
  2166. *
  2167. * This function is called with no lock held by the ring event handler
  2168. * when there is an unsolicited iocb posted to the response ring by the
  2169. * firmware. This function gets the buffer associated with the iocbs
  2170. * and calls the event handler for the ring. This function handles both
  2171. * qring buffers and hbq buffers.
  2172. * When the function returns 1 the caller can free the iocb object otherwise
  2173. * upper layer functions will free the iocb objects.
  2174. **/
  2175. static int
  2176. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2177. struct lpfc_iocbq *saveq)
  2178. {
  2179. IOCB_t * irsp;
  2180. WORD5 * w5p;
  2181. uint32_t Rctl, Type;
  2182. uint32_t match;
  2183. struct lpfc_iocbq *iocbq;
  2184. struct lpfc_dmabuf *dmzbuf;
  2185. match = 0;
  2186. irsp = &(saveq->iocb);
  2187. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2188. if (pring->lpfc_sli_rcv_async_status)
  2189. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2190. else
  2191. lpfc_printf_log(phba,
  2192. KERN_WARNING,
  2193. LOG_SLI,
  2194. "0316 Ring %d handler: unexpected "
  2195. "ASYNC_STATUS iocb received evt_code "
  2196. "0x%x\n",
  2197. pring->ringno,
  2198. irsp->un.asyncstat.evt_code);
  2199. return 1;
  2200. }
  2201. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2202. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2203. if (irsp->ulpBdeCount > 0) {
  2204. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2205. irsp->un.ulpWord[3]);
  2206. lpfc_in_buf_free(phba, dmzbuf);
  2207. }
  2208. if (irsp->ulpBdeCount > 1) {
  2209. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2210. irsp->unsli3.sli3Words[3]);
  2211. lpfc_in_buf_free(phba, dmzbuf);
  2212. }
  2213. if (irsp->ulpBdeCount > 2) {
  2214. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2215. irsp->unsli3.sli3Words[7]);
  2216. lpfc_in_buf_free(phba, dmzbuf);
  2217. }
  2218. return 1;
  2219. }
  2220. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2221. if (irsp->ulpBdeCount != 0) {
  2222. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2223. irsp->un.ulpWord[3]);
  2224. if (!saveq->context2)
  2225. lpfc_printf_log(phba,
  2226. KERN_ERR,
  2227. LOG_SLI,
  2228. "0341 Ring %d Cannot find buffer for "
  2229. "an unsolicited iocb. tag 0x%x\n",
  2230. pring->ringno,
  2231. irsp->un.ulpWord[3]);
  2232. }
  2233. if (irsp->ulpBdeCount == 2) {
  2234. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2235. irsp->unsli3.sli3Words[7]);
  2236. if (!saveq->context3)
  2237. lpfc_printf_log(phba,
  2238. KERN_ERR,
  2239. LOG_SLI,
  2240. "0342 Ring %d Cannot find buffer for an"
  2241. " unsolicited iocb. tag 0x%x\n",
  2242. pring->ringno,
  2243. irsp->unsli3.sli3Words[7]);
  2244. }
  2245. list_for_each_entry(iocbq, &saveq->list, list) {
  2246. irsp = &(iocbq->iocb);
  2247. if (irsp->ulpBdeCount != 0) {
  2248. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2249. irsp->un.ulpWord[3]);
  2250. if (!iocbq->context2)
  2251. lpfc_printf_log(phba,
  2252. KERN_ERR,
  2253. LOG_SLI,
  2254. "0343 Ring %d Cannot find "
  2255. "buffer for an unsolicited iocb"
  2256. ". tag 0x%x\n", pring->ringno,
  2257. irsp->un.ulpWord[3]);
  2258. }
  2259. if (irsp->ulpBdeCount == 2) {
  2260. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2261. irsp->unsli3.sli3Words[7]);
  2262. if (!iocbq->context3)
  2263. lpfc_printf_log(phba,
  2264. KERN_ERR,
  2265. LOG_SLI,
  2266. "0344 Ring %d Cannot find "
  2267. "buffer for an unsolicited "
  2268. "iocb. tag 0x%x\n",
  2269. pring->ringno,
  2270. irsp->unsli3.sli3Words[7]);
  2271. }
  2272. }
  2273. }
  2274. if (irsp->ulpBdeCount != 0 &&
  2275. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2276. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2277. int found = 0;
  2278. /* search continue save q for same XRI */
  2279. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2280. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  2281. saveq->iocb.unsli3.rcvsli3.ox_id) {
  2282. list_add_tail(&saveq->list, &iocbq->list);
  2283. found = 1;
  2284. break;
  2285. }
  2286. }
  2287. if (!found)
  2288. list_add_tail(&saveq->clist,
  2289. &pring->iocb_continue_saveq);
  2290. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2291. list_del_init(&iocbq->clist);
  2292. saveq = iocbq;
  2293. irsp = &(saveq->iocb);
  2294. } else
  2295. return 0;
  2296. }
  2297. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2298. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2299. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2300. Rctl = FC_RCTL_ELS_REQ;
  2301. Type = FC_TYPE_ELS;
  2302. } else {
  2303. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2304. Rctl = w5p->hcsw.Rctl;
  2305. Type = w5p->hcsw.Type;
  2306. /* Firmware Workaround */
  2307. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2308. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2309. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2310. Rctl = FC_RCTL_ELS_REQ;
  2311. Type = FC_TYPE_ELS;
  2312. w5p->hcsw.Rctl = Rctl;
  2313. w5p->hcsw.Type = Type;
  2314. }
  2315. }
  2316. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2317. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2318. "0313 Ring %d handler: unexpected Rctl x%x "
  2319. "Type x%x received\n",
  2320. pring->ringno, Rctl, Type);
  2321. return 1;
  2322. }
  2323. /**
  2324. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2325. * @phba: Pointer to HBA context object.
  2326. * @pring: Pointer to driver SLI ring object.
  2327. * @prspiocb: Pointer to response iocb object.
  2328. *
  2329. * This function looks up the iocb_lookup table to get the command iocb
  2330. * corresponding to the given response iocb using the iotag of the
  2331. * response iocb. This function is called with the hbalock held.
  2332. * This function returns the command iocb object if it finds the command
  2333. * iocb else returns NULL.
  2334. **/
  2335. static struct lpfc_iocbq *
  2336. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2337. struct lpfc_sli_ring *pring,
  2338. struct lpfc_iocbq *prspiocb)
  2339. {
  2340. struct lpfc_iocbq *cmd_iocb = NULL;
  2341. uint16_t iotag;
  2342. iotag = prspiocb->iocb.ulpIoTag;
  2343. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2344. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2345. list_del_init(&cmd_iocb->list);
  2346. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2347. pring->txcmplq_cnt--;
  2348. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2349. }
  2350. return cmd_iocb;
  2351. }
  2352. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2353. "0317 iotag x%x is out off "
  2354. "range: max iotag x%x wd0 x%x\n",
  2355. iotag, phba->sli.last_iotag,
  2356. *(((uint32_t *) &prspiocb->iocb) + 7));
  2357. return NULL;
  2358. }
  2359. /**
  2360. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2361. * @phba: Pointer to HBA context object.
  2362. * @pring: Pointer to driver SLI ring object.
  2363. * @iotag: IOCB tag.
  2364. *
  2365. * This function looks up the iocb_lookup table to get the command iocb
  2366. * corresponding to the given iotag. This function is called with the
  2367. * hbalock held.
  2368. * This function returns the command iocb object if it finds the command
  2369. * iocb else returns NULL.
  2370. **/
  2371. static struct lpfc_iocbq *
  2372. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2373. struct lpfc_sli_ring *pring, uint16_t iotag)
  2374. {
  2375. struct lpfc_iocbq *cmd_iocb;
  2376. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2377. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2378. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2379. /* remove from txcmpl queue list */
  2380. list_del_init(&cmd_iocb->list);
  2381. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2382. pring->txcmplq_cnt--;
  2383. return cmd_iocb;
  2384. }
  2385. }
  2386. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2387. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2388. iotag, phba->sli.last_iotag);
  2389. return NULL;
  2390. }
  2391. /**
  2392. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2393. * @phba: Pointer to HBA context object.
  2394. * @pring: Pointer to driver SLI ring object.
  2395. * @saveq: Pointer to the response iocb to be processed.
  2396. *
  2397. * This function is called by the ring event handler for non-fcp
  2398. * rings when there is a new response iocb in the response ring.
  2399. * The caller is not required to hold any locks. This function
  2400. * gets the command iocb associated with the response iocb and
  2401. * calls the completion handler for the command iocb. If there
  2402. * is no completion handler, the function will free the resources
  2403. * associated with command iocb. If the response iocb is for
  2404. * an already aborted command iocb, the status of the completion
  2405. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2406. * This function always returns 1.
  2407. **/
  2408. static int
  2409. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2410. struct lpfc_iocbq *saveq)
  2411. {
  2412. struct lpfc_iocbq *cmdiocbp;
  2413. int rc = 1;
  2414. unsigned long iflag;
  2415. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2416. spin_lock_irqsave(&phba->hbalock, iflag);
  2417. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2418. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2419. if (cmdiocbp) {
  2420. if (cmdiocbp->iocb_cmpl) {
  2421. /*
  2422. * If an ELS command failed send an event to mgmt
  2423. * application.
  2424. */
  2425. if (saveq->iocb.ulpStatus &&
  2426. (pring->ringno == LPFC_ELS_RING) &&
  2427. (cmdiocbp->iocb.ulpCommand ==
  2428. CMD_ELS_REQUEST64_CR))
  2429. lpfc_send_els_failure_event(phba,
  2430. cmdiocbp, saveq);
  2431. /*
  2432. * Post all ELS completions to the worker thread.
  2433. * All other are passed to the completion callback.
  2434. */
  2435. if (pring->ringno == LPFC_ELS_RING) {
  2436. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2437. (cmdiocbp->iocb_flag &
  2438. LPFC_DRIVER_ABORTED)) {
  2439. spin_lock_irqsave(&phba->hbalock,
  2440. iflag);
  2441. cmdiocbp->iocb_flag &=
  2442. ~LPFC_DRIVER_ABORTED;
  2443. spin_unlock_irqrestore(&phba->hbalock,
  2444. iflag);
  2445. saveq->iocb.ulpStatus =
  2446. IOSTAT_LOCAL_REJECT;
  2447. saveq->iocb.un.ulpWord[4] =
  2448. IOERR_SLI_ABORTED;
  2449. /* Firmware could still be in progress
  2450. * of DMAing payload, so don't free data
  2451. * buffer till after a hbeat.
  2452. */
  2453. spin_lock_irqsave(&phba->hbalock,
  2454. iflag);
  2455. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2456. spin_unlock_irqrestore(&phba->hbalock,
  2457. iflag);
  2458. }
  2459. if (phba->sli_rev == LPFC_SLI_REV4) {
  2460. if (saveq->iocb_flag &
  2461. LPFC_EXCHANGE_BUSY) {
  2462. /* Set cmdiocb flag for the
  2463. * exchange busy so sgl (xri)
  2464. * will not be released until
  2465. * the abort xri is received
  2466. * from hba.
  2467. */
  2468. spin_lock_irqsave(
  2469. &phba->hbalock, iflag);
  2470. cmdiocbp->iocb_flag |=
  2471. LPFC_EXCHANGE_BUSY;
  2472. spin_unlock_irqrestore(
  2473. &phba->hbalock, iflag);
  2474. }
  2475. if (cmdiocbp->iocb_flag &
  2476. LPFC_DRIVER_ABORTED) {
  2477. /*
  2478. * Clear LPFC_DRIVER_ABORTED
  2479. * bit in case it was driver
  2480. * initiated abort.
  2481. */
  2482. spin_lock_irqsave(
  2483. &phba->hbalock, iflag);
  2484. cmdiocbp->iocb_flag &=
  2485. ~LPFC_DRIVER_ABORTED;
  2486. spin_unlock_irqrestore(
  2487. &phba->hbalock, iflag);
  2488. cmdiocbp->iocb.ulpStatus =
  2489. IOSTAT_LOCAL_REJECT;
  2490. cmdiocbp->iocb.un.ulpWord[4] =
  2491. IOERR_ABORT_REQUESTED;
  2492. /*
  2493. * For SLI4, irsiocb contains
  2494. * NO_XRI in sli_xritag, it
  2495. * shall not affect releasing
  2496. * sgl (xri) process.
  2497. */
  2498. saveq->iocb.ulpStatus =
  2499. IOSTAT_LOCAL_REJECT;
  2500. saveq->iocb.un.ulpWord[4] =
  2501. IOERR_SLI_ABORTED;
  2502. spin_lock_irqsave(
  2503. &phba->hbalock, iflag);
  2504. saveq->iocb_flag |=
  2505. LPFC_DELAY_MEM_FREE;
  2506. spin_unlock_irqrestore(
  2507. &phba->hbalock, iflag);
  2508. }
  2509. }
  2510. }
  2511. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2512. } else
  2513. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2514. } else {
  2515. /*
  2516. * Unknown initiating command based on the response iotag.
  2517. * This could be the case on the ELS ring because of
  2518. * lpfc_els_abort().
  2519. */
  2520. if (pring->ringno != LPFC_ELS_RING) {
  2521. /*
  2522. * Ring <ringno> handler: unexpected completion IoTag
  2523. * <IoTag>
  2524. */
  2525. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2526. "0322 Ring %d handler: "
  2527. "unexpected completion IoTag x%x "
  2528. "Data: x%x x%x x%x x%x\n",
  2529. pring->ringno,
  2530. saveq->iocb.ulpIoTag,
  2531. saveq->iocb.ulpStatus,
  2532. saveq->iocb.un.ulpWord[4],
  2533. saveq->iocb.ulpCommand,
  2534. saveq->iocb.ulpContext);
  2535. }
  2536. }
  2537. return rc;
  2538. }
  2539. /**
  2540. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2541. * @phba: Pointer to HBA context object.
  2542. * @pring: Pointer to driver SLI ring object.
  2543. *
  2544. * This function is called from the iocb ring event handlers when
  2545. * put pointer is ahead of the get pointer for a ring. This function signal
  2546. * an error attention condition to the worker thread and the worker
  2547. * thread will transition the HBA to offline state.
  2548. **/
  2549. static void
  2550. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2551. {
  2552. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2553. /*
  2554. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2555. * rsp ring <portRspMax>
  2556. */
  2557. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2558. "0312 Ring %d handler: portRspPut %d "
  2559. "is bigger than rsp ring %d\n",
  2560. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2561. pring->numRiocb);
  2562. phba->link_state = LPFC_HBA_ERROR;
  2563. /*
  2564. * All error attention handlers are posted to
  2565. * worker thread
  2566. */
  2567. phba->work_ha |= HA_ERATT;
  2568. phba->work_hs = HS_FFER3;
  2569. lpfc_worker_wake_up(phba);
  2570. return;
  2571. }
  2572. /**
  2573. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2574. * @ptr: Pointer to address of HBA context object.
  2575. *
  2576. * This function is invoked by the Error Attention polling timer when the
  2577. * timer times out. It will check the SLI Error Attention register for
  2578. * possible attention events. If so, it will post an Error Attention event
  2579. * and wake up worker thread to process it. Otherwise, it will set up the
  2580. * Error Attention polling timer for the next poll.
  2581. **/
  2582. void lpfc_poll_eratt(unsigned long ptr)
  2583. {
  2584. struct lpfc_hba *phba;
  2585. uint32_t eratt = 0;
  2586. phba = (struct lpfc_hba *)ptr;
  2587. /* Check chip HA register for error event */
  2588. eratt = lpfc_sli_check_eratt(phba);
  2589. if (eratt)
  2590. /* Tell the worker thread there is work to do */
  2591. lpfc_worker_wake_up(phba);
  2592. else
  2593. /* Restart the timer for next eratt poll */
  2594. mod_timer(&phba->eratt_poll, jiffies +
  2595. HZ * LPFC_ERATT_POLL_INTERVAL);
  2596. return;
  2597. }
  2598. /**
  2599. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2600. * @phba: Pointer to HBA context object.
  2601. * @pring: Pointer to driver SLI ring object.
  2602. * @mask: Host attention register mask for this ring.
  2603. *
  2604. * This function is called from the interrupt context when there is a ring
  2605. * event for the fcp ring. The caller does not hold any lock.
  2606. * The function processes each response iocb in the response ring until it
  2607. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2608. * LE bit set. The function will call the completion handler of the command iocb
  2609. * if the response iocb indicates a completion for a command iocb or it is
  2610. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2611. * function if this is an unsolicited iocb.
  2612. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2613. * to check it explicitly.
  2614. */
  2615. int
  2616. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2617. struct lpfc_sli_ring *pring, uint32_t mask)
  2618. {
  2619. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2620. IOCB_t *irsp = NULL;
  2621. IOCB_t *entry = NULL;
  2622. struct lpfc_iocbq *cmdiocbq = NULL;
  2623. struct lpfc_iocbq rspiocbq;
  2624. uint32_t status;
  2625. uint32_t portRspPut, portRspMax;
  2626. int rc = 1;
  2627. lpfc_iocb_type type;
  2628. unsigned long iflag;
  2629. uint32_t rsp_cmpl = 0;
  2630. spin_lock_irqsave(&phba->hbalock, iflag);
  2631. pring->stats.iocb_event++;
  2632. /*
  2633. * The next available response entry should never exceed the maximum
  2634. * entries. If it does, treat it as an adapter hardware error.
  2635. */
  2636. portRspMax = pring->numRiocb;
  2637. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2638. if (unlikely(portRspPut >= portRspMax)) {
  2639. lpfc_sli_rsp_pointers_error(phba, pring);
  2640. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2641. return 1;
  2642. }
  2643. if (phba->fcp_ring_in_use) {
  2644. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2645. return 1;
  2646. } else
  2647. phba->fcp_ring_in_use = 1;
  2648. rmb();
  2649. while (pring->rspidx != portRspPut) {
  2650. /*
  2651. * Fetch an entry off the ring and copy it into a local data
  2652. * structure. The copy involves a byte-swap since the
  2653. * network byte order and pci byte orders are different.
  2654. */
  2655. entry = lpfc_resp_iocb(phba, pring);
  2656. phba->last_completion_time = jiffies;
  2657. if (++pring->rspidx >= portRspMax)
  2658. pring->rspidx = 0;
  2659. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2660. (uint32_t *) &rspiocbq.iocb,
  2661. phba->iocb_rsp_size);
  2662. INIT_LIST_HEAD(&(rspiocbq.list));
  2663. irsp = &rspiocbq.iocb;
  2664. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2665. pring->stats.iocb_rsp++;
  2666. rsp_cmpl++;
  2667. if (unlikely(irsp->ulpStatus)) {
  2668. /*
  2669. * If resource errors reported from HBA, reduce
  2670. * queuedepths of the SCSI device.
  2671. */
  2672. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2673. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2674. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2675. phba->lpfc_rampdown_queue_depth(phba);
  2676. spin_lock_irqsave(&phba->hbalock, iflag);
  2677. }
  2678. /* Rsp ring <ringno> error: IOCB */
  2679. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2680. "0336 Rsp Ring %d error: IOCB Data: "
  2681. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2682. pring->ringno,
  2683. irsp->un.ulpWord[0],
  2684. irsp->un.ulpWord[1],
  2685. irsp->un.ulpWord[2],
  2686. irsp->un.ulpWord[3],
  2687. irsp->un.ulpWord[4],
  2688. irsp->un.ulpWord[5],
  2689. *(uint32_t *)&irsp->un1,
  2690. *((uint32_t *)&irsp->un1 + 1));
  2691. }
  2692. switch (type) {
  2693. case LPFC_ABORT_IOCB:
  2694. case LPFC_SOL_IOCB:
  2695. /*
  2696. * Idle exchange closed via ABTS from port. No iocb
  2697. * resources need to be recovered.
  2698. */
  2699. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2700. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2701. "0333 IOCB cmd 0x%x"
  2702. " processed. Skipping"
  2703. " completion\n",
  2704. irsp->ulpCommand);
  2705. break;
  2706. }
  2707. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2708. &rspiocbq);
  2709. if (unlikely(!cmdiocbq))
  2710. break;
  2711. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2712. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2713. if (cmdiocbq->iocb_cmpl) {
  2714. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2715. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2716. &rspiocbq);
  2717. spin_lock_irqsave(&phba->hbalock, iflag);
  2718. }
  2719. break;
  2720. case LPFC_UNSOL_IOCB:
  2721. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2722. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2723. spin_lock_irqsave(&phba->hbalock, iflag);
  2724. break;
  2725. default:
  2726. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2727. char adaptermsg[LPFC_MAX_ADPTMSG];
  2728. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2729. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2730. MAX_MSG_DATA);
  2731. dev_warn(&((phba->pcidev)->dev),
  2732. "lpfc%d: %s\n",
  2733. phba->brd_no, adaptermsg);
  2734. } else {
  2735. /* Unknown IOCB command */
  2736. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2737. "0334 Unknown IOCB command "
  2738. "Data: x%x, x%x x%x x%x x%x\n",
  2739. type, irsp->ulpCommand,
  2740. irsp->ulpStatus,
  2741. irsp->ulpIoTag,
  2742. irsp->ulpContext);
  2743. }
  2744. break;
  2745. }
  2746. /*
  2747. * The response IOCB has been processed. Update the ring
  2748. * pointer in SLIM. If the port response put pointer has not
  2749. * been updated, sync the pgp->rspPutInx and fetch the new port
  2750. * response put pointer.
  2751. */
  2752. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2753. if (pring->rspidx == portRspPut)
  2754. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2755. }
  2756. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2757. pring->stats.iocb_rsp_full++;
  2758. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2759. writel(status, phba->CAregaddr);
  2760. readl(phba->CAregaddr);
  2761. }
  2762. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2763. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2764. pring->stats.iocb_cmd_empty++;
  2765. /* Force update of the local copy of cmdGetInx */
  2766. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2767. lpfc_sli_resume_iocb(phba, pring);
  2768. if ((pring->lpfc_sli_cmd_available))
  2769. (pring->lpfc_sli_cmd_available) (phba, pring);
  2770. }
  2771. phba->fcp_ring_in_use = 0;
  2772. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2773. return rc;
  2774. }
  2775. /**
  2776. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2777. * @phba: Pointer to HBA context object.
  2778. * @pring: Pointer to driver SLI ring object.
  2779. * @rspiocbp: Pointer to driver response IOCB object.
  2780. *
  2781. * This function is called from the worker thread when there is a slow-path
  2782. * response IOCB to process. This function chains all the response iocbs until
  2783. * seeing the iocb with the LE bit set. The function will call
  2784. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2785. * completion of a command iocb. The function will call the
  2786. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2787. * The function frees the resources or calls the completion handler if this
  2788. * iocb is an abort completion. The function returns NULL when the response
  2789. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2790. * this function shall chain the iocb on to the iocb_continueq and return the
  2791. * response iocb passed in.
  2792. **/
  2793. static struct lpfc_iocbq *
  2794. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2795. struct lpfc_iocbq *rspiocbp)
  2796. {
  2797. struct lpfc_iocbq *saveq;
  2798. struct lpfc_iocbq *cmdiocbp;
  2799. struct lpfc_iocbq *next_iocb;
  2800. IOCB_t *irsp = NULL;
  2801. uint32_t free_saveq;
  2802. uint8_t iocb_cmd_type;
  2803. lpfc_iocb_type type;
  2804. unsigned long iflag;
  2805. int rc;
  2806. spin_lock_irqsave(&phba->hbalock, iflag);
  2807. /* First add the response iocb to the countinueq list */
  2808. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2809. pring->iocb_continueq_cnt++;
  2810. /* Now, determine whether the list is completed for processing */
  2811. irsp = &rspiocbp->iocb;
  2812. if (irsp->ulpLe) {
  2813. /*
  2814. * By default, the driver expects to free all resources
  2815. * associated with this iocb completion.
  2816. */
  2817. free_saveq = 1;
  2818. saveq = list_get_first(&pring->iocb_continueq,
  2819. struct lpfc_iocbq, list);
  2820. irsp = &(saveq->iocb);
  2821. list_del_init(&pring->iocb_continueq);
  2822. pring->iocb_continueq_cnt = 0;
  2823. pring->stats.iocb_rsp++;
  2824. /*
  2825. * If resource errors reported from HBA, reduce
  2826. * queuedepths of the SCSI device.
  2827. */
  2828. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2829. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2830. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2831. phba->lpfc_rampdown_queue_depth(phba);
  2832. spin_lock_irqsave(&phba->hbalock, iflag);
  2833. }
  2834. if (irsp->ulpStatus) {
  2835. /* Rsp ring <ringno> error: IOCB */
  2836. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2837. "0328 Rsp Ring %d error: "
  2838. "IOCB Data: "
  2839. "x%x x%x x%x x%x "
  2840. "x%x x%x x%x x%x "
  2841. "x%x x%x x%x x%x "
  2842. "x%x x%x x%x x%x\n",
  2843. pring->ringno,
  2844. irsp->un.ulpWord[0],
  2845. irsp->un.ulpWord[1],
  2846. irsp->un.ulpWord[2],
  2847. irsp->un.ulpWord[3],
  2848. irsp->un.ulpWord[4],
  2849. irsp->un.ulpWord[5],
  2850. *(((uint32_t *) irsp) + 6),
  2851. *(((uint32_t *) irsp) + 7),
  2852. *(((uint32_t *) irsp) + 8),
  2853. *(((uint32_t *) irsp) + 9),
  2854. *(((uint32_t *) irsp) + 10),
  2855. *(((uint32_t *) irsp) + 11),
  2856. *(((uint32_t *) irsp) + 12),
  2857. *(((uint32_t *) irsp) + 13),
  2858. *(((uint32_t *) irsp) + 14),
  2859. *(((uint32_t *) irsp) + 15));
  2860. }
  2861. /*
  2862. * Fetch the IOCB command type and call the correct completion
  2863. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2864. * get freed back to the lpfc_iocb_list by the discovery
  2865. * kernel thread.
  2866. */
  2867. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2868. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2869. switch (type) {
  2870. case LPFC_SOL_IOCB:
  2871. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2872. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2873. spin_lock_irqsave(&phba->hbalock, iflag);
  2874. break;
  2875. case LPFC_UNSOL_IOCB:
  2876. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2877. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2878. spin_lock_irqsave(&phba->hbalock, iflag);
  2879. if (!rc)
  2880. free_saveq = 0;
  2881. break;
  2882. case LPFC_ABORT_IOCB:
  2883. cmdiocbp = NULL;
  2884. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2885. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2886. saveq);
  2887. if (cmdiocbp) {
  2888. /* Call the specified completion routine */
  2889. if (cmdiocbp->iocb_cmpl) {
  2890. spin_unlock_irqrestore(&phba->hbalock,
  2891. iflag);
  2892. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2893. saveq);
  2894. spin_lock_irqsave(&phba->hbalock,
  2895. iflag);
  2896. } else
  2897. __lpfc_sli_release_iocbq(phba,
  2898. cmdiocbp);
  2899. }
  2900. break;
  2901. case LPFC_UNKNOWN_IOCB:
  2902. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2903. char adaptermsg[LPFC_MAX_ADPTMSG];
  2904. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2905. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2906. MAX_MSG_DATA);
  2907. dev_warn(&((phba->pcidev)->dev),
  2908. "lpfc%d: %s\n",
  2909. phba->brd_no, adaptermsg);
  2910. } else {
  2911. /* Unknown IOCB command */
  2912. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2913. "0335 Unknown IOCB "
  2914. "command Data: x%x "
  2915. "x%x x%x x%x\n",
  2916. irsp->ulpCommand,
  2917. irsp->ulpStatus,
  2918. irsp->ulpIoTag,
  2919. irsp->ulpContext);
  2920. }
  2921. break;
  2922. }
  2923. if (free_saveq) {
  2924. list_for_each_entry_safe(rspiocbp, next_iocb,
  2925. &saveq->list, list) {
  2926. list_del(&rspiocbp->list);
  2927. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2928. }
  2929. __lpfc_sli_release_iocbq(phba, saveq);
  2930. }
  2931. rspiocbp = NULL;
  2932. }
  2933. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2934. return rspiocbp;
  2935. }
  2936. /**
  2937. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2938. * @phba: Pointer to HBA context object.
  2939. * @pring: Pointer to driver SLI ring object.
  2940. * @mask: Host attention register mask for this ring.
  2941. *
  2942. * This routine wraps the actual slow_ring event process routine from the
  2943. * API jump table function pointer from the lpfc_hba struct.
  2944. **/
  2945. void
  2946. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2947. struct lpfc_sli_ring *pring, uint32_t mask)
  2948. {
  2949. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2950. }
  2951. /**
  2952. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2953. * @phba: Pointer to HBA context object.
  2954. * @pring: Pointer to driver SLI ring object.
  2955. * @mask: Host attention register mask for this ring.
  2956. *
  2957. * This function is called from the worker thread when there is a ring event
  2958. * for non-fcp rings. The caller does not hold any lock. The function will
  2959. * remove each response iocb in the response ring and calls the handle
  2960. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2961. **/
  2962. static void
  2963. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2964. struct lpfc_sli_ring *pring, uint32_t mask)
  2965. {
  2966. struct lpfc_pgp *pgp;
  2967. IOCB_t *entry;
  2968. IOCB_t *irsp = NULL;
  2969. struct lpfc_iocbq *rspiocbp = NULL;
  2970. uint32_t portRspPut, portRspMax;
  2971. unsigned long iflag;
  2972. uint32_t status;
  2973. pgp = &phba->port_gp[pring->ringno];
  2974. spin_lock_irqsave(&phba->hbalock, iflag);
  2975. pring->stats.iocb_event++;
  2976. /*
  2977. * The next available response entry should never exceed the maximum
  2978. * entries. If it does, treat it as an adapter hardware error.
  2979. */
  2980. portRspMax = pring->numRiocb;
  2981. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2982. if (portRspPut >= portRspMax) {
  2983. /*
  2984. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2985. * rsp ring <portRspMax>
  2986. */
  2987. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2988. "0303 Ring %d handler: portRspPut %d "
  2989. "is bigger than rsp ring %d\n",
  2990. pring->ringno, portRspPut, portRspMax);
  2991. phba->link_state = LPFC_HBA_ERROR;
  2992. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2993. phba->work_hs = HS_FFER3;
  2994. lpfc_handle_eratt(phba);
  2995. return;
  2996. }
  2997. rmb();
  2998. while (pring->rspidx != portRspPut) {
  2999. /*
  3000. * Build a completion list and call the appropriate handler.
  3001. * The process is to get the next available response iocb, get
  3002. * a free iocb from the list, copy the response data into the
  3003. * free iocb, insert to the continuation list, and update the
  3004. * next response index to slim. This process makes response
  3005. * iocb's in the ring available to DMA as fast as possible but
  3006. * pays a penalty for a copy operation. Since the iocb is
  3007. * only 32 bytes, this penalty is considered small relative to
  3008. * the PCI reads for register values and a slim write. When
  3009. * the ulpLe field is set, the entire Command has been
  3010. * received.
  3011. */
  3012. entry = lpfc_resp_iocb(phba, pring);
  3013. phba->last_completion_time = jiffies;
  3014. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3015. if (rspiocbp == NULL) {
  3016. printk(KERN_ERR "%s: out of buffers! Failing "
  3017. "completion.\n", __func__);
  3018. break;
  3019. }
  3020. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3021. phba->iocb_rsp_size);
  3022. irsp = &rspiocbp->iocb;
  3023. if (++pring->rspidx >= portRspMax)
  3024. pring->rspidx = 0;
  3025. if (pring->ringno == LPFC_ELS_RING) {
  3026. lpfc_debugfs_slow_ring_trc(phba,
  3027. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3028. *(((uint32_t *) irsp) + 4),
  3029. *(((uint32_t *) irsp) + 6),
  3030. *(((uint32_t *) irsp) + 7));
  3031. }
  3032. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3033. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3034. /* Handle the response IOCB */
  3035. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3036. spin_lock_irqsave(&phba->hbalock, iflag);
  3037. /*
  3038. * If the port response put pointer has not been updated, sync
  3039. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3040. * response put pointer.
  3041. */
  3042. if (pring->rspidx == portRspPut) {
  3043. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3044. }
  3045. } /* while (pring->rspidx != portRspPut) */
  3046. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3047. /* At least one response entry has been freed */
  3048. pring->stats.iocb_rsp_full++;
  3049. /* SET RxRE_RSP in Chip Att register */
  3050. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3051. writel(status, phba->CAregaddr);
  3052. readl(phba->CAregaddr); /* flush */
  3053. }
  3054. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3055. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3056. pring->stats.iocb_cmd_empty++;
  3057. /* Force update of the local copy of cmdGetInx */
  3058. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3059. lpfc_sli_resume_iocb(phba, pring);
  3060. if ((pring->lpfc_sli_cmd_available))
  3061. (pring->lpfc_sli_cmd_available) (phba, pring);
  3062. }
  3063. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3064. return;
  3065. }
  3066. /**
  3067. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3068. * @phba: Pointer to HBA context object.
  3069. * @pring: Pointer to driver SLI ring object.
  3070. * @mask: Host attention register mask for this ring.
  3071. *
  3072. * This function is called from the worker thread when there is a pending
  3073. * ELS response iocb on the driver internal slow-path response iocb worker
  3074. * queue. The caller does not hold any lock. The function will remove each
  3075. * response iocb from the response worker queue and calls the handle
  3076. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3077. **/
  3078. static void
  3079. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3080. struct lpfc_sli_ring *pring, uint32_t mask)
  3081. {
  3082. struct lpfc_iocbq *irspiocbq;
  3083. struct hbq_dmabuf *dmabuf;
  3084. struct lpfc_cq_event *cq_event;
  3085. unsigned long iflag;
  3086. spin_lock_irqsave(&phba->hbalock, iflag);
  3087. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3088. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3089. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3090. /* Get the response iocb from the head of work queue */
  3091. spin_lock_irqsave(&phba->hbalock, iflag);
  3092. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3093. cq_event, struct lpfc_cq_event, list);
  3094. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3095. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3096. case CQE_CODE_COMPL_WQE:
  3097. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3098. cq_event);
  3099. /* Translate ELS WCQE to response IOCBQ */
  3100. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3101. irspiocbq);
  3102. if (irspiocbq)
  3103. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3104. irspiocbq);
  3105. break;
  3106. case CQE_CODE_RECEIVE:
  3107. case CQE_CODE_RECEIVE_V1:
  3108. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3109. cq_event);
  3110. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3111. break;
  3112. default:
  3113. break;
  3114. }
  3115. }
  3116. }
  3117. /**
  3118. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3119. * @phba: Pointer to HBA context object.
  3120. * @pring: Pointer to driver SLI ring object.
  3121. *
  3122. * This function aborts all iocbs in the given ring and frees all the iocb
  3123. * objects in txq. This function issues an abort iocb for all the iocb commands
  3124. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3125. * the return of this function. The caller is not required to hold any locks.
  3126. **/
  3127. void
  3128. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3129. {
  3130. LIST_HEAD(completions);
  3131. struct lpfc_iocbq *iocb, *next_iocb;
  3132. if (pring->ringno == LPFC_ELS_RING) {
  3133. lpfc_fabric_abort_hba(phba);
  3134. }
  3135. /* Error everything on txq and txcmplq
  3136. * First do the txq.
  3137. */
  3138. spin_lock_irq(&phba->hbalock);
  3139. list_splice_init(&pring->txq, &completions);
  3140. pring->txq_cnt = 0;
  3141. /* Next issue ABTS for everything on the txcmplq */
  3142. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3143. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3144. spin_unlock_irq(&phba->hbalock);
  3145. /* Cancel all the IOCBs from the completions list */
  3146. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3147. IOERR_SLI_ABORTED);
  3148. }
  3149. /**
  3150. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3151. * @phba: Pointer to HBA context object.
  3152. *
  3153. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3154. * objects in txq and txcmplq. This function will not issue abort iocbs
  3155. * for all the iocb commands in txcmplq, they will just be returned with
  3156. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3157. * slot has been permanently disabled.
  3158. **/
  3159. void
  3160. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3161. {
  3162. LIST_HEAD(txq);
  3163. LIST_HEAD(txcmplq);
  3164. struct lpfc_sli *psli = &phba->sli;
  3165. struct lpfc_sli_ring *pring;
  3166. /* Currently, only one fcp ring */
  3167. pring = &psli->ring[psli->fcp_ring];
  3168. spin_lock_irq(&phba->hbalock);
  3169. /* Retrieve everything on txq */
  3170. list_splice_init(&pring->txq, &txq);
  3171. pring->txq_cnt = 0;
  3172. /* Retrieve everything on the txcmplq */
  3173. list_splice_init(&pring->txcmplq, &txcmplq);
  3174. pring->txcmplq_cnt = 0;
  3175. /* Indicate the I/O queues are flushed */
  3176. phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
  3177. spin_unlock_irq(&phba->hbalock);
  3178. /* Flush the txq */
  3179. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3180. IOERR_SLI_DOWN);
  3181. /* Flush the txcmpq */
  3182. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3183. IOERR_SLI_DOWN);
  3184. }
  3185. /**
  3186. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3187. * @phba: Pointer to HBA context object.
  3188. * @mask: Bit mask to be checked.
  3189. *
  3190. * This function reads the host status register and compares
  3191. * with the provided bit mask to check if HBA completed
  3192. * the restart. This function will wait in a loop for the
  3193. * HBA to complete restart. If the HBA does not restart within
  3194. * 15 iterations, the function will reset the HBA again. The
  3195. * function returns 1 when HBA fail to restart otherwise returns
  3196. * zero.
  3197. **/
  3198. static int
  3199. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3200. {
  3201. uint32_t status;
  3202. int i = 0;
  3203. int retval = 0;
  3204. /* Read the HBA Host Status Register */
  3205. if (lpfc_readl(phba->HSregaddr, &status))
  3206. return 1;
  3207. /*
  3208. * Check status register every 100ms for 5 retries, then every
  3209. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3210. * every 2.5 sec for 4.
  3211. * Break our of the loop if errors occurred during init.
  3212. */
  3213. while (((status & mask) != mask) &&
  3214. !(status & HS_FFERM) &&
  3215. i++ < 20) {
  3216. if (i <= 5)
  3217. msleep(10);
  3218. else if (i <= 10)
  3219. msleep(500);
  3220. else
  3221. msleep(2500);
  3222. if (i == 15) {
  3223. /* Do post */
  3224. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3225. lpfc_sli_brdrestart(phba);
  3226. }
  3227. /* Read the HBA Host Status Register */
  3228. if (lpfc_readl(phba->HSregaddr, &status)) {
  3229. retval = 1;
  3230. break;
  3231. }
  3232. }
  3233. /* Check to see if any errors occurred during init */
  3234. if ((status & HS_FFERM) || (i >= 20)) {
  3235. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3236. "2751 Adapter failed to restart, "
  3237. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3238. status,
  3239. readl(phba->MBslimaddr + 0xa8),
  3240. readl(phba->MBslimaddr + 0xac));
  3241. phba->link_state = LPFC_HBA_ERROR;
  3242. retval = 1;
  3243. }
  3244. return retval;
  3245. }
  3246. /**
  3247. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3248. * @phba: Pointer to HBA context object.
  3249. * @mask: Bit mask to be checked.
  3250. *
  3251. * This function checks the host status register to check if HBA is
  3252. * ready. This function will wait in a loop for the HBA to be ready
  3253. * If the HBA is not ready , the function will will reset the HBA PCI
  3254. * function again. The function returns 1 when HBA fail to be ready
  3255. * otherwise returns zero.
  3256. **/
  3257. static int
  3258. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3259. {
  3260. uint32_t status;
  3261. int retval = 0;
  3262. /* Read the HBA Host Status Register */
  3263. status = lpfc_sli4_post_status_check(phba);
  3264. if (status) {
  3265. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3266. lpfc_sli_brdrestart(phba);
  3267. status = lpfc_sli4_post_status_check(phba);
  3268. }
  3269. /* Check to see if any errors occurred during init */
  3270. if (status) {
  3271. phba->link_state = LPFC_HBA_ERROR;
  3272. retval = 1;
  3273. } else
  3274. phba->sli4_hba.intr_enable = 0;
  3275. return retval;
  3276. }
  3277. /**
  3278. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3279. * @phba: Pointer to HBA context object.
  3280. * @mask: Bit mask to be checked.
  3281. *
  3282. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3283. * from the API jump table function pointer from the lpfc_hba struct.
  3284. **/
  3285. int
  3286. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3287. {
  3288. return phba->lpfc_sli_brdready(phba, mask);
  3289. }
  3290. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3291. /**
  3292. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3293. * @phba: Pointer to HBA context object.
  3294. *
  3295. * This function is called before resetting an HBA. This function is called
  3296. * with hbalock held and requests HBA to quiesce DMAs before a reset.
  3297. **/
  3298. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3299. {
  3300. uint32_t __iomem *resp_buf;
  3301. uint32_t __iomem *mbox_buf;
  3302. volatile uint32_t mbox;
  3303. uint32_t hc_copy, ha_copy, resp_data;
  3304. int i;
  3305. uint8_t hdrtype;
  3306. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3307. if (hdrtype != 0x80 ||
  3308. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3309. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3310. return;
  3311. /*
  3312. * Tell the other part of the chip to suspend temporarily all
  3313. * its DMA activity.
  3314. */
  3315. resp_buf = phba->MBslimaddr;
  3316. /* Disable the error attention */
  3317. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3318. return;
  3319. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3320. readl(phba->HCregaddr); /* flush */
  3321. phba->link_flag |= LS_IGNORE_ERATT;
  3322. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3323. return;
  3324. if (ha_copy & HA_ERATT) {
  3325. /* Clear Chip error bit */
  3326. writel(HA_ERATT, phba->HAregaddr);
  3327. phba->pport->stopped = 1;
  3328. }
  3329. mbox = 0;
  3330. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3331. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3332. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3333. mbox_buf = phba->MBslimaddr;
  3334. writel(mbox, mbox_buf);
  3335. for (i = 0; i < 50; i++) {
  3336. if (lpfc_readl((resp_buf + 1), &resp_data))
  3337. return;
  3338. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3339. mdelay(1);
  3340. else
  3341. break;
  3342. }
  3343. resp_data = 0;
  3344. if (lpfc_readl((resp_buf + 1), &resp_data))
  3345. return;
  3346. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3347. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3348. phba->pport->stopped)
  3349. goto restore_hc;
  3350. else
  3351. goto clear_errat;
  3352. }
  3353. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3354. resp_data = 0;
  3355. for (i = 0; i < 500; i++) {
  3356. if (lpfc_readl(resp_buf, &resp_data))
  3357. return;
  3358. if (resp_data != mbox)
  3359. mdelay(1);
  3360. else
  3361. break;
  3362. }
  3363. clear_errat:
  3364. while (++i < 500) {
  3365. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3366. return;
  3367. if (!(ha_copy & HA_ERATT))
  3368. mdelay(1);
  3369. else
  3370. break;
  3371. }
  3372. if (readl(phba->HAregaddr) & HA_ERATT) {
  3373. writel(HA_ERATT, phba->HAregaddr);
  3374. phba->pport->stopped = 1;
  3375. }
  3376. restore_hc:
  3377. phba->link_flag &= ~LS_IGNORE_ERATT;
  3378. writel(hc_copy, phba->HCregaddr);
  3379. readl(phba->HCregaddr); /* flush */
  3380. }
  3381. /**
  3382. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3383. * @phba: Pointer to HBA context object.
  3384. *
  3385. * This function issues a kill_board mailbox command and waits for
  3386. * the error attention interrupt. This function is called for stopping
  3387. * the firmware processing. The caller is not required to hold any
  3388. * locks. This function calls lpfc_hba_down_post function to free
  3389. * any pending commands after the kill. The function will return 1 when it
  3390. * fails to kill the board else will return 0.
  3391. **/
  3392. int
  3393. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3394. {
  3395. struct lpfc_sli *psli;
  3396. LPFC_MBOXQ_t *pmb;
  3397. uint32_t status;
  3398. uint32_t ha_copy;
  3399. int retval;
  3400. int i = 0;
  3401. psli = &phba->sli;
  3402. /* Kill HBA */
  3403. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3404. "0329 Kill HBA Data: x%x x%x\n",
  3405. phba->pport->port_state, psli->sli_flag);
  3406. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3407. if (!pmb)
  3408. return 1;
  3409. /* Disable the error attention */
  3410. spin_lock_irq(&phba->hbalock);
  3411. if (lpfc_readl(phba->HCregaddr, &status)) {
  3412. spin_unlock_irq(&phba->hbalock);
  3413. mempool_free(pmb, phba->mbox_mem_pool);
  3414. return 1;
  3415. }
  3416. status &= ~HC_ERINT_ENA;
  3417. writel(status, phba->HCregaddr);
  3418. readl(phba->HCregaddr); /* flush */
  3419. phba->link_flag |= LS_IGNORE_ERATT;
  3420. spin_unlock_irq(&phba->hbalock);
  3421. lpfc_kill_board(phba, pmb);
  3422. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3423. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3424. if (retval != MBX_SUCCESS) {
  3425. if (retval != MBX_BUSY)
  3426. mempool_free(pmb, phba->mbox_mem_pool);
  3427. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3428. "2752 KILL_BOARD command failed retval %d\n",
  3429. retval);
  3430. spin_lock_irq(&phba->hbalock);
  3431. phba->link_flag &= ~LS_IGNORE_ERATT;
  3432. spin_unlock_irq(&phba->hbalock);
  3433. return 1;
  3434. }
  3435. spin_lock_irq(&phba->hbalock);
  3436. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3437. spin_unlock_irq(&phba->hbalock);
  3438. mempool_free(pmb, phba->mbox_mem_pool);
  3439. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3440. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3441. * 3 seconds we still set HBA_ERROR state because the status of the
  3442. * board is now undefined.
  3443. */
  3444. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3445. return 1;
  3446. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3447. mdelay(100);
  3448. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3449. return 1;
  3450. }
  3451. del_timer_sync(&psli->mbox_tmo);
  3452. if (ha_copy & HA_ERATT) {
  3453. writel(HA_ERATT, phba->HAregaddr);
  3454. phba->pport->stopped = 1;
  3455. }
  3456. spin_lock_irq(&phba->hbalock);
  3457. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3458. psli->mbox_active = NULL;
  3459. phba->link_flag &= ~LS_IGNORE_ERATT;
  3460. spin_unlock_irq(&phba->hbalock);
  3461. lpfc_hba_down_post(phba);
  3462. phba->link_state = LPFC_HBA_ERROR;
  3463. return ha_copy & HA_ERATT ? 0 : 1;
  3464. }
  3465. /**
  3466. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3467. * @phba: Pointer to HBA context object.
  3468. *
  3469. * This function resets the HBA by writing HC_INITFF to the control
  3470. * register. After the HBA resets, this function resets all the iocb ring
  3471. * indices. This function disables PCI layer parity checking during
  3472. * the reset.
  3473. * This function returns 0 always.
  3474. * The caller is not required to hold any locks.
  3475. **/
  3476. int
  3477. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3478. {
  3479. struct lpfc_sli *psli;
  3480. struct lpfc_sli_ring *pring;
  3481. uint16_t cfg_value;
  3482. int i;
  3483. psli = &phba->sli;
  3484. /* Reset HBA */
  3485. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3486. "0325 Reset HBA Data: x%x x%x\n",
  3487. phba->pport->port_state, psli->sli_flag);
  3488. /* perform board reset */
  3489. phba->fc_eventTag = 0;
  3490. phba->link_events = 0;
  3491. phba->pport->fc_myDID = 0;
  3492. phba->pport->fc_prevDID = 0;
  3493. /* Turn off parity checking and serr during the physical reset */
  3494. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3495. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3496. (cfg_value &
  3497. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3498. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3499. /* Now toggle INITFF bit in the Host Control Register */
  3500. writel(HC_INITFF, phba->HCregaddr);
  3501. mdelay(1);
  3502. readl(phba->HCregaddr); /* flush */
  3503. writel(0, phba->HCregaddr);
  3504. readl(phba->HCregaddr); /* flush */
  3505. /* Restore PCI cmd register */
  3506. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3507. /* Initialize relevant SLI info */
  3508. for (i = 0; i < psli->num_rings; i++) {
  3509. pring = &psli->ring[i];
  3510. pring->flag = 0;
  3511. pring->rspidx = 0;
  3512. pring->next_cmdidx = 0;
  3513. pring->local_getidx = 0;
  3514. pring->cmdidx = 0;
  3515. pring->missbufcnt = 0;
  3516. }
  3517. phba->link_state = LPFC_WARM_START;
  3518. return 0;
  3519. }
  3520. /**
  3521. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3522. * @phba: Pointer to HBA context object.
  3523. *
  3524. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3525. * checking during resets the device. The caller is not required to hold
  3526. * any locks.
  3527. *
  3528. * This function returns 0 always.
  3529. **/
  3530. int
  3531. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3532. {
  3533. struct lpfc_sli *psli = &phba->sli;
  3534. uint16_t cfg_value;
  3535. /* Reset HBA */
  3536. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3537. "0295 Reset HBA Data: x%x x%x\n",
  3538. phba->pport->port_state, psli->sli_flag);
  3539. /* perform board reset */
  3540. phba->fc_eventTag = 0;
  3541. phba->link_events = 0;
  3542. phba->pport->fc_myDID = 0;
  3543. phba->pport->fc_prevDID = 0;
  3544. spin_lock_irq(&phba->hbalock);
  3545. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3546. phba->fcf.fcf_flag = 0;
  3547. spin_unlock_irq(&phba->hbalock);
  3548. /* Now physically reset the device */
  3549. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3550. "0389 Performing PCI function reset!\n");
  3551. /* Turn off parity checking and serr during the physical reset */
  3552. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3553. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3554. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3555. /* Perform FCoE PCI function reset */
  3556. lpfc_sli4_queue_destroy(phba);
  3557. lpfc_pci_function_reset(phba);
  3558. /* Restore PCI cmd register */
  3559. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3560. return 0;
  3561. }
  3562. /**
  3563. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3564. * @phba: Pointer to HBA context object.
  3565. *
  3566. * This function is called in the SLI initialization code path to
  3567. * restart the HBA. The caller is not required to hold any lock.
  3568. * This function writes MBX_RESTART mailbox command to the SLIM and
  3569. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3570. * function to free any pending commands. The function enables
  3571. * POST only during the first initialization. The function returns zero.
  3572. * The function does not guarantee completion of MBX_RESTART mailbox
  3573. * command before the return of this function.
  3574. **/
  3575. static int
  3576. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3577. {
  3578. MAILBOX_t *mb;
  3579. struct lpfc_sli *psli;
  3580. volatile uint32_t word0;
  3581. void __iomem *to_slim;
  3582. uint32_t hba_aer_enabled;
  3583. spin_lock_irq(&phba->hbalock);
  3584. /* Take PCIe device Advanced Error Reporting (AER) state */
  3585. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3586. psli = &phba->sli;
  3587. /* Restart HBA */
  3588. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3589. "0337 Restart HBA Data: x%x x%x\n",
  3590. phba->pport->port_state, psli->sli_flag);
  3591. word0 = 0;
  3592. mb = (MAILBOX_t *) &word0;
  3593. mb->mbxCommand = MBX_RESTART;
  3594. mb->mbxHc = 1;
  3595. lpfc_reset_barrier(phba);
  3596. to_slim = phba->MBslimaddr;
  3597. writel(*(uint32_t *) mb, to_slim);
  3598. readl(to_slim); /* flush */
  3599. /* Only skip post after fc_ffinit is completed */
  3600. if (phba->pport->port_state)
  3601. word0 = 1; /* This is really setting up word1 */
  3602. else
  3603. word0 = 0; /* This is really setting up word1 */
  3604. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3605. writel(*(uint32_t *) mb, to_slim);
  3606. readl(to_slim); /* flush */
  3607. lpfc_sli_brdreset(phba);
  3608. phba->pport->stopped = 0;
  3609. phba->link_state = LPFC_INIT_START;
  3610. phba->hba_flag = 0;
  3611. spin_unlock_irq(&phba->hbalock);
  3612. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3613. psli->stats_start = get_seconds();
  3614. /* Give the INITFF and Post time to settle. */
  3615. mdelay(100);
  3616. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3617. if (hba_aer_enabled)
  3618. pci_disable_pcie_error_reporting(phba->pcidev);
  3619. lpfc_hba_down_post(phba);
  3620. return 0;
  3621. }
  3622. /**
  3623. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3624. * @phba: Pointer to HBA context object.
  3625. *
  3626. * This function is called in the SLI initialization code path to restart
  3627. * a SLI4 HBA. The caller is not required to hold any lock.
  3628. * At the end of the function, it calls lpfc_hba_down_post function to
  3629. * free any pending commands.
  3630. **/
  3631. static int
  3632. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3633. {
  3634. struct lpfc_sli *psli = &phba->sli;
  3635. uint32_t hba_aer_enabled;
  3636. /* Restart HBA */
  3637. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3638. "0296 Restart HBA Data: x%x x%x\n",
  3639. phba->pport->port_state, psli->sli_flag);
  3640. /* Take PCIe device Advanced Error Reporting (AER) state */
  3641. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3642. lpfc_sli4_brdreset(phba);
  3643. spin_lock_irq(&phba->hbalock);
  3644. phba->pport->stopped = 0;
  3645. phba->link_state = LPFC_INIT_START;
  3646. phba->hba_flag = 0;
  3647. spin_unlock_irq(&phba->hbalock);
  3648. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3649. psli->stats_start = get_seconds();
  3650. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3651. if (hba_aer_enabled)
  3652. pci_disable_pcie_error_reporting(phba->pcidev);
  3653. lpfc_hba_down_post(phba);
  3654. return 0;
  3655. }
  3656. /**
  3657. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3658. * @phba: Pointer to HBA context object.
  3659. *
  3660. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3661. * API jump table function pointer from the lpfc_hba struct.
  3662. **/
  3663. int
  3664. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3665. {
  3666. return phba->lpfc_sli_brdrestart(phba);
  3667. }
  3668. /**
  3669. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3670. * @phba: Pointer to HBA context object.
  3671. *
  3672. * This function is called after a HBA restart to wait for successful
  3673. * restart of the HBA. Successful restart of the HBA is indicated by
  3674. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3675. * iteration, the function will restart the HBA again. The function returns
  3676. * zero if HBA successfully restarted else returns negative error code.
  3677. **/
  3678. static int
  3679. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3680. {
  3681. uint32_t status, i = 0;
  3682. /* Read the HBA Host Status Register */
  3683. if (lpfc_readl(phba->HSregaddr, &status))
  3684. return -EIO;
  3685. /* Check status register to see what current state is */
  3686. i = 0;
  3687. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3688. /* Check every 10ms for 10 retries, then every 100ms for 90
  3689. * retries, then every 1 sec for 50 retires for a total of
  3690. * ~60 seconds before reset the board again and check every
  3691. * 1 sec for 50 retries. The up to 60 seconds before the
  3692. * board ready is required by the Falcon FIPS zeroization
  3693. * complete, and any reset the board in between shall cause
  3694. * restart of zeroization, further delay the board ready.
  3695. */
  3696. if (i++ >= 200) {
  3697. /* Adapter failed to init, timeout, status reg
  3698. <status> */
  3699. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3700. "0436 Adapter failed to init, "
  3701. "timeout, status reg x%x, "
  3702. "FW Data: A8 x%x AC x%x\n", status,
  3703. readl(phba->MBslimaddr + 0xa8),
  3704. readl(phba->MBslimaddr + 0xac));
  3705. phba->link_state = LPFC_HBA_ERROR;
  3706. return -ETIMEDOUT;
  3707. }
  3708. /* Check to see if any errors occurred during init */
  3709. if (status & HS_FFERM) {
  3710. /* ERROR: During chipset initialization */
  3711. /* Adapter failed to init, chipset, status reg
  3712. <status> */
  3713. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3714. "0437 Adapter failed to init, "
  3715. "chipset, status reg x%x, "
  3716. "FW Data: A8 x%x AC x%x\n", status,
  3717. readl(phba->MBslimaddr + 0xa8),
  3718. readl(phba->MBslimaddr + 0xac));
  3719. phba->link_state = LPFC_HBA_ERROR;
  3720. return -EIO;
  3721. }
  3722. if (i <= 10)
  3723. msleep(10);
  3724. else if (i <= 100)
  3725. msleep(100);
  3726. else
  3727. msleep(1000);
  3728. if (i == 150) {
  3729. /* Do post */
  3730. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3731. lpfc_sli_brdrestart(phba);
  3732. }
  3733. /* Read the HBA Host Status Register */
  3734. if (lpfc_readl(phba->HSregaddr, &status))
  3735. return -EIO;
  3736. }
  3737. /* Check to see if any errors occurred during init */
  3738. if (status & HS_FFERM) {
  3739. /* ERROR: During chipset initialization */
  3740. /* Adapter failed to init, chipset, status reg <status> */
  3741. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3742. "0438 Adapter failed to init, chipset, "
  3743. "status reg x%x, "
  3744. "FW Data: A8 x%x AC x%x\n", status,
  3745. readl(phba->MBslimaddr + 0xa8),
  3746. readl(phba->MBslimaddr + 0xac));
  3747. phba->link_state = LPFC_HBA_ERROR;
  3748. return -EIO;
  3749. }
  3750. /* Clear all interrupt enable conditions */
  3751. writel(0, phba->HCregaddr);
  3752. readl(phba->HCregaddr); /* flush */
  3753. /* setup host attn register */
  3754. writel(0xffffffff, phba->HAregaddr);
  3755. readl(phba->HAregaddr); /* flush */
  3756. return 0;
  3757. }
  3758. /**
  3759. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3760. *
  3761. * This function calculates and returns the number of HBQs required to be
  3762. * configured.
  3763. **/
  3764. int
  3765. lpfc_sli_hbq_count(void)
  3766. {
  3767. return ARRAY_SIZE(lpfc_hbq_defs);
  3768. }
  3769. /**
  3770. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3771. *
  3772. * This function adds the number of hbq entries in every HBQ to get
  3773. * the total number of hbq entries required for the HBA and returns
  3774. * the total count.
  3775. **/
  3776. static int
  3777. lpfc_sli_hbq_entry_count(void)
  3778. {
  3779. int hbq_count = lpfc_sli_hbq_count();
  3780. int count = 0;
  3781. int i;
  3782. for (i = 0; i < hbq_count; ++i)
  3783. count += lpfc_hbq_defs[i]->entry_count;
  3784. return count;
  3785. }
  3786. /**
  3787. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3788. *
  3789. * This function calculates amount of memory required for all hbq entries
  3790. * to be configured and returns the total memory required.
  3791. **/
  3792. int
  3793. lpfc_sli_hbq_size(void)
  3794. {
  3795. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3796. }
  3797. /**
  3798. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3799. * @phba: Pointer to HBA context object.
  3800. *
  3801. * This function is called during the SLI initialization to configure
  3802. * all the HBQs and post buffers to the HBQ. The caller is not
  3803. * required to hold any locks. This function will return zero if successful
  3804. * else it will return negative error code.
  3805. **/
  3806. static int
  3807. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3808. {
  3809. int hbq_count = lpfc_sli_hbq_count();
  3810. LPFC_MBOXQ_t *pmb;
  3811. MAILBOX_t *pmbox;
  3812. uint32_t hbqno;
  3813. uint32_t hbq_entry_index;
  3814. /* Get a Mailbox buffer to setup mailbox
  3815. * commands for HBA initialization
  3816. */
  3817. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3818. if (!pmb)
  3819. return -ENOMEM;
  3820. pmbox = &pmb->u.mb;
  3821. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3822. phba->link_state = LPFC_INIT_MBX_CMDS;
  3823. phba->hbq_in_use = 1;
  3824. hbq_entry_index = 0;
  3825. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3826. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3827. phba->hbqs[hbqno].hbqPutIdx = 0;
  3828. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3829. phba->hbqs[hbqno].entry_count =
  3830. lpfc_hbq_defs[hbqno]->entry_count;
  3831. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3832. hbq_entry_index, pmb);
  3833. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3834. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3835. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3836. mbxStatus <status>, ring <num> */
  3837. lpfc_printf_log(phba, KERN_ERR,
  3838. LOG_SLI | LOG_VPORT,
  3839. "1805 Adapter failed to init. "
  3840. "Data: x%x x%x x%x\n",
  3841. pmbox->mbxCommand,
  3842. pmbox->mbxStatus, hbqno);
  3843. phba->link_state = LPFC_HBA_ERROR;
  3844. mempool_free(pmb, phba->mbox_mem_pool);
  3845. return -ENXIO;
  3846. }
  3847. }
  3848. phba->hbq_count = hbq_count;
  3849. mempool_free(pmb, phba->mbox_mem_pool);
  3850. /* Initially populate or replenish the HBQs */
  3851. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3852. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3853. return 0;
  3854. }
  3855. /**
  3856. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3857. * @phba: Pointer to HBA context object.
  3858. *
  3859. * This function is called during the SLI initialization to configure
  3860. * all the HBQs and post buffers to the HBQ. The caller is not
  3861. * required to hold any locks. This function will return zero if successful
  3862. * else it will return negative error code.
  3863. **/
  3864. static int
  3865. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3866. {
  3867. phba->hbq_in_use = 1;
  3868. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3869. phba->hbq_count = 1;
  3870. /* Initially populate or replenish the HBQs */
  3871. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3872. return 0;
  3873. }
  3874. /**
  3875. * lpfc_sli_config_port - Issue config port mailbox command
  3876. * @phba: Pointer to HBA context object.
  3877. * @sli_mode: sli mode - 2/3
  3878. *
  3879. * This function is called by the sli intialization code path
  3880. * to issue config_port mailbox command. This function restarts the
  3881. * HBA firmware and issues a config_port mailbox command to configure
  3882. * the SLI interface in the sli mode specified by sli_mode
  3883. * variable. The caller is not required to hold any locks.
  3884. * The function returns 0 if successful, else returns negative error
  3885. * code.
  3886. **/
  3887. int
  3888. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3889. {
  3890. LPFC_MBOXQ_t *pmb;
  3891. uint32_t resetcount = 0, rc = 0, done = 0;
  3892. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3893. if (!pmb) {
  3894. phba->link_state = LPFC_HBA_ERROR;
  3895. return -ENOMEM;
  3896. }
  3897. phba->sli_rev = sli_mode;
  3898. while (resetcount < 2 && !done) {
  3899. spin_lock_irq(&phba->hbalock);
  3900. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3901. spin_unlock_irq(&phba->hbalock);
  3902. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3903. lpfc_sli_brdrestart(phba);
  3904. rc = lpfc_sli_chipset_init(phba);
  3905. if (rc)
  3906. break;
  3907. spin_lock_irq(&phba->hbalock);
  3908. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3909. spin_unlock_irq(&phba->hbalock);
  3910. resetcount++;
  3911. /* Call pre CONFIG_PORT mailbox command initialization. A
  3912. * value of 0 means the call was successful. Any other
  3913. * nonzero value is a failure, but if ERESTART is returned,
  3914. * the driver may reset the HBA and try again.
  3915. */
  3916. rc = lpfc_config_port_prep(phba);
  3917. if (rc == -ERESTART) {
  3918. phba->link_state = LPFC_LINK_UNKNOWN;
  3919. continue;
  3920. } else if (rc)
  3921. break;
  3922. phba->link_state = LPFC_INIT_MBX_CMDS;
  3923. lpfc_config_port(phba, pmb);
  3924. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3925. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3926. LPFC_SLI3_HBQ_ENABLED |
  3927. LPFC_SLI3_CRP_ENABLED |
  3928. LPFC_SLI3_BG_ENABLED |
  3929. LPFC_SLI3_DSS_ENABLED);
  3930. if (rc != MBX_SUCCESS) {
  3931. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3932. "0442 Adapter failed to init, mbxCmd x%x "
  3933. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3934. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3935. spin_lock_irq(&phba->hbalock);
  3936. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3937. spin_unlock_irq(&phba->hbalock);
  3938. rc = -ENXIO;
  3939. } else {
  3940. /* Allow asynchronous mailbox command to go through */
  3941. spin_lock_irq(&phba->hbalock);
  3942. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3943. spin_unlock_irq(&phba->hbalock);
  3944. done = 1;
  3945. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  3946. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  3947. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3948. "3110 Port did not grant ASABT\n");
  3949. }
  3950. }
  3951. if (!done) {
  3952. rc = -EINVAL;
  3953. goto do_prep_failed;
  3954. }
  3955. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3956. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3957. rc = -ENXIO;
  3958. goto do_prep_failed;
  3959. }
  3960. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3961. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3962. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3963. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3964. phba->max_vpi : phba->max_vports;
  3965. } else
  3966. phba->max_vpi = 0;
  3967. phba->fips_level = 0;
  3968. phba->fips_spec_rev = 0;
  3969. if (pmb->u.mb.un.varCfgPort.gdss) {
  3970. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3971. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3972. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3973. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3974. "2850 Security Crypto Active. FIPS x%d "
  3975. "(Spec Rev: x%d)",
  3976. phba->fips_level, phba->fips_spec_rev);
  3977. }
  3978. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3979. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3980. "2856 Config Port Security Crypto "
  3981. "Error: x%x ",
  3982. pmb->u.mb.un.varCfgPort.sec_err);
  3983. }
  3984. if (pmb->u.mb.un.varCfgPort.gerbm)
  3985. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3986. if (pmb->u.mb.un.varCfgPort.gcrp)
  3987. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3988. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3989. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3990. if (phba->cfg_enable_bg) {
  3991. if (pmb->u.mb.un.varCfgPort.gbg)
  3992. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3993. else
  3994. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3995. "0443 Adapter did not grant "
  3996. "BlockGuard\n");
  3997. }
  3998. } else {
  3999. phba->hbq_get = NULL;
  4000. phba->port_gp = phba->mbox->us.s2.port;
  4001. phba->max_vpi = 0;
  4002. }
  4003. do_prep_failed:
  4004. mempool_free(pmb, phba->mbox_mem_pool);
  4005. return rc;
  4006. }
  4007. /**
  4008. * lpfc_sli_hba_setup - SLI intialization function
  4009. * @phba: Pointer to HBA context object.
  4010. *
  4011. * This function is the main SLI intialization function. This function
  4012. * is called by the HBA intialization code, HBA reset code and HBA
  4013. * error attention handler code. Caller is not required to hold any
  4014. * locks. This function issues config_port mailbox command to configure
  4015. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4016. * calls the config_port_post function to issue init_link mailbox
  4017. * command and to start the discovery. The function will return zero
  4018. * if successful, else it will return negative error code.
  4019. **/
  4020. int
  4021. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4022. {
  4023. uint32_t rc;
  4024. int mode = 3, i;
  4025. int longs;
  4026. switch (lpfc_sli_mode) {
  4027. case 2:
  4028. if (phba->cfg_enable_npiv) {
  4029. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4030. "1824 NPIV enabled: Override lpfc_sli_mode "
  4031. "parameter (%d) to auto (0).\n",
  4032. lpfc_sli_mode);
  4033. break;
  4034. }
  4035. mode = 2;
  4036. break;
  4037. case 0:
  4038. case 3:
  4039. break;
  4040. default:
  4041. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4042. "1819 Unrecognized lpfc_sli_mode "
  4043. "parameter: %d.\n", lpfc_sli_mode);
  4044. break;
  4045. }
  4046. rc = lpfc_sli_config_port(phba, mode);
  4047. if (rc && lpfc_sli_mode == 3)
  4048. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4049. "1820 Unable to select SLI-3. "
  4050. "Not supported by adapter.\n");
  4051. if (rc && mode != 2)
  4052. rc = lpfc_sli_config_port(phba, 2);
  4053. if (rc)
  4054. goto lpfc_sli_hba_setup_error;
  4055. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4056. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4057. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4058. if (!rc) {
  4059. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4060. "2709 This device supports "
  4061. "Advanced Error Reporting (AER)\n");
  4062. spin_lock_irq(&phba->hbalock);
  4063. phba->hba_flag |= HBA_AER_ENABLED;
  4064. spin_unlock_irq(&phba->hbalock);
  4065. } else {
  4066. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4067. "2708 This device does not support "
  4068. "Advanced Error Reporting (AER)\n");
  4069. phba->cfg_aer_support = 0;
  4070. }
  4071. }
  4072. if (phba->sli_rev == 3) {
  4073. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4074. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4075. } else {
  4076. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4077. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4078. phba->sli3_options = 0;
  4079. }
  4080. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4081. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4082. phba->sli_rev, phba->max_vpi);
  4083. rc = lpfc_sli_ring_map(phba);
  4084. if (rc)
  4085. goto lpfc_sli_hba_setup_error;
  4086. /* Initialize VPIs. */
  4087. if (phba->sli_rev == LPFC_SLI_REV3) {
  4088. /*
  4089. * The VPI bitmask and physical ID array are allocated
  4090. * and initialized once only - at driver load. A port
  4091. * reset doesn't need to reinitialize this memory.
  4092. */
  4093. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4094. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4095. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4096. GFP_KERNEL);
  4097. if (!phba->vpi_bmask) {
  4098. rc = -ENOMEM;
  4099. goto lpfc_sli_hba_setup_error;
  4100. }
  4101. phba->vpi_ids = kzalloc(
  4102. (phba->max_vpi+1) * sizeof(uint16_t),
  4103. GFP_KERNEL);
  4104. if (!phba->vpi_ids) {
  4105. kfree(phba->vpi_bmask);
  4106. rc = -ENOMEM;
  4107. goto lpfc_sli_hba_setup_error;
  4108. }
  4109. for (i = 0; i < phba->max_vpi; i++)
  4110. phba->vpi_ids[i] = i;
  4111. }
  4112. }
  4113. /* Init HBQs */
  4114. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4115. rc = lpfc_sli_hbq_setup(phba);
  4116. if (rc)
  4117. goto lpfc_sli_hba_setup_error;
  4118. }
  4119. spin_lock_irq(&phba->hbalock);
  4120. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4121. spin_unlock_irq(&phba->hbalock);
  4122. rc = lpfc_config_port_post(phba);
  4123. if (rc)
  4124. goto lpfc_sli_hba_setup_error;
  4125. return rc;
  4126. lpfc_sli_hba_setup_error:
  4127. phba->link_state = LPFC_HBA_ERROR;
  4128. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4129. "0445 Firmware initialization failed\n");
  4130. return rc;
  4131. }
  4132. /**
  4133. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4134. * @phba: Pointer to HBA context object.
  4135. * @mboxq: mailbox pointer.
  4136. * This function issue a dump mailbox command to read config region
  4137. * 23 and parse the records in the region and populate driver
  4138. * data structure.
  4139. **/
  4140. static int
  4141. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4142. {
  4143. LPFC_MBOXQ_t *mboxq;
  4144. struct lpfc_dmabuf *mp;
  4145. struct lpfc_mqe *mqe;
  4146. uint32_t data_length;
  4147. int rc;
  4148. /* Program the default value of vlan_id and fc_map */
  4149. phba->valid_vlan = 0;
  4150. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4151. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4152. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4153. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4154. if (!mboxq)
  4155. return -ENOMEM;
  4156. mqe = &mboxq->u.mqe;
  4157. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4158. rc = -ENOMEM;
  4159. goto out_free_mboxq;
  4160. }
  4161. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4162. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4163. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4164. "(%d):2571 Mailbox cmd x%x Status x%x "
  4165. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4166. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4167. "CQ: x%x x%x x%x x%x\n",
  4168. mboxq->vport ? mboxq->vport->vpi : 0,
  4169. bf_get(lpfc_mqe_command, mqe),
  4170. bf_get(lpfc_mqe_status, mqe),
  4171. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4172. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4173. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4174. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4175. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4176. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4177. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4178. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4179. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4180. mboxq->mcqe.word0,
  4181. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4182. mboxq->mcqe.trailer);
  4183. if (rc) {
  4184. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4185. kfree(mp);
  4186. rc = -EIO;
  4187. goto out_free_mboxq;
  4188. }
  4189. data_length = mqe->un.mb_words[5];
  4190. if (data_length > DMP_RGN23_SIZE) {
  4191. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4192. kfree(mp);
  4193. rc = -EIO;
  4194. goto out_free_mboxq;
  4195. }
  4196. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4197. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4198. kfree(mp);
  4199. rc = 0;
  4200. out_free_mboxq:
  4201. mempool_free(mboxq, phba->mbox_mem_pool);
  4202. return rc;
  4203. }
  4204. /**
  4205. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4206. * @phba: pointer to lpfc hba data structure.
  4207. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4208. * @vpd: pointer to the memory to hold resulting port vpd data.
  4209. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4210. * On output, the number of data bytes in @vpd.
  4211. *
  4212. * This routine executes a READ_REV SLI4 mailbox command. In
  4213. * addition, this routine gets the port vpd data.
  4214. *
  4215. * Return codes
  4216. * 0 - successful
  4217. * -ENOMEM - could not allocated memory.
  4218. **/
  4219. static int
  4220. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4221. uint8_t *vpd, uint32_t *vpd_size)
  4222. {
  4223. int rc = 0;
  4224. uint32_t dma_size;
  4225. struct lpfc_dmabuf *dmabuf;
  4226. struct lpfc_mqe *mqe;
  4227. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4228. if (!dmabuf)
  4229. return -ENOMEM;
  4230. /*
  4231. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4232. * mailbox command.
  4233. */
  4234. dma_size = *vpd_size;
  4235. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4236. dma_size,
  4237. &dmabuf->phys,
  4238. GFP_KERNEL);
  4239. if (!dmabuf->virt) {
  4240. kfree(dmabuf);
  4241. return -ENOMEM;
  4242. }
  4243. memset(dmabuf->virt, 0, dma_size);
  4244. /*
  4245. * The SLI4 implementation of READ_REV conflicts at word1,
  4246. * bits 31:16 and SLI4 adds vpd functionality not present
  4247. * in SLI3. This code corrects the conflicts.
  4248. */
  4249. lpfc_read_rev(phba, mboxq);
  4250. mqe = &mboxq->u.mqe;
  4251. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4252. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4253. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4254. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4255. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4256. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4257. if (rc) {
  4258. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4259. dmabuf->virt, dmabuf->phys);
  4260. kfree(dmabuf);
  4261. return -EIO;
  4262. }
  4263. /*
  4264. * The available vpd length cannot be bigger than the
  4265. * DMA buffer passed to the port. Catch the less than
  4266. * case and update the caller's size.
  4267. */
  4268. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4269. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4270. memcpy(vpd, dmabuf->virt, *vpd_size);
  4271. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4272. dmabuf->virt, dmabuf->phys);
  4273. kfree(dmabuf);
  4274. return 0;
  4275. }
  4276. /**
  4277. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4278. * @phba: pointer to lpfc hba data structure.
  4279. *
  4280. * This routine retrieves SLI4 device physical port name this PCI function
  4281. * is attached to.
  4282. *
  4283. * Return codes
  4284. * 0 - sucessful
  4285. * otherwise - failed to retrieve physical port name
  4286. **/
  4287. static int
  4288. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4289. {
  4290. LPFC_MBOXQ_t *mboxq;
  4291. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4292. struct lpfc_controller_attribute *cntl_attr;
  4293. struct lpfc_mbx_get_port_name *get_port_name;
  4294. void *virtaddr = NULL;
  4295. uint32_t alloclen, reqlen;
  4296. uint32_t shdr_status, shdr_add_status;
  4297. union lpfc_sli4_cfg_shdr *shdr;
  4298. char cport_name = 0;
  4299. int rc;
  4300. /* We assume nothing at this point */
  4301. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4302. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4303. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4304. if (!mboxq)
  4305. return -ENOMEM;
  4306. /* obtain link type and link number via READ_CONFIG */
  4307. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4308. lpfc_sli4_read_config(phba);
  4309. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4310. goto retrieve_ppname;
  4311. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4312. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4313. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4314. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4315. LPFC_SLI4_MBX_NEMBED);
  4316. if (alloclen < reqlen) {
  4317. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4318. "3084 Allocated DMA memory size (%d) is "
  4319. "less than the requested DMA memory size "
  4320. "(%d)\n", alloclen, reqlen);
  4321. rc = -ENOMEM;
  4322. goto out_free_mboxq;
  4323. }
  4324. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4325. virtaddr = mboxq->sge_array->addr[0];
  4326. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4327. shdr = &mbx_cntl_attr->cfg_shdr;
  4328. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4329. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4330. if (shdr_status || shdr_add_status || rc) {
  4331. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4332. "3085 Mailbox x%x (x%x/x%x) failed, "
  4333. "rc:x%x, status:x%x, add_status:x%x\n",
  4334. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4335. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4336. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4337. rc, shdr_status, shdr_add_status);
  4338. rc = -ENXIO;
  4339. goto out_free_mboxq;
  4340. }
  4341. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4342. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4343. phba->sli4_hba.lnk_info.lnk_tp =
  4344. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4345. phba->sli4_hba.lnk_info.lnk_no =
  4346. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4347. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4348. "3086 lnk_type:%d, lnk_numb:%d\n",
  4349. phba->sli4_hba.lnk_info.lnk_tp,
  4350. phba->sli4_hba.lnk_info.lnk_no);
  4351. retrieve_ppname:
  4352. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4353. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4354. sizeof(struct lpfc_mbx_get_port_name) -
  4355. sizeof(struct lpfc_sli4_cfg_mhdr),
  4356. LPFC_SLI4_MBX_EMBED);
  4357. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4358. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4359. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4360. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4361. phba->sli4_hba.lnk_info.lnk_tp);
  4362. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4363. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4364. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4365. if (shdr_status || shdr_add_status || rc) {
  4366. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4367. "3087 Mailbox x%x (x%x/x%x) failed: "
  4368. "rc:x%x, status:x%x, add_status:x%x\n",
  4369. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4370. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4371. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4372. rc, shdr_status, shdr_add_status);
  4373. rc = -ENXIO;
  4374. goto out_free_mboxq;
  4375. }
  4376. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4377. case LPFC_LINK_NUMBER_0:
  4378. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4379. &get_port_name->u.response);
  4380. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4381. break;
  4382. case LPFC_LINK_NUMBER_1:
  4383. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4384. &get_port_name->u.response);
  4385. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4386. break;
  4387. case LPFC_LINK_NUMBER_2:
  4388. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4389. &get_port_name->u.response);
  4390. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4391. break;
  4392. case LPFC_LINK_NUMBER_3:
  4393. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4394. &get_port_name->u.response);
  4395. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4396. break;
  4397. default:
  4398. break;
  4399. }
  4400. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4401. phba->Port[0] = cport_name;
  4402. phba->Port[1] = '\0';
  4403. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4404. "3091 SLI get port name: %s\n", phba->Port);
  4405. }
  4406. out_free_mboxq:
  4407. if (rc != MBX_TIMEOUT) {
  4408. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4409. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4410. else
  4411. mempool_free(mboxq, phba->mbox_mem_pool);
  4412. }
  4413. return rc;
  4414. }
  4415. /**
  4416. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4417. * @phba: pointer to lpfc hba data structure.
  4418. *
  4419. * This routine is called to explicitly arm the SLI4 device's completion and
  4420. * event queues
  4421. **/
  4422. static void
  4423. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4424. {
  4425. uint8_t fcp_eqidx;
  4426. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4427. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4428. fcp_eqidx = 0;
  4429. if (phba->sli4_hba.fcp_cq) {
  4430. do
  4431. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4432. LPFC_QUEUE_REARM);
  4433. while (++fcp_eqidx < phba->cfg_fcp_eq_count);
  4434. }
  4435. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4436. if (phba->sli4_hba.fp_eq) {
  4437. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count;
  4438. fcp_eqidx++)
  4439. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4440. LPFC_QUEUE_REARM);
  4441. }
  4442. }
  4443. /**
  4444. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4445. * @phba: Pointer to HBA context object.
  4446. * @type: The resource extent type.
  4447. * @extnt_count: buffer to hold port available extent count.
  4448. * @extnt_size: buffer to hold element count per extent.
  4449. *
  4450. * This function calls the port and retrievs the number of available
  4451. * extents and their size for a particular extent type.
  4452. *
  4453. * Returns: 0 if successful. Nonzero otherwise.
  4454. **/
  4455. int
  4456. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4457. uint16_t *extnt_count, uint16_t *extnt_size)
  4458. {
  4459. int rc = 0;
  4460. uint32_t length;
  4461. uint32_t mbox_tmo;
  4462. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4463. LPFC_MBOXQ_t *mbox;
  4464. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4465. if (!mbox)
  4466. return -ENOMEM;
  4467. /* Find out how many extents are available for this resource type */
  4468. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4469. sizeof(struct lpfc_sli4_cfg_mhdr));
  4470. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4471. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4472. length, LPFC_SLI4_MBX_EMBED);
  4473. /* Send an extents count of 0 - the GET doesn't use it. */
  4474. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4475. LPFC_SLI4_MBX_EMBED);
  4476. if (unlikely(rc)) {
  4477. rc = -EIO;
  4478. goto err_exit;
  4479. }
  4480. if (!phba->sli4_hba.intr_enable)
  4481. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4482. else {
  4483. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4484. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4485. }
  4486. if (unlikely(rc)) {
  4487. rc = -EIO;
  4488. goto err_exit;
  4489. }
  4490. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4491. if (bf_get(lpfc_mbox_hdr_status,
  4492. &rsrc_info->header.cfg_shdr.response)) {
  4493. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4494. "2930 Failed to get resource extents "
  4495. "Status 0x%x Add'l Status 0x%x\n",
  4496. bf_get(lpfc_mbox_hdr_status,
  4497. &rsrc_info->header.cfg_shdr.response),
  4498. bf_get(lpfc_mbox_hdr_add_status,
  4499. &rsrc_info->header.cfg_shdr.response));
  4500. rc = -EIO;
  4501. goto err_exit;
  4502. }
  4503. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4504. &rsrc_info->u.rsp);
  4505. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4506. &rsrc_info->u.rsp);
  4507. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4508. "3162 Retrieved extents type-%d from port: count:%d, "
  4509. "size:%d\n", type, *extnt_count, *extnt_size);
  4510. err_exit:
  4511. mempool_free(mbox, phba->mbox_mem_pool);
  4512. return rc;
  4513. }
  4514. /**
  4515. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4516. * @phba: Pointer to HBA context object.
  4517. * @type: The extent type to check.
  4518. *
  4519. * This function reads the current available extents from the port and checks
  4520. * if the extent count or extent size has changed since the last access.
  4521. * Callers use this routine post port reset to understand if there is a
  4522. * extent reprovisioning requirement.
  4523. *
  4524. * Returns:
  4525. * -Error: error indicates problem.
  4526. * 1: Extent count or size has changed.
  4527. * 0: No changes.
  4528. **/
  4529. static int
  4530. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4531. {
  4532. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4533. uint16_t size_diff, rsrc_ext_size;
  4534. int rc = 0;
  4535. struct lpfc_rsrc_blks *rsrc_entry;
  4536. struct list_head *rsrc_blk_list = NULL;
  4537. size_diff = 0;
  4538. curr_ext_cnt = 0;
  4539. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4540. &rsrc_ext_cnt,
  4541. &rsrc_ext_size);
  4542. if (unlikely(rc))
  4543. return -EIO;
  4544. switch (type) {
  4545. case LPFC_RSC_TYPE_FCOE_RPI:
  4546. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4547. break;
  4548. case LPFC_RSC_TYPE_FCOE_VPI:
  4549. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4550. break;
  4551. case LPFC_RSC_TYPE_FCOE_XRI:
  4552. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4553. break;
  4554. case LPFC_RSC_TYPE_FCOE_VFI:
  4555. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4556. break;
  4557. default:
  4558. break;
  4559. }
  4560. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4561. curr_ext_cnt++;
  4562. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4563. size_diff++;
  4564. }
  4565. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4566. rc = 1;
  4567. return rc;
  4568. }
  4569. /**
  4570. * lpfc_sli4_cfg_post_extnts -
  4571. * @phba: Pointer to HBA context object.
  4572. * @extnt_cnt - number of available extents.
  4573. * @type - the extent type (rpi, xri, vfi, vpi).
  4574. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4575. * @mbox - pointer to the caller's allocated mailbox structure.
  4576. *
  4577. * This function executes the extents allocation request. It also
  4578. * takes care of the amount of memory needed to allocate or get the
  4579. * allocated extents. It is the caller's responsibility to evaluate
  4580. * the response.
  4581. *
  4582. * Returns:
  4583. * -Error: Error value describes the condition found.
  4584. * 0: if successful
  4585. **/
  4586. static int
  4587. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
  4588. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4589. {
  4590. int rc = 0;
  4591. uint32_t req_len;
  4592. uint32_t emb_len;
  4593. uint32_t alloc_len, mbox_tmo;
  4594. /* Calculate the total requested length of the dma memory */
  4595. req_len = extnt_cnt * sizeof(uint16_t);
  4596. /*
  4597. * Calculate the size of an embedded mailbox. The uint32_t
  4598. * accounts for extents-specific word.
  4599. */
  4600. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4601. sizeof(uint32_t);
  4602. /*
  4603. * Presume the allocation and response will fit into an embedded
  4604. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4605. */
  4606. *emb = LPFC_SLI4_MBX_EMBED;
  4607. if (req_len > emb_len) {
  4608. req_len = extnt_cnt * sizeof(uint16_t) +
  4609. sizeof(union lpfc_sli4_cfg_shdr) +
  4610. sizeof(uint32_t);
  4611. *emb = LPFC_SLI4_MBX_NEMBED;
  4612. }
  4613. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4614. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4615. req_len, *emb);
  4616. if (alloc_len < req_len) {
  4617. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4618. "2982 Allocated DMA memory size (x%x) is "
  4619. "less than the requested DMA memory "
  4620. "size (x%x)\n", alloc_len, req_len);
  4621. return -ENOMEM;
  4622. }
  4623. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
  4624. if (unlikely(rc))
  4625. return -EIO;
  4626. if (!phba->sli4_hba.intr_enable)
  4627. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4628. else {
  4629. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4630. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4631. }
  4632. if (unlikely(rc))
  4633. rc = -EIO;
  4634. return rc;
  4635. }
  4636. /**
  4637. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4638. * @phba: Pointer to HBA context object.
  4639. * @type: The resource extent type to allocate.
  4640. *
  4641. * This function allocates the number of elements for the specified
  4642. * resource type.
  4643. **/
  4644. static int
  4645. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4646. {
  4647. bool emb = false;
  4648. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4649. uint16_t rsrc_id, rsrc_start, j, k;
  4650. uint16_t *ids;
  4651. int i, rc;
  4652. unsigned long longs;
  4653. unsigned long *bmask;
  4654. struct lpfc_rsrc_blks *rsrc_blks;
  4655. LPFC_MBOXQ_t *mbox;
  4656. uint32_t length;
  4657. struct lpfc_id_range *id_array = NULL;
  4658. void *virtaddr = NULL;
  4659. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4660. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4661. struct list_head *ext_blk_list;
  4662. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4663. &rsrc_cnt,
  4664. &rsrc_size);
  4665. if (unlikely(rc))
  4666. return -EIO;
  4667. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4668. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4669. "3009 No available Resource Extents "
  4670. "for resource type 0x%x: Count: 0x%x, "
  4671. "Size 0x%x\n", type, rsrc_cnt,
  4672. rsrc_size);
  4673. return -ENOMEM;
  4674. }
  4675. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
  4676. "2903 Post resource extents type-0x%x: "
  4677. "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
  4678. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4679. if (!mbox)
  4680. return -ENOMEM;
  4681. rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
  4682. if (unlikely(rc)) {
  4683. rc = -EIO;
  4684. goto err_exit;
  4685. }
  4686. /*
  4687. * Figure out where the response is located. Then get local pointers
  4688. * to the response data. The port does not guarantee to respond to
  4689. * all extents counts request so update the local variable with the
  4690. * allocated count from the port.
  4691. */
  4692. if (emb == LPFC_SLI4_MBX_EMBED) {
  4693. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4694. id_array = &rsrc_ext->u.rsp.id[0];
  4695. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4696. } else {
  4697. virtaddr = mbox->sge_array->addr[0];
  4698. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4699. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4700. id_array = &n_rsrc->id;
  4701. }
  4702. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4703. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4704. /*
  4705. * Based on the resource size and count, correct the base and max
  4706. * resource values.
  4707. */
  4708. length = sizeof(struct lpfc_rsrc_blks);
  4709. switch (type) {
  4710. case LPFC_RSC_TYPE_FCOE_RPI:
  4711. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4712. sizeof(unsigned long),
  4713. GFP_KERNEL);
  4714. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4715. rc = -ENOMEM;
  4716. goto err_exit;
  4717. }
  4718. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4719. sizeof(uint16_t),
  4720. GFP_KERNEL);
  4721. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4722. kfree(phba->sli4_hba.rpi_bmask);
  4723. rc = -ENOMEM;
  4724. goto err_exit;
  4725. }
  4726. /*
  4727. * The next_rpi was initialized with the maximum available
  4728. * count but the port may allocate a smaller number. Catch
  4729. * that case and update the next_rpi.
  4730. */
  4731. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4732. /* Initialize local ptrs for common extent processing later. */
  4733. bmask = phba->sli4_hba.rpi_bmask;
  4734. ids = phba->sli4_hba.rpi_ids;
  4735. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4736. break;
  4737. case LPFC_RSC_TYPE_FCOE_VPI:
  4738. phba->vpi_bmask = kzalloc(longs *
  4739. sizeof(unsigned long),
  4740. GFP_KERNEL);
  4741. if (unlikely(!phba->vpi_bmask)) {
  4742. rc = -ENOMEM;
  4743. goto err_exit;
  4744. }
  4745. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4746. sizeof(uint16_t),
  4747. GFP_KERNEL);
  4748. if (unlikely(!phba->vpi_ids)) {
  4749. kfree(phba->vpi_bmask);
  4750. rc = -ENOMEM;
  4751. goto err_exit;
  4752. }
  4753. /* Initialize local ptrs for common extent processing later. */
  4754. bmask = phba->vpi_bmask;
  4755. ids = phba->vpi_ids;
  4756. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4757. break;
  4758. case LPFC_RSC_TYPE_FCOE_XRI:
  4759. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4760. sizeof(unsigned long),
  4761. GFP_KERNEL);
  4762. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4763. rc = -ENOMEM;
  4764. goto err_exit;
  4765. }
  4766. phba->sli4_hba.max_cfg_param.xri_used = 0;
  4767. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4768. sizeof(uint16_t),
  4769. GFP_KERNEL);
  4770. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4771. kfree(phba->sli4_hba.xri_bmask);
  4772. rc = -ENOMEM;
  4773. goto err_exit;
  4774. }
  4775. /* Initialize local ptrs for common extent processing later. */
  4776. bmask = phba->sli4_hba.xri_bmask;
  4777. ids = phba->sli4_hba.xri_ids;
  4778. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4779. break;
  4780. case LPFC_RSC_TYPE_FCOE_VFI:
  4781. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4782. sizeof(unsigned long),
  4783. GFP_KERNEL);
  4784. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4785. rc = -ENOMEM;
  4786. goto err_exit;
  4787. }
  4788. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4789. sizeof(uint16_t),
  4790. GFP_KERNEL);
  4791. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4792. kfree(phba->sli4_hba.vfi_bmask);
  4793. rc = -ENOMEM;
  4794. goto err_exit;
  4795. }
  4796. /* Initialize local ptrs for common extent processing later. */
  4797. bmask = phba->sli4_hba.vfi_bmask;
  4798. ids = phba->sli4_hba.vfi_ids;
  4799. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4800. break;
  4801. default:
  4802. /* Unsupported Opcode. Fail call. */
  4803. id_array = NULL;
  4804. bmask = NULL;
  4805. ids = NULL;
  4806. ext_blk_list = NULL;
  4807. goto err_exit;
  4808. }
  4809. /*
  4810. * Complete initializing the extent configuration with the
  4811. * allocated ids assigned to this function. The bitmask serves
  4812. * as an index into the array and manages the available ids. The
  4813. * array just stores the ids communicated to the port via the wqes.
  4814. */
  4815. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  4816. if ((i % 2) == 0)
  4817. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  4818. &id_array[k]);
  4819. else
  4820. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  4821. &id_array[k]);
  4822. rsrc_blks = kzalloc(length, GFP_KERNEL);
  4823. if (unlikely(!rsrc_blks)) {
  4824. rc = -ENOMEM;
  4825. kfree(bmask);
  4826. kfree(ids);
  4827. goto err_exit;
  4828. }
  4829. rsrc_blks->rsrc_start = rsrc_id;
  4830. rsrc_blks->rsrc_size = rsrc_size;
  4831. list_add_tail(&rsrc_blks->list, ext_blk_list);
  4832. rsrc_start = rsrc_id;
  4833. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  4834. phba->sli4_hba.scsi_xri_start = rsrc_start +
  4835. lpfc_sli4_get_els_iocb_cnt(phba);
  4836. while (rsrc_id < (rsrc_start + rsrc_size)) {
  4837. ids[j] = rsrc_id;
  4838. rsrc_id++;
  4839. j++;
  4840. }
  4841. /* Entire word processed. Get next word.*/
  4842. if ((i % 2) == 1)
  4843. k++;
  4844. }
  4845. err_exit:
  4846. lpfc_sli4_mbox_cmd_free(phba, mbox);
  4847. return rc;
  4848. }
  4849. /**
  4850. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  4851. * @phba: Pointer to HBA context object.
  4852. * @type: the extent's type.
  4853. *
  4854. * This function deallocates all extents of a particular resource type.
  4855. * SLI4 does not allow for deallocating a particular extent range. It
  4856. * is the caller's responsibility to release all kernel memory resources.
  4857. **/
  4858. static int
  4859. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  4860. {
  4861. int rc;
  4862. uint32_t length, mbox_tmo = 0;
  4863. LPFC_MBOXQ_t *mbox;
  4864. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  4865. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  4866. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4867. if (!mbox)
  4868. return -ENOMEM;
  4869. /*
  4870. * This function sends an embedded mailbox because it only sends the
  4871. * the resource type. All extents of this type are released by the
  4872. * port.
  4873. */
  4874. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  4875. sizeof(struct lpfc_sli4_cfg_mhdr));
  4876. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4877. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  4878. length, LPFC_SLI4_MBX_EMBED);
  4879. /* Send an extents count of 0 - the dealloc doesn't use it. */
  4880. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4881. LPFC_SLI4_MBX_EMBED);
  4882. if (unlikely(rc)) {
  4883. rc = -EIO;
  4884. goto out_free_mbox;
  4885. }
  4886. if (!phba->sli4_hba.intr_enable)
  4887. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4888. else {
  4889. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4890. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4891. }
  4892. if (unlikely(rc)) {
  4893. rc = -EIO;
  4894. goto out_free_mbox;
  4895. }
  4896. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  4897. if (bf_get(lpfc_mbox_hdr_status,
  4898. &dealloc_rsrc->header.cfg_shdr.response)) {
  4899. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4900. "2919 Failed to release resource extents "
  4901. "for type %d - Status 0x%x Add'l Status 0x%x. "
  4902. "Resource memory not released.\n",
  4903. type,
  4904. bf_get(lpfc_mbox_hdr_status,
  4905. &dealloc_rsrc->header.cfg_shdr.response),
  4906. bf_get(lpfc_mbox_hdr_add_status,
  4907. &dealloc_rsrc->header.cfg_shdr.response));
  4908. rc = -EIO;
  4909. goto out_free_mbox;
  4910. }
  4911. /* Release kernel memory resources for the specific type. */
  4912. switch (type) {
  4913. case LPFC_RSC_TYPE_FCOE_VPI:
  4914. kfree(phba->vpi_bmask);
  4915. kfree(phba->vpi_ids);
  4916. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4917. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4918. &phba->lpfc_vpi_blk_list, list) {
  4919. list_del_init(&rsrc_blk->list);
  4920. kfree(rsrc_blk);
  4921. }
  4922. break;
  4923. case LPFC_RSC_TYPE_FCOE_XRI:
  4924. kfree(phba->sli4_hba.xri_bmask);
  4925. kfree(phba->sli4_hba.xri_ids);
  4926. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4927. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  4928. list_del_init(&rsrc_blk->list);
  4929. kfree(rsrc_blk);
  4930. }
  4931. break;
  4932. case LPFC_RSC_TYPE_FCOE_VFI:
  4933. kfree(phba->sli4_hba.vfi_bmask);
  4934. kfree(phba->sli4_hba.vfi_ids);
  4935. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4936. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4937. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  4938. list_del_init(&rsrc_blk->list);
  4939. kfree(rsrc_blk);
  4940. }
  4941. break;
  4942. case LPFC_RSC_TYPE_FCOE_RPI:
  4943. /* RPI bitmask and physical id array are cleaned up earlier. */
  4944. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4945. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  4946. list_del_init(&rsrc_blk->list);
  4947. kfree(rsrc_blk);
  4948. }
  4949. break;
  4950. default:
  4951. break;
  4952. }
  4953. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4954. out_free_mbox:
  4955. mempool_free(mbox, phba->mbox_mem_pool);
  4956. return rc;
  4957. }
  4958. /**
  4959. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  4960. * @phba: Pointer to HBA context object.
  4961. *
  4962. * This function allocates all SLI4 resource identifiers.
  4963. **/
  4964. int
  4965. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  4966. {
  4967. int i, rc, error = 0;
  4968. uint16_t count, base;
  4969. unsigned long longs;
  4970. if (!phba->sli4_hba.rpi_hdrs_in_use)
  4971. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  4972. if (phba->sli4_hba.extents_in_use) {
  4973. /*
  4974. * The port supports resource extents. The XRI, VPI, VFI, RPI
  4975. * resource extent count must be read and allocated before
  4976. * provisioning the resource id arrays.
  4977. */
  4978. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  4979. LPFC_IDX_RSRC_RDY) {
  4980. /*
  4981. * Extent-based resources are set - the driver could
  4982. * be in a port reset. Figure out if any corrective
  4983. * actions need to be taken.
  4984. */
  4985. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4986. LPFC_RSC_TYPE_FCOE_VFI);
  4987. if (rc != 0)
  4988. error++;
  4989. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4990. LPFC_RSC_TYPE_FCOE_VPI);
  4991. if (rc != 0)
  4992. error++;
  4993. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4994. LPFC_RSC_TYPE_FCOE_XRI);
  4995. if (rc != 0)
  4996. error++;
  4997. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4998. LPFC_RSC_TYPE_FCOE_RPI);
  4999. if (rc != 0)
  5000. error++;
  5001. /*
  5002. * It's possible that the number of resources
  5003. * provided to this port instance changed between
  5004. * resets. Detect this condition and reallocate
  5005. * resources. Otherwise, there is no action.
  5006. */
  5007. if (error) {
  5008. lpfc_printf_log(phba, KERN_INFO,
  5009. LOG_MBOX | LOG_INIT,
  5010. "2931 Detected extent resource "
  5011. "change. Reallocating all "
  5012. "extents.\n");
  5013. rc = lpfc_sli4_dealloc_extent(phba,
  5014. LPFC_RSC_TYPE_FCOE_VFI);
  5015. rc = lpfc_sli4_dealloc_extent(phba,
  5016. LPFC_RSC_TYPE_FCOE_VPI);
  5017. rc = lpfc_sli4_dealloc_extent(phba,
  5018. LPFC_RSC_TYPE_FCOE_XRI);
  5019. rc = lpfc_sli4_dealloc_extent(phba,
  5020. LPFC_RSC_TYPE_FCOE_RPI);
  5021. } else
  5022. return 0;
  5023. }
  5024. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5025. if (unlikely(rc))
  5026. goto err_exit;
  5027. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5028. if (unlikely(rc))
  5029. goto err_exit;
  5030. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5031. if (unlikely(rc))
  5032. goto err_exit;
  5033. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5034. if (unlikely(rc))
  5035. goto err_exit;
  5036. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5037. LPFC_IDX_RSRC_RDY);
  5038. return rc;
  5039. } else {
  5040. /*
  5041. * The port does not support resource extents. The XRI, VPI,
  5042. * VFI, RPI resource ids were determined from READ_CONFIG.
  5043. * Just allocate the bitmasks and provision the resource id
  5044. * arrays. If a port reset is active, the resources don't
  5045. * need any action - just exit.
  5046. */
  5047. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5048. LPFC_IDX_RSRC_RDY) {
  5049. lpfc_sli4_dealloc_resource_identifiers(phba);
  5050. lpfc_sli4_remove_rpis(phba);
  5051. }
  5052. /* RPIs. */
  5053. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5054. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5055. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5056. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5057. sizeof(unsigned long),
  5058. GFP_KERNEL);
  5059. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5060. rc = -ENOMEM;
  5061. goto err_exit;
  5062. }
  5063. phba->sli4_hba.rpi_ids = kzalloc(count *
  5064. sizeof(uint16_t),
  5065. GFP_KERNEL);
  5066. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5067. rc = -ENOMEM;
  5068. goto free_rpi_bmask;
  5069. }
  5070. for (i = 0; i < count; i++)
  5071. phba->sli4_hba.rpi_ids[i] = base + i;
  5072. /* VPIs. */
  5073. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5074. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5075. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5076. phba->vpi_bmask = kzalloc(longs *
  5077. sizeof(unsigned long),
  5078. GFP_KERNEL);
  5079. if (unlikely(!phba->vpi_bmask)) {
  5080. rc = -ENOMEM;
  5081. goto free_rpi_ids;
  5082. }
  5083. phba->vpi_ids = kzalloc(count *
  5084. sizeof(uint16_t),
  5085. GFP_KERNEL);
  5086. if (unlikely(!phba->vpi_ids)) {
  5087. rc = -ENOMEM;
  5088. goto free_vpi_bmask;
  5089. }
  5090. for (i = 0; i < count; i++)
  5091. phba->vpi_ids[i] = base + i;
  5092. /* XRIs. */
  5093. count = phba->sli4_hba.max_cfg_param.max_xri;
  5094. base = phba->sli4_hba.max_cfg_param.xri_base;
  5095. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5096. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5097. sizeof(unsigned long),
  5098. GFP_KERNEL);
  5099. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5100. rc = -ENOMEM;
  5101. goto free_vpi_ids;
  5102. }
  5103. phba->sli4_hba.max_cfg_param.xri_used = 0;
  5104. phba->sli4_hba.xri_ids = kzalloc(count *
  5105. sizeof(uint16_t),
  5106. GFP_KERNEL);
  5107. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5108. rc = -ENOMEM;
  5109. goto free_xri_bmask;
  5110. }
  5111. for (i = 0; i < count; i++)
  5112. phba->sli4_hba.xri_ids[i] = base + i;
  5113. /* VFIs. */
  5114. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5115. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5116. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5117. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5118. sizeof(unsigned long),
  5119. GFP_KERNEL);
  5120. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5121. rc = -ENOMEM;
  5122. goto free_xri_ids;
  5123. }
  5124. phba->sli4_hba.vfi_ids = kzalloc(count *
  5125. sizeof(uint16_t),
  5126. GFP_KERNEL);
  5127. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5128. rc = -ENOMEM;
  5129. goto free_vfi_bmask;
  5130. }
  5131. for (i = 0; i < count; i++)
  5132. phba->sli4_hba.vfi_ids[i] = base + i;
  5133. /*
  5134. * Mark all resources ready. An HBA reset doesn't need
  5135. * to reset the initialization.
  5136. */
  5137. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5138. LPFC_IDX_RSRC_RDY);
  5139. return 0;
  5140. }
  5141. free_vfi_bmask:
  5142. kfree(phba->sli4_hba.vfi_bmask);
  5143. free_xri_ids:
  5144. kfree(phba->sli4_hba.xri_ids);
  5145. free_xri_bmask:
  5146. kfree(phba->sli4_hba.xri_bmask);
  5147. free_vpi_ids:
  5148. kfree(phba->vpi_ids);
  5149. free_vpi_bmask:
  5150. kfree(phba->vpi_bmask);
  5151. free_rpi_ids:
  5152. kfree(phba->sli4_hba.rpi_ids);
  5153. free_rpi_bmask:
  5154. kfree(phba->sli4_hba.rpi_bmask);
  5155. err_exit:
  5156. return rc;
  5157. }
  5158. /**
  5159. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5160. * @phba: Pointer to HBA context object.
  5161. *
  5162. * This function allocates the number of elements for the specified
  5163. * resource type.
  5164. **/
  5165. int
  5166. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5167. {
  5168. if (phba->sli4_hba.extents_in_use) {
  5169. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5170. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5171. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5172. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5173. } else {
  5174. kfree(phba->vpi_bmask);
  5175. kfree(phba->vpi_ids);
  5176. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5177. kfree(phba->sli4_hba.xri_bmask);
  5178. kfree(phba->sli4_hba.xri_ids);
  5179. kfree(phba->sli4_hba.vfi_bmask);
  5180. kfree(phba->sli4_hba.vfi_ids);
  5181. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5182. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5183. }
  5184. return 0;
  5185. }
  5186. /**
  5187. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5188. * @phba: Pointer to HBA context object.
  5189. * @type: The resource extent type.
  5190. * @extnt_count: buffer to hold port extent count response
  5191. * @extnt_size: buffer to hold port extent size response.
  5192. *
  5193. * This function calls the port to read the host allocated extents
  5194. * for a particular type.
  5195. **/
  5196. int
  5197. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5198. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5199. {
  5200. bool emb;
  5201. int rc = 0;
  5202. uint16_t curr_blks = 0;
  5203. uint32_t req_len, emb_len;
  5204. uint32_t alloc_len, mbox_tmo;
  5205. struct list_head *blk_list_head;
  5206. struct lpfc_rsrc_blks *rsrc_blk;
  5207. LPFC_MBOXQ_t *mbox;
  5208. void *virtaddr = NULL;
  5209. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5210. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5211. union lpfc_sli4_cfg_shdr *shdr;
  5212. switch (type) {
  5213. case LPFC_RSC_TYPE_FCOE_VPI:
  5214. blk_list_head = &phba->lpfc_vpi_blk_list;
  5215. break;
  5216. case LPFC_RSC_TYPE_FCOE_XRI:
  5217. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5218. break;
  5219. case LPFC_RSC_TYPE_FCOE_VFI:
  5220. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5221. break;
  5222. case LPFC_RSC_TYPE_FCOE_RPI:
  5223. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5224. break;
  5225. default:
  5226. return -EIO;
  5227. }
  5228. /* Count the number of extents currently allocatd for this type. */
  5229. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5230. if (curr_blks == 0) {
  5231. /*
  5232. * The GET_ALLOCATED mailbox does not return the size,
  5233. * just the count. The size should be just the size
  5234. * stored in the current allocated block and all sizes
  5235. * for an extent type are the same so set the return
  5236. * value now.
  5237. */
  5238. *extnt_size = rsrc_blk->rsrc_size;
  5239. }
  5240. curr_blks++;
  5241. }
  5242. /* Calculate the total requested length of the dma memory. */
  5243. req_len = curr_blks * sizeof(uint16_t);
  5244. /*
  5245. * Calculate the size of an embedded mailbox. The uint32_t
  5246. * accounts for extents-specific word.
  5247. */
  5248. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5249. sizeof(uint32_t);
  5250. /*
  5251. * Presume the allocation and response will fit into an embedded
  5252. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5253. */
  5254. emb = LPFC_SLI4_MBX_EMBED;
  5255. req_len = emb_len;
  5256. if (req_len > emb_len) {
  5257. req_len = curr_blks * sizeof(uint16_t) +
  5258. sizeof(union lpfc_sli4_cfg_shdr) +
  5259. sizeof(uint32_t);
  5260. emb = LPFC_SLI4_MBX_NEMBED;
  5261. }
  5262. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5263. if (!mbox)
  5264. return -ENOMEM;
  5265. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5266. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5267. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5268. req_len, emb);
  5269. if (alloc_len < req_len) {
  5270. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5271. "2983 Allocated DMA memory size (x%x) is "
  5272. "less than the requested DMA memory "
  5273. "size (x%x)\n", alloc_len, req_len);
  5274. rc = -ENOMEM;
  5275. goto err_exit;
  5276. }
  5277. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5278. if (unlikely(rc)) {
  5279. rc = -EIO;
  5280. goto err_exit;
  5281. }
  5282. if (!phba->sli4_hba.intr_enable)
  5283. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5284. else {
  5285. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5286. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5287. }
  5288. if (unlikely(rc)) {
  5289. rc = -EIO;
  5290. goto err_exit;
  5291. }
  5292. /*
  5293. * Figure out where the response is located. Then get local pointers
  5294. * to the response data. The port does not guarantee to respond to
  5295. * all extents counts request so update the local variable with the
  5296. * allocated count from the port.
  5297. */
  5298. if (emb == LPFC_SLI4_MBX_EMBED) {
  5299. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5300. shdr = &rsrc_ext->header.cfg_shdr;
  5301. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5302. } else {
  5303. virtaddr = mbox->sge_array->addr[0];
  5304. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5305. shdr = &n_rsrc->cfg_shdr;
  5306. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5307. }
  5308. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5309. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5310. "2984 Failed to read allocated resources "
  5311. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5312. type,
  5313. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5314. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5315. rc = -EIO;
  5316. goto err_exit;
  5317. }
  5318. err_exit:
  5319. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5320. return rc;
  5321. }
  5322. /**
  5323. * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
  5324. * @phba: pointer to lpfc hba data structure.
  5325. *
  5326. * This routine walks the list of els buffers that have been allocated and
  5327. * repost them to the port by using SGL block post. This is needed after a
  5328. * pci_function_reset/warm_start or start. It attempts to construct blocks
  5329. * of els buffer sgls which contains contiguous xris and uses the non-embedded
  5330. * SGL block post mailbox commands to post them to the port. For single els
  5331. * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
  5332. * mailbox command for posting.
  5333. *
  5334. * Returns: 0 = success, non-zero failure.
  5335. **/
  5336. static int
  5337. lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
  5338. {
  5339. struct lpfc_sglq *sglq_entry = NULL;
  5340. struct lpfc_sglq *sglq_entry_next = NULL;
  5341. struct lpfc_sglq *sglq_entry_first = NULL;
  5342. int status, post_cnt = 0, num_posted = 0, block_cnt = 0;
  5343. int last_xritag = NO_XRI;
  5344. LIST_HEAD(prep_sgl_list);
  5345. LIST_HEAD(blck_sgl_list);
  5346. LIST_HEAD(allc_sgl_list);
  5347. LIST_HEAD(post_sgl_list);
  5348. LIST_HEAD(free_sgl_list);
  5349. spin_lock(&phba->hbalock);
  5350. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
  5351. spin_unlock(&phba->hbalock);
  5352. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  5353. &allc_sgl_list, list) {
  5354. list_del_init(&sglq_entry->list);
  5355. block_cnt++;
  5356. if ((last_xritag != NO_XRI) &&
  5357. (sglq_entry->sli4_xritag != last_xritag + 1)) {
  5358. /* a hole in xri block, form a sgl posting block */
  5359. list_splice_init(&prep_sgl_list, &blck_sgl_list);
  5360. post_cnt = block_cnt - 1;
  5361. /* prepare list for next posting block */
  5362. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5363. block_cnt = 1;
  5364. } else {
  5365. /* prepare list for next posting block */
  5366. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5367. /* enough sgls for non-embed sgl mbox command */
  5368. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  5369. list_splice_init(&prep_sgl_list,
  5370. &blck_sgl_list);
  5371. post_cnt = block_cnt;
  5372. block_cnt = 0;
  5373. }
  5374. }
  5375. num_posted++;
  5376. /* keep track of last sgl's xritag */
  5377. last_xritag = sglq_entry->sli4_xritag;
  5378. /* end of repost sgl list condition for els buffers */
  5379. if (num_posted == phba->sli4_hba.els_xri_cnt) {
  5380. if (post_cnt == 0) {
  5381. list_splice_init(&prep_sgl_list,
  5382. &blck_sgl_list);
  5383. post_cnt = block_cnt;
  5384. } else if (block_cnt == 1) {
  5385. status = lpfc_sli4_post_sgl(phba,
  5386. sglq_entry->phys, 0,
  5387. sglq_entry->sli4_xritag);
  5388. if (!status) {
  5389. /* successful, put sgl to posted list */
  5390. list_add_tail(&sglq_entry->list,
  5391. &post_sgl_list);
  5392. } else {
  5393. /* Failure, put sgl to free list */
  5394. lpfc_printf_log(phba, KERN_WARNING,
  5395. LOG_SLI,
  5396. "3159 Failed to post els "
  5397. "sgl, xritag:x%x\n",
  5398. sglq_entry->sli4_xritag);
  5399. list_add_tail(&sglq_entry->list,
  5400. &free_sgl_list);
  5401. spin_lock_irq(&phba->hbalock);
  5402. phba->sli4_hba.els_xri_cnt--;
  5403. spin_unlock_irq(&phba->hbalock);
  5404. }
  5405. }
  5406. }
  5407. /* continue until a nembed page worth of sgls */
  5408. if (post_cnt == 0)
  5409. continue;
  5410. /* post the els buffer list sgls as a block */
  5411. status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
  5412. post_cnt);
  5413. if (!status) {
  5414. /* success, put sgl list to posted sgl list */
  5415. list_splice_init(&blck_sgl_list, &post_sgl_list);
  5416. } else {
  5417. /* Failure, put sgl list to free sgl list */
  5418. sglq_entry_first = list_first_entry(&blck_sgl_list,
  5419. struct lpfc_sglq,
  5420. list);
  5421. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5422. "3160 Failed to post els sgl-list, "
  5423. "xritag:x%x-x%x\n",
  5424. sglq_entry_first->sli4_xritag,
  5425. (sglq_entry_first->sli4_xritag +
  5426. post_cnt - 1));
  5427. list_splice_init(&blck_sgl_list, &free_sgl_list);
  5428. spin_lock_irq(&phba->hbalock);
  5429. phba->sli4_hba.els_xri_cnt -= post_cnt;
  5430. spin_unlock_irq(&phba->hbalock);
  5431. }
  5432. /* don't reset xirtag due to hole in xri block */
  5433. if (block_cnt == 0)
  5434. last_xritag = NO_XRI;
  5435. /* reset els sgl post count for next round of posting */
  5436. post_cnt = 0;
  5437. }
  5438. /* free the els sgls failed to post */
  5439. lpfc_free_sgl_list(phba, &free_sgl_list);
  5440. /* push els sgls posted to the availble list */
  5441. if (!list_empty(&post_sgl_list)) {
  5442. spin_lock(&phba->hbalock);
  5443. list_splice_init(&post_sgl_list,
  5444. &phba->sli4_hba.lpfc_sgl_list);
  5445. spin_unlock(&phba->hbalock);
  5446. } else {
  5447. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5448. "3161 Failure to post els sgl to port.\n");
  5449. return -EIO;
  5450. }
  5451. return 0;
  5452. }
  5453. /**
  5454. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5455. * @phba: Pointer to HBA context object.
  5456. *
  5457. * This function is the main SLI4 device intialization PCI function. This
  5458. * function is called by the HBA intialization code, HBA reset code and
  5459. * HBA error attention handler code. Caller is not required to hold any
  5460. * locks.
  5461. **/
  5462. int
  5463. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5464. {
  5465. int rc;
  5466. LPFC_MBOXQ_t *mboxq;
  5467. struct lpfc_mqe *mqe;
  5468. uint8_t *vpd;
  5469. uint32_t vpd_size;
  5470. uint32_t ftr_rsp = 0;
  5471. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5472. struct lpfc_vport *vport = phba->pport;
  5473. struct lpfc_dmabuf *mp;
  5474. /* Perform a PCI function reset to start from clean */
  5475. rc = lpfc_pci_function_reset(phba);
  5476. if (unlikely(rc))
  5477. return -ENODEV;
  5478. /* Check the HBA Host Status Register for readyness */
  5479. rc = lpfc_sli4_post_status_check(phba);
  5480. if (unlikely(rc))
  5481. return -ENODEV;
  5482. else {
  5483. spin_lock_irq(&phba->hbalock);
  5484. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5485. spin_unlock_irq(&phba->hbalock);
  5486. }
  5487. /*
  5488. * Allocate a single mailbox container for initializing the
  5489. * port.
  5490. */
  5491. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5492. if (!mboxq)
  5493. return -ENOMEM;
  5494. /* Issue READ_REV to collect vpd and FW information. */
  5495. vpd_size = SLI4_PAGE_SIZE;
  5496. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5497. if (!vpd) {
  5498. rc = -ENOMEM;
  5499. goto out_free_mbox;
  5500. }
  5501. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5502. if (unlikely(rc)) {
  5503. kfree(vpd);
  5504. goto out_free_mbox;
  5505. }
  5506. mqe = &mboxq->u.mqe;
  5507. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5508. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  5509. phba->hba_flag |= HBA_FCOE_MODE;
  5510. else
  5511. phba->hba_flag &= ~HBA_FCOE_MODE;
  5512. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5513. LPFC_DCBX_CEE_MODE)
  5514. phba->hba_flag |= HBA_FIP_SUPPORT;
  5515. else
  5516. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5517. phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
  5518. if (phba->sli_rev != LPFC_SLI_REV4) {
  5519. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5520. "0376 READ_REV Error. SLI Level %d "
  5521. "FCoE enabled %d\n",
  5522. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5523. rc = -EIO;
  5524. kfree(vpd);
  5525. goto out_free_mbox;
  5526. }
  5527. /*
  5528. * Continue initialization with default values even if driver failed
  5529. * to read FCoE param config regions, only read parameters if the
  5530. * board is FCoE
  5531. */
  5532. if (phba->hba_flag & HBA_FCOE_MODE &&
  5533. lpfc_sli4_read_fcoe_params(phba))
  5534. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5535. "2570 Failed to read FCoE parameters\n");
  5536. /*
  5537. * Retrieve sli4 device physical port name, failure of doing it
  5538. * is considered as non-fatal.
  5539. */
  5540. rc = lpfc_sli4_retrieve_pport_name(phba);
  5541. if (!rc)
  5542. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5543. "3080 Successful retrieving SLI4 device "
  5544. "physical port name: %s.\n", phba->Port);
  5545. /*
  5546. * Evaluate the read rev and vpd data. Populate the driver
  5547. * state with the results. If this routine fails, the failure
  5548. * is not fatal as the driver will use generic values.
  5549. */
  5550. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5551. if (unlikely(!rc)) {
  5552. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5553. "0377 Error %d parsing vpd. "
  5554. "Using defaults.\n", rc);
  5555. rc = 0;
  5556. }
  5557. kfree(vpd);
  5558. /* Save information as VPD data */
  5559. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5560. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5561. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5562. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5563. &mqe->un.read_rev);
  5564. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5565. &mqe->un.read_rev);
  5566. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5567. &mqe->un.read_rev);
  5568. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5569. &mqe->un.read_rev);
  5570. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5571. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5572. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5573. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5574. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5575. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5576. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5577. "(%d):0380 READ_REV Status x%x "
  5578. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5579. mboxq->vport ? mboxq->vport->vpi : 0,
  5580. bf_get(lpfc_mqe_status, mqe),
  5581. phba->vpd.rev.opFwName,
  5582. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5583. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5584. /*
  5585. * Discover the port's supported feature set and match it against the
  5586. * hosts requests.
  5587. */
  5588. lpfc_request_features(phba, mboxq);
  5589. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5590. if (unlikely(rc)) {
  5591. rc = -EIO;
  5592. goto out_free_mbox;
  5593. }
  5594. /*
  5595. * The port must support FCP initiator mode as this is the
  5596. * only mode running in the host.
  5597. */
  5598. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5599. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5600. "0378 No support for fcpi mode.\n");
  5601. ftr_rsp++;
  5602. }
  5603. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5604. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5605. else
  5606. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5607. /*
  5608. * If the port cannot support the host's requested features
  5609. * then turn off the global config parameters to disable the
  5610. * feature in the driver. This is not a fatal error.
  5611. */
  5612. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5613. if (phba->cfg_enable_bg) {
  5614. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5615. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5616. else
  5617. ftr_rsp++;
  5618. }
  5619. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5620. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5621. ftr_rsp++;
  5622. if (ftr_rsp) {
  5623. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5624. "0379 Feature Mismatch Data: x%08x %08x "
  5625. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5626. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5627. phba->cfg_enable_npiv, phba->max_vpi);
  5628. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5629. phba->cfg_enable_bg = 0;
  5630. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5631. phba->cfg_enable_npiv = 0;
  5632. }
  5633. /* These SLI3 features are assumed in SLI4 */
  5634. spin_lock_irq(&phba->hbalock);
  5635. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5636. spin_unlock_irq(&phba->hbalock);
  5637. /*
  5638. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5639. * calls depends on these resources to complete port setup.
  5640. */
  5641. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5642. if (rc) {
  5643. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5644. "2920 Failed to alloc Resource IDs "
  5645. "rc = x%x\n", rc);
  5646. goto out_free_mbox;
  5647. }
  5648. /* Read the port's service parameters. */
  5649. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5650. if (rc) {
  5651. phba->link_state = LPFC_HBA_ERROR;
  5652. rc = -ENOMEM;
  5653. goto out_free_mbox;
  5654. }
  5655. mboxq->vport = vport;
  5656. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5657. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5658. if (rc == MBX_SUCCESS) {
  5659. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5660. rc = 0;
  5661. }
  5662. /*
  5663. * This memory was allocated by the lpfc_read_sparam routine. Release
  5664. * it to the mbuf pool.
  5665. */
  5666. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5667. kfree(mp);
  5668. mboxq->context1 = NULL;
  5669. if (unlikely(rc)) {
  5670. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5671. "0382 READ_SPARAM command failed "
  5672. "status %d, mbxStatus x%x\n",
  5673. rc, bf_get(lpfc_mqe_status, mqe));
  5674. phba->link_state = LPFC_HBA_ERROR;
  5675. rc = -EIO;
  5676. goto out_free_mbox;
  5677. }
  5678. lpfc_update_vport_wwn(vport);
  5679. /* Update the fc_host data structures with new wwn. */
  5680. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5681. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5682. /* update host els and scsi xri-sgl sizes and mappings */
  5683. rc = lpfc_sli4_xri_sgl_update(phba);
  5684. if (unlikely(rc)) {
  5685. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5686. "1400 Failed to update xri-sgl size and "
  5687. "mapping: %d\n", rc);
  5688. goto out_free_mbox;
  5689. }
  5690. /* register the els sgl pool to the port */
  5691. rc = lpfc_sli4_repost_els_sgl_list(phba);
  5692. if (unlikely(rc)) {
  5693. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5694. "0582 Error %d during els sgl post "
  5695. "operation\n", rc);
  5696. rc = -ENODEV;
  5697. goto out_free_mbox;
  5698. }
  5699. /* register the allocated scsi sgl pool to the port */
  5700. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  5701. if (unlikely(rc)) {
  5702. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5703. "0383 Error %d during scsi sgl post "
  5704. "operation\n", rc);
  5705. /* Some Scsi buffers were moved to the abort scsi list */
  5706. /* A pci function reset will repost them */
  5707. rc = -ENODEV;
  5708. goto out_free_mbox;
  5709. }
  5710. /* Post the rpi header region to the device. */
  5711. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  5712. if (unlikely(rc)) {
  5713. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5714. "0393 Error %d during rpi post operation\n",
  5715. rc);
  5716. rc = -ENODEV;
  5717. goto out_free_mbox;
  5718. }
  5719. lpfc_sli4_node_prep(phba);
  5720. /* Create all the SLI4 queues */
  5721. rc = lpfc_sli4_queue_create(phba);
  5722. if (rc) {
  5723. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5724. "3089 Failed to allocate queues\n");
  5725. rc = -ENODEV;
  5726. goto out_stop_timers;
  5727. }
  5728. /* Set up all the queues to the device */
  5729. rc = lpfc_sli4_queue_setup(phba);
  5730. if (unlikely(rc)) {
  5731. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5732. "0381 Error %d during queue setup.\n ", rc);
  5733. goto out_destroy_queue;
  5734. }
  5735. /* Arm the CQs and then EQs on device */
  5736. lpfc_sli4_arm_cqeq_intr(phba);
  5737. /* Indicate device interrupt mode */
  5738. phba->sli4_hba.intr_enable = 1;
  5739. /* Allow asynchronous mailbox command to go through */
  5740. spin_lock_irq(&phba->hbalock);
  5741. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5742. spin_unlock_irq(&phba->hbalock);
  5743. /* Post receive buffers to the device */
  5744. lpfc_sli4_rb_setup(phba);
  5745. /* Reset HBA FCF states after HBA reset */
  5746. phba->fcf.fcf_flag = 0;
  5747. phba->fcf.current_rec.flag = 0;
  5748. /* Start the ELS watchdog timer */
  5749. mod_timer(&vport->els_tmofunc,
  5750. jiffies + HZ * (phba->fc_ratov * 2));
  5751. /* Start heart beat timer */
  5752. mod_timer(&phba->hb_tmofunc,
  5753. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  5754. phba->hb_outstanding = 0;
  5755. phba->last_completion_time = jiffies;
  5756. /* Start error attention (ERATT) polling timer */
  5757. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  5758. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  5759. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  5760. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  5761. if (!rc) {
  5762. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5763. "2829 This device supports "
  5764. "Advanced Error Reporting (AER)\n");
  5765. spin_lock_irq(&phba->hbalock);
  5766. phba->hba_flag |= HBA_AER_ENABLED;
  5767. spin_unlock_irq(&phba->hbalock);
  5768. } else {
  5769. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5770. "2830 This device does not support "
  5771. "Advanced Error Reporting (AER)\n");
  5772. phba->cfg_aer_support = 0;
  5773. }
  5774. rc = 0;
  5775. }
  5776. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  5777. /*
  5778. * The FC Port needs to register FCFI (index 0)
  5779. */
  5780. lpfc_reg_fcfi(phba, mboxq);
  5781. mboxq->vport = phba->pport;
  5782. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5783. if (rc != MBX_SUCCESS)
  5784. goto out_unset_queue;
  5785. rc = 0;
  5786. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  5787. &mboxq->u.mqe.un.reg_fcfi);
  5788. /* Check if the port is configured to be disabled */
  5789. lpfc_sli_read_link_ste(phba);
  5790. }
  5791. /*
  5792. * The port is ready, set the host's link state to LINK_DOWN
  5793. * in preparation for link interrupts.
  5794. */
  5795. spin_lock_irq(&phba->hbalock);
  5796. phba->link_state = LPFC_LINK_DOWN;
  5797. spin_unlock_irq(&phba->hbalock);
  5798. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  5799. (phba->hba_flag & LINK_DISABLED)) {
  5800. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5801. "3103 Adapter Link is disabled.\n");
  5802. lpfc_down_link(phba, mboxq);
  5803. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5804. if (rc != MBX_SUCCESS) {
  5805. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5806. "3104 Adapter failed to issue "
  5807. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  5808. goto out_unset_queue;
  5809. }
  5810. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  5811. /* don't perform init_link on SLI4 FC port loopback test */
  5812. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  5813. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  5814. if (rc)
  5815. goto out_unset_queue;
  5816. }
  5817. }
  5818. mempool_free(mboxq, phba->mbox_mem_pool);
  5819. return rc;
  5820. out_unset_queue:
  5821. /* Unset all the queues set up in this routine when error out */
  5822. lpfc_sli4_queue_unset(phba);
  5823. out_destroy_queue:
  5824. lpfc_sli4_queue_destroy(phba);
  5825. out_stop_timers:
  5826. lpfc_stop_hba_timers(phba);
  5827. out_free_mbox:
  5828. mempool_free(mboxq, phba->mbox_mem_pool);
  5829. return rc;
  5830. }
  5831. /**
  5832. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  5833. * @ptr: context object - pointer to hba structure.
  5834. *
  5835. * This is the callback function for mailbox timer. The mailbox
  5836. * timer is armed when a new mailbox command is issued and the timer
  5837. * is deleted when the mailbox complete. The function is called by
  5838. * the kernel timer code when a mailbox does not complete within
  5839. * expected time. This function wakes up the worker thread to
  5840. * process the mailbox timeout and returns. All the processing is
  5841. * done by the worker thread function lpfc_mbox_timeout_handler.
  5842. **/
  5843. void
  5844. lpfc_mbox_timeout(unsigned long ptr)
  5845. {
  5846. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  5847. unsigned long iflag;
  5848. uint32_t tmo_posted;
  5849. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  5850. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  5851. if (!tmo_posted)
  5852. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  5853. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  5854. if (!tmo_posted)
  5855. lpfc_worker_wake_up(phba);
  5856. return;
  5857. }
  5858. /**
  5859. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  5860. * @phba: Pointer to HBA context object.
  5861. *
  5862. * This function is called from worker thread when a mailbox command times out.
  5863. * The caller is not required to hold any locks. This function will reset the
  5864. * HBA and recover all the pending commands.
  5865. **/
  5866. void
  5867. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  5868. {
  5869. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  5870. MAILBOX_t *mb = &pmbox->u.mb;
  5871. struct lpfc_sli *psli = &phba->sli;
  5872. struct lpfc_sli_ring *pring;
  5873. /* Check the pmbox pointer first. There is a race condition
  5874. * between the mbox timeout handler getting executed in the
  5875. * worklist and the mailbox actually completing. When this
  5876. * race condition occurs, the mbox_active will be NULL.
  5877. */
  5878. spin_lock_irq(&phba->hbalock);
  5879. if (pmbox == NULL) {
  5880. lpfc_printf_log(phba, KERN_WARNING,
  5881. LOG_MBOX | LOG_SLI,
  5882. "0353 Active Mailbox cleared - mailbox timeout "
  5883. "exiting\n");
  5884. spin_unlock_irq(&phba->hbalock);
  5885. return;
  5886. }
  5887. /* Mbox cmd <mbxCommand> timeout */
  5888. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5889. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  5890. mb->mbxCommand,
  5891. phba->pport->port_state,
  5892. phba->sli.sli_flag,
  5893. phba->sli.mbox_active);
  5894. spin_unlock_irq(&phba->hbalock);
  5895. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  5896. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  5897. * it to fail all outstanding SCSI IO.
  5898. */
  5899. spin_lock_irq(&phba->pport->work_port_lock);
  5900. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  5901. spin_unlock_irq(&phba->pport->work_port_lock);
  5902. spin_lock_irq(&phba->hbalock);
  5903. phba->link_state = LPFC_LINK_UNKNOWN;
  5904. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  5905. spin_unlock_irq(&phba->hbalock);
  5906. pring = &psli->ring[psli->fcp_ring];
  5907. lpfc_sli_abort_iocb_ring(phba, pring);
  5908. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5909. "0345 Resetting board due to mailbox timeout\n");
  5910. /* Reset the HBA device */
  5911. lpfc_reset_hba(phba);
  5912. }
  5913. /**
  5914. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  5915. * @phba: Pointer to HBA context object.
  5916. * @pmbox: Pointer to mailbox object.
  5917. * @flag: Flag indicating how the mailbox need to be processed.
  5918. *
  5919. * This function is called by discovery code and HBA management code
  5920. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  5921. * function gets the hbalock to protect the data structures.
  5922. * The mailbox command can be submitted in polling mode, in which case
  5923. * this function will wait in a polling loop for the completion of the
  5924. * mailbox.
  5925. * If the mailbox is submitted in no_wait mode (not polling) the
  5926. * function will submit the command and returns immediately without waiting
  5927. * for the mailbox completion. The no_wait is supported only when HBA
  5928. * is in SLI2/SLI3 mode - interrupts are enabled.
  5929. * The SLI interface allows only one mailbox pending at a time. If the
  5930. * mailbox is issued in polling mode and there is already a mailbox
  5931. * pending, then the function will return an error. If the mailbox is issued
  5932. * in NO_WAIT mode and there is a mailbox pending already, the function
  5933. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  5934. * The sli layer owns the mailbox object until the completion of mailbox
  5935. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  5936. * return codes the caller owns the mailbox command after the return of
  5937. * the function.
  5938. **/
  5939. static int
  5940. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  5941. uint32_t flag)
  5942. {
  5943. MAILBOX_t *mb;
  5944. struct lpfc_sli *psli = &phba->sli;
  5945. uint32_t status, evtctr;
  5946. uint32_t ha_copy, hc_copy;
  5947. int i;
  5948. unsigned long timeout;
  5949. unsigned long drvr_flag = 0;
  5950. uint32_t word0, ldata;
  5951. void __iomem *to_slim;
  5952. int processing_queue = 0;
  5953. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  5954. if (!pmbox) {
  5955. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5956. /* processing mbox queue from intr_handler */
  5957. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5958. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5959. return MBX_SUCCESS;
  5960. }
  5961. processing_queue = 1;
  5962. pmbox = lpfc_mbox_get(phba);
  5963. if (!pmbox) {
  5964. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5965. return MBX_SUCCESS;
  5966. }
  5967. }
  5968. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  5969. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  5970. if(!pmbox->vport) {
  5971. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5972. lpfc_printf_log(phba, KERN_ERR,
  5973. LOG_MBOX | LOG_VPORT,
  5974. "1806 Mbox x%x failed. No vport\n",
  5975. pmbox->u.mb.mbxCommand);
  5976. dump_stack();
  5977. goto out_not_finished;
  5978. }
  5979. }
  5980. /* If the PCI channel is in offline state, do not post mbox. */
  5981. if (unlikely(pci_channel_offline(phba->pcidev))) {
  5982. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5983. goto out_not_finished;
  5984. }
  5985. /* If HBA has a deferred error attention, fail the iocb. */
  5986. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  5987. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5988. goto out_not_finished;
  5989. }
  5990. psli = &phba->sli;
  5991. mb = &pmbox->u.mb;
  5992. status = MBX_SUCCESS;
  5993. if (phba->link_state == LPFC_HBA_ERROR) {
  5994. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5995. /* Mbox command <mbxCommand> cannot issue */
  5996. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5997. "(%d):0311 Mailbox command x%x cannot "
  5998. "issue Data: x%x x%x\n",
  5999. pmbox->vport ? pmbox->vport->vpi : 0,
  6000. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6001. goto out_not_finished;
  6002. }
  6003. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  6004. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  6005. !(hc_copy & HC_MBINT_ENA)) {
  6006. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6007. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6008. "(%d):2528 Mailbox command x%x cannot "
  6009. "issue Data: x%x x%x\n",
  6010. pmbox->vport ? pmbox->vport->vpi : 0,
  6011. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6012. goto out_not_finished;
  6013. }
  6014. }
  6015. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6016. /* Polling for a mbox command when another one is already active
  6017. * is not allowed in SLI. Also, the driver must have established
  6018. * SLI2 mode to queue and process multiple mbox commands.
  6019. */
  6020. if (flag & MBX_POLL) {
  6021. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6022. /* Mbox command <mbxCommand> cannot issue */
  6023. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6024. "(%d):2529 Mailbox command x%x "
  6025. "cannot issue Data: x%x x%x\n",
  6026. pmbox->vport ? pmbox->vport->vpi : 0,
  6027. pmbox->u.mb.mbxCommand,
  6028. psli->sli_flag, flag);
  6029. goto out_not_finished;
  6030. }
  6031. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6032. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6033. /* Mbox command <mbxCommand> cannot issue */
  6034. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6035. "(%d):2530 Mailbox command x%x "
  6036. "cannot issue Data: x%x x%x\n",
  6037. pmbox->vport ? pmbox->vport->vpi : 0,
  6038. pmbox->u.mb.mbxCommand,
  6039. psli->sli_flag, flag);
  6040. goto out_not_finished;
  6041. }
  6042. /* Another mailbox command is still being processed, queue this
  6043. * command to be processed later.
  6044. */
  6045. lpfc_mbox_put(phba, pmbox);
  6046. /* Mbox cmd issue - BUSY */
  6047. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6048. "(%d):0308 Mbox cmd issue - BUSY Data: "
  6049. "x%x x%x x%x x%x\n",
  6050. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  6051. mb->mbxCommand, phba->pport->port_state,
  6052. psli->sli_flag, flag);
  6053. psli->slistat.mbox_busy++;
  6054. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6055. if (pmbox->vport) {
  6056. lpfc_debugfs_disc_trc(pmbox->vport,
  6057. LPFC_DISC_TRC_MBOX_VPORT,
  6058. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  6059. (uint32_t)mb->mbxCommand,
  6060. mb->un.varWords[0], mb->un.varWords[1]);
  6061. }
  6062. else {
  6063. lpfc_debugfs_disc_trc(phba->pport,
  6064. LPFC_DISC_TRC_MBOX,
  6065. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  6066. (uint32_t)mb->mbxCommand,
  6067. mb->un.varWords[0], mb->un.varWords[1]);
  6068. }
  6069. return MBX_BUSY;
  6070. }
  6071. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6072. /* If we are not polling, we MUST be in SLI2 mode */
  6073. if (flag != MBX_POLL) {
  6074. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  6075. (mb->mbxCommand != MBX_KILL_BOARD)) {
  6076. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6077. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6078. /* Mbox command <mbxCommand> cannot issue */
  6079. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6080. "(%d):2531 Mailbox command x%x "
  6081. "cannot issue Data: x%x x%x\n",
  6082. pmbox->vport ? pmbox->vport->vpi : 0,
  6083. pmbox->u.mb.mbxCommand,
  6084. psli->sli_flag, flag);
  6085. goto out_not_finished;
  6086. }
  6087. /* timeout active mbox command */
  6088. mod_timer(&psli->mbox_tmo, (jiffies +
  6089. (HZ * lpfc_mbox_tmo_val(phba, pmbox))));
  6090. }
  6091. /* Mailbox cmd <cmd> issue */
  6092. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6093. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  6094. "x%x\n",
  6095. pmbox->vport ? pmbox->vport->vpi : 0,
  6096. mb->mbxCommand, phba->pport->port_state,
  6097. psli->sli_flag, flag);
  6098. if (mb->mbxCommand != MBX_HEARTBEAT) {
  6099. if (pmbox->vport) {
  6100. lpfc_debugfs_disc_trc(pmbox->vport,
  6101. LPFC_DISC_TRC_MBOX_VPORT,
  6102. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6103. (uint32_t)mb->mbxCommand,
  6104. mb->un.varWords[0], mb->un.varWords[1]);
  6105. }
  6106. else {
  6107. lpfc_debugfs_disc_trc(phba->pport,
  6108. LPFC_DISC_TRC_MBOX,
  6109. "MBOX Send: cmd:x%x mb:x%x x%x",
  6110. (uint32_t)mb->mbxCommand,
  6111. mb->un.varWords[0], mb->un.varWords[1]);
  6112. }
  6113. }
  6114. psli->slistat.mbox_cmd++;
  6115. evtctr = psli->slistat.mbox_event;
  6116. /* next set own bit for the adapter and copy over command word */
  6117. mb->mbxOwner = OWN_CHIP;
  6118. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6119. /* Populate mbox extension offset word. */
  6120. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  6121. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  6122. = (uint8_t *)phba->mbox_ext
  6123. - (uint8_t *)phba->mbox;
  6124. }
  6125. /* Copy the mailbox extension data */
  6126. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6127. lpfc_sli_pcimem_bcopy(pmbox->context2,
  6128. (uint8_t *)phba->mbox_ext,
  6129. pmbox->in_ext_byte_len);
  6130. }
  6131. /* Copy command data to host SLIM area */
  6132. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  6133. } else {
  6134. /* Populate mbox extension offset word. */
  6135. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  6136. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  6137. = MAILBOX_HBA_EXT_OFFSET;
  6138. /* Copy the mailbox extension data */
  6139. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6140. lpfc_memcpy_to_slim(phba->MBslimaddr +
  6141. MAILBOX_HBA_EXT_OFFSET,
  6142. pmbox->context2, pmbox->in_ext_byte_len);
  6143. }
  6144. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6145. /* copy command data into host mbox for cmpl */
  6146. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  6147. }
  6148. /* First copy mbox command data to HBA SLIM, skip past first
  6149. word */
  6150. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6151. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  6152. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6153. /* Next copy over first word, with mbxOwner set */
  6154. ldata = *((uint32_t *)mb);
  6155. to_slim = phba->MBslimaddr;
  6156. writel(ldata, to_slim);
  6157. readl(to_slim); /* flush */
  6158. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6159. /* switch over to host mailbox */
  6160. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6161. }
  6162. }
  6163. wmb();
  6164. switch (flag) {
  6165. case MBX_NOWAIT:
  6166. /* Set up reference to mailbox command */
  6167. psli->mbox_active = pmbox;
  6168. /* Interrupt board to do it */
  6169. writel(CA_MBATT, phba->CAregaddr);
  6170. readl(phba->CAregaddr); /* flush */
  6171. /* Don't wait for it to finish, just return */
  6172. break;
  6173. case MBX_POLL:
  6174. /* Set up null reference to mailbox command */
  6175. psli->mbox_active = NULL;
  6176. /* Interrupt board to do it */
  6177. writel(CA_MBATT, phba->CAregaddr);
  6178. readl(phba->CAregaddr); /* flush */
  6179. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6180. /* First read mbox status word */
  6181. word0 = *((uint32_t *)phba->mbox);
  6182. word0 = le32_to_cpu(word0);
  6183. } else {
  6184. /* First read mbox status word */
  6185. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6186. spin_unlock_irqrestore(&phba->hbalock,
  6187. drvr_flag);
  6188. goto out_not_finished;
  6189. }
  6190. }
  6191. /* Read the HBA Host Attention Register */
  6192. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6193. spin_unlock_irqrestore(&phba->hbalock,
  6194. drvr_flag);
  6195. goto out_not_finished;
  6196. }
  6197. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6198. 1000) + jiffies;
  6199. i = 0;
  6200. /* Wait for command to complete */
  6201. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6202. (!(ha_copy & HA_MBATT) &&
  6203. (phba->link_state > LPFC_WARM_START))) {
  6204. if (time_after(jiffies, timeout)) {
  6205. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6206. spin_unlock_irqrestore(&phba->hbalock,
  6207. drvr_flag);
  6208. goto out_not_finished;
  6209. }
  6210. /* Check if we took a mbox interrupt while we were
  6211. polling */
  6212. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6213. && (evtctr != psli->slistat.mbox_event))
  6214. break;
  6215. if (i++ > 10) {
  6216. spin_unlock_irqrestore(&phba->hbalock,
  6217. drvr_flag);
  6218. msleep(1);
  6219. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6220. }
  6221. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6222. /* First copy command data */
  6223. word0 = *((uint32_t *)phba->mbox);
  6224. word0 = le32_to_cpu(word0);
  6225. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6226. MAILBOX_t *slimmb;
  6227. uint32_t slimword0;
  6228. /* Check real SLIM for any errors */
  6229. slimword0 = readl(phba->MBslimaddr);
  6230. slimmb = (MAILBOX_t *) & slimword0;
  6231. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6232. && slimmb->mbxStatus) {
  6233. psli->sli_flag &=
  6234. ~LPFC_SLI_ACTIVE;
  6235. word0 = slimword0;
  6236. }
  6237. }
  6238. } else {
  6239. /* First copy command data */
  6240. word0 = readl(phba->MBslimaddr);
  6241. }
  6242. /* Read the HBA Host Attention Register */
  6243. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6244. spin_unlock_irqrestore(&phba->hbalock,
  6245. drvr_flag);
  6246. goto out_not_finished;
  6247. }
  6248. }
  6249. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6250. /* copy results back to user */
  6251. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  6252. /* Copy the mailbox extension data */
  6253. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6254. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6255. pmbox->context2,
  6256. pmbox->out_ext_byte_len);
  6257. }
  6258. } else {
  6259. /* First copy command data */
  6260. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  6261. MAILBOX_CMD_SIZE);
  6262. /* Copy the mailbox extension data */
  6263. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6264. lpfc_memcpy_from_slim(pmbox->context2,
  6265. phba->MBslimaddr +
  6266. MAILBOX_HBA_EXT_OFFSET,
  6267. pmbox->out_ext_byte_len);
  6268. }
  6269. }
  6270. writel(HA_MBATT, phba->HAregaddr);
  6271. readl(phba->HAregaddr); /* flush */
  6272. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6273. status = mb->mbxStatus;
  6274. }
  6275. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6276. return status;
  6277. out_not_finished:
  6278. if (processing_queue) {
  6279. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6280. lpfc_mbox_cmpl_put(phba, pmbox);
  6281. }
  6282. return MBX_NOT_FINISHED;
  6283. }
  6284. /**
  6285. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6286. * @phba: Pointer to HBA context object.
  6287. *
  6288. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6289. * the driver internal pending mailbox queue. It will then try to wait out the
  6290. * possible outstanding mailbox command before return.
  6291. *
  6292. * Returns:
  6293. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6294. * the outstanding mailbox command timed out.
  6295. **/
  6296. static int
  6297. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6298. {
  6299. struct lpfc_sli *psli = &phba->sli;
  6300. int rc = 0;
  6301. unsigned long timeout = 0;
  6302. /* Mark the asynchronous mailbox command posting as blocked */
  6303. spin_lock_irq(&phba->hbalock);
  6304. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6305. /* Determine how long we might wait for the active mailbox
  6306. * command to be gracefully completed by firmware.
  6307. */
  6308. if (phba->sli.mbox_active)
  6309. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6310. phba->sli.mbox_active) *
  6311. 1000) + jiffies;
  6312. spin_unlock_irq(&phba->hbalock);
  6313. /* Wait for the outstnading mailbox command to complete */
  6314. while (phba->sli.mbox_active) {
  6315. /* Check active mailbox complete status every 2ms */
  6316. msleep(2);
  6317. if (time_after(jiffies, timeout)) {
  6318. /* Timeout, marked the outstanding cmd not complete */
  6319. rc = 1;
  6320. break;
  6321. }
  6322. }
  6323. /* Can not cleanly block async mailbox command, fails it */
  6324. if (rc) {
  6325. spin_lock_irq(&phba->hbalock);
  6326. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6327. spin_unlock_irq(&phba->hbalock);
  6328. }
  6329. return rc;
  6330. }
  6331. /**
  6332. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6333. * @phba: Pointer to HBA context object.
  6334. *
  6335. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6336. * commands from the driver internal pending mailbox queue. It makes sure
  6337. * that there is no outstanding mailbox command before resuming posting
  6338. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6339. * mailbox command, it will try to wait it out before resuming asynchronous
  6340. * mailbox command posting.
  6341. **/
  6342. static void
  6343. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6344. {
  6345. struct lpfc_sli *psli = &phba->sli;
  6346. spin_lock_irq(&phba->hbalock);
  6347. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6348. /* Asynchronous mailbox posting is not blocked, do nothing */
  6349. spin_unlock_irq(&phba->hbalock);
  6350. return;
  6351. }
  6352. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6353. * successful or timeout, after timing-out the outstanding mailbox
  6354. * command shall always be removed, so just unblock posting async
  6355. * mailbox command and resume
  6356. */
  6357. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6358. spin_unlock_irq(&phba->hbalock);
  6359. /* wake up worker thread to post asynchronlous mailbox command */
  6360. lpfc_worker_wake_up(phba);
  6361. }
  6362. /**
  6363. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6364. * @phba: Pointer to HBA context object.
  6365. * @mboxq: Pointer to mailbox object.
  6366. *
  6367. * The function posts a mailbox to the port. The mailbox is expected
  6368. * to be comletely filled in and ready for the port to operate on it.
  6369. * This routine executes a synchronous completion operation on the
  6370. * mailbox by polling for its completion.
  6371. *
  6372. * The caller must not be holding any locks when calling this routine.
  6373. *
  6374. * Returns:
  6375. * MBX_SUCCESS - mailbox posted successfully
  6376. * Any of the MBX error values.
  6377. **/
  6378. static int
  6379. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6380. {
  6381. int rc = MBX_SUCCESS;
  6382. unsigned long iflag;
  6383. uint32_t db_ready;
  6384. uint32_t mcqe_status;
  6385. uint32_t mbx_cmnd;
  6386. unsigned long timeout;
  6387. struct lpfc_sli *psli = &phba->sli;
  6388. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6389. struct lpfc_bmbx_create *mbox_rgn;
  6390. struct dma_address *dma_address;
  6391. struct lpfc_register bmbx_reg;
  6392. /*
  6393. * Only one mailbox can be active to the bootstrap mailbox region
  6394. * at a time and there is no queueing provided.
  6395. */
  6396. spin_lock_irqsave(&phba->hbalock, iflag);
  6397. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6398. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6399. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6400. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6401. "cannot issue Data: x%x x%x\n",
  6402. mboxq->vport ? mboxq->vport->vpi : 0,
  6403. mboxq->u.mb.mbxCommand,
  6404. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6405. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6406. psli->sli_flag, MBX_POLL);
  6407. return MBXERR_ERROR;
  6408. }
  6409. /* The server grabs the token and owns it until release */
  6410. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6411. phba->sli.mbox_active = mboxq;
  6412. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6413. /*
  6414. * Initialize the bootstrap memory region to avoid stale data areas
  6415. * in the mailbox post. Then copy the caller's mailbox contents to
  6416. * the bmbx mailbox region.
  6417. */
  6418. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6419. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6420. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6421. sizeof(struct lpfc_mqe));
  6422. /* Post the high mailbox dma address to the port and wait for ready. */
  6423. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6424. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6425. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6426. * 1000) + jiffies;
  6427. do {
  6428. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6429. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6430. if (!db_ready)
  6431. msleep(2);
  6432. if (time_after(jiffies, timeout)) {
  6433. rc = MBXERR_ERROR;
  6434. goto exit;
  6435. }
  6436. } while (!db_ready);
  6437. /* Post the low mailbox dma address to the port. */
  6438. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6439. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6440. * 1000) + jiffies;
  6441. do {
  6442. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6443. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6444. if (!db_ready)
  6445. msleep(2);
  6446. if (time_after(jiffies, timeout)) {
  6447. rc = MBXERR_ERROR;
  6448. goto exit;
  6449. }
  6450. } while (!db_ready);
  6451. /*
  6452. * Read the CQ to ensure the mailbox has completed.
  6453. * If so, update the mailbox status so that the upper layers
  6454. * can complete the request normally.
  6455. */
  6456. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6457. sizeof(struct lpfc_mqe));
  6458. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6459. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6460. sizeof(struct lpfc_mcqe));
  6461. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6462. /*
  6463. * When the CQE status indicates a failure and the mailbox status
  6464. * indicates success then copy the CQE status into the mailbox status
  6465. * (and prefix it with x4000).
  6466. */
  6467. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6468. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6469. bf_set(lpfc_mqe_status, mb,
  6470. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6471. rc = MBXERR_ERROR;
  6472. } else
  6473. lpfc_sli4_swap_str(phba, mboxq);
  6474. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6475. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6476. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6477. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6478. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6479. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6480. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6481. bf_get(lpfc_mqe_status, mb),
  6482. mb->un.mb_words[0], mb->un.mb_words[1],
  6483. mb->un.mb_words[2], mb->un.mb_words[3],
  6484. mb->un.mb_words[4], mb->un.mb_words[5],
  6485. mb->un.mb_words[6], mb->un.mb_words[7],
  6486. mb->un.mb_words[8], mb->un.mb_words[9],
  6487. mb->un.mb_words[10], mb->un.mb_words[11],
  6488. mb->un.mb_words[12], mboxq->mcqe.word0,
  6489. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6490. mboxq->mcqe.trailer);
  6491. exit:
  6492. /* We are holding the token, no needed for lock when release */
  6493. spin_lock_irqsave(&phba->hbalock, iflag);
  6494. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6495. phba->sli.mbox_active = NULL;
  6496. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6497. return rc;
  6498. }
  6499. /**
  6500. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6501. * @phba: Pointer to HBA context object.
  6502. * @pmbox: Pointer to mailbox object.
  6503. * @flag: Flag indicating how the mailbox need to be processed.
  6504. *
  6505. * This function is called by discovery code and HBA management code to submit
  6506. * a mailbox command to firmware with SLI-4 interface spec.
  6507. *
  6508. * Return codes the caller owns the mailbox command after the return of the
  6509. * function.
  6510. **/
  6511. static int
  6512. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6513. uint32_t flag)
  6514. {
  6515. struct lpfc_sli *psli = &phba->sli;
  6516. unsigned long iflags;
  6517. int rc;
  6518. /* dump from issue mailbox command if setup */
  6519. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6520. rc = lpfc_mbox_dev_check(phba);
  6521. if (unlikely(rc)) {
  6522. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6523. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6524. "cannot issue Data: x%x x%x\n",
  6525. mboxq->vport ? mboxq->vport->vpi : 0,
  6526. mboxq->u.mb.mbxCommand,
  6527. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6528. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6529. psli->sli_flag, flag);
  6530. goto out_not_finished;
  6531. }
  6532. /* Detect polling mode and jump to a handler */
  6533. if (!phba->sli4_hba.intr_enable) {
  6534. if (flag == MBX_POLL)
  6535. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6536. else
  6537. rc = -EIO;
  6538. if (rc != MBX_SUCCESS)
  6539. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6540. "(%d):2541 Mailbox command x%x "
  6541. "(x%x/x%x) failure: "
  6542. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6543. "Data: x%x x%x\n,",
  6544. mboxq->vport ? mboxq->vport->vpi : 0,
  6545. mboxq->u.mb.mbxCommand,
  6546. lpfc_sli_config_mbox_subsys_get(phba,
  6547. mboxq),
  6548. lpfc_sli_config_mbox_opcode_get(phba,
  6549. mboxq),
  6550. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6551. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6552. bf_get(lpfc_mcqe_ext_status,
  6553. &mboxq->mcqe),
  6554. psli->sli_flag, flag);
  6555. return rc;
  6556. } else if (flag == MBX_POLL) {
  6557. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6558. "(%d):2542 Try to issue mailbox command "
  6559. "x%x (x%x/x%x) synchronously ahead of async"
  6560. "mailbox command queue: x%x x%x\n",
  6561. mboxq->vport ? mboxq->vport->vpi : 0,
  6562. mboxq->u.mb.mbxCommand,
  6563. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6564. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6565. psli->sli_flag, flag);
  6566. /* Try to block the asynchronous mailbox posting */
  6567. rc = lpfc_sli4_async_mbox_block(phba);
  6568. if (!rc) {
  6569. /* Successfully blocked, now issue sync mbox cmd */
  6570. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6571. if (rc != MBX_SUCCESS)
  6572. lpfc_printf_log(phba, KERN_WARNING,
  6573. LOG_MBOX | LOG_SLI,
  6574. "(%d):2597 Sync Mailbox command "
  6575. "x%x (x%x/x%x) failure: "
  6576. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6577. "Data: x%x x%x\n,",
  6578. mboxq->vport ? mboxq->vport->vpi : 0,
  6579. mboxq->u.mb.mbxCommand,
  6580. lpfc_sli_config_mbox_subsys_get(phba,
  6581. mboxq),
  6582. lpfc_sli_config_mbox_opcode_get(phba,
  6583. mboxq),
  6584. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6585. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6586. bf_get(lpfc_mcqe_ext_status,
  6587. &mboxq->mcqe),
  6588. psli->sli_flag, flag);
  6589. /* Unblock the async mailbox posting afterward */
  6590. lpfc_sli4_async_mbox_unblock(phba);
  6591. }
  6592. return rc;
  6593. }
  6594. /* Now, interrupt mode asynchrous mailbox command */
  6595. rc = lpfc_mbox_cmd_check(phba, mboxq);
  6596. if (rc) {
  6597. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6598. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  6599. "cannot issue Data: x%x x%x\n",
  6600. mboxq->vport ? mboxq->vport->vpi : 0,
  6601. mboxq->u.mb.mbxCommand,
  6602. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6603. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6604. psli->sli_flag, flag);
  6605. goto out_not_finished;
  6606. }
  6607. /* Put the mailbox command to the driver internal FIFO */
  6608. psli->slistat.mbox_busy++;
  6609. spin_lock_irqsave(&phba->hbalock, iflags);
  6610. lpfc_mbox_put(phba, mboxq);
  6611. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6612. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6613. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  6614. "x%x (x%x/x%x) x%x x%x x%x\n",
  6615. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  6616. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  6617. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6618. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6619. phba->pport->port_state,
  6620. psli->sli_flag, MBX_NOWAIT);
  6621. /* Wake up worker thread to transport mailbox command from head */
  6622. lpfc_worker_wake_up(phba);
  6623. return MBX_BUSY;
  6624. out_not_finished:
  6625. return MBX_NOT_FINISHED;
  6626. }
  6627. /**
  6628. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  6629. * @phba: Pointer to HBA context object.
  6630. *
  6631. * This function is called by worker thread to send a mailbox command to
  6632. * SLI4 HBA firmware.
  6633. *
  6634. **/
  6635. int
  6636. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  6637. {
  6638. struct lpfc_sli *psli = &phba->sli;
  6639. LPFC_MBOXQ_t *mboxq;
  6640. int rc = MBX_SUCCESS;
  6641. unsigned long iflags;
  6642. struct lpfc_mqe *mqe;
  6643. uint32_t mbx_cmnd;
  6644. /* Check interrupt mode before post async mailbox command */
  6645. if (unlikely(!phba->sli4_hba.intr_enable))
  6646. return MBX_NOT_FINISHED;
  6647. /* Check for mailbox command service token */
  6648. spin_lock_irqsave(&phba->hbalock, iflags);
  6649. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6650. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6651. return MBX_NOT_FINISHED;
  6652. }
  6653. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6654. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6655. return MBX_NOT_FINISHED;
  6656. }
  6657. if (unlikely(phba->sli.mbox_active)) {
  6658. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6659. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6660. "0384 There is pending active mailbox cmd\n");
  6661. return MBX_NOT_FINISHED;
  6662. }
  6663. /* Take the mailbox command service token */
  6664. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6665. /* Get the next mailbox command from head of queue */
  6666. mboxq = lpfc_mbox_get(phba);
  6667. /* If no more mailbox command waiting for post, we're done */
  6668. if (!mboxq) {
  6669. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6670. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6671. return MBX_SUCCESS;
  6672. }
  6673. phba->sli.mbox_active = mboxq;
  6674. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6675. /* Check device readiness for posting mailbox command */
  6676. rc = lpfc_mbox_dev_check(phba);
  6677. if (unlikely(rc))
  6678. /* Driver clean routine will clean up pending mailbox */
  6679. goto out_not_finished;
  6680. /* Prepare the mbox command to be posted */
  6681. mqe = &mboxq->u.mqe;
  6682. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  6683. /* Start timer for the mbox_tmo and log some mailbox post messages */
  6684. mod_timer(&psli->mbox_tmo, (jiffies +
  6685. (HZ * lpfc_mbox_tmo_val(phba, mboxq))));
  6686. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6687. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  6688. "x%x x%x\n",
  6689. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6690. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6691. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6692. phba->pport->port_state, psli->sli_flag);
  6693. if (mbx_cmnd != MBX_HEARTBEAT) {
  6694. if (mboxq->vport) {
  6695. lpfc_debugfs_disc_trc(mboxq->vport,
  6696. LPFC_DISC_TRC_MBOX_VPORT,
  6697. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6698. mbx_cmnd, mqe->un.mb_words[0],
  6699. mqe->un.mb_words[1]);
  6700. } else {
  6701. lpfc_debugfs_disc_trc(phba->pport,
  6702. LPFC_DISC_TRC_MBOX,
  6703. "MBOX Send: cmd:x%x mb:x%x x%x",
  6704. mbx_cmnd, mqe->un.mb_words[0],
  6705. mqe->un.mb_words[1]);
  6706. }
  6707. }
  6708. psli->slistat.mbox_cmd++;
  6709. /* Post the mailbox command to the port */
  6710. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  6711. if (rc != MBX_SUCCESS) {
  6712. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6713. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  6714. "cannot issue Data: x%x x%x\n",
  6715. mboxq->vport ? mboxq->vport->vpi : 0,
  6716. mboxq->u.mb.mbxCommand,
  6717. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6718. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6719. psli->sli_flag, MBX_NOWAIT);
  6720. goto out_not_finished;
  6721. }
  6722. return rc;
  6723. out_not_finished:
  6724. spin_lock_irqsave(&phba->hbalock, iflags);
  6725. if (phba->sli.mbox_active) {
  6726. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6727. __lpfc_mbox_cmpl_put(phba, mboxq);
  6728. /* Release the token */
  6729. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6730. phba->sli.mbox_active = NULL;
  6731. }
  6732. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6733. return MBX_NOT_FINISHED;
  6734. }
  6735. /**
  6736. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  6737. * @phba: Pointer to HBA context object.
  6738. * @pmbox: Pointer to mailbox object.
  6739. * @flag: Flag indicating how the mailbox need to be processed.
  6740. *
  6741. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  6742. * the API jump table function pointer from the lpfc_hba struct.
  6743. *
  6744. * Return codes the caller owns the mailbox command after the return of the
  6745. * function.
  6746. **/
  6747. int
  6748. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  6749. {
  6750. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  6751. }
  6752. /**
  6753. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  6754. * @phba: The hba struct for which this call is being executed.
  6755. * @dev_grp: The HBA PCI-Device group number.
  6756. *
  6757. * This routine sets up the mbox interface API function jump table in @phba
  6758. * struct.
  6759. * Returns: 0 - success, -ENODEV - failure.
  6760. **/
  6761. int
  6762. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6763. {
  6764. switch (dev_grp) {
  6765. case LPFC_PCI_DEV_LP:
  6766. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  6767. phba->lpfc_sli_handle_slow_ring_event =
  6768. lpfc_sli_handle_slow_ring_event_s3;
  6769. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  6770. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  6771. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  6772. break;
  6773. case LPFC_PCI_DEV_OC:
  6774. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  6775. phba->lpfc_sli_handle_slow_ring_event =
  6776. lpfc_sli_handle_slow_ring_event_s4;
  6777. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  6778. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  6779. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  6780. break;
  6781. default:
  6782. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6783. "1420 Invalid HBA PCI-device group: 0x%x\n",
  6784. dev_grp);
  6785. return -ENODEV;
  6786. break;
  6787. }
  6788. return 0;
  6789. }
  6790. /**
  6791. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  6792. * @phba: Pointer to HBA context object.
  6793. * @pring: Pointer to driver SLI ring object.
  6794. * @piocb: Pointer to address of newly added command iocb.
  6795. *
  6796. * This function is called with hbalock held to add a command
  6797. * iocb to the txq when SLI layer cannot submit the command iocb
  6798. * to the ring.
  6799. **/
  6800. void
  6801. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6802. struct lpfc_iocbq *piocb)
  6803. {
  6804. /* Insert the caller's iocb in the txq tail for later processing. */
  6805. list_add_tail(&piocb->list, &pring->txq);
  6806. pring->txq_cnt++;
  6807. }
  6808. /**
  6809. * lpfc_sli_next_iocb - Get the next iocb in the txq
  6810. * @phba: Pointer to HBA context object.
  6811. * @pring: Pointer to driver SLI ring object.
  6812. * @piocb: Pointer to address of newly added command iocb.
  6813. *
  6814. * This function is called with hbalock held before a new
  6815. * iocb is submitted to the firmware. This function checks
  6816. * txq to flush the iocbs in txq to Firmware before
  6817. * submitting new iocbs to the Firmware.
  6818. * If there are iocbs in the txq which need to be submitted
  6819. * to firmware, lpfc_sli_next_iocb returns the first element
  6820. * of the txq after dequeuing it from txq.
  6821. * If there is no iocb in the txq then the function will return
  6822. * *piocb and *piocb is set to NULL. Caller needs to check
  6823. * *piocb to find if there are more commands in the txq.
  6824. **/
  6825. static struct lpfc_iocbq *
  6826. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6827. struct lpfc_iocbq **piocb)
  6828. {
  6829. struct lpfc_iocbq * nextiocb;
  6830. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  6831. if (!nextiocb) {
  6832. nextiocb = *piocb;
  6833. *piocb = NULL;
  6834. }
  6835. return nextiocb;
  6836. }
  6837. /**
  6838. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  6839. * @phba: Pointer to HBA context object.
  6840. * @ring_number: SLI ring number to issue iocb on.
  6841. * @piocb: Pointer to command iocb.
  6842. * @flag: Flag indicating if this command can be put into txq.
  6843. *
  6844. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  6845. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  6846. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  6847. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  6848. * this function allows only iocbs for posting buffers. This function finds
  6849. * next available slot in the command ring and posts the command to the
  6850. * available slot and writes the port attention register to request HBA start
  6851. * processing new iocb. If there is no slot available in the ring and
  6852. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  6853. * the function returns IOCB_BUSY.
  6854. *
  6855. * This function is called with hbalock held. The function will return success
  6856. * after it successfully submit the iocb to firmware or after adding to the
  6857. * txq.
  6858. **/
  6859. static int
  6860. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  6861. struct lpfc_iocbq *piocb, uint32_t flag)
  6862. {
  6863. struct lpfc_iocbq *nextiocb;
  6864. IOCB_t *iocb;
  6865. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6866. if (piocb->iocb_cmpl && (!piocb->vport) &&
  6867. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  6868. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  6869. lpfc_printf_log(phba, KERN_ERR,
  6870. LOG_SLI | LOG_VPORT,
  6871. "1807 IOCB x%x failed. No vport\n",
  6872. piocb->iocb.ulpCommand);
  6873. dump_stack();
  6874. return IOCB_ERROR;
  6875. }
  6876. /* If the PCI channel is in offline state, do not post iocbs. */
  6877. if (unlikely(pci_channel_offline(phba->pcidev)))
  6878. return IOCB_ERROR;
  6879. /* If HBA has a deferred error attention, fail the iocb. */
  6880. if (unlikely(phba->hba_flag & DEFER_ERATT))
  6881. return IOCB_ERROR;
  6882. /*
  6883. * We should never get an IOCB if we are in a < LINK_DOWN state
  6884. */
  6885. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  6886. return IOCB_ERROR;
  6887. /*
  6888. * Check to see if we are blocking IOCB processing because of a
  6889. * outstanding event.
  6890. */
  6891. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  6892. goto iocb_busy;
  6893. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  6894. /*
  6895. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  6896. * can be issued if the link is not up.
  6897. */
  6898. switch (piocb->iocb.ulpCommand) {
  6899. case CMD_GEN_REQUEST64_CR:
  6900. case CMD_GEN_REQUEST64_CX:
  6901. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  6902. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  6903. FC_RCTL_DD_UNSOL_CMD) ||
  6904. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  6905. MENLO_TRANSPORT_TYPE))
  6906. goto iocb_busy;
  6907. break;
  6908. case CMD_QUE_RING_BUF_CN:
  6909. case CMD_QUE_RING_BUF64_CN:
  6910. /*
  6911. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  6912. * completion, iocb_cmpl MUST be 0.
  6913. */
  6914. if (piocb->iocb_cmpl)
  6915. piocb->iocb_cmpl = NULL;
  6916. /*FALLTHROUGH*/
  6917. case CMD_CREATE_XRI_CR:
  6918. case CMD_CLOSE_XRI_CN:
  6919. case CMD_CLOSE_XRI_CX:
  6920. break;
  6921. default:
  6922. goto iocb_busy;
  6923. }
  6924. /*
  6925. * For FCP commands, we must be in a state where we can process link
  6926. * attention events.
  6927. */
  6928. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  6929. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  6930. goto iocb_busy;
  6931. }
  6932. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  6933. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  6934. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  6935. if (iocb)
  6936. lpfc_sli_update_ring(phba, pring);
  6937. else
  6938. lpfc_sli_update_full_ring(phba, pring);
  6939. if (!piocb)
  6940. return IOCB_SUCCESS;
  6941. goto out_busy;
  6942. iocb_busy:
  6943. pring->stats.iocb_cmd_delay++;
  6944. out_busy:
  6945. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6946. __lpfc_sli_ringtx_put(phba, pring, piocb);
  6947. return IOCB_SUCCESS;
  6948. }
  6949. return IOCB_BUSY;
  6950. }
  6951. /**
  6952. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  6953. * @phba: Pointer to HBA context object.
  6954. * @piocb: Pointer to command iocb.
  6955. * @sglq: Pointer to the scatter gather queue object.
  6956. *
  6957. * This routine converts the bpl or bde that is in the IOCB
  6958. * to a sgl list for the sli4 hardware. The physical address
  6959. * of the bpl/bde is converted back to a virtual address.
  6960. * If the IOCB contains a BPL then the list of BDE's is
  6961. * converted to sli4_sge's. If the IOCB contains a single
  6962. * BDE then it is converted to a single sli_sge.
  6963. * The IOCB is still in cpu endianess so the contents of
  6964. * the bpl can be used without byte swapping.
  6965. *
  6966. * Returns valid XRI = Success, NO_XRI = Failure.
  6967. **/
  6968. static uint16_t
  6969. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  6970. struct lpfc_sglq *sglq)
  6971. {
  6972. uint16_t xritag = NO_XRI;
  6973. struct ulp_bde64 *bpl = NULL;
  6974. struct ulp_bde64 bde;
  6975. struct sli4_sge *sgl = NULL;
  6976. struct lpfc_dmabuf *dmabuf;
  6977. IOCB_t *icmd;
  6978. int numBdes = 0;
  6979. int i = 0;
  6980. uint32_t offset = 0; /* accumulated offset in the sg request list */
  6981. int inbound = 0; /* number of sg reply entries inbound from firmware */
  6982. if (!piocbq || !sglq)
  6983. return xritag;
  6984. sgl = (struct sli4_sge *)sglq->sgl;
  6985. icmd = &piocbq->iocb;
  6986. if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  6987. return sglq->sli4_xritag;
  6988. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  6989. numBdes = icmd->un.genreq64.bdl.bdeSize /
  6990. sizeof(struct ulp_bde64);
  6991. /* The addrHigh and addrLow fields within the IOCB
  6992. * have not been byteswapped yet so there is no
  6993. * need to swap them back.
  6994. */
  6995. if (piocbq->context3)
  6996. dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
  6997. else
  6998. return xritag;
  6999. bpl = (struct ulp_bde64 *)dmabuf->virt;
  7000. if (!bpl)
  7001. return xritag;
  7002. for (i = 0; i < numBdes; i++) {
  7003. /* Should already be byte swapped. */
  7004. sgl->addr_hi = bpl->addrHigh;
  7005. sgl->addr_lo = bpl->addrLow;
  7006. sgl->word2 = le32_to_cpu(sgl->word2);
  7007. if ((i+1) == numBdes)
  7008. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7009. else
  7010. bf_set(lpfc_sli4_sge_last, sgl, 0);
  7011. /* swap the size field back to the cpu so we
  7012. * can assign it to the sgl.
  7013. */
  7014. bde.tus.w = le32_to_cpu(bpl->tus.w);
  7015. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  7016. /* The offsets in the sgl need to be accumulated
  7017. * separately for the request and reply lists.
  7018. * The request is always first, the reply follows.
  7019. */
  7020. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  7021. /* add up the reply sg entries */
  7022. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  7023. inbound++;
  7024. /* first inbound? reset the offset */
  7025. if (inbound == 1)
  7026. offset = 0;
  7027. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  7028. bf_set(lpfc_sli4_sge_type, sgl,
  7029. LPFC_SGE_TYPE_DATA);
  7030. offset += bde.tus.f.bdeSize;
  7031. }
  7032. sgl->word2 = cpu_to_le32(sgl->word2);
  7033. bpl++;
  7034. sgl++;
  7035. }
  7036. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  7037. /* The addrHigh and addrLow fields of the BDE have not
  7038. * been byteswapped yet so they need to be swapped
  7039. * before putting them in the sgl.
  7040. */
  7041. sgl->addr_hi =
  7042. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  7043. sgl->addr_lo =
  7044. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  7045. sgl->word2 = le32_to_cpu(sgl->word2);
  7046. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7047. sgl->word2 = cpu_to_le32(sgl->word2);
  7048. sgl->sge_len =
  7049. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  7050. }
  7051. return sglq->sli4_xritag;
  7052. }
  7053. /**
  7054. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  7055. * @phba: Pointer to HBA context object.
  7056. *
  7057. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  7058. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  7059. * held.
  7060. *
  7061. * Return: index into SLI4 fast-path FCP queue index.
  7062. **/
  7063. static uint32_t
  7064. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  7065. {
  7066. ++phba->fcp_qidx;
  7067. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  7068. phba->fcp_qidx = 0;
  7069. return phba->fcp_qidx;
  7070. }
  7071. /**
  7072. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  7073. * @phba: Pointer to HBA context object.
  7074. * @piocb: Pointer to command iocb.
  7075. * @wqe: Pointer to the work queue entry.
  7076. *
  7077. * This routine converts the iocb command to its Work Queue Entry
  7078. * equivalent. The wqe pointer should not have any fields set when
  7079. * this routine is called because it will memcpy over them.
  7080. * This routine does not set the CQ_ID or the WQEC bits in the
  7081. * wqe.
  7082. *
  7083. * Returns: 0 = Success, IOCB_ERROR = Failure.
  7084. **/
  7085. static int
  7086. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  7087. union lpfc_wqe *wqe)
  7088. {
  7089. uint32_t xmit_len = 0, total_len = 0;
  7090. uint8_t ct = 0;
  7091. uint32_t fip;
  7092. uint32_t abort_tag;
  7093. uint8_t command_type = ELS_COMMAND_NON_FIP;
  7094. uint8_t cmnd;
  7095. uint16_t xritag;
  7096. uint16_t abrt_iotag;
  7097. struct lpfc_iocbq *abrtiocbq;
  7098. struct ulp_bde64 *bpl = NULL;
  7099. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  7100. int numBdes, i;
  7101. struct ulp_bde64 bde;
  7102. struct lpfc_nodelist *ndlp;
  7103. uint32_t *pcmd;
  7104. uint32_t if_type;
  7105. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  7106. /* The fcp commands will set command type */
  7107. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7108. command_type = FCP_COMMAND;
  7109. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  7110. command_type = ELS_COMMAND_FIP;
  7111. else
  7112. command_type = ELS_COMMAND_NON_FIP;
  7113. /* Some of the fields are in the right position already */
  7114. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  7115. abort_tag = (uint32_t) iocbq->iotag;
  7116. xritag = iocbq->sli4_xritag;
  7117. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  7118. /* words0-2 bpl convert bde */
  7119. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7120. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7121. sizeof(struct ulp_bde64);
  7122. bpl = (struct ulp_bde64 *)
  7123. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  7124. if (!bpl)
  7125. return IOCB_ERROR;
  7126. /* Should already be byte swapped. */
  7127. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  7128. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  7129. /* swap the size field back to the cpu so we
  7130. * can assign it to the sgl.
  7131. */
  7132. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  7133. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  7134. total_len = 0;
  7135. for (i = 0; i < numBdes; i++) {
  7136. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7137. total_len += bde.tus.f.bdeSize;
  7138. }
  7139. } else
  7140. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  7141. iocbq->iocb.ulpIoTag = iocbq->iotag;
  7142. cmnd = iocbq->iocb.ulpCommand;
  7143. switch (iocbq->iocb.ulpCommand) {
  7144. case CMD_ELS_REQUEST64_CR:
  7145. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7146. if (!iocbq->iocb.ulpLe) {
  7147. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7148. "2007 Only Limited Edition cmd Format"
  7149. " supported 0x%x\n",
  7150. iocbq->iocb.ulpCommand);
  7151. return IOCB_ERROR;
  7152. }
  7153. wqe->els_req.payload_len = xmit_len;
  7154. /* Els_reguest64 has a TMO */
  7155. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  7156. iocbq->iocb.ulpTimeout);
  7157. /* Need a VF for word 4 set the vf bit*/
  7158. bf_set(els_req64_vf, &wqe->els_req, 0);
  7159. /* And a VFID for word 12 */
  7160. bf_set(els_req64_vfid, &wqe->els_req, 0);
  7161. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7162. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7163. iocbq->iocb.ulpContext);
  7164. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  7165. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  7166. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7167. if (command_type == ELS_COMMAND_FIP)
  7168. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7169. >> LPFC_FIP_ELS_ID_SHIFT);
  7170. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7171. iocbq->context2)->virt);
  7172. if_type = bf_get(lpfc_sli_intf_if_type,
  7173. &phba->sli4_hba.sli_intf);
  7174. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7175. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7176. *pcmd == ELS_CMD_SCR ||
  7177. *pcmd == ELS_CMD_FDISC ||
  7178. *pcmd == ELS_CMD_LOGO ||
  7179. *pcmd == ELS_CMD_PLOGI)) {
  7180. bf_set(els_req64_sp, &wqe->els_req, 1);
  7181. bf_set(els_req64_sid, &wqe->els_req,
  7182. iocbq->vport->fc_myDID);
  7183. if ((*pcmd == ELS_CMD_FLOGI) &&
  7184. !(phba->fc_topology ==
  7185. LPFC_TOPOLOGY_LOOP))
  7186. bf_set(els_req64_sid, &wqe->els_req, 0);
  7187. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7188. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7189. phba->vpi_ids[iocbq->vport->vpi]);
  7190. } else if (pcmd && iocbq->context1) {
  7191. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7192. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7193. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7194. }
  7195. }
  7196. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7197. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7198. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7199. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7200. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7201. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7202. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7203. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7204. break;
  7205. case CMD_XMIT_SEQUENCE64_CX:
  7206. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7207. iocbq->iocb.un.ulpWord[3]);
  7208. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7209. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7210. /* The entire sequence is transmitted for this IOCB */
  7211. xmit_len = total_len;
  7212. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7213. if (phba->link_flag & LS_LOOPBACK_MODE)
  7214. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  7215. case CMD_XMIT_SEQUENCE64_CR:
  7216. /* word3 iocb=io_tag32 wqe=reserved */
  7217. wqe->xmit_sequence.rsvd3 = 0;
  7218. /* word4 relative_offset memcpy */
  7219. /* word5 r_ctl/df_ctl memcpy */
  7220. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7221. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7222. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7223. LPFC_WQE_IOD_WRITE);
  7224. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7225. LPFC_WQE_LENLOC_WORD12);
  7226. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7227. wqe->xmit_sequence.xmit_len = xmit_len;
  7228. command_type = OTHER_COMMAND;
  7229. break;
  7230. case CMD_XMIT_BCAST64_CN:
  7231. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7232. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7233. /* word4 iocb=rsvd wqe=rsvd */
  7234. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7235. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7236. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7237. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7238. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7239. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7240. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7241. LPFC_WQE_LENLOC_WORD3);
  7242. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7243. break;
  7244. case CMD_FCP_IWRITE64_CR:
  7245. command_type = FCP_COMMAND_DATA_OUT;
  7246. /* word3 iocb=iotag wqe=payload_offset_len */
  7247. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7248. wqe->fcp_iwrite.payload_offset_len =
  7249. xmit_len + sizeof(struct fcp_rsp);
  7250. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7251. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7252. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7253. iocbq->iocb.ulpFCP2Rcvy);
  7254. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7255. /* Always open the exchange */
  7256. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  7257. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7258. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7259. LPFC_WQE_LENLOC_WORD4);
  7260. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  7261. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7262. if (iocbq->iocb_flag & LPFC_IO_DIF) {
  7263. iocbq->iocb_flag &= ~LPFC_IO_DIF;
  7264. bf_set(wqe_dif, &wqe->generic.wqe_com, 1);
  7265. }
  7266. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7267. break;
  7268. case CMD_FCP_IREAD64_CR:
  7269. /* word3 iocb=iotag wqe=payload_offset_len */
  7270. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7271. wqe->fcp_iread.payload_offset_len =
  7272. xmit_len + sizeof(struct fcp_rsp);
  7273. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7274. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7275. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7276. iocbq->iocb.ulpFCP2Rcvy);
  7277. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7278. /* Always open the exchange */
  7279. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  7280. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7281. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7282. LPFC_WQE_LENLOC_WORD4);
  7283. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  7284. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7285. if (iocbq->iocb_flag & LPFC_IO_DIF) {
  7286. iocbq->iocb_flag &= ~LPFC_IO_DIF;
  7287. bf_set(wqe_dif, &wqe->generic.wqe_com, 1);
  7288. }
  7289. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7290. break;
  7291. case CMD_FCP_ICMND64_CR:
  7292. /* word3 iocb=IO_TAG wqe=reserved */
  7293. wqe->fcp_icmd.rsrvd3 = 0;
  7294. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7295. /* Always open the exchange */
  7296. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  7297. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7298. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7299. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7300. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7301. LPFC_WQE_LENLOC_NONE);
  7302. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  7303. break;
  7304. case CMD_GEN_REQUEST64_CR:
  7305. /* For this command calculate the xmit length of the
  7306. * request bde.
  7307. */
  7308. xmit_len = 0;
  7309. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7310. sizeof(struct ulp_bde64);
  7311. for (i = 0; i < numBdes; i++) {
  7312. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7313. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7314. break;
  7315. xmit_len += bde.tus.f.bdeSize;
  7316. }
  7317. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7318. wqe->gen_req.request_payload_len = xmit_len;
  7319. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7320. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7321. /* word6 context tag copied in memcpy */
  7322. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7323. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7324. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7325. "2015 Invalid CT %x command 0x%x\n",
  7326. ct, iocbq->iocb.ulpCommand);
  7327. return IOCB_ERROR;
  7328. }
  7329. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7330. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7331. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7332. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7333. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7334. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7335. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7336. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7337. command_type = OTHER_COMMAND;
  7338. break;
  7339. case CMD_XMIT_ELS_RSP64_CX:
  7340. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7341. /* words0-2 BDE memcpy */
  7342. /* word3 iocb=iotag32 wqe=response_payload_len */
  7343. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7344. /* word4 */
  7345. wqe->xmit_els_rsp.word4 = 0;
  7346. /* word5 iocb=rsvd wge=did */
  7347. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7348. iocbq->iocb.un.xseq64.xmit_els_remoteID);
  7349. if_type = bf_get(lpfc_sli_intf_if_type,
  7350. &phba->sli4_hba.sli_intf);
  7351. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7352. if (iocbq->vport->fc_flag & FC_PT2PT) {
  7353. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7354. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7355. iocbq->vport->fc_myDID);
  7356. if (iocbq->vport->fc_myDID == Fabric_DID) {
  7357. bf_set(wqe_els_did,
  7358. &wqe->xmit_els_rsp.wqe_dest, 0);
  7359. }
  7360. }
  7361. }
  7362. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7363. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7364. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7365. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7366. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7367. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7368. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7369. phba->vpi_ids[iocbq->vport->vpi]);
  7370. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7371. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7372. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7373. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7374. LPFC_WQE_LENLOC_WORD3);
  7375. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7376. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7377. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7378. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7379. iocbq->context2)->virt);
  7380. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7381. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7382. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7383. iocbq->vport->fc_myDID);
  7384. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
  7385. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7386. phba->vpi_ids[phba->pport->vpi]);
  7387. }
  7388. command_type = OTHER_COMMAND;
  7389. break;
  7390. case CMD_CLOSE_XRI_CN:
  7391. case CMD_ABORT_XRI_CN:
  7392. case CMD_ABORT_XRI_CX:
  7393. /* words 0-2 memcpy should be 0 rserved */
  7394. /* port will send abts */
  7395. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7396. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7397. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7398. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7399. } else
  7400. fip = 0;
  7401. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7402. /*
  7403. * The link is down, or the command was ELS_FIP
  7404. * so the fw does not need to send abts
  7405. * on the wire.
  7406. */
  7407. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7408. else
  7409. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7410. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7411. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7412. wqe->abort_cmd.rsrvd5 = 0;
  7413. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7414. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7415. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7416. /*
  7417. * The abort handler will send us CMD_ABORT_XRI_CN or
  7418. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7419. */
  7420. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7421. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7422. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7423. LPFC_WQE_LENLOC_NONE);
  7424. cmnd = CMD_ABORT_XRI_CX;
  7425. command_type = OTHER_COMMAND;
  7426. xritag = 0;
  7427. break;
  7428. case CMD_XMIT_BLS_RSP64_CX:
  7429. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7430. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7431. * we re-construct this WQE here based on information in
  7432. * iocbq from scratch.
  7433. */
  7434. memset(wqe, 0, sizeof(union lpfc_wqe));
  7435. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7436. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7437. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7438. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7439. LPFC_ABTS_UNSOL_INT) {
  7440. /* ABTS sent by initiator to CT exchange, the
  7441. * RX_ID field will be filled with the newly
  7442. * allocated responder XRI.
  7443. */
  7444. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7445. iocbq->sli4_xritag);
  7446. } else {
  7447. /* ABTS sent by responder to CT exchange, the
  7448. * RX_ID field will be filled with the responder
  7449. * RX_ID from ABTS.
  7450. */
  7451. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7452. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7453. }
  7454. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7455. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7456. /* Use CT=VPI */
  7457. bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
  7458. ndlp->nlp_DID);
  7459. bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
  7460. iocbq->iocb.ulpContext);
  7461. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  7462. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7463. phba->vpi_ids[phba->pport->vpi]);
  7464. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7465. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7466. LPFC_WQE_LENLOC_NONE);
  7467. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7468. command_type = OTHER_COMMAND;
  7469. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7470. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7471. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7472. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7473. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7474. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7475. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7476. }
  7477. break;
  7478. case CMD_XRI_ABORTED_CX:
  7479. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7480. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7481. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7482. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7483. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7484. default:
  7485. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7486. "2014 Invalid command 0x%x\n",
  7487. iocbq->iocb.ulpCommand);
  7488. return IOCB_ERROR;
  7489. break;
  7490. }
  7491. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7492. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7493. wqe->generic.wqe_com.abort_tag = abort_tag;
  7494. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  7495. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  7496. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  7497. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  7498. return 0;
  7499. }
  7500. /**
  7501. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  7502. * @phba: Pointer to HBA context object.
  7503. * @ring_number: SLI ring number to issue iocb on.
  7504. * @piocb: Pointer to command iocb.
  7505. * @flag: Flag indicating if this command can be put into txq.
  7506. *
  7507. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  7508. * an iocb command to an HBA with SLI-4 interface spec.
  7509. *
  7510. * This function is called with hbalock held. The function will return success
  7511. * after it successfully submit the iocb to firmware or after adding to the
  7512. * txq.
  7513. **/
  7514. static int
  7515. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  7516. struct lpfc_iocbq *piocb, uint32_t flag)
  7517. {
  7518. struct lpfc_sglq *sglq;
  7519. union lpfc_wqe wqe;
  7520. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7521. if (piocb->sli4_xritag == NO_XRI) {
  7522. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  7523. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  7524. sglq = NULL;
  7525. else {
  7526. if (pring->txq_cnt) {
  7527. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7528. __lpfc_sli_ringtx_put(phba,
  7529. pring, piocb);
  7530. return IOCB_SUCCESS;
  7531. } else {
  7532. return IOCB_BUSY;
  7533. }
  7534. } else {
  7535. sglq = __lpfc_sli_get_sglq(phba, piocb);
  7536. if (!sglq) {
  7537. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7538. __lpfc_sli_ringtx_put(phba,
  7539. pring,
  7540. piocb);
  7541. return IOCB_SUCCESS;
  7542. } else
  7543. return IOCB_BUSY;
  7544. }
  7545. }
  7546. }
  7547. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  7548. /* These IO's already have an XRI and a mapped sgl. */
  7549. sglq = NULL;
  7550. } else {
  7551. /*
  7552. * This is a continuation of a commandi,(CX) so this
  7553. * sglq is on the active list
  7554. */
  7555. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  7556. if (!sglq)
  7557. return IOCB_ERROR;
  7558. }
  7559. if (sglq) {
  7560. piocb->sli4_lxritag = sglq->sli4_lxritag;
  7561. piocb->sli4_xritag = sglq->sli4_xritag;
  7562. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  7563. return IOCB_ERROR;
  7564. }
  7565. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  7566. return IOCB_ERROR;
  7567. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  7568. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  7569. /*
  7570. * For FCP command IOCB, get a new WQ index to distribute
  7571. * WQE across the WQsr. On the other hand, for abort IOCB,
  7572. * it carries the same WQ index to the original command
  7573. * IOCB.
  7574. */
  7575. if (piocb->iocb_flag & LPFC_IO_FCP)
  7576. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  7577. if (unlikely(!phba->sli4_hba.fcp_wq))
  7578. return IOCB_ERROR;
  7579. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  7580. &wqe))
  7581. return IOCB_ERROR;
  7582. } else {
  7583. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  7584. return IOCB_ERROR;
  7585. }
  7586. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  7587. return 0;
  7588. }
  7589. /**
  7590. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  7591. *
  7592. * This routine wraps the actual lockless version for issusing IOCB function
  7593. * pointer from the lpfc_hba struct.
  7594. *
  7595. * Return codes:
  7596. * IOCB_ERROR - Error
  7597. * IOCB_SUCCESS - Success
  7598. * IOCB_BUSY - Busy
  7599. **/
  7600. int
  7601. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7602. struct lpfc_iocbq *piocb, uint32_t flag)
  7603. {
  7604. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7605. }
  7606. /**
  7607. * lpfc_sli_api_table_setup - Set up sli api function jump table
  7608. * @phba: The hba struct for which this call is being executed.
  7609. * @dev_grp: The HBA PCI-Device group number.
  7610. *
  7611. * This routine sets up the SLI interface API function jump table in @phba
  7612. * struct.
  7613. * Returns: 0 - success, -ENODEV - failure.
  7614. **/
  7615. int
  7616. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7617. {
  7618. switch (dev_grp) {
  7619. case LPFC_PCI_DEV_LP:
  7620. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  7621. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  7622. break;
  7623. case LPFC_PCI_DEV_OC:
  7624. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  7625. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  7626. break;
  7627. default:
  7628. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7629. "1419 Invalid HBA PCI-device group: 0x%x\n",
  7630. dev_grp);
  7631. return -ENODEV;
  7632. break;
  7633. }
  7634. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  7635. return 0;
  7636. }
  7637. /**
  7638. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  7639. * @phba: Pointer to HBA context object.
  7640. * @pring: Pointer to driver SLI ring object.
  7641. * @piocb: Pointer to command iocb.
  7642. * @flag: Flag indicating if this command can be put into txq.
  7643. *
  7644. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  7645. * function. This function gets the hbalock and calls
  7646. * __lpfc_sli_issue_iocb function and will return the error returned
  7647. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  7648. * functions which do not hold hbalock.
  7649. **/
  7650. int
  7651. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7652. struct lpfc_iocbq *piocb, uint32_t flag)
  7653. {
  7654. unsigned long iflags;
  7655. int rc;
  7656. spin_lock_irqsave(&phba->hbalock, iflags);
  7657. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7658. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7659. return rc;
  7660. }
  7661. /**
  7662. * lpfc_extra_ring_setup - Extra ring setup function
  7663. * @phba: Pointer to HBA context object.
  7664. *
  7665. * This function is called while driver attaches with the
  7666. * HBA to setup the extra ring. The extra ring is used
  7667. * only when driver needs to support target mode functionality
  7668. * or IP over FC functionalities.
  7669. *
  7670. * This function is called with no lock held.
  7671. **/
  7672. static int
  7673. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  7674. {
  7675. struct lpfc_sli *psli;
  7676. struct lpfc_sli_ring *pring;
  7677. psli = &phba->sli;
  7678. /* Adjust cmd/rsp ring iocb entries more evenly */
  7679. /* Take some away from the FCP ring */
  7680. pring = &psli->ring[psli->fcp_ring];
  7681. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7682. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7683. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7684. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7685. /* and give them to the extra ring */
  7686. pring = &psli->ring[psli->extra_ring];
  7687. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7688. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7689. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7690. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7691. /* Setup default profile for this ring */
  7692. pring->iotag_max = 4096;
  7693. pring->num_mask = 1;
  7694. pring->prt[0].profile = 0; /* Mask 0 */
  7695. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  7696. pring->prt[0].type = phba->cfg_multi_ring_type;
  7697. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  7698. return 0;
  7699. }
  7700. /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS.
  7701. * @vport: pointer to virtual port object.
  7702. * @ndlp: nodelist pointer for the impacted rport.
  7703. *
  7704. * The driver calls this routine in response to a XRI ABORT CQE
  7705. * event from the port. In this event, the driver is required to
  7706. * recover its login to the rport even though its login may be valid
  7707. * from the driver's perspective. The failed ABTS notice from the
  7708. * port indicates the rport is not responding.
  7709. */
  7710. static void
  7711. lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
  7712. struct lpfc_nodelist *ndlp)
  7713. {
  7714. struct Scsi_Host *shost;
  7715. struct lpfc_hba *phba;
  7716. unsigned long flags = 0;
  7717. shost = lpfc_shost_from_vport(vport);
  7718. phba = vport->phba;
  7719. if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
  7720. lpfc_printf_log(phba, KERN_INFO,
  7721. LOG_SLI, "3093 No rport recovery needed. "
  7722. "rport in state 0x%x\n",
  7723. ndlp->nlp_state);
  7724. return;
  7725. }
  7726. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7727. "3094 Start rport recovery on shost id 0x%x "
  7728. "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
  7729. "flags 0x%x\n",
  7730. shost->host_no, ndlp->nlp_DID,
  7731. vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
  7732. ndlp->nlp_flag);
  7733. /*
  7734. * The rport is not responding. Don't attempt ADISC recovery.
  7735. * Remove the FCP-2 flag to force a PLOGI.
  7736. */
  7737. spin_lock_irqsave(shost->host_lock, flags);
  7738. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  7739. spin_unlock_irqrestore(shost->host_lock, flags);
  7740. lpfc_disc_state_machine(vport, ndlp, NULL,
  7741. NLP_EVT_DEVICE_RECOVERY);
  7742. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  7743. spin_lock_irqsave(shost->host_lock, flags);
  7744. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  7745. spin_unlock_irqrestore(shost->host_lock, flags);
  7746. lpfc_disc_start(vport);
  7747. }
  7748. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  7749. * @phba: Pointer to HBA context object.
  7750. * @iocbq: Pointer to iocb object.
  7751. *
  7752. * The async_event handler calls this routine when it receives
  7753. * an ASYNC_STATUS_CN event from the port. The port generates
  7754. * this event when an Abort Sequence request to an rport fails
  7755. * twice in succession. The abort could be originated by the
  7756. * driver or by the port. The ABTS could have been for an ELS
  7757. * or FCP IO. The port only generates this event when an ABTS
  7758. * fails to complete after one retry.
  7759. */
  7760. static void
  7761. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  7762. struct lpfc_iocbq *iocbq)
  7763. {
  7764. struct lpfc_nodelist *ndlp = NULL;
  7765. uint16_t rpi = 0, vpi = 0;
  7766. struct lpfc_vport *vport = NULL;
  7767. /* The rpi in the ulpContext is vport-sensitive. */
  7768. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  7769. rpi = iocbq->iocb.ulpContext;
  7770. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7771. "3092 Port generated ABTS async event "
  7772. "on vpi %d rpi %d status 0x%x\n",
  7773. vpi, rpi, iocbq->iocb.ulpStatus);
  7774. vport = lpfc_find_vport_by_vpid(phba, vpi);
  7775. if (!vport)
  7776. goto err_exit;
  7777. ndlp = lpfc_findnode_rpi(vport, rpi);
  7778. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  7779. goto err_exit;
  7780. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  7781. lpfc_sli_abts_recover_port(vport, ndlp);
  7782. return;
  7783. err_exit:
  7784. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7785. "3095 Event Context not found, no "
  7786. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  7787. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  7788. vpi, rpi);
  7789. }
  7790. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  7791. * @phba: pointer to HBA context object.
  7792. * @ndlp: nodelist pointer for the impacted rport.
  7793. * @axri: pointer to the wcqe containing the failed exchange.
  7794. *
  7795. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  7796. * port. The port generates this event when an abort exchange request to an
  7797. * rport fails twice in succession with no reply. The abort could be originated
  7798. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  7799. */
  7800. void
  7801. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  7802. struct lpfc_nodelist *ndlp,
  7803. struct sli4_wcqe_xri_aborted *axri)
  7804. {
  7805. struct lpfc_vport *vport;
  7806. uint32_t ext_status = 0;
  7807. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  7808. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7809. "3115 Node Context not found, driver "
  7810. "ignoring abts err event\n");
  7811. return;
  7812. }
  7813. vport = ndlp->vport;
  7814. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7815. "3116 Port generated FCP XRI ABORT event on "
  7816. "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
  7817. ndlp->vport->vpi, ndlp->nlp_rpi,
  7818. bf_get(lpfc_wcqe_xa_xri, axri),
  7819. bf_get(lpfc_wcqe_xa_status, axri),
  7820. axri->parameter);
  7821. /*
  7822. * Catch the ABTS protocol failure case. Older OCe FW releases returned
  7823. * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
  7824. * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
  7825. */
  7826. ext_status = axri->parameter & WCQE_PARAM_MASK;
  7827. if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
  7828. ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
  7829. lpfc_sli_abts_recover_port(vport, ndlp);
  7830. }
  7831. /**
  7832. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  7833. * @phba: Pointer to HBA context object.
  7834. * @pring: Pointer to driver SLI ring object.
  7835. * @iocbq: Pointer to iocb object.
  7836. *
  7837. * This function is called by the slow ring event handler
  7838. * function when there is an ASYNC event iocb in the ring.
  7839. * This function is called with no lock held.
  7840. * Currently this function handles only temperature related
  7841. * ASYNC events. The function decodes the temperature sensor
  7842. * event message and posts events for the management applications.
  7843. **/
  7844. static void
  7845. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  7846. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  7847. {
  7848. IOCB_t *icmd;
  7849. uint16_t evt_code;
  7850. struct temp_event temp_event_data;
  7851. struct Scsi_Host *shost;
  7852. uint32_t *iocb_w;
  7853. icmd = &iocbq->iocb;
  7854. evt_code = icmd->un.asyncstat.evt_code;
  7855. switch (evt_code) {
  7856. case ASYNC_TEMP_WARN:
  7857. case ASYNC_TEMP_SAFE:
  7858. temp_event_data.data = (uint32_t) icmd->ulpContext;
  7859. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  7860. if (evt_code == ASYNC_TEMP_WARN) {
  7861. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  7862. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7863. "0347 Adapter is very hot, please take "
  7864. "corrective action. temperature : %d Celsius\n",
  7865. (uint32_t) icmd->ulpContext);
  7866. } else {
  7867. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  7868. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7869. "0340 Adapter temperature is OK now. "
  7870. "temperature : %d Celsius\n",
  7871. (uint32_t) icmd->ulpContext);
  7872. }
  7873. /* Send temperature change event to applications */
  7874. shost = lpfc_shost_from_vport(phba->pport);
  7875. fc_host_post_vendor_event(shost, fc_get_event_number(),
  7876. sizeof(temp_event_data), (char *) &temp_event_data,
  7877. LPFC_NL_VENDOR_ID);
  7878. break;
  7879. case ASYNC_STATUS_CN:
  7880. lpfc_sli_abts_err_handler(phba, iocbq);
  7881. break;
  7882. default:
  7883. iocb_w = (uint32_t *) icmd;
  7884. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7885. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  7886. " evt_code 0x%x\n"
  7887. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  7888. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  7889. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  7890. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  7891. pring->ringno, icmd->un.asyncstat.evt_code,
  7892. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  7893. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  7894. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  7895. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  7896. break;
  7897. }
  7898. }
  7899. /**
  7900. * lpfc_sli_setup - SLI ring setup function
  7901. * @phba: Pointer to HBA context object.
  7902. *
  7903. * lpfc_sli_setup sets up rings of the SLI interface with
  7904. * number of iocbs per ring and iotags. This function is
  7905. * called while driver attach to the HBA and before the
  7906. * interrupts are enabled. So there is no need for locking.
  7907. *
  7908. * This function always returns 0.
  7909. **/
  7910. int
  7911. lpfc_sli_setup(struct lpfc_hba *phba)
  7912. {
  7913. int i, totiocbsize = 0;
  7914. struct lpfc_sli *psli = &phba->sli;
  7915. struct lpfc_sli_ring *pring;
  7916. psli->num_rings = MAX_CONFIGURED_RINGS;
  7917. psli->sli_flag = 0;
  7918. psli->fcp_ring = LPFC_FCP_RING;
  7919. psli->next_ring = LPFC_FCP_NEXT_RING;
  7920. psli->extra_ring = LPFC_EXTRA_RING;
  7921. psli->iocbq_lookup = NULL;
  7922. psli->iocbq_lookup_len = 0;
  7923. psli->last_iotag = 0;
  7924. for (i = 0; i < psli->num_rings; i++) {
  7925. pring = &psli->ring[i];
  7926. switch (i) {
  7927. case LPFC_FCP_RING: /* ring 0 - FCP */
  7928. /* numCiocb and numRiocb are used in config_port */
  7929. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  7930. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  7931. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7932. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7933. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7934. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7935. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7936. SLI3_IOCB_CMD_SIZE :
  7937. SLI2_IOCB_CMD_SIZE;
  7938. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7939. SLI3_IOCB_RSP_SIZE :
  7940. SLI2_IOCB_RSP_SIZE;
  7941. pring->iotag_ctr = 0;
  7942. pring->iotag_max =
  7943. (phba->cfg_hba_queue_depth * 2);
  7944. pring->fast_iotag = pring->iotag_max;
  7945. pring->num_mask = 0;
  7946. break;
  7947. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  7948. /* numCiocb and numRiocb are used in config_port */
  7949. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  7950. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  7951. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7952. SLI3_IOCB_CMD_SIZE :
  7953. SLI2_IOCB_CMD_SIZE;
  7954. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7955. SLI3_IOCB_RSP_SIZE :
  7956. SLI2_IOCB_RSP_SIZE;
  7957. pring->iotag_max = phba->cfg_hba_queue_depth;
  7958. pring->num_mask = 0;
  7959. break;
  7960. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  7961. /* numCiocb and numRiocb are used in config_port */
  7962. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  7963. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  7964. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7965. SLI3_IOCB_CMD_SIZE :
  7966. SLI2_IOCB_CMD_SIZE;
  7967. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7968. SLI3_IOCB_RSP_SIZE :
  7969. SLI2_IOCB_RSP_SIZE;
  7970. pring->fast_iotag = 0;
  7971. pring->iotag_ctr = 0;
  7972. pring->iotag_max = 4096;
  7973. pring->lpfc_sli_rcv_async_status =
  7974. lpfc_sli_async_event_handler;
  7975. pring->num_mask = LPFC_MAX_RING_MASK;
  7976. pring->prt[0].profile = 0; /* Mask 0 */
  7977. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  7978. pring->prt[0].type = FC_TYPE_ELS;
  7979. pring->prt[0].lpfc_sli_rcv_unsol_event =
  7980. lpfc_els_unsol_event;
  7981. pring->prt[1].profile = 0; /* Mask 1 */
  7982. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  7983. pring->prt[1].type = FC_TYPE_ELS;
  7984. pring->prt[1].lpfc_sli_rcv_unsol_event =
  7985. lpfc_els_unsol_event;
  7986. pring->prt[2].profile = 0; /* Mask 2 */
  7987. /* NameServer Inquiry */
  7988. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  7989. /* NameServer */
  7990. pring->prt[2].type = FC_TYPE_CT;
  7991. pring->prt[2].lpfc_sli_rcv_unsol_event =
  7992. lpfc_ct_unsol_event;
  7993. pring->prt[3].profile = 0; /* Mask 3 */
  7994. /* NameServer response */
  7995. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  7996. /* NameServer */
  7997. pring->prt[3].type = FC_TYPE_CT;
  7998. pring->prt[3].lpfc_sli_rcv_unsol_event =
  7999. lpfc_ct_unsol_event;
  8000. /* abort unsolicited sequence */
  8001. pring->prt[4].profile = 0; /* Mask 4 */
  8002. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  8003. pring->prt[4].type = FC_TYPE_BLS;
  8004. pring->prt[4].lpfc_sli_rcv_unsol_event =
  8005. lpfc_sli4_ct_abort_unsol_event;
  8006. break;
  8007. }
  8008. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  8009. (pring->numRiocb * pring->sizeRiocb);
  8010. }
  8011. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  8012. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  8013. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  8014. "SLI2 SLIM Data: x%x x%lx\n",
  8015. phba->brd_no, totiocbsize,
  8016. (unsigned long) MAX_SLIM_IOCB_SIZE);
  8017. }
  8018. if (phba->cfg_multi_ring_support == 2)
  8019. lpfc_extra_ring_setup(phba);
  8020. return 0;
  8021. }
  8022. /**
  8023. * lpfc_sli_queue_setup - Queue initialization function
  8024. * @phba: Pointer to HBA context object.
  8025. *
  8026. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  8027. * ring. This function also initializes ring indices of each ring.
  8028. * This function is called during the initialization of the SLI
  8029. * interface of an HBA.
  8030. * This function is called with no lock held and always returns
  8031. * 1.
  8032. **/
  8033. int
  8034. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  8035. {
  8036. struct lpfc_sli *psli;
  8037. struct lpfc_sli_ring *pring;
  8038. int i;
  8039. psli = &phba->sli;
  8040. spin_lock_irq(&phba->hbalock);
  8041. INIT_LIST_HEAD(&psli->mboxq);
  8042. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  8043. /* Initialize list headers for txq and txcmplq as double linked lists */
  8044. for (i = 0; i < psli->num_rings; i++) {
  8045. pring = &psli->ring[i];
  8046. pring->ringno = i;
  8047. pring->next_cmdidx = 0;
  8048. pring->local_getidx = 0;
  8049. pring->cmdidx = 0;
  8050. INIT_LIST_HEAD(&pring->txq);
  8051. INIT_LIST_HEAD(&pring->txcmplq);
  8052. INIT_LIST_HEAD(&pring->iocb_continueq);
  8053. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  8054. INIT_LIST_HEAD(&pring->postbufq);
  8055. }
  8056. spin_unlock_irq(&phba->hbalock);
  8057. return 1;
  8058. }
  8059. /**
  8060. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  8061. * @phba: Pointer to HBA context object.
  8062. *
  8063. * This routine flushes the mailbox command subsystem. It will unconditionally
  8064. * flush all the mailbox commands in the three possible stages in the mailbox
  8065. * command sub-system: pending mailbox command queue; the outstanding mailbox
  8066. * command; and completed mailbox command queue. It is caller's responsibility
  8067. * to make sure that the driver is in the proper state to flush the mailbox
  8068. * command sub-system. Namely, the posting of mailbox commands into the
  8069. * pending mailbox command queue from the various clients must be stopped;
  8070. * either the HBA is in a state that it will never works on the outstanding
  8071. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  8072. * mailbox command has been completed.
  8073. **/
  8074. static void
  8075. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  8076. {
  8077. LIST_HEAD(completions);
  8078. struct lpfc_sli *psli = &phba->sli;
  8079. LPFC_MBOXQ_t *pmb;
  8080. unsigned long iflag;
  8081. /* Flush all the mailbox commands in the mbox system */
  8082. spin_lock_irqsave(&phba->hbalock, iflag);
  8083. /* The pending mailbox command queue */
  8084. list_splice_init(&phba->sli.mboxq, &completions);
  8085. /* The outstanding active mailbox command */
  8086. if (psli->mbox_active) {
  8087. list_add_tail(&psli->mbox_active->list, &completions);
  8088. psli->mbox_active = NULL;
  8089. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8090. }
  8091. /* The completed mailbox command queue */
  8092. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  8093. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8094. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  8095. while (!list_empty(&completions)) {
  8096. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  8097. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8098. if (pmb->mbox_cmpl)
  8099. pmb->mbox_cmpl(phba, pmb);
  8100. }
  8101. }
  8102. /**
  8103. * lpfc_sli_host_down - Vport cleanup function
  8104. * @vport: Pointer to virtual port object.
  8105. *
  8106. * lpfc_sli_host_down is called to clean up the resources
  8107. * associated with a vport before destroying virtual
  8108. * port data structures.
  8109. * This function does following operations:
  8110. * - Free discovery resources associated with this virtual
  8111. * port.
  8112. * - Free iocbs associated with this virtual port in
  8113. * the txq.
  8114. * - Send abort for all iocb commands associated with this
  8115. * vport in txcmplq.
  8116. *
  8117. * This function is called with no lock held and always returns 1.
  8118. **/
  8119. int
  8120. lpfc_sli_host_down(struct lpfc_vport *vport)
  8121. {
  8122. LIST_HEAD(completions);
  8123. struct lpfc_hba *phba = vport->phba;
  8124. struct lpfc_sli *psli = &phba->sli;
  8125. struct lpfc_sli_ring *pring;
  8126. struct lpfc_iocbq *iocb, *next_iocb;
  8127. int i;
  8128. unsigned long flags = 0;
  8129. uint16_t prev_pring_flag;
  8130. lpfc_cleanup_discovery_resources(vport);
  8131. spin_lock_irqsave(&phba->hbalock, flags);
  8132. for (i = 0; i < psli->num_rings; i++) {
  8133. pring = &psli->ring[i];
  8134. prev_pring_flag = pring->flag;
  8135. /* Only slow rings */
  8136. if (pring->ringno == LPFC_ELS_RING) {
  8137. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8138. /* Set the lpfc data pending flag */
  8139. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8140. }
  8141. /*
  8142. * Error everything on the txq since these iocbs have not been
  8143. * given to the FW yet.
  8144. */
  8145. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  8146. if (iocb->vport != vport)
  8147. continue;
  8148. list_move_tail(&iocb->list, &completions);
  8149. pring->txq_cnt--;
  8150. }
  8151. /* Next issue ABTS for everything on the txcmplq */
  8152. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  8153. list) {
  8154. if (iocb->vport != vport)
  8155. continue;
  8156. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  8157. }
  8158. pring->flag = prev_pring_flag;
  8159. }
  8160. spin_unlock_irqrestore(&phba->hbalock, flags);
  8161. /* Cancel all the IOCBs from the completions list */
  8162. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8163. IOERR_SLI_DOWN);
  8164. return 1;
  8165. }
  8166. /**
  8167. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  8168. * @phba: Pointer to HBA context object.
  8169. *
  8170. * This function cleans up all iocb, buffers, mailbox commands
  8171. * while shutting down the HBA. This function is called with no
  8172. * lock held and always returns 1.
  8173. * This function does the following to cleanup driver resources:
  8174. * - Free discovery resources for each virtual port
  8175. * - Cleanup any pending fabric iocbs
  8176. * - Iterate through the iocb txq and free each entry
  8177. * in the list.
  8178. * - Free up any buffer posted to the HBA
  8179. * - Free mailbox commands in the mailbox queue.
  8180. **/
  8181. int
  8182. lpfc_sli_hba_down(struct lpfc_hba *phba)
  8183. {
  8184. LIST_HEAD(completions);
  8185. struct lpfc_sli *psli = &phba->sli;
  8186. struct lpfc_sli_ring *pring;
  8187. struct lpfc_dmabuf *buf_ptr;
  8188. unsigned long flags = 0;
  8189. int i;
  8190. /* Shutdown the mailbox command sub-system */
  8191. lpfc_sli_mbox_sys_shutdown(phba);
  8192. lpfc_hba_down_prep(phba);
  8193. lpfc_fabric_abort_hba(phba);
  8194. spin_lock_irqsave(&phba->hbalock, flags);
  8195. for (i = 0; i < psli->num_rings; i++) {
  8196. pring = &psli->ring[i];
  8197. /* Only slow rings */
  8198. if (pring->ringno == LPFC_ELS_RING) {
  8199. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8200. /* Set the lpfc data pending flag */
  8201. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8202. }
  8203. /*
  8204. * Error everything on the txq since these iocbs have not been
  8205. * given to the FW yet.
  8206. */
  8207. list_splice_init(&pring->txq, &completions);
  8208. pring->txq_cnt = 0;
  8209. }
  8210. spin_unlock_irqrestore(&phba->hbalock, flags);
  8211. /* Cancel all the IOCBs from the completions list */
  8212. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8213. IOERR_SLI_DOWN);
  8214. spin_lock_irqsave(&phba->hbalock, flags);
  8215. list_splice_init(&phba->elsbuf, &completions);
  8216. phba->elsbuf_cnt = 0;
  8217. phba->elsbuf_prev_cnt = 0;
  8218. spin_unlock_irqrestore(&phba->hbalock, flags);
  8219. while (!list_empty(&completions)) {
  8220. list_remove_head(&completions, buf_ptr,
  8221. struct lpfc_dmabuf, list);
  8222. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8223. kfree(buf_ptr);
  8224. }
  8225. /* Return any active mbox cmds */
  8226. del_timer_sync(&psli->mbox_tmo);
  8227. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8228. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8229. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8230. return 1;
  8231. }
  8232. /**
  8233. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8234. * @srcp: Source memory pointer.
  8235. * @destp: Destination memory pointer.
  8236. * @cnt: Number of words required to be copied.
  8237. *
  8238. * This function is used for copying data between driver memory
  8239. * and the SLI memory. This function also changes the endianness
  8240. * of each word if native endianness is different from SLI
  8241. * endianness. This function can be called with or without
  8242. * lock.
  8243. **/
  8244. void
  8245. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8246. {
  8247. uint32_t *src = srcp;
  8248. uint32_t *dest = destp;
  8249. uint32_t ldata;
  8250. int i;
  8251. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8252. ldata = *src;
  8253. ldata = le32_to_cpu(ldata);
  8254. *dest = ldata;
  8255. src++;
  8256. dest++;
  8257. }
  8258. }
  8259. /**
  8260. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8261. * @srcp: Source memory pointer.
  8262. * @destp: Destination memory pointer.
  8263. * @cnt: Number of words required to be copied.
  8264. *
  8265. * This function is used for copying data between a data structure
  8266. * with big endian representation to local endianness.
  8267. * This function can be called with or without lock.
  8268. **/
  8269. void
  8270. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8271. {
  8272. uint32_t *src = srcp;
  8273. uint32_t *dest = destp;
  8274. uint32_t ldata;
  8275. int i;
  8276. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8277. ldata = *src;
  8278. ldata = be32_to_cpu(ldata);
  8279. *dest = ldata;
  8280. src++;
  8281. dest++;
  8282. }
  8283. }
  8284. /**
  8285. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8286. * @phba: Pointer to HBA context object.
  8287. * @pring: Pointer to driver SLI ring object.
  8288. * @mp: Pointer to driver buffer object.
  8289. *
  8290. * This function is called with no lock held.
  8291. * It always return zero after adding the buffer to the postbufq
  8292. * buffer list.
  8293. **/
  8294. int
  8295. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8296. struct lpfc_dmabuf *mp)
  8297. {
  8298. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8299. later */
  8300. spin_lock_irq(&phba->hbalock);
  8301. list_add_tail(&mp->list, &pring->postbufq);
  8302. pring->postbufq_cnt++;
  8303. spin_unlock_irq(&phba->hbalock);
  8304. return 0;
  8305. }
  8306. /**
  8307. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8308. * @phba: Pointer to HBA context object.
  8309. *
  8310. * When HBQ is enabled, buffers are searched based on tags. This function
  8311. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8312. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8313. * does not conflict with tags of buffer posted for unsolicited events.
  8314. * The function returns the allocated tag. The function is called with
  8315. * no locks held.
  8316. **/
  8317. uint32_t
  8318. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8319. {
  8320. spin_lock_irq(&phba->hbalock);
  8321. phba->buffer_tag_count++;
  8322. /*
  8323. * Always set the QUE_BUFTAG_BIT to distiguish between
  8324. * a tag assigned by HBQ.
  8325. */
  8326. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8327. spin_unlock_irq(&phba->hbalock);
  8328. return phba->buffer_tag_count;
  8329. }
  8330. /**
  8331. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8332. * @phba: Pointer to HBA context object.
  8333. * @pring: Pointer to driver SLI ring object.
  8334. * @tag: Buffer tag.
  8335. *
  8336. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8337. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8338. * iocb is posted to the response ring with the tag of the buffer.
  8339. * This function searches the pring->postbufq list using the tag
  8340. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8341. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8342. * buffer is returned to the caller else NULL is returned.
  8343. * This function is called with no lock held.
  8344. **/
  8345. struct lpfc_dmabuf *
  8346. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8347. uint32_t tag)
  8348. {
  8349. struct lpfc_dmabuf *mp, *next_mp;
  8350. struct list_head *slp = &pring->postbufq;
  8351. /* Search postbufq, from the beginning, looking for a match on tag */
  8352. spin_lock_irq(&phba->hbalock);
  8353. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8354. if (mp->buffer_tag == tag) {
  8355. list_del_init(&mp->list);
  8356. pring->postbufq_cnt--;
  8357. spin_unlock_irq(&phba->hbalock);
  8358. return mp;
  8359. }
  8360. }
  8361. spin_unlock_irq(&phba->hbalock);
  8362. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8363. "0402 Cannot find virtual addr for buffer tag on "
  8364. "ring %d Data x%lx x%p x%p x%x\n",
  8365. pring->ringno, (unsigned long) tag,
  8366. slp->next, slp->prev, pring->postbufq_cnt);
  8367. return NULL;
  8368. }
  8369. /**
  8370. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8371. * @phba: Pointer to HBA context object.
  8372. * @pring: Pointer to driver SLI ring object.
  8373. * @phys: DMA address of the buffer.
  8374. *
  8375. * This function searches the buffer list using the dma_address
  8376. * of unsolicited event to find the driver's lpfc_dmabuf object
  8377. * corresponding to the dma_address. The function returns the
  8378. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8379. * This function is called by the ct and els unsolicited event
  8380. * handlers to get the buffer associated with the unsolicited
  8381. * event.
  8382. *
  8383. * This function is called with no lock held.
  8384. **/
  8385. struct lpfc_dmabuf *
  8386. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8387. dma_addr_t phys)
  8388. {
  8389. struct lpfc_dmabuf *mp, *next_mp;
  8390. struct list_head *slp = &pring->postbufq;
  8391. /* Search postbufq, from the beginning, looking for a match on phys */
  8392. spin_lock_irq(&phba->hbalock);
  8393. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8394. if (mp->phys == phys) {
  8395. list_del_init(&mp->list);
  8396. pring->postbufq_cnt--;
  8397. spin_unlock_irq(&phba->hbalock);
  8398. return mp;
  8399. }
  8400. }
  8401. spin_unlock_irq(&phba->hbalock);
  8402. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8403. "0410 Cannot find virtual addr for mapped buf on "
  8404. "ring %d Data x%llx x%p x%p x%x\n",
  8405. pring->ringno, (unsigned long long)phys,
  8406. slp->next, slp->prev, pring->postbufq_cnt);
  8407. return NULL;
  8408. }
  8409. /**
  8410. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8411. * @phba: Pointer to HBA context object.
  8412. * @cmdiocb: Pointer to driver command iocb object.
  8413. * @rspiocb: Pointer to driver response iocb object.
  8414. *
  8415. * This function is the completion handler for the abort iocbs for
  8416. * ELS commands. This function is called from the ELS ring event
  8417. * handler with no lock held. This function frees memory resources
  8418. * associated with the abort iocb.
  8419. **/
  8420. static void
  8421. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8422. struct lpfc_iocbq *rspiocb)
  8423. {
  8424. IOCB_t *irsp = &rspiocb->iocb;
  8425. uint16_t abort_iotag, abort_context;
  8426. struct lpfc_iocbq *abort_iocb = NULL;
  8427. if (irsp->ulpStatus) {
  8428. /*
  8429. * Assume that the port already completed and returned, or
  8430. * will return the iocb. Just Log the message.
  8431. */
  8432. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8433. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8434. spin_lock_irq(&phba->hbalock);
  8435. if (phba->sli_rev < LPFC_SLI_REV4) {
  8436. if (abort_iotag != 0 &&
  8437. abort_iotag <= phba->sli.last_iotag)
  8438. abort_iocb =
  8439. phba->sli.iocbq_lookup[abort_iotag];
  8440. } else
  8441. /* For sli4 the abort_tag is the XRI,
  8442. * so the abort routine puts the iotag of the iocb
  8443. * being aborted in the context field of the abort
  8444. * IOCB.
  8445. */
  8446. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8447. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8448. "0327 Cannot abort els iocb %p "
  8449. "with tag %x context %x, abort status %x, "
  8450. "abort code %x\n",
  8451. abort_iocb, abort_iotag, abort_context,
  8452. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8453. spin_unlock_irq(&phba->hbalock);
  8454. }
  8455. lpfc_sli_release_iocbq(phba, cmdiocb);
  8456. return;
  8457. }
  8458. /**
  8459. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  8460. * @phba: Pointer to HBA context object.
  8461. * @cmdiocb: Pointer to driver command iocb object.
  8462. * @rspiocb: Pointer to driver response iocb object.
  8463. *
  8464. * The function is called from SLI ring event handler with no
  8465. * lock held. This function is the completion handler for ELS commands
  8466. * which are aborted. The function frees memory resources used for
  8467. * the aborted ELS commands.
  8468. **/
  8469. static void
  8470. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8471. struct lpfc_iocbq *rspiocb)
  8472. {
  8473. IOCB_t *irsp = &rspiocb->iocb;
  8474. /* ELS cmd tag <ulpIoTag> completes */
  8475. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8476. "0139 Ignoring ELS cmd tag x%x completion Data: "
  8477. "x%x x%x x%x\n",
  8478. irsp->ulpIoTag, irsp->ulpStatus,
  8479. irsp->un.ulpWord[4], irsp->ulpTimeout);
  8480. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  8481. lpfc_ct_free_iocb(phba, cmdiocb);
  8482. else
  8483. lpfc_els_free_iocb(phba, cmdiocb);
  8484. return;
  8485. }
  8486. /**
  8487. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  8488. * @phba: Pointer to HBA context object.
  8489. * @pring: Pointer to driver SLI ring object.
  8490. * @cmdiocb: Pointer to driver command iocb object.
  8491. *
  8492. * This function issues an abort iocb for the provided command iocb down to
  8493. * the port. Other than the case the outstanding command iocb is an abort
  8494. * request, this function issues abort out unconditionally. This function is
  8495. * called with hbalock held. The function returns 0 when it fails due to
  8496. * memory allocation failure or when the command iocb is an abort request.
  8497. **/
  8498. static int
  8499. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8500. struct lpfc_iocbq *cmdiocb)
  8501. {
  8502. struct lpfc_vport *vport = cmdiocb->vport;
  8503. struct lpfc_iocbq *abtsiocbp;
  8504. IOCB_t *icmd = NULL;
  8505. IOCB_t *iabt = NULL;
  8506. int retval;
  8507. /*
  8508. * There are certain command types we don't want to abort. And we
  8509. * don't want to abort commands that are already in the process of
  8510. * being aborted.
  8511. */
  8512. icmd = &cmdiocb->iocb;
  8513. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8514. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8515. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8516. return 0;
  8517. /* issue ABTS for this IOCB based on iotag */
  8518. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  8519. if (abtsiocbp == NULL)
  8520. return 0;
  8521. /* This signals the response to set the correct status
  8522. * before calling the completion handler
  8523. */
  8524. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  8525. iabt = &abtsiocbp->iocb;
  8526. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  8527. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  8528. if (phba->sli_rev == LPFC_SLI_REV4) {
  8529. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  8530. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  8531. }
  8532. else
  8533. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  8534. iabt->ulpLe = 1;
  8535. iabt->ulpClass = icmd->ulpClass;
  8536. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8537. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  8538. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  8539. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  8540. if (phba->link_state >= LPFC_LINK_UP)
  8541. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  8542. else
  8543. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  8544. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  8545. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  8546. "0339 Abort xri x%x, original iotag x%x, "
  8547. "abort cmd iotag x%x\n",
  8548. iabt->un.acxri.abortIoTag,
  8549. iabt->un.acxri.abortContextTag,
  8550. abtsiocbp->iotag);
  8551. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  8552. if (retval)
  8553. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  8554. /*
  8555. * Caller to this routine should check for IOCB_ERROR
  8556. * and handle it properly. This routine no longer removes
  8557. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8558. */
  8559. return retval;
  8560. }
  8561. /**
  8562. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  8563. * @phba: Pointer to HBA context object.
  8564. * @pring: Pointer to driver SLI ring object.
  8565. * @cmdiocb: Pointer to driver command iocb object.
  8566. *
  8567. * This function issues an abort iocb for the provided command iocb. In case
  8568. * of unloading, the abort iocb will not be issued to commands on the ELS
  8569. * ring. Instead, the callback function shall be changed to those commands
  8570. * so that nothing happens when them finishes. This function is called with
  8571. * hbalock held. The function returns 0 when the command iocb is an abort
  8572. * request.
  8573. **/
  8574. int
  8575. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8576. struct lpfc_iocbq *cmdiocb)
  8577. {
  8578. struct lpfc_vport *vport = cmdiocb->vport;
  8579. int retval = IOCB_ERROR;
  8580. IOCB_t *icmd = NULL;
  8581. /*
  8582. * There are certain command types we don't want to abort. And we
  8583. * don't want to abort commands that are already in the process of
  8584. * being aborted.
  8585. */
  8586. icmd = &cmdiocb->iocb;
  8587. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8588. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8589. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8590. return 0;
  8591. /*
  8592. * If we're unloading, don't abort iocb on the ELS ring, but change
  8593. * the callback so that nothing happens when it finishes.
  8594. */
  8595. if ((vport->load_flag & FC_UNLOADING) &&
  8596. (pring->ringno == LPFC_ELS_RING)) {
  8597. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  8598. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  8599. else
  8600. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  8601. goto abort_iotag_exit;
  8602. }
  8603. /* Now, we try to issue the abort to the cmdiocb out */
  8604. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  8605. abort_iotag_exit:
  8606. /*
  8607. * Caller to this routine should check for IOCB_ERROR
  8608. * and handle it properly. This routine no longer removes
  8609. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8610. */
  8611. return retval;
  8612. }
  8613. /**
  8614. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  8615. * @phba: Pointer to HBA context object.
  8616. * @pring: Pointer to driver SLI ring object.
  8617. *
  8618. * This function aborts all iocbs in the given ring and frees all the iocb
  8619. * objects in txq. This function issues abort iocbs unconditionally for all
  8620. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  8621. * to complete before the return of this function. The caller is not required
  8622. * to hold any locks.
  8623. **/
  8624. static void
  8625. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  8626. {
  8627. LIST_HEAD(completions);
  8628. struct lpfc_iocbq *iocb, *next_iocb;
  8629. if (pring->ringno == LPFC_ELS_RING)
  8630. lpfc_fabric_abort_hba(phba);
  8631. spin_lock_irq(&phba->hbalock);
  8632. /* Take off all the iocbs on txq for cancelling */
  8633. list_splice_init(&pring->txq, &completions);
  8634. pring->txq_cnt = 0;
  8635. /* Next issue ABTS for everything on the txcmplq */
  8636. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  8637. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  8638. spin_unlock_irq(&phba->hbalock);
  8639. /* Cancel all the IOCBs from the completions list */
  8640. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8641. IOERR_SLI_ABORTED);
  8642. }
  8643. /**
  8644. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  8645. * @phba: pointer to lpfc HBA data structure.
  8646. *
  8647. * This routine will abort all pending and outstanding iocbs to an HBA.
  8648. **/
  8649. void
  8650. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  8651. {
  8652. struct lpfc_sli *psli = &phba->sli;
  8653. struct lpfc_sli_ring *pring;
  8654. int i;
  8655. for (i = 0; i < psli->num_rings; i++) {
  8656. pring = &psli->ring[i];
  8657. lpfc_sli_iocb_ring_abort(phba, pring);
  8658. }
  8659. }
  8660. /**
  8661. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  8662. * @iocbq: Pointer to driver iocb object.
  8663. * @vport: Pointer to driver virtual port object.
  8664. * @tgt_id: SCSI ID of the target.
  8665. * @lun_id: LUN ID of the scsi device.
  8666. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  8667. *
  8668. * This function acts as an iocb filter for functions which abort or count
  8669. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  8670. * 0 if the filtering criteria is met for the given iocb and will return
  8671. * 1 if the filtering criteria is not met.
  8672. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  8673. * given iocb is for the SCSI device specified by vport, tgt_id and
  8674. * lun_id parameter.
  8675. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  8676. * given iocb is for the SCSI target specified by vport and tgt_id
  8677. * parameters.
  8678. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  8679. * given iocb is for the SCSI host associated with the given vport.
  8680. * This function is called with no locks held.
  8681. **/
  8682. static int
  8683. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  8684. uint16_t tgt_id, uint64_t lun_id,
  8685. lpfc_ctx_cmd ctx_cmd)
  8686. {
  8687. struct lpfc_scsi_buf *lpfc_cmd;
  8688. int rc = 1;
  8689. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  8690. return rc;
  8691. if (iocbq->vport != vport)
  8692. return rc;
  8693. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  8694. if (lpfc_cmd->pCmd == NULL)
  8695. return rc;
  8696. switch (ctx_cmd) {
  8697. case LPFC_CTX_LUN:
  8698. if ((lpfc_cmd->rdata->pnode) &&
  8699. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  8700. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  8701. rc = 0;
  8702. break;
  8703. case LPFC_CTX_TGT:
  8704. if ((lpfc_cmd->rdata->pnode) &&
  8705. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  8706. rc = 0;
  8707. break;
  8708. case LPFC_CTX_HOST:
  8709. rc = 0;
  8710. break;
  8711. default:
  8712. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  8713. __func__, ctx_cmd);
  8714. break;
  8715. }
  8716. return rc;
  8717. }
  8718. /**
  8719. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  8720. * @vport: Pointer to virtual port.
  8721. * @tgt_id: SCSI ID of the target.
  8722. * @lun_id: LUN ID of the scsi device.
  8723. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8724. *
  8725. * This function returns number of FCP commands pending for the vport.
  8726. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  8727. * commands pending on the vport associated with SCSI device specified
  8728. * by tgt_id and lun_id parameters.
  8729. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  8730. * commands pending on the vport associated with SCSI target specified
  8731. * by tgt_id parameter.
  8732. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  8733. * commands pending on the vport.
  8734. * This function returns the number of iocbs which satisfy the filter.
  8735. * This function is called without any lock held.
  8736. **/
  8737. int
  8738. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  8739. lpfc_ctx_cmd ctx_cmd)
  8740. {
  8741. struct lpfc_hba *phba = vport->phba;
  8742. struct lpfc_iocbq *iocbq;
  8743. int sum, i;
  8744. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  8745. iocbq = phba->sli.iocbq_lookup[i];
  8746. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  8747. ctx_cmd) == 0)
  8748. sum++;
  8749. }
  8750. return sum;
  8751. }
  8752. /**
  8753. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  8754. * @phba: Pointer to HBA context object
  8755. * @cmdiocb: Pointer to command iocb object.
  8756. * @rspiocb: Pointer to response iocb object.
  8757. *
  8758. * This function is called when an aborted FCP iocb completes. This
  8759. * function is called by the ring event handler with no lock held.
  8760. * This function frees the iocb.
  8761. **/
  8762. void
  8763. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8764. struct lpfc_iocbq *rspiocb)
  8765. {
  8766. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8767. "3096 ABORT_XRI_CN completing on xri x%x "
  8768. "original iotag x%x, abort cmd iotag x%x "
  8769. "status 0x%x, reason 0x%x\n",
  8770. cmdiocb->iocb.un.acxri.abortContextTag,
  8771. cmdiocb->iocb.un.acxri.abortIoTag,
  8772. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  8773. rspiocb->iocb.un.ulpWord[4]);
  8774. lpfc_sli_release_iocbq(phba, cmdiocb);
  8775. return;
  8776. }
  8777. /**
  8778. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  8779. * @vport: Pointer to virtual port.
  8780. * @pring: Pointer to driver SLI ring object.
  8781. * @tgt_id: SCSI ID of the target.
  8782. * @lun_id: LUN ID of the scsi device.
  8783. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8784. *
  8785. * This function sends an abort command for every SCSI command
  8786. * associated with the given virtual port pending on the ring
  8787. * filtered by lpfc_sli_validate_fcp_iocb function.
  8788. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  8789. * FCP iocbs associated with lun specified by tgt_id and lun_id
  8790. * parameters
  8791. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  8792. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  8793. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  8794. * FCP iocbs associated with virtual port.
  8795. * This function returns number of iocbs it failed to abort.
  8796. * This function is called with no locks held.
  8797. **/
  8798. int
  8799. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  8800. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  8801. {
  8802. struct lpfc_hba *phba = vport->phba;
  8803. struct lpfc_iocbq *iocbq;
  8804. struct lpfc_iocbq *abtsiocb;
  8805. IOCB_t *cmd = NULL;
  8806. int errcnt = 0, ret_val = 0;
  8807. int i;
  8808. for (i = 1; i <= phba->sli.last_iotag; i++) {
  8809. iocbq = phba->sli.iocbq_lookup[i];
  8810. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  8811. abort_cmd) != 0)
  8812. continue;
  8813. /* issue ABTS for this IOCB based on iotag */
  8814. abtsiocb = lpfc_sli_get_iocbq(phba);
  8815. if (abtsiocb == NULL) {
  8816. errcnt++;
  8817. continue;
  8818. }
  8819. cmd = &iocbq->iocb;
  8820. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  8821. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  8822. if (phba->sli_rev == LPFC_SLI_REV4)
  8823. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  8824. else
  8825. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  8826. abtsiocb->iocb.ulpLe = 1;
  8827. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  8828. abtsiocb->vport = phba->pport;
  8829. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8830. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  8831. if (iocbq->iocb_flag & LPFC_IO_FCP)
  8832. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  8833. if (lpfc_is_link_up(phba))
  8834. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  8835. else
  8836. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  8837. /* Setup callback routine and issue the command. */
  8838. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  8839. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  8840. abtsiocb, 0);
  8841. if (ret_val == IOCB_ERROR) {
  8842. lpfc_sli_release_iocbq(phba, abtsiocb);
  8843. errcnt++;
  8844. continue;
  8845. }
  8846. }
  8847. return errcnt;
  8848. }
  8849. /**
  8850. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  8851. * @phba: Pointer to HBA context object.
  8852. * @cmdiocbq: Pointer to command iocb.
  8853. * @rspiocbq: Pointer to response iocb.
  8854. *
  8855. * This function is the completion handler for iocbs issued using
  8856. * lpfc_sli_issue_iocb_wait function. This function is called by the
  8857. * ring event handler function without any lock held. This function
  8858. * can be called from both worker thread context and interrupt
  8859. * context. This function also can be called from other thread which
  8860. * cleans up the SLI layer objects.
  8861. * This function copy the contents of the response iocb to the
  8862. * response iocb memory object provided by the caller of
  8863. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  8864. * sleeps for the iocb completion.
  8865. **/
  8866. static void
  8867. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  8868. struct lpfc_iocbq *cmdiocbq,
  8869. struct lpfc_iocbq *rspiocbq)
  8870. {
  8871. wait_queue_head_t *pdone_q;
  8872. unsigned long iflags;
  8873. struct lpfc_scsi_buf *lpfc_cmd;
  8874. spin_lock_irqsave(&phba->hbalock, iflags);
  8875. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  8876. if (cmdiocbq->context2 && rspiocbq)
  8877. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  8878. &rspiocbq->iocb, sizeof(IOCB_t));
  8879. /* Set the exchange busy flag for task management commands */
  8880. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  8881. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  8882. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  8883. cur_iocbq);
  8884. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  8885. }
  8886. pdone_q = cmdiocbq->context_un.wait_queue;
  8887. if (pdone_q)
  8888. wake_up(pdone_q);
  8889. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8890. return;
  8891. }
  8892. /**
  8893. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  8894. * @phba: Pointer to HBA context object..
  8895. * @piocbq: Pointer to command iocb.
  8896. * @flag: Flag to test.
  8897. *
  8898. * This routine grabs the hbalock and then test the iocb_flag to
  8899. * see if the passed in flag is set.
  8900. * Returns:
  8901. * 1 if flag is set.
  8902. * 0 if flag is not set.
  8903. **/
  8904. static int
  8905. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  8906. struct lpfc_iocbq *piocbq, uint32_t flag)
  8907. {
  8908. unsigned long iflags;
  8909. int ret;
  8910. spin_lock_irqsave(&phba->hbalock, iflags);
  8911. ret = piocbq->iocb_flag & flag;
  8912. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8913. return ret;
  8914. }
  8915. /**
  8916. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  8917. * @phba: Pointer to HBA context object..
  8918. * @pring: Pointer to sli ring.
  8919. * @piocb: Pointer to command iocb.
  8920. * @prspiocbq: Pointer to response iocb.
  8921. * @timeout: Timeout in number of seconds.
  8922. *
  8923. * This function issues the iocb to firmware and waits for the
  8924. * iocb to complete. If the iocb command is not
  8925. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  8926. * Caller should not free the iocb resources if this function
  8927. * returns IOCB_TIMEDOUT.
  8928. * The function waits for the iocb completion using an
  8929. * non-interruptible wait.
  8930. * This function will sleep while waiting for iocb completion.
  8931. * So, this function should not be called from any context which
  8932. * does not allow sleeping. Due to the same reason, this function
  8933. * cannot be called with interrupt disabled.
  8934. * This function assumes that the iocb completions occur while
  8935. * this function sleep. So, this function cannot be called from
  8936. * the thread which process iocb completion for this ring.
  8937. * This function clears the iocb_flag of the iocb object before
  8938. * issuing the iocb and the iocb completion handler sets this
  8939. * flag and wakes this thread when the iocb completes.
  8940. * The contents of the response iocb will be copied to prspiocbq
  8941. * by the completion handler when the command completes.
  8942. * This function returns IOCB_SUCCESS when success.
  8943. * This function is called with no lock held.
  8944. **/
  8945. int
  8946. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  8947. uint32_t ring_number,
  8948. struct lpfc_iocbq *piocb,
  8949. struct lpfc_iocbq *prspiocbq,
  8950. uint32_t timeout)
  8951. {
  8952. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  8953. long timeleft, timeout_req = 0;
  8954. int retval = IOCB_SUCCESS;
  8955. uint32_t creg_val;
  8956. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8957. /*
  8958. * If the caller has provided a response iocbq buffer, then context2
  8959. * is NULL or its an error.
  8960. */
  8961. if (prspiocbq) {
  8962. if (piocb->context2)
  8963. return IOCB_ERROR;
  8964. piocb->context2 = prspiocbq;
  8965. }
  8966. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  8967. piocb->context_un.wait_queue = &done_q;
  8968. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  8969. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  8970. if (lpfc_readl(phba->HCregaddr, &creg_val))
  8971. return IOCB_ERROR;
  8972. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  8973. writel(creg_val, phba->HCregaddr);
  8974. readl(phba->HCregaddr); /* flush */
  8975. }
  8976. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  8977. SLI_IOCB_RET_IOCB);
  8978. if (retval == IOCB_SUCCESS) {
  8979. timeout_req = timeout * HZ;
  8980. timeleft = wait_event_timeout(done_q,
  8981. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  8982. timeout_req);
  8983. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  8984. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8985. "0331 IOCB wake signaled\n");
  8986. } else if (timeleft == 0) {
  8987. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8988. "0338 IOCB wait timeout error - no "
  8989. "wake response Data x%x\n", timeout);
  8990. retval = IOCB_TIMEDOUT;
  8991. } else {
  8992. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8993. "0330 IOCB wake NOT set, "
  8994. "Data x%x x%lx\n",
  8995. timeout, (timeleft / jiffies));
  8996. retval = IOCB_TIMEDOUT;
  8997. }
  8998. } else if (retval == IOCB_BUSY) {
  8999. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9000. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  9001. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  9002. return retval;
  9003. } else {
  9004. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9005. "0332 IOCB wait issue failed, Data x%x\n",
  9006. retval);
  9007. retval = IOCB_ERROR;
  9008. }
  9009. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9010. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9011. return IOCB_ERROR;
  9012. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  9013. writel(creg_val, phba->HCregaddr);
  9014. readl(phba->HCregaddr); /* flush */
  9015. }
  9016. if (prspiocbq)
  9017. piocb->context2 = NULL;
  9018. piocb->context_un.wait_queue = NULL;
  9019. piocb->iocb_cmpl = NULL;
  9020. return retval;
  9021. }
  9022. /**
  9023. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  9024. * @phba: Pointer to HBA context object.
  9025. * @pmboxq: Pointer to driver mailbox object.
  9026. * @timeout: Timeout in number of seconds.
  9027. *
  9028. * This function issues the mailbox to firmware and waits for the
  9029. * mailbox command to complete. If the mailbox command is not
  9030. * completed within timeout seconds, it returns MBX_TIMEOUT.
  9031. * The function waits for the mailbox completion using an
  9032. * interruptible wait. If the thread is woken up due to a
  9033. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  9034. * should not free the mailbox resources, if this function returns
  9035. * MBX_TIMEOUT.
  9036. * This function will sleep while waiting for mailbox completion.
  9037. * So, this function should not be called from any context which
  9038. * does not allow sleeping. Due to the same reason, this function
  9039. * cannot be called with interrupt disabled.
  9040. * This function assumes that the mailbox completion occurs while
  9041. * this function sleep. So, this function cannot be called from
  9042. * the worker thread which processes mailbox completion.
  9043. * This function is called in the context of HBA management
  9044. * applications.
  9045. * This function returns MBX_SUCCESS when successful.
  9046. * This function is called with no lock held.
  9047. **/
  9048. int
  9049. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  9050. uint32_t timeout)
  9051. {
  9052. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9053. int retval;
  9054. unsigned long flag;
  9055. /* The caller must leave context1 empty. */
  9056. if (pmboxq->context1)
  9057. return MBX_NOT_FINISHED;
  9058. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  9059. /* setup wake call as IOCB callback */
  9060. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  9061. /* setup context field to pass wait_queue pointer to wake function */
  9062. pmboxq->context1 = &done_q;
  9063. /* now issue the command */
  9064. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  9065. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  9066. wait_event_interruptible_timeout(done_q,
  9067. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  9068. timeout * HZ);
  9069. spin_lock_irqsave(&phba->hbalock, flag);
  9070. pmboxq->context1 = NULL;
  9071. /*
  9072. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  9073. * else do not free the resources.
  9074. */
  9075. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  9076. retval = MBX_SUCCESS;
  9077. lpfc_sli4_swap_str(phba, pmboxq);
  9078. } else {
  9079. retval = MBX_TIMEOUT;
  9080. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9081. }
  9082. spin_unlock_irqrestore(&phba->hbalock, flag);
  9083. }
  9084. return retval;
  9085. }
  9086. /**
  9087. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  9088. * @phba: Pointer to HBA context.
  9089. *
  9090. * This function is called to shutdown the driver's mailbox sub-system.
  9091. * It first marks the mailbox sub-system is in a block state to prevent
  9092. * the asynchronous mailbox command from issued off the pending mailbox
  9093. * command queue. If the mailbox command sub-system shutdown is due to
  9094. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  9095. * the mailbox sub-system flush routine to forcefully bring down the
  9096. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  9097. * as with offline or HBA function reset), this routine will wait for the
  9098. * outstanding mailbox command to complete before invoking the mailbox
  9099. * sub-system flush routine to gracefully bring down mailbox sub-system.
  9100. **/
  9101. void
  9102. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  9103. {
  9104. struct lpfc_sli *psli = &phba->sli;
  9105. unsigned long timeout;
  9106. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  9107. spin_lock_irq(&phba->hbalock);
  9108. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  9109. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  9110. /* Determine how long we might wait for the active mailbox
  9111. * command to be gracefully completed by firmware.
  9112. */
  9113. if (phba->sli.mbox_active)
  9114. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  9115. phba->sli.mbox_active) *
  9116. 1000) + jiffies;
  9117. spin_unlock_irq(&phba->hbalock);
  9118. while (phba->sli.mbox_active) {
  9119. /* Check active mailbox complete status every 2ms */
  9120. msleep(2);
  9121. if (time_after(jiffies, timeout))
  9122. /* Timeout, let the mailbox flush routine to
  9123. * forcefully release active mailbox command
  9124. */
  9125. break;
  9126. }
  9127. } else
  9128. spin_unlock_irq(&phba->hbalock);
  9129. lpfc_sli_mbox_sys_flush(phba);
  9130. }
  9131. /**
  9132. * lpfc_sli_eratt_read - read sli-3 error attention events
  9133. * @phba: Pointer to HBA context.
  9134. *
  9135. * This function is called to read the SLI3 device error attention registers
  9136. * for possible error attention events. The caller must hold the hostlock
  9137. * with spin_lock_irq().
  9138. *
  9139. * This function returns 1 when there is Error Attention in the Host Attention
  9140. * Register and returns 0 otherwise.
  9141. **/
  9142. static int
  9143. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  9144. {
  9145. uint32_t ha_copy;
  9146. /* Read chip Host Attention (HA) register */
  9147. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9148. goto unplug_err;
  9149. if (ha_copy & HA_ERATT) {
  9150. /* Read host status register to retrieve error event */
  9151. if (lpfc_sli_read_hs(phba))
  9152. goto unplug_err;
  9153. /* Check if there is a deferred error condition is active */
  9154. if ((HS_FFER1 & phba->work_hs) &&
  9155. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9156. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  9157. phba->hba_flag |= DEFER_ERATT;
  9158. /* Clear all interrupt enable conditions */
  9159. writel(0, phba->HCregaddr);
  9160. readl(phba->HCregaddr);
  9161. }
  9162. /* Set the driver HA work bitmap */
  9163. phba->work_ha |= HA_ERATT;
  9164. /* Indicate polling handles this ERATT */
  9165. phba->hba_flag |= HBA_ERATT_HANDLED;
  9166. return 1;
  9167. }
  9168. return 0;
  9169. unplug_err:
  9170. /* Set the driver HS work bitmap */
  9171. phba->work_hs |= UNPLUG_ERR;
  9172. /* Set the driver HA work bitmap */
  9173. phba->work_ha |= HA_ERATT;
  9174. /* Indicate polling handles this ERATT */
  9175. phba->hba_flag |= HBA_ERATT_HANDLED;
  9176. return 1;
  9177. }
  9178. /**
  9179. * lpfc_sli4_eratt_read - read sli-4 error attention events
  9180. * @phba: Pointer to HBA context.
  9181. *
  9182. * This function is called to read the SLI4 device error attention registers
  9183. * for possible error attention events. The caller must hold the hostlock
  9184. * with spin_lock_irq().
  9185. *
  9186. * This function returns 1 when there is Error Attention in the Host Attention
  9187. * Register and returns 0 otherwise.
  9188. **/
  9189. static int
  9190. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  9191. {
  9192. uint32_t uerr_sta_hi, uerr_sta_lo;
  9193. uint32_t if_type, portsmphr;
  9194. struct lpfc_register portstat_reg;
  9195. /*
  9196. * For now, use the SLI4 device internal unrecoverable error
  9197. * registers for error attention. This can be changed later.
  9198. */
  9199. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9200. switch (if_type) {
  9201. case LPFC_SLI_INTF_IF_TYPE_0:
  9202. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  9203. &uerr_sta_lo) ||
  9204. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  9205. &uerr_sta_hi)) {
  9206. phba->work_hs |= UNPLUG_ERR;
  9207. phba->work_ha |= HA_ERATT;
  9208. phba->hba_flag |= HBA_ERATT_HANDLED;
  9209. return 1;
  9210. }
  9211. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  9212. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  9213. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9214. "1423 HBA Unrecoverable error: "
  9215. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9216. "ue_mask_lo_reg=0x%x, "
  9217. "ue_mask_hi_reg=0x%x\n",
  9218. uerr_sta_lo, uerr_sta_hi,
  9219. phba->sli4_hba.ue_mask_lo,
  9220. phba->sli4_hba.ue_mask_hi);
  9221. phba->work_status[0] = uerr_sta_lo;
  9222. phba->work_status[1] = uerr_sta_hi;
  9223. phba->work_ha |= HA_ERATT;
  9224. phba->hba_flag |= HBA_ERATT_HANDLED;
  9225. return 1;
  9226. }
  9227. break;
  9228. case LPFC_SLI_INTF_IF_TYPE_2:
  9229. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9230. &portstat_reg.word0) ||
  9231. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9232. &portsmphr)){
  9233. phba->work_hs |= UNPLUG_ERR;
  9234. phba->work_ha |= HA_ERATT;
  9235. phba->hba_flag |= HBA_ERATT_HANDLED;
  9236. return 1;
  9237. }
  9238. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9239. phba->work_status[0] =
  9240. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9241. phba->work_status[1] =
  9242. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9243. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9244. "2885 Port Status Event: "
  9245. "port status reg 0x%x, "
  9246. "port smphr reg 0x%x, "
  9247. "error 1=0x%x, error 2=0x%x\n",
  9248. portstat_reg.word0,
  9249. portsmphr,
  9250. phba->work_status[0],
  9251. phba->work_status[1]);
  9252. phba->work_ha |= HA_ERATT;
  9253. phba->hba_flag |= HBA_ERATT_HANDLED;
  9254. return 1;
  9255. }
  9256. break;
  9257. case LPFC_SLI_INTF_IF_TYPE_1:
  9258. default:
  9259. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9260. "2886 HBA Error Attention on unsupported "
  9261. "if type %d.", if_type);
  9262. return 1;
  9263. }
  9264. return 0;
  9265. }
  9266. /**
  9267. * lpfc_sli_check_eratt - check error attention events
  9268. * @phba: Pointer to HBA context.
  9269. *
  9270. * This function is called from timer soft interrupt context to check HBA's
  9271. * error attention register bit for error attention events.
  9272. *
  9273. * This function returns 1 when there is Error Attention in the Host Attention
  9274. * Register and returns 0 otherwise.
  9275. **/
  9276. int
  9277. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9278. {
  9279. uint32_t ha_copy;
  9280. /* If somebody is waiting to handle an eratt, don't process it
  9281. * here. The brdkill function will do this.
  9282. */
  9283. if (phba->link_flag & LS_IGNORE_ERATT)
  9284. return 0;
  9285. /* Check if interrupt handler handles this ERATT */
  9286. spin_lock_irq(&phba->hbalock);
  9287. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  9288. /* Interrupt handler has handled ERATT */
  9289. spin_unlock_irq(&phba->hbalock);
  9290. return 0;
  9291. }
  9292. /*
  9293. * If there is deferred error attention, do not check for error
  9294. * attention
  9295. */
  9296. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9297. spin_unlock_irq(&phba->hbalock);
  9298. return 0;
  9299. }
  9300. /* If PCI channel is offline, don't process it */
  9301. if (unlikely(pci_channel_offline(phba->pcidev))) {
  9302. spin_unlock_irq(&phba->hbalock);
  9303. return 0;
  9304. }
  9305. switch (phba->sli_rev) {
  9306. case LPFC_SLI_REV2:
  9307. case LPFC_SLI_REV3:
  9308. /* Read chip Host Attention (HA) register */
  9309. ha_copy = lpfc_sli_eratt_read(phba);
  9310. break;
  9311. case LPFC_SLI_REV4:
  9312. /* Read device Uncoverable Error (UERR) registers */
  9313. ha_copy = lpfc_sli4_eratt_read(phba);
  9314. break;
  9315. default:
  9316. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9317. "0299 Invalid SLI revision (%d)\n",
  9318. phba->sli_rev);
  9319. ha_copy = 0;
  9320. break;
  9321. }
  9322. spin_unlock_irq(&phba->hbalock);
  9323. return ha_copy;
  9324. }
  9325. /**
  9326. * lpfc_intr_state_check - Check device state for interrupt handling
  9327. * @phba: Pointer to HBA context.
  9328. *
  9329. * This inline routine checks whether a device or its PCI slot is in a state
  9330. * that the interrupt should be handled.
  9331. *
  9332. * This function returns 0 if the device or the PCI slot is in a state that
  9333. * interrupt should be handled, otherwise -EIO.
  9334. */
  9335. static inline int
  9336. lpfc_intr_state_check(struct lpfc_hba *phba)
  9337. {
  9338. /* If the pci channel is offline, ignore all the interrupts */
  9339. if (unlikely(pci_channel_offline(phba->pcidev)))
  9340. return -EIO;
  9341. /* Update device level interrupt statistics */
  9342. phba->sli.slistat.sli_intr++;
  9343. /* Ignore all interrupts during initialization. */
  9344. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  9345. return -EIO;
  9346. return 0;
  9347. }
  9348. /**
  9349. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  9350. * @irq: Interrupt number.
  9351. * @dev_id: The device context pointer.
  9352. *
  9353. * This function is directly called from the PCI layer as an interrupt
  9354. * service routine when device with SLI-3 interface spec is enabled with
  9355. * MSI-X multi-message interrupt mode and there are slow-path events in
  9356. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9357. * interrupt mode, this function is called as part of the device-level
  9358. * interrupt handler. When the PCI slot is in error recovery or the HBA
  9359. * is undergoing initialization, the interrupt handler will not process
  9360. * the interrupt. The link attention and ELS ring attention events are
  9361. * handled by the worker thread. The interrupt handler signals the worker
  9362. * thread and returns for these events. This function is called without
  9363. * any lock held. It gets the hbalock to access and update SLI data
  9364. * structures.
  9365. *
  9366. * This function returns IRQ_HANDLED when interrupt is handled else it
  9367. * returns IRQ_NONE.
  9368. **/
  9369. irqreturn_t
  9370. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  9371. {
  9372. struct lpfc_hba *phba;
  9373. uint32_t ha_copy, hc_copy;
  9374. uint32_t work_ha_copy;
  9375. unsigned long status;
  9376. unsigned long iflag;
  9377. uint32_t control;
  9378. MAILBOX_t *mbox, *pmbox;
  9379. struct lpfc_vport *vport;
  9380. struct lpfc_nodelist *ndlp;
  9381. struct lpfc_dmabuf *mp;
  9382. LPFC_MBOXQ_t *pmb;
  9383. int rc;
  9384. /*
  9385. * Get the driver's phba structure from the dev_id and
  9386. * assume the HBA is not interrupting.
  9387. */
  9388. phba = (struct lpfc_hba *)dev_id;
  9389. if (unlikely(!phba))
  9390. return IRQ_NONE;
  9391. /*
  9392. * Stuff needs to be attented to when this function is invoked as an
  9393. * individual interrupt handler in MSI-X multi-message interrupt mode
  9394. */
  9395. if (phba->intr_type == MSIX) {
  9396. /* Check device state for handling interrupt */
  9397. if (lpfc_intr_state_check(phba))
  9398. return IRQ_NONE;
  9399. /* Need to read HA REG for slow-path events */
  9400. spin_lock_irqsave(&phba->hbalock, iflag);
  9401. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9402. goto unplug_error;
  9403. /* If somebody is waiting to handle an eratt don't process it
  9404. * here. The brdkill function will do this.
  9405. */
  9406. if (phba->link_flag & LS_IGNORE_ERATT)
  9407. ha_copy &= ~HA_ERATT;
  9408. /* Check the need for handling ERATT in interrupt handler */
  9409. if (ha_copy & HA_ERATT) {
  9410. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9411. /* ERATT polling has handled ERATT */
  9412. ha_copy &= ~HA_ERATT;
  9413. else
  9414. /* Indicate interrupt handler handles ERATT */
  9415. phba->hba_flag |= HBA_ERATT_HANDLED;
  9416. }
  9417. /*
  9418. * If there is deferred error attention, do not check for any
  9419. * interrupt.
  9420. */
  9421. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9422. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9423. return IRQ_NONE;
  9424. }
  9425. /* Clear up only attention source related to slow-path */
  9426. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  9427. goto unplug_error;
  9428. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  9429. HC_LAINT_ENA | HC_ERINT_ENA),
  9430. phba->HCregaddr);
  9431. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  9432. phba->HAregaddr);
  9433. writel(hc_copy, phba->HCregaddr);
  9434. readl(phba->HAregaddr); /* flush */
  9435. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9436. } else
  9437. ha_copy = phba->ha_copy;
  9438. work_ha_copy = ha_copy & phba->work_ha_mask;
  9439. if (work_ha_copy) {
  9440. if (work_ha_copy & HA_LATT) {
  9441. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  9442. /*
  9443. * Turn off Link Attention interrupts
  9444. * until CLEAR_LA done
  9445. */
  9446. spin_lock_irqsave(&phba->hbalock, iflag);
  9447. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  9448. if (lpfc_readl(phba->HCregaddr, &control))
  9449. goto unplug_error;
  9450. control &= ~HC_LAINT_ENA;
  9451. writel(control, phba->HCregaddr);
  9452. readl(phba->HCregaddr); /* flush */
  9453. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9454. }
  9455. else
  9456. work_ha_copy &= ~HA_LATT;
  9457. }
  9458. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  9459. /*
  9460. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  9461. * the only slow ring.
  9462. */
  9463. status = (work_ha_copy &
  9464. (HA_RXMASK << (4*LPFC_ELS_RING)));
  9465. status >>= (4*LPFC_ELS_RING);
  9466. if (status & HA_RXMASK) {
  9467. spin_lock_irqsave(&phba->hbalock, iflag);
  9468. if (lpfc_readl(phba->HCregaddr, &control))
  9469. goto unplug_error;
  9470. lpfc_debugfs_slow_ring_trc(phba,
  9471. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  9472. control, status,
  9473. (uint32_t)phba->sli.slistat.sli_intr);
  9474. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  9475. lpfc_debugfs_slow_ring_trc(phba,
  9476. "ISR Disable ring:"
  9477. "pwork:x%x hawork:x%x wait:x%x",
  9478. phba->work_ha, work_ha_copy,
  9479. (uint32_t)((unsigned long)
  9480. &phba->work_waitq));
  9481. control &=
  9482. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  9483. writel(control, phba->HCregaddr);
  9484. readl(phba->HCregaddr); /* flush */
  9485. }
  9486. else {
  9487. lpfc_debugfs_slow_ring_trc(phba,
  9488. "ISR slow ring: pwork:"
  9489. "x%x hawork:x%x wait:x%x",
  9490. phba->work_ha, work_ha_copy,
  9491. (uint32_t)((unsigned long)
  9492. &phba->work_waitq));
  9493. }
  9494. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9495. }
  9496. }
  9497. spin_lock_irqsave(&phba->hbalock, iflag);
  9498. if (work_ha_copy & HA_ERATT) {
  9499. if (lpfc_sli_read_hs(phba))
  9500. goto unplug_error;
  9501. /*
  9502. * Check if there is a deferred error condition
  9503. * is active
  9504. */
  9505. if ((HS_FFER1 & phba->work_hs) &&
  9506. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9507. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  9508. phba->work_hs)) {
  9509. phba->hba_flag |= DEFER_ERATT;
  9510. /* Clear all interrupt enable conditions */
  9511. writel(0, phba->HCregaddr);
  9512. readl(phba->HCregaddr);
  9513. }
  9514. }
  9515. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  9516. pmb = phba->sli.mbox_active;
  9517. pmbox = &pmb->u.mb;
  9518. mbox = phba->mbox;
  9519. vport = pmb->vport;
  9520. /* First check out the status word */
  9521. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  9522. if (pmbox->mbxOwner != OWN_HOST) {
  9523. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9524. /*
  9525. * Stray Mailbox Interrupt, mbxCommand <cmd>
  9526. * mbxStatus <status>
  9527. */
  9528. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9529. LOG_SLI,
  9530. "(%d):0304 Stray Mailbox "
  9531. "Interrupt mbxCommand x%x "
  9532. "mbxStatus x%x\n",
  9533. (vport ? vport->vpi : 0),
  9534. pmbox->mbxCommand,
  9535. pmbox->mbxStatus);
  9536. /* clear mailbox attention bit */
  9537. work_ha_copy &= ~HA_MBATT;
  9538. } else {
  9539. phba->sli.mbox_active = NULL;
  9540. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9541. phba->last_completion_time = jiffies;
  9542. del_timer(&phba->sli.mbox_tmo);
  9543. if (pmb->mbox_cmpl) {
  9544. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  9545. MAILBOX_CMD_SIZE);
  9546. if (pmb->out_ext_byte_len &&
  9547. pmb->context2)
  9548. lpfc_sli_pcimem_bcopy(
  9549. phba->mbox_ext,
  9550. pmb->context2,
  9551. pmb->out_ext_byte_len);
  9552. }
  9553. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  9554. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  9555. lpfc_debugfs_disc_trc(vport,
  9556. LPFC_DISC_TRC_MBOX_VPORT,
  9557. "MBOX dflt rpi: : "
  9558. "status:x%x rpi:x%x",
  9559. (uint32_t)pmbox->mbxStatus,
  9560. pmbox->un.varWords[0], 0);
  9561. if (!pmbox->mbxStatus) {
  9562. mp = (struct lpfc_dmabuf *)
  9563. (pmb->context1);
  9564. ndlp = (struct lpfc_nodelist *)
  9565. pmb->context2;
  9566. /* Reg_LOGIN of dflt RPI was
  9567. * successful. new lets get
  9568. * rid of the RPI using the
  9569. * same mbox buffer.
  9570. */
  9571. lpfc_unreg_login(phba,
  9572. vport->vpi,
  9573. pmbox->un.varWords[0],
  9574. pmb);
  9575. pmb->mbox_cmpl =
  9576. lpfc_mbx_cmpl_dflt_rpi;
  9577. pmb->context1 = mp;
  9578. pmb->context2 = ndlp;
  9579. pmb->vport = vport;
  9580. rc = lpfc_sli_issue_mbox(phba,
  9581. pmb,
  9582. MBX_NOWAIT);
  9583. if (rc != MBX_BUSY)
  9584. lpfc_printf_log(phba,
  9585. KERN_ERR,
  9586. LOG_MBOX | LOG_SLI,
  9587. "0350 rc should have"
  9588. "been MBX_BUSY\n");
  9589. if (rc != MBX_NOT_FINISHED)
  9590. goto send_current_mbox;
  9591. }
  9592. }
  9593. spin_lock_irqsave(
  9594. &phba->pport->work_port_lock,
  9595. iflag);
  9596. phba->pport->work_port_events &=
  9597. ~WORKER_MBOX_TMO;
  9598. spin_unlock_irqrestore(
  9599. &phba->pport->work_port_lock,
  9600. iflag);
  9601. lpfc_mbox_cmpl_put(phba, pmb);
  9602. }
  9603. } else
  9604. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9605. if ((work_ha_copy & HA_MBATT) &&
  9606. (phba->sli.mbox_active == NULL)) {
  9607. send_current_mbox:
  9608. /* Process next mailbox command if there is one */
  9609. do {
  9610. rc = lpfc_sli_issue_mbox(phba, NULL,
  9611. MBX_NOWAIT);
  9612. } while (rc == MBX_NOT_FINISHED);
  9613. if (rc != MBX_SUCCESS)
  9614. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9615. LOG_SLI, "0349 rc should be "
  9616. "MBX_SUCCESS\n");
  9617. }
  9618. spin_lock_irqsave(&phba->hbalock, iflag);
  9619. phba->work_ha |= work_ha_copy;
  9620. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9621. lpfc_worker_wake_up(phba);
  9622. }
  9623. return IRQ_HANDLED;
  9624. unplug_error:
  9625. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9626. return IRQ_HANDLED;
  9627. } /* lpfc_sli_sp_intr_handler */
  9628. /**
  9629. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  9630. * @irq: Interrupt number.
  9631. * @dev_id: The device context pointer.
  9632. *
  9633. * This function is directly called from the PCI layer as an interrupt
  9634. * service routine when device with SLI-3 interface spec is enabled with
  9635. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9636. * ring event in the HBA. However, when the device is enabled with either
  9637. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9638. * device-level interrupt handler. When the PCI slot is in error recovery
  9639. * or the HBA is undergoing initialization, the interrupt handler will not
  9640. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9641. * the intrrupt context. This function is called without any lock held.
  9642. * It gets the hbalock to access and update SLI data structures.
  9643. *
  9644. * This function returns IRQ_HANDLED when interrupt is handled else it
  9645. * returns IRQ_NONE.
  9646. **/
  9647. irqreturn_t
  9648. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  9649. {
  9650. struct lpfc_hba *phba;
  9651. uint32_t ha_copy;
  9652. unsigned long status;
  9653. unsigned long iflag;
  9654. /* Get the driver's phba structure from the dev_id and
  9655. * assume the HBA is not interrupting.
  9656. */
  9657. phba = (struct lpfc_hba *) dev_id;
  9658. if (unlikely(!phba))
  9659. return IRQ_NONE;
  9660. /*
  9661. * Stuff needs to be attented to when this function is invoked as an
  9662. * individual interrupt handler in MSI-X multi-message interrupt mode
  9663. */
  9664. if (phba->intr_type == MSIX) {
  9665. /* Check device state for handling interrupt */
  9666. if (lpfc_intr_state_check(phba))
  9667. return IRQ_NONE;
  9668. /* Need to read HA REG for FCP ring and other ring events */
  9669. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9670. return IRQ_HANDLED;
  9671. /* Clear up only attention source related to fast-path */
  9672. spin_lock_irqsave(&phba->hbalock, iflag);
  9673. /*
  9674. * If there is deferred error attention, do not check for
  9675. * any interrupt.
  9676. */
  9677. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9678. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9679. return IRQ_NONE;
  9680. }
  9681. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  9682. phba->HAregaddr);
  9683. readl(phba->HAregaddr); /* flush */
  9684. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9685. } else
  9686. ha_copy = phba->ha_copy;
  9687. /*
  9688. * Process all events on FCP ring. Take the optimized path for FCP IO.
  9689. */
  9690. ha_copy &= ~(phba->work_ha_mask);
  9691. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9692. status >>= (4*LPFC_FCP_RING);
  9693. if (status & HA_RXMASK)
  9694. lpfc_sli_handle_fast_ring_event(phba,
  9695. &phba->sli.ring[LPFC_FCP_RING],
  9696. status);
  9697. if (phba->cfg_multi_ring_support == 2) {
  9698. /*
  9699. * Process all events on extra ring. Take the optimized path
  9700. * for extra ring IO.
  9701. */
  9702. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9703. status >>= (4*LPFC_EXTRA_RING);
  9704. if (status & HA_RXMASK) {
  9705. lpfc_sli_handle_fast_ring_event(phba,
  9706. &phba->sli.ring[LPFC_EXTRA_RING],
  9707. status);
  9708. }
  9709. }
  9710. return IRQ_HANDLED;
  9711. } /* lpfc_sli_fp_intr_handler */
  9712. /**
  9713. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  9714. * @irq: Interrupt number.
  9715. * @dev_id: The device context pointer.
  9716. *
  9717. * This function is the HBA device-level interrupt handler to device with
  9718. * SLI-3 interface spec, called from the PCI layer when either MSI or
  9719. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  9720. * requires driver attention. This function invokes the slow-path interrupt
  9721. * attention handling function and fast-path interrupt attention handling
  9722. * function in turn to process the relevant HBA attention events. This
  9723. * function is called without any lock held. It gets the hbalock to access
  9724. * and update SLI data structures.
  9725. *
  9726. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9727. * returns IRQ_NONE.
  9728. **/
  9729. irqreturn_t
  9730. lpfc_sli_intr_handler(int irq, void *dev_id)
  9731. {
  9732. struct lpfc_hba *phba;
  9733. irqreturn_t sp_irq_rc, fp_irq_rc;
  9734. unsigned long status1, status2;
  9735. uint32_t hc_copy;
  9736. /*
  9737. * Get the driver's phba structure from the dev_id and
  9738. * assume the HBA is not interrupting.
  9739. */
  9740. phba = (struct lpfc_hba *) dev_id;
  9741. if (unlikely(!phba))
  9742. return IRQ_NONE;
  9743. /* Check device state for handling interrupt */
  9744. if (lpfc_intr_state_check(phba))
  9745. return IRQ_NONE;
  9746. spin_lock(&phba->hbalock);
  9747. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  9748. spin_unlock(&phba->hbalock);
  9749. return IRQ_HANDLED;
  9750. }
  9751. if (unlikely(!phba->ha_copy)) {
  9752. spin_unlock(&phba->hbalock);
  9753. return IRQ_NONE;
  9754. } else if (phba->ha_copy & HA_ERATT) {
  9755. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9756. /* ERATT polling has handled ERATT */
  9757. phba->ha_copy &= ~HA_ERATT;
  9758. else
  9759. /* Indicate interrupt handler handles ERATT */
  9760. phba->hba_flag |= HBA_ERATT_HANDLED;
  9761. }
  9762. /*
  9763. * If there is deferred error attention, do not check for any interrupt.
  9764. */
  9765. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9766. spin_unlock(&phba->hbalock);
  9767. return IRQ_NONE;
  9768. }
  9769. /* Clear attention sources except link and error attentions */
  9770. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  9771. spin_unlock(&phba->hbalock);
  9772. return IRQ_HANDLED;
  9773. }
  9774. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  9775. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  9776. phba->HCregaddr);
  9777. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  9778. writel(hc_copy, phba->HCregaddr);
  9779. readl(phba->HAregaddr); /* flush */
  9780. spin_unlock(&phba->hbalock);
  9781. /*
  9782. * Invokes slow-path host attention interrupt handling as appropriate.
  9783. */
  9784. /* status of events with mailbox and link attention */
  9785. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  9786. /* status of events with ELS ring */
  9787. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  9788. status2 >>= (4*LPFC_ELS_RING);
  9789. if (status1 || (status2 & HA_RXMASK))
  9790. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  9791. else
  9792. sp_irq_rc = IRQ_NONE;
  9793. /*
  9794. * Invoke fast-path host attention interrupt handling as appropriate.
  9795. */
  9796. /* status of events with FCP ring */
  9797. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9798. status1 >>= (4*LPFC_FCP_RING);
  9799. /* status of events with extra ring */
  9800. if (phba->cfg_multi_ring_support == 2) {
  9801. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9802. status2 >>= (4*LPFC_EXTRA_RING);
  9803. } else
  9804. status2 = 0;
  9805. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  9806. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  9807. else
  9808. fp_irq_rc = IRQ_NONE;
  9809. /* Return device-level interrupt handling status */
  9810. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  9811. } /* lpfc_sli_intr_handler */
  9812. /**
  9813. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  9814. * @phba: pointer to lpfc hba data structure.
  9815. *
  9816. * This routine is invoked by the worker thread to process all the pending
  9817. * SLI4 FCP abort XRI events.
  9818. **/
  9819. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  9820. {
  9821. struct lpfc_cq_event *cq_event;
  9822. /* First, declare the fcp xri abort event has been handled */
  9823. spin_lock_irq(&phba->hbalock);
  9824. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  9825. spin_unlock_irq(&phba->hbalock);
  9826. /* Now, handle all the fcp xri abort events */
  9827. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  9828. /* Get the first event from the head of the event queue */
  9829. spin_lock_irq(&phba->hbalock);
  9830. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  9831. cq_event, struct lpfc_cq_event, list);
  9832. spin_unlock_irq(&phba->hbalock);
  9833. /* Notify aborted XRI for FCP work queue */
  9834. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9835. /* Free the event processed back to the free pool */
  9836. lpfc_sli4_cq_event_release(phba, cq_event);
  9837. }
  9838. }
  9839. /**
  9840. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  9841. * @phba: pointer to lpfc hba data structure.
  9842. *
  9843. * This routine is invoked by the worker thread to process all the pending
  9844. * SLI4 els abort xri events.
  9845. **/
  9846. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  9847. {
  9848. struct lpfc_cq_event *cq_event;
  9849. /* First, declare the els xri abort event has been handled */
  9850. spin_lock_irq(&phba->hbalock);
  9851. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  9852. spin_unlock_irq(&phba->hbalock);
  9853. /* Now, handle all the els xri abort events */
  9854. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  9855. /* Get the first event from the head of the event queue */
  9856. spin_lock_irq(&phba->hbalock);
  9857. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  9858. cq_event, struct lpfc_cq_event, list);
  9859. spin_unlock_irq(&phba->hbalock);
  9860. /* Notify aborted XRI for ELS work queue */
  9861. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9862. /* Free the event processed back to the free pool */
  9863. lpfc_sli4_cq_event_release(phba, cq_event);
  9864. }
  9865. }
  9866. /**
  9867. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  9868. * @phba: pointer to lpfc hba data structure
  9869. * @pIocbIn: pointer to the rspiocbq
  9870. * @pIocbOut: pointer to the cmdiocbq
  9871. * @wcqe: pointer to the complete wcqe
  9872. *
  9873. * This routine transfers the fields of a command iocbq to a response iocbq
  9874. * by copying all the IOCB fields from command iocbq and transferring the
  9875. * completion status information from the complete wcqe.
  9876. **/
  9877. static void
  9878. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  9879. struct lpfc_iocbq *pIocbIn,
  9880. struct lpfc_iocbq *pIocbOut,
  9881. struct lpfc_wcqe_complete *wcqe)
  9882. {
  9883. unsigned long iflags;
  9884. uint32_t status;
  9885. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  9886. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  9887. sizeof(struct lpfc_iocbq) - offset);
  9888. /* Map WCQE parameters into irspiocb parameters */
  9889. status = bf_get(lpfc_wcqe_c_status, wcqe);
  9890. pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
  9891. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  9892. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  9893. pIocbIn->iocb.un.fcpi.fcpi_parm =
  9894. pIocbOut->iocb.un.fcpi.fcpi_parm -
  9895. wcqe->total_data_placed;
  9896. else
  9897. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9898. else {
  9899. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9900. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  9901. }
  9902. /* Convert BG errors for completion status */
  9903. if (status == CQE_STATUS_DI_ERROR) {
  9904. pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  9905. if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
  9906. pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
  9907. else
  9908. pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
  9909. pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
  9910. if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
  9911. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9912. BGS_GUARD_ERR_MASK;
  9913. if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
  9914. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9915. BGS_APPTAG_ERR_MASK;
  9916. if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
  9917. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9918. BGS_REFTAG_ERR_MASK;
  9919. /* Check to see if there was any good data before the error */
  9920. if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
  9921. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9922. BGS_HI_WATER_MARK_PRESENT_MASK;
  9923. pIocbIn->iocb.unsli3.sli3_bg.bghm =
  9924. wcqe->total_data_placed;
  9925. }
  9926. /*
  9927. * Set ALL the error bits to indicate we don't know what
  9928. * type of error it is.
  9929. */
  9930. if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
  9931. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9932. (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
  9933. BGS_GUARD_ERR_MASK);
  9934. }
  9935. /* Pick up HBA exchange busy condition */
  9936. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  9937. spin_lock_irqsave(&phba->hbalock, iflags);
  9938. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  9939. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9940. }
  9941. }
  9942. /**
  9943. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  9944. * @phba: Pointer to HBA context object.
  9945. * @wcqe: Pointer to work-queue completion queue entry.
  9946. *
  9947. * This routine handles an ELS work-queue completion event and construct
  9948. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  9949. * discovery engine to handle.
  9950. *
  9951. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  9952. **/
  9953. static struct lpfc_iocbq *
  9954. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  9955. struct lpfc_iocbq *irspiocbq)
  9956. {
  9957. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9958. struct lpfc_iocbq *cmdiocbq;
  9959. struct lpfc_wcqe_complete *wcqe;
  9960. unsigned long iflags;
  9961. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  9962. spin_lock_irqsave(&phba->hbalock, iflags);
  9963. pring->stats.iocb_event++;
  9964. /* Look up the ELS command IOCB and create pseudo response IOCB */
  9965. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  9966. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9967. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9968. if (unlikely(!cmdiocbq)) {
  9969. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9970. "0386 ELS complete with no corresponding "
  9971. "cmdiocb: iotag (%d)\n",
  9972. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9973. lpfc_sli_release_iocbq(phba, irspiocbq);
  9974. return NULL;
  9975. }
  9976. /* Fake the irspiocbq and copy necessary response information */
  9977. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  9978. return irspiocbq;
  9979. }
  9980. /**
  9981. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  9982. * @phba: Pointer to HBA context object.
  9983. * @cqe: Pointer to mailbox completion queue entry.
  9984. *
  9985. * This routine process a mailbox completion queue entry with asynchrous
  9986. * event.
  9987. *
  9988. * Return: true if work posted to worker thread, otherwise false.
  9989. **/
  9990. static bool
  9991. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  9992. {
  9993. struct lpfc_cq_event *cq_event;
  9994. unsigned long iflags;
  9995. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9996. "0392 Async Event: word0:x%x, word1:x%x, "
  9997. "word2:x%x, word3:x%x\n", mcqe->word0,
  9998. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  9999. /* Allocate a new internal CQ_EVENT entry */
  10000. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10001. if (!cq_event) {
  10002. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10003. "0394 Failed to allocate CQ_EVENT entry\n");
  10004. return false;
  10005. }
  10006. /* Move the CQE into an asynchronous event entry */
  10007. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  10008. spin_lock_irqsave(&phba->hbalock, iflags);
  10009. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  10010. /* Set the async event flag */
  10011. phba->hba_flag |= ASYNC_EVENT;
  10012. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10013. return true;
  10014. }
  10015. /**
  10016. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  10017. * @phba: Pointer to HBA context object.
  10018. * @cqe: Pointer to mailbox completion queue entry.
  10019. *
  10020. * This routine process a mailbox completion queue entry with mailbox
  10021. * completion event.
  10022. *
  10023. * Return: true if work posted to worker thread, otherwise false.
  10024. **/
  10025. static bool
  10026. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10027. {
  10028. uint32_t mcqe_status;
  10029. MAILBOX_t *mbox, *pmbox;
  10030. struct lpfc_mqe *mqe;
  10031. struct lpfc_vport *vport;
  10032. struct lpfc_nodelist *ndlp;
  10033. struct lpfc_dmabuf *mp;
  10034. unsigned long iflags;
  10035. LPFC_MBOXQ_t *pmb;
  10036. bool workposted = false;
  10037. int rc;
  10038. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  10039. if (!bf_get(lpfc_trailer_completed, mcqe))
  10040. goto out_no_mqe_complete;
  10041. /* Get the reference to the active mbox command */
  10042. spin_lock_irqsave(&phba->hbalock, iflags);
  10043. pmb = phba->sli.mbox_active;
  10044. if (unlikely(!pmb)) {
  10045. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10046. "1832 No pending MBOX command to handle\n");
  10047. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10048. goto out_no_mqe_complete;
  10049. }
  10050. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10051. mqe = &pmb->u.mqe;
  10052. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  10053. mbox = phba->mbox;
  10054. vport = pmb->vport;
  10055. /* Reset heartbeat timer */
  10056. phba->last_completion_time = jiffies;
  10057. del_timer(&phba->sli.mbox_tmo);
  10058. /* Move mbox data to caller's mailbox region, do endian swapping */
  10059. if (pmb->mbox_cmpl && mbox)
  10060. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  10061. /*
  10062. * For mcqe errors, conditionally move a modified error code to
  10063. * the mbox so that the error will not be missed.
  10064. */
  10065. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  10066. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  10067. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  10068. bf_set(lpfc_mqe_status, mqe,
  10069. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  10070. }
  10071. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10072. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10073. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  10074. "MBOX dflt rpi: status:x%x rpi:x%x",
  10075. mcqe_status,
  10076. pmbox->un.varWords[0], 0);
  10077. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  10078. mp = (struct lpfc_dmabuf *)(pmb->context1);
  10079. ndlp = (struct lpfc_nodelist *)pmb->context2;
  10080. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  10081. * RID of the PPI using the same mbox buffer.
  10082. */
  10083. lpfc_unreg_login(phba, vport->vpi,
  10084. pmbox->un.varWords[0], pmb);
  10085. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  10086. pmb->context1 = mp;
  10087. pmb->context2 = ndlp;
  10088. pmb->vport = vport;
  10089. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  10090. if (rc != MBX_BUSY)
  10091. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10092. LOG_SLI, "0385 rc should "
  10093. "have been MBX_BUSY\n");
  10094. if (rc != MBX_NOT_FINISHED)
  10095. goto send_current_mbox;
  10096. }
  10097. }
  10098. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  10099. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  10100. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  10101. /* There is mailbox completion work to do */
  10102. spin_lock_irqsave(&phba->hbalock, iflags);
  10103. __lpfc_mbox_cmpl_put(phba, pmb);
  10104. phba->work_ha |= HA_MBATT;
  10105. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10106. workposted = true;
  10107. send_current_mbox:
  10108. spin_lock_irqsave(&phba->hbalock, iflags);
  10109. /* Release the mailbox command posting token */
  10110. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  10111. /* Setting active mailbox pointer need to be in sync to flag clear */
  10112. phba->sli.mbox_active = NULL;
  10113. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10114. /* Wake up worker thread to post the next pending mailbox command */
  10115. lpfc_worker_wake_up(phba);
  10116. out_no_mqe_complete:
  10117. if (bf_get(lpfc_trailer_consumed, mcqe))
  10118. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  10119. return workposted;
  10120. }
  10121. /**
  10122. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  10123. * @phba: Pointer to HBA context object.
  10124. * @cqe: Pointer to mailbox completion queue entry.
  10125. *
  10126. * This routine process a mailbox completion queue entry, it invokes the
  10127. * proper mailbox complete handling or asynchrous event handling routine
  10128. * according to the MCQE's async bit.
  10129. *
  10130. * Return: true if work posted to worker thread, otherwise false.
  10131. **/
  10132. static bool
  10133. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  10134. {
  10135. struct lpfc_mcqe mcqe;
  10136. bool workposted;
  10137. /* Copy the mailbox MCQE and convert endian order as needed */
  10138. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  10139. /* Invoke the proper event handling routine */
  10140. if (!bf_get(lpfc_trailer_async, &mcqe))
  10141. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  10142. else
  10143. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  10144. return workposted;
  10145. }
  10146. /**
  10147. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  10148. * @phba: Pointer to HBA context object.
  10149. * @wcqe: Pointer to work-queue completion queue entry.
  10150. *
  10151. * This routine handles an ELS work-queue completion event.
  10152. *
  10153. * Return: true if work posted to worker thread, otherwise false.
  10154. **/
  10155. static bool
  10156. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  10157. struct lpfc_wcqe_complete *wcqe)
  10158. {
  10159. struct lpfc_iocbq *irspiocbq;
  10160. unsigned long iflags;
  10161. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  10162. /* Get an irspiocbq for later ELS response processing use */
  10163. irspiocbq = lpfc_sli_get_iocbq(phba);
  10164. if (!irspiocbq) {
  10165. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10166. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  10167. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  10168. pring->txq_cnt, phba->iocb_cnt,
  10169. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  10170. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  10171. return false;
  10172. }
  10173. /* Save off the slow-path queue event for work thread to process */
  10174. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  10175. spin_lock_irqsave(&phba->hbalock, iflags);
  10176. list_add_tail(&irspiocbq->cq_event.list,
  10177. &phba->sli4_hba.sp_queue_event);
  10178. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10179. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10180. return true;
  10181. }
  10182. /**
  10183. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  10184. * @phba: Pointer to HBA context object.
  10185. * @wcqe: Pointer to work-queue completion queue entry.
  10186. *
  10187. * This routine handles slow-path WQ entry comsumed event by invoking the
  10188. * proper WQ release routine to the slow-path WQ.
  10189. **/
  10190. static void
  10191. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  10192. struct lpfc_wcqe_release *wcqe)
  10193. {
  10194. /* sanity check on queue memory */
  10195. if (unlikely(!phba->sli4_hba.els_wq))
  10196. return;
  10197. /* Check for the slow-path ELS work queue */
  10198. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  10199. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  10200. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10201. else
  10202. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10203. "2579 Slow-path wqe consume event carries "
  10204. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  10205. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  10206. phba->sli4_hba.els_wq->queue_id);
  10207. }
  10208. /**
  10209. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  10210. * @phba: Pointer to HBA context object.
  10211. * @cq: Pointer to a WQ completion queue.
  10212. * @wcqe: Pointer to work-queue completion queue entry.
  10213. *
  10214. * This routine handles an XRI abort event.
  10215. *
  10216. * Return: true if work posted to worker thread, otherwise false.
  10217. **/
  10218. static bool
  10219. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  10220. struct lpfc_queue *cq,
  10221. struct sli4_wcqe_xri_aborted *wcqe)
  10222. {
  10223. bool workposted = false;
  10224. struct lpfc_cq_event *cq_event;
  10225. unsigned long iflags;
  10226. /* Allocate a new internal CQ_EVENT entry */
  10227. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10228. if (!cq_event) {
  10229. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10230. "0602 Failed to allocate CQ_EVENT entry\n");
  10231. return false;
  10232. }
  10233. /* Move the CQE into the proper xri abort event list */
  10234. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  10235. switch (cq->subtype) {
  10236. case LPFC_FCP:
  10237. spin_lock_irqsave(&phba->hbalock, iflags);
  10238. list_add_tail(&cq_event->list,
  10239. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  10240. /* Set the fcp xri abort event flag */
  10241. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  10242. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10243. workposted = true;
  10244. break;
  10245. case LPFC_ELS:
  10246. spin_lock_irqsave(&phba->hbalock, iflags);
  10247. list_add_tail(&cq_event->list,
  10248. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  10249. /* Set the els xri abort event flag */
  10250. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  10251. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10252. workposted = true;
  10253. break;
  10254. default:
  10255. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10256. "0603 Invalid work queue CQE subtype (x%x)\n",
  10257. cq->subtype);
  10258. workposted = false;
  10259. break;
  10260. }
  10261. return workposted;
  10262. }
  10263. /**
  10264. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  10265. * @phba: Pointer to HBA context object.
  10266. * @rcqe: Pointer to receive-queue completion queue entry.
  10267. *
  10268. * This routine process a receive-queue completion queue entry.
  10269. *
  10270. * Return: true if work posted to worker thread, otherwise false.
  10271. **/
  10272. static bool
  10273. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  10274. {
  10275. bool workposted = false;
  10276. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  10277. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  10278. struct hbq_dmabuf *dma_buf;
  10279. uint32_t status, rq_id;
  10280. unsigned long iflags;
  10281. /* sanity check on queue memory */
  10282. if (unlikely(!hrq) || unlikely(!drq))
  10283. return workposted;
  10284. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  10285. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  10286. else
  10287. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  10288. if (rq_id != hrq->queue_id)
  10289. goto out;
  10290. status = bf_get(lpfc_rcqe_status, rcqe);
  10291. switch (status) {
  10292. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  10293. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10294. "2537 Receive Frame Truncated!!\n");
  10295. case FC_STATUS_RQ_SUCCESS:
  10296. lpfc_sli4_rq_release(hrq, drq);
  10297. spin_lock_irqsave(&phba->hbalock, iflags);
  10298. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  10299. if (!dma_buf) {
  10300. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10301. goto out;
  10302. }
  10303. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  10304. /* save off the frame for the word thread to process */
  10305. list_add_tail(&dma_buf->cq_event.list,
  10306. &phba->sli4_hba.sp_queue_event);
  10307. /* Frame received */
  10308. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10309. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10310. workposted = true;
  10311. break;
  10312. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  10313. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  10314. /* Post more buffers if possible */
  10315. spin_lock_irqsave(&phba->hbalock, iflags);
  10316. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  10317. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10318. workposted = true;
  10319. break;
  10320. }
  10321. out:
  10322. return workposted;
  10323. }
  10324. /**
  10325. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  10326. * @phba: Pointer to HBA context object.
  10327. * @cq: Pointer to the completion queue.
  10328. * @wcqe: Pointer to a completion queue entry.
  10329. *
  10330. * This routine process a slow-path work-queue or receive queue completion queue
  10331. * entry.
  10332. *
  10333. * Return: true if work posted to worker thread, otherwise false.
  10334. **/
  10335. static bool
  10336. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10337. struct lpfc_cqe *cqe)
  10338. {
  10339. struct lpfc_cqe cqevt;
  10340. bool workposted = false;
  10341. /* Copy the work queue CQE and convert endian order if needed */
  10342. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  10343. /* Check and process for different type of WCQE and dispatch */
  10344. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  10345. case CQE_CODE_COMPL_WQE:
  10346. /* Process the WQ/RQ complete event */
  10347. phba->last_completion_time = jiffies;
  10348. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  10349. (struct lpfc_wcqe_complete *)&cqevt);
  10350. break;
  10351. case CQE_CODE_RELEASE_WQE:
  10352. /* Process the WQ release event */
  10353. lpfc_sli4_sp_handle_rel_wcqe(phba,
  10354. (struct lpfc_wcqe_release *)&cqevt);
  10355. break;
  10356. case CQE_CODE_XRI_ABORTED:
  10357. /* Process the WQ XRI abort event */
  10358. phba->last_completion_time = jiffies;
  10359. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10360. (struct sli4_wcqe_xri_aborted *)&cqevt);
  10361. break;
  10362. case CQE_CODE_RECEIVE:
  10363. case CQE_CODE_RECEIVE_V1:
  10364. /* Process the RQ event */
  10365. phba->last_completion_time = jiffies;
  10366. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  10367. (struct lpfc_rcqe *)&cqevt);
  10368. break;
  10369. default:
  10370. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10371. "0388 Not a valid WCQE code: x%x\n",
  10372. bf_get(lpfc_cqe_code, &cqevt));
  10373. break;
  10374. }
  10375. return workposted;
  10376. }
  10377. /**
  10378. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  10379. * @phba: Pointer to HBA context object.
  10380. * @eqe: Pointer to fast-path event queue entry.
  10381. *
  10382. * This routine process a event queue entry from the slow-path event queue.
  10383. * It will check the MajorCode and MinorCode to determine this is for a
  10384. * completion event on a completion queue, if not, an error shall be logged
  10385. * and just return. Otherwise, it will get to the corresponding completion
  10386. * queue and process all the entries on that completion queue, rearm the
  10387. * completion queue, and then return.
  10388. *
  10389. **/
  10390. static void
  10391. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  10392. {
  10393. struct lpfc_queue *cq = NULL, *childq, *speq;
  10394. struct lpfc_cqe *cqe;
  10395. bool workposted = false;
  10396. int ecount = 0;
  10397. uint16_t cqid;
  10398. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  10399. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10400. "0359 Not a valid slow-path completion "
  10401. "event: majorcode=x%x, minorcode=x%x\n",
  10402. bf_get_le32(lpfc_eqe_major_code, eqe),
  10403. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10404. return;
  10405. }
  10406. /* Get the reference to the corresponding CQ */
  10407. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10408. /* Search for completion queue pointer matching this cqid */
  10409. speq = phba->sli4_hba.sp_eq;
  10410. /* sanity check on queue memory */
  10411. if (unlikely(!speq))
  10412. return;
  10413. list_for_each_entry(childq, &speq->child_list, list) {
  10414. if (childq->queue_id == cqid) {
  10415. cq = childq;
  10416. break;
  10417. }
  10418. }
  10419. if (unlikely(!cq)) {
  10420. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10421. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10422. "0365 Slow-path CQ identifier "
  10423. "(%d) does not exist\n", cqid);
  10424. return;
  10425. }
  10426. /* Process all the entries to the CQ */
  10427. switch (cq->type) {
  10428. case LPFC_MCQ:
  10429. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10430. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  10431. if (!(++ecount % cq->entry_repost))
  10432. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10433. }
  10434. break;
  10435. case LPFC_WCQ:
  10436. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10437. if (cq->subtype == LPFC_FCP)
  10438. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  10439. cqe);
  10440. else
  10441. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  10442. cqe);
  10443. if (!(++ecount % cq->entry_repost))
  10444. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10445. }
  10446. break;
  10447. default:
  10448. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10449. "0370 Invalid completion queue type (%d)\n",
  10450. cq->type);
  10451. return;
  10452. }
  10453. /* Catch the no cq entry condition, log an error */
  10454. if (unlikely(ecount == 0))
  10455. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10456. "0371 No entry from the CQ: identifier "
  10457. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  10458. /* In any case, flash and re-arm the RCQ */
  10459. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10460. /* wake up worker thread if there are works to be done */
  10461. if (workposted)
  10462. lpfc_worker_wake_up(phba);
  10463. }
  10464. /**
  10465. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  10466. * @eqe: Pointer to fast-path completion queue entry.
  10467. *
  10468. * This routine process a fast-path work queue completion entry from fast-path
  10469. * event queue for FCP command response completion.
  10470. **/
  10471. static void
  10472. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  10473. struct lpfc_wcqe_complete *wcqe)
  10474. {
  10475. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  10476. struct lpfc_iocbq *cmdiocbq;
  10477. struct lpfc_iocbq irspiocbq;
  10478. unsigned long iflags;
  10479. spin_lock_irqsave(&phba->hbalock, iflags);
  10480. pring->stats.iocb_event++;
  10481. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10482. /* Check for response status */
  10483. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  10484. /* If resource errors reported from HBA, reduce queue
  10485. * depth of the SCSI device.
  10486. */
  10487. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  10488. IOSTAT_LOCAL_REJECT) &&
  10489. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  10490. phba->lpfc_rampdown_queue_depth(phba);
  10491. }
  10492. /* Log the error status */
  10493. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10494. "0373 FCP complete error: status=x%x, "
  10495. "hw_status=x%x, total_data_specified=%d, "
  10496. "parameter=x%x, word3=x%x\n",
  10497. bf_get(lpfc_wcqe_c_status, wcqe),
  10498. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  10499. wcqe->total_data_placed, wcqe->parameter,
  10500. wcqe->word3);
  10501. }
  10502. /* Look up the FCP command IOCB and create pseudo response IOCB */
  10503. spin_lock_irqsave(&phba->hbalock, iflags);
  10504. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10505. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10506. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10507. if (unlikely(!cmdiocbq)) {
  10508. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10509. "0374 FCP complete with no corresponding "
  10510. "cmdiocb: iotag (%d)\n",
  10511. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10512. return;
  10513. }
  10514. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  10515. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10516. "0375 FCP cmdiocb not callback function "
  10517. "iotag: (%d)\n",
  10518. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10519. return;
  10520. }
  10521. /* Fake the irspiocb and copy necessary response information */
  10522. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  10523. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  10524. spin_lock_irqsave(&phba->hbalock, iflags);
  10525. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  10526. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10527. }
  10528. /* Pass the cmd_iocb and the rsp state to the upper layer */
  10529. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  10530. }
  10531. /**
  10532. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  10533. * @phba: Pointer to HBA context object.
  10534. * @cq: Pointer to completion queue.
  10535. * @wcqe: Pointer to work-queue completion queue entry.
  10536. *
  10537. * This routine handles an fast-path WQ entry comsumed event by invoking the
  10538. * proper WQ release routine to the slow-path WQ.
  10539. **/
  10540. static void
  10541. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10542. struct lpfc_wcqe_release *wcqe)
  10543. {
  10544. struct lpfc_queue *childwq;
  10545. bool wqid_matched = false;
  10546. uint16_t fcp_wqid;
  10547. /* Check for fast-path FCP work queue release */
  10548. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  10549. list_for_each_entry(childwq, &cq->child_list, list) {
  10550. if (childwq->queue_id == fcp_wqid) {
  10551. lpfc_sli4_wq_release(childwq,
  10552. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10553. wqid_matched = true;
  10554. break;
  10555. }
  10556. }
  10557. /* Report warning log message if no match found */
  10558. if (wqid_matched != true)
  10559. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10560. "2580 Fast-path wqe consume event carries "
  10561. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  10562. }
  10563. /**
  10564. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  10565. * @cq: Pointer to the completion queue.
  10566. * @eqe: Pointer to fast-path completion queue entry.
  10567. *
  10568. * This routine process a fast-path work queue completion entry from fast-path
  10569. * event queue for FCP command response completion.
  10570. **/
  10571. static int
  10572. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10573. struct lpfc_cqe *cqe)
  10574. {
  10575. struct lpfc_wcqe_release wcqe;
  10576. bool workposted = false;
  10577. /* Copy the work queue CQE and convert endian order if needed */
  10578. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  10579. /* Check and process for different type of WCQE and dispatch */
  10580. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  10581. case CQE_CODE_COMPL_WQE:
  10582. /* Process the WQ complete event */
  10583. phba->last_completion_time = jiffies;
  10584. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  10585. (struct lpfc_wcqe_complete *)&wcqe);
  10586. break;
  10587. case CQE_CODE_RELEASE_WQE:
  10588. /* Process the WQ release event */
  10589. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  10590. (struct lpfc_wcqe_release *)&wcqe);
  10591. break;
  10592. case CQE_CODE_XRI_ABORTED:
  10593. /* Process the WQ XRI abort event */
  10594. phba->last_completion_time = jiffies;
  10595. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10596. (struct sli4_wcqe_xri_aborted *)&wcqe);
  10597. break;
  10598. default:
  10599. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10600. "0144 Not a valid WCQE code: x%x\n",
  10601. bf_get(lpfc_wcqe_c_code, &wcqe));
  10602. break;
  10603. }
  10604. return workposted;
  10605. }
  10606. /**
  10607. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  10608. * @phba: Pointer to HBA context object.
  10609. * @eqe: Pointer to fast-path event queue entry.
  10610. *
  10611. * This routine process a event queue entry from the fast-path event queue.
  10612. * It will check the MajorCode and MinorCode to determine this is for a
  10613. * completion event on a completion queue, if not, an error shall be logged
  10614. * and just return. Otherwise, it will get to the corresponding completion
  10615. * queue and process all the entries on the completion queue, rearm the
  10616. * completion queue, and then return.
  10617. **/
  10618. static void
  10619. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10620. uint32_t fcp_cqidx)
  10621. {
  10622. struct lpfc_queue *cq;
  10623. struct lpfc_cqe *cqe;
  10624. bool workposted = false;
  10625. uint16_t cqid;
  10626. int ecount = 0;
  10627. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  10628. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10629. "0366 Not a valid fast-path completion "
  10630. "event: majorcode=x%x, minorcode=x%x\n",
  10631. bf_get_le32(lpfc_eqe_major_code, eqe),
  10632. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10633. return;
  10634. }
  10635. if (unlikely(!phba->sli4_hba.fcp_cq)) {
  10636. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10637. "3146 Fast-path completion queues "
  10638. "does not exist\n");
  10639. return;
  10640. }
  10641. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  10642. if (unlikely(!cq)) {
  10643. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10644. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10645. "0367 Fast-path completion queue "
  10646. "(%d) does not exist\n", fcp_cqidx);
  10647. return;
  10648. }
  10649. /* Get the reference to the corresponding CQ */
  10650. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10651. if (unlikely(cqid != cq->queue_id)) {
  10652. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10653. "0368 Miss-matched fast-path completion "
  10654. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  10655. cqid, cq->queue_id);
  10656. return;
  10657. }
  10658. /* Process all the entries to the CQ */
  10659. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10660. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  10661. if (!(++ecount % cq->entry_repost))
  10662. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10663. }
  10664. /* Catch the no cq entry condition */
  10665. if (unlikely(ecount == 0))
  10666. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10667. "0369 No entry from fast-path completion "
  10668. "queue fcpcqid=%d\n", cq->queue_id);
  10669. /* In any case, flash and re-arm the CQ */
  10670. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10671. /* wake up worker thread if there are works to be done */
  10672. if (workposted)
  10673. lpfc_worker_wake_up(phba);
  10674. }
  10675. static void
  10676. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10677. {
  10678. struct lpfc_eqe *eqe;
  10679. /* walk all the EQ entries and drop on the floor */
  10680. while ((eqe = lpfc_sli4_eq_get(eq)))
  10681. ;
  10682. /* Clear and re-arm the EQ */
  10683. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  10684. }
  10685. /**
  10686. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  10687. * @irq: Interrupt number.
  10688. * @dev_id: The device context pointer.
  10689. *
  10690. * This function is directly called from the PCI layer as an interrupt
  10691. * service routine when device with SLI-4 interface spec is enabled with
  10692. * MSI-X multi-message interrupt mode and there are slow-path events in
  10693. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  10694. * interrupt mode, this function is called as part of the device-level
  10695. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  10696. * undergoing initialization, the interrupt handler will not process the
  10697. * interrupt. The link attention and ELS ring attention events are handled
  10698. * by the worker thread. The interrupt handler signals the worker thread
  10699. * and returns for these events. This function is called without any lock
  10700. * held. It gets the hbalock to access and update SLI data structures.
  10701. *
  10702. * This function returns IRQ_HANDLED when interrupt is handled else it
  10703. * returns IRQ_NONE.
  10704. **/
  10705. irqreturn_t
  10706. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  10707. {
  10708. struct lpfc_hba *phba;
  10709. struct lpfc_queue *speq;
  10710. struct lpfc_eqe *eqe;
  10711. unsigned long iflag;
  10712. int ecount = 0;
  10713. /*
  10714. * Get the driver's phba structure from the dev_id
  10715. */
  10716. phba = (struct lpfc_hba *)dev_id;
  10717. if (unlikely(!phba))
  10718. return IRQ_NONE;
  10719. /* Get to the EQ struct associated with this vector */
  10720. speq = phba->sli4_hba.sp_eq;
  10721. if (unlikely(!speq))
  10722. return IRQ_NONE;
  10723. /* Check device state for handling interrupt */
  10724. if (unlikely(lpfc_intr_state_check(phba))) {
  10725. /* Check again for link_state with lock held */
  10726. spin_lock_irqsave(&phba->hbalock, iflag);
  10727. if (phba->link_state < LPFC_LINK_DOWN)
  10728. /* Flush, clear interrupt, and rearm the EQ */
  10729. lpfc_sli4_eq_flush(phba, speq);
  10730. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10731. return IRQ_NONE;
  10732. }
  10733. /*
  10734. * Process all the event on FCP slow-path EQ
  10735. */
  10736. while ((eqe = lpfc_sli4_eq_get(speq))) {
  10737. lpfc_sli4_sp_handle_eqe(phba, eqe);
  10738. if (!(++ecount % speq->entry_repost))
  10739. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  10740. }
  10741. /* Always clear and re-arm the slow-path EQ */
  10742. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  10743. /* Catch the no cq entry condition */
  10744. if (unlikely(ecount == 0)) {
  10745. if (phba->intr_type == MSIX)
  10746. /* MSI-X treated interrupt served as no EQ share INT */
  10747. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10748. "0357 MSI-X interrupt with no EQE\n");
  10749. else
  10750. /* Non MSI-X treated on interrupt as EQ share INT */
  10751. return IRQ_NONE;
  10752. }
  10753. return IRQ_HANDLED;
  10754. } /* lpfc_sli4_sp_intr_handler */
  10755. /**
  10756. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  10757. * @irq: Interrupt number.
  10758. * @dev_id: The device context pointer.
  10759. *
  10760. * This function is directly called from the PCI layer as an interrupt
  10761. * service routine when device with SLI-4 interface spec is enabled with
  10762. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10763. * ring event in the HBA. However, when the device is enabled with either
  10764. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10765. * device-level interrupt handler. When the PCI slot is in error recovery
  10766. * or the HBA is undergoing initialization, the interrupt handler will not
  10767. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10768. * the intrrupt context. This function is called without any lock held.
  10769. * It gets the hbalock to access and update SLI data structures. Note that,
  10770. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  10771. * equal to that of FCP CQ index.
  10772. *
  10773. * This function returns IRQ_HANDLED when interrupt is handled else it
  10774. * returns IRQ_NONE.
  10775. **/
  10776. irqreturn_t
  10777. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  10778. {
  10779. struct lpfc_hba *phba;
  10780. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  10781. struct lpfc_queue *fpeq;
  10782. struct lpfc_eqe *eqe;
  10783. unsigned long iflag;
  10784. int ecount = 0;
  10785. uint32_t fcp_eqidx;
  10786. /* Get the driver's phba structure from the dev_id */
  10787. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  10788. phba = fcp_eq_hdl->phba;
  10789. fcp_eqidx = fcp_eq_hdl->idx;
  10790. if (unlikely(!phba))
  10791. return IRQ_NONE;
  10792. if (unlikely(!phba->sli4_hba.fp_eq))
  10793. return IRQ_NONE;
  10794. /* Get to the EQ struct associated with this vector */
  10795. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  10796. if (unlikely(!fpeq))
  10797. return IRQ_NONE;
  10798. /* Check device state for handling interrupt */
  10799. if (unlikely(lpfc_intr_state_check(phba))) {
  10800. /* Check again for link_state with lock held */
  10801. spin_lock_irqsave(&phba->hbalock, iflag);
  10802. if (phba->link_state < LPFC_LINK_DOWN)
  10803. /* Flush, clear interrupt, and rearm the EQ */
  10804. lpfc_sli4_eq_flush(phba, fpeq);
  10805. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10806. return IRQ_NONE;
  10807. }
  10808. /*
  10809. * Process all the event on FCP fast-path EQ
  10810. */
  10811. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  10812. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  10813. if (!(++ecount % fpeq->entry_repost))
  10814. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  10815. }
  10816. /* Always clear and re-arm the fast-path EQ */
  10817. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  10818. if (unlikely(ecount == 0)) {
  10819. if (phba->intr_type == MSIX)
  10820. /* MSI-X treated interrupt served as no EQ share INT */
  10821. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10822. "0358 MSI-X interrupt with no EQE\n");
  10823. else
  10824. /* Non MSI-X treated on interrupt as EQ share INT */
  10825. return IRQ_NONE;
  10826. }
  10827. return IRQ_HANDLED;
  10828. } /* lpfc_sli4_fp_intr_handler */
  10829. /**
  10830. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  10831. * @irq: Interrupt number.
  10832. * @dev_id: The device context pointer.
  10833. *
  10834. * This function is the device-level interrupt handler to device with SLI-4
  10835. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  10836. * interrupt mode is enabled and there is an event in the HBA which requires
  10837. * driver attention. This function invokes the slow-path interrupt attention
  10838. * handling function and fast-path interrupt attention handling function in
  10839. * turn to process the relevant HBA attention events. This function is called
  10840. * without any lock held. It gets the hbalock to access and update SLI data
  10841. * structures.
  10842. *
  10843. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10844. * returns IRQ_NONE.
  10845. **/
  10846. irqreturn_t
  10847. lpfc_sli4_intr_handler(int irq, void *dev_id)
  10848. {
  10849. struct lpfc_hba *phba;
  10850. irqreturn_t sp_irq_rc, fp_irq_rc;
  10851. bool fp_handled = false;
  10852. uint32_t fcp_eqidx;
  10853. /* Get the driver's phba structure from the dev_id */
  10854. phba = (struct lpfc_hba *)dev_id;
  10855. if (unlikely(!phba))
  10856. return IRQ_NONE;
  10857. /*
  10858. * Invokes slow-path host attention interrupt handling as appropriate.
  10859. */
  10860. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  10861. /*
  10862. * Invoke fast-path host attention interrupt handling as appropriate.
  10863. */
  10864. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  10865. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  10866. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  10867. if (fp_irq_rc == IRQ_HANDLED)
  10868. fp_handled |= true;
  10869. }
  10870. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  10871. } /* lpfc_sli4_intr_handler */
  10872. /**
  10873. * lpfc_sli4_queue_free - free a queue structure and associated memory
  10874. * @queue: The queue structure to free.
  10875. *
  10876. * This function frees a queue structure and the DMAable memory used for
  10877. * the host resident queue. This function must be called after destroying the
  10878. * queue on the HBA.
  10879. **/
  10880. void
  10881. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  10882. {
  10883. struct lpfc_dmabuf *dmabuf;
  10884. if (!queue)
  10885. return;
  10886. while (!list_empty(&queue->page_list)) {
  10887. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  10888. list);
  10889. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  10890. dmabuf->virt, dmabuf->phys);
  10891. kfree(dmabuf);
  10892. }
  10893. kfree(queue);
  10894. return;
  10895. }
  10896. /**
  10897. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  10898. * @phba: The HBA that this queue is being created on.
  10899. * @entry_size: The size of each queue entry for this queue.
  10900. * @entry count: The number of entries that this queue will handle.
  10901. *
  10902. * This function allocates a queue structure and the DMAable memory used for
  10903. * the host resident queue. This function must be called before creating the
  10904. * queue on the HBA.
  10905. **/
  10906. struct lpfc_queue *
  10907. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  10908. uint32_t entry_count)
  10909. {
  10910. struct lpfc_queue *queue;
  10911. struct lpfc_dmabuf *dmabuf;
  10912. int x, total_qe_count;
  10913. void *dma_pointer;
  10914. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10915. if (!phba->sli4_hba.pc_sli4_params.supported)
  10916. hw_page_size = SLI4_PAGE_SIZE;
  10917. queue = kzalloc(sizeof(struct lpfc_queue) +
  10918. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  10919. if (!queue)
  10920. return NULL;
  10921. queue->page_count = (ALIGN(entry_size * entry_count,
  10922. hw_page_size))/hw_page_size;
  10923. INIT_LIST_HEAD(&queue->list);
  10924. INIT_LIST_HEAD(&queue->page_list);
  10925. INIT_LIST_HEAD(&queue->child_list);
  10926. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  10927. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  10928. if (!dmabuf)
  10929. goto out_fail;
  10930. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  10931. hw_page_size, &dmabuf->phys,
  10932. GFP_KERNEL);
  10933. if (!dmabuf->virt) {
  10934. kfree(dmabuf);
  10935. goto out_fail;
  10936. }
  10937. memset(dmabuf->virt, 0, hw_page_size);
  10938. dmabuf->buffer_tag = x;
  10939. list_add_tail(&dmabuf->list, &queue->page_list);
  10940. /* initialize queue's entry array */
  10941. dma_pointer = dmabuf->virt;
  10942. for (; total_qe_count < entry_count &&
  10943. dma_pointer < (hw_page_size + dmabuf->virt);
  10944. total_qe_count++, dma_pointer += entry_size) {
  10945. queue->qe[total_qe_count].address = dma_pointer;
  10946. }
  10947. }
  10948. queue->entry_size = entry_size;
  10949. queue->entry_count = entry_count;
  10950. /*
  10951. * entry_repost is calculated based on the number of entries in the
  10952. * queue. This works out except for RQs. If buffers are NOT initially
  10953. * posted for every RQE, entry_repost should be adjusted accordingly.
  10954. */
  10955. queue->entry_repost = (entry_count >> 3);
  10956. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  10957. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  10958. queue->phba = phba;
  10959. return queue;
  10960. out_fail:
  10961. lpfc_sli4_queue_free(queue);
  10962. return NULL;
  10963. }
  10964. /**
  10965. * lpfc_eq_create - Create an Event Queue on the HBA
  10966. * @phba: HBA structure that indicates port to create a queue on.
  10967. * @eq: The queue structure to use to create the event queue.
  10968. * @imax: The maximum interrupt per second limit.
  10969. *
  10970. * This function creates an event queue, as detailed in @eq, on a port,
  10971. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  10972. *
  10973. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  10974. * is used to get the entry count and entry size that are necessary to
  10975. * determine the number of pages to allocate and use for this queue. This
  10976. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  10977. * event queue. This function is asynchronous and will wait for the mailbox
  10978. * command to finish before continuing.
  10979. *
  10980. * On success this function will return a zero. If unable to allocate enough
  10981. * memory this function will return -ENOMEM. If the queue create mailbox command
  10982. * fails this function will return -ENXIO.
  10983. **/
  10984. uint32_t
  10985. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  10986. {
  10987. struct lpfc_mbx_eq_create *eq_create;
  10988. LPFC_MBOXQ_t *mbox;
  10989. int rc, length, status = 0;
  10990. struct lpfc_dmabuf *dmabuf;
  10991. uint32_t shdr_status, shdr_add_status;
  10992. union lpfc_sli4_cfg_shdr *shdr;
  10993. uint16_t dmult;
  10994. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10995. /* sanity check on queue memory */
  10996. if (!eq)
  10997. return -ENODEV;
  10998. if (!phba->sli4_hba.pc_sli4_params.supported)
  10999. hw_page_size = SLI4_PAGE_SIZE;
  11000. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11001. if (!mbox)
  11002. return -ENOMEM;
  11003. length = (sizeof(struct lpfc_mbx_eq_create) -
  11004. sizeof(struct lpfc_sli4_cfg_mhdr));
  11005. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11006. LPFC_MBOX_OPCODE_EQ_CREATE,
  11007. length, LPFC_SLI4_MBX_EMBED);
  11008. eq_create = &mbox->u.mqe.un.eq_create;
  11009. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  11010. eq->page_count);
  11011. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  11012. LPFC_EQE_SIZE);
  11013. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  11014. /* Calculate delay multiper from maximum interrupt per second */
  11015. dmult = LPFC_DMULT_CONST/imax - 1;
  11016. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  11017. dmult);
  11018. switch (eq->entry_count) {
  11019. default:
  11020. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11021. "0360 Unsupported EQ count. (%d)\n",
  11022. eq->entry_count);
  11023. if (eq->entry_count < 256)
  11024. return -EINVAL;
  11025. /* otherwise default to smallest count (drop through) */
  11026. case 256:
  11027. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11028. LPFC_EQ_CNT_256);
  11029. break;
  11030. case 512:
  11031. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11032. LPFC_EQ_CNT_512);
  11033. break;
  11034. case 1024:
  11035. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11036. LPFC_EQ_CNT_1024);
  11037. break;
  11038. case 2048:
  11039. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11040. LPFC_EQ_CNT_2048);
  11041. break;
  11042. case 4096:
  11043. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11044. LPFC_EQ_CNT_4096);
  11045. break;
  11046. }
  11047. list_for_each_entry(dmabuf, &eq->page_list, list) {
  11048. memset(dmabuf->virt, 0, hw_page_size);
  11049. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11050. putPaddrLow(dmabuf->phys);
  11051. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11052. putPaddrHigh(dmabuf->phys);
  11053. }
  11054. mbox->vport = phba->pport;
  11055. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11056. mbox->context1 = NULL;
  11057. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11058. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  11059. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11060. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11061. if (shdr_status || shdr_add_status || rc) {
  11062. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11063. "2500 EQ_CREATE mailbox failed with "
  11064. "status x%x add_status x%x, mbx status x%x\n",
  11065. shdr_status, shdr_add_status, rc);
  11066. status = -ENXIO;
  11067. }
  11068. eq->type = LPFC_EQ;
  11069. eq->subtype = LPFC_NONE;
  11070. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  11071. if (eq->queue_id == 0xFFFF)
  11072. status = -ENXIO;
  11073. eq->host_index = 0;
  11074. eq->hba_index = 0;
  11075. mempool_free(mbox, phba->mbox_mem_pool);
  11076. return status;
  11077. }
  11078. /**
  11079. * lpfc_cq_create - Create a Completion Queue on the HBA
  11080. * @phba: HBA structure that indicates port to create a queue on.
  11081. * @cq: The queue structure to use to create the completion queue.
  11082. * @eq: The event queue to bind this completion queue to.
  11083. *
  11084. * This function creates a completion queue, as detailed in @wq, on a port,
  11085. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  11086. *
  11087. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11088. * is used to get the entry count and entry size that are necessary to
  11089. * determine the number of pages to allocate and use for this queue. The @eq
  11090. * is used to indicate which event queue to bind this completion queue to. This
  11091. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  11092. * completion queue. This function is asynchronous and will wait for the mailbox
  11093. * command to finish before continuing.
  11094. *
  11095. * On success this function will return a zero. If unable to allocate enough
  11096. * memory this function will return -ENOMEM. If the queue create mailbox command
  11097. * fails this function will return -ENXIO.
  11098. **/
  11099. uint32_t
  11100. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11101. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  11102. {
  11103. struct lpfc_mbx_cq_create *cq_create;
  11104. struct lpfc_dmabuf *dmabuf;
  11105. LPFC_MBOXQ_t *mbox;
  11106. int rc, length, status = 0;
  11107. uint32_t shdr_status, shdr_add_status;
  11108. union lpfc_sli4_cfg_shdr *shdr;
  11109. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11110. /* sanity check on queue memory */
  11111. if (!cq || !eq)
  11112. return -ENODEV;
  11113. if (!phba->sli4_hba.pc_sli4_params.supported)
  11114. hw_page_size = SLI4_PAGE_SIZE;
  11115. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11116. if (!mbox)
  11117. return -ENOMEM;
  11118. length = (sizeof(struct lpfc_mbx_cq_create) -
  11119. sizeof(struct lpfc_sli4_cfg_mhdr));
  11120. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11121. LPFC_MBOX_OPCODE_CQ_CREATE,
  11122. length, LPFC_SLI4_MBX_EMBED);
  11123. cq_create = &mbox->u.mqe.un.cq_create;
  11124. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  11125. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  11126. cq->page_count);
  11127. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  11128. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  11129. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11130. phba->sli4_hba.pc_sli4_params.cqv);
  11131. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  11132. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  11133. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  11134. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  11135. eq->queue_id);
  11136. } else {
  11137. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  11138. eq->queue_id);
  11139. }
  11140. switch (cq->entry_count) {
  11141. default:
  11142. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11143. "0361 Unsupported CQ count. (%d)\n",
  11144. cq->entry_count);
  11145. if (cq->entry_count < 256)
  11146. return -EINVAL;
  11147. /* otherwise default to smallest count (drop through) */
  11148. case 256:
  11149. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11150. LPFC_CQ_CNT_256);
  11151. break;
  11152. case 512:
  11153. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11154. LPFC_CQ_CNT_512);
  11155. break;
  11156. case 1024:
  11157. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11158. LPFC_CQ_CNT_1024);
  11159. break;
  11160. }
  11161. list_for_each_entry(dmabuf, &cq->page_list, list) {
  11162. memset(dmabuf->virt, 0, hw_page_size);
  11163. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11164. putPaddrLow(dmabuf->phys);
  11165. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11166. putPaddrHigh(dmabuf->phys);
  11167. }
  11168. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11169. /* The IOCTL status is embedded in the mailbox subheader. */
  11170. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11171. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11172. if (shdr_status || shdr_add_status || rc) {
  11173. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11174. "2501 CQ_CREATE mailbox failed with "
  11175. "status x%x add_status x%x, mbx status x%x\n",
  11176. shdr_status, shdr_add_status, rc);
  11177. status = -ENXIO;
  11178. goto out;
  11179. }
  11180. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11181. if (cq->queue_id == 0xFFFF) {
  11182. status = -ENXIO;
  11183. goto out;
  11184. }
  11185. /* link the cq onto the parent eq child list */
  11186. list_add_tail(&cq->list, &eq->child_list);
  11187. /* Set up completion queue's type and subtype */
  11188. cq->type = type;
  11189. cq->subtype = subtype;
  11190. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11191. cq->assoc_qid = eq->queue_id;
  11192. cq->host_index = 0;
  11193. cq->hba_index = 0;
  11194. out:
  11195. mempool_free(mbox, phba->mbox_mem_pool);
  11196. return status;
  11197. }
  11198. /**
  11199. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  11200. * @phba: HBA structure that indicates port to create a queue on.
  11201. * @mq: The queue structure to use to create the mailbox queue.
  11202. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  11203. * @cq: The completion queue to associate with this cq.
  11204. *
  11205. * This function provides failback (fb) functionality when the
  11206. * mq_create_ext fails on older FW generations. It's purpose is identical
  11207. * to mq_create_ext otherwise.
  11208. *
  11209. * This routine cannot fail as all attributes were previously accessed and
  11210. * initialized in mq_create_ext.
  11211. **/
  11212. static void
  11213. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11214. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  11215. {
  11216. struct lpfc_mbx_mq_create *mq_create;
  11217. struct lpfc_dmabuf *dmabuf;
  11218. int length;
  11219. length = (sizeof(struct lpfc_mbx_mq_create) -
  11220. sizeof(struct lpfc_sli4_cfg_mhdr));
  11221. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11222. LPFC_MBOX_OPCODE_MQ_CREATE,
  11223. length, LPFC_SLI4_MBX_EMBED);
  11224. mq_create = &mbox->u.mqe.un.mq_create;
  11225. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  11226. mq->page_count);
  11227. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  11228. cq->queue_id);
  11229. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  11230. switch (mq->entry_count) {
  11231. case 16:
  11232. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11233. LPFC_MQ_RING_SIZE_16);
  11234. break;
  11235. case 32:
  11236. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11237. LPFC_MQ_RING_SIZE_32);
  11238. break;
  11239. case 64:
  11240. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11241. LPFC_MQ_RING_SIZE_64);
  11242. break;
  11243. case 128:
  11244. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11245. LPFC_MQ_RING_SIZE_128);
  11246. break;
  11247. }
  11248. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11249. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11250. putPaddrLow(dmabuf->phys);
  11251. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11252. putPaddrHigh(dmabuf->phys);
  11253. }
  11254. }
  11255. /**
  11256. * lpfc_mq_create - Create a mailbox Queue on the HBA
  11257. * @phba: HBA structure that indicates port to create a queue on.
  11258. * @mq: The queue structure to use to create the mailbox queue.
  11259. * @cq: The completion queue to associate with this cq.
  11260. * @subtype: The queue's subtype.
  11261. *
  11262. * This function creates a mailbox queue, as detailed in @mq, on a port,
  11263. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  11264. *
  11265. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11266. * is used to get the entry count and entry size that are necessary to
  11267. * determine the number of pages to allocate and use for this queue. This
  11268. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  11269. * mailbox queue. This function is asynchronous and will wait for the mailbox
  11270. * command to finish before continuing.
  11271. *
  11272. * On success this function will return a zero. If unable to allocate enough
  11273. * memory this function will return -ENOMEM. If the queue create mailbox command
  11274. * fails this function will return -ENXIO.
  11275. **/
  11276. int32_t
  11277. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11278. struct lpfc_queue *cq, uint32_t subtype)
  11279. {
  11280. struct lpfc_mbx_mq_create *mq_create;
  11281. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  11282. struct lpfc_dmabuf *dmabuf;
  11283. LPFC_MBOXQ_t *mbox;
  11284. int rc, length, status = 0;
  11285. uint32_t shdr_status, shdr_add_status;
  11286. union lpfc_sli4_cfg_shdr *shdr;
  11287. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11288. /* sanity check on queue memory */
  11289. if (!mq || !cq)
  11290. return -ENODEV;
  11291. if (!phba->sli4_hba.pc_sli4_params.supported)
  11292. hw_page_size = SLI4_PAGE_SIZE;
  11293. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11294. if (!mbox)
  11295. return -ENOMEM;
  11296. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  11297. sizeof(struct lpfc_sli4_cfg_mhdr));
  11298. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11299. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  11300. length, LPFC_SLI4_MBX_EMBED);
  11301. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  11302. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  11303. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  11304. &mq_create_ext->u.request, mq->page_count);
  11305. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  11306. &mq_create_ext->u.request, 1);
  11307. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  11308. &mq_create_ext->u.request, 1);
  11309. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  11310. &mq_create_ext->u.request, 1);
  11311. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  11312. &mq_create_ext->u.request, 1);
  11313. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  11314. &mq_create_ext->u.request, 1);
  11315. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  11316. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11317. phba->sli4_hba.pc_sli4_params.mqv);
  11318. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  11319. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  11320. cq->queue_id);
  11321. else
  11322. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  11323. cq->queue_id);
  11324. switch (mq->entry_count) {
  11325. default:
  11326. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11327. "0362 Unsupported MQ count. (%d)\n",
  11328. mq->entry_count);
  11329. if (mq->entry_count < 16)
  11330. return -EINVAL;
  11331. /* otherwise default to smallest count (drop through) */
  11332. case 16:
  11333. bf_set(lpfc_mq_context_ring_size,
  11334. &mq_create_ext->u.request.context,
  11335. LPFC_MQ_RING_SIZE_16);
  11336. break;
  11337. case 32:
  11338. bf_set(lpfc_mq_context_ring_size,
  11339. &mq_create_ext->u.request.context,
  11340. LPFC_MQ_RING_SIZE_32);
  11341. break;
  11342. case 64:
  11343. bf_set(lpfc_mq_context_ring_size,
  11344. &mq_create_ext->u.request.context,
  11345. LPFC_MQ_RING_SIZE_64);
  11346. break;
  11347. case 128:
  11348. bf_set(lpfc_mq_context_ring_size,
  11349. &mq_create_ext->u.request.context,
  11350. LPFC_MQ_RING_SIZE_128);
  11351. break;
  11352. }
  11353. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11354. memset(dmabuf->virt, 0, hw_page_size);
  11355. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  11356. putPaddrLow(dmabuf->phys);
  11357. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  11358. putPaddrHigh(dmabuf->phys);
  11359. }
  11360. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11361. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11362. &mq_create_ext->u.response);
  11363. if (rc != MBX_SUCCESS) {
  11364. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11365. "2795 MQ_CREATE_EXT failed with "
  11366. "status x%x. Failback to MQ_CREATE.\n",
  11367. rc);
  11368. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  11369. mq_create = &mbox->u.mqe.un.mq_create;
  11370. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11371. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  11372. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11373. &mq_create->u.response);
  11374. }
  11375. /* The IOCTL status is embedded in the mailbox subheader. */
  11376. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11377. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11378. if (shdr_status || shdr_add_status || rc) {
  11379. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11380. "2502 MQ_CREATE mailbox failed with "
  11381. "status x%x add_status x%x, mbx status x%x\n",
  11382. shdr_status, shdr_add_status, rc);
  11383. status = -ENXIO;
  11384. goto out;
  11385. }
  11386. if (mq->queue_id == 0xFFFF) {
  11387. status = -ENXIO;
  11388. goto out;
  11389. }
  11390. mq->type = LPFC_MQ;
  11391. mq->assoc_qid = cq->queue_id;
  11392. mq->subtype = subtype;
  11393. mq->host_index = 0;
  11394. mq->hba_index = 0;
  11395. /* link the mq onto the parent cq child list */
  11396. list_add_tail(&mq->list, &cq->child_list);
  11397. out:
  11398. mempool_free(mbox, phba->mbox_mem_pool);
  11399. return status;
  11400. }
  11401. /**
  11402. * lpfc_wq_create - Create a Work Queue on the HBA
  11403. * @phba: HBA structure that indicates port to create a queue on.
  11404. * @wq: The queue structure to use to create the work queue.
  11405. * @cq: The completion queue to bind this work queue to.
  11406. * @subtype: The subtype of the work queue indicating its functionality.
  11407. *
  11408. * This function creates a work queue, as detailed in @wq, on a port, described
  11409. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  11410. *
  11411. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  11412. * is used to get the entry count and entry size that are necessary to
  11413. * determine the number of pages to allocate and use for this queue. The @cq
  11414. * is used to indicate which completion queue to bind this work queue to. This
  11415. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  11416. * work queue. This function is asynchronous and will wait for the mailbox
  11417. * command to finish before continuing.
  11418. *
  11419. * On success this function will return a zero. If unable to allocate enough
  11420. * memory this function will return -ENOMEM. If the queue create mailbox command
  11421. * fails this function will return -ENXIO.
  11422. **/
  11423. uint32_t
  11424. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  11425. struct lpfc_queue *cq, uint32_t subtype)
  11426. {
  11427. struct lpfc_mbx_wq_create *wq_create;
  11428. struct lpfc_dmabuf *dmabuf;
  11429. LPFC_MBOXQ_t *mbox;
  11430. int rc, length, status = 0;
  11431. uint32_t shdr_status, shdr_add_status;
  11432. union lpfc_sli4_cfg_shdr *shdr;
  11433. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11434. struct dma_address *page;
  11435. /* sanity check on queue memory */
  11436. if (!wq || !cq)
  11437. return -ENODEV;
  11438. if (!phba->sli4_hba.pc_sli4_params.supported)
  11439. hw_page_size = SLI4_PAGE_SIZE;
  11440. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11441. if (!mbox)
  11442. return -ENOMEM;
  11443. length = (sizeof(struct lpfc_mbx_wq_create) -
  11444. sizeof(struct lpfc_sli4_cfg_mhdr));
  11445. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11446. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  11447. length, LPFC_SLI4_MBX_EMBED);
  11448. wq_create = &mbox->u.mqe.un.wq_create;
  11449. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  11450. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  11451. wq->page_count);
  11452. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  11453. cq->queue_id);
  11454. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11455. phba->sli4_hba.pc_sli4_params.wqv);
  11456. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  11457. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  11458. wq->entry_count);
  11459. switch (wq->entry_size) {
  11460. default:
  11461. case 64:
  11462. bf_set(lpfc_mbx_wq_create_wqe_size,
  11463. &wq_create->u.request_1,
  11464. LPFC_WQ_WQE_SIZE_64);
  11465. break;
  11466. case 128:
  11467. bf_set(lpfc_mbx_wq_create_wqe_size,
  11468. &wq_create->u.request_1,
  11469. LPFC_WQ_WQE_SIZE_128);
  11470. break;
  11471. }
  11472. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  11473. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11474. page = wq_create->u.request_1.page;
  11475. } else {
  11476. page = wq_create->u.request.page;
  11477. }
  11478. list_for_each_entry(dmabuf, &wq->page_list, list) {
  11479. memset(dmabuf->virt, 0, hw_page_size);
  11480. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  11481. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  11482. }
  11483. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11484. /* The IOCTL status is embedded in the mailbox subheader. */
  11485. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11486. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11487. if (shdr_status || shdr_add_status || rc) {
  11488. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11489. "2503 WQ_CREATE mailbox failed with "
  11490. "status x%x add_status x%x, mbx status x%x\n",
  11491. shdr_status, shdr_add_status, rc);
  11492. status = -ENXIO;
  11493. goto out;
  11494. }
  11495. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  11496. if (wq->queue_id == 0xFFFF) {
  11497. status = -ENXIO;
  11498. goto out;
  11499. }
  11500. wq->type = LPFC_WQ;
  11501. wq->assoc_qid = cq->queue_id;
  11502. wq->subtype = subtype;
  11503. wq->host_index = 0;
  11504. wq->hba_index = 0;
  11505. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  11506. /* link the wq onto the parent cq child list */
  11507. list_add_tail(&wq->list, &cq->child_list);
  11508. out:
  11509. mempool_free(mbox, phba->mbox_mem_pool);
  11510. return status;
  11511. }
  11512. /**
  11513. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  11514. * @phba: HBA structure that indicates port to create a queue on.
  11515. * @rq: The queue structure to use for the receive queue.
  11516. * @qno: The associated HBQ number
  11517. *
  11518. *
  11519. * For SLI4 we need to adjust the RQ repost value based on
  11520. * the number of buffers that are initially posted to the RQ.
  11521. */
  11522. void
  11523. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  11524. {
  11525. uint32_t cnt;
  11526. /* sanity check on queue memory */
  11527. if (!rq)
  11528. return;
  11529. cnt = lpfc_hbq_defs[qno]->entry_count;
  11530. /* Recalc repost for RQs based on buffers initially posted */
  11531. cnt = (cnt >> 3);
  11532. if (cnt < LPFC_QUEUE_MIN_REPOST)
  11533. cnt = LPFC_QUEUE_MIN_REPOST;
  11534. rq->entry_repost = cnt;
  11535. }
  11536. /**
  11537. * lpfc_rq_create - Create a Receive Queue on the HBA
  11538. * @phba: HBA structure that indicates port to create a queue on.
  11539. * @hrq: The queue structure to use to create the header receive queue.
  11540. * @drq: The queue structure to use to create the data receive queue.
  11541. * @cq: The completion queue to bind this work queue to.
  11542. *
  11543. * This function creates a receive buffer queue pair , as detailed in @hrq and
  11544. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  11545. * to the HBA.
  11546. *
  11547. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  11548. * struct is used to get the entry count that is necessary to determine the
  11549. * number of pages to use for this queue. The @cq is used to indicate which
  11550. * completion queue to bind received buffers that are posted to these queues to.
  11551. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  11552. * receive queue pair. This function is asynchronous and will wait for the
  11553. * mailbox command to finish before continuing.
  11554. *
  11555. * On success this function will return a zero. If unable to allocate enough
  11556. * memory this function will return -ENOMEM. If the queue create mailbox command
  11557. * fails this function will return -ENXIO.
  11558. **/
  11559. uint32_t
  11560. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11561. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  11562. {
  11563. struct lpfc_mbx_rq_create *rq_create;
  11564. struct lpfc_dmabuf *dmabuf;
  11565. LPFC_MBOXQ_t *mbox;
  11566. int rc, length, status = 0;
  11567. uint32_t shdr_status, shdr_add_status;
  11568. union lpfc_sli4_cfg_shdr *shdr;
  11569. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11570. /* sanity check on queue memory */
  11571. if (!hrq || !drq || !cq)
  11572. return -ENODEV;
  11573. if (!phba->sli4_hba.pc_sli4_params.supported)
  11574. hw_page_size = SLI4_PAGE_SIZE;
  11575. if (hrq->entry_count != drq->entry_count)
  11576. return -EINVAL;
  11577. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11578. if (!mbox)
  11579. return -ENOMEM;
  11580. length = (sizeof(struct lpfc_mbx_rq_create) -
  11581. sizeof(struct lpfc_sli4_cfg_mhdr));
  11582. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11583. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11584. length, LPFC_SLI4_MBX_EMBED);
  11585. rq_create = &mbox->u.mqe.un.rq_create;
  11586. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11587. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11588. phba->sli4_hba.pc_sli4_params.rqv);
  11589. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11590. bf_set(lpfc_rq_context_rqe_count_1,
  11591. &rq_create->u.request.context,
  11592. hrq->entry_count);
  11593. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  11594. bf_set(lpfc_rq_context_rqe_size,
  11595. &rq_create->u.request.context,
  11596. LPFC_RQE_SIZE_8);
  11597. bf_set(lpfc_rq_context_page_size,
  11598. &rq_create->u.request.context,
  11599. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11600. } else {
  11601. switch (hrq->entry_count) {
  11602. default:
  11603. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11604. "2535 Unsupported RQ count. (%d)\n",
  11605. hrq->entry_count);
  11606. if (hrq->entry_count < 512)
  11607. return -EINVAL;
  11608. /* otherwise default to smallest count (drop through) */
  11609. case 512:
  11610. bf_set(lpfc_rq_context_rqe_count,
  11611. &rq_create->u.request.context,
  11612. LPFC_RQ_RING_SIZE_512);
  11613. break;
  11614. case 1024:
  11615. bf_set(lpfc_rq_context_rqe_count,
  11616. &rq_create->u.request.context,
  11617. LPFC_RQ_RING_SIZE_1024);
  11618. break;
  11619. case 2048:
  11620. bf_set(lpfc_rq_context_rqe_count,
  11621. &rq_create->u.request.context,
  11622. LPFC_RQ_RING_SIZE_2048);
  11623. break;
  11624. case 4096:
  11625. bf_set(lpfc_rq_context_rqe_count,
  11626. &rq_create->u.request.context,
  11627. LPFC_RQ_RING_SIZE_4096);
  11628. break;
  11629. }
  11630. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11631. LPFC_HDR_BUF_SIZE);
  11632. }
  11633. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11634. cq->queue_id);
  11635. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11636. hrq->page_count);
  11637. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  11638. memset(dmabuf->virt, 0, hw_page_size);
  11639. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11640. putPaddrLow(dmabuf->phys);
  11641. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11642. putPaddrHigh(dmabuf->phys);
  11643. }
  11644. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11645. /* The IOCTL status is embedded in the mailbox subheader. */
  11646. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11647. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11648. if (shdr_status || shdr_add_status || rc) {
  11649. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11650. "2504 RQ_CREATE mailbox failed with "
  11651. "status x%x add_status x%x, mbx status x%x\n",
  11652. shdr_status, shdr_add_status, rc);
  11653. status = -ENXIO;
  11654. goto out;
  11655. }
  11656. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11657. if (hrq->queue_id == 0xFFFF) {
  11658. status = -ENXIO;
  11659. goto out;
  11660. }
  11661. hrq->type = LPFC_HRQ;
  11662. hrq->assoc_qid = cq->queue_id;
  11663. hrq->subtype = subtype;
  11664. hrq->host_index = 0;
  11665. hrq->hba_index = 0;
  11666. /* now create the data queue */
  11667. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11668. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11669. length, LPFC_SLI4_MBX_EMBED);
  11670. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11671. phba->sli4_hba.pc_sli4_params.rqv);
  11672. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11673. bf_set(lpfc_rq_context_rqe_count_1,
  11674. &rq_create->u.request.context, hrq->entry_count);
  11675. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  11676. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  11677. LPFC_RQE_SIZE_8);
  11678. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  11679. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11680. } else {
  11681. switch (drq->entry_count) {
  11682. default:
  11683. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11684. "2536 Unsupported RQ count. (%d)\n",
  11685. drq->entry_count);
  11686. if (drq->entry_count < 512)
  11687. return -EINVAL;
  11688. /* otherwise default to smallest count (drop through) */
  11689. case 512:
  11690. bf_set(lpfc_rq_context_rqe_count,
  11691. &rq_create->u.request.context,
  11692. LPFC_RQ_RING_SIZE_512);
  11693. break;
  11694. case 1024:
  11695. bf_set(lpfc_rq_context_rqe_count,
  11696. &rq_create->u.request.context,
  11697. LPFC_RQ_RING_SIZE_1024);
  11698. break;
  11699. case 2048:
  11700. bf_set(lpfc_rq_context_rqe_count,
  11701. &rq_create->u.request.context,
  11702. LPFC_RQ_RING_SIZE_2048);
  11703. break;
  11704. case 4096:
  11705. bf_set(lpfc_rq_context_rqe_count,
  11706. &rq_create->u.request.context,
  11707. LPFC_RQ_RING_SIZE_4096);
  11708. break;
  11709. }
  11710. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11711. LPFC_DATA_BUF_SIZE);
  11712. }
  11713. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11714. cq->queue_id);
  11715. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11716. drq->page_count);
  11717. list_for_each_entry(dmabuf, &drq->page_list, list) {
  11718. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11719. putPaddrLow(dmabuf->phys);
  11720. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11721. putPaddrHigh(dmabuf->phys);
  11722. }
  11723. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11724. /* The IOCTL status is embedded in the mailbox subheader. */
  11725. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11726. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11727. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11728. if (shdr_status || shdr_add_status || rc) {
  11729. status = -ENXIO;
  11730. goto out;
  11731. }
  11732. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11733. if (drq->queue_id == 0xFFFF) {
  11734. status = -ENXIO;
  11735. goto out;
  11736. }
  11737. drq->type = LPFC_DRQ;
  11738. drq->assoc_qid = cq->queue_id;
  11739. drq->subtype = subtype;
  11740. drq->host_index = 0;
  11741. drq->hba_index = 0;
  11742. /* link the header and data RQs onto the parent cq child list */
  11743. list_add_tail(&hrq->list, &cq->child_list);
  11744. list_add_tail(&drq->list, &cq->child_list);
  11745. out:
  11746. mempool_free(mbox, phba->mbox_mem_pool);
  11747. return status;
  11748. }
  11749. /**
  11750. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  11751. * @eq: The queue structure associated with the queue to destroy.
  11752. *
  11753. * This function destroys a queue, as detailed in @eq by sending an mailbox
  11754. * command, specific to the type of queue, to the HBA.
  11755. *
  11756. * The @eq struct is used to get the queue ID of the queue to destroy.
  11757. *
  11758. * On success this function will return a zero. If the queue destroy mailbox
  11759. * command fails this function will return -ENXIO.
  11760. **/
  11761. uint32_t
  11762. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  11763. {
  11764. LPFC_MBOXQ_t *mbox;
  11765. int rc, length, status = 0;
  11766. uint32_t shdr_status, shdr_add_status;
  11767. union lpfc_sli4_cfg_shdr *shdr;
  11768. /* sanity check on queue memory */
  11769. if (!eq)
  11770. return -ENODEV;
  11771. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  11772. if (!mbox)
  11773. return -ENOMEM;
  11774. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  11775. sizeof(struct lpfc_sli4_cfg_mhdr));
  11776. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11777. LPFC_MBOX_OPCODE_EQ_DESTROY,
  11778. length, LPFC_SLI4_MBX_EMBED);
  11779. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  11780. eq->queue_id);
  11781. mbox->vport = eq->phba->pport;
  11782. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11783. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  11784. /* The IOCTL status is embedded in the mailbox subheader. */
  11785. shdr = (union lpfc_sli4_cfg_shdr *)
  11786. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  11787. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11788. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11789. if (shdr_status || shdr_add_status || rc) {
  11790. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11791. "2505 EQ_DESTROY mailbox failed with "
  11792. "status x%x add_status x%x, mbx status x%x\n",
  11793. shdr_status, shdr_add_status, rc);
  11794. status = -ENXIO;
  11795. }
  11796. /* Remove eq from any list */
  11797. list_del_init(&eq->list);
  11798. mempool_free(mbox, eq->phba->mbox_mem_pool);
  11799. return status;
  11800. }
  11801. /**
  11802. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  11803. * @cq: The queue structure associated with the queue to destroy.
  11804. *
  11805. * This function destroys a queue, as detailed in @cq by sending an mailbox
  11806. * command, specific to the type of queue, to the HBA.
  11807. *
  11808. * The @cq struct is used to get the queue ID of the queue to destroy.
  11809. *
  11810. * On success this function will return a zero. If the queue destroy mailbox
  11811. * command fails this function will return -ENXIO.
  11812. **/
  11813. uint32_t
  11814. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  11815. {
  11816. LPFC_MBOXQ_t *mbox;
  11817. int rc, length, status = 0;
  11818. uint32_t shdr_status, shdr_add_status;
  11819. union lpfc_sli4_cfg_shdr *shdr;
  11820. /* sanity check on queue memory */
  11821. if (!cq)
  11822. return -ENODEV;
  11823. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  11824. if (!mbox)
  11825. return -ENOMEM;
  11826. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  11827. sizeof(struct lpfc_sli4_cfg_mhdr));
  11828. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11829. LPFC_MBOX_OPCODE_CQ_DESTROY,
  11830. length, LPFC_SLI4_MBX_EMBED);
  11831. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  11832. cq->queue_id);
  11833. mbox->vport = cq->phba->pport;
  11834. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11835. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  11836. /* The IOCTL status is embedded in the mailbox subheader. */
  11837. shdr = (union lpfc_sli4_cfg_shdr *)
  11838. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  11839. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11840. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11841. if (shdr_status || shdr_add_status || rc) {
  11842. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11843. "2506 CQ_DESTROY mailbox failed with "
  11844. "status x%x add_status x%x, mbx status x%x\n",
  11845. shdr_status, shdr_add_status, rc);
  11846. status = -ENXIO;
  11847. }
  11848. /* Remove cq from any list */
  11849. list_del_init(&cq->list);
  11850. mempool_free(mbox, cq->phba->mbox_mem_pool);
  11851. return status;
  11852. }
  11853. /**
  11854. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  11855. * @qm: The queue structure associated with the queue to destroy.
  11856. *
  11857. * This function destroys a queue, as detailed in @mq by sending an mailbox
  11858. * command, specific to the type of queue, to the HBA.
  11859. *
  11860. * The @mq struct is used to get the queue ID of the queue to destroy.
  11861. *
  11862. * On success this function will return a zero. If the queue destroy mailbox
  11863. * command fails this function will return -ENXIO.
  11864. **/
  11865. uint32_t
  11866. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  11867. {
  11868. LPFC_MBOXQ_t *mbox;
  11869. int rc, length, status = 0;
  11870. uint32_t shdr_status, shdr_add_status;
  11871. union lpfc_sli4_cfg_shdr *shdr;
  11872. /* sanity check on queue memory */
  11873. if (!mq)
  11874. return -ENODEV;
  11875. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  11876. if (!mbox)
  11877. return -ENOMEM;
  11878. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  11879. sizeof(struct lpfc_sli4_cfg_mhdr));
  11880. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11881. LPFC_MBOX_OPCODE_MQ_DESTROY,
  11882. length, LPFC_SLI4_MBX_EMBED);
  11883. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  11884. mq->queue_id);
  11885. mbox->vport = mq->phba->pport;
  11886. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11887. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  11888. /* The IOCTL status is embedded in the mailbox subheader. */
  11889. shdr = (union lpfc_sli4_cfg_shdr *)
  11890. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  11891. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11892. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11893. if (shdr_status || shdr_add_status || rc) {
  11894. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11895. "2507 MQ_DESTROY mailbox failed with "
  11896. "status x%x add_status x%x, mbx status x%x\n",
  11897. shdr_status, shdr_add_status, rc);
  11898. status = -ENXIO;
  11899. }
  11900. /* Remove mq from any list */
  11901. list_del_init(&mq->list);
  11902. mempool_free(mbox, mq->phba->mbox_mem_pool);
  11903. return status;
  11904. }
  11905. /**
  11906. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  11907. * @wq: The queue structure associated with the queue to destroy.
  11908. *
  11909. * This function destroys a queue, as detailed in @wq by sending an mailbox
  11910. * command, specific to the type of queue, to the HBA.
  11911. *
  11912. * The @wq struct is used to get the queue ID of the queue to destroy.
  11913. *
  11914. * On success this function will return a zero. If the queue destroy mailbox
  11915. * command fails this function will return -ENXIO.
  11916. **/
  11917. uint32_t
  11918. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  11919. {
  11920. LPFC_MBOXQ_t *mbox;
  11921. int rc, length, status = 0;
  11922. uint32_t shdr_status, shdr_add_status;
  11923. union lpfc_sli4_cfg_shdr *shdr;
  11924. /* sanity check on queue memory */
  11925. if (!wq)
  11926. return -ENODEV;
  11927. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  11928. if (!mbox)
  11929. return -ENOMEM;
  11930. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  11931. sizeof(struct lpfc_sli4_cfg_mhdr));
  11932. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11933. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  11934. length, LPFC_SLI4_MBX_EMBED);
  11935. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  11936. wq->queue_id);
  11937. mbox->vport = wq->phba->pport;
  11938. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11939. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  11940. shdr = (union lpfc_sli4_cfg_shdr *)
  11941. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  11942. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11943. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11944. if (shdr_status || shdr_add_status || rc) {
  11945. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11946. "2508 WQ_DESTROY mailbox failed with "
  11947. "status x%x add_status x%x, mbx status x%x\n",
  11948. shdr_status, shdr_add_status, rc);
  11949. status = -ENXIO;
  11950. }
  11951. /* Remove wq from any list */
  11952. list_del_init(&wq->list);
  11953. mempool_free(mbox, wq->phba->mbox_mem_pool);
  11954. return status;
  11955. }
  11956. /**
  11957. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  11958. * @rq: The queue structure associated with the queue to destroy.
  11959. *
  11960. * This function destroys a queue, as detailed in @rq by sending an mailbox
  11961. * command, specific to the type of queue, to the HBA.
  11962. *
  11963. * The @rq struct is used to get the queue ID of the queue to destroy.
  11964. *
  11965. * On success this function will return a zero. If the queue destroy mailbox
  11966. * command fails this function will return -ENXIO.
  11967. **/
  11968. uint32_t
  11969. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11970. struct lpfc_queue *drq)
  11971. {
  11972. LPFC_MBOXQ_t *mbox;
  11973. int rc, length, status = 0;
  11974. uint32_t shdr_status, shdr_add_status;
  11975. union lpfc_sli4_cfg_shdr *shdr;
  11976. /* sanity check on queue memory */
  11977. if (!hrq || !drq)
  11978. return -ENODEV;
  11979. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  11980. if (!mbox)
  11981. return -ENOMEM;
  11982. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  11983. sizeof(struct lpfc_sli4_cfg_mhdr));
  11984. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11985. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  11986. length, LPFC_SLI4_MBX_EMBED);
  11987. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  11988. hrq->queue_id);
  11989. mbox->vport = hrq->phba->pport;
  11990. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11991. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  11992. /* The IOCTL status is embedded in the mailbox subheader. */
  11993. shdr = (union lpfc_sli4_cfg_shdr *)
  11994. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  11995. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11996. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11997. if (shdr_status || shdr_add_status || rc) {
  11998. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11999. "2509 RQ_DESTROY mailbox failed with "
  12000. "status x%x add_status x%x, mbx status x%x\n",
  12001. shdr_status, shdr_add_status, rc);
  12002. if (rc != MBX_TIMEOUT)
  12003. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12004. return -ENXIO;
  12005. }
  12006. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12007. drq->queue_id);
  12008. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  12009. shdr = (union lpfc_sli4_cfg_shdr *)
  12010. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12011. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12012. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12013. if (shdr_status || shdr_add_status || rc) {
  12014. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12015. "2510 RQ_DESTROY mailbox failed with "
  12016. "status x%x add_status x%x, mbx status x%x\n",
  12017. shdr_status, shdr_add_status, rc);
  12018. status = -ENXIO;
  12019. }
  12020. list_del_init(&hrq->list);
  12021. list_del_init(&drq->list);
  12022. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12023. return status;
  12024. }
  12025. /**
  12026. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  12027. * @phba: The virtual port for which this call being executed.
  12028. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  12029. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  12030. * @xritag: the xritag that ties this io to the SGL pages.
  12031. *
  12032. * This routine will post the sgl pages for the IO that has the xritag
  12033. * that is in the iocbq structure. The xritag is assigned during iocbq
  12034. * creation and persists for as long as the driver is loaded.
  12035. * if the caller has fewer than 256 scatter gather segments to map then
  12036. * pdma_phys_addr1 should be 0.
  12037. * If the caller needs to map more than 256 scatter gather segment then
  12038. * pdma_phys_addr1 should be a valid physical address.
  12039. * physical address for SGLs must be 64 byte aligned.
  12040. * If you are going to map 2 SGL's then the first one must have 256 entries
  12041. * the second sgl can have between 1 and 256 entries.
  12042. *
  12043. * Return codes:
  12044. * 0 - Success
  12045. * -ENXIO, -ENOMEM - Failure
  12046. **/
  12047. int
  12048. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  12049. dma_addr_t pdma_phys_addr0,
  12050. dma_addr_t pdma_phys_addr1,
  12051. uint16_t xritag)
  12052. {
  12053. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  12054. LPFC_MBOXQ_t *mbox;
  12055. int rc;
  12056. uint32_t shdr_status, shdr_add_status;
  12057. uint32_t mbox_tmo;
  12058. union lpfc_sli4_cfg_shdr *shdr;
  12059. if (xritag == NO_XRI) {
  12060. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12061. "0364 Invalid param:\n");
  12062. return -EINVAL;
  12063. }
  12064. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12065. if (!mbox)
  12066. return -ENOMEM;
  12067. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12068. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  12069. sizeof(struct lpfc_mbx_post_sgl_pages) -
  12070. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  12071. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  12072. &mbox->u.mqe.un.post_sgl_pages;
  12073. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  12074. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  12075. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  12076. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  12077. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  12078. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  12079. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  12080. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  12081. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  12082. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  12083. if (!phba->sli4_hba.intr_enable)
  12084. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12085. else {
  12086. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12087. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12088. }
  12089. /* The IOCTL status is embedded in the mailbox subheader. */
  12090. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  12091. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12092. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12093. if (rc != MBX_TIMEOUT)
  12094. mempool_free(mbox, phba->mbox_mem_pool);
  12095. if (shdr_status || shdr_add_status || rc) {
  12096. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12097. "2511 POST_SGL mailbox failed with "
  12098. "status x%x add_status x%x, mbx status x%x\n",
  12099. shdr_status, shdr_add_status, rc);
  12100. rc = -ENXIO;
  12101. }
  12102. return 0;
  12103. }
  12104. /**
  12105. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  12106. * @phba: pointer to lpfc hba data structure.
  12107. *
  12108. * This routine is invoked to post rpi header templates to the
  12109. * HBA consistent with the SLI-4 interface spec. This routine
  12110. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  12111. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  12112. *
  12113. * Returns
  12114. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  12115. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  12116. **/
  12117. uint16_t
  12118. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  12119. {
  12120. unsigned long xri;
  12121. /*
  12122. * Fetch the next logical xri. Because this index is logical,
  12123. * the driver starts at 0 each time.
  12124. */
  12125. spin_lock_irq(&phba->hbalock);
  12126. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  12127. phba->sli4_hba.max_cfg_param.max_xri, 0);
  12128. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  12129. spin_unlock_irq(&phba->hbalock);
  12130. return NO_XRI;
  12131. } else {
  12132. set_bit(xri, phba->sli4_hba.xri_bmask);
  12133. phba->sli4_hba.max_cfg_param.xri_used++;
  12134. }
  12135. spin_unlock_irq(&phba->hbalock);
  12136. return xri;
  12137. }
  12138. /**
  12139. * lpfc_sli4_free_xri - Release an xri for reuse.
  12140. * @phba: pointer to lpfc hba data structure.
  12141. *
  12142. * This routine is invoked to release an xri to the pool of
  12143. * available rpis maintained by the driver.
  12144. **/
  12145. void
  12146. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12147. {
  12148. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  12149. phba->sli4_hba.max_cfg_param.xri_used--;
  12150. }
  12151. }
  12152. /**
  12153. * lpfc_sli4_free_xri - Release an xri for reuse.
  12154. * @phba: pointer to lpfc hba data structure.
  12155. *
  12156. * This routine is invoked to release an xri to the pool of
  12157. * available rpis maintained by the driver.
  12158. **/
  12159. void
  12160. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12161. {
  12162. spin_lock_irq(&phba->hbalock);
  12163. __lpfc_sli4_free_xri(phba, xri);
  12164. spin_unlock_irq(&phba->hbalock);
  12165. }
  12166. /**
  12167. * lpfc_sli4_next_xritag - Get an xritag for the io
  12168. * @phba: Pointer to HBA context object.
  12169. *
  12170. * This function gets an xritag for the iocb. If there is no unused xritag
  12171. * it will return 0xffff.
  12172. * The function returns the allocated xritag if successful, else returns zero.
  12173. * Zero is not a valid xritag.
  12174. * The caller is not required to hold any lock.
  12175. **/
  12176. uint16_t
  12177. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  12178. {
  12179. uint16_t xri_index;
  12180. xri_index = lpfc_sli4_alloc_xri(phba);
  12181. if (xri_index == NO_XRI)
  12182. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  12183. "2004 Failed to allocate XRI.last XRITAG is %d"
  12184. " Max XRI is %d, Used XRI is %d\n",
  12185. xri_index,
  12186. phba->sli4_hba.max_cfg_param.max_xri,
  12187. phba->sli4_hba.max_cfg_param.xri_used);
  12188. return xri_index;
  12189. }
  12190. /**
  12191. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  12192. * @phba: pointer to lpfc hba data structure.
  12193. * @post_sgl_list: pointer to els sgl entry list.
  12194. * @count: number of els sgl entries on the list.
  12195. *
  12196. * This routine is invoked to post a block of driver's sgl pages to the
  12197. * HBA using non-embedded mailbox command. No Lock is held. This routine
  12198. * is only called when the driver is loading and after all IO has been
  12199. * stopped.
  12200. **/
  12201. static int
  12202. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
  12203. struct list_head *post_sgl_list,
  12204. int post_cnt)
  12205. {
  12206. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  12207. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12208. struct sgl_page_pairs *sgl_pg_pairs;
  12209. void *viraddr;
  12210. LPFC_MBOXQ_t *mbox;
  12211. uint32_t reqlen, alloclen, pg_pairs;
  12212. uint32_t mbox_tmo;
  12213. uint16_t xritag_start = 0;
  12214. int rc = 0;
  12215. uint32_t shdr_status, shdr_add_status;
  12216. union lpfc_sli4_cfg_shdr *shdr;
  12217. reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
  12218. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12219. if (reqlen > SLI4_PAGE_SIZE) {
  12220. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12221. "2559 Block sgl registration required DMA "
  12222. "size (%d) great than a page\n", reqlen);
  12223. return -ENOMEM;
  12224. }
  12225. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12226. if (!mbox)
  12227. return -ENOMEM;
  12228. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12229. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12230. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12231. LPFC_SLI4_MBX_NEMBED);
  12232. if (alloclen < reqlen) {
  12233. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12234. "0285 Allocated DMA memory size (%d) is "
  12235. "less than the requested DMA memory "
  12236. "size (%d)\n", alloclen, reqlen);
  12237. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12238. return -ENOMEM;
  12239. }
  12240. /* Set up the SGL pages in the non-embedded DMA pages */
  12241. viraddr = mbox->sge_array->addr[0];
  12242. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12243. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12244. pg_pairs = 0;
  12245. list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
  12246. /* Set up the sge entry */
  12247. sgl_pg_pairs->sgl_pg0_addr_lo =
  12248. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  12249. sgl_pg_pairs->sgl_pg0_addr_hi =
  12250. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  12251. sgl_pg_pairs->sgl_pg1_addr_lo =
  12252. cpu_to_le32(putPaddrLow(0));
  12253. sgl_pg_pairs->sgl_pg1_addr_hi =
  12254. cpu_to_le32(putPaddrHigh(0));
  12255. /* Keep the first xritag on the list */
  12256. if (pg_pairs == 0)
  12257. xritag_start = sglq_entry->sli4_xritag;
  12258. sgl_pg_pairs++;
  12259. pg_pairs++;
  12260. }
  12261. /* Complete initialization and perform endian conversion. */
  12262. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12263. bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
  12264. sgl->word0 = cpu_to_le32(sgl->word0);
  12265. if (!phba->sli4_hba.intr_enable)
  12266. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12267. else {
  12268. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12269. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12270. }
  12271. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12272. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12273. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12274. if (rc != MBX_TIMEOUT)
  12275. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12276. if (shdr_status || shdr_add_status || rc) {
  12277. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12278. "2513 POST_SGL_BLOCK mailbox command failed "
  12279. "status x%x add_status x%x mbx status x%x\n",
  12280. shdr_status, shdr_add_status, rc);
  12281. rc = -ENXIO;
  12282. }
  12283. return rc;
  12284. }
  12285. /**
  12286. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  12287. * @phba: pointer to lpfc hba data structure.
  12288. * @sblist: pointer to scsi buffer list.
  12289. * @count: number of scsi buffers on the list.
  12290. *
  12291. * This routine is invoked to post a block of @count scsi sgl pages from a
  12292. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  12293. * No Lock is held.
  12294. *
  12295. **/
  12296. int
  12297. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
  12298. struct list_head *sblist,
  12299. int count)
  12300. {
  12301. struct lpfc_scsi_buf *psb;
  12302. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12303. struct sgl_page_pairs *sgl_pg_pairs;
  12304. void *viraddr;
  12305. LPFC_MBOXQ_t *mbox;
  12306. uint32_t reqlen, alloclen, pg_pairs;
  12307. uint32_t mbox_tmo;
  12308. uint16_t xritag_start = 0;
  12309. int rc = 0;
  12310. uint32_t shdr_status, shdr_add_status;
  12311. dma_addr_t pdma_phys_bpl1;
  12312. union lpfc_sli4_cfg_shdr *shdr;
  12313. /* Calculate the requested length of the dma memory */
  12314. reqlen = count * sizeof(struct sgl_page_pairs) +
  12315. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12316. if (reqlen > SLI4_PAGE_SIZE) {
  12317. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12318. "0217 Block sgl registration required DMA "
  12319. "size (%d) great than a page\n", reqlen);
  12320. return -ENOMEM;
  12321. }
  12322. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12323. if (!mbox) {
  12324. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12325. "0283 Failed to allocate mbox cmd memory\n");
  12326. return -ENOMEM;
  12327. }
  12328. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12329. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12330. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12331. LPFC_SLI4_MBX_NEMBED);
  12332. if (alloclen < reqlen) {
  12333. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12334. "2561 Allocated DMA memory size (%d) is "
  12335. "less than the requested DMA memory "
  12336. "size (%d)\n", alloclen, reqlen);
  12337. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12338. return -ENOMEM;
  12339. }
  12340. /* Get the first SGE entry from the non-embedded DMA memory */
  12341. viraddr = mbox->sge_array->addr[0];
  12342. /* Set up the SGL pages in the non-embedded DMA pages */
  12343. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12344. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12345. pg_pairs = 0;
  12346. list_for_each_entry(psb, sblist, list) {
  12347. /* Set up the sge entry */
  12348. sgl_pg_pairs->sgl_pg0_addr_lo =
  12349. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  12350. sgl_pg_pairs->sgl_pg0_addr_hi =
  12351. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  12352. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  12353. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  12354. else
  12355. pdma_phys_bpl1 = 0;
  12356. sgl_pg_pairs->sgl_pg1_addr_lo =
  12357. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  12358. sgl_pg_pairs->sgl_pg1_addr_hi =
  12359. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  12360. /* Keep the first xritag on the list */
  12361. if (pg_pairs == 0)
  12362. xritag_start = psb->cur_iocbq.sli4_xritag;
  12363. sgl_pg_pairs++;
  12364. pg_pairs++;
  12365. }
  12366. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12367. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  12368. /* Perform endian conversion if necessary */
  12369. sgl->word0 = cpu_to_le32(sgl->word0);
  12370. if (!phba->sli4_hba.intr_enable)
  12371. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12372. else {
  12373. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12374. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12375. }
  12376. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12377. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12378. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12379. if (rc != MBX_TIMEOUT)
  12380. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12381. if (shdr_status || shdr_add_status || rc) {
  12382. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12383. "2564 POST_SGL_BLOCK mailbox command failed "
  12384. "status x%x add_status x%x mbx status x%x\n",
  12385. shdr_status, shdr_add_status, rc);
  12386. rc = -ENXIO;
  12387. }
  12388. return rc;
  12389. }
  12390. /**
  12391. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  12392. * @phba: pointer to lpfc_hba struct that the frame was received on
  12393. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12394. *
  12395. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  12396. * valid type of frame that the LPFC driver will handle. This function will
  12397. * return a zero if the frame is a valid frame or a non zero value when the
  12398. * frame does not pass the check.
  12399. **/
  12400. static int
  12401. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  12402. {
  12403. /* make rctl_names static to save stack space */
  12404. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  12405. char *type_names[] = FC_TYPE_NAMES_INIT;
  12406. struct fc_vft_header *fc_vft_hdr;
  12407. uint32_t *header = (uint32_t *) fc_hdr;
  12408. switch (fc_hdr->fh_r_ctl) {
  12409. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  12410. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  12411. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  12412. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  12413. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  12414. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  12415. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  12416. case FC_RCTL_DD_CMD_STATUS: /* command status */
  12417. case FC_RCTL_ELS_REQ: /* extended link services request */
  12418. case FC_RCTL_ELS_REP: /* extended link services reply */
  12419. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  12420. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  12421. case FC_RCTL_BA_NOP: /* basic link service NOP */
  12422. case FC_RCTL_BA_ABTS: /* basic link service abort */
  12423. case FC_RCTL_BA_RMC: /* remove connection */
  12424. case FC_RCTL_BA_ACC: /* basic accept */
  12425. case FC_RCTL_BA_RJT: /* basic reject */
  12426. case FC_RCTL_BA_PRMT:
  12427. case FC_RCTL_ACK_1: /* acknowledge_1 */
  12428. case FC_RCTL_ACK_0: /* acknowledge_0 */
  12429. case FC_RCTL_P_RJT: /* port reject */
  12430. case FC_RCTL_F_RJT: /* fabric reject */
  12431. case FC_RCTL_P_BSY: /* port busy */
  12432. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  12433. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  12434. case FC_RCTL_LCR: /* link credit reset */
  12435. case FC_RCTL_END: /* end */
  12436. break;
  12437. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  12438. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12439. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  12440. return lpfc_fc_frame_check(phba, fc_hdr);
  12441. default:
  12442. goto drop;
  12443. }
  12444. switch (fc_hdr->fh_type) {
  12445. case FC_TYPE_BLS:
  12446. case FC_TYPE_ELS:
  12447. case FC_TYPE_FCP:
  12448. case FC_TYPE_CT:
  12449. break;
  12450. case FC_TYPE_IP:
  12451. case FC_TYPE_ILS:
  12452. default:
  12453. goto drop;
  12454. }
  12455. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12456. "2538 Received frame rctl:%s type:%s "
  12457. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  12458. rctl_names[fc_hdr->fh_r_ctl],
  12459. type_names[fc_hdr->fh_type],
  12460. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  12461. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  12462. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  12463. return 0;
  12464. drop:
  12465. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12466. "2539 Dropped frame rctl:%s type:%s\n",
  12467. rctl_names[fc_hdr->fh_r_ctl],
  12468. type_names[fc_hdr->fh_type]);
  12469. return 1;
  12470. }
  12471. /**
  12472. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  12473. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12474. *
  12475. * This function processes the FC header to retrieve the VFI from the VF
  12476. * header, if one exists. This function will return the VFI if one exists
  12477. * or 0 if no VSAN Header exists.
  12478. **/
  12479. static uint32_t
  12480. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  12481. {
  12482. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12483. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  12484. return 0;
  12485. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  12486. }
  12487. /**
  12488. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  12489. * @phba: Pointer to the HBA structure to search for the vport on
  12490. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12491. * @fcfi: The FC Fabric ID that the frame came from
  12492. *
  12493. * This function searches the @phba for a vport that matches the content of the
  12494. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  12495. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  12496. * returns the matching vport pointer or NULL if unable to match frame to a
  12497. * vport.
  12498. **/
  12499. static struct lpfc_vport *
  12500. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  12501. uint16_t fcfi)
  12502. {
  12503. struct lpfc_vport **vports;
  12504. struct lpfc_vport *vport = NULL;
  12505. int i;
  12506. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  12507. fc_hdr->fh_d_id[1] << 8 |
  12508. fc_hdr->fh_d_id[2]);
  12509. if (did == Fabric_DID)
  12510. return phba->pport;
  12511. if ((phba->pport->fc_flag & FC_PT2PT) &&
  12512. !(phba->link_state == LPFC_HBA_READY))
  12513. return phba->pport;
  12514. vports = lpfc_create_vport_work_array(phba);
  12515. if (vports != NULL)
  12516. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  12517. if (phba->fcf.fcfi == fcfi &&
  12518. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  12519. vports[i]->fc_myDID == did) {
  12520. vport = vports[i];
  12521. break;
  12522. }
  12523. }
  12524. lpfc_destroy_vport_work_array(phba, vports);
  12525. return vport;
  12526. }
  12527. /**
  12528. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  12529. * @vport: The vport to work on.
  12530. *
  12531. * This function updates the receive sequence time stamp for this vport. The
  12532. * receive sequence time stamp indicates the time that the last frame of the
  12533. * the sequence that has been idle for the longest amount of time was received.
  12534. * the driver uses this time stamp to indicate if any received sequences have
  12535. * timed out.
  12536. **/
  12537. void
  12538. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  12539. {
  12540. struct lpfc_dmabuf *h_buf;
  12541. struct hbq_dmabuf *dmabuf = NULL;
  12542. /* get the oldest sequence on the rcv list */
  12543. h_buf = list_get_first(&vport->rcv_buffer_list,
  12544. struct lpfc_dmabuf, list);
  12545. if (!h_buf)
  12546. return;
  12547. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12548. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  12549. }
  12550. /**
  12551. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  12552. * @vport: The vport that the received sequences were sent to.
  12553. *
  12554. * This function cleans up all outstanding received sequences. This is called
  12555. * by the driver when a link event or user action invalidates all the received
  12556. * sequences.
  12557. **/
  12558. void
  12559. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  12560. {
  12561. struct lpfc_dmabuf *h_buf, *hnext;
  12562. struct lpfc_dmabuf *d_buf, *dnext;
  12563. struct hbq_dmabuf *dmabuf = NULL;
  12564. /* start with the oldest sequence on the rcv list */
  12565. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12566. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12567. list_del_init(&dmabuf->hbuf.list);
  12568. list_for_each_entry_safe(d_buf, dnext,
  12569. &dmabuf->dbuf.list, list) {
  12570. list_del_init(&d_buf->list);
  12571. lpfc_in_buf_free(vport->phba, d_buf);
  12572. }
  12573. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12574. }
  12575. }
  12576. /**
  12577. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  12578. * @vport: The vport that the received sequences were sent to.
  12579. *
  12580. * This function determines whether any received sequences have timed out by
  12581. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  12582. * indicates that there is at least one timed out sequence this routine will
  12583. * go through the received sequences one at a time from most inactive to most
  12584. * active to determine which ones need to be cleaned up. Once it has determined
  12585. * that a sequence needs to be cleaned up it will simply free up the resources
  12586. * without sending an abort.
  12587. **/
  12588. void
  12589. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  12590. {
  12591. struct lpfc_dmabuf *h_buf, *hnext;
  12592. struct lpfc_dmabuf *d_buf, *dnext;
  12593. struct hbq_dmabuf *dmabuf = NULL;
  12594. unsigned long timeout;
  12595. int abort_count = 0;
  12596. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12597. vport->rcv_buffer_time_stamp);
  12598. if (list_empty(&vport->rcv_buffer_list) ||
  12599. time_before(jiffies, timeout))
  12600. return;
  12601. /* start with the oldest sequence on the rcv list */
  12602. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12603. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12604. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12605. dmabuf->time_stamp);
  12606. if (time_before(jiffies, timeout))
  12607. break;
  12608. abort_count++;
  12609. list_del_init(&dmabuf->hbuf.list);
  12610. list_for_each_entry_safe(d_buf, dnext,
  12611. &dmabuf->dbuf.list, list) {
  12612. list_del_init(&d_buf->list);
  12613. lpfc_in_buf_free(vport->phba, d_buf);
  12614. }
  12615. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12616. }
  12617. if (abort_count)
  12618. lpfc_update_rcv_time_stamp(vport);
  12619. }
  12620. /**
  12621. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  12622. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  12623. *
  12624. * This function searches through the existing incomplete sequences that have
  12625. * been sent to this @vport. If the frame matches one of the incomplete
  12626. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  12627. * make up that sequence. If no sequence is found that matches this frame then
  12628. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  12629. * This function returns a pointer to the first dmabuf in the sequence list that
  12630. * the frame was linked to.
  12631. **/
  12632. static struct hbq_dmabuf *
  12633. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  12634. {
  12635. struct fc_frame_header *new_hdr;
  12636. struct fc_frame_header *temp_hdr;
  12637. struct lpfc_dmabuf *d_buf;
  12638. struct lpfc_dmabuf *h_buf;
  12639. struct hbq_dmabuf *seq_dmabuf = NULL;
  12640. struct hbq_dmabuf *temp_dmabuf = NULL;
  12641. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12642. dmabuf->time_stamp = jiffies;
  12643. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12644. /* Use the hdr_buf to find the sequence that this frame belongs to */
  12645. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12646. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12647. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12648. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12649. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12650. continue;
  12651. /* found a pending sequence that matches this frame */
  12652. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12653. break;
  12654. }
  12655. if (!seq_dmabuf) {
  12656. /*
  12657. * This indicates first frame received for this sequence.
  12658. * Queue the buffer on the vport's rcv_buffer_list.
  12659. */
  12660. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12661. lpfc_update_rcv_time_stamp(vport);
  12662. return dmabuf;
  12663. }
  12664. temp_hdr = seq_dmabuf->hbuf.virt;
  12665. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  12666. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12667. list_del_init(&seq_dmabuf->hbuf.list);
  12668. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12669. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12670. lpfc_update_rcv_time_stamp(vport);
  12671. return dmabuf;
  12672. }
  12673. /* move this sequence to the tail to indicate a young sequence */
  12674. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12675. seq_dmabuf->time_stamp = jiffies;
  12676. lpfc_update_rcv_time_stamp(vport);
  12677. if (list_empty(&seq_dmabuf->dbuf.list)) {
  12678. temp_hdr = dmabuf->hbuf.virt;
  12679. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12680. return seq_dmabuf;
  12681. }
  12682. /* find the correct place in the sequence to insert this frame */
  12683. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  12684. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  12685. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  12686. /*
  12687. * If the frame's sequence count is greater than the frame on
  12688. * the list then insert the frame right after this frame
  12689. */
  12690. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  12691. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12692. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  12693. return seq_dmabuf;
  12694. }
  12695. }
  12696. return NULL;
  12697. }
  12698. /**
  12699. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  12700. * @vport: pointer to a vitural port
  12701. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12702. *
  12703. * This function tries to abort from the partially assembed sequence, described
  12704. * by the information from basic abbort @dmabuf. It checks to see whether such
  12705. * partially assembled sequence held by the driver. If so, it shall free up all
  12706. * the frames from the partially assembled sequence.
  12707. *
  12708. * Return
  12709. * true -- if there is matching partially assembled sequence present and all
  12710. * the frames freed with the sequence;
  12711. * false -- if there is no matching partially assembled sequence present so
  12712. * nothing got aborted in the lower layer driver
  12713. **/
  12714. static bool
  12715. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  12716. struct hbq_dmabuf *dmabuf)
  12717. {
  12718. struct fc_frame_header *new_hdr;
  12719. struct fc_frame_header *temp_hdr;
  12720. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  12721. struct hbq_dmabuf *seq_dmabuf = NULL;
  12722. /* Use the hdr_buf to find the sequence that matches this frame */
  12723. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12724. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  12725. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12726. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12727. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12728. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12729. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12730. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12731. continue;
  12732. /* found a pending sequence that matches this frame */
  12733. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12734. break;
  12735. }
  12736. /* Free up all the frames from the partially assembled sequence */
  12737. if (seq_dmabuf) {
  12738. list_for_each_entry_safe(d_buf, n_buf,
  12739. &seq_dmabuf->dbuf.list, list) {
  12740. list_del_init(&d_buf->list);
  12741. lpfc_in_buf_free(vport->phba, d_buf);
  12742. }
  12743. return true;
  12744. }
  12745. return false;
  12746. }
  12747. /**
  12748. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  12749. * @phba: Pointer to HBA context object.
  12750. * @cmd_iocbq: pointer to the command iocbq structure.
  12751. * @rsp_iocbq: pointer to the response iocbq structure.
  12752. *
  12753. * This function handles the sequence abort response iocb command complete
  12754. * event. It properly releases the memory allocated to the sequence abort
  12755. * accept iocb.
  12756. **/
  12757. static void
  12758. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  12759. struct lpfc_iocbq *cmd_iocbq,
  12760. struct lpfc_iocbq *rsp_iocbq)
  12761. {
  12762. if (cmd_iocbq)
  12763. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  12764. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  12765. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  12766. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12767. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  12768. rsp_iocbq->iocb.ulpStatus,
  12769. rsp_iocbq->iocb.un.ulpWord[4]);
  12770. }
  12771. /**
  12772. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  12773. * @phba: Pointer to HBA context object.
  12774. * @xri: xri id in transaction.
  12775. *
  12776. * This function validates the xri maps to the known range of XRIs allocated an
  12777. * used by the driver.
  12778. **/
  12779. uint16_t
  12780. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  12781. uint16_t xri)
  12782. {
  12783. int i;
  12784. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  12785. if (xri == phba->sli4_hba.xri_ids[i])
  12786. return i;
  12787. }
  12788. return NO_XRI;
  12789. }
  12790. /**
  12791. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  12792. * @phba: Pointer to HBA context object.
  12793. * @fc_hdr: pointer to a FC frame header.
  12794. *
  12795. * This function sends a basic response to a previous unsol sequence abort
  12796. * event after aborting the sequence handling.
  12797. **/
  12798. static void
  12799. lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba,
  12800. struct fc_frame_header *fc_hdr)
  12801. {
  12802. struct lpfc_iocbq *ctiocb = NULL;
  12803. struct lpfc_nodelist *ndlp;
  12804. uint16_t oxid, rxid;
  12805. uint32_t sid, fctl;
  12806. IOCB_t *icmd;
  12807. int rc;
  12808. if (!lpfc_is_link_up(phba))
  12809. return;
  12810. sid = sli4_sid_from_fc_hdr(fc_hdr);
  12811. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  12812. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  12813. ndlp = lpfc_findnode_did(phba->pport, sid);
  12814. if (!ndlp) {
  12815. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12816. "1268 Find ndlp returned NULL for oxid:x%x "
  12817. "SID:x%x\n", oxid, sid);
  12818. return;
  12819. }
  12820. if (lpfc_sli4_xri_inrange(phba, rxid))
  12821. lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
  12822. /* Allocate buffer for rsp iocb */
  12823. ctiocb = lpfc_sli_get_iocbq(phba);
  12824. if (!ctiocb)
  12825. return;
  12826. /* Extract the F_CTL field from FC_HDR */
  12827. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  12828. icmd = &ctiocb->iocb;
  12829. icmd->un.xseq64.bdl.bdeSize = 0;
  12830. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  12831. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  12832. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  12833. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  12834. /* Fill in the rest of iocb fields */
  12835. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  12836. icmd->ulpBdeCount = 0;
  12837. icmd->ulpLe = 1;
  12838. icmd->ulpClass = CLASS3;
  12839. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  12840. ctiocb->context1 = ndlp;
  12841. ctiocb->iocb_cmpl = NULL;
  12842. ctiocb->vport = phba->pport;
  12843. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  12844. ctiocb->sli4_lxritag = NO_XRI;
  12845. ctiocb->sli4_xritag = NO_XRI;
  12846. /* If the oxid maps to the FCP XRI range or if it is out of range,
  12847. * send a BLS_RJT. The driver no longer has that exchange.
  12848. * Override the IOCB for a BA_RJT.
  12849. */
  12850. if (oxid > (phba->sli4_hba.max_cfg_param.max_xri +
  12851. phba->sli4_hba.max_cfg_param.xri_base) ||
  12852. oxid > (lpfc_sli4_get_els_iocb_cnt(phba) +
  12853. phba->sli4_hba.max_cfg_param.xri_base)) {
  12854. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  12855. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  12856. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  12857. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  12858. }
  12859. if (fctl & FC_FC_EX_CTX) {
  12860. /* ABTS sent by responder to CT exchange, construction
  12861. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  12862. * field and RX_ID from ABTS for RX_ID field.
  12863. */
  12864. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  12865. } else {
  12866. /* ABTS sent by initiator to CT exchange, construction
  12867. * of BA_ACC will need to allocate a new XRI as for the
  12868. * XRI_TAG field.
  12869. */
  12870. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  12871. }
  12872. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  12873. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  12874. /* Xmit CT abts response on exchange <xid> */
  12875. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12876. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  12877. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  12878. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  12879. if (rc == IOCB_ERROR) {
  12880. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  12881. "2925 Failed to issue CT ABTS RSP x%x on "
  12882. "xri x%x, Data x%x\n",
  12883. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  12884. phba->link_state);
  12885. lpfc_sli_release_iocbq(phba, ctiocb);
  12886. }
  12887. }
  12888. /**
  12889. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  12890. * @vport: Pointer to the vport on which this sequence was received
  12891. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12892. *
  12893. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  12894. * receive sequence is only partially assembed by the driver, it shall abort
  12895. * the partially assembled frames for the sequence. Otherwise, if the
  12896. * unsolicited receive sequence has been completely assembled and passed to
  12897. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  12898. * unsolicited sequence has been aborted. After that, it will issue a basic
  12899. * accept to accept the abort.
  12900. **/
  12901. void
  12902. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  12903. struct hbq_dmabuf *dmabuf)
  12904. {
  12905. struct lpfc_hba *phba = vport->phba;
  12906. struct fc_frame_header fc_hdr;
  12907. uint32_t fctl;
  12908. bool abts_par;
  12909. /* Make a copy of fc_hdr before the dmabuf being released */
  12910. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  12911. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  12912. if (fctl & FC_FC_EX_CTX) {
  12913. /*
  12914. * ABTS sent by responder to exchange, just free the buffer
  12915. */
  12916. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  12917. } else {
  12918. /*
  12919. * ABTS sent by initiator to exchange, need to do cleanup
  12920. */
  12921. /* Try to abort partially assembled seq */
  12922. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  12923. /* Send abort to ULP if partially seq abort failed */
  12924. if (abts_par == false)
  12925. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  12926. else
  12927. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  12928. }
  12929. /* Send basic accept (BA_ACC) to the abort requester */
  12930. lpfc_sli4_seq_abort_rsp(phba, &fc_hdr);
  12931. }
  12932. /**
  12933. * lpfc_seq_complete - Indicates if a sequence is complete
  12934. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12935. *
  12936. * This function checks the sequence, starting with the frame described by
  12937. * @dmabuf, to see if all the frames associated with this sequence are present.
  12938. * the frames associated with this sequence are linked to the @dmabuf using the
  12939. * dbuf list. This function looks for two major things. 1) That the first frame
  12940. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  12941. * set. 3) That there are no holes in the sequence count. The function will
  12942. * return 1 when the sequence is complete, otherwise it will return 0.
  12943. **/
  12944. static int
  12945. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  12946. {
  12947. struct fc_frame_header *hdr;
  12948. struct lpfc_dmabuf *d_buf;
  12949. struct hbq_dmabuf *seq_dmabuf;
  12950. uint32_t fctl;
  12951. int seq_count = 0;
  12952. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12953. /* make sure first fame of sequence has a sequence count of zero */
  12954. if (hdr->fh_seq_cnt != seq_count)
  12955. return 0;
  12956. fctl = (hdr->fh_f_ctl[0] << 16 |
  12957. hdr->fh_f_ctl[1] << 8 |
  12958. hdr->fh_f_ctl[2]);
  12959. /* If last frame of sequence we can return success. */
  12960. if (fctl & FC_FC_END_SEQ)
  12961. return 1;
  12962. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  12963. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  12964. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  12965. /* If there is a hole in the sequence count then fail. */
  12966. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  12967. return 0;
  12968. fctl = (hdr->fh_f_ctl[0] << 16 |
  12969. hdr->fh_f_ctl[1] << 8 |
  12970. hdr->fh_f_ctl[2]);
  12971. /* If last frame of sequence we can return success. */
  12972. if (fctl & FC_FC_END_SEQ)
  12973. return 1;
  12974. }
  12975. return 0;
  12976. }
  12977. /**
  12978. * lpfc_prep_seq - Prep sequence for ULP processing
  12979. * @vport: Pointer to the vport on which this sequence was received
  12980. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12981. *
  12982. * This function takes a sequence, described by a list of frames, and creates
  12983. * a list of iocbq structures to describe the sequence. This iocbq list will be
  12984. * used to issue to the generic unsolicited sequence handler. This routine
  12985. * returns a pointer to the first iocbq in the list. If the function is unable
  12986. * to allocate an iocbq then it throw out the received frames that were not
  12987. * able to be described and return a pointer to the first iocbq. If unable to
  12988. * allocate any iocbqs (including the first) this function will return NULL.
  12989. **/
  12990. static struct lpfc_iocbq *
  12991. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  12992. {
  12993. struct hbq_dmabuf *hbq_buf;
  12994. struct lpfc_dmabuf *d_buf, *n_buf;
  12995. struct lpfc_iocbq *first_iocbq, *iocbq;
  12996. struct fc_frame_header *fc_hdr;
  12997. uint32_t sid;
  12998. uint32_t len, tot_len;
  12999. struct ulp_bde64 *pbde;
  13000. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13001. /* remove from receive buffer list */
  13002. list_del_init(&seq_dmabuf->hbuf.list);
  13003. lpfc_update_rcv_time_stamp(vport);
  13004. /* get the Remote Port's SID */
  13005. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13006. tot_len = 0;
  13007. /* Get an iocbq struct to fill in. */
  13008. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  13009. if (first_iocbq) {
  13010. /* Initialize the first IOCB. */
  13011. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  13012. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  13013. /* Check FC Header to see what TYPE of frame we are rcv'ing */
  13014. if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
  13015. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
  13016. first_iocbq->iocb.un.rcvels.parmRo =
  13017. sli4_did_from_fc_hdr(fc_hdr);
  13018. first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
  13019. } else
  13020. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  13021. first_iocbq->iocb.ulpContext = NO_XRI;
  13022. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  13023. be16_to_cpu(fc_hdr->fh_ox_id);
  13024. /* iocbq is prepped for internal consumption. Physical vpi. */
  13025. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  13026. vport->phba->vpi_ids[vport->vpi];
  13027. /* put the first buffer into the first IOCBq */
  13028. first_iocbq->context2 = &seq_dmabuf->dbuf;
  13029. first_iocbq->context3 = NULL;
  13030. first_iocbq->iocb.ulpBdeCount = 1;
  13031. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13032. LPFC_DATA_BUF_SIZE;
  13033. first_iocbq->iocb.un.rcvels.remoteID = sid;
  13034. tot_len = bf_get(lpfc_rcqe_length,
  13035. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  13036. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13037. }
  13038. iocbq = first_iocbq;
  13039. /*
  13040. * Each IOCBq can have two Buffers assigned, so go through the list
  13041. * of buffers for this sequence and save two buffers in each IOCBq
  13042. */
  13043. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  13044. if (!iocbq) {
  13045. lpfc_in_buf_free(vport->phba, d_buf);
  13046. continue;
  13047. }
  13048. if (!iocbq->context3) {
  13049. iocbq->context3 = d_buf;
  13050. iocbq->iocb.ulpBdeCount++;
  13051. pbde = (struct ulp_bde64 *)
  13052. &iocbq->iocb.unsli3.sli3Words[4];
  13053. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  13054. /* We need to get the size out of the right CQE */
  13055. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13056. len = bf_get(lpfc_rcqe_length,
  13057. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13058. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  13059. tot_len += len;
  13060. } else {
  13061. iocbq = lpfc_sli_get_iocbq(vport->phba);
  13062. if (!iocbq) {
  13063. if (first_iocbq) {
  13064. first_iocbq->iocb.ulpStatus =
  13065. IOSTAT_FCP_RSP_ERROR;
  13066. first_iocbq->iocb.un.ulpWord[4] =
  13067. IOERR_NO_RESOURCES;
  13068. }
  13069. lpfc_in_buf_free(vport->phba, d_buf);
  13070. continue;
  13071. }
  13072. iocbq->context2 = d_buf;
  13073. iocbq->context3 = NULL;
  13074. iocbq->iocb.ulpBdeCount = 1;
  13075. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13076. LPFC_DATA_BUF_SIZE;
  13077. /* We need to get the size out of the right CQE */
  13078. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13079. len = bf_get(lpfc_rcqe_length,
  13080. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13081. tot_len += len;
  13082. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13083. iocbq->iocb.un.rcvels.remoteID = sid;
  13084. list_add_tail(&iocbq->list, &first_iocbq->list);
  13085. }
  13086. }
  13087. return first_iocbq;
  13088. }
  13089. static void
  13090. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  13091. struct hbq_dmabuf *seq_dmabuf)
  13092. {
  13093. struct fc_frame_header *fc_hdr;
  13094. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  13095. struct lpfc_hba *phba = vport->phba;
  13096. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13097. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  13098. if (!iocbq) {
  13099. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13100. "2707 Ring %d handler: Failed to allocate "
  13101. "iocb Rctl x%x Type x%x received\n",
  13102. LPFC_ELS_RING,
  13103. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13104. return;
  13105. }
  13106. if (!lpfc_complete_unsol_iocb(phba,
  13107. &phba->sli.ring[LPFC_ELS_RING],
  13108. iocbq, fc_hdr->fh_r_ctl,
  13109. fc_hdr->fh_type))
  13110. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13111. "2540 Ring %d handler: unexpected Rctl "
  13112. "x%x Type x%x received\n",
  13113. LPFC_ELS_RING,
  13114. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13115. /* Free iocb created in lpfc_prep_seq */
  13116. list_for_each_entry_safe(curr_iocb, next_iocb,
  13117. &iocbq->list, list) {
  13118. list_del_init(&curr_iocb->list);
  13119. lpfc_sli_release_iocbq(phba, curr_iocb);
  13120. }
  13121. lpfc_sli_release_iocbq(phba, iocbq);
  13122. }
  13123. /**
  13124. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  13125. * @phba: Pointer to HBA context object.
  13126. *
  13127. * This function is called with no lock held. This function processes all
  13128. * the received buffers and gives it to upper layers when a received buffer
  13129. * indicates that it is the final frame in the sequence. The interrupt
  13130. * service routine processes received buffers at interrupt contexts and adds
  13131. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  13132. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  13133. * appropriate receive function when the final frame in a sequence is received.
  13134. **/
  13135. void
  13136. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  13137. struct hbq_dmabuf *dmabuf)
  13138. {
  13139. struct hbq_dmabuf *seq_dmabuf;
  13140. struct fc_frame_header *fc_hdr;
  13141. struct lpfc_vport *vport;
  13142. uint32_t fcfi;
  13143. uint32_t did;
  13144. /* Process each received buffer */
  13145. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13146. /* check to see if this a valid type of frame */
  13147. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  13148. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13149. return;
  13150. }
  13151. if ((bf_get(lpfc_cqe_code,
  13152. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  13153. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  13154. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13155. else
  13156. fcfi = bf_get(lpfc_rcqe_fcf_id,
  13157. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13158. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  13159. if (!vport) {
  13160. /* throw out the frame */
  13161. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13162. return;
  13163. }
  13164. /* d_id this frame is directed to */
  13165. did = sli4_did_from_fc_hdr(fc_hdr);
  13166. /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
  13167. if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
  13168. (did != Fabric_DID)) {
  13169. /*
  13170. * Throw out the frame if we are not pt2pt.
  13171. * The pt2pt protocol allows for discovery frames
  13172. * to be received without a registered VPI.
  13173. */
  13174. if (!(vport->fc_flag & FC_PT2PT) ||
  13175. (phba->link_state == LPFC_HBA_READY)) {
  13176. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13177. return;
  13178. }
  13179. }
  13180. /* Handle the basic abort sequence (BA_ABTS) event */
  13181. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  13182. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  13183. return;
  13184. }
  13185. /* Link this frame */
  13186. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  13187. if (!seq_dmabuf) {
  13188. /* unable to add frame to vport - throw it out */
  13189. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13190. return;
  13191. }
  13192. /* If not last frame in sequence continue processing frames. */
  13193. if (!lpfc_seq_complete(seq_dmabuf))
  13194. return;
  13195. /* Send the complete sequence to the upper layer protocol */
  13196. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  13197. }
  13198. /**
  13199. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  13200. * @phba: pointer to lpfc hba data structure.
  13201. *
  13202. * This routine is invoked to post rpi header templates to the
  13203. * HBA consistent with the SLI-4 interface spec. This routine
  13204. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13205. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13206. *
  13207. * This routine does not require any locks. It's usage is expected
  13208. * to be driver load or reset recovery when the driver is
  13209. * sequential.
  13210. *
  13211. * Return codes
  13212. * 0 - successful
  13213. * -EIO - The mailbox failed to complete successfully.
  13214. * When this error occurs, the driver is not guaranteed
  13215. * to have any rpi regions posted to the device and
  13216. * must either attempt to repost the regions or take a
  13217. * fatal error.
  13218. **/
  13219. int
  13220. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  13221. {
  13222. struct lpfc_rpi_hdr *rpi_page;
  13223. uint32_t rc = 0;
  13224. uint16_t lrpi = 0;
  13225. /* SLI4 ports that support extents do not require RPI headers. */
  13226. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13227. goto exit;
  13228. if (phba->sli4_hba.extents_in_use)
  13229. return -EIO;
  13230. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  13231. /*
  13232. * Assign the rpi headers a physical rpi only if the driver
  13233. * has not initialized those resources. A port reset only
  13234. * needs the headers posted.
  13235. */
  13236. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  13237. LPFC_RPI_RSRC_RDY)
  13238. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13239. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  13240. if (rc != MBX_SUCCESS) {
  13241. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13242. "2008 Error %d posting all rpi "
  13243. "headers\n", rc);
  13244. rc = -EIO;
  13245. break;
  13246. }
  13247. }
  13248. exit:
  13249. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  13250. LPFC_RPI_RSRC_RDY);
  13251. return rc;
  13252. }
  13253. /**
  13254. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  13255. * @phba: pointer to lpfc hba data structure.
  13256. * @rpi_page: pointer to the rpi memory region.
  13257. *
  13258. * This routine is invoked to post a single rpi header to the
  13259. * HBA consistent with the SLI-4 interface spec. This memory region
  13260. * maps up to 64 rpi context regions.
  13261. *
  13262. * Return codes
  13263. * 0 - successful
  13264. * -ENOMEM - No available memory
  13265. * -EIO - The mailbox failed to complete successfully.
  13266. **/
  13267. int
  13268. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  13269. {
  13270. LPFC_MBOXQ_t *mboxq;
  13271. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  13272. uint32_t rc = 0;
  13273. uint32_t shdr_status, shdr_add_status;
  13274. union lpfc_sli4_cfg_shdr *shdr;
  13275. /* SLI4 ports that support extents do not require RPI headers. */
  13276. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13277. return rc;
  13278. if (phba->sli4_hba.extents_in_use)
  13279. return -EIO;
  13280. /* The port is notified of the header region via a mailbox command. */
  13281. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13282. if (!mboxq) {
  13283. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13284. "2001 Unable to allocate memory for issuing "
  13285. "SLI_CONFIG_SPECIAL mailbox command\n");
  13286. return -ENOMEM;
  13287. }
  13288. /* Post all rpi memory regions to the port. */
  13289. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  13290. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13291. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  13292. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  13293. sizeof(struct lpfc_sli4_cfg_mhdr),
  13294. LPFC_SLI4_MBX_EMBED);
  13295. /* Post the physical rpi to the port for this rpi header. */
  13296. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  13297. rpi_page->start_rpi);
  13298. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  13299. hdr_tmpl, rpi_page->page_count);
  13300. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  13301. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  13302. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  13303. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  13304. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13305. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13306. if (rc != MBX_TIMEOUT)
  13307. mempool_free(mboxq, phba->mbox_mem_pool);
  13308. if (shdr_status || shdr_add_status || rc) {
  13309. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13310. "2514 POST_RPI_HDR mailbox failed with "
  13311. "status x%x add_status x%x, mbx status x%x\n",
  13312. shdr_status, shdr_add_status, rc);
  13313. rc = -ENXIO;
  13314. }
  13315. return rc;
  13316. }
  13317. /**
  13318. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  13319. * @phba: pointer to lpfc hba data structure.
  13320. *
  13321. * This routine is invoked to post rpi header templates to the
  13322. * HBA consistent with the SLI-4 interface spec. This routine
  13323. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13324. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13325. *
  13326. * Returns
  13327. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13328. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13329. **/
  13330. int
  13331. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  13332. {
  13333. unsigned long rpi;
  13334. uint16_t max_rpi, rpi_limit;
  13335. uint16_t rpi_remaining, lrpi = 0;
  13336. struct lpfc_rpi_hdr *rpi_hdr;
  13337. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  13338. rpi_limit = phba->sli4_hba.next_rpi;
  13339. /*
  13340. * Fetch the next logical rpi. Because this index is logical,
  13341. * the driver starts at 0 each time.
  13342. */
  13343. spin_lock_irq(&phba->hbalock);
  13344. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  13345. if (rpi >= rpi_limit)
  13346. rpi = LPFC_RPI_ALLOC_ERROR;
  13347. else {
  13348. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  13349. phba->sli4_hba.max_cfg_param.rpi_used++;
  13350. phba->sli4_hba.rpi_count++;
  13351. }
  13352. /*
  13353. * Don't try to allocate more rpi header regions if the device limit
  13354. * has been exhausted.
  13355. */
  13356. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  13357. (phba->sli4_hba.rpi_count >= max_rpi)) {
  13358. spin_unlock_irq(&phba->hbalock);
  13359. return rpi;
  13360. }
  13361. /*
  13362. * RPI header postings are not required for SLI4 ports capable of
  13363. * extents.
  13364. */
  13365. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  13366. spin_unlock_irq(&phba->hbalock);
  13367. return rpi;
  13368. }
  13369. /*
  13370. * If the driver is running low on rpi resources, allocate another
  13371. * page now. Note that the next_rpi value is used because
  13372. * it represents how many are actually in use whereas max_rpi notes
  13373. * how many are supported max by the device.
  13374. */
  13375. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  13376. spin_unlock_irq(&phba->hbalock);
  13377. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  13378. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  13379. if (!rpi_hdr) {
  13380. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13381. "2002 Error Could not grow rpi "
  13382. "count\n");
  13383. } else {
  13384. lrpi = rpi_hdr->start_rpi;
  13385. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13386. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  13387. }
  13388. }
  13389. return rpi;
  13390. }
  13391. /**
  13392. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13393. * @phba: pointer to lpfc hba data structure.
  13394. *
  13395. * This routine is invoked to release an rpi to the pool of
  13396. * available rpis maintained by the driver.
  13397. **/
  13398. void
  13399. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13400. {
  13401. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  13402. phba->sli4_hba.rpi_count--;
  13403. phba->sli4_hba.max_cfg_param.rpi_used--;
  13404. }
  13405. }
  13406. /**
  13407. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13408. * @phba: pointer to lpfc hba data structure.
  13409. *
  13410. * This routine is invoked to release an rpi to the pool of
  13411. * available rpis maintained by the driver.
  13412. **/
  13413. void
  13414. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13415. {
  13416. spin_lock_irq(&phba->hbalock);
  13417. __lpfc_sli4_free_rpi(phba, rpi);
  13418. spin_unlock_irq(&phba->hbalock);
  13419. }
  13420. /**
  13421. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  13422. * @phba: pointer to lpfc hba data structure.
  13423. *
  13424. * This routine is invoked to remove the memory region that
  13425. * provided rpi via a bitmask.
  13426. **/
  13427. void
  13428. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  13429. {
  13430. kfree(phba->sli4_hba.rpi_bmask);
  13431. kfree(phba->sli4_hba.rpi_ids);
  13432. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  13433. }
  13434. /**
  13435. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  13436. * @phba: pointer to lpfc hba data structure.
  13437. *
  13438. * This routine is invoked to remove the memory region that
  13439. * provided rpi via a bitmask.
  13440. **/
  13441. int
  13442. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  13443. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  13444. {
  13445. LPFC_MBOXQ_t *mboxq;
  13446. struct lpfc_hba *phba = ndlp->phba;
  13447. int rc;
  13448. /* The port is notified of the header region via a mailbox command. */
  13449. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13450. if (!mboxq)
  13451. return -ENOMEM;
  13452. /* Post all rpi memory regions to the port. */
  13453. lpfc_resume_rpi(mboxq, ndlp);
  13454. if (cmpl) {
  13455. mboxq->mbox_cmpl = cmpl;
  13456. mboxq->context1 = arg;
  13457. mboxq->context2 = ndlp;
  13458. } else
  13459. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13460. mboxq->vport = ndlp->vport;
  13461. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13462. if (rc == MBX_NOT_FINISHED) {
  13463. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13464. "2010 Resume RPI Mailbox failed "
  13465. "status %d, mbxStatus x%x\n", rc,
  13466. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13467. mempool_free(mboxq, phba->mbox_mem_pool);
  13468. return -EIO;
  13469. }
  13470. return 0;
  13471. }
  13472. /**
  13473. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  13474. * @vport: Pointer to the vport for which the vpi is being initialized
  13475. *
  13476. * This routine is invoked to activate a vpi with the port.
  13477. *
  13478. * Returns:
  13479. * 0 success
  13480. * -Evalue otherwise
  13481. **/
  13482. int
  13483. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  13484. {
  13485. LPFC_MBOXQ_t *mboxq;
  13486. int rc = 0;
  13487. int retval = MBX_SUCCESS;
  13488. uint32_t mbox_tmo;
  13489. struct lpfc_hba *phba = vport->phba;
  13490. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13491. if (!mboxq)
  13492. return -ENOMEM;
  13493. lpfc_init_vpi(phba, mboxq, vport->vpi);
  13494. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  13495. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  13496. if (rc != MBX_SUCCESS) {
  13497. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  13498. "2022 INIT VPI Mailbox failed "
  13499. "status %d, mbxStatus x%x\n", rc,
  13500. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13501. retval = -EIO;
  13502. }
  13503. if (rc != MBX_TIMEOUT)
  13504. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  13505. return retval;
  13506. }
  13507. /**
  13508. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  13509. * @phba: pointer to lpfc hba data structure.
  13510. * @mboxq: Pointer to mailbox object.
  13511. *
  13512. * This routine is invoked to manually add a single FCF record. The caller
  13513. * must pass a completely initialized FCF_Record. This routine takes
  13514. * care of the nonembedded mailbox operations.
  13515. **/
  13516. static void
  13517. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  13518. {
  13519. void *virt_addr;
  13520. union lpfc_sli4_cfg_shdr *shdr;
  13521. uint32_t shdr_status, shdr_add_status;
  13522. virt_addr = mboxq->sge_array->addr[0];
  13523. /* The IOCTL status is embedded in the mailbox subheader. */
  13524. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  13525. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13526. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13527. if ((shdr_status || shdr_add_status) &&
  13528. (shdr_status != STATUS_FCF_IN_USE))
  13529. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13530. "2558 ADD_FCF_RECORD mailbox failed with "
  13531. "status x%x add_status x%x\n",
  13532. shdr_status, shdr_add_status);
  13533. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13534. }
  13535. /**
  13536. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  13537. * @phba: pointer to lpfc hba data structure.
  13538. * @fcf_record: pointer to the initialized fcf record to add.
  13539. *
  13540. * This routine is invoked to manually add a single FCF record. The caller
  13541. * must pass a completely initialized FCF_Record. This routine takes
  13542. * care of the nonembedded mailbox operations.
  13543. **/
  13544. int
  13545. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  13546. {
  13547. int rc = 0;
  13548. LPFC_MBOXQ_t *mboxq;
  13549. uint8_t *bytep;
  13550. void *virt_addr;
  13551. dma_addr_t phys_addr;
  13552. struct lpfc_mbx_sge sge;
  13553. uint32_t alloc_len, req_len;
  13554. uint32_t fcfindex;
  13555. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13556. if (!mboxq) {
  13557. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13558. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  13559. return -ENOMEM;
  13560. }
  13561. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  13562. sizeof(uint32_t);
  13563. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13564. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13565. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  13566. req_len, LPFC_SLI4_MBX_NEMBED);
  13567. if (alloc_len < req_len) {
  13568. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13569. "2523 Allocated DMA memory size (x%x) is "
  13570. "less than the requested DMA memory "
  13571. "size (x%x)\n", alloc_len, req_len);
  13572. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13573. return -ENOMEM;
  13574. }
  13575. /*
  13576. * Get the first SGE entry from the non-embedded DMA memory. This
  13577. * routine only uses a single SGE.
  13578. */
  13579. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  13580. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  13581. virt_addr = mboxq->sge_array->addr[0];
  13582. /*
  13583. * Configure the FCF record for FCFI 0. This is the driver's
  13584. * hardcoded default and gets used in nonFIP mode.
  13585. */
  13586. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  13587. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  13588. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  13589. /*
  13590. * Copy the fcf_index and the FCF Record Data. The data starts after
  13591. * the FCoE header plus word10. The data copy needs to be endian
  13592. * correct.
  13593. */
  13594. bytep += sizeof(uint32_t);
  13595. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  13596. mboxq->vport = phba->pport;
  13597. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  13598. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13599. if (rc == MBX_NOT_FINISHED) {
  13600. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13601. "2515 ADD_FCF_RECORD mailbox failed with "
  13602. "status 0x%x\n", rc);
  13603. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13604. rc = -EIO;
  13605. } else
  13606. rc = 0;
  13607. return rc;
  13608. }
  13609. /**
  13610. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  13611. * @phba: pointer to lpfc hba data structure.
  13612. * @fcf_record: pointer to the fcf record to write the default data.
  13613. * @fcf_index: FCF table entry index.
  13614. *
  13615. * This routine is invoked to build the driver's default FCF record. The
  13616. * values used are hardcoded. This routine handles memory initialization.
  13617. *
  13618. **/
  13619. void
  13620. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  13621. struct fcf_record *fcf_record,
  13622. uint16_t fcf_index)
  13623. {
  13624. memset(fcf_record, 0, sizeof(struct fcf_record));
  13625. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  13626. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  13627. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  13628. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  13629. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  13630. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  13631. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  13632. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  13633. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  13634. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  13635. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  13636. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  13637. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  13638. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  13639. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  13640. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  13641. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  13642. /* Set the VLAN bit map */
  13643. if (phba->valid_vlan) {
  13644. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  13645. = 1 << (phba->vlan_id % 8);
  13646. }
  13647. }
  13648. /**
  13649. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  13650. * @phba: pointer to lpfc hba data structure.
  13651. * @fcf_index: FCF table entry offset.
  13652. *
  13653. * This routine is invoked to scan the entire FCF table by reading FCF
  13654. * record and processing it one at a time starting from the @fcf_index
  13655. * for initial FCF discovery or fast FCF failover rediscovery.
  13656. *
  13657. * Return 0 if the mailbox command is submitted successfully, none 0
  13658. * otherwise.
  13659. **/
  13660. int
  13661. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13662. {
  13663. int rc = 0, error;
  13664. LPFC_MBOXQ_t *mboxq;
  13665. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  13666. phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
  13667. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13668. if (!mboxq) {
  13669. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13670. "2000 Failed to allocate mbox for "
  13671. "READ_FCF cmd\n");
  13672. error = -ENOMEM;
  13673. goto fail_fcf_scan;
  13674. }
  13675. /* Construct the read FCF record mailbox command */
  13676. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13677. if (rc) {
  13678. error = -EINVAL;
  13679. goto fail_fcf_scan;
  13680. }
  13681. /* Issue the mailbox command asynchronously */
  13682. mboxq->vport = phba->pport;
  13683. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  13684. spin_lock_irq(&phba->hbalock);
  13685. phba->hba_flag |= FCF_TS_INPROG;
  13686. spin_unlock_irq(&phba->hbalock);
  13687. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13688. if (rc == MBX_NOT_FINISHED)
  13689. error = -EIO;
  13690. else {
  13691. /* Reset eligible FCF count for new scan */
  13692. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  13693. phba->fcf.eligible_fcf_cnt = 0;
  13694. error = 0;
  13695. }
  13696. fail_fcf_scan:
  13697. if (error) {
  13698. if (mboxq)
  13699. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13700. /* FCF scan failed, clear FCF_TS_INPROG flag */
  13701. spin_lock_irq(&phba->hbalock);
  13702. phba->hba_flag &= ~FCF_TS_INPROG;
  13703. spin_unlock_irq(&phba->hbalock);
  13704. }
  13705. return error;
  13706. }
  13707. /**
  13708. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  13709. * @phba: pointer to lpfc hba data structure.
  13710. * @fcf_index: FCF table entry offset.
  13711. *
  13712. * This routine is invoked to read an FCF record indicated by @fcf_index
  13713. * and to use it for FLOGI roundrobin FCF failover.
  13714. *
  13715. * Return 0 if the mailbox command is submitted successfully, none 0
  13716. * otherwise.
  13717. **/
  13718. int
  13719. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13720. {
  13721. int rc = 0, error;
  13722. LPFC_MBOXQ_t *mboxq;
  13723. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13724. if (!mboxq) {
  13725. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13726. "2763 Failed to allocate mbox for "
  13727. "READ_FCF cmd\n");
  13728. error = -ENOMEM;
  13729. goto fail_fcf_read;
  13730. }
  13731. /* Construct the read FCF record mailbox command */
  13732. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13733. if (rc) {
  13734. error = -EINVAL;
  13735. goto fail_fcf_read;
  13736. }
  13737. /* Issue the mailbox command asynchronously */
  13738. mboxq->vport = phba->pport;
  13739. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  13740. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13741. if (rc == MBX_NOT_FINISHED)
  13742. error = -EIO;
  13743. else
  13744. error = 0;
  13745. fail_fcf_read:
  13746. if (error && mboxq)
  13747. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13748. return error;
  13749. }
  13750. /**
  13751. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  13752. * @phba: pointer to lpfc hba data structure.
  13753. * @fcf_index: FCF table entry offset.
  13754. *
  13755. * This routine is invoked to read an FCF record indicated by @fcf_index to
  13756. * determine whether it's eligible for FLOGI roundrobin failover list.
  13757. *
  13758. * Return 0 if the mailbox command is submitted successfully, none 0
  13759. * otherwise.
  13760. **/
  13761. int
  13762. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13763. {
  13764. int rc = 0, error;
  13765. LPFC_MBOXQ_t *mboxq;
  13766. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13767. if (!mboxq) {
  13768. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13769. "2758 Failed to allocate mbox for "
  13770. "READ_FCF cmd\n");
  13771. error = -ENOMEM;
  13772. goto fail_fcf_read;
  13773. }
  13774. /* Construct the read FCF record mailbox command */
  13775. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13776. if (rc) {
  13777. error = -EINVAL;
  13778. goto fail_fcf_read;
  13779. }
  13780. /* Issue the mailbox command asynchronously */
  13781. mboxq->vport = phba->pport;
  13782. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  13783. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13784. if (rc == MBX_NOT_FINISHED)
  13785. error = -EIO;
  13786. else
  13787. error = 0;
  13788. fail_fcf_read:
  13789. if (error && mboxq)
  13790. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13791. return error;
  13792. }
  13793. /**
  13794. * lpfc_check_next_fcf_pri
  13795. * phba pointer to the lpfc_hba struct for this port.
  13796. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  13797. * routine when the rr_bmask is empty. The FCF indecies are put into the
  13798. * rr_bmask based on their priority level. Starting from the highest priority
  13799. * to the lowest. The most likely FCF candidate will be in the highest
  13800. * priority group. When this routine is called it searches the fcf_pri list for
  13801. * next lowest priority group and repopulates the rr_bmask with only those
  13802. * fcf_indexes.
  13803. * returns:
  13804. * 1=success 0=failure
  13805. **/
  13806. int
  13807. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  13808. {
  13809. uint16_t next_fcf_pri;
  13810. uint16_t last_index;
  13811. struct lpfc_fcf_pri *fcf_pri;
  13812. int rc;
  13813. int ret = 0;
  13814. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  13815. LPFC_SLI4_FCF_TBL_INDX_MAX);
  13816. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13817. "3060 Last IDX %d\n", last_index);
  13818. if (list_empty(&phba->fcf.fcf_pri_list)) {
  13819. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13820. "3061 Last IDX %d\n", last_index);
  13821. return 0; /* Empty rr list */
  13822. }
  13823. next_fcf_pri = 0;
  13824. /*
  13825. * Clear the rr_bmask and set all of the bits that are at this
  13826. * priority.
  13827. */
  13828. memset(phba->fcf.fcf_rr_bmask, 0,
  13829. sizeof(*phba->fcf.fcf_rr_bmask));
  13830. spin_lock_irq(&phba->hbalock);
  13831. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13832. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  13833. continue;
  13834. /*
  13835. * the 1st priority that has not FLOGI failed
  13836. * will be the highest.
  13837. */
  13838. if (!next_fcf_pri)
  13839. next_fcf_pri = fcf_pri->fcf_rec.priority;
  13840. spin_unlock_irq(&phba->hbalock);
  13841. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  13842. rc = lpfc_sli4_fcf_rr_index_set(phba,
  13843. fcf_pri->fcf_rec.fcf_index);
  13844. if (rc)
  13845. return 0;
  13846. }
  13847. spin_lock_irq(&phba->hbalock);
  13848. }
  13849. /*
  13850. * if next_fcf_pri was not set above and the list is not empty then
  13851. * we have failed flogis on all of them. So reset flogi failed
  13852. * and start at the begining.
  13853. */
  13854. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  13855. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13856. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  13857. /*
  13858. * the 1st priority that has not FLOGI failed
  13859. * will be the highest.
  13860. */
  13861. if (!next_fcf_pri)
  13862. next_fcf_pri = fcf_pri->fcf_rec.priority;
  13863. spin_unlock_irq(&phba->hbalock);
  13864. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  13865. rc = lpfc_sli4_fcf_rr_index_set(phba,
  13866. fcf_pri->fcf_rec.fcf_index);
  13867. if (rc)
  13868. return 0;
  13869. }
  13870. spin_lock_irq(&phba->hbalock);
  13871. }
  13872. } else
  13873. ret = 1;
  13874. spin_unlock_irq(&phba->hbalock);
  13875. return ret;
  13876. }
  13877. /**
  13878. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  13879. * @phba: pointer to lpfc hba data structure.
  13880. *
  13881. * This routine is to get the next eligible FCF record index in a round
  13882. * robin fashion. If the next eligible FCF record index equals to the
  13883. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  13884. * shall be returned, otherwise, the next eligible FCF record's index
  13885. * shall be returned.
  13886. **/
  13887. uint16_t
  13888. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  13889. {
  13890. uint16_t next_fcf_index;
  13891. /* Search start from next bit of currently registered FCF index */
  13892. next_priority:
  13893. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  13894. LPFC_SLI4_FCF_TBL_INDX_MAX;
  13895. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  13896. LPFC_SLI4_FCF_TBL_INDX_MAX,
  13897. next_fcf_index);
  13898. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  13899. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  13900. /*
  13901. * If we have wrapped then we need to clear the bits that
  13902. * have been tested so that we can detect when we should
  13903. * change the priority level.
  13904. */
  13905. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  13906. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  13907. }
  13908. /* Check roundrobin failover list empty condition */
  13909. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  13910. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  13911. /*
  13912. * If next fcf index is not found check if there are lower
  13913. * Priority level fcf's in the fcf_priority list.
  13914. * Set up the rr_bmask with all of the avaiable fcf bits
  13915. * at that level and continue the selection process.
  13916. */
  13917. if (lpfc_check_next_fcf_pri_level(phba))
  13918. goto next_priority;
  13919. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  13920. "2844 No roundrobin failover FCF available\n");
  13921. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  13922. return LPFC_FCOE_FCF_NEXT_NONE;
  13923. else {
  13924. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  13925. "3063 Only FCF available idx %d, flag %x\n",
  13926. next_fcf_index,
  13927. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  13928. return next_fcf_index;
  13929. }
  13930. }
  13931. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  13932. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  13933. LPFC_FCF_FLOGI_FAILED)
  13934. goto next_priority;
  13935. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13936. "2845 Get next roundrobin failover FCF (x%x)\n",
  13937. next_fcf_index);
  13938. return next_fcf_index;
  13939. }
  13940. /**
  13941. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  13942. * @phba: pointer to lpfc hba data structure.
  13943. *
  13944. * This routine sets the FCF record index in to the eligible bmask for
  13945. * roundrobin failover search. It checks to make sure that the index
  13946. * does not go beyond the range of the driver allocated bmask dimension
  13947. * before setting the bit.
  13948. *
  13949. * Returns 0 if the index bit successfully set, otherwise, it returns
  13950. * -EINVAL.
  13951. **/
  13952. int
  13953. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  13954. {
  13955. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  13956. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13957. "2610 FCF (x%x) reached driver's book "
  13958. "keeping dimension:x%x\n",
  13959. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  13960. return -EINVAL;
  13961. }
  13962. /* Set the eligible FCF record index bmask */
  13963. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  13964. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13965. "2790 Set FCF (x%x) to roundrobin FCF failover "
  13966. "bmask\n", fcf_index);
  13967. return 0;
  13968. }
  13969. /**
  13970. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  13971. * @phba: pointer to lpfc hba data structure.
  13972. *
  13973. * This routine clears the FCF record index from the eligible bmask for
  13974. * roundrobin failover search. It checks to make sure that the index
  13975. * does not go beyond the range of the driver allocated bmask dimension
  13976. * before clearing the bit.
  13977. **/
  13978. void
  13979. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  13980. {
  13981. struct lpfc_fcf_pri *fcf_pri;
  13982. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  13983. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13984. "2762 FCF (x%x) reached driver's book "
  13985. "keeping dimension:x%x\n",
  13986. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  13987. return;
  13988. }
  13989. /* Clear the eligible FCF record index bmask */
  13990. spin_lock_irq(&phba->hbalock);
  13991. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13992. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  13993. list_del_init(&fcf_pri->list);
  13994. break;
  13995. }
  13996. }
  13997. spin_unlock_irq(&phba->hbalock);
  13998. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  13999. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14000. "2791 Clear FCF (x%x) from roundrobin failover "
  14001. "bmask\n", fcf_index);
  14002. }
  14003. /**
  14004. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  14005. * @phba: pointer to lpfc hba data structure.
  14006. *
  14007. * This routine is the completion routine for the rediscover FCF table mailbox
  14008. * command. If the mailbox command returned failure, it will try to stop the
  14009. * FCF rediscover wait timer.
  14010. **/
  14011. void
  14012. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  14013. {
  14014. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14015. uint32_t shdr_status, shdr_add_status;
  14016. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14017. shdr_status = bf_get(lpfc_mbox_hdr_status,
  14018. &redisc_fcf->header.cfg_shdr.response);
  14019. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  14020. &redisc_fcf->header.cfg_shdr.response);
  14021. if (shdr_status || shdr_add_status) {
  14022. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14023. "2746 Requesting for FCF rediscovery failed "
  14024. "status x%x add_status x%x\n",
  14025. shdr_status, shdr_add_status);
  14026. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  14027. spin_lock_irq(&phba->hbalock);
  14028. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  14029. spin_unlock_irq(&phba->hbalock);
  14030. /*
  14031. * CVL event triggered FCF rediscover request failed,
  14032. * last resort to re-try current registered FCF entry.
  14033. */
  14034. lpfc_retry_pport_discovery(phba);
  14035. } else {
  14036. spin_lock_irq(&phba->hbalock);
  14037. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  14038. spin_unlock_irq(&phba->hbalock);
  14039. /*
  14040. * DEAD FCF event triggered FCF rediscover request
  14041. * failed, last resort to fail over as a link down
  14042. * to FCF registration.
  14043. */
  14044. lpfc_sli4_fcf_dead_failthrough(phba);
  14045. }
  14046. } else {
  14047. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14048. "2775 Start FCF rediscover quiescent timer\n");
  14049. /*
  14050. * Start FCF rediscovery wait timer for pending FCF
  14051. * before rescan FCF record table.
  14052. */
  14053. lpfc_fcf_redisc_wait_start_timer(phba);
  14054. }
  14055. mempool_free(mbox, phba->mbox_mem_pool);
  14056. }
  14057. /**
  14058. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  14059. * @phba: pointer to lpfc hba data structure.
  14060. *
  14061. * This routine is invoked to request for rediscovery of the entire FCF table
  14062. * by the port.
  14063. **/
  14064. int
  14065. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  14066. {
  14067. LPFC_MBOXQ_t *mbox;
  14068. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14069. int rc, length;
  14070. /* Cancel retry delay timers to all vports before FCF rediscover */
  14071. lpfc_cancel_all_vport_retry_delay_timer(phba);
  14072. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14073. if (!mbox) {
  14074. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14075. "2745 Failed to allocate mbox for "
  14076. "requesting FCF rediscover.\n");
  14077. return -ENOMEM;
  14078. }
  14079. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  14080. sizeof(struct lpfc_sli4_cfg_mhdr));
  14081. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  14082. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  14083. length, LPFC_SLI4_MBX_EMBED);
  14084. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14085. /* Set count to 0 for invalidating the entire FCF database */
  14086. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  14087. /* Issue the mailbox command asynchronously */
  14088. mbox->vport = phba->pport;
  14089. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  14090. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  14091. if (rc == MBX_NOT_FINISHED) {
  14092. mempool_free(mbox, phba->mbox_mem_pool);
  14093. return -EIO;
  14094. }
  14095. return 0;
  14096. }
  14097. /**
  14098. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  14099. * @phba: pointer to lpfc hba data structure.
  14100. *
  14101. * This function is the failover routine as a last resort to the FCF DEAD
  14102. * event when driver failed to perform fast FCF failover.
  14103. **/
  14104. void
  14105. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  14106. {
  14107. uint32_t link_state;
  14108. /*
  14109. * Last resort as FCF DEAD event failover will treat this as
  14110. * a link down, but save the link state because we don't want
  14111. * it to be changed to Link Down unless it is already down.
  14112. */
  14113. link_state = phba->link_state;
  14114. lpfc_linkdown(phba);
  14115. phba->link_state = link_state;
  14116. /* Unregister FCF if no devices connected to it */
  14117. lpfc_unregister_unused_fcf(phba);
  14118. }
  14119. /**
  14120. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  14121. * @phba: pointer to lpfc hba data structure.
  14122. * @rgn23_data: pointer to configure region 23 data.
  14123. *
  14124. * This function gets SLI3 port configure region 23 data through memory dump
  14125. * mailbox command. When it successfully retrieves data, the size of the data
  14126. * will be returned, otherwise, 0 will be returned.
  14127. **/
  14128. static uint32_t
  14129. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14130. {
  14131. LPFC_MBOXQ_t *pmb = NULL;
  14132. MAILBOX_t *mb;
  14133. uint32_t offset = 0;
  14134. int rc;
  14135. if (!rgn23_data)
  14136. return 0;
  14137. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14138. if (!pmb) {
  14139. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14140. "2600 failed to allocate mailbox memory\n");
  14141. return 0;
  14142. }
  14143. mb = &pmb->u.mb;
  14144. do {
  14145. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  14146. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  14147. if (rc != MBX_SUCCESS) {
  14148. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  14149. "2601 failed to read config "
  14150. "region 23, rc 0x%x Status 0x%x\n",
  14151. rc, mb->mbxStatus);
  14152. mb->un.varDmp.word_cnt = 0;
  14153. }
  14154. /*
  14155. * dump mem may return a zero when finished or we got a
  14156. * mailbox error, either way we are done.
  14157. */
  14158. if (mb->un.varDmp.word_cnt == 0)
  14159. break;
  14160. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  14161. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  14162. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  14163. rgn23_data + offset,
  14164. mb->un.varDmp.word_cnt);
  14165. offset += mb->un.varDmp.word_cnt;
  14166. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  14167. mempool_free(pmb, phba->mbox_mem_pool);
  14168. return offset;
  14169. }
  14170. /**
  14171. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  14172. * @phba: pointer to lpfc hba data structure.
  14173. * @rgn23_data: pointer to configure region 23 data.
  14174. *
  14175. * This function gets SLI4 port configure region 23 data through memory dump
  14176. * mailbox command. When it successfully retrieves data, the size of the data
  14177. * will be returned, otherwise, 0 will be returned.
  14178. **/
  14179. static uint32_t
  14180. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14181. {
  14182. LPFC_MBOXQ_t *mboxq = NULL;
  14183. struct lpfc_dmabuf *mp = NULL;
  14184. struct lpfc_mqe *mqe;
  14185. uint32_t data_length = 0;
  14186. int rc;
  14187. if (!rgn23_data)
  14188. return 0;
  14189. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14190. if (!mboxq) {
  14191. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14192. "3105 failed to allocate mailbox memory\n");
  14193. return 0;
  14194. }
  14195. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  14196. goto out;
  14197. mqe = &mboxq->u.mqe;
  14198. mp = (struct lpfc_dmabuf *) mboxq->context1;
  14199. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14200. if (rc)
  14201. goto out;
  14202. data_length = mqe->un.mb_words[5];
  14203. if (data_length == 0)
  14204. goto out;
  14205. if (data_length > DMP_RGN23_SIZE) {
  14206. data_length = 0;
  14207. goto out;
  14208. }
  14209. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  14210. out:
  14211. mempool_free(mboxq, phba->mbox_mem_pool);
  14212. if (mp) {
  14213. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14214. kfree(mp);
  14215. }
  14216. return data_length;
  14217. }
  14218. /**
  14219. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  14220. * @phba: pointer to lpfc hba data structure.
  14221. *
  14222. * This function read region 23 and parse TLV for port status to
  14223. * decide if the user disaled the port. If the TLV indicates the
  14224. * port is disabled, the hba_flag is set accordingly.
  14225. **/
  14226. void
  14227. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  14228. {
  14229. uint8_t *rgn23_data = NULL;
  14230. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  14231. uint32_t offset = 0;
  14232. /* Get adapter Region 23 data */
  14233. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  14234. if (!rgn23_data)
  14235. goto out;
  14236. if (phba->sli_rev < LPFC_SLI_REV4)
  14237. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  14238. else {
  14239. if_type = bf_get(lpfc_sli_intf_if_type,
  14240. &phba->sli4_hba.sli_intf);
  14241. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  14242. goto out;
  14243. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  14244. }
  14245. if (!data_size)
  14246. goto out;
  14247. /* Check the region signature first */
  14248. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  14249. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14250. "2619 Config region 23 has bad signature\n");
  14251. goto out;
  14252. }
  14253. offset += 4;
  14254. /* Check the data structure version */
  14255. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  14256. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14257. "2620 Config region 23 has bad version\n");
  14258. goto out;
  14259. }
  14260. offset += 4;
  14261. /* Parse TLV entries in the region */
  14262. while (offset < data_size) {
  14263. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  14264. break;
  14265. /*
  14266. * If the TLV is not driver specific TLV or driver id is
  14267. * not linux driver id, skip the record.
  14268. */
  14269. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  14270. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  14271. (rgn23_data[offset + 3] != 0)) {
  14272. offset += rgn23_data[offset + 1] * 4 + 4;
  14273. continue;
  14274. }
  14275. /* Driver found a driver specific TLV in the config region */
  14276. sub_tlv_len = rgn23_data[offset + 1] * 4;
  14277. offset += 4;
  14278. tlv_offset = 0;
  14279. /*
  14280. * Search for configured port state sub-TLV.
  14281. */
  14282. while ((offset < data_size) &&
  14283. (tlv_offset < sub_tlv_len)) {
  14284. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  14285. offset += 4;
  14286. tlv_offset += 4;
  14287. break;
  14288. }
  14289. if (rgn23_data[offset] != PORT_STE_TYPE) {
  14290. offset += rgn23_data[offset + 1] * 4 + 4;
  14291. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  14292. continue;
  14293. }
  14294. /* This HBA contains PORT_STE configured */
  14295. if (!rgn23_data[offset + 2])
  14296. phba->hba_flag |= LINK_DISABLED;
  14297. goto out;
  14298. }
  14299. }
  14300. out:
  14301. kfree(rgn23_data);
  14302. return;
  14303. }
  14304. /**
  14305. * lpfc_wr_object - write an object to the firmware
  14306. * @phba: HBA structure that indicates port to create a queue on.
  14307. * @dmabuf_list: list of dmabufs to write to the port.
  14308. * @size: the total byte value of the objects to write to the port.
  14309. * @offset: the current offset to be used to start the transfer.
  14310. *
  14311. * This routine will create a wr_object mailbox command to send to the port.
  14312. * the mailbox command will be constructed using the dma buffers described in
  14313. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  14314. * BDEs that the imbedded mailbox can support. The @offset variable will be
  14315. * used to indicate the starting offset of the transfer and will also return
  14316. * the offset after the write object mailbox has completed. @size is used to
  14317. * determine the end of the object and whether the eof bit should be set.
  14318. *
  14319. * Return 0 is successful and offset will contain the the new offset to use
  14320. * for the next write.
  14321. * Return negative value for error cases.
  14322. **/
  14323. int
  14324. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  14325. uint32_t size, uint32_t *offset)
  14326. {
  14327. struct lpfc_mbx_wr_object *wr_object;
  14328. LPFC_MBOXQ_t *mbox;
  14329. int rc = 0, i = 0;
  14330. uint32_t shdr_status, shdr_add_status;
  14331. uint32_t mbox_tmo;
  14332. union lpfc_sli4_cfg_shdr *shdr;
  14333. struct lpfc_dmabuf *dmabuf;
  14334. uint32_t written = 0;
  14335. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14336. if (!mbox)
  14337. return -ENOMEM;
  14338. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14339. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  14340. sizeof(struct lpfc_mbx_wr_object) -
  14341. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  14342. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  14343. wr_object->u.request.write_offset = *offset;
  14344. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  14345. wr_object->u.request.object_name[0] =
  14346. cpu_to_le32(wr_object->u.request.object_name[0]);
  14347. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  14348. list_for_each_entry(dmabuf, dmabuf_list, list) {
  14349. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  14350. break;
  14351. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  14352. wr_object->u.request.bde[i].addrHigh =
  14353. putPaddrHigh(dmabuf->phys);
  14354. if (written + SLI4_PAGE_SIZE >= size) {
  14355. wr_object->u.request.bde[i].tus.f.bdeSize =
  14356. (size - written);
  14357. written += (size - written);
  14358. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  14359. } else {
  14360. wr_object->u.request.bde[i].tus.f.bdeSize =
  14361. SLI4_PAGE_SIZE;
  14362. written += SLI4_PAGE_SIZE;
  14363. }
  14364. i++;
  14365. }
  14366. wr_object->u.request.bde_count = i;
  14367. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  14368. if (!phba->sli4_hba.intr_enable)
  14369. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14370. else {
  14371. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  14372. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  14373. }
  14374. /* The IOCTL status is embedded in the mailbox subheader. */
  14375. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  14376. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14377. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14378. if (rc != MBX_TIMEOUT)
  14379. mempool_free(mbox, phba->mbox_mem_pool);
  14380. if (shdr_status || shdr_add_status || rc) {
  14381. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14382. "3025 Write Object mailbox failed with "
  14383. "status x%x add_status x%x, mbx status x%x\n",
  14384. shdr_status, shdr_add_status, rc);
  14385. rc = -ENXIO;
  14386. } else
  14387. *offset += wr_object->u.response.actual_write_length;
  14388. return rc;
  14389. }
  14390. /**
  14391. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  14392. * @vport: pointer to vport data structure.
  14393. *
  14394. * This function iterate through the mailboxq and clean up all REG_LOGIN
  14395. * and REG_VPI mailbox commands associated with the vport. This function
  14396. * is called when driver want to restart discovery of the vport due to
  14397. * a Clear Virtual Link event.
  14398. **/
  14399. void
  14400. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  14401. {
  14402. struct lpfc_hba *phba = vport->phba;
  14403. LPFC_MBOXQ_t *mb, *nextmb;
  14404. struct lpfc_dmabuf *mp;
  14405. struct lpfc_nodelist *ndlp;
  14406. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  14407. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  14408. LIST_HEAD(mbox_cmd_list);
  14409. uint8_t restart_loop;
  14410. /* Clean up internally queued mailbox commands with the vport */
  14411. spin_lock_irq(&phba->hbalock);
  14412. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  14413. if (mb->vport != vport)
  14414. continue;
  14415. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14416. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14417. continue;
  14418. list_del(&mb->list);
  14419. list_add_tail(&mb->list, &mbox_cmd_list);
  14420. }
  14421. /* Clean up active mailbox command with the vport */
  14422. mb = phba->sli.mbox_active;
  14423. if (mb && (mb->vport == vport)) {
  14424. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  14425. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  14426. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14427. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14428. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  14429. /* Put reference count for delayed processing */
  14430. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  14431. /* Unregister the RPI when mailbox complete */
  14432. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14433. }
  14434. }
  14435. /* Cleanup any mailbox completions which are not yet processed */
  14436. do {
  14437. restart_loop = 0;
  14438. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  14439. /*
  14440. * If this mailox is already processed or it is
  14441. * for another vport ignore it.
  14442. */
  14443. if ((mb->vport != vport) ||
  14444. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  14445. continue;
  14446. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14447. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14448. continue;
  14449. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14450. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14451. ndlp = (struct lpfc_nodelist *)mb->context2;
  14452. /* Unregister the RPI when mailbox complete */
  14453. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14454. restart_loop = 1;
  14455. spin_unlock_irq(&phba->hbalock);
  14456. spin_lock(shost->host_lock);
  14457. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14458. spin_unlock(shost->host_lock);
  14459. spin_lock_irq(&phba->hbalock);
  14460. break;
  14461. }
  14462. }
  14463. } while (restart_loop);
  14464. spin_unlock_irq(&phba->hbalock);
  14465. /* Release the cleaned-up mailbox commands */
  14466. while (!list_empty(&mbox_cmd_list)) {
  14467. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  14468. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14469. mp = (struct lpfc_dmabuf *) (mb->context1);
  14470. if (mp) {
  14471. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14472. kfree(mp);
  14473. }
  14474. ndlp = (struct lpfc_nodelist *) mb->context2;
  14475. mb->context2 = NULL;
  14476. if (ndlp) {
  14477. spin_lock(shost->host_lock);
  14478. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14479. spin_unlock(shost->host_lock);
  14480. lpfc_nlp_put(ndlp);
  14481. }
  14482. }
  14483. mempool_free(mb, phba->mbox_mem_pool);
  14484. }
  14485. /* Release the ndlp with the cleaned-up active mailbox command */
  14486. if (act_mbx_ndlp) {
  14487. spin_lock(shost->host_lock);
  14488. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14489. spin_unlock(shost->host_lock);
  14490. lpfc_nlp_put(act_mbx_ndlp);
  14491. }
  14492. }
  14493. /**
  14494. * lpfc_drain_txq - Drain the txq
  14495. * @phba: Pointer to HBA context object.
  14496. *
  14497. * This function attempt to submit IOCBs on the txq
  14498. * to the adapter. For SLI4 adapters, the txq contains
  14499. * ELS IOCBs that have been deferred because the there
  14500. * are no SGLs. This congestion can occur with large
  14501. * vport counts during node discovery.
  14502. **/
  14503. uint32_t
  14504. lpfc_drain_txq(struct lpfc_hba *phba)
  14505. {
  14506. LIST_HEAD(completions);
  14507. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  14508. struct lpfc_iocbq *piocbq = 0;
  14509. unsigned long iflags = 0;
  14510. char *fail_msg = NULL;
  14511. struct lpfc_sglq *sglq;
  14512. union lpfc_wqe wqe;
  14513. spin_lock_irqsave(&phba->hbalock, iflags);
  14514. if (pring->txq_cnt > pring->txq_max)
  14515. pring->txq_max = pring->txq_cnt;
  14516. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14517. while (pring->txq_cnt) {
  14518. spin_lock_irqsave(&phba->hbalock, iflags);
  14519. piocbq = lpfc_sli_ringtx_get(phba, pring);
  14520. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  14521. if (!sglq) {
  14522. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  14523. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14524. break;
  14525. } else {
  14526. if (!piocbq) {
  14527. /* The txq_cnt out of sync. This should
  14528. * never happen
  14529. */
  14530. sglq = __lpfc_clear_active_sglq(phba,
  14531. sglq->sli4_lxritag);
  14532. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14533. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14534. "2823 txq empty and txq_cnt is %d\n ",
  14535. pring->txq_cnt);
  14536. break;
  14537. }
  14538. }
  14539. /* The xri and iocb resources secured,
  14540. * attempt to issue request
  14541. */
  14542. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  14543. piocbq->sli4_xritag = sglq->sli4_xritag;
  14544. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  14545. fail_msg = "to convert bpl to sgl";
  14546. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  14547. fail_msg = "to convert iocb to wqe";
  14548. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  14549. fail_msg = " - Wq is full";
  14550. else
  14551. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  14552. if (fail_msg) {
  14553. /* Failed means we can't issue and need to cancel */
  14554. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14555. "2822 IOCB failed %s iotag 0x%x "
  14556. "xri 0x%x\n",
  14557. fail_msg,
  14558. piocbq->iotag, piocbq->sli4_xritag);
  14559. list_add_tail(&piocbq->list, &completions);
  14560. }
  14561. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14562. }
  14563. /* Cancel all the IOCBs that cannot be issued */
  14564. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  14565. IOERR_SLI_ABORTED);
  14566. return pring->txq_cnt;
  14567. }