lpfc_sli.c 490 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2012 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *,
  63. struct lpfc_cqe *);
  64. static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *,
  65. int);
  66. static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *,
  67. uint32_t);
  68. static IOCB_t *
  69. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  70. {
  71. return &iocbq->iocb;
  72. }
  73. /**
  74. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  75. * @q: The Work Queue to operate on.
  76. * @wqe: The work Queue Entry to put on the Work queue.
  77. *
  78. * This routine will copy the contents of @wqe to the next available entry on
  79. * the @q. This function will then ring the Work Queue Doorbell to signal the
  80. * HBA to start processing the Work Queue Entry. This function returns 0 if
  81. * successful. If no entries are available on @q then this function will return
  82. * -ENOMEM.
  83. * The caller is expected to hold the hbalock when calling this routine.
  84. **/
  85. static uint32_t
  86. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  87. {
  88. union lpfc_wqe *temp_wqe;
  89. struct lpfc_register doorbell;
  90. uint32_t host_index;
  91. uint32_t idx;
  92. /* sanity check on queue memory */
  93. if (unlikely(!q))
  94. return -ENOMEM;
  95. temp_wqe = q->qe[q->host_index].wqe;
  96. /* If the host has not yet processed the next entry then we are done */
  97. idx = ((q->host_index + 1) % q->entry_count);
  98. if (idx == q->hba_index) {
  99. q->WQ_overflow++;
  100. return -ENOMEM;
  101. }
  102. q->WQ_posted++;
  103. /* set consumption flag every once in a while */
  104. if (!((q->host_index + 1) % q->entry_repost))
  105. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  106. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  107. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  108. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  109. /* Update the host index before invoking device */
  110. host_index = q->host_index;
  111. q->host_index = idx;
  112. /* Ring Doorbell */
  113. doorbell.word0 = 0;
  114. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  115. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  116. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  117. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  118. return 0;
  119. }
  120. /**
  121. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  122. * @q: The Work Queue to operate on.
  123. * @index: The index to advance the hba index to.
  124. *
  125. * This routine will update the HBA index of a queue to reflect consumption of
  126. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  127. * an entry the host calls this function to update the queue's internal
  128. * pointers. This routine returns the number of entries that were consumed by
  129. * the HBA.
  130. **/
  131. static uint32_t
  132. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  133. {
  134. uint32_t released = 0;
  135. /* sanity check on queue memory */
  136. if (unlikely(!q))
  137. return 0;
  138. if (q->hba_index == index)
  139. return 0;
  140. do {
  141. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  142. released++;
  143. } while (q->hba_index != index);
  144. return released;
  145. }
  146. /**
  147. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  148. * @q: The Mailbox Queue to operate on.
  149. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  150. *
  151. * This routine will copy the contents of @mqe to the next available entry on
  152. * the @q. This function will then ring the Work Queue Doorbell to signal the
  153. * HBA to start processing the Work Queue Entry. This function returns 0 if
  154. * successful. If no entries are available on @q then this function will return
  155. * -ENOMEM.
  156. * The caller is expected to hold the hbalock when calling this routine.
  157. **/
  158. static uint32_t
  159. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  160. {
  161. struct lpfc_mqe *temp_mqe;
  162. struct lpfc_register doorbell;
  163. uint32_t host_index;
  164. /* sanity check on queue memory */
  165. if (unlikely(!q))
  166. return -ENOMEM;
  167. temp_mqe = q->qe[q->host_index].mqe;
  168. /* If the host has not yet processed the next entry then we are done */
  169. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  170. return -ENOMEM;
  171. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  172. /* Save off the mailbox pointer for completion */
  173. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  174. /* Update the host index before invoking device */
  175. host_index = q->host_index;
  176. q->host_index = ((q->host_index + 1) % q->entry_count);
  177. /* Ring Doorbell */
  178. doorbell.word0 = 0;
  179. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  180. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  181. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  182. return 0;
  183. }
  184. /**
  185. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  186. * @q: The Mailbox Queue to operate on.
  187. *
  188. * This routine will update the HBA index of a queue to reflect consumption of
  189. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  190. * an entry the host calls this function to update the queue's internal
  191. * pointers. This routine returns the number of entries that were consumed by
  192. * the HBA.
  193. **/
  194. static uint32_t
  195. lpfc_sli4_mq_release(struct lpfc_queue *q)
  196. {
  197. /* sanity check on queue memory */
  198. if (unlikely(!q))
  199. return 0;
  200. /* Clear the mailbox pointer for completion */
  201. q->phba->mbox = NULL;
  202. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  203. return 1;
  204. }
  205. /**
  206. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  207. * @q: The Event Queue to get the first valid EQE from
  208. *
  209. * This routine will get the first valid Event Queue Entry from @q, update
  210. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  211. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  212. * processed, but not popped back to the HBA then this routine will return NULL.
  213. **/
  214. static struct lpfc_eqe *
  215. lpfc_sli4_eq_get(struct lpfc_queue *q)
  216. {
  217. struct lpfc_eqe *eqe;
  218. uint32_t idx;
  219. /* sanity check on queue memory */
  220. if (unlikely(!q))
  221. return NULL;
  222. eqe = q->qe[q->hba_index].eqe;
  223. /* If the next EQE is not valid then we are done */
  224. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  225. return NULL;
  226. /* If the host has not yet processed the next entry then we are done */
  227. idx = ((q->hba_index + 1) % q->entry_count);
  228. if (idx == q->host_index)
  229. return NULL;
  230. q->hba_index = idx;
  231. return eqe;
  232. }
  233. /**
  234. * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
  235. * @q: The Event Queue to disable interrupts
  236. *
  237. **/
  238. static inline void
  239. lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
  240. {
  241. struct lpfc_register doorbell;
  242. doorbell.word0 = 0;
  243. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  244. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  245. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  246. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  247. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  248. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  249. }
  250. /**
  251. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  252. * @q: The Event Queue that the host has completed processing for.
  253. * @arm: Indicates whether the host wants to arms this CQ.
  254. *
  255. * This routine will mark all Event Queue Entries on @q, from the last
  256. * known completed entry to the last entry that was processed, as completed
  257. * by clearing the valid bit for each completion queue entry. Then it will
  258. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  259. * The internal host index in the @q will be updated by this routine to indicate
  260. * that the host has finished processing the entries. The @arm parameter
  261. * indicates that the queue should be rearmed when ringing the doorbell.
  262. *
  263. * This function will return the number of EQEs that were popped.
  264. **/
  265. uint32_t
  266. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  267. {
  268. uint32_t released = 0;
  269. struct lpfc_eqe *temp_eqe;
  270. struct lpfc_register doorbell;
  271. /* sanity check on queue memory */
  272. if (unlikely(!q))
  273. return 0;
  274. /* while there are valid entries */
  275. while (q->hba_index != q->host_index) {
  276. temp_eqe = q->qe[q->host_index].eqe;
  277. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  278. released++;
  279. q->host_index = ((q->host_index + 1) % q->entry_count);
  280. }
  281. if (unlikely(released == 0 && !arm))
  282. return 0;
  283. /* ring doorbell for number popped */
  284. doorbell.word0 = 0;
  285. if (arm) {
  286. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  287. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  288. }
  289. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  290. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  291. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  292. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  293. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  294. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  295. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  296. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  297. readl(q->phba->sli4_hba.EQCQDBregaddr);
  298. return released;
  299. }
  300. /**
  301. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  302. * @q: The Completion Queue to get the first valid CQE from
  303. *
  304. * This routine will get the first valid Completion Queue Entry from @q, update
  305. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  306. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  307. * processed, but not popped back to the HBA then this routine will return NULL.
  308. **/
  309. static struct lpfc_cqe *
  310. lpfc_sli4_cq_get(struct lpfc_queue *q)
  311. {
  312. struct lpfc_cqe *cqe;
  313. uint32_t idx;
  314. /* sanity check on queue memory */
  315. if (unlikely(!q))
  316. return NULL;
  317. /* If the next CQE is not valid then we are done */
  318. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  319. return NULL;
  320. /* If the host has not yet processed the next entry then we are done */
  321. idx = ((q->hba_index + 1) % q->entry_count);
  322. if (idx == q->host_index)
  323. return NULL;
  324. cqe = q->qe[q->hba_index].cqe;
  325. q->hba_index = idx;
  326. return cqe;
  327. }
  328. /**
  329. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  330. * @q: The Completion Queue that the host has completed processing for.
  331. * @arm: Indicates whether the host wants to arms this CQ.
  332. *
  333. * This routine will mark all Completion queue entries on @q, from the last
  334. * known completed entry to the last entry that was processed, as completed
  335. * by clearing the valid bit for each completion queue entry. Then it will
  336. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  337. * The internal host index in the @q will be updated by this routine to indicate
  338. * that the host has finished processing the entries. The @arm parameter
  339. * indicates that the queue should be rearmed when ringing the doorbell.
  340. *
  341. * This function will return the number of CQEs that were released.
  342. **/
  343. uint32_t
  344. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  345. {
  346. uint32_t released = 0;
  347. struct lpfc_cqe *temp_qe;
  348. struct lpfc_register doorbell;
  349. /* sanity check on queue memory */
  350. if (unlikely(!q))
  351. return 0;
  352. /* while there are valid entries */
  353. while (q->hba_index != q->host_index) {
  354. temp_qe = q->qe[q->host_index].cqe;
  355. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  356. released++;
  357. q->host_index = ((q->host_index + 1) % q->entry_count);
  358. }
  359. if (unlikely(released == 0 && !arm))
  360. return 0;
  361. /* ring doorbell for number popped */
  362. doorbell.word0 = 0;
  363. if (arm)
  364. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  365. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  366. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  367. bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
  368. (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
  369. bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
  370. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  371. return released;
  372. }
  373. /**
  374. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  375. * @q: The Header Receive Queue to operate on.
  376. * @wqe: The Receive Queue Entry to put on the Receive queue.
  377. *
  378. * This routine will copy the contents of @wqe to the next available entry on
  379. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  380. * HBA to start processing the Receive Queue Entry. This function returns the
  381. * index that the rqe was copied to if successful. If no entries are available
  382. * on @q then this function will return -ENOMEM.
  383. * The caller is expected to hold the hbalock when calling this routine.
  384. **/
  385. static int
  386. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  387. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  388. {
  389. struct lpfc_rqe *temp_hrqe;
  390. struct lpfc_rqe *temp_drqe;
  391. struct lpfc_register doorbell;
  392. int put_index = hq->host_index;
  393. /* sanity check on queue memory */
  394. if (unlikely(!hq) || unlikely(!dq))
  395. return -ENOMEM;
  396. temp_hrqe = hq->qe[hq->host_index].rqe;
  397. temp_drqe = dq->qe[dq->host_index].rqe;
  398. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  399. return -EINVAL;
  400. if (hq->host_index != dq->host_index)
  401. return -EINVAL;
  402. /* If the host has not yet processed the next entry then we are done */
  403. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  404. return -EBUSY;
  405. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  406. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  407. /* Update the host index to point to the next slot */
  408. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  409. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  410. /* Ring The Header Receive Queue Doorbell */
  411. if (!(hq->host_index % hq->entry_repost)) {
  412. doorbell.word0 = 0;
  413. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  414. hq->entry_repost);
  415. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  416. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  417. }
  418. return put_index;
  419. }
  420. /**
  421. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  422. * @q: The Header Receive Queue to operate on.
  423. *
  424. * This routine will update the HBA index of a queue to reflect consumption of
  425. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  426. * consumed an entry the host calls this function to update the queue's
  427. * internal pointers. This routine returns the number of entries that were
  428. * consumed by the HBA.
  429. **/
  430. static uint32_t
  431. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  432. {
  433. /* sanity check on queue memory */
  434. if (unlikely(!hq) || unlikely(!dq))
  435. return 0;
  436. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  437. return 0;
  438. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  439. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  440. return 1;
  441. }
  442. /**
  443. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  444. * @phba: Pointer to HBA context object.
  445. * @pring: Pointer to driver SLI ring object.
  446. *
  447. * This function returns pointer to next command iocb entry
  448. * in the command ring. The caller must hold hbalock to prevent
  449. * other threads consume the next command iocb.
  450. * SLI-2/SLI-3 provide different sized iocbs.
  451. **/
  452. static inline IOCB_t *
  453. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  454. {
  455. return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
  456. pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
  457. }
  458. /**
  459. * lpfc_resp_iocb - Get next response iocb entry in the ring
  460. * @phba: Pointer to HBA context object.
  461. * @pring: Pointer to driver SLI ring object.
  462. *
  463. * This function returns pointer to next response iocb entry
  464. * in the response ring. The caller must hold hbalock to make sure
  465. * that no other thread consume the next response iocb.
  466. * SLI-2/SLI-3 provide different sized iocbs.
  467. **/
  468. static inline IOCB_t *
  469. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  470. {
  471. return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
  472. pring->sli.sli3.rspidx * phba->iocb_rsp_size);
  473. }
  474. /**
  475. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  476. * @phba: Pointer to HBA context object.
  477. *
  478. * This function is called with hbalock held. This function
  479. * allocates a new driver iocb object from the iocb pool. If the
  480. * allocation is successful, it returns pointer to the newly
  481. * allocated iocb object else it returns NULL.
  482. **/
  483. struct lpfc_iocbq *
  484. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  485. {
  486. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  487. struct lpfc_iocbq * iocbq = NULL;
  488. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  489. if (iocbq)
  490. phba->iocb_cnt++;
  491. if (phba->iocb_cnt > phba->iocb_max)
  492. phba->iocb_max = phba->iocb_cnt;
  493. return iocbq;
  494. }
  495. /**
  496. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  497. * @phba: Pointer to HBA context object.
  498. * @xritag: XRI value.
  499. *
  500. * This function clears the sglq pointer from the array of acive
  501. * sglq's. The xritag that is passed in is used to index into the
  502. * array. Before the xritag can be used it needs to be adjusted
  503. * by subtracting the xribase.
  504. *
  505. * Returns sglq ponter = success, NULL = Failure.
  506. **/
  507. static struct lpfc_sglq *
  508. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  509. {
  510. struct lpfc_sglq *sglq;
  511. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  512. phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
  513. return sglq;
  514. }
  515. /**
  516. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  517. * @phba: Pointer to HBA context object.
  518. * @xritag: XRI value.
  519. *
  520. * This function returns the sglq pointer from the array of acive
  521. * sglq's. The xritag that is passed in is used to index into the
  522. * array. Before the xritag can be used it needs to be adjusted
  523. * by subtracting the xribase.
  524. *
  525. * Returns sglq ponter = success, NULL = Failure.
  526. **/
  527. struct lpfc_sglq *
  528. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  529. {
  530. struct lpfc_sglq *sglq;
  531. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  532. return sglq;
  533. }
  534. /**
  535. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  536. * @phba: Pointer to HBA context object.
  537. * @xritag: xri used in this exchange.
  538. * @rrq: The RRQ to be cleared.
  539. *
  540. **/
  541. void
  542. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  543. uint16_t xritag,
  544. struct lpfc_node_rrq *rrq)
  545. {
  546. struct lpfc_nodelist *ndlp = NULL;
  547. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  548. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  549. /* The target DID could have been swapped (cable swap)
  550. * we should use the ndlp from the findnode if it is
  551. * available.
  552. */
  553. if ((!ndlp) && rrq->ndlp)
  554. ndlp = rrq->ndlp;
  555. if (!ndlp)
  556. goto out;
  557. if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) {
  558. rrq->send_rrq = 0;
  559. rrq->xritag = 0;
  560. rrq->rrq_stop_time = 0;
  561. }
  562. out:
  563. mempool_free(rrq, phba->rrq_pool);
  564. }
  565. /**
  566. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  567. * @phba: Pointer to HBA context object.
  568. *
  569. * This function is called with hbalock held. This function
  570. * Checks if stop_time (ratov from setting rrq active) has
  571. * been reached, if it has and the send_rrq flag is set then
  572. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  573. * then it will just call the routine to clear the rrq and
  574. * free the rrq resource.
  575. * The timer is set to the next rrq that is going to expire before
  576. * leaving the routine.
  577. *
  578. **/
  579. void
  580. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  581. {
  582. struct lpfc_node_rrq *rrq;
  583. struct lpfc_node_rrq *nextrrq;
  584. unsigned long next_time;
  585. unsigned long iflags;
  586. LIST_HEAD(send_rrq);
  587. spin_lock_irqsave(&phba->hbalock, iflags);
  588. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  589. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  590. list_for_each_entry_safe(rrq, nextrrq,
  591. &phba->active_rrq_list, list) {
  592. if (time_after(jiffies, rrq->rrq_stop_time))
  593. list_move(&rrq->list, &send_rrq);
  594. else if (time_before(rrq->rrq_stop_time, next_time))
  595. next_time = rrq->rrq_stop_time;
  596. }
  597. spin_unlock_irqrestore(&phba->hbalock, iflags);
  598. if (!list_empty(&phba->active_rrq_list))
  599. mod_timer(&phba->rrq_tmr, next_time);
  600. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  601. list_del(&rrq->list);
  602. if (!rrq->send_rrq)
  603. /* this call will free the rrq */
  604. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  605. else if (lpfc_send_rrq(phba, rrq)) {
  606. /* if we send the rrq then the completion handler
  607. * will clear the bit in the xribitmap.
  608. */
  609. lpfc_clr_rrq_active(phba, rrq->xritag,
  610. rrq);
  611. }
  612. }
  613. }
  614. /**
  615. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  616. * @vport: Pointer to vport context object.
  617. * @xri: The xri used in the exchange.
  618. * @did: The targets DID for this exchange.
  619. *
  620. * returns NULL = rrq not found in the phba->active_rrq_list.
  621. * rrq = rrq for this xri and target.
  622. **/
  623. struct lpfc_node_rrq *
  624. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  625. {
  626. struct lpfc_hba *phba = vport->phba;
  627. struct lpfc_node_rrq *rrq;
  628. struct lpfc_node_rrq *nextrrq;
  629. unsigned long iflags;
  630. if (phba->sli_rev != LPFC_SLI_REV4)
  631. return NULL;
  632. spin_lock_irqsave(&phba->hbalock, iflags);
  633. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  634. if (rrq->vport == vport && rrq->xritag == xri &&
  635. rrq->nlp_DID == did){
  636. list_del(&rrq->list);
  637. spin_unlock_irqrestore(&phba->hbalock, iflags);
  638. return rrq;
  639. }
  640. }
  641. spin_unlock_irqrestore(&phba->hbalock, iflags);
  642. return NULL;
  643. }
  644. /**
  645. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  646. * @vport: Pointer to vport context object.
  647. * @ndlp: Pointer to the lpfc_node_list structure.
  648. * If ndlp is NULL Remove all active RRQs for this vport from the
  649. * phba->active_rrq_list and clear the rrq.
  650. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  651. **/
  652. void
  653. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  654. {
  655. struct lpfc_hba *phba = vport->phba;
  656. struct lpfc_node_rrq *rrq;
  657. struct lpfc_node_rrq *nextrrq;
  658. unsigned long iflags;
  659. LIST_HEAD(rrq_list);
  660. if (phba->sli_rev != LPFC_SLI_REV4)
  661. return;
  662. if (!ndlp) {
  663. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  664. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  665. }
  666. spin_lock_irqsave(&phba->hbalock, iflags);
  667. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  668. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  669. list_move(&rrq->list, &rrq_list);
  670. spin_unlock_irqrestore(&phba->hbalock, iflags);
  671. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  672. list_del(&rrq->list);
  673. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  674. }
  675. }
  676. /**
  677. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  678. * @phba: Pointer to HBA context object.
  679. *
  680. * Remove all rrqs from the phba->active_rrq_list and free them by
  681. * calling __lpfc_clr_active_rrq
  682. *
  683. **/
  684. void
  685. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  686. {
  687. struct lpfc_node_rrq *rrq;
  688. struct lpfc_node_rrq *nextrrq;
  689. unsigned long next_time;
  690. unsigned long iflags;
  691. LIST_HEAD(rrq_list);
  692. if (phba->sli_rev != LPFC_SLI_REV4)
  693. return;
  694. spin_lock_irqsave(&phba->hbalock, iflags);
  695. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  696. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  697. list_splice_init(&phba->active_rrq_list, &rrq_list);
  698. spin_unlock_irqrestore(&phba->hbalock, iflags);
  699. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  700. list_del(&rrq->list);
  701. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  702. }
  703. if (!list_empty(&phba->active_rrq_list))
  704. mod_timer(&phba->rrq_tmr, next_time);
  705. }
  706. /**
  707. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  708. * @phba: Pointer to HBA context object.
  709. * @ndlp: Targets nodelist pointer for this exchange.
  710. * @xritag the xri in the bitmap to test.
  711. *
  712. * This function is called with hbalock held. This function
  713. * returns 0 = rrq not active for this xri
  714. * 1 = rrq is valid for this xri.
  715. **/
  716. int
  717. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  718. uint16_t xritag)
  719. {
  720. if (!ndlp)
  721. return 0;
  722. if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  723. return 1;
  724. else
  725. return 0;
  726. }
  727. /**
  728. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  729. * @phba: Pointer to HBA context object.
  730. * @ndlp: nodelist pointer for this target.
  731. * @xritag: xri used in this exchange.
  732. * @rxid: Remote Exchange ID.
  733. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  734. *
  735. * This function takes the hbalock.
  736. * The active bit is always set in the active rrq xri_bitmap even
  737. * if there is no slot avaiable for the other rrq information.
  738. *
  739. * returns 0 rrq actived for this xri
  740. * < 0 No memory or invalid ndlp.
  741. **/
  742. int
  743. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  744. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  745. {
  746. unsigned long iflags;
  747. struct lpfc_node_rrq *rrq;
  748. int empty;
  749. if (!ndlp)
  750. return -EINVAL;
  751. if (!phba->cfg_enable_rrq)
  752. return -EINVAL;
  753. spin_lock_irqsave(&phba->hbalock, iflags);
  754. if (phba->pport->load_flag & FC_UNLOADING) {
  755. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  756. goto out;
  757. }
  758. /*
  759. * set the active bit even if there is no mem available.
  760. */
  761. if (NLP_CHK_FREE_REQ(ndlp))
  762. goto out;
  763. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  764. goto out;
  765. if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  766. goto out;
  767. spin_unlock_irqrestore(&phba->hbalock, iflags);
  768. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  769. if (!rrq) {
  770. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  771. "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
  772. " DID:0x%x Send:%d\n",
  773. xritag, rxid, ndlp->nlp_DID, send_rrq);
  774. return -EINVAL;
  775. }
  776. rrq->send_rrq = send_rrq;
  777. rrq->xritag = xritag;
  778. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  779. rrq->ndlp = ndlp;
  780. rrq->nlp_DID = ndlp->nlp_DID;
  781. rrq->vport = ndlp->vport;
  782. rrq->rxid = rxid;
  783. rrq->send_rrq = send_rrq;
  784. spin_lock_irqsave(&phba->hbalock, iflags);
  785. empty = list_empty(&phba->active_rrq_list);
  786. list_add_tail(&rrq->list, &phba->active_rrq_list);
  787. phba->hba_flag |= HBA_RRQ_ACTIVE;
  788. if (empty)
  789. lpfc_worker_wake_up(phba);
  790. spin_unlock_irqrestore(&phba->hbalock, iflags);
  791. return 0;
  792. out:
  793. spin_unlock_irqrestore(&phba->hbalock, iflags);
  794. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  795. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  796. " DID:0x%x Send:%d\n",
  797. xritag, rxid, ndlp->nlp_DID, send_rrq);
  798. return -EINVAL;
  799. }
  800. /**
  801. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  802. * @phba: Pointer to HBA context object.
  803. * @piocb: Pointer to the iocbq.
  804. *
  805. * This function is called with hbalock held. This function
  806. * gets a new driver sglq object from the sglq list. If the
  807. * list is not empty then it is successful, it returns pointer to the newly
  808. * allocated sglq object else it returns NULL.
  809. **/
  810. static struct lpfc_sglq *
  811. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  812. {
  813. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  814. struct lpfc_sglq *sglq = NULL;
  815. struct lpfc_sglq *start_sglq = NULL;
  816. struct lpfc_scsi_buf *lpfc_cmd;
  817. struct lpfc_nodelist *ndlp;
  818. int found = 0;
  819. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  820. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  821. ndlp = lpfc_cmd->rdata->pnode;
  822. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  823. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  824. ndlp = piocbq->context_un.ndlp;
  825. else if ((piocbq->iocb.ulpCommand == CMD_ELS_REQUEST64_CR) &&
  826. (piocbq->iocb_flag & LPFC_IO_LIBDFC))
  827. ndlp = piocbq->context_un.ndlp;
  828. else
  829. ndlp = piocbq->context1;
  830. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  831. start_sglq = sglq;
  832. while (!found) {
  833. if (!sglq)
  834. return NULL;
  835. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) {
  836. /* This xri has an rrq outstanding for this DID.
  837. * put it back in the list and get another xri.
  838. */
  839. list_add_tail(&sglq->list, lpfc_sgl_list);
  840. sglq = NULL;
  841. list_remove_head(lpfc_sgl_list, sglq,
  842. struct lpfc_sglq, list);
  843. if (sglq == start_sglq) {
  844. sglq = NULL;
  845. break;
  846. } else
  847. continue;
  848. }
  849. sglq->ndlp = ndlp;
  850. found = 1;
  851. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  852. sglq->state = SGL_ALLOCATED;
  853. }
  854. return sglq;
  855. }
  856. /**
  857. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  858. * @phba: Pointer to HBA context object.
  859. *
  860. * This function is called with no lock held. This function
  861. * allocates a new driver iocb object from the iocb pool. If the
  862. * allocation is successful, it returns pointer to the newly
  863. * allocated iocb object else it returns NULL.
  864. **/
  865. struct lpfc_iocbq *
  866. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  867. {
  868. struct lpfc_iocbq * iocbq = NULL;
  869. unsigned long iflags;
  870. spin_lock_irqsave(&phba->hbalock, iflags);
  871. iocbq = __lpfc_sli_get_iocbq(phba);
  872. spin_unlock_irqrestore(&phba->hbalock, iflags);
  873. return iocbq;
  874. }
  875. /**
  876. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  877. * @phba: Pointer to HBA context object.
  878. * @iocbq: Pointer to driver iocb object.
  879. *
  880. * This function is called with hbalock held to release driver
  881. * iocb object to the iocb pool. The iotag in the iocb object
  882. * does not change for each use of the iocb object. This function
  883. * clears all other fields of the iocb object when it is freed.
  884. * The sqlq structure that holds the xritag and phys and virtual
  885. * mappings for the scatter gather list is retrieved from the
  886. * active array of sglq. The get of the sglq pointer also clears
  887. * the entry in the array. If the status of the IO indiactes that
  888. * this IO was aborted then the sglq entry it put on the
  889. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  890. * IO has good status or fails for any other reason then the sglq
  891. * entry is added to the free list (lpfc_sgl_list).
  892. **/
  893. static void
  894. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  895. {
  896. struct lpfc_sglq *sglq;
  897. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  898. unsigned long iflag = 0;
  899. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  900. if (iocbq->sli4_xritag == NO_XRI)
  901. sglq = NULL;
  902. else
  903. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  904. if (sglq) {
  905. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  906. (sglq->state != SGL_XRI_ABORTED)) {
  907. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  908. iflag);
  909. list_add(&sglq->list,
  910. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  911. spin_unlock_irqrestore(
  912. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  913. } else {
  914. sglq->state = SGL_FREED;
  915. sglq->ndlp = NULL;
  916. list_add_tail(&sglq->list,
  917. &phba->sli4_hba.lpfc_sgl_list);
  918. /* Check if TXQ queue needs to be serviced */
  919. if (pring->txq_cnt)
  920. lpfc_worker_wake_up(phba);
  921. }
  922. }
  923. /*
  924. * Clean all volatile data fields, preserve iotag and node struct.
  925. */
  926. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  927. iocbq->sli4_lxritag = NO_XRI;
  928. iocbq->sli4_xritag = NO_XRI;
  929. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  930. }
  931. /**
  932. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  933. * @phba: Pointer to HBA context object.
  934. * @iocbq: Pointer to driver iocb object.
  935. *
  936. * This function is called with hbalock held to release driver
  937. * iocb object to the iocb pool. The iotag in the iocb object
  938. * does not change for each use of the iocb object. This function
  939. * clears all other fields of the iocb object when it is freed.
  940. **/
  941. static void
  942. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  943. {
  944. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  945. /*
  946. * Clean all volatile data fields, preserve iotag and node struct.
  947. */
  948. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  949. iocbq->sli4_xritag = NO_XRI;
  950. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  951. }
  952. /**
  953. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  954. * @phba: Pointer to HBA context object.
  955. * @iocbq: Pointer to driver iocb object.
  956. *
  957. * This function is called with hbalock held to release driver
  958. * iocb object to the iocb pool. The iotag in the iocb object
  959. * does not change for each use of the iocb object. This function
  960. * clears all other fields of the iocb object when it is freed.
  961. **/
  962. static void
  963. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  964. {
  965. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  966. phba->iocb_cnt--;
  967. }
  968. /**
  969. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  970. * @phba: Pointer to HBA context object.
  971. * @iocbq: Pointer to driver iocb object.
  972. *
  973. * This function is called with no lock held to release the iocb to
  974. * iocb pool.
  975. **/
  976. void
  977. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  978. {
  979. unsigned long iflags;
  980. /*
  981. * Clean all volatile data fields, preserve iotag and node struct.
  982. */
  983. spin_lock_irqsave(&phba->hbalock, iflags);
  984. __lpfc_sli_release_iocbq(phba, iocbq);
  985. spin_unlock_irqrestore(&phba->hbalock, iflags);
  986. }
  987. /**
  988. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  989. * @phba: Pointer to HBA context object.
  990. * @iocblist: List of IOCBs.
  991. * @ulpstatus: ULP status in IOCB command field.
  992. * @ulpWord4: ULP word-4 in IOCB command field.
  993. *
  994. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  995. * on the list by invoking the complete callback function associated with the
  996. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  997. * fields.
  998. **/
  999. void
  1000. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  1001. uint32_t ulpstatus, uint32_t ulpWord4)
  1002. {
  1003. struct lpfc_iocbq *piocb;
  1004. while (!list_empty(iocblist)) {
  1005. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  1006. if (!piocb->iocb_cmpl)
  1007. lpfc_sli_release_iocbq(phba, piocb);
  1008. else {
  1009. piocb->iocb.ulpStatus = ulpstatus;
  1010. piocb->iocb.un.ulpWord[4] = ulpWord4;
  1011. (piocb->iocb_cmpl) (phba, piocb, piocb);
  1012. }
  1013. }
  1014. return;
  1015. }
  1016. /**
  1017. * lpfc_sli_iocb_cmd_type - Get the iocb type
  1018. * @iocb_cmnd: iocb command code.
  1019. *
  1020. * This function is called by ring event handler function to get the iocb type.
  1021. * This function translates the iocb command to an iocb command type used to
  1022. * decide the final disposition of each completed IOCB.
  1023. * The function returns
  1024. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1025. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1026. * LPFC_ABORT_IOCB if it is an abort iocb
  1027. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1028. *
  1029. * The caller is not required to hold any lock.
  1030. **/
  1031. static lpfc_iocb_type
  1032. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1033. {
  1034. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1035. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1036. return 0;
  1037. switch (iocb_cmnd) {
  1038. case CMD_XMIT_SEQUENCE_CR:
  1039. case CMD_XMIT_SEQUENCE_CX:
  1040. case CMD_XMIT_BCAST_CN:
  1041. case CMD_XMIT_BCAST_CX:
  1042. case CMD_ELS_REQUEST_CR:
  1043. case CMD_ELS_REQUEST_CX:
  1044. case CMD_CREATE_XRI_CR:
  1045. case CMD_CREATE_XRI_CX:
  1046. case CMD_GET_RPI_CN:
  1047. case CMD_XMIT_ELS_RSP_CX:
  1048. case CMD_GET_RPI_CR:
  1049. case CMD_FCP_IWRITE_CR:
  1050. case CMD_FCP_IWRITE_CX:
  1051. case CMD_FCP_IREAD_CR:
  1052. case CMD_FCP_IREAD_CX:
  1053. case CMD_FCP_ICMND_CR:
  1054. case CMD_FCP_ICMND_CX:
  1055. case CMD_FCP_TSEND_CX:
  1056. case CMD_FCP_TRSP_CX:
  1057. case CMD_FCP_TRECEIVE_CX:
  1058. case CMD_FCP_AUTO_TRSP_CX:
  1059. case CMD_ADAPTER_MSG:
  1060. case CMD_ADAPTER_DUMP:
  1061. case CMD_XMIT_SEQUENCE64_CR:
  1062. case CMD_XMIT_SEQUENCE64_CX:
  1063. case CMD_XMIT_BCAST64_CN:
  1064. case CMD_XMIT_BCAST64_CX:
  1065. case CMD_ELS_REQUEST64_CR:
  1066. case CMD_ELS_REQUEST64_CX:
  1067. case CMD_FCP_IWRITE64_CR:
  1068. case CMD_FCP_IWRITE64_CX:
  1069. case CMD_FCP_IREAD64_CR:
  1070. case CMD_FCP_IREAD64_CX:
  1071. case CMD_FCP_ICMND64_CR:
  1072. case CMD_FCP_ICMND64_CX:
  1073. case CMD_FCP_TSEND64_CX:
  1074. case CMD_FCP_TRSP64_CX:
  1075. case CMD_FCP_TRECEIVE64_CX:
  1076. case CMD_GEN_REQUEST64_CR:
  1077. case CMD_GEN_REQUEST64_CX:
  1078. case CMD_XMIT_ELS_RSP64_CX:
  1079. case DSSCMD_IWRITE64_CR:
  1080. case DSSCMD_IWRITE64_CX:
  1081. case DSSCMD_IREAD64_CR:
  1082. case DSSCMD_IREAD64_CX:
  1083. type = LPFC_SOL_IOCB;
  1084. break;
  1085. case CMD_ABORT_XRI_CN:
  1086. case CMD_ABORT_XRI_CX:
  1087. case CMD_CLOSE_XRI_CN:
  1088. case CMD_CLOSE_XRI_CX:
  1089. case CMD_XRI_ABORTED_CX:
  1090. case CMD_ABORT_MXRI64_CN:
  1091. case CMD_XMIT_BLS_RSP64_CX:
  1092. type = LPFC_ABORT_IOCB;
  1093. break;
  1094. case CMD_RCV_SEQUENCE_CX:
  1095. case CMD_RCV_ELS_REQ_CX:
  1096. case CMD_RCV_SEQUENCE64_CX:
  1097. case CMD_RCV_ELS_REQ64_CX:
  1098. case CMD_ASYNC_STATUS:
  1099. case CMD_IOCB_RCV_SEQ64_CX:
  1100. case CMD_IOCB_RCV_ELS64_CX:
  1101. case CMD_IOCB_RCV_CONT64_CX:
  1102. case CMD_IOCB_RET_XRI64_CX:
  1103. type = LPFC_UNSOL_IOCB;
  1104. break;
  1105. case CMD_IOCB_XMIT_MSEQ64_CR:
  1106. case CMD_IOCB_XMIT_MSEQ64_CX:
  1107. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1108. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1109. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1110. case CMD_IOCB_ABORT_EXTENDED_CN:
  1111. case CMD_IOCB_RET_HBQE64_CN:
  1112. case CMD_IOCB_FCP_IBIDIR64_CR:
  1113. case CMD_IOCB_FCP_IBIDIR64_CX:
  1114. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1115. case CMD_IOCB_LOGENTRY_CN:
  1116. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1117. printk("%s - Unhandled SLI-3 Command x%x\n",
  1118. __func__, iocb_cmnd);
  1119. type = LPFC_UNKNOWN_IOCB;
  1120. break;
  1121. default:
  1122. type = LPFC_UNKNOWN_IOCB;
  1123. break;
  1124. }
  1125. return type;
  1126. }
  1127. /**
  1128. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1129. * @phba: Pointer to HBA context object.
  1130. *
  1131. * This function is called from SLI initialization code
  1132. * to configure every ring of the HBA's SLI interface. The
  1133. * caller is not required to hold any lock. This function issues
  1134. * a config_ring mailbox command for each ring.
  1135. * This function returns zero if successful else returns a negative
  1136. * error code.
  1137. **/
  1138. static int
  1139. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1140. {
  1141. struct lpfc_sli *psli = &phba->sli;
  1142. LPFC_MBOXQ_t *pmb;
  1143. MAILBOX_t *pmbox;
  1144. int i, rc, ret = 0;
  1145. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1146. if (!pmb)
  1147. return -ENOMEM;
  1148. pmbox = &pmb->u.mb;
  1149. phba->link_state = LPFC_INIT_MBX_CMDS;
  1150. for (i = 0; i < psli->num_rings; i++) {
  1151. lpfc_config_ring(phba, i, pmb);
  1152. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1153. if (rc != MBX_SUCCESS) {
  1154. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1155. "0446 Adapter failed to init (%d), "
  1156. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1157. "ring %d\n",
  1158. rc, pmbox->mbxCommand,
  1159. pmbox->mbxStatus, i);
  1160. phba->link_state = LPFC_HBA_ERROR;
  1161. ret = -ENXIO;
  1162. break;
  1163. }
  1164. }
  1165. mempool_free(pmb, phba->mbox_mem_pool);
  1166. return ret;
  1167. }
  1168. /**
  1169. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1170. * @phba: Pointer to HBA context object.
  1171. * @pring: Pointer to driver SLI ring object.
  1172. * @piocb: Pointer to the driver iocb object.
  1173. *
  1174. * This function is called with hbalock held. The function adds the
  1175. * new iocb to txcmplq of the given ring. This function always returns
  1176. * 0. If this function is called for ELS ring, this function checks if
  1177. * there is a vport associated with the ELS command. This function also
  1178. * starts els_tmofunc timer if this is an ELS command.
  1179. **/
  1180. static int
  1181. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1182. struct lpfc_iocbq *piocb)
  1183. {
  1184. list_add_tail(&piocb->list, &pring->txcmplq);
  1185. piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
  1186. pring->txcmplq_cnt++;
  1187. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1188. pring->txcmplq_max = pring->txcmplq_cnt;
  1189. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1190. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1191. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1192. if (!piocb->vport)
  1193. BUG();
  1194. else
  1195. mod_timer(&piocb->vport->els_tmofunc,
  1196. jiffies + HZ * (phba->fc_ratov << 1));
  1197. }
  1198. return 0;
  1199. }
  1200. /**
  1201. * lpfc_sli_ringtx_get - Get first element of the txq
  1202. * @phba: Pointer to HBA context object.
  1203. * @pring: Pointer to driver SLI ring object.
  1204. *
  1205. * This function is called with hbalock held to get next
  1206. * iocb in txq of the given ring. If there is any iocb in
  1207. * the txq, the function returns first iocb in the list after
  1208. * removing the iocb from the list, else it returns NULL.
  1209. **/
  1210. struct lpfc_iocbq *
  1211. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1212. {
  1213. struct lpfc_iocbq *cmd_iocb;
  1214. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1215. if (cmd_iocb != NULL)
  1216. pring->txq_cnt--;
  1217. return cmd_iocb;
  1218. }
  1219. /**
  1220. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1221. * @phba: Pointer to HBA context object.
  1222. * @pring: Pointer to driver SLI ring object.
  1223. *
  1224. * This function is called with hbalock held and the caller must post the
  1225. * iocb without releasing the lock. If the caller releases the lock,
  1226. * iocb slot returned by the function is not guaranteed to be available.
  1227. * The function returns pointer to the next available iocb slot if there
  1228. * is available slot in the ring, else it returns NULL.
  1229. * If the get index of the ring is ahead of the put index, the function
  1230. * will post an error attention event to the worker thread to take the
  1231. * HBA to offline state.
  1232. **/
  1233. static IOCB_t *
  1234. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1235. {
  1236. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1237. uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
  1238. if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
  1239. (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
  1240. pring->sli.sli3.next_cmdidx = 0;
  1241. if (unlikely(pring->sli.sli3.local_getidx ==
  1242. pring->sli.sli3.next_cmdidx)) {
  1243. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1244. if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
  1245. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1246. "0315 Ring %d issue: portCmdGet %d "
  1247. "is bigger than cmd ring %d\n",
  1248. pring->ringno,
  1249. pring->sli.sli3.local_getidx,
  1250. max_cmd_idx);
  1251. phba->link_state = LPFC_HBA_ERROR;
  1252. /*
  1253. * All error attention handlers are posted to
  1254. * worker thread
  1255. */
  1256. phba->work_ha |= HA_ERATT;
  1257. phba->work_hs = HS_FFER3;
  1258. lpfc_worker_wake_up(phba);
  1259. return NULL;
  1260. }
  1261. if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
  1262. return NULL;
  1263. }
  1264. return lpfc_cmd_iocb(phba, pring);
  1265. }
  1266. /**
  1267. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1268. * @phba: Pointer to HBA context object.
  1269. * @iocbq: Pointer to driver iocb object.
  1270. *
  1271. * This function gets an iotag for the iocb. If there is no unused iotag and
  1272. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1273. * array and assigns a new iotag.
  1274. * The function returns the allocated iotag if successful, else returns zero.
  1275. * Zero is not a valid iotag.
  1276. * The caller is not required to hold any lock.
  1277. **/
  1278. uint16_t
  1279. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1280. {
  1281. struct lpfc_iocbq **new_arr;
  1282. struct lpfc_iocbq **old_arr;
  1283. size_t new_len;
  1284. struct lpfc_sli *psli = &phba->sli;
  1285. uint16_t iotag;
  1286. spin_lock_irq(&phba->hbalock);
  1287. iotag = psli->last_iotag;
  1288. if(++iotag < psli->iocbq_lookup_len) {
  1289. psli->last_iotag = iotag;
  1290. psli->iocbq_lookup[iotag] = iocbq;
  1291. spin_unlock_irq(&phba->hbalock);
  1292. iocbq->iotag = iotag;
  1293. return iotag;
  1294. } else if (psli->iocbq_lookup_len < (0xffff
  1295. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1296. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1297. spin_unlock_irq(&phba->hbalock);
  1298. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1299. GFP_KERNEL);
  1300. if (new_arr) {
  1301. spin_lock_irq(&phba->hbalock);
  1302. old_arr = psli->iocbq_lookup;
  1303. if (new_len <= psli->iocbq_lookup_len) {
  1304. /* highly unprobable case */
  1305. kfree(new_arr);
  1306. iotag = psli->last_iotag;
  1307. if(++iotag < psli->iocbq_lookup_len) {
  1308. psli->last_iotag = iotag;
  1309. psli->iocbq_lookup[iotag] = iocbq;
  1310. spin_unlock_irq(&phba->hbalock);
  1311. iocbq->iotag = iotag;
  1312. return iotag;
  1313. }
  1314. spin_unlock_irq(&phba->hbalock);
  1315. return 0;
  1316. }
  1317. if (psli->iocbq_lookup)
  1318. memcpy(new_arr, old_arr,
  1319. ((psli->last_iotag + 1) *
  1320. sizeof (struct lpfc_iocbq *)));
  1321. psli->iocbq_lookup = new_arr;
  1322. psli->iocbq_lookup_len = new_len;
  1323. psli->last_iotag = iotag;
  1324. psli->iocbq_lookup[iotag] = iocbq;
  1325. spin_unlock_irq(&phba->hbalock);
  1326. iocbq->iotag = iotag;
  1327. kfree(old_arr);
  1328. return iotag;
  1329. }
  1330. } else
  1331. spin_unlock_irq(&phba->hbalock);
  1332. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1333. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1334. psli->last_iotag);
  1335. return 0;
  1336. }
  1337. /**
  1338. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1339. * @phba: Pointer to HBA context object.
  1340. * @pring: Pointer to driver SLI ring object.
  1341. * @iocb: Pointer to iocb slot in the ring.
  1342. * @nextiocb: Pointer to driver iocb object which need to be
  1343. * posted to firmware.
  1344. *
  1345. * This function is called with hbalock held to post a new iocb to
  1346. * the firmware. This function copies the new iocb to ring iocb slot and
  1347. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1348. * a completion call back for this iocb else the function will free the
  1349. * iocb object.
  1350. **/
  1351. static void
  1352. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1353. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1354. {
  1355. /*
  1356. * Set up an iotag
  1357. */
  1358. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1359. if (pring->ringno == LPFC_ELS_RING) {
  1360. lpfc_debugfs_slow_ring_trc(phba,
  1361. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1362. *(((uint32_t *) &nextiocb->iocb) + 4),
  1363. *(((uint32_t *) &nextiocb->iocb) + 6),
  1364. *(((uint32_t *) &nextiocb->iocb) + 7));
  1365. }
  1366. /*
  1367. * Issue iocb command to adapter
  1368. */
  1369. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1370. wmb();
  1371. pring->stats.iocb_cmd++;
  1372. /*
  1373. * If there is no completion routine to call, we can release the
  1374. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1375. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1376. */
  1377. if (nextiocb->iocb_cmpl)
  1378. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1379. else
  1380. __lpfc_sli_release_iocbq(phba, nextiocb);
  1381. /*
  1382. * Let the HBA know what IOCB slot will be the next one the
  1383. * driver will put a command into.
  1384. */
  1385. pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
  1386. writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1387. }
  1388. /**
  1389. * lpfc_sli_update_full_ring - Update the chip attention register
  1390. * @phba: Pointer to HBA context object.
  1391. * @pring: Pointer to driver SLI ring object.
  1392. *
  1393. * The caller is not required to hold any lock for calling this function.
  1394. * This function updates the chip attention bits for the ring to inform firmware
  1395. * that there are pending work to be done for this ring and requests an
  1396. * interrupt when there is space available in the ring. This function is
  1397. * called when the driver is unable to post more iocbs to the ring due
  1398. * to unavailability of space in the ring.
  1399. **/
  1400. static void
  1401. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1402. {
  1403. int ringno = pring->ringno;
  1404. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1405. wmb();
  1406. /*
  1407. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1408. * The HBA will tell us when an IOCB entry is available.
  1409. */
  1410. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1411. readl(phba->CAregaddr); /* flush */
  1412. pring->stats.iocb_cmd_full++;
  1413. }
  1414. /**
  1415. * lpfc_sli_update_ring - Update chip attention register
  1416. * @phba: Pointer to HBA context object.
  1417. * @pring: Pointer to driver SLI ring object.
  1418. *
  1419. * This function updates the chip attention register bit for the
  1420. * given ring to inform HBA that there is more work to be done
  1421. * in this ring. The caller is not required to hold any lock.
  1422. **/
  1423. static void
  1424. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1425. {
  1426. int ringno = pring->ringno;
  1427. /*
  1428. * Tell the HBA that there is work to do in this ring.
  1429. */
  1430. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1431. wmb();
  1432. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1433. readl(phba->CAregaddr); /* flush */
  1434. }
  1435. }
  1436. /**
  1437. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1438. * @phba: Pointer to HBA context object.
  1439. * @pring: Pointer to driver SLI ring object.
  1440. *
  1441. * This function is called with hbalock held to post pending iocbs
  1442. * in the txq to the firmware. This function is called when driver
  1443. * detects space available in the ring.
  1444. **/
  1445. static void
  1446. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1447. {
  1448. IOCB_t *iocb;
  1449. struct lpfc_iocbq *nextiocb;
  1450. /*
  1451. * Check to see if:
  1452. * (a) there is anything on the txq to send
  1453. * (b) link is up
  1454. * (c) link attention events can be processed (fcp ring only)
  1455. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1456. */
  1457. if (pring->txq_cnt &&
  1458. lpfc_is_link_up(phba) &&
  1459. (pring->ringno != phba->sli.fcp_ring ||
  1460. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1461. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1462. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1463. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1464. if (iocb)
  1465. lpfc_sli_update_ring(phba, pring);
  1466. else
  1467. lpfc_sli_update_full_ring(phba, pring);
  1468. }
  1469. return;
  1470. }
  1471. /**
  1472. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1473. * @phba: Pointer to HBA context object.
  1474. * @hbqno: HBQ number.
  1475. *
  1476. * This function is called with hbalock held to get the next
  1477. * available slot for the given HBQ. If there is free slot
  1478. * available for the HBQ it will return pointer to the next available
  1479. * HBQ entry else it will return NULL.
  1480. **/
  1481. static struct lpfc_hbq_entry *
  1482. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1483. {
  1484. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1485. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1486. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1487. hbqp->next_hbqPutIdx = 0;
  1488. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1489. uint32_t raw_index = phba->hbq_get[hbqno];
  1490. uint32_t getidx = le32_to_cpu(raw_index);
  1491. hbqp->local_hbqGetIdx = getidx;
  1492. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1493. lpfc_printf_log(phba, KERN_ERR,
  1494. LOG_SLI | LOG_VPORT,
  1495. "1802 HBQ %d: local_hbqGetIdx "
  1496. "%u is > than hbqp->entry_count %u\n",
  1497. hbqno, hbqp->local_hbqGetIdx,
  1498. hbqp->entry_count);
  1499. phba->link_state = LPFC_HBA_ERROR;
  1500. return NULL;
  1501. }
  1502. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1503. return NULL;
  1504. }
  1505. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1506. hbqp->hbqPutIdx;
  1507. }
  1508. /**
  1509. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1510. * @phba: Pointer to HBA context object.
  1511. *
  1512. * This function is called with no lock held to free all the
  1513. * hbq buffers while uninitializing the SLI interface. It also
  1514. * frees the HBQ buffers returned by the firmware but not yet
  1515. * processed by the upper layers.
  1516. **/
  1517. void
  1518. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1519. {
  1520. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1521. struct hbq_dmabuf *hbq_buf;
  1522. unsigned long flags;
  1523. int i, hbq_count;
  1524. uint32_t hbqno;
  1525. hbq_count = lpfc_sli_hbq_count();
  1526. /* Return all memory used by all HBQs */
  1527. spin_lock_irqsave(&phba->hbalock, flags);
  1528. for (i = 0; i < hbq_count; ++i) {
  1529. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1530. &phba->hbqs[i].hbq_buffer_list, list) {
  1531. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1532. list_del(&hbq_buf->dbuf.list);
  1533. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1534. }
  1535. phba->hbqs[i].buffer_count = 0;
  1536. }
  1537. /* Return all HBQ buffer that are in-fly */
  1538. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1539. list) {
  1540. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1541. list_del(&hbq_buf->dbuf.list);
  1542. if (hbq_buf->tag == -1) {
  1543. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1544. (phba, hbq_buf);
  1545. } else {
  1546. hbqno = hbq_buf->tag >> 16;
  1547. if (hbqno >= LPFC_MAX_HBQS)
  1548. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1549. (phba, hbq_buf);
  1550. else
  1551. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1552. hbq_buf);
  1553. }
  1554. }
  1555. /* Mark the HBQs not in use */
  1556. phba->hbq_in_use = 0;
  1557. spin_unlock_irqrestore(&phba->hbalock, flags);
  1558. }
  1559. /**
  1560. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1561. * @phba: Pointer to HBA context object.
  1562. * @hbqno: HBQ number.
  1563. * @hbq_buf: Pointer to HBQ buffer.
  1564. *
  1565. * This function is called with the hbalock held to post a
  1566. * hbq buffer to the firmware. If the function finds an empty
  1567. * slot in the HBQ, it will post the buffer. The function will return
  1568. * pointer to the hbq entry if it successfully post the buffer
  1569. * else it will return NULL.
  1570. **/
  1571. static int
  1572. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1573. struct hbq_dmabuf *hbq_buf)
  1574. {
  1575. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1576. }
  1577. /**
  1578. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1579. * @phba: Pointer to HBA context object.
  1580. * @hbqno: HBQ number.
  1581. * @hbq_buf: Pointer to HBQ buffer.
  1582. *
  1583. * This function is called with the hbalock held to post a hbq buffer to the
  1584. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1585. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1586. * it successfully post the buffer else it will return an error.
  1587. **/
  1588. static int
  1589. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1590. struct hbq_dmabuf *hbq_buf)
  1591. {
  1592. struct lpfc_hbq_entry *hbqe;
  1593. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1594. /* Get next HBQ entry slot to use */
  1595. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1596. if (hbqe) {
  1597. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1598. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1599. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1600. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1601. hbqe->bde.tus.f.bdeFlags = 0;
  1602. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1603. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1604. /* Sync SLIM */
  1605. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1606. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1607. /* flush */
  1608. readl(phba->hbq_put + hbqno);
  1609. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1610. return 0;
  1611. } else
  1612. return -ENOMEM;
  1613. }
  1614. /**
  1615. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1616. * @phba: Pointer to HBA context object.
  1617. * @hbqno: HBQ number.
  1618. * @hbq_buf: Pointer to HBQ buffer.
  1619. *
  1620. * This function is called with the hbalock held to post an RQE to the SLI4
  1621. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1622. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1623. **/
  1624. static int
  1625. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1626. struct hbq_dmabuf *hbq_buf)
  1627. {
  1628. int rc;
  1629. struct lpfc_rqe hrqe;
  1630. struct lpfc_rqe drqe;
  1631. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1632. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1633. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1634. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1635. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1636. &hrqe, &drqe);
  1637. if (rc < 0)
  1638. return rc;
  1639. hbq_buf->tag = rc;
  1640. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1641. return 0;
  1642. }
  1643. /* HBQ for ELS and CT traffic. */
  1644. static struct lpfc_hbq_init lpfc_els_hbq = {
  1645. .rn = 1,
  1646. .entry_count = 256,
  1647. .mask_count = 0,
  1648. .profile = 0,
  1649. .ring_mask = (1 << LPFC_ELS_RING),
  1650. .buffer_count = 0,
  1651. .init_count = 40,
  1652. .add_count = 40,
  1653. };
  1654. /* HBQ for the extra ring if needed */
  1655. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1656. .rn = 1,
  1657. .entry_count = 200,
  1658. .mask_count = 0,
  1659. .profile = 0,
  1660. .ring_mask = (1 << LPFC_EXTRA_RING),
  1661. .buffer_count = 0,
  1662. .init_count = 0,
  1663. .add_count = 5,
  1664. };
  1665. /* Array of HBQs */
  1666. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1667. &lpfc_els_hbq,
  1668. &lpfc_extra_hbq,
  1669. };
  1670. /**
  1671. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1672. * @phba: Pointer to HBA context object.
  1673. * @hbqno: HBQ number.
  1674. * @count: Number of HBQ buffers to be posted.
  1675. *
  1676. * This function is called with no lock held to post more hbq buffers to the
  1677. * given HBQ. The function returns the number of HBQ buffers successfully
  1678. * posted.
  1679. **/
  1680. static int
  1681. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1682. {
  1683. uint32_t i, posted = 0;
  1684. unsigned long flags;
  1685. struct hbq_dmabuf *hbq_buffer;
  1686. LIST_HEAD(hbq_buf_list);
  1687. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1688. return 0;
  1689. if ((phba->hbqs[hbqno].buffer_count + count) >
  1690. lpfc_hbq_defs[hbqno]->entry_count)
  1691. count = lpfc_hbq_defs[hbqno]->entry_count -
  1692. phba->hbqs[hbqno].buffer_count;
  1693. if (!count)
  1694. return 0;
  1695. /* Allocate HBQ entries */
  1696. for (i = 0; i < count; i++) {
  1697. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1698. if (!hbq_buffer)
  1699. break;
  1700. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1701. }
  1702. /* Check whether HBQ is still in use */
  1703. spin_lock_irqsave(&phba->hbalock, flags);
  1704. if (!phba->hbq_in_use)
  1705. goto err;
  1706. while (!list_empty(&hbq_buf_list)) {
  1707. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1708. dbuf.list);
  1709. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1710. (hbqno << 16));
  1711. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1712. phba->hbqs[hbqno].buffer_count++;
  1713. posted++;
  1714. } else
  1715. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1716. }
  1717. spin_unlock_irqrestore(&phba->hbalock, flags);
  1718. return posted;
  1719. err:
  1720. spin_unlock_irqrestore(&phba->hbalock, flags);
  1721. while (!list_empty(&hbq_buf_list)) {
  1722. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1723. dbuf.list);
  1724. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1725. }
  1726. return 0;
  1727. }
  1728. /**
  1729. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1730. * @phba: Pointer to HBA context object.
  1731. * @qno: HBQ number.
  1732. *
  1733. * This function posts more buffers to the HBQ. This function
  1734. * is called with no lock held. The function returns the number of HBQ entries
  1735. * successfully allocated.
  1736. **/
  1737. int
  1738. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1739. {
  1740. if (phba->sli_rev == LPFC_SLI_REV4)
  1741. return 0;
  1742. else
  1743. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1744. lpfc_hbq_defs[qno]->add_count);
  1745. }
  1746. /**
  1747. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1748. * @phba: Pointer to HBA context object.
  1749. * @qno: HBQ queue number.
  1750. *
  1751. * This function is called from SLI initialization code path with
  1752. * no lock held to post initial HBQ buffers to firmware. The
  1753. * function returns the number of HBQ entries successfully allocated.
  1754. **/
  1755. static int
  1756. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1757. {
  1758. if (phba->sli_rev == LPFC_SLI_REV4)
  1759. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1760. lpfc_hbq_defs[qno]->entry_count);
  1761. else
  1762. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1763. lpfc_hbq_defs[qno]->init_count);
  1764. }
  1765. /**
  1766. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1767. * @phba: Pointer to HBA context object.
  1768. * @hbqno: HBQ number.
  1769. *
  1770. * This function removes the first hbq buffer on an hbq list and returns a
  1771. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1772. **/
  1773. static struct hbq_dmabuf *
  1774. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1775. {
  1776. struct lpfc_dmabuf *d_buf;
  1777. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1778. if (!d_buf)
  1779. return NULL;
  1780. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1781. }
  1782. /**
  1783. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1784. * @phba: Pointer to HBA context object.
  1785. * @tag: Tag of the hbq buffer.
  1786. *
  1787. * This function is called with hbalock held. This function searches
  1788. * for the hbq buffer associated with the given tag in the hbq buffer
  1789. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1790. * it returns NULL.
  1791. **/
  1792. static struct hbq_dmabuf *
  1793. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1794. {
  1795. struct lpfc_dmabuf *d_buf;
  1796. struct hbq_dmabuf *hbq_buf;
  1797. uint32_t hbqno;
  1798. hbqno = tag >> 16;
  1799. if (hbqno >= LPFC_MAX_HBQS)
  1800. return NULL;
  1801. spin_lock_irq(&phba->hbalock);
  1802. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1803. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1804. if (hbq_buf->tag == tag) {
  1805. spin_unlock_irq(&phba->hbalock);
  1806. return hbq_buf;
  1807. }
  1808. }
  1809. spin_unlock_irq(&phba->hbalock);
  1810. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1811. "1803 Bad hbq tag. Data: x%x x%x\n",
  1812. tag, phba->hbqs[tag >> 16].buffer_count);
  1813. return NULL;
  1814. }
  1815. /**
  1816. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1817. * @phba: Pointer to HBA context object.
  1818. * @hbq_buffer: Pointer to HBQ buffer.
  1819. *
  1820. * This function is called with hbalock. This function gives back
  1821. * the hbq buffer to firmware. If the HBQ does not have space to
  1822. * post the buffer, it will free the buffer.
  1823. **/
  1824. void
  1825. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1826. {
  1827. uint32_t hbqno;
  1828. if (hbq_buffer) {
  1829. hbqno = hbq_buffer->tag >> 16;
  1830. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1831. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1832. }
  1833. }
  1834. /**
  1835. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1836. * @mbxCommand: mailbox command code.
  1837. *
  1838. * This function is called by the mailbox event handler function to verify
  1839. * that the completed mailbox command is a legitimate mailbox command. If the
  1840. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1841. * and the mailbox event handler will take the HBA offline.
  1842. **/
  1843. static int
  1844. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1845. {
  1846. uint8_t ret;
  1847. switch (mbxCommand) {
  1848. case MBX_LOAD_SM:
  1849. case MBX_READ_NV:
  1850. case MBX_WRITE_NV:
  1851. case MBX_WRITE_VPARMS:
  1852. case MBX_RUN_BIU_DIAG:
  1853. case MBX_INIT_LINK:
  1854. case MBX_DOWN_LINK:
  1855. case MBX_CONFIG_LINK:
  1856. case MBX_CONFIG_RING:
  1857. case MBX_RESET_RING:
  1858. case MBX_READ_CONFIG:
  1859. case MBX_READ_RCONFIG:
  1860. case MBX_READ_SPARM:
  1861. case MBX_READ_STATUS:
  1862. case MBX_READ_RPI:
  1863. case MBX_READ_XRI:
  1864. case MBX_READ_REV:
  1865. case MBX_READ_LNK_STAT:
  1866. case MBX_REG_LOGIN:
  1867. case MBX_UNREG_LOGIN:
  1868. case MBX_CLEAR_LA:
  1869. case MBX_DUMP_MEMORY:
  1870. case MBX_DUMP_CONTEXT:
  1871. case MBX_RUN_DIAGS:
  1872. case MBX_RESTART:
  1873. case MBX_UPDATE_CFG:
  1874. case MBX_DOWN_LOAD:
  1875. case MBX_DEL_LD_ENTRY:
  1876. case MBX_RUN_PROGRAM:
  1877. case MBX_SET_MASK:
  1878. case MBX_SET_VARIABLE:
  1879. case MBX_UNREG_D_ID:
  1880. case MBX_KILL_BOARD:
  1881. case MBX_CONFIG_FARP:
  1882. case MBX_BEACON:
  1883. case MBX_LOAD_AREA:
  1884. case MBX_RUN_BIU_DIAG64:
  1885. case MBX_CONFIG_PORT:
  1886. case MBX_READ_SPARM64:
  1887. case MBX_READ_RPI64:
  1888. case MBX_REG_LOGIN64:
  1889. case MBX_READ_TOPOLOGY:
  1890. case MBX_WRITE_WWN:
  1891. case MBX_SET_DEBUG:
  1892. case MBX_LOAD_EXP_ROM:
  1893. case MBX_ASYNCEVT_ENABLE:
  1894. case MBX_REG_VPI:
  1895. case MBX_UNREG_VPI:
  1896. case MBX_HEARTBEAT:
  1897. case MBX_PORT_CAPABILITIES:
  1898. case MBX_PORT_IOV_CONTROL:
  1899. case MBX_SLI4_CONFIG:
  1900. case MBX_SLI4_REQ_FTRS:
  1901. case MBX_REG_FCFI:
  1902. case MBX_UNREG_FCFI:
  1903. case MBX_REG_VFI:
  1904. case MBX_UNREG_VFI:
  1905. case MBX_INIT_VPI:
  1906. case MBX_INIT_VFI:
  1907. case MBX_RESUME_RPI:
  1908. case MBX_READ_EVENT_LOG_STATUS:
  1909. case MBX_READ_EVENT_LOG:
  1910. case MBX_SECURITY_MGMT:
  1911. case MBX_AUTH_PORT:
  1912. case MBX_ACCESS_VDATA:
  1913. ret = mbxCommand;
  1914. break;
  1915. default:
  1916. ret = MBX_SHUTDOWN;
  1917. break;
  1918. }
  1919. return ret;
  1920. }
  1921. /**
  1922. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1923. * @phba: Pointer to HBA context object.
  1924. * @pmboxq: Pointer to mailbox command.
  1925. *
  1926. * This is completion handler function for mailbox commands issued from
  1927. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1928. * mailbox event handler function with no lock held. This function
  1929. * will wake up thread waiting on the wait queue pointed by context1
  1930. * of the mailbox.
  1931. **/
  1932. void
  1933. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1934. {
  1935. wait_queue_head_t *pdone_q;
  1936. unsigned long drvr_flag;
  1937. /*
  1938. * If pdone_q is empty, the driver thread gave up waiting and
  1939. * continued running.
  1940. */
  1941. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1942. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1943. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1944. if (pdone_q)
  1945. wake_up_interruptible(pdone_q);
  1946. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1947. return;
  1948. }
  1949. /**
  1950. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1951. * @phba: Pointer to HBA context object.
  1952. * @pmb: Pointer to mailbox object.
  1953. *
  1954. * This function is the default mailbox completion handler. It
  1955. * frees the memory resources associated with the completed mailbox
  1956. * command. If the completed command is a REG_LOGIN mailbox command,
  1957. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1958. **/
  1959. void
  1960. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1961. {
  1962. struct lpfc_vport *vport = pmb->vport;
  1963. struct lpfc_dmabuf *mp;
  1964. struct lpfc_nodelist *ndlp;
  1965. struct Scsi_Host *shost;
  1966. uint16_t rpi, vpi;
  1967. int rc;
  1968. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1969. if (mp) {
  1970. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1971. kfree(mp);
  1972. }
  1973. /*
  1974. * If a REG_LOGIN succeeded after node is destroyed or node
  1975. * is in re-discovery driver need to cleanup the RPI.
  1976. */
  1977. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1978. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1979. !pmb->u.mb.mbxStatus) {
  1980. rpi = pmb->u.mb.un.varWords[0];
  1981. vpi = pmb->u.mb.un.varRegLogin.vpi;
  1982. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1983. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1984. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1985. if (rc != MBX_NOT_FINISHED)
  1986. return;
  1987. }
  1988. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1989. !(phba->pport->load_flag & FC_UNLOADING) &&
  1990. !pmb->u.mb.mbxStatus) {
  1991. shost = lpfc_shost_from_vport(vport);
  1992. spin_lock_irq(shost->host_lock);
  1993. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1994. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1995. spin_unlock_irq(shost->host_lock);
  1996. }
  1997. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1998. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1999. lpfc_nlp_put(ndlp);
  2000. pmb->context2 = NULL;
  2001. }
  2002. /* Check security permission status on INIT_LINK mailbox command */
  2003. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  2004. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  2005. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2006. "2860 SLI authentication is required "
  2007. "for INIT_LINK but has not done yet\n");
  2008. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  2009. lpfc_sli4_mbox_cmd_free(phba, pmb);
  2010. else
  2011. mempool_free(pmb, phba->mbox_mem_pool);
  2012. }
  2013. /**
  2014. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  2015. * @phba: Pointer to HBA context object.
  2016. *
  2017. * This function is called with no lock held. This function processes all
  2018. * the completed mailbox commands and gives it to upper layers. The interrupt
  2019. * service routine processes mailbox completion interrupt and adds completed
  2020. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  2021. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  2022. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  2023. * function returns the mailbox commands to the upper layer by calling the
  2024. * completion handler function of each mailbox.
  2025. **/
  2026. int
  2027. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2028. {
  2029. MAILBOX_t *pmbox;
  2030. LPFC_MBOXQ_t *pmb;
  2031. int rc;
  2032. LIST_HEAD(cmplq);
  2033. phba->sli.slistat.mbox_event++;
  2034. /* Get all completed mailboxe buffers into the cmplq */
  2035. spin_lock_irq(&phba->hbalock);
  2036. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2037. spin_unlock_irq(&phba->hbalock);
  2038. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2039. do {
  2040. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2041. if (pmb == NULL)
  2042. break;
  2043. pmbox = &pmb->u.mb;
  2044. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2045. if (pmb->vport) {
  2046. lpfc_debugfs_disc_trc(pmb->vport,
  2047. LPFC_DISC_TRC_MBOX_VPORT,
  2048. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2049. (uint32_t)pmbox->mbxCommand,
  2050. pmbox->un.varWords[0],
  2051. pmbox->un.varWords[1]);
  2052. }
  2053. else {
  2054. lpfc_debugfs_disc_trc(phba->pport,
  2055. LPFC_DISC_TRC_MBOX,
  2056. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2057. (uint32_t)pmbox->mbxCommand,
  2058. pmbox->un.varWords[0],
  2059. pmbox->un.varWords[1]);
  2060. }
  2061. }
  2062. /*
  2063. * It is a fatal error if unknown mbox command completion.
  2064. */
  2065. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2066. MBX_SHUTDOWN) {
  2067. /* Unknown mailbox command compl */
  2068. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2069. "(%d):0323 Unknown Mailbox command "
  2070. "x%x (x%x/x%x) Cmpl\n",
  2071. pmb->vport ? pmb->vport->vpi : 0,
  2072. pmbox->mbxCommand,
  2073. lpfc_sli_config_mbox_subsys_get(phba,
  2074. pmb),
  2075. lpfc_sli_config_mbox_opcode_get(phba,
  2076. pmb));
  2077. phba->link_state = LPFC_HBA_ERROR;
  2078. phba->work_hs = HS_FFER3;
  2079. lpfc_handle_eratt(phba);
  2080. continue;
  2081. }
  2082. if (pmbox->mbxStatus) {
  2083. phba->sli.slistat.mbox_stat_err++;
  2084. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2085. /* Mbox cmd cmpl error - RETRYing */
  2086. lpfc_printf_log(phba, KERN_INFO,
  2087. LOG_MBOX | LOG_SLI,
  2088. "(%d):0305 Mbox cmd cmpl "
  2089. "error - RETRYing Data: x%x "
  2090. "(x%x/x%x) x%x x%x x%x\n",
  2091. pmb->vport ? pmb->vport->vpi : 0,
  2092. pmbox->mbxCommand,
  2093. lpfc_sli_config_mbox_subsys_get(phba,
  2094. pmb),
  2095. lpfc_sli_config_mbox_opcode_get(phba,
  2096. pmb),
  2097. pmbox->mbxStatus,
  2098. pmbox->un.varWords[0],
  2099. pmb->vport->port_state);
  2100. pmbox->mbxStatus = 0;
  2101. pmbox->mbxOwner = OWN_HOST;
  2102. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2103. if (rc != MBX_NOT_FINISHED)
  2104. continue;
  2105. }
  2106. }
  2107. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2108. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2109. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
  2110. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2111. pmb->vport ? pmb->vport->vpi : 0,
  2112. pmbox->mbxCommand,
  2113. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2114. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2115. pmb->mbox_cmpl,
  2116. *((uint32_t *) pmbox),
  2117. pmbox->un.varWords[0],
  2118. pmbox->un.varWords[1],
  2119. pmbox->un.varWords[2],
  2120. pmbox->un.varWords[3],
  2121. pmbox->un.varWords[4],
  2122. pmbox->un.varWords[5],
  2123. pmbox->un.varWords[6],
  2124. pmbox->un.varWords[7]);
  2125. if (pmb->mbox_cmpl)
  2126. pmb->mbox_cmpl(phba,pmb);
  2127. } while (1);
  2128. return 0;
  2129. }
  2130. /**
  2131. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2132. * @phba: Pointer to HBA context object.
  2133. * @pring: Pointer to driver SLI ring object.
  2134. * @tag: buffer tag.
  2135. *
  2136. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2137. * is set in the tag the buffer is posted for a particular exchange,
  2138. * the function will return the buffer without replacing the buffer.
  2139. * If the buffer is for unsolicited ELS or CT traffic, this function
  2140. * returns the buffer and also posts another buffer to the firmware.
  2141. **/
  2142. static struct lpfc_dmabuf *
  2143. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2144. struct lpfc_sli_ring *pring,
  2145. uint32_t tag)
  2146. {
  2147. struct hbq_dmabuf *hbq_entry;
  2148. if (tag & QUE_BUFTAG_BIT)
  2149. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2150. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2151. if (!hbq_entry)
  2152. return NULL;
  2153. return &hbq_entry->dbuf;
  2154. }
  2155. /**
  2156. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2157. * @phba: Pointer to HBA context object.
  2158. * @pring: Pointer to driver SLI ring object.
  2159. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2160. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2161. * @fch_type: the type for the first frame of the sequence.
  2162. *
  2163. * This function is called with no lock held. This function uses the r_ctl and
  2164. * type of the received sequence to find the correct callback function to call
  2165. * to process the sequence.
  2166. **/
  2167. static int
  2168. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2169. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2170. uint32_t fch_type)
  2171. {
  2172. int i;
  2173. /* unSolicited Responses */
  2174. if (pring->prt[0].profile) {
  2175. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2176. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2177. saveq);
  2178. return 1;
  2179. }
  2180. /* We must search, based on rctl / type
  2181. for the right routine */
  2182. for (i = 0; i < pring->num_mask; i++) {
  2183. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2184. (pring->prt[i].type == fch_type)) {
  2185. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2186. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2187. (phba, pring, saveq);
  2188. return 1;
  2189. }
  2190. }
  2191. return 0;
  2192. }
  2193. /**
  2194. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2195. * @phba: Pointer to HBA context object.
  2196. * @pring: Pointer to driver SLI ring object.
  2197. * @saveq: Pointer to the unsolicited iocb.
  2198. *
  2199. * This function is called with no lock held by the ring event handler
  2200. * when there is an unsolicited iocb posted to the response ring by the
  2201. * firmware. This function gets the buffer associated with the iocbs
  2202. * and calls the event handler for the ring. This function handles both
  2203. * qring buffers and hbq buffers.
  2204. * When the function returns 1 the caller can free the iocb object otherwise
  2205. * upper layer functions will free the iocb objects.
  2206. **/
  2207. static int
  2208. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2209. struct lpfc_iocbq *saveq)
  2210. {
  2211. IOCB_t * irsp;
  2212. WORD5 * w5p;
  2213. uint32_t Rctl, Type;
  2214. uint32_t match;
  2215. struct lpfc_iocbq *iocbq;
  2216. struct lpfc_dmabuf *dmzbuf;
  2217. match = 0;
  2218. irsp = &(saveq->iocb);
  2219. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2220. if (pring->lpfc_sli_rcv_async_status)
  2221. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2222. else
  2223. lpfc_printf_log(phba,
  2224. KERN_WARNING,
  2225. LOG_SLI,
  2226. "0316 Ring %d handler: unexpected "
  2227. "ASYNC_STATUS iocb received evt_code "
  2228. "0x%x\n",
  2229. pring->ringno,
  2230. irsp->un.asyncstat.evt_code);
  2231. return 1;
  2232. }
  2233. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2234. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2235. if (irsp->ulpBdeCount > 0) {
  2236. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2237. irsp->un.ulpWord[3]);
  2238. lpfc_in_buf_free(phba, dmzbuf);
  2239. }
  2240. if (irsp->ulpBdeCount > 1) {
  2241. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2242. irsp->unsli3.sli3Words[3]);
  2243. lpfc_in_buf_free(phba, dmzbuf);
  2244. }
  2245. if (irsp->ulpBdeCount > 2) {
  2246. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2247. irsp->unsli3.sli3Words[7]);
  2248. lpfc_in_buf_free(phba, dmzbuf);
  2249. }
  2250. return 1;
  2251. }
  2252. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2253. if (irsp->ulpBdeCount != 0) {
  2254. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2255. irsp->un.ulpWord[3]);
  2256. if (!saveq->context2)
  2257. lpfc_printf_log(phba,
  2258. KERN_ERR,
  2259. LOG_SLI,
  2260. "0341 Ring %d Cannot find buffer for "
  2261. "an unsolicited iocb. tag 0x%x\n",
  2262. pring->ringno,
  2263. irsp->un.ulpWord[3]);
  2264. }
  2265. if (irsp->ulpBdeCount == 2) {
  2266. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2267. irsp->unsli3.sli3Words[7]);
  2268. if (!saveq->context3)
  2269. lpfc_printf_log(phba,
  2270. KERN_ERR,
  2271. LOG_SLI,
  2272. "0342 Ring %d Cannot find buffer for an"
  2273. " unsolicited iocb. tag 0x%x\n",
  2274. pring->ringno,
  2275. irsp->unsli3.sli3Words[7]);
  2276. }
  2277. list_for_each_entry(iocbq, &saveq->list, list) {
  2278. irsp = &(iocbq->iocb);
  2279. if (irsp->ulpBdeCount != 0) {
  2280. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2281. irsp->un.ulpWord[3]);
  2282. if (!iocbq->context2)
  2283. lpfc_printf_log(phba,
  2284. KERN_ERR,
  2285. LOG_SLI,
  2286. "0343 Ring %d Cannot find "
  2287. "buffer for an unsolicited iocb"
  2288. ". tag 0x%x\n", pring->ringno,
  2289. irsp->un.ulpWord[3]);
  2290. }
  2291. if (irsp->ulpBdeCount == 2) {
  2292. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2293. irsp->unsli3.sli3Words[7]);
  2294. if (!iocbq->context3)
  2295. lpfc_printf_log(phba,
  2296. KERN_ERR,
  2297. LOG_SLI,
  2298. "0344 Ring %d Cannot find "
  2299. "buffer for an unsolicited "
  2300. "iocb. tag 0x%x\n",
  2301. pring->ringno,
  2302. irsp->unsli3.sli3Words[7]);
  2303. }
  2304. }
  2305. }
  2306. if (irsp->ulpBdeCount != 0 &&
  2307. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2308. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2309. int found = 0;
  2310. /* search continue save q for same XRI */
  2311. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2312. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  2313. saveq->iocb.unsli3.rcvsli3.ox_id) {
  2314. list_add_tail(&saveq->list, &iocbq->list);
  2315. found = 1;
  2316. break;
  2317. }
  2318. }
  2319. if (!found)
  2320. list_add_tail(&saveq->clist,
  2321. &pring->iocb_continue_saveq);
  2322. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2323. list_del_init(&iocbq->clist);
  2324. saveq = iocbq;
  2325. irsp = &(saveq->iocb);
  2326. } else
  2327. return 0;
  2328. }
  2329. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2330. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2331. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2332. Rctl = FC_RCTL_ELS_REQ;
  2333. Type = FC_TYPE_ELS;
  2334. } else {
  2335. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2336. Rctl = w5p->hcsw.Rctl;
  2337. Type = w5p->hcsw.Type;
  2338. /* Firmware Workaround */
  2339. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2340. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2341. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2342. Rctl = FC_RCTL_ELS_REQ;
  2343. Type = FC_TYPE_ELS;
  2344. w5p->hcsw.Rctl = Rctl;
  2345. w5p->hcsw.Type = Type;
  2346. }
  2347. }
  2348. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2349. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2350. "0313 Ring %d handler: unexpected Rctl x%x "
  2351. "Type x%x received\n",
  2352. pring->ringno, Rctl, Type);
  2353. return 1;
  2354. }
  2355. /**
  2356. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2357. * @phba: Pointer to HBA context object.
  2358. * @pring: Pointer to driver SLI ring object.
  2359. * @prspiocb: Pointer to response iocb object.
  2360. *
  2361. * This function looks up the iocb_lookup table to get the command iocb
  2362. * corresponding to the given response iocb using the iotag of the
  2363. * response iocb. This function is called with the hbalock held.
  2364. * This function returns the command iocb object if it finds the command
  2365. * iocb else returns NULL.
  2366. **/
  2367. static struct lpfc_iocbq *
  2368. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2369. struct lpfc_sli_ring *pring,
  2370. struct lpfc_iocbq *prspiocb)
  2371. {
  2372. struct lpfc_iocbq *cmd_iocb = NULL;
  2373. uint16_t iotag;
  2374. iotag = prspiocb->iocb.ulpIoTag;
  2375. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2376. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2377. list_del_init(&cmd_iocb->list);
  2378. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2379. pring->txcmplq_cnt--;
  2380. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2381. }
  2382. return cmd_iocb;
  2383. }
  2384. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2385. "0317 iotag x%x is out off "
  2386. "range: max iotag x%x wd0 x%x\n",
  2387. iotag, phba->sli.last_iotag,
  2388. *(((uint32_t *) &prspiocb->iocb) + 7));
  2389. return NULL;
  2390. }
  2391. /**
  2392. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2393. * @phba: Pointer to HBA context object.
  2394. * @pring: Pointer to driver SLI ring object.
  2395. * @iotag: IOCB tag.
  2396. *
  2397. * This function looks up the iocb_lookup table to get the command iocb
  2398. * corresponding to the given iotag. This function is called with the
  2399. * hbalock held.
  2400. * This function returns the command iocb object if it finds the command
  2401. * iocb else returns NULL.
  2402. **/
  2403. static struct lpfc_iocbq *
  2404. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2405. struct lpfc_sli_ring *pring, uint16_t iotag)
  2406. {
  2407. struct lpfc_iocbq *cmd_iocb;
  2408. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2409. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2410. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2411. /* remove from txcmpl queue list */
  2412. list_del_init(&cmd_iocb->list);
  2413. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2414. pring->txcmplq_cnt--;
  2415. return cmd_iocb;
  2416. }
  2417. }
  2418. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2419. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2420. iotag, phba->sli.last_iotag);
  2421. return NULL;
  2422. }
  2423. /**
  2424. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2425. * @phba: Pointer to HBA context object.
  2426. * @pring: Pointer to driver SLI ring object.
  2427. * @saveq: Pointer to the response iocb to be processed.
  2428. *
  2429. * This function is called by the ring event handler for non-fcp
  2430. * rings when there is a new response iocb in the response ring.
  2431. * The caller is not required to hold any locks. This function
  2432. * gets the command iocb associated with the response iocb and
  2433. * calls the completion handler for the command iocb. If there
  2434. * is no completion handler, the function will free the resources
  2435. * associated with command iocb. If the response iocb is for
  2436. * an already aborted command iocb, the status of the completion
  2437. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2438. * This function always returns 1.
  2439. **/
  2440. static int
  2441. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2442. struct lpfc_iocbq *saveq)
  2443. {
  2444. struct lpfc_iocbq *cmdiocbp;
  2445. int rc = 1;
  2446. unsigned long iflag;
  2447. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2448. spin_lock_irqsave(&phba->hbalock, iflag);
  2449. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2450. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2451. if (cmdiocbp) {
  2452. if (cmdiocbp->iocb_cmpl) {
  2453. /*
  2454. * If an ELS command failed send an event to mgmt
  2455. * application.
  2456. */
  2457. if (saveq->iocb.ulpStatus &&
  2458. (pring->ringno == LPFC_ELS_RING) &&
  2459. (cmdiocbp->iocb.ulpCommand ==
  2460. CMD_ELS_REQUEST64_CR))
  2461. lpfc_send_els_failure_event(phba,
  2462. cmdiocbp, saveq);
  2463. /*
  2464. * Post all ELS completions to the worker thread.
  2465. * All other are passed to the completion callback.
  2466. */
  2467. if (pring->ringno == LPFC_ELS_RING) {
  2468. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2469. (cmdiocbp->iocb_flag &
  2470. LPFC_DRIVER_ABORTED)) {
  2471. spin_lock_irqsave(&phba->hbalock,
  2472. iflag);
  2473. cmdiocbp->iocb_flag &=
  2474. ~LPFC_DRIVER_ABORTED;
  2475. spin_unlock_irqrestore(&phba->hbalock,
  2476. iflag);
  2477. saveq->iocb.ulpStatus =
  2478. IOSTAT_LOCAL_REJECT;
  2479. saveq->iocb.un.ulpWord[4] =
  2480. IOERR_SLI_ABORTED;
  2481. /* Firmware could still be in progress
  2482. * of DMAing payload, so don't free data
  2483. * buffer till after a hbeat.
  2484. */
  2485. spin_lock_irqsave(&phba->hbalock,
  2486. iflag);
  2487. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2488. spin_unlock_irqrestore(&phba->hbalock,
  2489. iflag);
  2490. }
  2491. if (phba->sli_rev == LPFC_SLI_REV4) {
  2492. if (saveq->iocb_flag &
  2493. LPFC_EXCHANGE_BUSY) {
  2494. /* Set cmdiocb flag for the
  2495. * exchange busy so sgl (xri)
  2496. * will not be released until
  2497. * the abort xri is received
  2498. * from hba.
  2499. */
  2500. spin_lock_irqsave(
  2501. &phba->hbalock, iflag);
  2502. cmdiocbp->iocb_flag |=
  2503. LPFC_EXCHANGE_BUSY;
  2504. spin_unlock_irqrestore(
  2505. &phba->hbalock, iflag);
  2506. }
  2507. if (cmdiocbp->iocb_flag &
  2508. LPFC_DRIVER_ABORTED) {
  2509. /*
  2510. * Clear LPFC_DRIVER_ABORTED
  2511. * bit in case it was driver
  2512. * initiated abort.
  2513. */
  2514. spin_lock_irqsave(
  2515. &phba->hbalock, iflag);
  2516. cmdiocbp->iocb_flag &=
  2517. ~LPFC_DRIVER_ABORTED;
  2518. spin_unlock_irqrestore(
  2519. &phba->hbalock, iflag);
  2520. cmdiocbp->iocb.ulpStatus =
  2521. IOSTAT_LOCAL_REJECT;
  2522. cmdiocbp->iocb.un.ulpWord[4] =
  2523. IOERR_ABORT_REQUESTED;
  2524. /*
  2525. * For SLI4, irsiocb contains
  2526. * NO_XRI in sli_xritag, it
  2527. * shall not affect releasing
  2528. * sgl (xri) process.
  2529. */
  2530. saveq->iocb.ulpStatus =
  2531. IOSTAT_LOCAL_REJECT;
  2532. saveq->iocb.un.ulpWord[4] =
  2533. IOERR_SLI_ABORTED;
  2534. spin_lock_irqsave(
  2535. &phba->hbalock, iflag);
  2536. saveq->iocb_flag |=
  2537. LPFC_DELAY_MEM_FREE;
  2538. spin_unlock_irqrestore(
  2539. &phba->hbalock, iflag);
  2540. }
  2541. }
  2542. }
  2543. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2544. } else
  2545. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2546. } else {
  2547. /*
  2548. * Unknown initiating command based on the response iotag.
  2549. * This could be the case on the ELS ring because of
  2550. * lpfc_els_abort().
  2551. */
  2552. if (pring->ringno != LPFC_ELS_RING) {
  2553. /*
  2554. * Ring <ringno> handler: unexpected completion IoTag
  2555. * <IoTag>
  2556. */
  2557. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2558. "0322 Ring %d handler: "
  2559. "unexpected completion IoTag x%x "
  2560. "Data: x%x x%x x%x x%x\n",
  2561. pring->ringno,
  2562. saveq->iocb.ulpIoTag,
  2563. saveq->iocb.ulpStatus,
  2564. saveq->iocb.un.ulpWord[4],
  2565. saveq->iocb.ulpCommand,
  2566. saveq->iocb.ulpContext);
  2567. }
  2568. }
  2569. return rc;
  2570. }
  2571. /**
  2572. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2573. * @phba: Pointer to HBA context object.
  2574. * @pring: Pointer to driver SLI ring object.
  2575. *
  2576. * This function is called from the iocb ring event handlers when
  2577. * put pointer is ahead of the get pointer for a ring. This function signal
  2578. * an error attention condition to the worker thread and the worker
  2579. * thread will transition the HBA to offline state.
  2580. **/
  2581. static void
  2582. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2583. {
  2584. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2585. /*
  2586. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2587. * rsp ring <portRspMax>
  2588. */
  2589. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2590. "0312 Ring %d handler: portRspPut %d "
  2591. "is bigger than rsp ring %d\n",
  2592. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2593. pring->sli.sli3.numRiocb);
  2594. phba->link_state = LPFC_HBA_ERROR;
  2595. /*
  2596. * All error attention handlers are posted to
  2597. * worker thread
  2598. */
  2599. phba->work_ha |= HA_ERATT;
  2600. phba->work_hs = HS_FFER3;
  2601. lpfc_worker_wake_up(phba);
  2602. return;
  2603. }
  2604. /**
  2605. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2606. * @ptr: Pointer to address of HBA context object.
  2607. *
  2608. * This function is invoked by the Error Attention polling timer when the
  2609. * timer times out. It will check the SLI Error Attention register for
  2610. * possible attention events. If so, it will post an Error Attention event
  2611. * and wake up worker thread to process it. Otherwise, it will set up the
  2612. * Error Attention polling timer for the next poll.
  2613. **/
  2614. void lpfc_poll_eratt(unsigned long ptr)
  2615. {
  2616. struct lpfc_hba *phba;
  2617. uint32_t eratt = 0, rem;
  2618. uint64_t sli_intr, cnt;
  2619. phba = (struct lpfc_hba *)ptr;
  2620. /* Here we will also keep track of interrupts per sec of the hba */
  2621. sli_intr = phba->sli.slistat.sli_intr;
  2622. if (phba->sli.slistat.sli_prev_intr > sli_intr)
  2623. cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
  2624. sli_intr);
  2625. else
  2626. cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
  2627. /* 64-bit integer division not supporte on 32-bit x86 - use do_div */
  2628. rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL);
  2629. phba->sli.slistat.sli_ips = cnt;
  2630. phba->sli.slistat.sli_prev_intr = sli_intr;
  2631. /* Check chip HA register for error event */
  2632. eratt = lpfc_sli_check_eratt(phba);
  2633. if (eratt)
  2634. /* Tell the worker thread there is work to do */
  2635. lpfc_worker_wake_up(phba);
  2636. else
  2637. /* Restart the timer for next eratt poll */
  2638. mod_timer(&phba->eratt_poll, jiffies +
  2639. HZ * LPFC_ERATT_POLL_INTERVAL);
  2640. return;
  2641. }
  2642. /**
  2643. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2644. * @phba: Pointer to HBA context object.
  2645. * @pring: Pointer to driver SLI ring object.
  2646. * @mask: Host attention register mask for this ring.
  2647. *
  2648. * This function is called from the interrupt context when there is a ring
  2649. * event for the fcp ring. The caller does not hold any lock.
  2650. * The function processes each response iocb in the response ring until it
  2651. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2652. * LE bit set. The function will call the completion handler of the command iocb
  2653. * if the response iocb indicates a completion for a command iocb or it is
  2654. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2655. * function if this is an unsolicited iocb.
  2656. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2657. * to check it explicitly.
  2658. */
  2659. int
  2660. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2661. struct lpfc_sli_ring *pring, uint32_t mask)
  2662. {
  2663. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2664. IOCB_t *irsp = NULL;
  2665. IOCB_t *entry = NULL;
  2666. struct lpfc_iocbq *cmdiocbq = NULL;
  2667. struct lpfc_iocbq rspiocbq;
  2668. uint32_t status;
  2669. uint32_t portRspPut, portRspMax;
  2670. int rc = 1;
  2671. lpfc_iocb_type type;
  2672. unsigned long iflag;
  2673. uint32_t rsp_cmpl = 0;
  2674. spin_lock_irqsave(&phba->hbalock, iflag);
  2675. pring->stats.iocb_event++;
  2676. /*
  2677. * The next available response entry should never exceed the maximum
  2678. * entries. If it does, treat it as an adapter hardware error.
  2679. */
  2680. portRspMax = pring->sli.sli3.numRiocb;
  2681. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2682. if (unlikely(portRspPut >= portRspMax)) {
  2683. lpfc_sli_rsp_pointers_error(phba, pring);
  2684. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2685. return 1;
  2686. }
  2687. if (phba->fcp_ring_in_use) {
  2688. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2689. return 1;
  2690. } else
  2691. phba->fcp_ring_in_use = 1;
  2692. rmb();
  2693. while (pring->sli.sli3.rspidx != portRspPut) {
  2694. /*
  2695. * Fetch an entry off the ring and copy it into a local data
  2696. * structure. The copy involves a byte-swap since the
  2697. * network byte order and pci byte orders are different.
  2698. */
  2699. entry = lpfc_resp_iocb(phba, pring);
  2700. phba->last_completion_time = jiffies;
  2701. if (++pring->sli.sli3.rspidx >= portRspMax)
  2702. pring->sli.sli3.rspidx = 0;
  2703. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2704. (uint32_t *) &rspiocbq.iocb,
  2705. phba->iocb_rsp_size);
  2706. INIT_LIST_HEAD(&(rspiocbq.list));
  2707. irsp = &rspiocbq.iocb;
  2708. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2709. pring->stats.iocb_rsp++;
  2710. rsp_cmpl++;
  2711. if (unlikely(irsp->ulpStatus)) {
  2712. /*
  2713. * If resource errors reported from HBA, reduce
  2714. * queuedepths of the SCSI device.
  2715. */
  2716. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2717. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2718. IOERR_NO_RESOURCES)) {
  2719. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2720. phba->lpfc_rampdown_queue_depth(phba);
  2721. spin_lock_irqsave(&phba->hbalock, iflag);
  2722. }
  2723. /* Rsp ring <ringno> error: IOCB */
  2724. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2725. "0336 Rsp Ring %d error: IOCB Data: "
  2726. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2727. pring->ringno,
  2728. irsp->un.ulpWord[0],
  2729. irsp->un.ulpWord[1],
  2730. irsp->un.ulpWord[2],
  2731. irsp->un.ulpWord[3],
  2732. irsp->un.ulpWord[4],
  2733. irsp->un.ulpWord[5],
  2734. *(uint32_t *)&irsp->un1,
  2735. *((uint32_t *)&irsp->un1 + 1));
  2736. }
  2737. switch (type) {
  2738. case LPFC_ABORT_IOCB:
  2739. case LPFC_SOL_IOCB:
  2740. /*
  2741. * Idle exchange closed via ABTS from port. No iocb
  2742. * resources need to be recovered.
  2743. */
  2744. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2745. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2746. "0333 IOCB cmd 0x%x"
  2747. " processed. Skipping"
  2748. " completion\n",
  2749. irsp->ulpCommand);
  2750. break;
  2751. }
  2752. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2753. &rspiocbq);
  2754. if (unlikely(!cmdiocbq))
  2755. break;
  2756. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2757. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2758. if (cmdiocbq->iocb_cmpl) {
  2759. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2760. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2761. &rspiocbq);
  2762. spin_lock_irqsave(&phba->hbalock, iflag);
  2763. }
  2764. break;
  2765. case LPFC_UNSOL_IOCB:
  2766. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2767. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2768. spin_lock_irqsave(&phba->hbalock, iflag);
  2769. break;
  2770. default:
  2771. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2772. char adaptermsg[LPFC_MAX_ADPTMSG];
  2773. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2774. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2775. MAX_MSG_DATA);
  2776. dev_warn(&((phba->pcidev)->dev),
  2777. "lpfc%d: %s\n",
  2778. phba->brd_no, adaptermsg);
  2779. } else {
  2780. /* Unknown IOCB command */
  2781. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2782. "0334 Unknown IOCB command "
  2783. "Data: x%x, x%x x%x x%x x%x\n",
  2784. type, irsp->ulpCommand,
  2785. irsp->ulpStatus,
  2786. irsp->ulpIoTag,
  2787. irsp->ulpContext);
  2788. }
  2789. break;
  2790. }
  2791. /*
  2792. * The response IOCB has been processed. Update the ring
  2793. * pointer in SLIM. If the port response put pointer has not
  2794. * been updated, sync the pgp->rspPutInx and fetch the new port
  2795. * response put pointer.
  2796. */
  2797. writel(pring->sli.sli3.rspidx,
  2798. &phba->host_gp[pring->ringno].rspGetInx);
  2799. if (pring->sli.sli3.rspidx == portRspPut)
  2800. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2801. }
  2802. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2803. pring->stats.iocb_rsp_full++;
  2804. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2805. writel(status, phba->CAregaddr);
  2806. readl(phba->CAregaddr);
  2807. }
  2808. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2809. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2810. pring->stats.iocb_cmd_empty++;
  2811. /* Force update of the local copy of cmdGetInx */
  2812. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2813. lpfc_sli_resume_iocb(phba, pring);
  2814. if ((pring->lpfc_sli_cmd_available))
  2815. (pring->lpfc_sli_cmd_available) (phba, pring);
  2816. }
  2817. phba->fcp_ring_in_use = 0;
  2818. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2819. return rc;
  2820. }
  2821. /**
  2822. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2823. * @phba: Pointer to HBA context object.
  2824. * @pring: Pointer to driver SLI ring object.
  2825. * @rspiocbp: Pointer to driver response IOCB object.
  2826. *
  2827. * This function is called from the worker thread when there is a slow-path
  2828. * response IOCB to process. This function chains all the response iocbs until
  2829. * seeing the iocb with the LE bit set. The function will call
  2830. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2831. * completion of a command iocb. The function will call the
  2832. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2833. * The function frees the resources or calls the completion handler if this
  2834. * iocb is an abort completion. The function returns NULL when the response
  2835. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2836. * this function shall chain the iocb on to the iocb_continueq and return the
  2837. * response iocb passed in.
  2838. **/
  2839. static struct lpfc_iocbq *
  2840. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2841. struct lpfc_iocbq *rspiocbp)
  2842. {
  2843. struct lpfc_iocbq *saveq;
  2844. struct lpfc_iocbq *cmdiocbp;
  2845. struct lpfc_iocbq *next_iocb;
  2846. IOCB_t *irsp = NULL;
  2847. uint32_t free_saveq;
  2848. uint8_t iocb_cmd_type;
  2849. lpfc_iocb_type type;
  2850. unsigned long iflag;
  2851. int rc;
  2852. spin_lock_irqsave(&phba->hbalock, iflag);
  2853. /* First add the response iocb to the countinueq list */
  2854. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2855. pring->iocb_continueq_cnt++;
  2856. /* Now, determine whether the list is completed for processing */
  2857. irsp = &rspiocbp->iocb;
  2858. if (irsp->ulpLe) {
  2859. /*
  2860. * By default, the driver expects to free all resources
  2861. * associated with this iocb completion.
  2862. */
  2863. free_saveq = 1;
  2864. saveq = list_get_first(&pring->iocb_continueq,
  2865. struct lpfc_iocbq, list);
  2866. irsp = &(saveq->iocb);
  2867. list_del_init(&pring->iocb_continueq);
  2868. pring->iocb_continueq_cnt = 0;
  2869. pring->stats.iocb_rsp++;
  2870. /*
  2871. * If resource errors reported from HBA, reduce
  2872. * queuedepths of the SCSI device.
  2873. */
  2874. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2875. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2876. IOERR_NO_RESOURCES)) {
  2877. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2878. phba->lpfc_rampdown_queue_depth(phba);
  2879. spin_lock_irqsave(&phba->hbalock, iflag);
  2880. }
  2881. if (irsp->ulpStatus) {
  2882. /* Rsp ring <ringno> error: IOCB */
  2883. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2884. "0328 Rsp Ring %d error: "
  2885. "IOCB Data: "
  2886. "x%x x%x x%x x%x "
  2887. "x%x x%x x%x x%x "
  2888. "x%x x%x x%x x%x "
  2889. "x%x x%x x%x x%x\n",
  2890. pring->ringno,
  2891. irsp->un.ulpWord[0],
  2892. irsp->un.ulpWord[1],
  2893. irsp->un.ulpWord[2],
  2894. irsp->un.ulpWord[3],
  2895. irsp->un.ulpWord[4],
  2896. irsp->un.ulpWord[5],
  2897. *(((uint32_t *) irsp) + 6),
  2898. *(((uint32_t *) irsp) + 7),
  2899. *(((uint32_t *) irsp) + 8),
  2900. *(((uint32_t *) irsp) + 9),
  2901. *(((uint32_t *) irsp) + 10),
  2902. *(((uint32_t *) irsp) + 11),
  2903. *(((uint32_t *) irsp) + 12),
  2904. *(((uint32_t *) irsp) + 13),
  2905. *(((uint32_t *) irsp) + 14),
  2906. *(((uint32_t *) irsp) + 15));
  2907. }
  2908. /*
  2909. * Fetch the IOCB command type and call the correct completion
  2910. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2911. * get freed back to the lpfc_iocb_list by the discovery
  2912. * kernel thread.
  2913. */
  2914. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2915. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2916. switch (type) {
  2917. case LPFC_SOL_IOCB:
  2918. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2919. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2920. spin_lock_irqsave(&phba->hbalock, iflag);
  2921. break;
  2922. case LPFC_UNSOL_IOCB:
  2923. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2924. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2925. spin_lock_irqsave(&phba->hbalock, iflag);
  2926. if (!rc)
  2927. free_saveq = 0;
  2928. break;
  2929. case LPFC_ABORT_IOCB:
  2930. cmdiocbp = NULL;
  2931. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2932. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2933. saveq);
  2934. if (cmdiocbp) {
  2935. /* Call the specified completion routine */
  2936. if (cmdiocbp->iocb_cmpl) {
  2937. spin_unlock_irqrestore(&phba->hbalock,
  2938. iflag);
  2939. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2940. saveq);
  2941. spin_lock_irqsave(&phba->hbalock,
  2942. iflag);
  2943. } else
  2944. __lpfc_sli_release_iocbq(phba,
  2945. cmdiocbp);
  2946. }
  2947. break;
  2948. case LPFC_UNKNOWN_IOCB:
  2949. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2950. char adaptermsg[LPFC_MAX_ADPTMSG];
  2951. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2952. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2953. MAX_MSG_DATA);
  2954. dev_warn(&((phba->pcidev)->dev),
  2955. "lpfc%d: %s\n",
  2956. phba->brd_no, adaptermsg);
  2957. } else {
  2958. /* Unknown IOCB command */
  2959. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2960. "0335 Unknown IOCB "
  2961. "command Data: x%x "
  2962. "x%x x%x x%x\n",
  2963. irsp->ulpCommand,
  2964. irsp->ulpStatus,
  2965. irsp->ulpIoTag,
  2966. irsp->ulpContext);
  2967. }
  2968. break;
  2969. }
  2970. if (free_saveq) {
  2971. list_for_each_entry_safe(rspiocbp, next_iocb,
  2972. &saveq->list, list) {
  2973. list_del(&rspiocbp->list);
  2974. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2975. }
  2976. __lpfc_sli_release_iocbq(phba, saveq);
  2977. }
  2978. rspiocbp = NULL;
  2979. }
  2980. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2981. return rspiocbp;
  2982. }
  2983. /**
  2984. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2985. * @phba: Pointer to HBA context object.
  2986. * @pring: Pointer to driver SLI ring object.
  2987. * @mask: Host attention register mask for this ring.
  2988. *
  2989. * This routine wraps the actual slow_ring event process routine from the
  2990. * API jump table function pointer from the lpfc_hba struct.
  2991. **/
  2992. void
  2993. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2994. struct lpfc_sli_ring *pring, uint32_t mask)
  2995. {
  2996. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2997. }
  2998. /**
  2999. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  3000. * @phba: Pointer to HBA context object.
  3001. * @pring: Pointer to driver SLI ring object.
  3002. * @mask: Host attention register mask for this ring.
  3003. *
  3004. * This function is called from the worker thread when there is a ring event
  3005. * for non-fcp rings. The caller does not hold any lock. The function will
  3006. * remove each response iocb in the response ring and calls the handle
  3007. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3008. **/
  3009. static void
  3010. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  3011. struct lpfc_sli_ring *pring, uint32_t mask)
  3012. {
  3013. struct lpfc_pgp *pgp;
  3014. IOCB_t *entry;
  3015. IOCB_t *irsp = NULL;
  3016. struct lpfc_iocbq *rspiocbp = NULL;
  3017. uint32_t portRspPut, portRspMax;
  3018. unsigned long iflag;
  3019. uint32_t status;
  3020. pgp = &phba->port_gp[pring->ringno];
  3021. spin_lock_irqsave(&phba->hbalock, iflag);
  3022. pring->stats.iocb_event++;
  3023. /*
  3024. * The next available response entry should never exceed the maximum
  3025. * entries. If it does, treat it as an adapter hardware error.
  3026. */
  3027. portRspMax = pring->sli.sli3.numRiocb;
  3028. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3029. if (portRspPut >= portRspMax) {
  3030. /*
  3031. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  3032. * rsp ring <portRspMax>
  3033. */
  3034. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3035. "0303 Ring %d handler: portRspPut %d "
  3036. "is bigger than rsp ring %d\n",
  3037. pring->ringno, portRspPut, portRspMax);
  3038. phba->link_state = LPFC_HBA_ERROR;
  3039. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3040. phba->work_hs = HS_FFER3;
  3041. lpfc_handle_eratt(phba);
  3042. return;
  3043. }
  3044. rmb();
  3045. while (pring->sli.sli3.rspidx != portRspPut) {
  3046. /*
  3047. * Build a completion list and call the appropriate handler.
  3048. * The process is to get the next available response iocb, get
  3049. * a free iocb from the list, copy the response data into the
  3050. * free iocb, insert to the continuation list, and update the
  3051. * next response index to slim. This process makes response
  3052. * iocb's in the ring available to DMA as fast as possible but
  3053. * pays a penalty for a copy operation. Since the iocb is
  3054. * only 32 bytes, this penalty is considered small relative to
  3055. * the PCI reads for register values and a slim write. When
  3056. * the ulpLe field is set, the entire Command has been
  3057. * received.
  3058. */
  3059. entry = lpfc_resp_iocb(phba, pring);
  3060. phba->last_completion_time = jiffies;
  3061. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3062. if (rspiocbp == NULL) {
  3063. printk(KERN_ERR "%s: out of buffers! Failing "
  3064. "completion.\n", __func__);
  3065. break;
  3066. }
  3067. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3068. phba->iocb_rsp_size);
  3069. irsp = &rspiocbp->iocb;
  3070. if (++pring->sli.sli3.rspidx >= portRspMax)
  3071. pring->sli.sli3.rspidx = 0;
  3072. if (pring->ringno == LPFC_ELS_RING) {
  3073. lpfc_debugfs_slow_ring_trc(phba,
  3074. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3075. *(((uint32_t *) irsp) + 4),
  3076. *(((uint32_t *) irsp) + 6),
  3077. *(((uint32_t *) irsp) + 7));
  3078. }
  3079. writel(pring->sli.sli3.rspidx,
  3080. &phba->host_gp[pring->ringno].rspGetInx);
  3081. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3082. /* Handle the response IOCB */
  3083. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3084. spin_lock_irqsave(&phba->hbalock, iflag);
  3085. /*
  3086. * If the port response put pointer has not been updated, sync
  3087. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3088. * response put pointer.
  3089. */
  3090. if (pring->sli.sli3.rspidx == portRspPut) {
  3091. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3092. }
  3093. } /* while (pring->sli.sli3.rspidx != portRspPut) */
  3094. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3095. /* At least one response entry has been freed */
  3096. pring->stats.iocb_rsp_full++;
  3097. /* SET RxRE_RSP in Chip Att register */
  3098. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3099. writel(status, phba->CAregaddr);
  3100. readl(phba->CAregaddr); /* flush */
  3101. }
  3102. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3103. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3104. pring->stats.iocb_cmd_empty++;
  3105. /* Force update of the local copy of cmdGetInx */
  3106. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3107. lpfc_sli_resume_iocb(phba, pring);
  3108. if ((pring->lpfc_sli_cmd_available))
  3109. (pring->lpfc_sli_cmd_available) (phba, pring);
  3110. }
  3111. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3112. return;
  3113. }
  3114. /**
  3115. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3116. * @phba: Pointer to HBA context object.
  3117. * @pring: Pointer to driver SLI ring object.
  3118. * @mask: Host attention register mask for this ring.
  3119. *
  3120. * This function is called from the worker thread when there is a pending
  3121. * ELS response iocb on the driver internal slow-path response iocb worker
  3122. * queue. The caller does not hold any lock. The function will remove each
  3123. * response iocb from the response worker queue and calls the handle
  3124. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3125. **/
  3126. static void
  3127. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3128. struct lpfc_sli_ring *pring, uint32_t mask)
  3129. {
  3130. struct lpfc_iocbq *irspiocbq;
  3131. struct hbq_dmabuf *dmabuf;
  3132. struct lpfc_cq_event *cq_event;
  3133. unsigned long iflag;
  3134. spin_lock_irqsave(&phba->hbalock, iflag);
  3135. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3136. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3137. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3138. /* Get the response iocb from the head of work queue */
  3139. spin_lock_irqsave(&phba->hbalock, iflag);
  3140. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3141. cq_event, struct lpfc_cq_event, list);
  3142. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3143. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3144. case CQE_CODE_COMPL_WQE:
  3145. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3146. cq_event);
  3147. /* Translate ELS WCQE to response IOCBQ */
  3148. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3149. irspiocbq);
  3150. if (irspiocbq)
  3151. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3152. irspiocbq);
  3153. break;
  3154. case CQE_CODE_RECEIVE:
  3155. case CQE_CODE_RECEIVE_V1:
  3156. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3157. cq_event);
  3158. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3159. break;
  3160. default:
  3161. break;
  3162. }
  3163. }
  3164. }
  3165. /**
  3166. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3167. * @phba: Pointer to HBA context object.
  3168. * @pring: Pointer to driver SLI ring object.
  3169. *
  3170. * This function aborts all iocbs in the given ring and frees all the iocb
  3171. * objects in txq. This function issues an abort iocb for all the iocb commands
  3172. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3173. * the return of this function. The caller is not required to hold any locks.
  3174. **/
  3175. void
  3176. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3177. {
  3178. LIST_HEAD(completions);
  3179. struct lpfc_iocbq *iocb, *next_iocb;
  3180. if (pring->ringno == LPFC_ELS_RING) {
  3181. lpfc_fabric_abort_hba(phba);
  3182. }
  3183. /* Error everything on txq and txcmplq
  3184. * First do the txq.
  3185. */
  3186. spin_lock_irq(&phba->hbalock);
  3187. list_splice_init(&pring->txq, &completions);
  3188. pring->txq_cnt = 0;
  3189. /* Next issue ABTS for everything on the txcmplq */
  3190. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3191. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3192. spin_unlock_irq(&phba->hbalock);
  3193. /* Cancel all the IOCBs from the completions list */
  3194. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3195. IOERR_SLI_ABORTED);
  3196. }
  3197. /**
  3198. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3199. * @phba: Pointer to HBA context object.
  3200. *
  3201. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3202. * objects in txq and txcmplq. This function will not issue abort iocbs
  3203. * for all the iocb commands in txcmplq, they will just be returned with
  3204. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3205. * slot has been permanently disabled.
  3206. **/
  3207. void
  3208. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3209. {
  3210. LIST_HEAD(txq);
  3211. LIST_HEAD(txcmplq);
  3212. struct lpfc_sli *psli = &phba->sli;
  3213. struct lpfc_sli_ring *pring;
  3214. /* Currently, only one fcp ring */
  3215. pring = &psli->ring[psli->fcp_ring];
  3216. spin_lock_irq(&phba->hbalock);
  3217. /* Retrieve everything on txq */
  3218. list_splice_init(&pring->txq, &txq);
  3219. pring->txq_cnt = 0;
  3220. /* Retrieve everything on the txcmplq */
  3221. list_splice_init(&pring->txcmplq, &txcmplq);
  3222. pring->txcmplq_cnt = 0;
  3223. /* Indicate the I/O queues are flushed */
  3224. phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
  3225. spin_unlock_irq(&phba->hbalock);
  3226. /* Flush the txq */
  3227. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3228. IOERR_SLI_DOWN);
  3229. /* Flush the txcmpq */
  3230. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3231. IOERR_SLI_DOWN);
  3232. }
  3233. /**
  3234. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3235. * @phba: Pointer to HBA context object.
  3236. * @mask: Bit mask to be checked.
  3237. *
  3238. * This function reads the host status register and compares
  3239. * with the provided bit mask to check if HBA completed
  3240. * the restart. This function will wait in a loop for the
  3241. * HBA to complete restart. If the HBA does not restart within
  3242. * 15 iterations, the function will reset the HBA again. The
  3243. * function returns 1 when HBA fail to restart otherwise returns
  3244. * zero.
  3245. **/
  3246. static int
  3247. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3248. {
  3249. uint32_t status;
  3250. int i = 0;
  3251. int retval = 0;
  3252. /* Read the HBA Host Status Register */
  3253. if (lpfc_readl(phba->HSregaddr, &status))
  3254. return 1;
  3255. /*
  3256. * Check status register every 100ms for 5 retries, then every
  3257. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3258. * every 2.5 sec for 4.
  3259. * Break our of the loop if errors occurred during init.
  3260. */
  3261. while (((status & mask) != mask) &&
  3262. !(status & HS_FFERM) &&
  3263. i++ < 20) {
  3264. if (i <= 5)
  3265. msleep(10);
  3266. else if (i <= 10)
  3267. msleep(500);
  3268. else
  3269. msleep(2500);
  3270. if (i == 15) {
  3271. /* Do post */
  3272. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3273. lpfc_sli_brdrestart(phba);
  3274. }
  3275. /* Read the HBA Host Status Register */
  3276. if (lpfc_readl(phba->HSregaddr, &status)) {
  3277. retval = 1;
  3278. break;
  3279. }
  3280. }
  3281. /* Check to see if any errors occurred during init */
  3282. if ((status & HS_FFERM) || (i >= 20)) {
  3283. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3284. "2751 Adapter failed to restart, "
  3285. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3286. status,
  3287. readl(phba->MBslimaddr + 0xa8),
  3288. readl(phba->MBslimaddr + 0xac));
  3289. phba->link_state = LPFC_HBA_ERROR;
  3290. retval = 1;
  3291. }
  3292. return retval;
  3293. }
  3294. /**
  3295. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3296. * @phba: Pointer to HBA context object.
  3297. * @mask: Bit mask to be checked.
  3298. *
  3299. * This function checks the host status register to check if HBA is
  3300. * ready. This function will wait in a loop for the HBA to be ready
  3301. * If the HBA is not ready , the function will will reset the HBA PCI
  3302. * function again. The function returns 1 when HBA fail to be ready
  3303. * otherwise returns zero.
  3304. **/
  3305. static int
  3306. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3307. {
  3308. uint32_t status;
  3309. int retval = 0;
  3310. /* Read the HBA Host Status Register */
  3311. status = lpfc_sli4_post_status_check(phba);
  3312. if (status) {
  3313. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3314. lpfc_sli_brdrestart(phba);
  3315. status = lpfc_sli4_post_status_check(phba);
  3316. }
  3317. /* Check to see if any errors occurred during init */
  3318. if (status) {
  3319. phba->link_state = LPFC_HBA_ERROR;
  3320. retval = 1;
  3321. } else
  3322. phba->sli4_hba.intr_enable = 0;
  3323. return retval;
  3324. }
  3325. /**
  3326. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3327. * @phba: Pointer to HBA context object.
  3328. * @mask: Bit mask to be checked.
  3329. *
  3330. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3331. * from the API jump table function pointer from the lpfc_hba struct.
  3332. **/
  3333. int
  3334. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3335. {
  3336. return phba->lpfc_sli_brdready(phba, mask);
  3337. }
  3338. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3339. /**
  3340. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3341. * @phba: Pointer to HBA context object.
  3342. *
  3343. * This function is called before resetting an HBA. This function is called
  3344. * with hbalock held and requests HBA to quiesce DMAs before a reset.
  3345. **/
  3346. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3347. {
  3348. uint32_t __iomem *resp_buf;
  3349. uint32_t __iomem *mbox_buf;
  3350. volatile uint32_t mbox;
  3351. uint32_t hc_copy, ha_copy, resp_data;
  3352. int i;
  3353. uint8_t hdrtype;
  3354. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3355. if (hdrtype != 0x80 ||
  3356. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3357. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3358. return;
  3359. /*
  3360. * Tell the other part of the chip to suspend temporarily all
  3361. * its DMA activity.
  3362. */
  3363. resp_buf = phba->MBslimaddr;
  3364. /* Disable the error attention */
  3365. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3366. return;
  3367. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3368. readl(phba->HCregaddr); /* flush */
  3369. phba->link_flag |= LS_IGNORE_ERATT;
  3370. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3371. return;
  3372. if (ha_copy & HA_ERATT) {
  3373. /* Clear Chip error bit */
  3374. writel(HA_ERATT, phba->HAregaddr);
  3375. phba->pport->stopped = 1;
  3376. }
  3377. mbox = 0;
  3378. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3379. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3380. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3381. mbox_buf = phba->MBslimaddr;
  3382. writel(mbox, mbox_buf);
  3383. for (i = 0; i < 50; i++) {
  3384. if (lpfc_readl((resp_buf + 1), &resp_data))
  3385. return;
  3386. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3387. mdelay(1);
  3388. else
  3389. break;
  3390. }
  3391. resp_data = 0;
  3392. if (lpfc_readl((resp_buf + 1), &resp_data))
  3393. return;
  3394. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3395. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3396. phba->pport->stopped)
  3397. goto restore_hc;
  3398. else
  3399. goto clear_errat;
  3400. }
  3401. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3402. resp_data = 0;
  3403. for (i = 0; i < 500; i++) {
  3404. if (lpfc_readl(resp_buf, &resp_data))
  3405. return;
  3406. if (resp_data != mbox)
  3407. mdelay(1);
  3408. else
  3409. break;
  3410. }
  3411. clear_errat:
  3412. while (++i < 500) {
  3413. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3414. return;
  3415. if (!(ha_copy & HA_ERATT))
  3416. mdelay(1);
  3417. else
  3418. break;
  3419. }
  3420. if (readl(phba->HAregaddr) & HA_ERATT) {
  3421. writel(HA_ERATT, phba->HAregaddr);
  3422. phba->pport->stopped = 1;
  3423. }
  3424. restore_hc:
  3425. phba->link_flag &= ~LS_IGNORE_ERATT;
  3426. writel(hc_copy, phba->HCregaddr);
  3427. readl(phba->HCregaddr); /* flush */
  3428. }
  3429. /**
  3430. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3431. * @phba: Pointer to HBA context object.
  3432. *
  3433. * This function issues a kill_board mailbox command and waits for
  3434. * the error attention interrupt. This function is called for stopping
  3435. * the firmware processing. The caller is not required to hold any
  3436. * locks. This function calls lpfc_hba_down_post function to free
  3437. * any pending commands after the kill. The function will return 1 when it
  3438. * fails to kill the board else will return 0.
  3439. **/
  3440. int
  3441. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3442. {
  3443. struct lpfc_sli *psli;
  3444. LPFC_MBOXQ_t *pmb;
  3445. uint32_t status;
  3446. uint32_t ha_copy;
  3447. int retval;
  3448. int i = 0;
  3449. psli = &phba->sli;
  3450. /* Kill HBA */
  3451. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3452. "0329 Kill HBA Data: x%x x%x\n",
  3453. phba->pport->port_state, psli->sli_flag);
  3454. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3455. if (!pmb)
  3456. return 1;
  3457. /* Disable the error attention */
  3458. spin_lock_irq(&phba->hbalock);
  3459. if (lpfc_readl(phba->HCregaddr, &status)) {
  3460. spin_unlock_irq(&phba->hbalock);
  3461. mempool_free(pmb, phba->mbox_mem_pool);
  3462. return 1;
  3463. }
  3464. status &= ~HC_ERINT_ENA;
  3465. writel(status, phba->HCregaddr);
  3466. readl(phba->HCregaddr); /* flush */
  3467. phba->link_flag |= LS_IGNORE_ERATT;
  3468. spin_unlock_irq(&phba->hbalock);
  3469. lpfc_kill_board(phba, pmb);
  3470. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3471. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3472. if (retval != MBX_SUCCESS) {
  3473. if (retval != MBX_BUSY)
  3474. mempool_free(pmb, phba->mbox_mem_pool);
  3475. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3476. "2752 KILL_BOARD command failed retval %d\n",
  3477. retval);
  3478. spin_lock_irq(&phba->hbalock);
  3479. phba->link_flag &= ~LS_IGNORE_ERATT;
  3480. spin_unlock_irq(&phba->hbalock);
  3481. return 1;
  3482. }
  3483. spin_lock_irq(&phba->hbalock);
  3484. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3485. spin_unlock_irq(&phba->hbalock);
  3486. mempool_free(pmb, phba->mbox_mem_pool);
  3487. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3488. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3489. * 3 seconds we still set HBA_ERROR state because the status of the
  3490. * board is now undefined.
  3491. */
  3492. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3493. return 1;
  3494. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3495. mdelay(100);
  3496. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3497. return 1;
  3498. }
  3499. del_timer_sync(&psli->mbox_tmo);
  3500. if (ha_copy & HA_ERATT) {
  3501. writel(HA_ERATT, phba->HAregaddr);
  3502. phba->pport->stopped = 1;
  3503. }
  3504. spin_lock_irq(&phba->hbalock);
  3505. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3506. psli->mbox_active = NULL;
  3507. phba->link_flag &= ~LS_IGNORE_ERATT;
  3508. spin_unlock_irq(&phba->hbalock);
  3509. lpfc_hba_down_post(phba);
  3510. phba->link_state = LPFC_HBA_ERROR;
  3511. return ha_copy & HA_ERATT ? 0 : 1;
  3512. }
  3513. /**
  3514. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3515. * @phba: Pointer to HBA context object.
  3516. *
  3517. * This function resets the HBA by writing HC_INITFF to the control
  3518. * register. After the HBA resets, this function resets all the iocb ring
  3519. * indices. This function disables PCI layer parity checking during
  3520. * the reset.
  3521. * This function returns 0 always.
  3522. * The caller is not required to hold any locks.
  3523. **/
  3524. int
  3525. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3526. {
  3527. struct lpfc_sli *psli;
  3528. struct lpfc_sli_ring *pring;
  3529. uint16_t cfg_value;
  3530. int i;
  3531. psli = &phba->sli;
  3532. /* Reset HBA */
  3533. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3534. "0325 Reset HBA Data: x%x x%x\n",
  3535. phba->pport->port_state, psli->sli_flag);
  3536. /* perform board reset */
  3537. phba->fc_eventTag = 0;
  3538. phba->link_events = 0;
  3539. phba->pport->fc_myDID = 0;
  3540. phba->pport->fc_prevDID = 0;
  3541. /* Turn off parity checking and serr during the physical reset */
  3542. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3543. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3544. (cfg_value &
  3545. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3546. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3547. /* Now toggle INITFF bit in the Host Control Register */
  3548. writel(HC_INITFF, phba->HCregaddr);
  3549. mdelay(1);
  3550. readl(phba->HCregaddr); /* flush */
  3551. writel(0, phba->HCregaddr);
  3552. readl(phba->HCregaddr); /* flush */
  3553. /* Restore PCI cmd register */
  3554. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3555. /* Initialize relevant SLI info */
  3556. for (i = 0; i < psli->num_rings; i++) {
  3557. pring = &psli->ring[i];
  3558. pring->flag = 0;
  3559. pring->sli.sli3.rspidx = 0;
  3560. pring->sli.sli3.next_cmdidx = 0;
  3561. pring->sli.sli3.local_getidx = 0;
  3562. pring->sli.sli3.cmdidx = 0;
  3563. pring->missbufcnt = 0;
  3564. }
  3565. phba->link_state = LPFC_WARM_START;
  3566. return 0;
  3567. }
  3568. /**
  3569. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3570. * @phba: Pointer to HBA context object.
  3571. *
  3572. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3573. * checking during resets the device. The caller is not required to hold
  3574. * any locks.
  3575. *
  3576. * This function returns 0 always.
  3577. **/
  3578. int
  3579. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3580. {
  3581. struct lpfc_sli *psli = &phba->sli;
  3582. uint16_t cfg_value;
  3583. int rc;
  3584. /* Reset HBA */
  3585. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3586. "0295 Reset HBA Data: x%x x%x\n",
  3587. phba->pport->port_state, psli->sli_flag);
  3588. /* perform board reset */
  3589. phba->fc_eventTag = 0;
  3590. phba->link_events = 0;
  3591. phba->pport->fc_myDID = 0;
  3592. phba->pport->fc_prevDID = 0;
  3593. spin_lock_irq(&phba->hbalock);
  3594. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3595. phba->fcf.fcf_flag = 0;
  3596. spin_unlock_irq(&phba->hbalock);
  3597. /* Now physically reset the device */
  3598. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3599. "0389 Performing PCI function reset!\n");
  3600. /* Turn off parity checking and serr during the physical reset */
  3601. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3602. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3603. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3604. /* Perform FCoE PCI function reset before freeing queue memory */
  3605. rc = lpfc_pci_function_reset(phba);
  3606. lpfc_sli4_queue_destroy(phba);
  3607. /* Restore PCI cmd register */
  3608. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3609. return rc;
  3610. }
  3611. /**
  3612. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3613. * @phba: Pointer to HBA context object.
  3614. *
  3615. * This function is called in the SLI initialization code path to
  3616. * restart the HBA. The caller is not required to hold any lock.
  3617. * This function writes MBX_RESTART mailbox command to the SLIM and
  3618. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3619. * function to free any pending commands. The function enables
  3620. * POST only during the first initialization. The function returns zero.
  3621. * The function does not guarantee completion of MBX_RESTART mailbox
  3622. * command before the return of this function.
  3623. **/
  3624. static int
  3625. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3626. {
  3627. MAILBOX_t *mb;
  3628. struct lpfc_sli *psli;
  3629. volatile uint32_t word0;
  3630. void __iomem *to_slim;
  3631. uint32_t hba_aer_enabled;
  3632. spin_lock_irq(&phba->hbalock);
  3633. /* Take PCIe device Advanced Error Reporting (AER) state */
  3634. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3635. psli = &phba->sli;
  3636. /* Restart HBA */
  3637. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3638. "0337 Restart HBA Data: x%x x%x\n",
  3639. phba->pport->port_state, psli->sli_flag);
  3640. word0 = 0;
  3641. mb = (MAILBOX_t *) &word0;
  3642. mb->mbxCommand = MBX_RESTART;
  3643. mb->mbxHc = 1;
  3644. lpfc_reset_barrier(phba);
  3645. to_slim = phba->MBslimaddr;
  3646. writel(*(uint32_t *) mb, to_slim);
  3647. readl(to_slim); /* flush */
  3648. /* Only skip post after fc_ffinit is completed */
  3649. if (phba->pport->port_state)
  3650. word0 = 1; /* This is really setting up word1 */
  3651. else
  3652. word0 = 0; /* This is really setting up word1 */
  3653. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3654. writel(*(uint32_t *) mb, to_slim);
  3655. readl(to_slim); /* flush */
  3656. lpfc_sli_brdreset(phba);
  3657. phba->pport->stopped = 0;
  3658. phba->link_state = LPFC_INIT_START;
  3659. phba->hba_flag = 0;
  3660. spin_unlock_irq(&phba->hbalock);
  3661. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3662. psli->stats_start = get_seconds();
  3663. /* Give the INITFF and Post time to settle. */
  3664. mdelay(100);
  3665. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3666. if (hba_aer_enabled)
  3667. pci_disable_pcie_error_reporting(phba->pcidev);
  3668. lpfc_hba_down_post(phba);
  3669. return 0;
  3670. }
  3671. /**
  3672. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3673. * @phba: Pointer to HBA context object.
  3674. *
  3675. * This function is called in the SLI initialization code path to restart
  3676. * a SLI4 HBA. The caller is not required to hold any lock.
  3677. * At the end of the function, it calls lpfc_hba_down_post function to
  3678. * free any pending commands.
  3679. **/
  3680. static int
  3681. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3682. {
  3683. struct lpfc_sli *psli = &phba->sli;
  3684. uint32_t hba_aer_enabled;
  3685. int rc;
  3686. /* Restart HBA */
  3687. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3688. "0296 Restart HBA Data: x%x x%x\n",
  3689. phba->pport->port_state, psli->sli_flag);
  3690. /* Take PCIe device Advanced Error Reporting (AER) state */
  3691. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3692. rc = lpfc_sli4_brdreset(phba);
  3693. spin_lock_irq(&phba->hbalock);
  3694. phba->pport->stopped = 0;
  3695. phba->link_state = LPFC_INIT_START;
  3696. phba->hba_flag = 0;
  3697. spin_unlock_irq(&phba->hbalock);
  3698. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3699. psli->stats_start = get_seconds();
  3700. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3701. if (hba_aer_enabled)
  3702. pci_disable_pcie_error_reporting(phba->pcidev);
  3703. lpfc_hba_down_post(phba);
  3704. return rc;
  3705. }
  3706. /**
  3707. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3708. * @phba: Pointer to HBA context object.
  3709. *
  3710. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3711. * API jump table function pointer from the lpfc_hba struct.
  3712. **/
  3713. int
  3714. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3715. {
  3716. return phba->lpfc_sli_brdrestart(phba);
  3717. }
  3718. /**
  3719. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3720. * @phba: Pointer to HBA context object.
  3721. *
  3722. * This function is called after a HBA restart to wait for successful
  3723. * restart of the HBA. Successful restart of the HBA is indicated by
  3724. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3725. * iteration, the function will restart the HBA again. The function returns
  3726. * zero if HBA successfully restarted else returns negative error code.
  3727. **/
  3728. static int
  3729. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3730. {
  3731. uint32_t status, i = 0;
  3732. /* Read the HBA Host Status Register */
  3733. if (lpfc_readl(phba->HSregaddr, &status))
  3734. return -EIO;
  3735. /* Check status register to see what current state is */
  3736. i = 0;
  3737. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3738. /* Check every 10ms for 10 retries, then every 100ms for 90
  3739. * retries, then every 1 sec for 50 retires for a total of
  3740. * ~60 seconds before reset the board again and check every
  3741. * 1 sec for 50 retries. The up to 60 seconds before the
  3742. * board ready is required by the Falcon FIPS zeroization
  3743. * complete, and any reset the board in between shall cause
  3744. * restart of zeroization, further delay the board ready.
  3745. */
  3746. if (i++ >= 200) {
  3747. /* Adapter failed to init, timeout, status reg
  3748. <status> */
  3749. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3750. "0436 Adapter failed to init, "
  3751. "timeout, status reg x%x, "
  3752. "FW Data: A8 x%x AC x%x\n", status,
  3753. readl(phba->MBslimaddr + 0xa8),
  3754. readl(phba->MBslimaddr + 0xac));
  3755. phba->link_state = LPFC_HBA_ERROR;
  3756. return -ETIMEDOUT;
  3757. }
  3758. /* Check to see if any errors occurred during init */
  3759. if (status & HS_FFERM) {
  3760. /* ERROR: During chipset initialization */
  3761. /* Adapter failed to init, chipset, status reg
  3762. <status> */
  3763. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3764. "0437 Adapter failed to init, "
  3765. "chipset, status reg x%x, "
  3766. "FW Data: A8 x%x AC x%x\n", status,
  3767. readl(phba->MBslimaddr + 0xa8),
  3768. readl(phba->MBslimaddr + 0xac));
  3769. phba->link_state = LPFC_HBA_ERROR;
  3770. return -EIO;
  3771. }
  3772. if (i <= 10)
  3773. msleep(10);
  3774. else if (i <= 100)
  3775. msleep(100);
  3776. else
  3777. msleep(1000);
  3778. if (i == 150) {
  3779. /* Do post */
  3780. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3781. lpfc_sli_brdrestart(phba);
  3782. }
  3783. /* Read the HBA Host Status Register */
  3784. if (lpfc_readl(phba->HSregaddr, &status))
  3785. return -EIO;
  3786. }
  3787. /* Check to see if any errors occurred during init */
  3788. if (status & HS_FFERM) {
  3789. /* ERROR: During chipset initialization */
  3790. /* Adapter failed to init, chipset, status reg <status> */
  3791. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3792. "0438 Adapter failed to init, chipset, "
  3793. "status reg x%x, "
  3794. "FW Data: A8 x%x AC x%x\n", status,
  3795. readl(phba->MBslimaddr + 0xa8),
  3796. readl(phba->MBslimaddr + 0xac));
  3797. phba->link_state = LPFC_HBA_ERROR;
  3798. return -EIO;
  3799. }
  3800. /* Clear all interrupt enable conditions */
  3801. writel(0, phba->HCregaddr);
  3802. readl(phba->HCregaddr); /* flush */
  3803. /* setup host attn register */
  3804. writel(0xffffffff, phba->HAregaddr);
  3805. readl(phba->HAregaddr); /* flush */
  3806. return 0;
  3807. }
  3808. /**
  3809. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3810. *
  3811. * This function calculates and returns the number of HBQs required to be
  3812. * configured.
  3813. **/
  3814. int
  3815. lpfc_sli_hbq_count(void)
  3816. {
  3817. return ARRAY_SIZE(lpfc_hbq_defs);
  3818. }
  3819. /**
  3820. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3821. *
  3822. * This function adds the number of hbq entries in every HBQ to get
  3823. * the total number of hbq entries required for the HBA and returns
  3824. * the total count.
  3825. **/
  3826. static int
  3827. lpfc_sli_hbq_entry_count(void)
  3828. {
  3829. int hbq_count = lpfc_sli_hbq_count();
  3830. int count = 0;
  3831. int i;
  3832. for (i = 0; i < hbq_count; ++i)
  3833. count += lpfc_hbq_defs[i]->entry_count;
  3834. return count;
  3835. }
  3836. /**
  3837. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3838. *
  3839. * This function calculates amount of memory required for all hbq entries
  3840. * to be configured and returns the total memory required.
  3841. **/
  3842. int
  3843. lpfc_sli_hbq_size(void)
  3844. {
  3845. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3846. }
  3847. /**
  3848. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3849. * @phba: Pointer to HBA context object.
  3850. *
  3851. * This function is called during the SLI initialization to configure
  3852. * all the HBQs and post buffers to the HBQ. The caller is not
  3853. * required to hold any locks. This function will return zero if successful
  3854. * else it will return negative error code.
  3855. **/
  3856. static int
  3857. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3858. {
  3859. int hbq_count = lpfc_sli_hbq_count();
  3860. LPFC_MBOXQ_t *pmb;
  3861. MAILBOX_t *pmbox;
  3862. uint32_t hbqno;
  3863. uint32_t hbq_entry_index;
  3864. /* Get a Mailbox buffer to setup mailbox
  3865. * commands for HBA initialization
  3866. */
  3867. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3868. if (!pmb)
  3869. return -ENOMEM;
  3870. pmbox = &pmb->u.mb;
  3871. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3872. phba->link_state = LPFC_INIT_MBX_CMDS;
  3873. phba->hbq_in_use = 1;
  3874. hbq_entry_index = 0;
  3875. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3876. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3877. phba->hbqs[hbqno].hbqPutIdx = 0;
  3878. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3879. phba->hbqs[hbqno].entry_count =
  3880. lpfc_hbq_defs[hbqno]->entry_count;
  3881. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3882. hbq_entry_index, pmb);
  3883. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3884. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3885. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3886. mbxStatus <status>, ring <num> */
  3887. lpfc_printf_log(phba, KERN_ERR,
  3888. LOG_SLI | LOG_VPORT,
  3889. "1805 Adapter failed to init. "
  3890. "Data: x%x x%x x%x\n",
  3891. pmbox->mbxCommand,
  3892. pmbox->mbxStatus, hbqno);
  3893. phba->link_state = LPFC_HBA_ERROR;
  3894. mempool_free(pmb, phba->mbox_mem_pool);
  3895. return -ENXIO;
  3896. }
  3897. }
  3898. phba->hbq_count = hbq_count;
  3899. mempool_free(pmb, phba->mbox_mem_pool);
  3900. /* Initially populate or replenish the HBQs */
  3901. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3902. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3903. return 0;
  3904. }
  3905. /**
  3906. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3907. * @phba: Pointer to HBA context object.
  3908. *
  3909. * This function is called during the SLI initialization to configure
  3910. * all the HBQs and post buffers to the HBQ. The caller is not
  3911. * required to hold any locks. This function will return zero if successful
  3912. * else it will return negative error code.
  3913. **/
  3914. static int
  3915. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3916. {
  3917. phba->hbq_in_use = 1;
  3918. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3919. phba->hbq_count = 1;
  3920. /* Initially populate or replenish the HBQs */
  3921. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3922. return 0;
  3923. }
  3924. /**
  3925. * lpfc_sli_config_port - Issue config port mailbox command
  3926. * @phba: Pointer to HBA context object.
  3927. * @sli_mode: sli mode - 2/3
  3928. *
  3929. * This function is called by the sli intialization code path
  3930. * to issue config_port mailbox command. This function restarts the
  3931. * HBA firmware and issues a config_port mailbox command to configure
  3932. * the SLI interface in the sli mode specified by sli_mode
  3933. * variable. The caller is not required to hold any locks.
  3934. * The function returns 0 if successful, else returns negative error
  3935. * code.
  3936. **/
  3937. int
  3938. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3939. {
  3940. LPFC_MBOXQ_t *pmb;
  3941. uint32_t resetcount = 0, rc = 0, done = 0;
  3942. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3943. if (!pmb) {
  3944. phba->link_state = LPFC_HBA_ERROR;
  3945. return -ENOMEM;
  3946. }
  3947. phba->sli_rev = sli_mode;
  3948. while (resetcount < 2 && !done) {
  3949. spin_lock_irq(&phba->hbalock);
  3950. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3951. spin_unlock_irq(&phba->hbalock);
  3952. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3953. lpfc_sli_brdrestart(phba);
  3954. rc = lpfc_sli_chipset_init(phba);
  3955. if (rc)
  3956. break;
  3957. spin_lock_irq(&phba->hbalock);
  3958. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3959. spin_unlock_irq(&phba->hbalock);
  3960. resetcount++;
  3961. /* Call pre CONFIG_PORT mailbox command initialization. A
  3962. * value of 0 means the call was successful. Any other
  3963. * nonzero value is a failure, but if ERESTART is returned,
  3964. * the driver may reset the HBA and try again.
  3965. */
  3966. rc = lpfc_config_port_prep(phba);
  3967. if (rc == -ERESTART) {
  3968. phba->link_state = LPFC_LINK_UNKNOWN;
  3969. continue;
  3970. } else if (rc)
  3971. break;
  3972. phba->link_state = LPFC_INIT_MBX_CMDS;
  3973. lpfc_config_port(phba, pmb);
  3974. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3975. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3976. LPFC_SLI3_HBQ_ENABLED |
  3977. LPFC_SLI3_CRP_ENABLED |
  3978. LPFC_SLI3_BG_ENABLED |
  3979. LPFC_SLI3_DSS_ENABLED);
  3980. if (rc != MBX_SUCCESS) {
  3981. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3982. "0442 Adapter failed to init, mbxCmd x%x "
  3983. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3984. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3985. spin_lock_irq(&phba->hbalock);
  3986. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3987. spin_unlock_irq(&phba->hbalock);
  3988. rc = -ENXIO;
  3989. } else {
  3990. /* Allow asynchronous mailbox command to go through */
  3991. spin_lock_irq(&phba->hbalock);
  3992. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3993. spin_unlock_irq(&phba->hbalock);
  3994. done = 1;
  3995. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  3996. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  3997. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3998. "3110 Port did not grant ASABT\n");
  3999. }
  4000. }
  4001. if (!done) {
  4002. rc = -EINVAL;
  4003. goto do_prep_failed;
  4004. }
  4005. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  4006. if (!pmb->u.mb.un.varCfgPort.cMA) {
  4007. rc = -ENXIO;
  4008. goto do_prep_failed;
  4009. }
  4010. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  4011. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  4012. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  4013. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  4014. phba->max_vpi : phba->max_vports;
  4015. } else
  4016. phba->max_vpi = 0;
  4017. phba->fips_level = 0;
  4018. phba->fips_spec_rev = 0;
  4019. if (pmb->u.mb.un.varCfgPort.gdss) {
  4020. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  4021. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  4022. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  4023. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4024. "2850 Security Crypto Active. FIPS x%d "
  4025. "(Spec Rev: x%d)",
  4026. phba->fips_level, phba->fips_spec_rev);
  4027. }
  4028. if (pmb->u.mb.un.varCfgPort.sec_err) {
  4029. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4030. "2856 Config Port Security Crypto "
  4031. "Error: x%x ",
  4032. pmb->u.mb.un.varCfgPort.sec_err);
  4033. }
  4034. if (pmb->u.mb.un.varCfgPort.gerbm)
  4035. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  4036. if (pmb->u.mb.un.varCfgPort.gcrp)
  4037. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  4038. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  4039. phba->port_gp = phba->mbox->us.s3_pgp.port;
  4040. if (phba->cfg_enable_bg) {
  4041. if (pmb->u.mb.un.varCfgPort.gbg)
  4042. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  4043. else
  4044. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4045. "0443 Adapter did not grant "
  4046. "BlockGuard\n");
  4047. }
  4048. } else {
  4049. phba->hbq_get = NULL;
  4050. phba->port_gp = phba->mbox->us.s2.port;
  4051. phba->max_vpi = 0;
  4052. }
  4053. do_prep_failed:
  4054. mempool_free(pmb, phba->mbox_mem_pool);
  4055. return rc;
  4056. }
  4057. /**
  4058. * lpfc_sli_hba_setup - SLI intialization function
  4059. * @phba: Pointer to HBA context object.
  4060. *
  4061. * This function is the main SLI intialization function. This function
  4062. * is called by the HBA intialization code, HBA reset code and HBA
  4063. * error attention handler code. Caller is not required to hold any
  4064. * locks. This function issues config_port mailbox command to configure
  4065. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4066. * calls the config_port_post function to issue init_link mailbox
  4067. * command and to start the discovery. The function will return zero
  4068. * if successful, else it will return negative error code.
  4069. **/
  4070. int
  4071. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4072. {
  4073. uint32_t rc;
  4074. int mode = 3, i;
  4075. int longs;
  4076. switch (lpfc_sli_mode) {
  4077. case 2:
  4078. if (phba->cfg_enable_npiv) {
  4079. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4080. "1824 NPIV enabled: Override lpfc_sli_mode "
  4081. "parameter (%d) to auto (0).\n",
  4082. lpfc_sli_mode);
  4083. break;
  4084. }
  4085. mode = 2;
  4086. break;
  4087. case 0:
  4088. case 3:
  4089. break;
  4090. default:
  4091. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4092. "1819 Unrecognized lpfc_sli_mode "
  4093. "parameter: %d.\n", lpfc_sli_mode);
  4094. break;
  4095. }
  4096. rc = lpfc_sli_config_port(phba, mode);
  4097. if (rc && lpfc_sli_mode == 3)
  4098. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4099. "1820 Unable to select SLI-3. "
  4100. "Not supported by adapter.\n");
  4101. if (rc && mode != 2)
  4102. rc = lpfc_sli_config_port(phba, 2);
  4103. if (rc)
  4104. goto lpfc_sli_hba_setup_error;
  4105. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4106. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4107. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4108. if (!rc) {
  4109. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4110. "2709 This device supports "
  4111. "Advanced Error Reporting (AER)\n");
  4112. spin_lock_irq(&phba->hbalock);
  4113. phba->hba_flag |= HBA_AER_ENABLED;
  4114. spin_unlock_irq(&phba->hbalock);
  4115. } else {
  4116. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4117. "2708 This device does not support "
  4118. "Advanced Error Reporting (AER)\n");
  4119. phba->cfg_aer_support = 0;
  4120. }
  4121. }
  4122. if (phba->sli_rev == 3) {
  4123. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4124. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4125. } else {
  4126. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4127. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4128. phba->sli3_options = 0;
  4129. }
  4130. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4131. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4132. phba->sli_rev, phba->max_vpi);
  4133. rc = lpfc_sli_ring_map(phba);
  4134. if (rc)
  4135. goto lpfc_sli_hba_setup_error;
  4136. /* Initialize VPIs. */
  4137. if (phba->sli_rev == LPFC_SLI_REV3) {
  4138. /*
  4139. * The VPI bitmask and physical ID array are allocated
  4140. * and initialized once only - at driver load. A port
  4141. * reset doesn't need to reinitialize this memory.
  4142. */
  4143. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4144. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4145. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4146. GFP_KERNEL);
  4147. if (!phba->vpi_bmask) {
  4148. rc = -ENOMEM;
  4149. goto lpfc_sli_hba_setup_error;
  4150. }
  4151. phba->vpi_ids = kzalloc(
  4152. (phba->max_vpi+1) * sizeof(uint16_t),
  4153. GFP_KERNEL);
  4154. if (!phba->vpi_ids) {
  4155. kfree(phba->vpi_bmask);
  4156. rc = -ENOMEM;
  4157. goto lpfc_sli_hba_setup_error;
  4158. }
  4159. for (i = 0; i < phba->max_vpi; i++)
  4160. phba->vpi_ids[i] = i;
  4161. }
  4162. }
  4163. /* Init HBQs */
  4164. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4165. rc = lpfc_sli_hbq_setup(phba);
  4166. if (rc)
  4167. goto lpfc_sli_hba_setup_error;
  4168. }
  4169. spin_lock_irq(&phba->hbalock);
  4170. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4171. spin_unlock_irq(&phba->hbalock);
  4172. rc = lpfc_config_port_post(phba);
  4173. if (rc)
  4174. goto lpfc_sli_hba_setup_error;
  4175. return rc;
  4176. lpfc_sli_hba_setup_error:
  4177. phba->link_state = LPFC_HBA_ERROR;
  4178. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4179. "0445 Firmware initialization failed\n");
  4180. return rc;
  4181. }
  4182. /**
  4183. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4184. * @phba: Pointer to HBA context object.
  4185. * @mboxq: mailbox pointer.
  4186. * This function issue a dump mailbox command to read config region
  4187. * 23 and parse the records in the region and populate driver
  4188. * data structure.
  4189. **/
  4190. static int
  4191. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4192. {
  4193. LPFC_MBOXQ_t *mboxq;
  4194. struct lpfc_dmabuf *mp;
  4195. struct lpfc_mqe *mqe;
  4196. uint32_t data_length;
  4197. int rc;
  4198. /* Program the default value of vlan_id and fc_map */
  4199. phba->valid_vlan = 0;
  4200. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4201. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4202. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4203. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4204. if (!mboxq)
  4205. return -ENOMEM;
  4206. mqe = &mboxq->u.mqe;
  4207. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4208. rc = -ENOMEM;
  4209. goto out_free_mboxq;
  4210. }
  4211. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4212. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4213. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4214. "(%d):2571 Mailbox cmd x%x Status x%x "
  4215. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4216. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4217. "CQ: x%x x%x x%x x%x\n",
  4218. mboxq->vport ? mboxq->vport->vpi : 0,
  4219. bf_get(lpfc_mqe_command, mqe),
  4220. bf_get(lpfc_mqe_status, mqe),
  4221. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4222. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4223. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4224. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4225. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4226. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4227. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4228. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4229. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4230. mboxq->mcqe.word0,
  4231. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4232. mboxq->mcqe.trailer);
  4233. if (rc) {
  4234. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4235. kfree(mp);
  4236. rc = -EIO;
  4237. goto out_free_mboxq;
  4238. }
  4239. data_length = mqe->un.mb_words[5];
  4240. if (data_length > DMP_RGN23_SIZE) {
  4241. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4242. kfree(mp);
  4243. rc = -EIO;
  4244. goto out_free_mboxq;
  4245. }
  4246. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4247. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4248. kfree(mp);
  4249. rc = 0;
  4250. out_free_mboxq:
  4251. mempool_free(mboxq, phba->mbox_mem_pool);
  4252. return rc;
  4253. }
  4254. /**
  4255. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4256. * @phba: pointer to lpfc hba data structure.
  4257. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4258. * @vpd: pointer to the memory to hold resulting port vpd data.
  4259. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4260. * On output, the number of data bytes in @vpd.
  4261. *
  4262. * This routine executes a READ_REV SLI4 mailbox command. In
  4263. * addition, this routine gets the port vpd data.
  4264. *
  4265. * Return codes
  4266. * 0 - successful
  4267. * -ENOMEM - could not allocated memory.
  4268. **/
  4269. static int
  4270. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4271. uint8_t *vpd, uint32_t *vpd_size)
  4272. {
  4273. int rc = 0;
  4274. uint32_t dma_size;
  4275. struct lpfc_dmabuf *dmabuf;
  4276. struct lpfc_mqe *mqe;
  4277. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4278. if (!dmabuf)
  4279. return -ENOMEM;
  4280. /*
  4281. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4282. * mailbox command.
  4283. */
  4284. dma_size = *vpd_size;
  4285. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4286. dma_size,
  4287. &dmabuf->phys,
  4288. GFP_KERNEL);
  4289. if (!dmabuf->virt) {
  4290. kfree(dmabuf);
  4291. return -ENOMEM;
  4292. }
  4293. memset(dmabuf->virt, 0, dma_size);
  4294. /*
  4295. * The SLI4 implementation of READ_REV conflicts at word1,
  4296. * bits 31:16 and SLI4 adds vpd functionality not present
  4297. * in SLI3. This code corrects the conflicts.
  4298. */
  4299. lpfc_read_rev(phba, mboxq);
  4300. mqe = &mboxq->u.mqe;
  4301. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4302. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4303. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4304. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4305. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4306. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4307. if (rc) {
  4308. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4309. dmabuf->virt, dmabuf->phys);
  4310. kfree(dmabuf);
  4311. return -EIO;
  4312. }
  4313. /*
  4314. * The available vpd length cannot be bigger than the
  4315. * DMA buffer passed to the port. Catch the less than
  4316. * case and update the caller's size.
  4317. */
  4318. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4319. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4320. memcpy(vpd, dmabuf->virt, *vpd_size);
  4321. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4322. dmabuf->virt, dmabuf->phys);
  4323. kfree(dmabuf);
  4324. return 0;
  4325. }
  4326. /**
  4327. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4328. * @phba: pointer to lpfc hba data structure.
  4329. *
  4330. * This routine retrieves SLI4 device physical port name this PCI function
  4331. * is attached to.
  4332. *
  4333. * Return codes
  4334. * 0 - successful
  4335. * otherwise - failed to retrieve physical port name
  4336. **/
  4337. static int
  4338. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4339. {
  4340. LPFC_MBOXQ_t *mboxq;
  4341. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4342. struct lpfc_controller_attribute *cntl_attr;
  4343. struct lpfc_mbx_get_port_name *get_port_name;
  4344. void *virtaddr = NULL;
  4345. uint32_t alloclen, reqlen;
  4346. uint32_t shdr_status, shdr_add_status;
  4347. union lpfc_sli4_cfg_shdr *shdr;
  4348. char cport_name = 0;
  4349. int rc;
  4350. /* We assume nothing at this point */
  4351. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4352. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4353. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4354. if (!mboxq)
  4355. return -ENOMEM;
  4356. /* obtain link type and link number via READ_CONFIG */
  4357. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4358. lpfc_sli4_read_config(phba);
  4359. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4360. goto retrieve_ppname;
  4361. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4362. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4363. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4364. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4365. LPFC_SLI4_MBX_NEMBED);
  4366. if (alloclen < reqlen) {
  4367. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4368. "3084 Allocated DMA memory size (%d) is "
  4369. "less than the requested DMA memory size "
  4370. "(%d)\n", alloclen, reqlen);
  4371. rc = -ENOMEM;
  4372. goto out_free_mboxq;
  4373. }
  4374. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4375. virtaddr = mboxq->sge_array->addr[0];
  4376. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4377. shdr = &mbx_cntl_attr->cfg_shdr;
  4378. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4379. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4380. if (shdr_status || shdr_add_status || rc) {
  4381. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4382. "3085 Mailbox x%x (x%x/x%x) failed, "
  4383. "rc:x%x, status:x%x, add_status:x%x\n",
  4384. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4385. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4386. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4387. rc, shdr_status, shdr_add_status);
  4388. rc = -ENXIO;
  4389. goto out_free_mboxq;
  4390. }
  4391. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4392. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4393. phba->sli4_hba.lnk_info.lnk_tp =
  4394. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4395. phba->sli4_hba.lnk_info.lnk_no =
  4396. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4397. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4398. "3086 lnk_type:%d, lnk_numb:%d\n",
  4399. phba->sli4_hba.lnk_info.lnk_tp,
  4400. phba->sli4_hba.lnk_info.lnk_no);
  4401. retrieve_ppname:
  4402. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4403. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4404. sizeof(struct lpfc_mbx_get_port_name) -
  4405. sizeof(struct lpfc_sli4_cfg_mhdr),
  4406. LPFC_SLI4_MBX_EMBED);
  4407. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4408. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4409. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4410. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4411. phba->sli4_hba.lnk_info.lnk_tp);
  4412. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4413. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4414. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4415. if (shdr_status || shdr_add_status || rc) {
  4416. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4417. "3087 Mailbox x%x (x%x/x%x) failed: "
  4418. "rc:x%x, status:x%x, add_status:x%x\n",
  4419. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4420. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4421. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4422. rc, shdr_status, shdr_add_status);
  4423. rc = -ENXIO;
  4424. goto out_free_mboxq;
  4425. }
  4426. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4427. case LPFC_LINK_NUMBER_0:
  4428. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4429. &get_port_name->u.response);
  4430. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4431. break;
  4432. case LPFC_LINK_NUMBER_1:
  4433. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4434. &get_port_name->u.response);
  4435. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4436. break;
  4437. case LPFC_LINK_NUMBER_2:
  4438. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4439. &get_port_name->u.response);
  4440. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4441. break;
  4442. case LPFC_LINK_NUMBER_3:
  4443. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4444. &get_port_name->u.response);
  4445. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4446. break;
  4447. default:
  4448. break;
  4449. }
  4450. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4451. phba->Port[0] = cport_name;
  4452. phba->Port[1] = '\0';
  4453. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4454. "3091 SLI get port name: %s\n", phba->Port);
  4455. }
  4456. out_free_mboxq:
  4457. if (rc != MBX_TIMEOUT) {
  4458. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4459. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4460. else
  4461. mempool_free(mboxq, phba->mbox_mem_pool);
  4462. }
  4463. return rc;
  4464. }
  4465. /**
  4466. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4467. * @phba: pointer to lpfc hba data structure.
  4468. *
  4469. * This routine is called to explicitly arm the SLI4 device's completion and
  4470. * event queues
  4471. **/
  4472. static void
  4473. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4474. {
  4475. uint8_t fcp_eqidx;
  4476. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4477. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4478. fcp_eqidx = 0;
  4479. if (phba->sli4_hba.fcp_cq) {
  4480. do {
  4481. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4482. LPFC_QUEUE_REARM);
  4483. } while (++fcp_eqidx < phba->cfg_fcp_io_channel);
  4484. }
  4485. if (phba->sli4_hba.hba_eq) {
  4486. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
  4487. fcp_eqidx++)
  4488. lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx],
  4489. LPFC_QUEUE_REARM);
  4490. }
  4491. }
  4492. /**
  4493. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4494. * @phba: Pointer to HBA context object.
  4495. * @type: The resource extent type.
  4496. * @extnt_count: buffer to hold port available extent count.
  4497. * @extnt_size: buffer to hold element count per extent.
  4498. *
  4499. * This function calls the port and retrievs the number of available
  4500. * extents and their size for a particular extent type.
  4501. *
  4502. * Returns: 0 if successful. Nonzero otherwise.
  4503. **/
  4504. int
  4505. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4506. uint16_t *extnt_count, uint16_t *extnt_size)
  4507. {
  4508. int rc = 0;
  4509. uint32_t length;
  4510. uint32_t mbox_tmo;
  4511. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4512. LPFC_MBOXQ_t *mbox;
  4513. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4514. if (!mbox)
  4515. return -ENOMEM;
  4516. /* Find out how many extents are available for this resource type */
  4517. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4518. sizeof(struct lpfc_sli4_cfg_mhdr));
  4519. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4520. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4521. length, LPFC_SLI4_MBX_EMBED);
  4522. /* Send an extents count of 0 - the GET doesn't use it. */
  4523. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4524. LPFC_SLI4_MBX_EMBED);
  4525. if (unlikely(rc)) {
  4526. rc = -EIO;
  4527. goto err_exit;
  4528. }
  4529. if (!phba->sli4_hba.intr_enable)
  4530. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4531. else {
  4532. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4533. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4534. }
  4535. if (unlikely(rc)) {
  4536. rc = -EIO;
  4537. goto err_exit;
  4538. }
  4539. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4540. if (bf_get(lpfc_mbox_hdr_status,
  4541. &rsrc_info->header.cfg_shdr.response)) {
  4542. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4543. "2930 Failed to get resource extents "
  4544. "Status 0x%x Add'l Status 0x%x\n",
  4545. bf_get(lpfc_mbox_hdr_status,
  4546. &rsrc_info->header.cfg_shdr.response),
  4547. bf_get(lpfc_mbox_hdr_add_status,
  4548. &rsrc_info->header.cfg_shdr.response));
  4549. rc = -EIO;
  4550. goto err_exit;
  4551. }
  4552. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4553. &rsrc_info->u.rsp);
  4554. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4555. &rsrc_info->u.rsp);
  4556. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4557. "3162 Retrieved extents type-%d from port: count:%d, "
  4558. "size:%d\n", type, *extnt_count, *extnt_size);
  4559. err_exit:
  4560. mempool_free(mbox, phba->mbox_mem_pool);
  4561. return rc;
  4562. }
  4563. /**
  4564. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4565. * @phba: Pointer to HBA context object.
  4566. * @type: The extent type to check.
  4567. *
  4568. * This function reads the current available extents from the port and checks
  4569. * if the extent count or extent size has changed since the last access.
  4570. * Callers use this routine post port reset to understand if there is a
  4571. * extent reprovisioning requirement.
  4572. *
  4573. * Returns:
  4574. * -Error: error indicates problem.
  4575. * 1: Extent count or size has changed.
  4576. * 0: No changes.
  4577. **/
  4578. static int
  4579. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4580. {
  4581. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4582. uint16_t size_diff, rsrc_ext_size;
  4583. int rc = 0;
  4584. struct lpfc_rsrc_blks *rsrc_entry;
  4585. struct list_head *rsrc_blk_list = NULL;
  4586. size_diff = 0;
  4587. curr_ext_cnt = 0;
  4588. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4589. &rsrc_ext_cnt,
  4590. &rsrc_ext_size);
  4591. if (unlikely(rc))
  4592. return -EIO;
  4593. switch (type) {
  4594. case LPFC_RSC_TYPE_FCOE_RPI:
  4595. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4596. break;
  4597. case LPFC_RSC_TYPE_FCOE_VPI:
  4598. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4599. break;
  4600. case LPFC_RSC_TYPE_FCOE_XRI:
  4601. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4602. break;
  4603. case LPFC_RSC_TYPE_FCOE_VFI:
  4604. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4605. break;
  4606. default:
  4607. break;
  4608. }
  4609. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4610. curr_ext_cnt++;
  4611. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4612. size_diff++;
  4613. }
  4614. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4615. rc = 1;
  4616. return rc;
  4617. }
  4618. /**
  4619. * lpfc_sli4_cfg_post_extnts -
  4620. * @phba: Pointer to HBA context object.
  4621. * @extnt_cnt - number of available extents.
  4622. * @type - the extent type (rpi, xri, vfi, vpi).
  4623. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4624. * @mbox - pointer to the caller's allocated mailbox structure.
  4625. *
  4626. * This function executes the extents allocation request. It also
  4627. * takes care of the amount of memory needed to allocate or get the
  4628. * allocated extents. It is the caller's responsibility to evaluate
  4629. * the response.
  4630. *
  4631. * Returns:
  4632. * -Error: Error value describes the condition found.
  4633. * 0: if successful
  4634. **/
  4635. static int
  4636. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
  4637. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4638. {
  4639. int rc = 0;
  4640. uint32_t req_len;
  4641. uint32_t emb_len;
  4642. uint32_t alloc_len, mbox_tmo;
  4643. /* Calculate the total requested length of the dma memory */
  4644. req_len = extnt_cnt * sizeof(uint16_t);
  4645. /*
  4646. * Calculate the size of an embedded mailbox. The uint32_t
  4647. * accounts for extents-specific word.
  4648. */
  4649. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4650. sizeof(uint32_t);
  4651. /*
  4652. * Presume the allocation and response will fit into an embedded
  4653. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4654. */
  4655. *emb = LPFC_SLI4_MBX_EMBED;
  4656. if (req_len > emb_len) {
  4657. req_len = extnt_cnt * sizeof(uint16_t) +
  4658. sizeof(union lpfc_sli4_cfg_shdr) +
  4659. sizeof(uint32_t);
  4660. *emb = LPFC_SLI4_MBX_NEMBED;
  4661. }
  4662. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4663. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4664. req_len, *emb);
  4665. if (alloc_len < req_len) {
  4666. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4667. "2982 Allocated DMA memory size (x%x) is "
  4668. "less than the requested DMA memory "
  4669. "size (x%x)\n", alloc_len, req_len);
  4670. return -ENOMEM;
  4671. }
  4672. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
  4673. if (unlikely(rc))
  4674. return -EIO;
  4675. if (!phba->sli4_hba.intr_enable)
  4676. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4677. else {
  4678. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4679. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4680. }
  4681. if (unlikely(rc))
  4682. rc = -EIO;
  4683. return rc;
  4684. }
  4685. /**
  4686. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4687. * @phba: Pointer to HBA context object.
  4688. * @type: The resource extent type to allocate.
  4689. *
  4690. * This function allocates the number of elements for the specified
  4691. * resource type.
  4692. **/
  4693. static int
  4694. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4695. {
  4696. bool emb = false;
  4697. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4698. uint16_t rsrc_id, rsrc_start, j, k;
  4699. uint16_t *ids;
  4700. int i, rc;
  4701. unsigned long longs;
  4702. unsigned long *bmask;
  4703. struct lpfc_rsrc_blks *rsrc_blks;
  4704. LPFC_MBOXQ_t *mbox;
  4705. uint32_t length;
  4706. struct lpfc_id_range *id_array = NULL;
  4707. void *virtaddr = NULL;
  4708. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4709. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4710. struct list_head *ext_blk_list;
  4711. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4712. &rsrc_cnt,
  4713. &rsrc_size);
  4714. if (unlikely(rc))
  4715. return -EIO;
  4716. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4717. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4718. "3009 No available Resource Extents "
  4719. "for resource type 0x%x: Count: 0x%x, "
  4720. "Size 0x%x\n", type, rsrc_cnt,
  4721. rsrc_size);
  4722. return -ENOMEM;
  4723. }
  4724. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
  4725. "2903 Post resource extents type-0x%x: "
  4726. "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
  4727. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4728. if (!mbox)
  4729. return -ENOMEM;
  4730. rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
  4731. if (unlikely(rc)) {
  4732. rc = -EIO;
  4733. goto err_exit;
  4734. }
  4735. /*
  4736. * Figure out where the response is located. Then get local pointers
  4737. * to the response data. The port does not guarantee to respond to
  4738. * all extents counts request so update the local variable with the
  4739. * allocated count from the port.
  4740. */
  4741. if (emb == LPFC_SLI4_MBX_EMBED) {
  4742. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4743. id_array = &rsrc_ext->u.rsp.id[0];
  4744. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4745. } else {
  4746. virtaddr = mbox->sge_array->addr[0];
  4747. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4748. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4749. id_array = &n_rsrc->id;
  4750. }
  4751. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4752. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4753. /*
  4754. * Based on the resource size and count, correct the base and max
  4755. * resource values.
  4756. */
  4757. length = sizeof(struct lpfc_rsrc_blks);
  4758. switch (type) {
  4759. case LPFC_RSC_TYPE_FCOE_RPI:
  4760. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4761. sizeof(unsigned long),
  4762. GFP_KERNEL);
  4763. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4764. rc = -ENOMEM;
  4765. goto err_exit;
  4766. }
  4767. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4768. sizeof(uint16_t),
  4769. GFP_KERNEL);
  4770. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4771. kfree(phba->sli4_hba.rpi_bmask);
  4772. rc = -ENOMEM;
  4773. goto err_exit;
  4774. }
  4775. /*
  4776. * The next_rpi was initialized with the maximum available
  4777. * count but the port may allocate a smaller number. Catch
  4778. * that case and update the next_rpi.
  4779. */
  4780. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4781. /* Initialize local ptrs for common extent processing later. */
  4782. bmask = phba->sli4_hba.rpi_bmask;
  4783. ids = phba->sli4_hba.rpi_ids;
  4784. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4785. break;
  4786. case LPFC_RSC_TYPE_FCOE_VPI:
  4787. phba->vpi_bmask = kzalloc(longs *
  4788. sizeof(unsigned long),
  4789. GFP_KERNEL);
  4790. if (unlikely(!phba->vpi_bmask)) {
  4791. rc = -ENOMEM;
  4792. goto err_exit;
  4793. }
  4794. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4795. sizeof(uint16_t),
  4796. GFP_KERNEL);
  4797. if (unlikely(!phba->vpi_ids)) {
  4798. kfree(phba->vpi_bmask);
  4799. rc = -ENOMEM;
  4800. goto err_exit;
  4801. }
  4802. /* Initialize local ptrs for common extent processing later. */
  4803. bmask = phba->vpi_bmask;
  4804. ids = phba->vpi_ids;
  4805. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4806. break;
  4807. case LPFC_RSC_TYPE_FCOE_XRI:
  4808. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4809. sizeof(unsigned long),
  4810. GFP_KERNEL);
  4811. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4812. rc = -ENOMEM;
  4813. goto err_exit;
  4814. }
  4815. phba->sli4_hba.max_cfg_param.xri_used = 0;
  4816. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4817. sizeof(uint16_t),
  4818. GFP_KERNEL);
  4819. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4820. kfree(phba->sli4_hba.xri_bmask);
  4821. rc = -ENOMEM;
  4822. goto err_exit;
  4823. }
  4824. /* Initialize local ptrs for common extent processing later. */
  4825. bmask = phba->sli4_hba.xri_bmask;
  4826. ids = phba->sli4_hba.xri_ids;
  4827. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4828. break;
  4829. case LPFC_RSC_TYPE_FCOE_VFI:
  4830. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4831. sizeof(unsigned long),
  4832. GFP_KERNEL);
  4833. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4834. rc = -ENOMEM;
  4835. goto err_exit;
  4836. }
  4837. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4838. sizeof(uint16_t),
  4839. GFP_KERNEL);
  4840. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4841. kfree(phba->sli4_hba.vfi_bmask);
  4842. rc = -ENOMEM;
  4843. goto err_exit;
  4844. }
  4845. /* Initialize local ptrs for common extent processing later. */
  4846. bmask = phba->sli4_hba.vfi_bmask;
  4847. ids = phba->sli4_hba.vfi_ids;
  4848. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4849. break;
  4850. default:
  4851. /* Unsupported Opcode. Fail call. */
  4852. id_array = NULL;
  4853. bmask = NULL;
  4854. ids = NULL;
  4855. ext_blk_list = NULL;
  4856. goto err_exit;
  4857. }
  4858. /*
  4859. * Complete initializing the extent configuration with the
  4860. * allocated ids assigned to this function. The bitmask serves
  4861. * as an index into the array and manages the available ids. The
  4862. * array just stores the ids communicated to the port via the wqes.
  4863. */
  4864. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  4865. if ((i % 2) == 0)
  4866. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  4867. &id_array[k]);
  4868. else
  4869. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  4870. &id_array[k]);
  4871. rsrc_blks = kzalloc(length, GFP_KERNEL);
  4872. if (unlikely(!rsrc_blks)) {
  4873. rc = -ENOMEM;
  4874. kfree(bmask);
  4875. kfree(ids);
  4876. goto err_exit;
  4877. }
  4878. rsrc_blks->rsrc_start = rsrc_id;
  4879. rsrc_blks->rsrc_size = rsrc_size;
  4880. list_add_tail(&rsrc_blks->list, ext_blk_list);
  4881. rsrc_start = rsrc_id;
  4882. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  4883. phba->sli4_hba.scsi_xri_start = rsrc_start +
  4884. lpfc_sli4_get_els_iocb_cnt(phba);
  4885. while (rsrc_id < (rsrc_start + rsrc_size)) {
  4886. ids[j] = rsrc_id;
  4887. rsrc_id++;
  4888. j++;
  4889. }
  4890. /* Entire word processed. Get next word.*/
  4891. if ((i % 2) == 1)
  4892. k++;
  4893. }
  4894. err_exit:
  4895. lpfc_sli4_mbox_cmd_free(phba, mbox);
  4896. return rc;
  4897. }
  4898. /**
  4899. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  4900. * @phba: Pointer to HBA context object.
  4901. * @type: the extent's type.
  4902. *
  4903. * This function deallocates all extents of a particular resource type.
  4904. * SLI4 does not allow for deallocating a particular extent range. It
  4905. * is the caller's responsibility to release all kernel memory resources.
  4906. **/
  4907. static int
  4908. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  4909. {
  4910. int rc;
  4911. uint32_t length, mbox_tmo = 0;
  4912. LPFC_MBOXQ_t *mbox;
  4913. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  4914. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  4915. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4916. if (!mbox)
  4917. return -ENOMEM;
  4918. /*
  4919. * This function sends an embedded mailbox because it only sends the
  4920. * the resource type. All extents of this type are released by the
  4921. * port.
  4922. */
  4923. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  4924. sizeof(struct lpfc_sli4_cfg_mhdr));
  4925. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4926. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  4927. length, LPFC_SLI4_MBX_EMBED);
  4928. /* Send an extents count of 0 - the dealloc doesn't use it. */
  4929. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4930. LPFC_SLI4_MBX_EMBED);
  4931. if (unlikely(rc)) {
  4932. rc = -EIO;
  4933. goto out_free_mbox;
  4934. }
  4935. if (!phba->sli4_hba.intr_enable)
  4936. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4937. else {
  4938. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4939. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4940. }
  4941. if (unlikely(rc)) {
  4942. rc = -EIO;
  4943. goto out_free_mbox;
  4944. }
  4945. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  4946. if (bf_get(lpfc_mbox_hdr_status,
  4947. &dealloc_rsrc->header.cfg_shdr.response)) {
  4948. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4949. "2919 Failed to release resource extents "
  4950. "for type %d - Status 0x%x Add'l Status 0x%x. "
  4951. "Resource memory not released.\n",
  4952. type,
  4953. bf_get(lpfc_mbox_hdr_status,
  4954. &dealloc_rsrc->header.cfg_shdr.response),
  4955. bf_get(lpfc_mbox_hdr_add_status,
  4956. &dealloc_rsrc->header.cfg_shdr.response));
  4957. rc = -EIO;
  4958. goto out_free_mbox;
  4959. }
  4960. /* Release kernel memory resources for the specific type. */
  4961. switch (type) {
  4962. case LPFC_RSC_TYPE_FCOE_VPI:
  4963. kfree(phba->vpi_bmask);
  4964. kfree(phba->vpi_ids);
  4965. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4966. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4967. &phba->lpfc_vpi_blk_list, list) {
  4968. list_del_init(&rsrc_blk->list);
  4969. kfree(rsrc_blk);
  4970. }
  4971. break;
  4972. case LPFC_RSC_TYPE_FCOE_XRI:
  4973. kfree(phba->sli4_hba.xri_bmask);
  4974. kfree(phba->sli4_hba.xri_ids);
  4975. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4976. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  4977. list_del_init(&rsrc_blk->list);
  4978. kfree(rsrc_blk);
  4979. }
  4980. break;
  4981. case LPFC_RSC_TYPE_FCOE_VFI:
  4982. kfree(phba->sli4_hba.vfi_bmask);
  4983. kfree(phba->sli4_hba.vfi_ids);
  4984. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4985. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4986. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  4987. list_del_init(&rsrc_blk->list);
  4988. kfree(rsrc_blk);
  4989. }
  4990. break;
  4991. case LPFC_RSC_TYPE_FCOE_RPI:
  4992. /* RPI bitmask and physical id array are cleaned up earlier. */
  4993. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4994. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  4995. list_del_init(&rsrc_blk->list);
  4996. kfree(rsrc_blk);
  4997. }
  4998. break;
  4999. default:
  5000. break;
  5001. }
  5002. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5003. out_free_mbox:
  5004. mempool_free(mbox, phba->mbox_mem_pool);
  5005. return rc;
  5006. }
  5007. /**
  5008. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  5009. * @phba: Pointer to HBA context object.
  5010. *
  5011. * This function allocates all SLI4 resource identifiers.
  5012. **/
  5013. int
  5014. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  5015. {
  5016. int i, rc, error = 0;
  5017. uint16_t count, base;
  5018. unsigned long longs;
  5019. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5020. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  5021. if (phba->sli4_hba.extents_in_use) {
  5022. /*
  5023. * The port supports resource extents. The XRI, VPI, VFI, RPI
  5024. * resource extent count must be read and allocated before
  5025. * provisioning the resource id arrays.
  5026. */
  5027. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5028. LPFC_IDX_RSRC_RDY) {
  5029. /*
  5030. * Extent-based resources are set - the driver could
  5031. * be in a port reset. Figure out if any corrective
  5032. * actions need to be taken.
  5033. */
  5034. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5035. LPFC_RSC_TYPE_FCOE_VFI);
  5036. if (rc != 0)
  5037. error++;
  5038. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5039. LPFC_RSC_TYPE_FCOE_VPI);
  5040. if (rc != 0)
  5041. error++;
  5042. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5043. LPFC_RSC_TYPE_FCOE_XRI);
  5044. if (rc != 0)
  5045. error++;
  5046. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5047. LPFC_RSC_TYPE_FCOE_RPI);
  5048. if (rc != 0)
  5049. error++;
  5050. /*
  5051. * It's possible that the number of resources
  5052. * provided to this port instance changed between
  5053. * resets. Detect this condition and reallocate
  5054. * resources. Otherwise, there is no action.
  5055. */
  5056. if (error) {
  5057. lpfc_printf_log(phba, KERN_INFO,
  5058. LOG_MBOX | LOG_INIT,
  5059. "2931 Detected extent resource "
  5060. "change. Reallocating all "
  5061. "extents.\n");
  5062. rc = lpfc_sli4_dealloc_extent(phba,
  5063. LPFC_RSC_TYPE_FCOE_VFI);
  5064. rc = lpfc_sli4_dealloc_extent(phba,
  5065. LPFC_RSC_TYPE_FCOE_VPI);
  5066. rc = lpfc_sli4_dealloc_extent(phba,
  5067. LPFC_RSC_TYPE_FCOE_XRI);
  5068. rc = lpfc_sli4_dealloc_extent(phba,
  5069. LPFC_RSC_TYPE_FCOE_RPI);
  5070. } else
  5071. return 0;
  5072. }
  5073. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5074. if (unlikely(rc))
  5075. goto err_exit;
  5076. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5077. if (unlikely(rc))
  5078. goto err_exit;
  5079. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5080. if (unlikely(rc))
  5081. goto err_exit;
  5082. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5083. if (unlikely(rc))
  5084. goto err_exit;
  5085. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5086. LPFC_IDX_RSRC_RDY);
  5087. return rc;
  5088. } else {
  5089. /*
  5090. * The port does not support resource extents. The XRI, VPI,
  5091. * VFI, RPI resource ids were determined from READ_CONFIG.
  5092. * Just allocate the bitmasks and provision the resource id
  5093. * arrays. If a port reset is active, the resources don't
  5094. * need any action - just exit.
  5095. */
  5096. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5097. LPFC_IDX_RSRC_RDY) {
  5098. lpfc_sli4_dealloc_resource_identifiers(phba);
  5099. lpfc_sli4_remove_rpis(phba);
  5100. }
  5101. /* RPIs. */
  5102. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5103. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5104. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5105. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5106. sizeof(unsigned long),
  5107. GFP_KERNEL);
  5108. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5109. rc = -ENOMEM;
  5110. goto err_exit;
  5111. }
  5112. phba->sli4_hba.rpi_ids = kzalloc(count *
  5113. sizeof(uint16_t),
  5114. GFP_KERNEL);
  5115. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5116. rc = -ENOMEM;
  5117. goto free_rpi_bmask;
  5118. }
  5119. for (i = 0; i < count; i++)
  5120. phba->sli4_hba.rpi_ids[i] = base + i;
  5121. /* VPIs. */
  5122. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5123. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5124. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5125. phba->vpi_bmask = kzalloc(longs *
  5126. sizeof(unsigned long),
  5127. GFP_KERNEL);
  5128. if (unlikely(!phba->vpi_bmask)) {
  5129. rc = -ENOMEM;
  5130. goto free_rpi_ids;
  5131. }
  5132. phba->vpi_ids = kzalloc(count *
  5133. sizeof(uint16_t),
  5134. GFP_KERNEL);
  5135. if (unlikely(!phba->vpi_ids)) {
  5136. rc = -ENOMEM;
  5137. goto free_vpi_bmask;
  5138. }
  5139. for (i = 0; i < count; i++)
  5140. phba->vpi_ids[i] = base + i;
  5141. /* XRIs. */
  5142. count = phba->sli4_hba.max_cfg_param.max_xri;
  5143. base = phba->sli4_hba.max_cfg_param.xri_base;
  5144. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5145. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5146. sizeof(unsigned long),
  5147. GFP_KERNEL);
  5148. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5149. rc = -ENOMEM;
  5150. goto free_vpi_ids;
  5151. }
  5152. phba->sli4_hba.max_cfg_param.xri_used = 0;
  5153. phba->sli4_hba.xri_ids = kzalloc(count *
  5154. sizeof(uint16_t),
  5155. GFP_KERNEL);
  5156. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5157. rc = -ENOMEM;
  5158. goto free_xri_bmask;
  5159. }
  5160. for (i = 0; i < count; i++)
  5161. phba->sli4_hba.xri_ids[i] = base + i;
  5162. /* VFIs. */
  5163. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5164. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5165. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5166. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5167. sizeof(unsigned long),
  5168. GFP_KERNEL);
  5169. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5170. rc = -ENOMEM;
  5171. goto free_xri_ids;
  5172. }
  5173. phba->sli4_hba.vfi_ids = kzalloc(count *
  5174. sizeof(uint16_t),
  5175. GFP_KERNEL);
  5176. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5177. rc = -ENOMEM;
  5178. goto free_vfi_bmask;
  5179. }
  5180. for (i = 0; i < count; i++)
  5181. phba->sli4_hba.vfi_ids[i] = base + i;
  5182. /*
  5183. * Mark all resources ready. An HBA reset doesn't need
  5184. * to reset the initialization.
  5185. */
  5186. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5187. LPFC_IDX_RSRC_RDY);
  5188. return 0;
  5189. }
  5190. free_vfi_bmask:
  5191. kfree(phba->sli4_hba.vfi_bmask);
  5192. free_xri_ids:
  5193. kfree(phba->sli4_hba.xri_ids);
  5194. free_xri_bmask:
  5195. kfree(phba->sli4_hba.xri_bmask);
  5196. free_vpi_ids:
  5197. kfree(phba->vpi_ids);
  5198. free_vpi_bmask:
  5199. kfree(phba->vpi_bmask);
  5200. free_rpi_ids:
  5201. kfree(phba->sli4_hba.rpi_ids);
  5202. free_rpi_bmask:
  5203. kfree(phba->sli4_hba.rpi_bmask);
  5204. err_exit:
  5205. return rc;
  5206. }
  5207. /**
  5208. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5209. * @phba: Pointer to HBA context object.
  5210. *
  5211. * This function allocates the number of elements for the specified
  5212. * resource type.
  5213. **/
  5214. int
  5215. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5216. {
  5217. if (phba->sli4_hba.extents_in_use) {
  5218. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5219. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5220. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5221. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5222. } else {
  5223. kfree(phba->vpi_bmask);
  5224. kfree(phba->vpi_ids);
  5225. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5226. kfree(phba->sli4_hba.xri_bmask);
  5227. kfree(phba->sli4_hba.xri_ids);
  5228. kfree(phba->sli4_hba.vfi_bmask);
  5229. kfree(phba->sli4_hba.vfi_ids);
  5230. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5231. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5232. }
  5233. return 0;
  5234. }
  5235. /**
  5236. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5237. * @phba: Pointer to HBA context object.
  5238. * @type: The resource extent type.
  5239. * @extnt_count: buffer to hold port extent count response
  5240. * @extnt_size: buffer to hold port extent size response.
  5241. *
  5242. * This function calls the port to read the host allocated extents
  5243. * for a particular type.
  5244. **/
  5245. int
  5246. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5247. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5248. {
  5249. bool emb;
  5250. int rc = 0;
  5251. uint16_t curr_blks = 0;
  5252. uint32_t req_len, emb_len;
  5253. uint32_t alloc_len, mbox_tmo;
  5254. struct list_head *blk_list_head;
  5255. struct lpfc_rsrc_blks *rsrc_blk;
  5256. LPFC_MBOXQ_t *mbox;
  5257. void *virtaddr = NULL;
  5258. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5259. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5260. union lpfc_sli4_cfg_shdr *shdr;
  5261. switch (type) {
  5262. case LPFC_RSC_TYPE_FCOE_VPI:
  5263. blk_list_head = &phba->lpfc_vpi_blk_list;
  5264. break;
  5265. case LPFC_RSC_TYPE_FCOE_XRI:
  5266. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5267. break;
  5268. case LPFC_RSC_TYPE_FCOE_VFI:
  5269. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5270. break;
  5271. case LPFC_RSC_TYPE_FCOE_RPI:
  5272. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5273. break;
  5274. default:
  5275. return -EIO;
  5276. }
  5277. /* Count the number of extents currently allocatd for this type. */
  5278. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5279. if (curr_blks == 0) {
  5280. /*
  5281. * The GET_ALLOCATED mailbox does not return the size,
  5282. * just the count. The size should be just the size
  5283. * stored in the current allocated block and all sizes
  5284. * for an extent type are the same so set the return
  5285. * value now.
  5286. */
  5287. *extnt_size = rsrc_blk->rsrc_size;
  5288. }
  5289. curr_blks++;
  5290. }
  5291. /* Calculate the total requested length of the dma memory. */
  5292. req_len = curr_blks * sizeof(uint16_t);
  5293. /*
  5294. * Calculate the size of an embedded mailbox. The uint32_t
  5295. * accounts for extents-specific word.
  5296. */
  5297. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5298. sizeof(uint32_t);
  5299. /*
  5300. * Presume the allocation and response will fit into an embedded
  5301. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5302. */
  5303. emb = LPFC_SLI4_MBX_EMBED;
  5304. req_len = emb_len;
  5305. if (req_len > emb_len) {
  5306. req_len = curr_blks * sizeof(uint16_t) +
  5307. sizeof(union lpfc_sli4_cfg_shdr) +
  5308. sizeof(uint32_t);
  5309. emb = LPFC_SLI4_MBX_NEMBED;
  5310. }
  5311. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5312. if (!mbox)
  5313. return -ENOMEM;
  5314. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5315. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5316. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5317. req_len, emb);
  5318. if (alloc_len < req_len) {
  5319. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5320. "2983 Allocated DMA memory size (x%x) is "
  5321. "less than the requested DMA memory "
  5322. "size (x%x)\n", alloc_len, req_len);
  5323. rc = -ENOMEM;
  5324. goto err_exit;
  5325. }
  5326. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5327. if (unlikely(rc)) {
  5328. rc = -EIO;
  5329. goto err_exit;
  5330. }
  5331. if (!phba->sli4_hba.intr_enable)
  5332. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5333. else {
  5334. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5335. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5336. }
  5337. if (unlikely(rc)) {
  5338. rc = -EIO;
  5339. goto err_exit;
  5340. }
  5341. /*
  5342. * Figure out where the response is located. Then get local pointers
  5343. * to the response data. The port does not guarantee to respond to
  5344. * all extents counts request so update the local variable with the
  5345. * allocated count from the port.
  5346. */
  5347. if (emb == LPFC_SLI4_MBX_EMBED) {
  5348. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5349. shdr = &rsrc_ext->header.cfg_shdr;
  5350. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5351. } else {
  5352. virtaddr = mbox->sge_array->addr[0];
  5353. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5354. shdr = &n_rsrc->cfg_shdr;
  5355. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5356. }
  5357. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5358. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5359. "2984 Failed to read allocated resources "
  5360. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5361. type,
  5362. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5363. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5364. rc = -EIO;
  5365. goto err_exit;
  5366. }
  5367. err_exit:
  5368. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5369. return rc;
  5370. }
  5371. /**
  5372. * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
  5373. * @phba: pointer to lpfc hba data structure.
  5374. *
  5375. * This routine walks the list of els buffers that have been allocated and
  5376. * repost them to the port by using SGL block post. This is needed after a
  5377. * pci_function_reset/warm_start or start. It attempts to construct blocks
  5378. * of els buffer sgls which contains contiguous xris and uses the non-embedded
  5379. * SGL block post mailbox commands to post them to the port. For single els
  5380. * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
  5381. * mailbox command for posting.
  5382. *
  5383. * Returns: 0 = success, non-zero failure.
  5384. **/
  5385. static int
  5386. lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
  5387. {
  5388. struct lpfc_sglq *sglq_entry = NULL;
  5389. struct lpfc_sglq *sglq_entry_next = NULL;
  5390. struct lpfc_sglq *sglq_entry_first = NULL;
  5391. int status, post_cnt = 0, num_posted = 0, block_cnt = 0;
  5392. int last_xritag = NO_XRI;
  5393. LIST_HEAD(prep_sgl_list);
  5394. LIST_HEAD(blck_sgl_list);
  5395. LIST_HEAD(allc_sgl_list);
  5396. LIST_HEAD(post_sgl_list);
  5397. LIST_HEAD(free_sgl_list);
  5398. spin_lock(&phba->hbalock);
  5399. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
  5400. spin_unlock(&phba->hbalock);
  5401. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  5402. &allc_sgl_list, list) {
  5403. list_del_init(&sglq_entry->list);
  5404. block_cnt++;
  5405. if ((last_xritag != NO_XRI) &&
  5406. (sglq_entry->sli4_xritag != last_xritag + 1)) {
  5407. /* a hole in xri block, form a sgl posting block */
  5408. list_splice_init(&prep_sgl_list, &blck_sgl_list);
  5409. post_cnt = block_cnt - 1;
  5410. /* prepare list for next posting block */
  5411. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5412. block_cnt = 1;
  5413. } else {
  5414. /* prepare list for next posting block */
  5415. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5416. /* enough sgls for non-embed sgl mbox command */
  5417. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  5418. list_splice_init(&prep_sgl_list,
  5419. &blck_sgl_list);
  5420. post_cnt = block_cnt;
  5421. block_cnt = 0;
  5422. }
  5423. }
  5424. num_posted++;
  5425. /* keep track of last sgl's xritag */
  5426. last_xritag = sglq_entry->sli4_xritag;
  5427. /* end of repost sgl list condition for els buffers */
  5428. if (num_posted == phba->sli4_hba.els_xri_cnt) {
  5429. if (post_cnt == 0) {
  5430. list_splice_init(&prep_sgl_list,
  5431. &blck_sgl_list);
  5432. post_cnt = block_cnt;
  5433. } else if (block_cnt == 1) {
  5434. status = lpfc_sli4_post_sgl(phba,
  5435. sglq_entry->phys, 0,
  5436. sglq_entry->sli4_xritag);
  5437. if (!status) {
  5438. /* successful, put sgl to posted list */
  5439. list_add_tail(&sglq_entry->list,
  5440. &post_sgl_list);
  5441. } else {
  5442. /* Failure, put sgl to free list */
  5443. lpfc_printf_log(phba, KERN_WARNING,
  5444. LOG_SLI,
  5445. "3159 Failed to post els "
  5446. "sgl, xritag:x%x\n",
  5447. sglq_entry->sli4_xritag);
  5448. list_add_tail(&sglq_entry->list,
  5449. &free_sgl_list);
  5450. spin_lock_irq(&phba->hbalock);
  5451. phba->sli4_hba.els_xri_cnt--;
  5452. spin_unlock_irq(&phba->hbalock);
  5453. }
  5454. }
  5455. }
  5456. /* continue until a nembed page worth of sgls */
  5457. if (post_cnt == 0)
  5458. continue;
  5459. /* post the els buffer list sgls as a block */
  5460. status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
  5461. post_cnt);
  5462. if (!status) {
  5463. /* success, put sgl list to posted sgl list */
  5464. list_splice_init(&blck_sgl_list, &post_sgl_list);
  5465. } else {
  5466. /* Failure, put sgl list to free sgl list */
  5467. sglq_entry_first = list_first_entry(&blck_sgl_list,
  5468. struct lpfc_sglq,
  5469. list);
  5470. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5471. "3160 Failed to post els sgl-list, "
  5472. "xritag:x%x-x%x\n",
  5473. sglq_entry_first->sli4_xritag,
  5474. (sglq_entry_first->sli4_xritag +
  5475. post_cnt - 1));
  5476. list_splice_init(&blck_sgl_list, &free_sgl_list);
  5477. spin_lock_irq(&phba->hbalock);
  5478. phba->sli4_hba.els_xri_cnt -= post_cnt;
  5479. spin_unlock_irq(&phba->hbalock);
  5480. }
  5481. /* don't reset xirtag due to hole in xri block */
  5482. if (block_cnt == 0)
  5483. last_xritag = NO_XRI;
  5484. /* reset els sgl post count for next round of posting */
  5485. post_cnt = 0;
  5486. }
  5487. /* free the els sgls failed to post */
  5488. lpfc_free_sgl_list(phba, &free_sgl_list);
  5489. /* push els sgls posted to the availble list */
  5490. if (!list_empty(&post_sgl_list)) {
  5491. spin_lock(&phba->hbalock);
  5492. list_splice_init(&post_sgl_list,
  5493. &phba->sli4_hba.lpfc_sgl_list);
  5494. spin_unlock(&phba->hbalock);
  5495. } else {
  5496. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5497. "3161 Failure to post els sgl to port.\n");
  5498. return -EIO;
  5499. }
  5500. return 0;
  5501. }
  5502. /**
  5503. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5504. * @phba: Pointer to HBA context object.
  5505. *
  5506. * This function is the main SLI4 device intialization PCI function. This
  5507. * function is called by the HBA intialization code, HBA reset code and
  5508. * HBA error attention handler code. Caller is not required to hold any
  5509. * locks.
  5510. **/
  5511. int
  5512. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5513. {
  5514. int rc;
  5515. LPFC_MBOXQ_t *mboxq;
  5516. struct lpfc_mqe *mqe;
  5517. uint8_t *vpd;
  5518. uint32_t vpd_size;
  5519. uint32_t ftr_rsp = 0;
  5520. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5521. struct lpfc_vport *vport = phba->pport;
  5522. struct lpfc_dmabuf *mp;
  5523. /* Perform a PCI function reset to start from clean */
  5524. rc = lpfc_pci_function_reset(phba);
  5525. if (unlikely(rc))
  5526. return -ENODEV;
  5527. /* Check the HBA Host Status Register for readyness */
  5528. rc = lpfc_sli4_post_status_check(phba);
  5529. if (unlikely(rc))
  5530. return -ENODEV;
  5531. else {
  5532. spin_lock_irq(&phba->hbalock);
  5533. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5534. spin_unlock_irq(&phba->hbalock);
  5535. }
  5536. /*
  5537. * Allocate a single mailbox container for initializing the
  5538. * port.
  5539. */
  5540. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5541. if (!mboxq)
  5542. return -ENOMEM;
  5543. /* Issue READ_REV to collect vpd and FW information. */
  5544. vpd_size = SLI4_PAGE_SIZE;
  5545. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5546. if (!vpd) {
  5547. rc = -ENOMEM;
  5548. goto out_free_mbox;
  5549. }
  5550. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5551. if (unlikely(rc)) {
  5552. kfree(vpd);
  5553. goto out_free_mbox;
  5554. }
  5555. mqe = &mboxq->u.mqe;
  5556. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5557. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  5558. phba->hba_flag |= HBA_FCOE_MODE;
  5559. else
  5560. phba->hba_flag &= ~HBA_FCOE_MODE;
  5561. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5562. LPFC_DCBX_CEE_MODE)
  5563. phba->hba_flag |= HBA_FIP_SUPPORT;
  5564. else
  5565. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5566. phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
  5567. if (phba->sli_rev != LPFC_SLI_REV4) {
  5568. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5569. "0376 READ_REV Error. SLI Level %d "
  5570. "FCoE enabled %d\n",
  5571. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5572. rc = -EIO;
  5573. kfree(vpd);
  5574. goto out_free_mbox;
  5575. }
  5576. /*
  5577. * Continue initialization with default values even if driver failed
  5578. * to read FCoE param config regions, only read parameters if the
  5579. * board is FCoE
  5580. */
  5581. if (phba->hba_flag & HBA_FCOE_MODE &&
  5582. lpfc_sli4_read_fcoe_params(phba))
  5583. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5584. "2570 Failed to read FCoE parameters\n");
  5585. /*
  5586. * Retrieve sli4 device physical port name, failure of doing it
  5587. * is considered as non-fatal.
  5588. */
  5589. rc = lpfc_sli4_retrieve_pport_name(phba);
  5590. if (!rc)
  5591. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5592. "3080 Successful retrieving SLI4 device "
  5593. "physical port name: %s.\n", phba->Port);
  5594. /*
  5595. * Evaluate the read rev and vpd data. Populate the driver
  5596. * state with the results. If this routine fails, the failure
  5597. * is not fatal as the driver will use generic values.
  5598. */
  5599. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5600. if (unlikely(!rc)) {
  5601. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5602. "0377 Error %d parsing vpd. "
  5603. "Using defaults.\n", rc);
  5604. rc = 0;
  5605. }
  5606. kfree(vpd);
  5607. /* Save information as VPD data */
  5608. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5609. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5610. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5611. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5612. &mqe->un.read_rev);
  5613. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5614. &mqe->un.read_rev);
  5615. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5616. &mqe->un.read_rev);
  5617. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5618. &mqe->un.read_rev);
  5619. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5620. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5621. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5622. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5623. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5624. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5625. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5626. "(%d):0380 READ_REV Status x%x "
  5627. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5628. mboxq->vport ? mboxq->vport->vpi : 0,
  5629. bf_get(lpfc_mqe_status, mqe),
  5630. phba->vpd.rev.opFwName,
  5631. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5632. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5633. /*
  5634. * Discover the port's supported feature set and match it against the
  5635. * hosts requests.
  5636. */
  5637. lpfc_request_features(phba, mboxq);
  5638. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5639. if (unlikely(rc)) {
  5640. rc = -EIO;
  5641. goto out_free_mbox;
  5642. }
  5643. /*
  5644. * The port must support FCP initiator mode as this is the
  5645. * only mode running in the host.
  5646. */
  5647. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5648. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5649. "0378 No support for fcpi mode.\n");
  5650. ftr_rsp++;
  5651. }
  5652. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5653. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5654. else
  5655. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5656. /*
  5657. * If the port cannot support the host's requested features
  5658. * then turn off the global config parameters to disable the
  5659. * feature in the driver. This is not a fatal error.
  5660. */
  5661. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5662. if (phba->cfg_enable_bg) {
  5663. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5664. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5665. else
  5666. ftr_rsp++;
  5667. }
  5668. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5669. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5670. ftr_rsp++;
  5671. if (ftr_rsp) {
  5672. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5673. "0379 Feature Mismatch Data: x%08x %08x "
  5674. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5675. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5676. phba->cfg_enable_npiv, phba->max_vpi);
  5677. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5678. phba->cfg_enable_bg = 0;
  5679. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5680. phba->cfg_enable_npiv = 0;
  5681. }
  5682. /* These SLI3 features are assumed in SLI4 */
  5683. spin_lock_irq(&phba->hbalock);
  5684. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5685. spin_unlock_irq(&phba->hbalock);
  5686. /*
  5687. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5688. * calls depends on these resources to complete port setup.
  5689. */
  5690. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5691. if (rc) {
  5692. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5693. "2920 Failed to alloc Resource IDs "
  5694. "rc = x%x\n", rc);
  5695. goto out_free_mbox;
  5696. }
  5697. /* Read the port's service parameters. */
  5698. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5699. if (rc) {
  5700. phba->link_state = LPFC_HBA_ERROR;
  5701. rc = -ENOMEM;
  5702. goto out_free_mbox;
  5703. }
  5704. mboxq->vport = vport;
  5705. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5706. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5707. if (rc == MBX_SUCCESS) {
  5708. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5709. rc = 0;
  5710. }
  5711. /*
  5712. * This memory was allocated by the lpfc_read_sparam routine. Release
  5713. * it to the mbuf pool.
  5714. */
  5715. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5716. kfree(mp);
  5717. mboxq->context1 = NULL;
  5718. if (unlikely(rc)) {
  5719. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5720. "0382 READ_SPARAM command failed "
  5721. "status %d, mbxStatus x%x\n",
  5722. rc, bf_get(lpfc_mqe_status, mqe));
  5723. phba->link_state = LPFC_HBA_ERROR;
  5724. rc = -EIO;
  5725. goto out_free_mbox;
  5726. }
  5727. lpfc_update_vport_wwn(vport);
  5728. /* Update the fc_host data structures with new wwn. */
  5729. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5730. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5731. /* update host els and scsi xri-sgl sizes and mappings */
  5732. rc = lpfc_sli4_xri_sgl_update(phba);
  5733. if (unlikely(rc)) {
  5734. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5735. "1400 Failed to update xri-sgl size and "
  5736. "mapping: %d\n", rc);
  5737. goto out_free_mbox;
  5738. }
  5739. /* register the els sgl pool to the port */
  5740. rc = lpfc_sli4_repost_els_sgl_list(phba);
  5741. if (unlikely(rc)) {
  5742. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5743. "0582 Error %d during els sgl post "
  5744. "operation\n", rc);
  5745. rc = -ENODEV;
  5746. goto out_free_mbox;
  5747. }
  5748. /* register the allocated scsi sgl pool to the port */
  5749. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  5750. if (unlikely(rc)) {
  5751. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5752. "0383 Error %d during scsi sgl post "
  5753. "operation\n", rc);
  5754. /* Some Scsi buffers were moved to the abort scsi list */
  5755. /* A pci function reset will repost them */
  5756. rc = -ENODEV;
  5757. goto out_free_mbox;
  5758. }
  5759. /* Post the rpi header region to the device. */
  5760. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  5761. if (unlikely(rc)) {
  5762. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5763. "0393 Error %d during rpi post operation\n",
  5764. rc);
  5765. rc = -ENODEV;
  5766. goto out_free_mbox;
  5767. }
  5768. lpfc_sli4_node_prep(phba);
  5769. /* Create all the SLI4 queues */
  5770. rc = lpfc_sli4_queue_create(phba);
  5771. if (rc) {
  5772. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5773. "3089 Failed to allocate queues\n");
  5774. rc = -ENODEV;
  5775. goto out_stop_timers;
  5776. }
  5777. /* Set up all the queues to the device */
  5778. rc = lpfc_sli4_queue_setup(phba);
  5779. if (unlikely(rc)) {
  5780. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5781. "0381 Error %d during queue setup.\n ", rc);
  5782. goto out_destroy_queue;
  5783. }
  5784. /* Arm the CQs and then EQs on device */
  5785. lpfc_sli4_arm_cqeq_intr(phba);
  5786. /* Indicate device interrupt mode */
  5787. phba->sli4_hba.intr_enable = 1;
  5788. /* Allow asynchronous mailbox command to go through */
  5789. spin_lock_irq(&phba->hbalock);
  5790. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5791. spin_unlock_irq(&phba->hbalock);
  5792. /* Post receive buffers to the device */
  5793. lpfc_sli4_rb_setup(phba);
  5794. /* Reset HBA FCF states after HBA reset */
  5795. phba->fcf.fcf_flag = 0;
  5796. phba->fcf.current_rec.flag = 0;
  5797. /* Start the ELS watchdog timer */
  5798. mod_timer(&vport->els_tmofunc,
  5799. jiffies + HZ * (phba->fc_ratov * 2));
  5800. /* Start heart beat timer */
  5801. mod_timer(&phba->hb_tmofunc,
  5802. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  5803. phba->hb_outstanding = 0;
  5804. phba->last_completion_time = jiffies;
  5805. /* Start error attention (ERATT) polling timer */
  5806. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  5807. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  5808. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  5809. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  5810. if (!rc) {
  5811. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5812. "2829 This device supports "
  5813. "Advanced Error Reporting (AER)\n");
  5814. spin_lock_irq(&phba->hbalock);
  5815. phba->hba_flag |= HBA_AER_ENABLED;
  5816. spin_unlock_irq(&phba->hbalock);
  5817. } else {
  5818. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5819. "2830 This device does not support "
  5820. "Advanced Error Reporting (AER)\n");
  5821. phba->cfg_aer_support = 0;
  5822. }
  5823. rc = 0;
  5824. }
  5825. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  5826. /*
  5827. * The FC Port needs to register FCFI (index 0)
  5828. */
  5829. lpfc_reg_fcfi(phba, mboxq);
  5830. mboxq->vport = phba->pport;
  5831. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5832. if (rc != MBX_SUCCESS)
  5833. goto out_unset_queue;
  5834. rc = 0;
  5835. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  5836. &mboxq->u.mqe.un.reg_fcfi);
  5837. /* Check if the port is configured to be disabled */
  5838. lpfc_sli_read_link_ste(phba);
  5839. }
  5840. /*
  5841. * The port is ready, set the host's link state to LINK_DOWN
  5842. * in preparation for link interrupts.
  5843. */
  5844. spin_lock_irq(&phba->hbalock);
  5845. phba->link_state = LPFC_LINK_DOWN;
  5846. spin_unlock_irq(&phba->hbalock);
  5847. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  5848. (phba->hba_flag & LINK_DISABLED)) {
  5849. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5850. "3103 Adapter Link is disabled.\n");
  5851. lpfc_down_link(phba, mboxq);
  5852. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5853. if (rc != MBX_SUCCESS) {
  5854. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5855. "3104 Adapter failed to issue "
  5856. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  5857. goto out_unset_queue;
  5858. }
  5859. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  5860. /* don't perform init_link on SLI4 FC port loopback test */
  5861. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  5862. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  5863. if (rc)
  5864. goto out_unset_queue;
  5865. }
  5866. }
  5867. mempool_free(mboxq, phba->mbox_mem_pool);
  5868. return rc;
  5869. out_unset_queue:
  5870. /* Unset all the queues set up in this routine when error out */
  5871. lpfc_sli4_queue_unset(phba);
  5872. out_destroy_queue:
  5873. lpfc_sli4_queue_destroy(phba);
  5874. out_stop_timers:
  5875. lpfc_stop_hba_timers(phba);
  5876. out_free_mbox:
  5877. mempool_free(mboxq, phba->mbox_mem_pool);
  5878. return rc;
  5879. }
  5880. /**
  5881. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  5882. * @ptr: context object - pointer to hba structure.
  5883. *
  5884. * This is the callback function for mailbox timer. The mailbox
  5885. * timer is armed when a new mailbox command is issued and the timer
  5886. * is deleted when the mailbox complete. The function is called by
  5887. * the kernel timer code when a mailbox does not complete within
  5888. * expected time. This function wakes up the worker thread to
  5889. * process the mailbox timeout and returns. All the processing is
  5890. * done by the worker thread function lpfc_mbox_timeout_handler.
  5891. **/
  5892. void
  5893. lpfc_mbox_timeout(unsigned long ptr)
  5894. {
  5895. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  5896. unsigned long iflag;
  5897. uint32_t tmo_posted;
  5898. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  5899. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  5900. if (!tmo_posted)
  5901. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  5902. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  5903. if (!tmo_posted)
  5904. lpfc_worker_wake_up(phba);
  5905. return;
  5906. }
  5907. /**
  5908. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  5909. * @phba: Pointer to HBA context object.
  5910. *
  5911. * This function is called from worker thread when a mailbox command times out.
  5912. * The caller is not required to hold any locks. This function will reset the
  5913. * HBA and recover all the pending commands.
  5914. **/
  5915. void
  5916. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  5917. {
  5918. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  5919. MAILBOX_t *mb = &pmbox->u.mb;
  5920. struct lpfc_sli *psli = &phba->sli;
  5921. struct lpfc_sli_ring *pring;
  5922. /* Check the pmbox pointer first. There is a race condition
  5923. * between the mbox timeout handler getting executed in the
  5924. * worklist and the mailbox actually completing. When this
  5925. * race condition occurs, the mbox_active will be NULL.
  5926. */
  5927. spin_lock_irq(&phba->hbalock);
  5928. if (pmbox == NULL) {
  5929. lpfc_printf_log(phba, KERN_WARNING,
  5930. LOG_MBOX | LOG_SLI,
  5931. "0353 Active Mailbox cleared - mailbox timeout "
  5932. "exiting\n");
  5933. spin_unlock_irq(&phba->hbalock);
  5934. return;
  5935. }
  5936. /* Mbox cmd <mbxCommand> timeout */
  5937. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5938. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  5939. mb->mbxCommand,
  5940. phba->pport->port_state,
  5941. phba->sli.sli_flag,
  5942. phba->sli.mbox_active);
  5943. spin_unlock_irq(&phba->hbalock);
  5944. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  5945. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  5946. * it to fail all outstanding SCSI IO.
  5947. */
  5948. spin_lock_irq(&phba->pport->work_port_lock);
  5949. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  5950. spin_unlock_irq(&phba->pport->work_port_lock);
  5951. spin_lock_irq(&phba->hbalock);
  5952. phba->link_state = LPFC_LINK_UNKNOWN;
  5953. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  5954. spin_unlock_irq(&phba->hbalock);
  5955. pring = &psli->ring[psli->fcp_ring];
  5956. lpfc_sli_abort_iocb_ring(phba, pring);
  5957. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5958. "0345 Resetting board due to mailbox timeout\n");
  5959. /* Reset the HBA device */
  5960. lpfc_reset_hba(phba);
  5961. }
  5962. /**
  5963. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  5964. * @phba: Pointer to HBA context object.
  5965. * @pmbox: Pointer to mailbox object.
  5966. * @flag: Flag indicating how the mailbox need to be processed.
  5967. *
  5968. * This function is called by discovery code and HBA management code
  5969. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  5970. * function gets the hbalock to protect the data structures.
  5971. * The mailbox command can be submitted in polling mode, in which case
  5972. * this function will wait in a polling loop for the completion of the
  5973. * mailbox.
  5974. * If the mailbox is submitted in no_wait mode (not polling) the
  5975. * function will submit the command and returns immediately without waiting
  5976. * for the mailbox completion. The no_wait is supported only when HBA
  5977. * is in SLI2/SLI3 mode - interrupts are enabled.
  5978. * The SLI interface allows only one mailbox pending at a time. If the
  5979. * mailbox is issued in polling mode and there is already a mailbox
  5980. * pending, then the function will return an error. If the mailbox is issued
  5981. * in NO_WAIT mode and there is a mailbox pending already, the function
  5982. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  5983. * The sli layer owns the mailbox object until the completion of mailbox
  5984. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  5985. * return codes the caller owns the mailbox command after the return of
  5986. * the function.
  5987. **/
  5988. static int
  5989. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  5990. uint32_t flag)
  5991. {
  5992. MAILBOX_t *mb;
  5993. struct lpfc_sli *psli = &phba->sli;
  5994. uint32_t status, evtctr;
  5995. uint32_t ha_copy, hc_copy;
  5996. int i;
  5997. unsigned long timeout;
  5998. unsigned long drvr_flag = 0;
  5999. uint32_t word0, ldata;
  6000. void __iomem *to_slim;
  6001. int processing_queue = 0;
  6002. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6003. if (!pmbox) {
  6004. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6005. /* processing mbox queue from intr_handler */
  6006. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6007. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6008. return MBX_SUCCESS;
  6009. }
  6010. processing_queue = 1;
  6011. pmbox = lpfc_mbox_get(phba);
  6012. if (!pmbox) {
  6013. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6014. return MBX_SUCCESS;
  6015. }
  6016. }
  6017. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  6018. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  6019. if(!pmbox->vport) {
  6020. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6021. lpfc_printf_log(phba, KERN_ERR,
  6022. LOG_MBOX | LOG_VPORT,
  6023. "1806 Mbox x%x failed. No vport\n",
  6024. pmbox->u.mb.mbxCommand);
  6025. dump_stack();
  6026. goto out_not_finished;
  6027. }
  6028. }
  6029. /* If the PCI channel is in offline state, do not post mbox. */
  6030. if (unlikely(pci_channel_offline(phba->pcidev))) {
  6031. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6032. goto out_not_finished;
  6033. }
  6034. /* If HBA has a deferred error attention, fail the iocb. */
  6035. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  6036. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6037. goto out_not_finished;
  6038. }
  6039. psli = &phba->sli;
  6040. mb = &pmbox->u.mb;
  6041. status = MBX_SUCCESS;
  6042. if (phba->link_state == LPFC_HBA_ERROR) {
  6043. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6044. /* Mbox command <mbxCommand> cannot issue */
  6045. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6046. "(%d):0311 Mailbox command x%x cannot "
  6047. "issue Data: x%x x%x\n",
  6048. pmbox->vport ? pmbox->vport->vpi : 0,
  6049. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6050. goto out_not_finished;
  6051. }
  6052. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  6053. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  6054. !(hc_copy & HC_MBINT_ENA)) {
  6055. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6056. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6057. "(%d):2528 Mailbox command x%x cannot "
  6058. "issue Data: x%x x%x\n",
  6059. pmbox->vport ? pmbox->vport->vpi : 0,
  6060. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6061. goto out_not_finished;
  6062. }
  6063. }
  6064. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6065. /* Polling for a mbox command when another one is already active
  6066. * is not allowed in SLI. Also, the driver must have established
  6067. * SLI2 mode to queue and process multiple mbox commands.
  6068. */
  6069. if (flag & MBX_POLL) {
  6070. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6071. /* Mbox command <mbxCommand> cannot issue */
  6072. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6073. "(%d):2529 Mailbox command x%x "
  6074. "cannot issue Data: x%x x%x\n",
  6075. pmbox->vport ? pmbox->vport->vpi : 0,
  6076. pmbox->u.mb.mbxCommand,
  6077. psli->sli_flag, flag);
  6078. goto out_not_finished;
  6079. }
  6080. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6081. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6082. /* Mbox command <mbxCommand> cannot issue */
  6083. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6084. "(%d):2530 Mailbox command x%x "
  6085. "cannot issue Data: x%x x%x\n",
  6086. pmbox->vport ? pmbox->vport->vpi : 0,
  6087. pmbox->u.mb.mbxCommand,
  6088. psli->sli_flag, flag);
  6089. goto out_not_finished;
  6090. }
  6091. /* Another mailbox command is still being processed, queue this
  6092. * command to be processed later.
  6093. */
  6094. lpfc_mbox_put(phba, pmbox);
  6095. /* Mbox cmd issue - BUSY */
  6096. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6097. "(%d):0308 Mbox cmd issue - BUSY Data: "
  6098. "x%x x%x x%x x%x\n",
  6099. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  6100. mb->mbxCommand, phba->pport->port_state,
  6101. psli->sli_flag, flag);
  6102. psli->slistat.mbox_busy++;
  6103. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6104. if (pmbox->vport) {
  6105. lpfc_debugfs_disc_trc(pmbox->vport,
  6106. LPFC_DISC_TRC_MBOX_VPORT,
  6107. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  6108. (uint32_t)mb->mbxCommand,
  6109. mb->un.varWords[0], mb->un.varWords[1]);
  6110. }
  6111. else {
  6112. lpfc_debugfs_disc_trc(phba->pport,
  6113. LPFC_DISC_TRC_MBOX,
  6114. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  6115. (uint32_t)mb->mbxCommand,
  6116. mb->un.varWords[0], mb->un.varWords[1]);
  6117. }
  6118. return MBX_BUSY;
  6119. }
  6120. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6121. /* If we are not polling, we MUST be in SLI2 mode */
  6122. if (flag != MBX_POLL) {
  6123. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  6124. (mb->mbxCommand != MBX_KILL_BOARD)) {
  6125. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6126. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6127. /* Mbox command <mbxCommand> cannot issue */
  6128. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6129. "(%d):2531 Mailbox command x%x "
  6130. "cannot issue Data: x%x x%x\n",
  6131. pmbox->vport ? pmbox->vport->vpi : 0,
  6132. pmbox->u.mb.mbxCommand,
  6133. psli->sli_flag, flag);
  6134. goto out_not_finished;
  6135. }
  6136. /* timeout active mbox command */
  6137. mod_timer(&psli->mbox_tmo, (jiffies +
  6138. (HZ * lpfc_mbox_tmo_val(phba, pmbox))));
  6139. }
  6140. /* Mailbox cmd <cmd> issue */
  6141. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6142. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  6143. "x%x\n",
  6144. pmbox->vport ? pmbox->vport->vpi : 0,
  6145. mb->mbxCommand, phba->pport->port_state,
  6146. psli->sli_flag, flag);
  6147. if (mb->mbxCommand != MBX_HEARTBEAT) {
  6148. if (pmbox->vport) {
  6149. lpfc_debugfs_disc_trc(pmbox->vport,
  6150. LPFC_DISC_TRC_MBOX_VPORT,
  6151. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6152. (uint32_t)mb->mbxCommand,
  6153. mb->un.varWords[0], mb->un.varWords[1]);
  6154. }
  6155. else {
  6156. lpfc_debugfs_disc_trc(phba->pport,
  6157. LPFC_DISC_TRC_MBOX,
  6158. "MBOX Send: cmd:x%x mb:x%x x%x",
  6159. (uint32_t)mb->mbxCommand,
  6160. mb->un.varWords[0], mb->un.varWords[1]);
  6161. }
  6162. }
  6163. psli->slistat.mbox_cmd++;
  6164. evtctr = psli->slistat.mbox_event;
  6165. /* next set own bit for the adapter and copy over command word */
  6166. mb->mbxOwner = OWN_CHIP;
  6167. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6168. /* Populate mbox extension offset word. */
  6169. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  6170. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  6171. = (uint8_t *)phba->mbox_ext
  6172. - (uint8_t *)phba->mbox;
  6173. }
  6174. /* Copy the mailbox extension data */
  6175. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6176. lpfc_sli_pcimem_bcopy(pmbox->context2,
  6177. (uint8_t *)phba->mbox_ext,
  6178. pmbox->in_ext_byte_len);
  6179. }
  6180. /* Copy command data to host SLIM area */
  6181. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  6182. } else {
  6183. /* Populate mbox extension offset word. */
  6184. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  6185. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  6186. = MAILBOX_HBA_EXT_OFFSET;
  6187. /* Copy the mailbox extension data */
  6188. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6189. lpfc_memcpy_to_slim(phba->MBslimaddr +
  6190. MAILBOX_HBA_EXT_OFFSET,
  6191. pmbox->context2, pmbox->in_ext_byte_len);
  6192. }
  6193. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6194. /* copy command data into host mbox for cmpl */
  6195. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  6196. }
  6197. /* First copy mbox command data to HBA SLIM, skip past first
  6198. word */
  6199. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6200. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  6201. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6202. /* Next copy over first word, with mbxOwner set */
  6203. ldata = *((uint32_t *)mb);
  6204. to_slim = phba->MBslimaddr;
  6205. writel(ldata, to_slim);
  6206. readl(to_slim); /* flush */
  6207. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6208. /* switch over to host mailbox */
  6209. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6210. }
  6211. }
  6212. wmb();
  6213. switch (flag) {
  6214. case MBX_NOWAIT:
  6215. /* Set up reference to mailbox command */
  6216. psli->mbox_active = pmbox;
  6217. /* Interrupt board to do it */
  6218. writel(CA_MBATT, phba->CAregaddr);
  6219. readl(phba->CAregaddr); /* flush */
  6220. /* Don't wait for it to finish, just return */
  6221. break;
  6222. case MBX_POLL:
  6223. /* Set up null reference to mailbox command */
  6224. psli->mbox_active = NULL;
  6225. /* Interrupt board to do it */
  6226. writel(CA_MBATT, phba->CAregaddr);
  6227. readl(phba->CAregaddr); /* flush */
  6228. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6229. /* First read mbox status word */
  6230. word0 = *((uint32_t *)phba->mbox);
  6231. word0 = le32_to_cpu(word0);
  6232. } else {
  6233. /* First read mbox status word */
  6234. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6235. spin_unlock_irqrestore(&phba->hbalock,
  6236. drvr_flag);
  6237. goto out_not_finished;
  6238. }
  6239. }
  6240. /* Read the HBA Host Attention Register */
  6241. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6242. spin_unlock_irqrestore(&phba->hbalock,
  6243. drvr_flag);
  6244. goto out_not_finished;
  6245. }
  6246. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6247. 1000) + jiffies;
  6248. i = 0;
  6249. /* Wait for command to complete */
  6250. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6251. (!(ha_copy & HA_MBATT) &&
  6252. (phba->link_state > LPFC_WARM_START))) {
  6253. if (time_after(jiffies, timeout)) {
  6254. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6255. spin_unlock_irqrestore(&phba->hbalock,
  6256. drvr_flag);
  6257. goto out_not_finished;
  6258. }
  6259. /* Check if we took a mbox interrupt while we were
  6260. polling */
  6261. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6262. && (evtctr != psli->slistat.mbox_event))
  6263. break;
  6264. if (i++ > 10) {
  6265. spin_unlock_irqrestore(&phba->hbalock,
  6266. drvr_flag);
  6267. msleep(1);
  6268. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6269. }
  6270. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6271. /* First copy command data */
  6272. word0 = *((uint32_t *)phba->mbox);
  6273. word0 = le32_to_cpu(word0);
  6274. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6275. MAILBOX_t *slimmb;
  6276. uint32_t slimword0;
  6277. /* Check real SLIM for any errors */
  6278. slimword0 = readl(phba->MBslimaddr);
  6279. slimmb = (MAILBOX_t *) & slimword0;
  6280. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6281. && slimmb->mbxStatus) {
  6282. psli->sli_flag &=
  6283. ~LPFC_SLI_ACTIVE;
  6284. word0 = slimword0;
  6285. }
  6286. }
  6287. } else {
  6288. /* First copy command data */
  6289. word0 = readl(phba->MBslimaddr);
  6290. }
  6291. /* Read the HBA Host Attention Register */
  6292. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6293. spin_unlock_irqrestore(&phba->hbalock,
  6294. drvr_flag);
  6295. goto out_not_finished;
  6296. }
  6297. }
  6298. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6299. /* copy results back to user */
  6300. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  6301. /* Copy the mailbox extension data */
  6302. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6303. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6304. pmbox->context2,
  6305. pmbox->out_ext_byte_len);
  6306. }
  6307. } else {
  6308. /* First copy command data */
  6309. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  6310. MAILBOX_CMD_SIZE);
  6311. /* Copy the mailbox extension data */
  6312. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6313. lpfc_memcpy_from_slim(pmbox->context2,
  6314. phba->MBslimaddr +
  6315. MAILBOX_HBA_EXT_OFFSET,
  6316. pmbox->out_ext_byte_len);
  6317. }
  6318. }
  6319. writel(HA_MBATT, phba->HAregaddr);
  6320. readl(phba->HAregaddr); /* flush */
  6321. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6322. status = mb->mbxStatus;
  6323. }
  6324. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6325. return status;
  6326. out_not_finished:
  6327. if (processing_queue) {
  6328. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6329. lpfc_mbox_cmpl_put(phba, pmbox);
  6330. }
  6331. return MBX_NOT_FINISHED;
  6332. }
  6333. /**
  6334. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6335. * @phba: Pointer to HBA context object.
  6336. *
  6337. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6338. * the driver internal pending mailbox queue. It will then try to wait out the
  6339. * possible outstanding mailbox command before return.
  6340. *
  6341. * Returns:
  6342. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6343. * the outstanding mailbox command timed out.
  6344. **/
  6345. static int
  6346. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6347. {
  6348. struct lpfc_sli *psli = &phba->sli;
  6349. int rc = 0;
  6350. unsigned long timeout = 0;
  6351. /* Mark the asynchronous mailbox command posting as blocked */
  6352. spin_lock_irq(&phba->hbalock);
  6353. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6354. /* Determine how long we might wait for the active mailbox
  6355. * command to be gracefully completed by firmware.
  6356. */
  6357. if (phba->sli.mbox_active)
  6358. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6359. phba->sli.mbox_active) *
  6360. 1000) + jiffies;
  6361. spin_unlock_irq(&phba->hbalock);
  6362. /* Wait for the outstnading mailbox command to complete */
  6363. while (phba->sli.mbox_active) {
  6364. /* Check active mailbox complete status every 2ms */
  6365. msleep(2);
  6366. if (time_after(jiffies, timeout)) {
  6367. /* Timeout, marked the outstanding cmd not complete */
  6368. rc = 1;
  6369. break;
  6370. }
  6371. }
  6372. /* Can not cleanly block async mailbox command, fails it */
  6373. if (rc) {
  6374. spin_lock_irq(&phba->hbalock);
  6375. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6376. spin_unlock_irq(&phba->hbalock);
  6377. }
  6378. return rc;
  6379. }
  6380. /**
  6381. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6382. * @phba: Pointer to HBA context object.
  6383. *
  6384. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6385. * commands from the driver internal pending mailbox queue. It makes sure
  6386. * that there is no outstanding mailbox command before resuming posting
  6387. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6388. * mailbox command, it will try to wait it out before resuming asynchronous
  6389. * mailbox command posting.
  6390. **/
  6391. static void
  6392. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6393. {
  6394. struct lpfc_sli *psli = &phba->sli;
  6395. spin_lock_irq(&phba->hbalock);
  6396. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6397. /* Asynchronous mailbox posting is not blocked, do nothing */
  6398. spin_unlock_irq(&phba->hbalock);
  6399. return;
  6400. }
  6401. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6402. * successful or timeout, after timing-out the outstanding mailbox
  6403. * command shall always be removed, so just unblock posting async
  6404. * mailbox command and resume
  6405. */
  6406. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6407. spin_unlock_irq(&phba->hbalock);
  6408. /* wake up worker thread to post asynchronlous mailbox command */
  6409. lpfc_worker_wake_up(phba);
  6410. }
  6411. /**
  6412. * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
  6413. * @phba: Pointer to HBA context object.
  6414. * @mboxq: Pointer to mailbox object.
  6415. *
  6416. * The function waits for the bootstrap mailbox register ready bit from
  6417. * port for twice the regular mailbox command timeout value.
  6418. *
  6419. * 0 - no timeout on waiting for bootstrap mailbox register ready.
  6420. * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
  6421. **/
  6422. static int
  6423. lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6424. {
  6425. uint32_t db_ready;
  6426. unsigned long timeout;
  6427. struct lpfc_register bmbx_reg;
  6428. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6429. * 1000) + jiffies;
  6430. do {
  6431. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6432. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6433. if (!db_ready)
  6434. msleep(2);
  6435. if (time_after(jiffies, timeout))
  6436. return MBXERR_ERROR;
  6437. } while (!db_ready);
  6438. return 0;
  6439. }
  6440. /**
  6441. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6442. * @phba: Pointer to HBA context object.
  6443. * @mboxq: Pointer to mailbox object.
  6444. *
  6445. * The function posts a mailbox to the port. The mailbox is expected
  6446. * to be comletely filled in and ready for the port to operate on it.
  6447. * This routine executes a synchronous completion operation on the
  6448. * mailbox by polling for its completion.
  6449. *
  6450. * The caller must not be holding any locks when calling this routine.
  6451. *
  6452. * Returns:
  6453. * MBX_SUCCESS - mailbox posted successfully
  6454. * Any of the MBX error values.
  6455. **/
  6456. static int
  6457. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6458. {
  6459. int rc = MBX_SUCCESS;
  6460. unsigned long iflag;
  6461. uint32_t mcqe_status;
  6462. uint32_t mbx_cmnd;
  6463. struct lpfc_sli *psli = &phba->sli;
  6464. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6465. struct lpfc_bmbx_create *mbox_rgn;
  6466. struct dma_address *dma_address;
  6467. /*
  6468. * Only one mailbox can be active to the bootstrap mailbox region
  6469. * at a time and there is no queueing provided.
  6470. */
  6471. spin_lock_irqsave(&phba->hbalock, iflag);
  6472. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6473. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6474. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6475. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6476. "cannot issue Data: x%x x%x\n",
  6477. mboxq->vport ? mboxq->vport->vpi : 0,
  6478. mboxq->u.mb.mbxCommand,
  6479. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6480. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6481. psli->sli_flag, MBX_POLL);
  6482. return MBXERR_ERROR;
  6483. }
  6484. /* The server grabs the token and owns it until release */
  6485. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6486. phba->sli.mbox_active = mboxq;
  6487. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6488. /* wait for bootstrap mbox register for readyness */
  6489. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6490. if (rc)
  6491. goto exit;
  6492. /*
  6493. * Initialize the bootstrap memory region to avoid stale data areas
  6494. * in the mailbox post. Then copy the caller's mailbox contents to
  6495. * the bmbx mailbox region.
  6496. */
  6497. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6498. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6499. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6500. sizeof(struct lpfc_mqe));
  6501. /* Post the high mailbox dma address to the port and wait for ready. */
  6502. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6503. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6504. /* wait for bootstrap mbox register for hi-address write done */
  6505. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6506. if (rc)
  6507. goto exit;
  6508. /* Post the low mailbox dma address to the port. */
  6509. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6510. /* wait for bootstrap mbox register for low address write done */
  6511. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6512. if (rc)
  6513. goto exit;
  6514. /*
  6515. * Read the CQ to ensure the mailbox has completed.
  6516. * If so, update the mailbox status so that the upper layers
  6517. * can complete the request normally.
  6518. */
  6519. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6520. sizeof(struct lpfc_mqe));
  6521. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6522. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6523. sizeof(struct lpfc_mcqe));
  6524. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6525. /*
  6526. * When the CQE status indicates a failure and the mailbox status
  6527. * indicates success then copy the CQE status into the mailbox status
  6528. * (and prefix it with x4000).
  6529. */
  6530. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6531. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6532. bf_set(lpfc_mqe_status, mb,
  6533. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6534. rc = MBXERR_ERROR;
  6535. } else
  6536. lpfc_sli4_swap_str(phba, mboxq);
  6537. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6538. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6539. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6540. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6541. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6542. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6543. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6544. bf_get(lpfc_mqe_status, mb),
  6545. mb->un.mb_words[0], mb->un.mb_words[1],
  6546. mb->un.mb_words[2], mb->un.mb_words[3],
  6547. mb->un.mb_words[4], mb->un.mb_words[5],
  6548. mb->un.mb_words[6], mb->un.mb_words[7],
  6549. mb->un.mb_words[8], mb->un.mb_words[9],
  6550. mb->un.mb_words[10], mb->un.mb_words[11],
  6551. mb->un.mb_words[12], mboxq->mcqe.word0,
  6552. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6553. mboxq->mcqe.trailer);
  6554. exit:
  6555. /* We are holding the token, no needed for lock when release */
  6556. spin_lock_irqsave(&phba->hbalock, iflag);
  6557. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6558. phba->sli.mbox_active = NULL;
  6559. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6560. return rc;
  6561. }
  6562. /**
  6563. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6564. * @phba: Pointer to HBA context object.
  6565. * @pmbox: Pointer to mailbox object.
  6566. * @flag: Flag indicating how the mailbox need to be processed.
  6567. *
  6568. * This function is called by discovery code and HBA management code to submit
  6569. * a mailbox command to firmware with SLI-4 interface spec.
  6570. *
  6571. * Return codes the caller owns the mailbox command after the return of the
  6572. * function.
  6573. **/
  6574. static int
  6575. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6576. uint32_t flag)
  6577. {
  6578. struct lpfc_sli *psli = &phba->sli;
  6579. unsigned long iflags;
  6580. int rc;
  6581. /* dump from issue mailbox command if setup */
  6582. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6583. rc = lpfc_mbox_dev_check(phba);
  6584. if (unlikely(rc)) {
  6585. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6586. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6587. "cannot issue Data: x%x x%x\n",
  6588. mboxq->vport ? mboxq->vport->vpi : 0,
  6589. mboxq->u.mb.mbxCommand,
  6590. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6591. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6592. psli->sli_flag, flag);
  6593. goto out_not_finished;
  6594. }
  6595. /* Detect polling mode and jump to a handler */
  6596. if (!phba->sli4_hba.intr_enable) {
  6597. if (flag == MBX_POLL)
  6598. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6599. else
  6600. rc = -EIO;
  6601. if (rc != MBX_SUCCESS)
  6602. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6603. "(%d):2541 Mailbox command x%x "
  6604. "(x%x/x%x) failure: "
  6605. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6606. "Data: x%x x%x\n,",
  6607. mboxq->vport ? mboxq->vport->vpi : 0,
  6608. mboxq->u.mb.mbxCommand,
  6609. lpfc_sli_config_mbox_subsys_get(phba,
  6610. mboxq),
  6611. lpfc_sli_config_mbox_opcode_get(phba,
  6612. mboxq),
  6613. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6614. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6615. bf_get(lpfc_mcqe_ext_status,
  6616. &mboxq->mcqe),
  6617. psli->sli_flag, flag);
  6618. return rc;
  6619. } else if (flag == MBX_POLL) {
  6620. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6621. "(%d):2542 Try to issue mailbox command "
  6622. "x%x (x%x/x%x) synchronously ahead of async"
  6623. "mailbox command queue: x%x x%x\n",
  6624. mboxq->vport ? mboxq->vport->vpi : 0,
  6625. mboxq->u.mb.mbxCommand,
  6626. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6627. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6628. psli->sli_flag, flag);
  6629. /* Try to block the asynchronous mailbox posting */
  6630. rc = lpfc_sli4_async_mbox_block(phba);
  6631. if (!rc) {
  6632. /* Successfully blocked, now issue sync mbox cmd */
  6633. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6634. if (rc != MBX_SUCCESS)
  6635. lpfc_printf_log(phba, KERN_WARNING,
  6636. LOG_MBOX | LOG_SLI,
  6637. "(%d):2597 Sync Mailbox command "
  6638. "x%x (x%x/x%x) failure: "
  6639. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6640. "Data: x%x x%x\n,",
  6641. mboxq->vport ? mboxq->vport->vpi : 0,
  6642. mboxq->u.mb.mbxCommand,
  6643. lpfc_sli_config_mbox_subsys_get(phba,
  6644. mboxq),
  6645. lpfc_sli_config_mbox_opcode_get(phba,
  6646. mboxq),
  6647. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6648. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6649. bf_get(lpfc_mcqe_ext_status,
  6650. &mboxq->mcqe),
  6651. psli->sli_flag, flag);
  6652. /* Unblock the async mailbox posting afterward */
  6653. lpfc_sli4_async_mbox_unblock(phba);
  6654. }
  6655. return rc;
  6656. }
  6657. /* Now, interrupt mode asynchrous mailbox command */
  6658. rc = lpfc_mbox_cmd_check(phba, mboxq);
  6659. if (rc) {
  6660. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6661. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  6662. "cannot issue Data: x%x x%x\n",
  6663. mboxq->vport ? mboxq->vport->vpi : 0,
  6664. mboxq->u.mb.mbxCommand,
  6665. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6666. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6667. psli->sli_flag, flag);
  6668. goto out_not_finished;
  6669. }
  6670. /* Put the mailbox command to the driver internal FIFO */
  6671. psli->slistat.mbox_busy++;
  6672. spin_lock_irqsave(&phba->hbalock, iflags);
  6673. lpfc_mbox_put(phba, mboxq);
  6674. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6675. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6676. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  6677. "x%x (x%x/x%x) x%x x%x x%x\n",
  6678. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  6679. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  6680. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6681. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6682. phba->pport->port_state,
  6683. psli->sli_flag, MBX_NOWAIT);
  6684. /* Wake up worker thread to transport mailbox command from head */
  6685. lpfc_worker_wake_up(phba);
  6686. return MBX_BUSY;
  6687. out_not_finished:
  6688. return MBX_NOT_FINISHED;
  6689. }
  6690. /**
  6691. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  6692. * @phba: Pointer to HBA context object.
  6693. *
  6694. * This function is called by worker thread to send a mailbox command to
  6695. * SLI4 HBA firmware.
  6696. *
  6697. **/
  6698. int
  6699. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  6700. {
  6701. struct lpfc_sli *psli = &phba->sli;
  6702. LPFC_MBOXQ_t *mboxq;
  6703. int rc = MBX_SUCCESS;
  6704. unsigned long iflags;
  6705. struct lpfc_mqe *mqe;
  6706. uint32_t mbx_cmnd;
  6707. /* Check interrupt mode before post async mailbox command */
  6708. if (unlikely(!phba->sli4_hba.intr_enable))
  6709. return MBX_NOT_FINISHED;
  6710. /* Check for mailbox command service token */
  6711. spin_lock_irqsave(&phba->hbalock, iflags);
  6712. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6713. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6714. return MBX_NOT_FINISHED;
  6715. }
  6716. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6717. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6718. return MBX_NOT_FINISHED;
  6719. }
  6720. if (unlikely(phba->sli.mbox_active)) {
  6721. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6722. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6723. "0384 There is pending active mailbox cmd\n");
  6724. return MBX_NOT_FINISHED;
  6725. }
  6726. /* Take the mailbox command service token */
  6727. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6728. /* Get the next mailbox command from head of queue */
  6729. mboxq = lpfc_mbox_get(phba);
  6730. /* If no more mailbox command waiting for post, we're done */
  6731. if (!mboxq) {
  6732. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6733. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6734. return MBX_SUCCESS;
  6735. }
  6736. phba->sli.mbox_active = mboxq;
  6737. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6738. /* Check device readiness for posting mailbox command */
  6739. rc = lpfc_mbox_dev_check(phba);
  6740. if (unlikely(rc))
  6741. /* Driver clean routine will clean up pending mailbox */
  6742. goto out_not_finished;
  6743. /* Prepare the mbox command to be posted */
  6744. mqe = &mboxq->u.mqe;
  6745. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  6746. /* Start timer for the mbox_tmo and log some mailbox post messages */
  6747. mod_timer(&psli->mbox_tmo, (jiffies +
  6748. (HZ * lpfc_mbox_tmo_val(phba, mboxq))));
  6749. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6750. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  6751. "x%x x%x\n",
  6752. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6753. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6754. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6755. phba->pport->port_state, psli->sli_flag);
  6756. if (mbx_cmnd != MBX_HEARTBEAT) {
  6757. if (mboxq->vport) {
  6758. lpfc_debugfs_disc_trc(mboxq->vport,
  6759. LPFC_DISC_TRC_MBOX_VPORT,
  6760. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6761. mbx_cmnd, mqe->un.mb_words[0],
  6762. mqe->un.mb_words[1]);
  6763. } else {
  6764. lpfc_debugfs_disc_trc(phba->pport,
  6765. LPFC_DISC_TRC_MBOX,
  6766. "MBOX Send: cmd:x%x mb:x%x x%x",
  6767. mbx_cmnd, mqe->un.mb_words[0],
  6768. mqe->un.mb_words[1]);
  6769. }
  6770. }
  6771. psli->slistat.mbox_cmd++;
  6772. /* Post the mailbox command to the port */
  6773. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  6774. if (rc != MBX_SUCCESS) {
  6775. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6776. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  6777. "cannot issue Data: x%x x%x\n",
  6778. mboxq->vport ? mboxq->vport->vpi : 0,
  6779. mboxq->u.mb.mbxCommand,
  6780. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6781. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6782. psli->sli_flag, MBX_NOWAIT);
  6783. goto out_not_finished;
  6784. }
  6785. return rc;
  6786. out_not_finished:
  6787. spin_lock_irqsave(&phba->hbalock, iflags);
  6788. if (phba->sli.mbox_active) {
  6789. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6790. __lpfc_mbox_cmpl_put(phba, mboxq);
  6791. /* Release the token */
  6792. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6793. phba->sli.mbox_active = NULL;
  6794. }
  6795. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6796. return MBX_NOT_FINISHED;
  6797. }
  6798. /**
  6799. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  6800. * @phba: Pointer to HBA context object.
  6801. * @pmbox: Pointer to mailbox object.
  6802. * @flag: Flag indicating how the mailbox need to be processed.
  6803. *
  6804. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  6805. * the API jump table function pointer from the lpfc_hba struct.
  6806. *
  6807. * Return codes the caller owns the mailbox command after the return of the
  6808. * function.
  6809. **/
  6810. int
  6811. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  6812. {
  6813. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  6814. }
  6815. /**
  6816. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  6817. * @phba: The hba struct for which this call is being executed.
  6818. * @dev_grp: The HBA PCI-Device group number.
  6819. *
  6820. * This routine sets up the mbox interface API function jump table in @phba
  6821. * struct.
  6822. * Returns: 0 - success, -ENODEV - failure.
  6823. **/
  6824. int
  6825. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6826. {
  6827. switch (dev_grp) {
  6828. case LPFC_PCI_DEV_LP:
  6829. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  6830. phba->lpfc_sli_handle_slow_ring_event =
  6831. lpfc_sli_handle_slow_ring_event_s3;
  6832. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  6833. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  6834. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  6835. break;
  6836. case LPFC_PCI_DEV_OC:
  6837. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  6838. phba->lpfc_sli_handle_slow_ring_event =
  6839. lpfc_sli_handle_slow_ring_event_s4;
  6840. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  6841. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  6842. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  6843. break;
  6844. default:
  6845. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6846. "1420 Invalid HBA PCI-device group: 0x%x\n",
  6847. dev_grp);
  6848. return -ENODEV;
  6849. break;
  6850. }
  6851. return 0;
  6852. }
  6853. /**
  6854. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  6855. * @phba: Pointer to HBA context object.
  6856. * @pring: Pointer to driver SLI ring object.
  6857. * @piocb: Pointer to address of newly added command iocb.
  6858. *
  6859. * This function is called with hbalock held to add a command
  6860. * iocb to the txq when SLI layer cannot submit the command iocb
  6861. * to the ring.
  6862. **/
  6863. void
  6864. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6865. struct lpfc_iocbq *piocb)
  6866. {
  6867. /* Insert the caller's iocb in the txq tail for later processing. */
  6868. list_add_tail(&piocb->list, &pring->txq);
  6869. pring->txq_cnt++;
  6870. }
  6871. /**
  6872. * lpfc_sli_next_iocb - Get the next iocb in the txq
  6873. * @phba: Pointer to HBA context object.
  6874. * @pring: Pointer to driver SLI ring object.
  6875. * @piocb: Pointer to address of newly added command iocb.
  6876. *
  6877. * This function is called with hbalock held before a new
  6878. * iocb is submitted to the firmware. This function checks
  6879. * txq to flush the iocbs in txq to Firmware before
  6880. * submitting new iocbs to the Firmware.
  6881. * If there are iocbs in the txq which need to be submitted
  6882. * to firmware, lpfc_sli_next_iocb returns the first element
  6883. * of the txq after dequeuing it from txq.
  6884. * If there is no iocb in the txq then the function will return
  6885. * *piocb and *piocb is set to NULL. Caller needs to check
  6886. * *piocb to find if there are more commands in the txq.
  6887. **/
  6888. static struct lpfc_iocbq *
  6889. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6890. struct lpfc_iocbq **piocb)
  6891. {
  6892. struct lpfc_iocbq * nextiocb;
  6893. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  6894. if (!nextiocb) {
  6895. nextiocb = *piocb;
  6896. *piocb = NULL;
  6897. }
  6898. return nextiocb;
  6899. }
  6900. /**
  6901. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  6902. * @phba: Pointer to HBA context object.
  6903. * @ring_number: SLI ring number to issue iocb on.
  6904. * @piocb: Pointer to command iocb.
  6905. * @flag: Flag indicating if this command can be put into txq.
  6906. *
  6907. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  6908. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  6909. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  6910. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  6911. * this function allows only iocbs for posting buffers. This function finds
  6912. * next available slot in the command ring and posts the command to the
  6913. * available slot and writes the port attention register to request HBA start
  6914. * processing new iocb. If there is no slot available in the ring and
  6915. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  6916. * the function returns IOCB_BUSY.
  6917. *
  6918. * This function is called with hbalock held. The function will return success
  6919. * after it successfully submit the iocb to firmware or after adding to the
  6920. * txq.
  6921. **/
  6922. static int
  6923. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  6924. struct lpfc_iocbq *piocb, uint32_t flag)
  6925. {
  6926. struct lpfc_iocbq *nextiocb;
  6927. IOCB_t *iocb;
  6928. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6929. if (piocb->iocb_cmpl && (!piocb->vport) &&
  6930. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  6931. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  6932. lpfc_printf_log(phba, KERN_ERR,
  6933. LOG_SLI | LOG_VPORT,
  6934. "1807 IOCB x%x failed. No vport\n",
  6935. piocb->iocb.ulpCommand);
  6936. dump_stack();
  6937. return IOCB_ERROR;
  6938. }
  6939. /* If the PCI channel is in offline state, do not post iocbs. */
  6940. if (unlikely(pci_channel_offline(phba->pcidev)))
  6941. return IOCB_ERROR;
  6942. /* If HBA has a deferred error attention, fail the iocb. */
  6943. if (unlikely(phba->hba_flag & DEFER_ERATT))
  6944. return IOCB_ERROR;
  6945. /*
  6946. * We should never get an IOCB if we are in a < LINK_DOWN state
  6947. */
  6948. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  6949. return IOCB_ERROR;
  6950. /*
  6951. * Check to see if we are blocking IOCB processing because of a
  6952. * outstanding event.
  6953. */
  6954. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  6955. goto iocb_busy;
  6956. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  6957. /*
  6958. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  6959. * can be issued if the link is not up.
  6960. */
  6961. switch (piocb->iocb.ulpCommand) {
  6962. case CMD_GEN_REQUEST64_CR:
  6963. case CMD_GEN_REQUEST64_CX:
  6964. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  6965. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  6966. FC_RCTL_DD_UNSOL_CMD) ||
  6967. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  6968. MENLO_TRANSPORT_TYPE))
  6969. goto iocb_busy;
  6970. break;
  6971. case CMD_QUE_RING_BUF_CN:
  6972. case CMD_QUE_RING_BUF64_CN:
  6973. /*
  6974. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  6975. * completion, iocb_cmpl MUST be 0.
  6976. */
  6977. if (piocb->iocb_cmpl)
  6978. piocb->iocb_cmpl = NULL;
  6979. /*FALLTHROUGH*/
  6980. case CMD_CREATE_XRI_CR:
  6981. case CMD_CLOSE_XRI_CN:
  6982. case CMD_CLOSE_XRI_CX:
  6983. break;
  6984. default:
  6985. goto iocb_busy;
  6986. }
  6987. /*
  6988. * For FCP commands, we must be in a state where we can process link
  6989. * attention events.
  6990. */
  6991. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  6992. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  6993. goto iocb_busy;
  6994. }
  6995. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  6996. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  6997. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  6998. if (iocb)
  6999. lpfc_sli_update_ring(phba, pring);
  7000. else
  7001. lpfc_sli_update_full_ring(phba, pring);
  7002. if (!piocb)
  7003. return IOCB_SUCCESS;
  7004. goto out_busy;
  7005. iocb_busy:
  7006. pring->stats.iocb_cmd_delay++;
  7007. out_busy:
  7008. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7009. __lpfc_sli_ringtx_put(phba, pring, piocb);
  7010. return IOCB_SUCCESS;
  7011. }
  7012. return IOCB_BUSY;
  7013. }
  7014. /**
  7015. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  7016. * @phba: Pointer to HBA context object.
  7017. * @piocb: Pointer to command iocb.
  7018. * @sglq: Pointer to the scatter gather queue object.
  7019. *
  7020. * This routine converts the bpl or bde that is in the IOCB
  7021. * to a sgl list for the sli4 hardware. The physical address
  7022. * of the bpl/bde is converted back to a virtual address.
  7023. * If the IOCB contains a BPL then the list of BDE's is
  7024. * converted to sli4_sge's. If the IOCB contains a single
  7025. * BDE then it is converted to a single sli_sge.
  7026. * The IOCB is still in cpu endianess so the contents of
  7027. * the bpl can be used without byte swapping.
  7028. *
  7029. * Returns valid XRI = Success, NO_XRI = Failure.
  7030. **/
  7031. static uint16_t
  7032. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  7033. struct lpfc_sglq *sglq)
  7034. {
  7035. uint16_t xritag = NO_XRI;
  7036. struct ulp_bde64 *bpl = NULL;
  7037. struct ulp_bde64 bde;
  7038. struct sli4_sge *sgl = NULL;
  7039. struct lpfc_dmabuf *dmabuf;
  7040. IOCB_t *icmd;
  7041. int numBdes = 0;
  7042. int i = 0;
  7043. uint32_t offset = 0; /* accumulated offset in the sg request list */
  7044. int inbound = 0; /* number of sg reply entries inbound from firmware */
  7045. if (!piocbq || !sglq)
  7046. return xritag;
  7047. sgl = (struct sli4_sge *)sglq->sgl;
  7048. icmd = &piocbq->iocb;
  7049. if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  7050. return sglq->sli4_xritag;
  7051. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7052. numBdes = icmd->un.genreq64.bdl.bdeSize /
  7053. sizeof(struct ulp_bde64);
  7054. /* The addrHigh and addrLow fields within the IOCB
  7055. * have not been byteswapped yet so there is no
  7056. * need to swap them back.
  7057. */
  7058. if (piocbq->context3)
  7059. dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
  7060. else
  7061. return xritag;
  7062. bpl = (struct ulp_bde64 *)dmabuf->virt;
  7063. if (!bpl)
  7064. return xritag;
  7065. for (i = 0; i < numBdes; i++) {
  7066. /* Should already be byte swapped. */
  7067. sgl->addr_hi = bpl->addrHigh;
  7068. sgl->addr_lo = bpl->addrLow;
  7069. sgl->word2 = le32_to_cpu(sgl->word2);
  7070. if ((i+1) == numBdes)
  7071. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7072. else
  7073. bf_set(lpfc_sli4_sge_last, sgl, 0);
  7074. /* swap the size field back to the cpu so we
  7075. * can assign it to the sgl.
  7076. */
  7077. bde.tus.w = le32_to_cpu(bpl->tus.w);
  7078. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  7079. /* The offsets in the sgl need to be accumulated
  7080. * separately for the request and reply lists.
  7081. * The request is always first, the reply follows.
  7082. */
  7083. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  7084. /* add up the reply sg entries */
  7085. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  7086. inbound++;
  7087. /* first inbound? reset the offset */
  7088. if (inbound == 1)
  7089. offset = 0;
  7090. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  7091. bf_set(lpfc_sli4_sge_type, sgl,
  7092. LPFC_SGE_TYPE_DATA);
  7093. offset += bde.tus.f.bdeSize;
  7094. }
  7095. sgl->word2 = cpu_to_le32(sgl->word2);
  7096. bpl++;
  7097. sgl++;
  7098. }
  7099. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  7100. /* The addrHigh and addrLow fields of the BDE have not
  7101. * been byteswapped yet so they need to be swapped
  7102. * before putting them in the sgl.
  7103. */
  7104. sgl->addr_hi =
  7105. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  7106. sgl->addr_lo =
  7107. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  7108. sgl->word2 = le32_to_cpu(sgl->word2);
  7109. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7110. sgl->word2 = cpu_to_le32(sgl->word2);
  7111. sgl->sge_len =
  7112. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  7113. }
  7114. return sglq->sli4_xritag;
  7115. }
  7116. /**
  7117. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  7118. * @phba: Pointer to HBA context object.
  7119. *
  7120. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  7121. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  7122. * held.
  7123. *
  7124. * Return: index into SLI4 fast-path FCP queue index.
  7125. **/
  7126. static inline uint32_t
  7127. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  7128. {
  7129. int i;
  7130. if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU)
  7131. i = smp_processor_id();
  7132. else
  7133. i = atomic_add_return(1, &phba->fcp_qidx);
  7134. i = (i % phba->cfg_fcp_io_channel);
  7135. return i;
  7136. }
  7137. /**
  7138. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  7139. * @phba: Pointer to HBA context object.
  7140. * @piocb: Pointer to command iocb.
  7141. * @wqe: Pointer to the work queue entry.
  7142. *
  7143. * This routine converts the iocb command to its Work Queue Entry
  7144. * equivalent. The wqe pointer should not have any fields set when
  7145. * this routine is called because it will memcpy over them.
  7146. * This routine does not set the CQ_ID or the WQEC bits in the
  7147. * wqe.
  7148. *
  7149. * Returns: 0 = Success, IOCB_ERROR = Failure.
  7150. **/
  7151. static int
  7152. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  7153. union lpfc_wqe *wqe)
  7154. {
  7155. uint32_t xmit_len = 0, total_len = 0;
  7156. uint8_t ct = 0;
  7157. uint32_t fip;
  7158. uint32_t abort_tag;
  7159. uint8_t command_type = ELS_COMMAND_NON_FIP;
  7160. uint8_t cmnd;
  7161. uint16_t xritag;
  7162. uint16_t abrt_iotag;
  7163. struct lpfc_iocbq *abrtiocbq;
  7164. struct ulp_bde64 *bpl = NULL;
  7165. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  7166. int numBdes, i;
  7167. struct ulp_bde64 bde;
  7168. struct lpfc_nodelist *ndlp;
  7169. uint32_t *pcmd;
  7170. uint32_t if_type;
  7171. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  7172. /* The fcp commands will set command type */
  7173. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7174. command_type = FCP_COMMAND;
  7175. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  7176. command_type = ELS_COMMAND_FIP;
  7177. else
  7178. command_type = ELS_COMMAND_NON_FIP;
  7179. /* Some of the fields are in the right position already */
  7180. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  7181. abort_tag = (uint32_t) iocbq->iotag;
  7182. xritag = iocbq->sli4_xritag;
  7183. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  7184. /* words0-2 bpl convert bde */
  7185. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7186. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7187. sizeof(struct ulp_bde64);
  7188. bpl = (struct ulp_bde64 *)
  7189. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  7190. if (!bpl)
  7191. return IOCB_ERROR;
  7192. /* Should already be byte swapped. */
  7193. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  7194. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  7195. /* swap the size field back to the cpu so we
  7196. * can assign it to the sgl.
  7197. */
  7198. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  7199. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  7200. total_len = 0;
  7201. for (i = 0; i < numBdes; i++) {
  7202. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7203. total_len += bde.tus.f.bdeSize;
  7204. }
  7205. } else
  7206. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  7207. iocbq->iocb.ulpIoTag = iocbq->iotag;
  7208. cmnd = iocbq->iocb.ulpCommand;
  7209. switch (iocbq->iocb.ulpCommand) {
  7210. case CMD_ELS_REQUEST64_CR:
  7211. if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
  7212. ndlp = iocbq->context_un.ndlp;
  7213. else
  7214. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7215. if (!iocbq->iocb.ulpLe) {
  7216. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7217. "2007 Only Limited Edition cmd Format"
  7218. " supported 0x%x\n",
  7219. iocbq->iocb.ulpCommand);
  7220. return IOCB_ERROR;
  7221. }
  7222. wqe->els_req.payload_len = xmit_len;
  7223. /* Els_reguest64 has a TMO */
  7224. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  7225. iocbq->iocb.ulpTimeout);
  7226. /* Need a VF for word 4 set the vf bit*/
  7227. bf_set(els_req64_vf, &wqe->els_req, 0);
  7228. /* And a VFID for word 12 */
  7229. bf_set(els_req64_vfid, &wqe->els_req, 0);
  7230. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7231. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7232. iocbq->iocb.ulpContext);
  7233. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  7234. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  7235. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7236. if (command_type == ELS_COMMAND_FIP)
  7237. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7238. >> LPFC_FIP_ELS_ID_SHIFT);
  7239. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7240. iocbq->context2)->virt);
  7241. if_type = bf_get(lpfc_sli_intf_if_type,
  7242. &phba->sli4_hba.sli_intf);
  7243. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7244. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7245. *pcmd == ELS_CMD_SCR ||
  7246. *pcmd == ELS_CMD_FDISC ||
  7247. *pcmd == ELS_CMD_LOGO ||
  7248. *pcmd == ELS_CMD_PLOGI)) {
  7249. bf_set(els_req64_sp, &wqe->els_req, 1);
  7250. bf_set(els_req64_sid, &wqe->els_req,
  7251. iocbq->vport->fc_myDID);
  7252. if ((*pcmd == ELS_CMD_FLOGI) &&
  7253. !(phba->fc_topology ==
  7254. LPFC_TOPOLOGY_LOOP))
  7255. bf_set(els_req64_sid, &wqe->els_req, 0);
  7256. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7257. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7258. phba->vpi_ids[iocbq->vport->vpi]);
  7259. } else if (pcmd && iocbq->context1) {
  7260. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7261. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7262. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7263. }
  7264. }
  7265. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7266. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7267. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7268. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7269. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7270. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7271. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7272. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7273. break;
  7274. case CMD_XMIT_SEQUENCE64_CX:
  7275. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7276. iocbq->iocb.un.ulpWord[3]);
  7277. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7278. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7279. /* The entire sequence is transmitted for this IOCB */
  7280. xmit_len = total_len;
  7281. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7282. if (phba->link_flag & LS_LOOPBACK_MODE)
  7283. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  7284. case CMD_XMIT_SEQUENCE64_CR:
  7285. /* word3 iocb=io_tag32 wqe=reserved */
  7286. wqe->xmit_sequence.rsvd3 = 0;
  7287. /* word4 relative_offset memcpy */
  7288. /* word5 r_ctl/df_ctl memcpy */
  7289. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7290. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7291. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7292. LPFC_WQE_IOD_WRITE);
  7293. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7294. LPFC_WQE_LENLOC_WORD12);
  7295. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7296. wqe->xmit_sequence.xmit_len = xmit_len;
  7297. command_type = OTHER_COMMAND;
  7298. break;
  7299. case CMD_XMIT_BCAST64_CN:
  7300. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7301. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7302. /* word4 iocb=rsvd wqe=rsvd */
  7303. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7304. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7305. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7306. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7307. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7308. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7309. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7310. LPFC_WQE_LENLOC_WORD3);
  7311. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7312. break;
  7313. case CMD_FCP_IWRITE64_CR:
  7314. command_type = FCP_COMMAND_DATA_OUT;
  7315. /* word3 iocb=iotag wqe=payload_offset_len */
  7316. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7317. wqe->fcp_iwrite.payload_offset_len =
  7318. xmit_len + sizeof(struct fcp_rsp);
  7319. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7320. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7321. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7322. iocbq->iocb.ulpFCP2Rcvy);
  7323. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7324. /* Always open the exchange */
  7325. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  7326. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7327. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7328. LPFC_WQE_LENLOC_WORD4);
  7329. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  7330. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7331. if (iocbq->iocb_flag & LPFC_IO_DIF) {
  7332. iocbq->iocb_flag &= ~LPFC_IO_DIF;
  7333. bf_set(wqe_dif, &wqe->generic.wqe_com, 1);
  7334. }
  7335. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7336. break;
  7337. case CMD_FCP_IREAD64_CR:
  7338. /* word3 iocb=iotag wqe=payload_offset_len */
  7339. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7340. wqe->fcp_iread.payload_offset_len =
  7341. xmit_len + sizeof(struct fcp_rsp);
  7342. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7343. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7344. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7345. iocbq->iocb.ulpFCP2Rcvy);
  7346. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7347. /* Always open the exchange */
  7348. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  7349. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7350. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7351. LPFC_WQE_LENLOC_WORD4);
  7352. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  7353. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7354. if (iocbq->iocb_flag & LPFC_IO_DIF) {
  7355. iocbq->iocb_flag &= ~LPFC_IO_DIF;
  7356. bf_set(wqe_dif, &wqe->generic.wqe_com, 1);
  7357. }
  7358. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7359. break;
  7360. case CMD_FCP_ICMND64_CR:
  7361. /* word3 iocb=IO_TAG wqe=reserved */
  7362. wqe->fcp_icmd.rsrvd3 = 0;
  7363. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7364. /* Always open the exchange */
  7365. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  7366. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7367. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7368. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7369. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7370. LPFC_WQE_LENLOC_NONE);
  7371. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  7372. break;
  7373. case CMD_GEN_REQUEST64_CR:
  7374. /* For this command calculate the xmit length of the
  7375. * request bde.
  7376. */
  7377. xmit_len = 0;
  7378. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7379. sizeof(struct ulp_bde64);
  7380. for (i = 0; i < numBdes; i++) {
  7381. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7382. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7383. break;
  7384. xmit_len += bde.tus.f.bdeSize;
  7385. }
  7386. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7387. wqe->gen_req.request_payload_len = xmit_len;
  7388. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7389. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7390. /* word6 context tag copied in memcpy */
  7391. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7392. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7393. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7394. "2015 Invalid CT %x command 0x%x\n",
  7395. ct, iocbq->iocb.ulpCommand);
  7396. return IOCB_ERROR;
  7397. }
  7398. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7399. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7400. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7401. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7402. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7403. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7404. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7405. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7406. command_type = OTHER_COMMAND;
  7407. break;
  7408. case CMD_XMIT_ELS_RSP64_CX:
  7409. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7410. /* words0-2 BDE memcpy */
  7411. /* word3 iocb=iotag32 wqe=response_payload_len */
  7412. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7413. /* word4 */
  7414. wqe->xmit_els_rsp.word4 = 0;
  7415. /* word5 iocb=rsvd wge=did */
  7416. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7417. iocbq->iocb.un.xseq64.xmit_els_remoteID);
  7418. if_type = bf_get(lpfc_sli_intf_if_type,
  7419. &phba->sli4_hba.sli_intf);
  7420. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7421. if (iocbq->vport->fc_flag & FC_PT2PT) {
  7422. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7423. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7424. iocbq->vport->fc_myDID);
  7425. if (iocbq->vport->fc_myDID == Fabric_DID) {
  7426. bf_set(wqe_els_did,
  7427. &wqe->xmit_els_rsp.wqe_dest, 0);
  7428. }
  7429. }
  7430. }
  7431. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7432. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7433. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7434. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7435. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7436. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7437. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7438. phba->vpi_ids[iocbq->vport->vpi]);
  7439. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7440. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7441. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7442. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7443. LPFC_WQE_LENLOC_WORD3);
  7444. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7445. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7446. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7447. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7448. iocbq->context2)->virt);
  7449. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7450. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7451. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7452. iocbq->vport->fc_myDID);
  7453. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
  7454. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7455. phba->vpi_ids[phba->pport->vpi]);
  7456. }
  7457. command_type = OTHER_COMMAND;
  7458. break;
  7459. case CMD_CLOSE_XRI_CN:
  7460. case CMD_ABORT_XRI_CN:
  7461. case CMD_ABORT_XRI_CX:
  7462. /* words 0-2 memcpy should be 0 rserved */
  7463. /* port will send abts */
  7464. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7465. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7466. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7467. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7468. } else
  7469. fip = 0;
  7470. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7471. /*
  7472. * The link is down, or the command was ELS_FIP
  7473. * so the fw does not need to send abts
  7474. * on the wire.
  7475. */
  7476. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7477. else
  7478. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7479. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7480. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7481. wqe->abort_cmd.rsrvd5 = 0;
  7482. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7483. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7484. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7485. /*
  7486. * The abort handler will send us CMD_ABORT_XRI_CN or
  7487. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7488. */
  7489. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7490. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7491. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7492. LPFC_WQE_LENLOC_NONE);
  7493. cmnd = CMD_ABORT_XRI_CX;
  7494. command_type = OTHER_COMMAND;
  7495. xritag = 0;
  7496. break;
  7497. case CMD_XMIT_BLS_RSP64_CX:
  7498. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7499. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7500. * we re-construct this WQE here based on information in
  7501. * iocbq from scratch.
  7502. */
  7503. memset(wqe, 0, sizeof(union lpfc_wqe));
  7504. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7505. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7506. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7507. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7508. LPFC_ABTS_UNSOL_INT) {
  7509. /* ABTS sent by initiator to CT exchange, the
  7510. * RX_ID field will be filled with the newly
  7511. * allocated responder XRI.
  7512. */
  7513. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7514. iocbq->sli4_xritag);
  7515. } else {
  7516. /* ABTS sent by responder to CT exchange, the
  7517. * RX_ID field will be filled with the responder
  7518. * RX_ID from ABTS.
  7519. */
  7520. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7521. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7522. }
  7523. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7524. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7525. /* Use CT=VPI */
  7526. bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
  7527. ndlp->nlp_DID);
  7528. bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
  7529. iocbq->iocb.ulpContext);
  7530. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  7531. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7532. phba->vpi_ids[phba->pport->vpi]);
  7533. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7534. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7535. LPFC_WQE_LENLOC_NONE);
  7536. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7537. command_type = OTHER_COMMAND;
  7538. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7539. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7540. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7541. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7542. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7543. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7544. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7545. }
  7546. break;
  7547. case CMD_XRI_ABORTED_CX:
  7548. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7549. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7550. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7551. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7552. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7553. default:
  7554. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7555. "2014 Invalid command 0x%x\n",
  7556. iocbq->iocb.ulpCommand);
  7557. return IOCB_ERROR;
  7558. break;
  7559. }
  7560. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7561. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7562. wqe->generic.wqe_com.abort_tag = abort_tag;
  7563. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  7564. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  7565. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  7566. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  7567. return 0;
  7568. }
  7569. /**
  7570. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  7571. * @phba: Pointer to HBA context object.
  7572. * @ring_number: SLI ring number to issue iocb on.
  7573. * @piocb: Pointer to command iocb.
  7574. * @flag: Flag indicating if this command can be put into txq.
  7575. *
  7576. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  7577. * an iocb command to an HBA with SLI-4 interface spec.
  7578. *
  7579. * This function is called with hbalock held. The function will return success
  7580. * after it successfully submit the iocb to firmware or after adding to the
  7581. * txq.
  7582. **/
  7583. static int
  7584. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  7585. struct lpfc_iocbq *piocb, uint32_t flag)
  7586. {
  7587. struct lpfc_sglq *sglq;
  7588. union lpfc_wqe wqe;
  7589. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7590. if (piocb->sli4_xritag == NO_XRI) {
  7591. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  7592. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  7593. sglq = NULL;
  7594. else {
  7595. if (pring->txq_cnt) {
  7596. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7597. __lpfc_sli_ringtx_put(phba,
  7598. pring, piocb);
  7599. return IOCB_SUCCESS;
  7600. } else {
  7601. return IOCB_BUSY;
  7602. }
  7603. } else {
  7604. sglq = __lpfc_sli_get_sglq(phba, piocb);
  7605. if (!sglq) {
  7606. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7607. __lpfc_sli_ringtx_put(phba,
  7608. pring,
  7609. piocb);
  7610. return IOCB_SUCCESS;
  7611. } else
  7612. return IOCB_BUSY;
  7613. }
  7614. }
  7615. }
  7616. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  7617. /* These IO's already have an XRI and a mapped sgl. */
  7618. sglq = NULL;
  7619. } else {
  7620. /*
  7621. * This is a continuation of a commandi,(CX) so this
  7622. * sglq is on the active list
  7623. */
  7624. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  7625. if (!sglq)
  7626. return IOCB_ERROR;
  7627. }
  7628. if (sglq) {
  7629. piocb->sli4_lxritag = sglq->sli4_lxritag;
  7630. piocb->sli4_xritag = sglq->sli4_xritag;
  7631. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  7632. return IOCB_ERROR;
  7633. }
  7634. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  7635. return IOCB_ERROR;
  7636. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  7637. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  7638. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  7639. &wqe))
  7640. return IOCB_ERROR;
  7641. } else {
  7642. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  7643. return IOCB_ERROR;
  7644. }
  7645. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  7646. return 0;
  7647. }
  7648. /**
  7649. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  7650. *
  7651. * This routine wraps the actual lockless version for issusing IOCB function
  7652. * pointer from the lpfc_hba struct.
  7653. *
  7654. * Return codes:
  7655. * IOCB_ERROR - Error
  7656. * IOCB_SUCCESS - Success
  7657. * IOCB_BUSY - Busy
  7658. **/
  7659. int
  7660. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7661. struct lpfc_iocbq *piocb, uint32_t flag)
  7662. {
  7663. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7664. }
  7665. /**
  7666. * lpfc_sli_api_table_setup - Set up sli api function jump table
  7667. * @phba: The hba struct for which this call is being executed.
  7668. * @dev_grp: The HBA PCI-Device group number.
  7669. *
  7670. * This routine sets up the SLI interface API function jump table in @phba
  7671. * struct.
  7672. * Returns: 0 - success, -ENODEV - failure.
  7673. **/
  7674. int
  7675. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7676. {
  7677. switch (dev_grp) {
  7678. case LPFC_PCI_DEV_LP:
  7679. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  7680. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  7681. break;
  7682. case LPFC_PCI_DEV_OC:
  7683. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  7684. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  7685. break;
  7686. default:
  7687. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7688. "1419 Invalid HBA PCI-device group: 0x%x\n",
  7689. dev_grp);
  7690. return -ENODEV;
  7691. break;
  7692. }
  7693. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  7694. return 0;
  7695. }
  7696. /**
  7697. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  7698. * @phba: Pointer to HBA context object.
  7699. * @pring: Pointer to driver SLI ring object.
  7700. * @piocb: Pointer to command iocb.
  7701. * @flag: Flag indicating if this command can be put into txq.
  7702. *
  7703. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  7704. * function. This function gets the hbalock and calls
  7705. * __lpfc_sli_issue_iocb function and will return the error returned
  7706. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  7707. * functions which do not hold hbalock.
  7708. **/
  7709. int
  7710. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7711. struct lpfc_iocbq *piocb, uint32_t flag)
  7712. {
  7713. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  7714. struct lpfc_sli_ring *pring;
  7715. struct lpfc_queue *fpeq;
  7716. struct lpfc_eqe *eqe;
  7717. unsigned long iflags;
  7718. int rc, idx;
  7719. if (phba->sli_rev == LPFC_SLI_REV4) {
  7720. if (piocb->iocb_flag & LPFC_IO_FCP) {
  7721. if (unlikely(!phba->sli4_hba.fcp_wq))
  7722. return IOCB_ERROR;
  7723. idx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  7724. piocb->fcp_wqidx = idx;
  7725. ring_number = MAX_SLI3_CONFIGURED_RINGS + idx;
  7726. pring = &phba->sli.ring[ring_number];
  7727. spin_lock_irqsave(&pring->ring_lock, iflags);
  7728. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7729. flag);
  7730. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  7731. if (lpfc_fcp_look_ahead) {
  7732. fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx];
  7733. if (atomic_dec_and_test(&fcp_eq_hdl->
  7734. fcp_eq_in_use)) {
  7735. /* Get associated EQ with this index */
  7736. fpeq = phba->sli4_hba.hba_eq[idx];
  7737. /* Turn off interrupts from this EQ */
  7738. lpfc_sli4_eq_clr_intr(fpeq);
  7739. /*
  7740. * Process all the events on FCP EQ
  7741. */
  7742. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  7743. lpfc_sli4_hba_handle_eqe(phba,
  7744. eqe, idx);
  7745. fpeq->EQ_processed++;
  7746. }
  7747. /* Always clear and re-arm the EQ */
  7748. lpfc_sli4_eq_release(fpeq,
  7749. LPFC_QUEUE_REARM);
  7750. }
  7751. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  7752. }
  7753. } else {
  7754. pring = &phba->sli.ring[ring_number];
  7755. spin_lock_irqsave(&pring->ring_lock, iflags);
  7756. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7757. flag);
  7758. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  7759. }
  7760. } else {
  7761. /* For now, SLI2/3 will still use hbalock */
  7762. spin_lock_irqsave(&phba->hbalock, iflags);
  7763. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7764. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7765. }
  7766. return rc;
  7767. }
  7768. /**
  7769. * lpfc_extra_ring_setup - Extra ring setup function
  7770. * @phba: Pointer to HBA context object.
  7771. *
  7772. * This function is called while driver attaches with the
  7773. * HBA to setup the extra ring. The extra ring is used
  7774. * only when driver needs to support target mode functionality
  7775. * or IP over FC functionalities.
  7776. *
  7777. * This function is called with no lock held.
  7778. **/
  7779. static int
  7780. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  7781. {
  7782. struct lpfc_sli *psli;
  7783. struct lpfc_sli_ring *pring;
  7784. psli = &phba->sli;
  7785. /* Adjust cmd/rsp ring iocb entries more evenly */
  7786. /* Take some away from the FCP ring */
  7787. pring = &psli->ring[psli->fcp_ring];
  7788. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7789. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7790. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7791. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7792. /* and give them to the extra ring */
  7793. pring = &psli->ring[psli->extra_ring];
  7794. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7795. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7796. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7797. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7798. /* Setup default profile for this ring */
  7799. pring->iotag_max = 4096;
  7800. pring->num_mask = 1;
  7801. pring->prt[0].profile = 0; /* Mask 0 */
  7802. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  7803. pring->prt[0].type = phba->cfg_multi_ring_type;
  7804. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  7805. return 0;
  7806. }
  7807. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  7808. * @phba: Pointer to HBA context object.
  7809. * @iocbq: Pointer to iocb object.
  7810. *
  7811. * The async_event handler calls this routine when it receives
  7812. * an ASYNC_STATUS_CN event from the port. The port generates
  7813. * this event when an Abort Sequence request to an rport fails
  7814. * twice in succession. The abort could be originated by the
  7815. * driver or by the port. The ABTS could have been for an ELS
  7816. * or FCP IO. The port only generates this event when an ABTS
  7817. * fails to complete after one retry.
  7818. */
  7819. static void
  7820. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  7821. struct lpfc_iocbq *iocbq)
  7822. {
  7823. struct lpfc_nodelist *ndlp = NULL;
  7824. uint16_t rpi = 0, vpi = 0;
  7825. struct lpfc_vport *vport = NULL;
  7826. /* The rpi in the ulpContext is vport-sensitive. */
  7827. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  7828. rpi = iocbq->iocb.ulpContext;
  7829. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7830. "3092 Port generated ABTS async event "
  7831. "on vpi %d rpi %d status 0x%x\n",
  7832. vpi, rpi, iocbq->iocb.ulpStatus);
  7833. vport = lpfc_find_vport_by_vpid(phba, vpi);
  7834. if (!vport)
  7835. goto err_exit;
  7836. ndlp = lpfc_findnode_rpi(vport, rpi);
  7837. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  7838. goto err_exit;
  7839. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  7840. lpfc_sli_abts_recover_port(vport, ndlp);
  7841. return;
  7842. err_exit:
  7843. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7844. "3095 Event Context not found, no "
  7845. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  7846. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  7847. vpi, rpi);
  7848. }
  7849. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  7850. * @phba: pointer to HBA context object.
  7851. * @ndlp: nodelist pointer for the impacted rport.
  7852. * @axri: pointer to the wcqe containing the failed exchange.
  7853. *
  7854. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  7855. * port. The port generates this event when an abort exchange request to an
  7856. * rport fails twice in succession with no reply. The abort could be originated
  7857. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  7858. */
  7859. void
  7860. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  7861. struct lpfc_nodelist *ndlp,
  7862. struct sli4_wcqe_xri_aborted *axri)
  7863. {
  7864. struct lpfc_vport *vport;
  7865. uint32_t ext_status = 0;
  7866. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  7867. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7868. "3115 Node Context not found, driver "
  7869. "ignoring abts err event\n");
  7870. return;
  7871. }
  7872. vport = ndlp->vport;
  7873. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7874. "3116 Port generated FCP XRI ABORT event on "
  7875. "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
  7876. ndlp->vport->vpi, ndlp->nlp_rpi,
  7877. bf_get(lpfc_wcqe_xa_xri, axri),
  7878. bf_get(lpfc_wcqe_xa_status, axri),
  7879. axri->parameter);
  7880. /*
  7881. * Catch the ABTS protocol failure case. Older OCe FW releases returned
  7882. * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
  7883. * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
  7884. */
  7885. ext_status = axri->parameter & IOERR_PARAM_MASK;
  7886. if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
  7887. ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
  7888. lpfc_sli_abts_recover_port(vport, ndlp);
  7889. }
  7890. /**
  7891. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  7892. * @phba: Pointer to HBA context object.
  7893. * @pring: Pointer to driver SLI ring object.
  7894. * @iocbq: Pointer to iocb object.
  7895. *
  7896. * This function is called by the slow ring event handler
  7897. * function when there is an ASYNC event iocb in the ring.
  7898. * This function is called with no lock held.
  7899. * Currently this function handles only temperature related
  7900. * ASYNC events. The function decodes the temperature sensor
  7901. * event message and posts events for the management applications.
  7902. **/
  7903. static void
  7904. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  7905. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  7906. {
  7907. IOCB_t *icmd;
  7908. uint16_t evt_code;
  7909. struct temp_event temp_event_data;
  7910. struct Scsi_Host *shost;
  7911. uint32_t *iocb_w;
  7912. icmd = &iocbq->iocb;
  7913. evt_code = icmd->un.asyncstat.evt_code;
  7914. switch (evt_code) {
  7915. case ASYNC_TEMP_WARN:
  7916. case ASYNC_TEMP_SAFE:
  7917. temp_event_data.data = (uint32_t) icmd->ulpContext;
  7918. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  7919. if (evt_code == ASYNC_TEMP_WARN) {
  7920. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  7921. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7922. "0347 Adapter is very hot, please take "
  7923. "corrective action. temperature : %d Celsius\n",
  7924. (uint32_t) icmd->ulpContext);
  7925. } else {
  7926. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  7927. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7928. "0340 Adapter temperature is OK now. "
  7929. "temperature : %d Celsius\n",
  7930. (uint32_t) icmd->ulpContext);
  7931. }
  7932. /* Send temperature change event to applications */
  7933. shost = lpfc_shost_from_vport(phba->pport);
  7934. fc_host_post_vendor_event(shost, fc_get_event_number(),
  7935. sizeof(temp_event_data), (char *) &temp_event_data,
  7936. LPFC_NL_VENDOR_ID);
  7937. break;
  7938. case ASYNC_STATUS_CN:
  7939. lpfc_sli_abts_err_handler(phba, iocbq);
  7940. break;
  7941. default:
  7942. iocb_w = (uint32_t *) icmd;
  7943. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7944. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  7945. " evt_code 0x%x\n"
  7946. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  7947. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  7948. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  7949. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  7950. pring->ringno, icmd->un.asyncstat.evt_code,
  7951. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  7952. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  7953. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  7954. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  7955. break;
  7956. }
  7957. }
  7958. /**
  7959. * lpfc_sli_setup - SLI ring setup function
  7960. * @phba: Pointer to HBA context object.
  7961. *
  7962. * lpfc_sli_setup sets up rings of the SLI interface with
  7963. * number of iocbs per ring and iotags. This function is
  7964. * called while driver attach to the HBA and before the
  7965. * interrupts are enabled. So there is no need for locking.
  7966. *
  7967. * This function always returns 0.
  7968. **/
  7969. int
  7970. lpfc_sli_setup(struct lpfc_hba *phba)
  7971. {
  7972. int i, totiocbsize = 0;
  7973. struct lpfc_sli *psli = &phba->sli;
  7974. struct lpfc_sli_ring *pring;
  7975. psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
  7976. if (phba->sli_rev == LPFC_SLI_REV4)
  7977. psli->num_rings += phba->cfg_fcp_io_channel;
  7978. psli->sli_flag = 0;
  7979. psli->fcp_ring = LPFC_FCP_RING;
  7980. psli->next_ring = LPFC_FCP_NEXT_RING;
  7981. psli->extra_ring = LPFC_EXTRA_RING;
  7982. psli->iocbq_lookup = NULL;
  7983. psli->iocbq_lookup_len = 0;
  7984. psli->last_iotag = 0;
  7985. for (i = 0; i < psli->num_rings; i++) {
  7986. pring = &psli->ring[i];
  7987. switch (i) {
  7988. case LPFC_FCP_RING: /* ring 0 - FCP */
  7989. /* numCiocb and numRiocb are used in config_port */
  7990. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  7991. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  7992. pring->sli.sli3.numCiocb +=
  7993. SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7994. pring->sli.sli3.numRiocb +=
  7995. SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7996. pring->sli.sli3.numCiocb +=
  7997. SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7998. pring->sli.sli3.numRiocb +=
  7999. SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8000. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8001. SLI3_IOCB_CMD_SIZE :
  8002. SLI2_IOCB_CMD_SIZE;
  8003. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8004. SLI3_IOCB_RSP_SIZE :
  8005. SLI2_IOCB_RSP_SIZE;
  8006. pring->iotag_ctr = 0;
  8007. pring->iotag_max =
  8008. (phba->cfg_hba_queue_depth * 2);
  8009. pring->fast_iotag = pring->iotag_max;
  8010. pring->num_mask = 0;
  8011. break;
  8012. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  8013. /* numCiocb and numRiocb are used in config_port */
  8014. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  8015. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  8016. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8017. SLI3_IOCB_CMD_SIZE :
  8018. SLI2_IOCB_CMD_SIZE;
  8019. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8020. SLI3_IOCB_RSP_SIZE :
  8021. SLI2_IOCB_RSP_SIZE;
  8022. pring->iotag_max = phba->cfg_hba_queue_depth;
  8023. pring->num_mask = 0;
  8024. break;
  8025. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  8026. /* numCiocb and numRiocb are used in config_port */
  8027. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  8028. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  8029. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8030. SLI3_IOCB_CMD_SIZE :
  8031. SLI2_IOCB_CMD_SIZE;
  8032. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8033. SLI3_IOCB_RSP_SIZE :
  8034. SLI2_IOCB_RSP_SIZE;
  8035. pring->fast_iotag = 0;
  8036. pring->iotag_ctr = 0;
  8037. pring->iotag_max = 4096;
  8038. pring->lpfc_sli_rcv_async_status =
  8039. lpfc_sli_async_event_handler;
  8040. pring->num_mask = LPFC_MAX_RING_MASK;
  8041. pring->prt[0].profile = 0; /* Mask 0 */
  8042. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  8043. pring->prt[0].type = FC_TYPE_ELS;
  8044. pring->prt[0].lpfc_sli_rcv_unsol_event =
  8045. lpfc_els_unsol_event;
  8046. pring->prt[1].profile = 0; /* Mask 1 */
  8047. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  8048. pring->prt[1].type = FC_TYPE_ELS;
  8049. pring->prt[1].lpfc_sli_rcv_unsol_event =
  8050. lpfc_els_unsol_event;
  8051. pring->prt[2].profile = 0; /* Mask 2 */
  8052. /* NameServer Inquiry */
  8053. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  8054. /* NameServer */
  8055. pring->prt[2].type = FC_TYPE_CT;
  8056. pring->prt[2].lpfc_sli_rcv_unsol_event =
  8057. lpfc_ct_unsol_event;
  8058. pring->prt[3].profile = 0; /* Mask 3 */
  8059. /* NameServer response */
  8060. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  8061. /* NameServer */
  8062. pring->prt[3].type = FC_TYPE_CT;
  8063. pring->prt[3].lpfc_sli_rcv_unsol_event =
  8064. lpfc_ct_unsol_event;
  8065. /* abort unsolicited sequence */
  8066. pring->prt[4].profile = 0; /* Mask 4 */
  8067. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  8068. pring->prt[4].type = FC_TYPE_BLS;
  8069. pring->prt[4].lpfc_sli_rcv_unsol_event =
  8070. lpfc_sli4_ct_abort_unsol_event;
  8071. break;
  8072. }
  8073. totiocbsize += (pring->sli.sli3.numCiocb *
  8074. pring->sli.sli3.sizeCiocb) +
  8075. (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
  8076. }
  8077. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  8078. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  8079. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  8080. "SLI2 SLIM Data: x%x x%lx\n",
  8081. phba->brd_no, totiocbsize,
  8082. (unsigned long) MAX_SLIM_IOCB_SIZE);
  8083. }
  8084. if (phba->cfg_multi_ring_support == 2)
  8085. lpfc_extra_ring_setup(phba);
  8086. return 0;
  8087. }
  8088. /**
  8089. * lpfc_sli_queue_setup - Queue initialization function
  8090. * @phba: Pointer to HBA context object.
  8091. *
  8092. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  8093. * ring. This function also initializes ring indices of each ring.
  8094. * This function is called during the initialization of the SLI
  8095. * interface of an HBA.
  8096. * This function is called with no lock held and always returns
  8097. * 1.
  8098. **/
  8099. int
  8100. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  8101. {
  8102. struct lpfc_sli *psli;
  8103. struct lpfc_sli_ring *pring;
  8104. int i;
  8105. psli = &phba->sli;
  8106. spin_lock_irq(&phba->hbalock);
  8107. INIT_LIST_HEAD(&psli->mboxq);
  8108. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  8109. /* Initialize list headers for txq and txcmplq as double linked lists */
  8110. for (i = 0; i < psli->num_rings; i++) {
  8111. pring = &psli->ring[i];
  8112. pring->ringno = i;
  8113. pring->sli.sli3.next_cmdidx = 0;
  8114. pring->sli.sli3.local_getidx = 0;
  8115. pring->sli.sli3.cmdidx = 0;
  8116. INIT_LIST_HEAD(&pring->txq);
  8117. INIT_LIST_HEAD(&pring->txcmplq);
  8118. INIT_LIST_HEAD(&pring->iocb_continueq);
  8119. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  8120. INIT_LIST_HEAD(&pring->postbufq);
  8121. spin_lock_init(&pring->ring_lock);
  8122. }
  8123. spin_unlock_irq(&phba->hbalock);
  8124. return 1;
  8125. }
  8126. /**
  8127. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  8128. * @phba: Pointer to HBA context object.
  8129. *
  8130. * This routine flushes the mailbox command subsystem. It will unconditionally
  8131. * flush all the mailbox commands in the three possible stages in the mailbox
  8132. * command sub-system: pending mailbox command queue; the outstanding mailbox
  8133. * command; and completed mailbox command queue. It is caller's responsibility
  8134. * to make sure that the driver is in the proper state to flush the mailbox
  8135. * command sub-system. Namely, the posting of mailbox commands into the
  8136. * pending mailbox command queue from the various clients must be stopped;
  8137. * either the HBA is in a state that it will never works on the outstanding
  8138. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  8139. * mailbox command has been completed.
  8140. **/
  8141. static void
  8142. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  8143. {
  8144. LIST_HEAD(completions);
  8145. struct lpfc_sli *psli = &phba->sli;
  8146. LPFC_MBOXQ_t *pmb;
  8147. unsigned long iflag;
  8148. /* Flush all the mailbox commands in the mbox system */
  8149. spin_lock_irqsave(&phba->hbalock, iflag);
  8150. /* The pending mailbox command queue */
  8151. list_splice_init(&phba->sli.mboxq, &completions);
  8152. /* The outstanding active mailbox command */
  8153. if (psli->mbox_active) {
  8154. list_add_tail(&psli->mbox_active->list, &completions);
  8155. psli->mbox_active = NULL;
  8156. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8157. }
  8158. /* The completed mailbox command queue */
  8159. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  8160. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8161. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  8162. while (!list_empty(&completions)) {
  8163. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  8164. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8165. if (pmb->mbox_cmpl)
  8166. pmb->mbox_cmpl(phba, pmb);
  8167. }
  8168. }
  8169. /**
  8170. * lpfc_sli_host_down - Vport cleanup function
  8171. * @vport: Pointer to virtual port object.
  8172. *
  8173. * lpfc_sli_host_down is called to clean up the resources
  8174. * associated with a vport before destroying virtual
  8175. * port data structures.
  8176. * This function does following operations:
  8177. * - Free discovery resources associated with this virtual
  8178. * port.
  8179. * - Free iocbs associated with this virtual port in
  8180. * the txq.
  8181. * - Send abort for all iocb commands associated with this
  8182. * vport in txcmplq.
  8183. *
  8184. * This function is called with no lock held and always returns 1.
  8185. **/
  8186. int
  8187. lpfc_sli_host_down(struct lpfc_vport *vport)
  8188. {
  8189. LIST_HEAD(completions);
  8190. struct lpfc_hba *phba = vport->phba;
  8191. struct lpfc_sli *psli = &phba->sli;
  8192. struct lpfc_sli_ring *pring;
  8193. struct lpfc_iocbq *iocb, *next_iocb;
  8194. int i;
  8195. unsigned long flags = 0;
  8196. uint16_t prev_pring_flag;
  8197. lpfc_cleanup_discovery_resources(vport);
  8198. spin_lock_irqsave(&phba->hbalock, flags);
  8199. for (i = 0; i < psli->num_rings; i++) {
  8200. pring = &psli->ring[i];
  8201. prev_pring_flag = pring->flag;
  8202. /* Only slow rings */
  8203. if (pring->ringno == LPFC_ELS_RING) {
  8204. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8205. /* Set the lpfc data pending flag */
  8206. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8207. }
  8208. /*
  8209. * Error everything on the txq since these iocbs have not been
  8210. * given to the FW yet.
  8211. */
  8212. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  8213. if (iocb->vport != vport)
  8214. continue;
  8215. list_move_tail(&iocb->list, &completions);
  8216. pring->txq_cnt--;
  8217. }
  8218. /* Next issue ABTS for everything on the txcmplq */
  8219. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  8220. list) {
  8221. if (iocb->vport != vport)
  8222. continue;
  8223. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  8224. }
  8225. pring->flag = prev_pring_flag;
  8226. }
  8227. spin_unlock_irqrestore(&phba->hbalock, flags);
  8228. /* Cancel all the IOCBs from the completions list */
  8229. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8230. IOERR_SLI_DOWN);
  8231. return 1;
  8232. }
  8233. /**
  8234. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  8235. * @phba: Pointer to HBA context object.
  8236. *
  8237. * This function cleans up all iocb, buffers, mailbox commands
  8238. * while shutting down the HBA. This function is called with no
  8239. * lock held and always returns 1.
  8240. * This function does the following to cleanup driver resources:
  8241. * - Free discovery resources for each virtual port
  8242. * - Cleanup any pending fabric iocbs
  8243. * - Iterate through the iocb txq and free each entry
  8244. * in the list.
  8245. * - Free up any buffer posted to the HBA
  8246. * - Free mailbox commands in the mailbox queue.
  8247. **/
  8248. int
  8249. lpfc_sli_hba_down(struct lpfc_hba *phba)
  8250. {
  8251. LIST_HEAD(completions);
  8252. struct lpfc_sli *psli = &phba->sli;
  8253. struct lpfc_sli_ring *pring;
  8254. struct lpfc_dmabuf *buf_ptr;
  8255. unsigned long flags = 0;
  8256. int i;
  8257. /* Shutdown the mailbox command sub-system */
  8258. lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
  8259. lpfc_hba_down_prep(phba);
  8260. lpfc_fabric_abort_hba(phba);
  8261. spin_lock_irqsave(&phba->hbalock, flags);
  8262. for (i = 0; i < psli->num_rings; i++) {
  8263. pring = &psli->ring[i];
  8264. /* Only slow rings */
  8265. if (pring->ringno == LPFC_ELS_RING) {
  8266. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8267. /* Set the lpfc data pending flag */
  8268. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8269. }
  8270. /*
  8271. * Error everything on the txq since these iocbs have not been
  8272. * given to the FW yet.
  8273. */
  8274. list_splice_init(&pring->txq, &completions);
  8275. pring->txq_cnt = 0;
  8276. }
  8277. spin_unlock_irqrestore(&phba->hbalock, flags);
  8278. /* Cancel all the IOCBs from the completions list */
  8279. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8280. IOERR_SLI_DOWN);
  8281. spin_lock_irqsave(&phba->hbalock, flags);
  8282. list_splice_init(&phba->elsbuf, &completions);
  8283. phba->elsbuf_cnt = 0;
  8284. phba->elsbuf_prev_cnt = 0;
  8285. spin_unlock_irqrestore(&phba->hbalock, flags);
  8286. while (!list_empty(&completions)) {
  8287. list_remove_head(&completions, buf_ptr,
  8288. struct lpfc_dmabuf, list);
  8289. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8290. kfree(buf_ptr);
  8291. }
  8292. /* Return any active mbox cmds */
  8293. del_timer_sync(&psli->mbox_tmo);
  8294. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8295. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8296. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8297. return 1;
  8298. }
  8299. /**
  8300. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8301. * @srcp: Source memory pointer.
  8302. * @destp: Destination memory pointer.
  8303. * @cnt: Number of words required to be copied.
  8304. *
  8305. * This function is used for copying data between driver memory
  8306. * and the SLI memory. This function also changes the endianness
  8307. * of each word if native endianness is different from SLI
  8308. * endianness. This function can be called with or without
  8309. * lock.
  8310. **/
  8311. void
  8312. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8313. {
  8314. uint32_t *src = srcp;
  8315. uint32_t *dest = destp;
  8316. uint32_t ldata;
  8317. int i;
  8318. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8319. ldata = *src;
  8320. ldata = le32_to_cpu(ldata);
  8321. *dest = ldata;
  8322. src++;
  8323. dest++;
  8324. }
  8325. }
  8326. /**
  8327. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8328. * @srcp: Source memory pointer.
  8329. * @destp: Destination memory pointer.
  8330. * @cnt: Number of words required to be copied.
  8331. *
  8332. * This function is used for copying data between a data structure
  8333. * with big endian representation to local endianness.
  8334. * This function can be called with or without lock.
  8335. **/
  8336. void
  8337. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8338. {
  8339. uint32_t *src = srcp;
  8340. uint32_t *dest = destp;
  8341. uint32_t ldata;
  8342. int i;
  8343. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8344. ldata = *src;
  8345. ldata = be32_to_cpu(ldata);
  8346. *dest = ldata;
  8347. src++;
  8348. dest++;
  8349. }
  8350. }
  8351. /**
  8352. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8353. * @phba: Pointer to HBA context object.
  8354. * @pring: Pointer to driver SLI ring object.
  8355. * @mp: Pointer to driver buffer object.
  8356. *
  8357. * This function is called with no lock held.
  8358. * It always return zero after adding the buffer to the postbufq
  8359. * buffer list.
  8360. **/
  8361. int
  8362. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8363. struct lpfc_dmabuf *mp)
  8364. {
  8365. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8366. later */
  8367. spin_lock_irq(&phba->hbalock);
  8368. list_add_tail(&mp->list, &pring->postbufq);
  8369. pring->postbufq_cnt++;
  8370. spin_unlock_irq(&phba->hbalock);
  8371. return 0;
  8372. }
  8373. /**
  8374. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8375. * @phba: Pointer to HBA context object.
  8376. *
  8377. * When HBQ is enabled, buffers are searched based on tags. This function
  8378. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8379. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8380. * does not conflict with tags of buffer posted for unsolicited events.
  8381. * The function returns the allocated tag. The function is called with
  8382. * no locks held.
  8383. **/
  8384. uint32_t
  8385. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8386. {
  8387. spin_lock_irq(&phba->hbalock);
  8388. phba->buffer_tag_count++;
  8389. /*
  8390. * Always set the QUE_BUFTAG_BIT to distiguish between
  8391. * a tag assigned by HBQ.
  8392. */
  8393. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8394. spin_unlock_irq(&phba->hbalock);
  8395. return phba->buffer_tag_count;
  8396. }
  8397. /**
  8398. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8399. * @phba: Pointer to HBA context object.
  8400. * @pring: Pointer to driver SLI ring object.
  8401. * @tag: Buffer tag.
  8402. *
  8403. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8404. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8405. * iocb is posted to the response ring with the tag of the buffer.
  8406. * This function searches the pring->postbufq list using the tag
  8407. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8408. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8409. * buffer is returned to the caller else NULL is returned.
  8410. * This function is called with no lock held.
  8411. **/
  8412. struct lpfc_dmabuf *
  8413. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8414. uint32_t tag)
  8415. {
  8416. struct lpfc_dmabuf *mp, *next_mp;
  8417. struct list_head *slp = &pring->postbufq;
  8418. /* Search postbufq, from the beginning, looking for a match on tag */
  8419. spin_lock_irq(&phba->hbalock);
  8420. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8421. if (mp->buffer_tag == tag) {
  8422. list_del_init(&mp->list);
  8423. pring->postbufq_cnt--;
  8424. spin_unlock_irq(&phba->hbalock);
  8425. return mp;
  8426. }
  8427. }
  8428. spin_unlock_irq(&phba->hbalock);
  8429. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8430. "0402 Cannot find virtual addr for buffer tag on "
  8431. "ring %d Data x%lx x%p x%p x%x\n",
  8432. pring->ringno, (unsigned long) tag,
  8433. slp->next, slp->prev, pring->postbufq_cnt);
  8434. return NULL;
  8435. }
  8436. /**
  8437. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8438. * @phba: Pointer to HBA context object.
  8439. * @pring: Pointer to driver SLI ring object.
  8440. * @phys: DMA address of the buffer.
  8441. *
  8442. * This function searches the buffer list using the dma_address
  8443. * of unsolicited event to find the driver's lpfc_dmabuf object
  8444. * corresponding to the dma_address. The function returns the
  8445. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8446. * This function is called by the ct and els unsolicited event
  8447. * handlers to get the buffer associated with the unsolicited
  8448. * event.
  8449. *
  8450. * This function is called with no lock held.
  8451. **/
  8452. struct lpfc_dmabuf *
  8453. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8454. dma_addr_t phys)
  8455. {
  8456. struct lpfc_dmabuf *mp, *next_mp;
  8457. struct list_head *slp = &pring->postbufq;
  8458. /* Search postbufq, from the beginning, looking for a match on phys */
  8459. spin_lock_irq(&phba->hbalock);
  8460. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8461. if (mp->phys == phys) {
  8462. list_del_init(&mp->list);
  8463. pring->postbufq_cnt--;
  8464. spin_unlock_irq(&phba->hbalock);
  8465. return mp;
  8466. }
  8467. }
  8468. spin_unlock_irq(&phba->hbalock);
  8469. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8470. "0410 Cannot find virtual addr for mapped buf on "
  8471. "ring %d Data x%llx x%p x%p x%x\n",
  8472. pring->ringno, (unsigned long long)phys,
  8473. slp->next, slp->prev, pring->postbufq_cnt);
  8474. return NULL;
  8475. }
  8476. /**
  8477. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8478. * @phba: Pointer to HBA context object.
  8479. * @cmdiocb: Pointer to driver command iocb object.
  8480. * @rspiocb: Pointer to driver response iocb object.
  8481. *
  8482. * This function is the completion handler for the abort iocbs for
  8483. * ELS commands. This function is called from the ELS ring event
  8484. * handler with no lock held. This function frees memory resources
  8485. * associated with the abort iocb.
  8486. **/
  8487. static void
  8488. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8489. struct lpfc_iocbq *rspiocb)
  8490. {
  8491. IOCB_t *irsp = &rspiocb->iocb;
  8492. uint16_t abort_iotag, abort_context;
  8493. struct lpfc_iocbq *abort_iocb = NULL;
  8494. if (irsp->ulpStatus) {
  8495. /*
  8496. * Assume that the port already completed and returned, or
  8497. * will return the iocb. Just Log the message.
  8498. */
  8499. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8500. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8501. spin_lock_irq(&phba->hbalock);
  8502. if (phba->sli_rev < LPFC_SLI_REV4) {
  8503. if (abort_iotag != 0 &&
  8504. abort_iotag <= phba->sli.last_iotag)
  8505. abort_iocb =
  8506. phba->sli.iocbq_lookup[abort_iotag];
  8507. } else
  8508. /* For sli4 the abort_tag is the XRI,
  8509. * so the abort routine puts the iotag of the iocb
  8510. * being aborted in the context field of the abort
  8511. * IOCB.
  8512. */
  8513. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8514. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8515. "0327 Cannot abort els iocb %p "
  8516. "with tag %x context %x, abort status %x, "
  8517. "abort code %x\n",
  8518. abort_iocb, abort_iotag, abort_context,
  8519. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8520. spin_unlock_irq(&phba->hbalock);
  8521. }
  8522. lpfc_sli_release_iocbq(phba, cmdiocb);
  8523. return;
  8524. }
  8525. /**
  8526. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  8527. * @phba: Pointer to HBA context object.
  8528. * @cmdiocb: Pointer to driver command iocb object.
  8529. * @rspiocb: Pointer to driver response iocb object.
  8530. *
  8531. * The function is called from SLI ring event handler with no
  8532. * lock held. This function is the completion handler for ELS commands
  8533. * which are aborted. The function frees memory resources used for
  8534. * the aborted ELS commands.
  8535. **/
  8536. static void
  8537. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8538. struct lpfc_iocbq *rspiocb)
  8539. {
  8540. IOCB_t *irsp = &rspiocb->iocb;
  8541. /* ELS cmd tag <ulpIoTag> completes */
  8542. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8543. "0139 Ignoring ELS cmd tag x%x completion Data: "
  8544. "x%x x%x x%x\n",
  8545. irsp->ulpIoTag, irsp->ulpStatus,
  8546. irsp->un.ulpWord[4], irsp->ulpTimeout);
  8547. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  8548. lpfc_ct_free_iocb(phba, cmdiocb);
  8549. else
  8550. lpfc_els_free_iocb(phba, cmdiocb);
  8551. return;
  8552. }
  8553. /**
  8554. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  8555. * @phba: Pointer to HBA context object.
  8556. * @pring: Pointer to driver SLI ring object.
  8557. * @cmdiocb: Pointer to driver command iocb object.
  8558. *
  8559. * This function issues an abort iocb for the provided command iocb down to
  8560. * the port. Other than the case the outstanding command iocb is an abort
  8561. * request, this function issues abort out unconditionally. This function is
  8562. * called with hbalock held. The function returns 0 when it fails due to
  8563. * memory allocation failure or when the command iocb is an abort request.
  8564. **/
  8565. static int
  8566. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8567. struct lpfc_iocbq *cmdiocb)
  8568. {
  8569. struct lpfc_vport *vport = cmdiocb->vport;
  8570. struct lpfc_iocbq *abtsiocbp;
  8571. IOCB_t *icmd = NULL;
  8572. IOCB_t *iabt = NULL;
  8573. int retval;
  8574. unsigned long iflags;
  8575. /*
  8576. * There are certain command types we don't want to abort. And we
  8577. * don't want to abort commands that are already in the process of
  8578. * being aborted.
  8579. */
  8580. icmd = &cmdiocb->iocb;
  8581. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8582. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8583. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8584. return 0;
  8585. /* issue ABTS for this IOCB based on iotag */
  8586. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  8587. if (abtsiocbp == NULL)
  8588. return 0;
  8589. /* This signals the response to set the correct status
  8590. * before calling the completion handler
  8591. */
  8592. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  8593. iabt = &abtsiocbp->iocb;
  8594. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  8595. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  8596. if (phba->sli_rev == LPFC_SLI_REV4) {
  8597. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  8598. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  8599. }
  8600. else
  8601. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  8602. iabt->ulpLe = 1;
  8603. iabt->ulpClass = icmd->ulpClass;
  8604. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8605. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  8606. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  8607. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  8608. if (phba->link_state >= LPFC_LINK_UP)
  8609. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  8610. else
  8611. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  8612. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  8613. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  8614. "0339 Abort xri x%x, original iotag x%x, "
  8615. "abort cmd iotag x%x\n",
  8616. iabt->un.acxri.abortIoTag,
  8617. iabt->un.acxri.abortContextTag,
  8618. abtsiocbp->iotag);
  8619. if (phba->sli_rev == LPFC_SLI_REV4) {
  8620. /* Note: both hbalock and ring_lock need to be set here */
  8621. spin_lock_irqsave(&pring->ring_lock, iflags);
  8622. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  8623. abtsiocbp, 0);
  8624. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  8625. } else {
  8626. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  8627. abtsiocbp, 0);
  8628. }
  8629. if (retval)
  8630. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  8631. /*
  8632. * Caller to this routine should check for IOCB_ERROR
  8633. * and handle it properly. This routine no longer removes
  8634. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8635. */
  8636. return retval;
  8637. }
  8638. /**
  8639. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  8640. * @phba: Pointer to HBA context object.
  8641. * @pring: Pointer to driver SLI ring object.
  8642. * @cmdiocb: Pointer to driver command iocb object.
  8643. *
  8644. * This function issues an abort iocb for the provided command iocb. In case
  8645. * of unloading, the abort iocb will not be issued to commands on the ELS
  8646. * ring. Instead, the callback function shall be changed to those commands
  8647. * so that nothing happens when them finishes. This function is called with
  8648. * hbalock held. The function returns 0 when the command iocb is an abort
  8649. * request.
  8650. **/
  8651. int
  8652. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8653. struct lpfc_iocbq *cmdiocb)
  8654. {
  8655. struct lpfc_vport *vport = cmdiocb->vport;
  8656. int retval = IOCB_ERROR;
  8657. IOCB_t *icmd = NULL;
  8658. /*
  8659. * There are certain command types we don't want to abort. And we
  8660. * don't want to abort commands that are already in the process of
  8661. * being aborted.
  8662. */
  8663. icmd = &cmdiocb->iocb;
  8664. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8665. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8666. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8667. return 0;
  8668. /*
  8669. * If we're unloading, don't abort iocb on the ELS ring, but change
  8670. * the callback so that nothing happens when it finishes.
  8671. */
  8672. if ((vport->load_flag & FC_UNLOADING) &&
  8673. (pring->ringno == LPFC_ELS_RING)) {
  8674. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  8675. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  8676. else
  8677. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  8678. goto abort_iotag_exit;
  8679. }
  8680. /* Now, we try to issue the abort to the cmdiocb out */
  8681. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  8682. abort_iotag_exit:
  8683. /*
  8684. * Caller to this routine should check for IOCB_ERROR
  8685. * and handle it properly. This routine no longer removes
  8686. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8687. */
  8688. return retval;
  8689. }
  8690. /**
  8691. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  8692. * @phba: Pointer to HBA context object.
  8693. * @pring: Pointer to driver SLI ring object.
  8694. *
  8695. * This function aborts all iocbs in the given ring and frees all the iocb
  8696. * objects in txq. This function issues abort iocbs unconditionally for all
  8697. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  8698. * to complete before the return of this function. The caller is not required
  8699. * to hold any locks.
  8700. **/
  8701. static void
  8702. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  8703. {
  8704. LIST_HEAD(completions);
  8705. struct lpfc_iocbq *iocb, *next_iocb;
  8706. if (pring->ringno == LPFC_ELS_RING)
  8707. lpfc_fabric_abort_hba(phba);
  8708. spin_lock_irq(&phba->hbalock);
  8709. /* Take off all the iocbs on txq for cancelling */
  8710. list_splice_init(&pring->txq, &completions);
  8711. pring->txq_cnt = 0;
  8712. /* Next issue ABTS for everything on the txcmplq */
  8713. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  8714. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  8715. spin_unlock_irq(&phba->hbalock);
  8716. /* Cancel all the IOCBs from the completions list */
  8717. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8718. IOERR_SLI_ABORTED);
  8719. }
  8720. /**
  8721. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  8722. * @phba: pointer to lpfc HBA data structure.
  8723. *
  8724. * This routine will abort all pending and outstanding iocbs to an HBA.
  8725. **/
  8726. void
  8727. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  8728. {
  8729. struct lpfc_sli *psli = &phba->sli;
  8730. struct lpfc_sli_ring *pring;
  8731. int i;
  8732. for (i = 0; i < psli->num_rings; i++) {
  8733. pring = &psli->ring[i];
  8734. lpfc_sli_iocb_ring_abort(phba, pring);
  8735. }
  8736. }
  8737. /**
  8738. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  8739. * @iocbq: Pointer to driver iocb object.
  8740. * @vport: Pointer to driver virtual port object.
  8741. * @tgt_id: SCSI ID of the target.
  8742. * @lun_id: LUN ID of the scsi device.
  8743. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  8744. *
  8745. * This function acts as an iocb filter for functions which abort or count
  8746. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  8747. * 0 if the filtering criteria is met for the given iocb and will return
  8748. * 1 if the filtering criteria is not met.
  8749. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  8750. * given iocb is for the SCSI device specified by vport, tgt_id and
  8751. * lun_id parameter.
  8752. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  8753. * given iocb is for the SCSI target specified by vport and tgt_id
  8754. * parameters.
  8755. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  8756. * given iocb is for the SCSI host associated with the given vport.
  8757. * This function is called with no locks held.
  8758. **/
  8759. static int
  8760. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  8761. uint16_t tgt_id, uint64_t lun_id,
  8762. lpfc_ctx_cmd ctx_cmd)
  8763. {
  8764. struct lpfc_scsi_buf *lpfc_cmd;
  8765. int rc = 1;
  8766. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  8767. return rc;
  8768. if (iocbq->vport != vport)
  8769. return rc;
  8770. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  8771. if (lpfc_cmd->pCmd == NULL)
  8772. return rc;
  8773. switch (ctx_cmd) {
  8774. case LPFC_CTX_LUN:
  8775. if ((lpfc_cmd->rdata->pnode) &&
  8776. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  8777. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  8778. rc = 0;
  8779. break;
  8780. case LPFC_CTX_TGT:
  8781. if ((lpfc_cmd->rdata->pnode) &&
  8782. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  8783. rc = 0;
  8784. break;
  8785. case LPFC_CTX_HOST:
  8786. rc = 0;
  8787. break;
  8788. default:
  8789. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  8790. __func__, ctx_cmd);
  8791. break;
  8792. }
  8793. return rc;
  8794. }
  8795. /**
  8796. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  8797. * @vport: Pointer to virtual port.
  8798. * @tgt_id: SCSI ID of the target.
  8799. * @lun_id: LUN ID of the scsi device.
  8800. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8801. *
  8802. * This function returns number of FCP commands pending for the vport.
  8803. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  8804. * commands pending on the vport associated with SCSI device specified
  8805. * by tgt_id and lun_id parameters.
  8806. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  8807. * commands pending on the vport associated with SCSI target specified
  8808. * by tgt_id parameter.
  8809. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  8810. * commands pending on the vport.
  8811. * This function returns the number of iocbs which satisfy the filter.
  8812. * This function is called without any lock held.
  8813. **/
  8814. int
  8815. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  8816. lpfc_ctx_cmd ctx_cmd)
  8817. {
  8818. struct lpfc_hba *phba = vport->phba;
  8819. struct lpfc_iocbq *iocbq;
  8820. int sum, i;
  8821. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  8822. iocbq = phba->sli.iocbq_lookup[i];
  8823. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  8824. ctx_cmd) == 0)
  8825. sum++;
  8826. }
  8827. return sum;
  8828. }
  8829. /**
  8830. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  8831. * @phba: Pointer to HBA context object
  8832. * @cmdiocb: Pointer to command iocb object.
  8833. * @rspiocb: Pointer to response iocb object.
  8834. *
  8835. * This function is called when an aborted FCP iocb completes. This
  8836. * function is called by the ring event handler with no lock held.
  8837. * This function frees the iocb.
  8838. **/
  8839. void
  8840. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8841. struct lpfc_iocbq *rspiocb)
  8842. {
  8843. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8844. "3096 ABORT_XRI_CN completing on xri x%x "
  8845. "original iotag x%x, abort cmd iotag x%x "
  8846. "status 0x%x, reason 0x%x\n",
  8847. cmdiocb->iocb.un.acxri.abortContextTag,
  8848. cmdiocb->iocb.un.acxri.abortIoTag,
  8849. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  8850. rspiocb->iocb.un.ulpWord[4]);
  8851. lpfc_sli_release_iocbq(phba, cmdiocb);
  8852. return;
  8853. }
  8854. /**
  8855. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  8856. * @vport: Pointer to virtual port.
  8857. * @pring: Pointer to driver SLI ring object.
  8858. * @tgt_id: SCSI ID of the target.
  8859. * @lun_id: LUN ID of the scsi device.
  8860. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8861. *
  8862. * This function sends an abort command for every SCSI command
  8863. * associated with the given virtual port pending on the ring
  8864. * filtered by lpfc_sli_validate_fcp_iocb function.
  8865. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  8866. * FCP iocbs associated with lun specified by tgt_id and lun_id
  8867. * parameters
  8868. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  8869. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  8870. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  8871. * FCP iocbs associated with virtual port.
  8872. * This function returns number of iocbs it failed to abort.
  8873. * This function is called with no locks held.
  8874. **/
  8875. int
  8876. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  8877. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  8878. {
  8879. struct lpfc_hba *phba = vport->phba;
  8880. struct lpfc_iocbq *iocbq;
  8881. struct lpfc_iocbq *abtsiocb;
  8882. IOCB_t *cmd = NULL;
  8883. int errcnt = 0, ret_val = 0;
  8884. int i;
  8885. for (i = 1; i <= phba->sli.last_iotag; i++) {
  8886. iocbq = phba->sli.iocbq_lookup[i];
  8887. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  8888. abort_cmd) != 0)
  8889. continue;
  8890. /* issue ABTS for this IOCB based on iotag */
  8891. abtsiocb = lpfc_sli_get_iocbq(phba);
  8892. if (abtsiocb == NULL) {
  8893. errcnt++;
  8894. continue;
  8895. }
  8896. cmd = &iocbq->iocb;
  8897. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  8898. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  8899. if (phba->sli_rev == LPFC_SLI_REV4)
  8900. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  8901. else
  8902. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  8903. abtsiocb->iocb.ulpLe = 1;
  8904. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  8905. abtsiocb->vport = phba->pport;
  8906. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8907. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  8908. if (iocbq->iocb_flag & LPFC_IO_FCP)
  8909. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  8910. if (lpfc_is_link_up(phba))
  8911. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  8912. else
  8913. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  8914. /* Setup callback routine and issue the command. */
  8915. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  8916. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  8917. abtsiocb, 0);
  8918. if (ret_val == IOCB_ERROR) {
  8919. lpfc_sli_release_iocbq(phba, abtsiocb);
  8920. errcnt++;
  8921. continue;
  8922. }
  8923. }
  8924. return errcnt;
  8925. }
  8926. /**
  8927. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  8928. * @phba: Pointer to HBA context object.
  8929. * @cmdiocbq: Pointer to command iocb.
  8930. * @rspiocbq: Pointer to response iocb.
  8931. *
  8932. * This function is the completion handler for iocbs issued using
  8933. * lpfc_sli_issue_iocb_wait function. This function is called by the
  8934. * ring event handler function without any lock held. This function
  8935. * can be called from both worker thread context and interrupt
  8936. * context. This function also can be called from other thread which
  8937. * cleans up the SLI layer objects.
  8938. * This function copy the contents of the response iocb to the
  8939. * response iocb memory object provided by the caller of
  8940. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  8941. * sleeps for the iocb completion.
  8942. **/
  8943. static void
  8944. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  8945. struct lpfc_iocbq *cmdiocbq,
  8946. struct lpfc_iocbq *rspiocbq)
  8947. {
  8948. wait_queue_head_t *pdone_q;
  8949. unsigned long iflags;
  8950. struct lpfc_scsi_buf *lpfc_cmd;
  8951. spin_lock_irqsave(&phba->hbalock, iflags);
  8952. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  8953. if (cmdiocbq->context2 && rspiocbq)
  8954. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  8955. &rspiocbq->iocb, sizeof(IOCB_t));
  8956. /* Set the exchange busy flag for task management commands */
  8957. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  8958. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  8959. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  8960. cur_iocbq);
  8961. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  8962. }
  8963. pdone_q = cmdiocbq->context_un.wait_queue;
  8964. if (pdone_q)
  8965. wake_up(pdone_q);
  8966. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8967. return;
  8968. }
  8969. /**
  8970. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  8971. * @phba: Pointer to HBA context object..
  8972. * @piocbq: Pointer to command iocb.
  8973. * @flag: Flag to test.
  8974. *
  8975. * This routine grabs the hbalock and then test the iocb_flag to
  8976. * see if the passed in flag is set.
  8977. * Returns:
  8978. * 1 if flag is set.
  8979. * 0 if flag is not set.
  8980. **/
  8981. static int
  8982. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  8983. struct lpfc_iocbq *piocbq, uint32_t flag)
  8984. {
  8985. unsigned long iflags;
  8986. int ret;
  8987. spin_lock_irqsave(&phba->hbalock, iflags);
  8988. ret = piocbq->iocb_flag & flag;
  8989. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8990. return ret;
  8991. }
  8992. /**
  8993. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  8994. * @phba: Pointer to HBA context object..
  8995. * @pring: Pointer to sli ring.
  8996. * @piocb: Pointer to command iocb.
  8997. * @prspiocbq: Pointer to response iocb.
  8998. * @timeout: Timeout in number of seconds.
  8999. *
  9000. * This function issues the iocb to firmware and waits for the
  9001. * iocb to complete. If the iocb command is not
  9002. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  9003. * Caller should not free the iocb resources if this function
  9004. * returns IOCB_TIMEDOUT.
  9005. * The function waits for the iocb completion using an
  9006. * non-interruptible wait.
  9007. * This function will sleep while waiting for iocb completion.
  9008. * So, this function should not be called from any context which
  9009. * does not allow sleeping. Due to the same reason, this function
  9010. * cannot be called with interrupt disabled.
  9011. * This function assumes that the iocb completions occur while
  9012. * this function sleep. So, this function cannot be called from
  9013. * the thread which process iocb completion for this ring.
  9014. * This function clears the iocb_flag of the iocb object before
  9015. * issuing the iocb and the iocb completion handler sets this
  9016. * flag and wakes this thread when the iocb completes.
  9017. * The contents of the response iocb will be copied to prspiocbq
  9018. * by the completion handler when the command completes.
  9019. * This function returns IOCB_SUCCESS when success.
  9020. * This function is called with no lock held.
  9021. **/
  9022. int
  9023. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  9024. uint32_t ring_number,
  9025. struct lpfc_iocbq *piocb,
  9026. struct lpfc_iocbq *prspiocbq,
  9027. uint32_t timeout)
  9028. {
  9029. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9030. long timeleft, timeout_req = 0;
  9031. int retval = IOCB_SUCCESS;
  9032. uint32_t creg_val;
  9033. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9034. /*
  9035. * If the caller has provided a response iocbq buffer, then context2
  9036. * is NULL or its an error.
  9037. */
  9038. if (prspiocbq) {
  9039. if (piocb->context2)
  9040. return IOCB_ERROR;
  9041. piocb->context2 = prspiocbq;
  9042. }
  9043. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  9044. piocb->context_un.wait_queue = &done_q;
  9045. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  9046. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9047. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9048. return IOCB_ERROR;
  9049. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  9050. writel(creg_val, phba->HCregaddr);
  9051. readl(phba->HCregaddr); /* flush */
  9052. }
  9053. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  9054. SLI_IOCB_RET_IOCB);
  9055. if (retval == IOCB_SUCCESS) {
  9056. timeout_req = timeout * HZ;
  9057. timeleft = wait_event_timeout(done_q,
  9058. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  9059. timeout_req);
  9060. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  9061. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9062. "0331 IOCB wake signaled\n");
  9063. } else if (timeleft == 0) {
  9064. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9065. "0338 IOCB wait timeout error - no "
  9066. "wake response Data x%x\n", timeout);
  9067. retval = IOCB_TIMEDOUT;
  9068. } else {
  9069. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9070. "0330 IOCB wake NOT set, "
  9071. "Data x%x x%lx\n",
  9072. timeout, (timeleft / jiffies));
  9073. retval = IOCB_TIMEDOUT;
  9074. }
  9075. } else if (retval == IOCB_BUSY) {
  9076. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9077. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  9078. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  9079. return retval;
  9080. } else {
  9081. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9082. "0332 IOCB wait issue failed, Data x%x\n",
  9083. retval);
  9084. retval = IOCB_ERROR;
  9085. }
  9086. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9087. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9088. return IOCB_ERROR;
  9089. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  9090. writel(creg_val, phba->HCregaddr);
  9091. readl(phba->HCregaddr); /* flush */
  9092. }
  9093. if (prspiocbq)
  9094. piocb->context2 = NULL;
  9095. piocb->context_un.wait_queue = NULL;
  9096. piocb->iocb_cmpl = NULL;
  9097. return retval;
  9098. }
  9099. /**
  9100. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  9101. * @phba: Pointer to HBA context object.
  9102. * @pmboxq: Pointer to driver mailbox object.
  9103. * @timeout: Timeout in number of seconds.
  9104. *
  9105. * This function issues the mailbox to firmware and waits for the
  9106. * mailbox command to complete. If the mailbox command is not
  9107. * completed within timeout seconds, it returns MBX_TIMEOUT.
  9108. * The function waits for the mailbox completion using an
  9109. * interruptible wait. If the thread is woken up due to a
  9110. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  9111. * should not free the mailbox resources, if this function returns
  9112. * MBX_TIMEOUT.
  9113. * This function will sleep while waiting for mailbox completion.
  9114. * So, this function should not be called from any context which
  9115. * does not allow sleeping. Due to the same reason, this function
  9116. * cannot be called with interrupt disabled.
  9117. * This function assumes that the mailbox completion occurs while
  9118. * this function sleep. So, this function cannot be called from
  9119. * the worker thread which processes mailbox completion.
  9120. * This function is called in the context of HBA management
  9121. * applications.
  9122. * This function returns MBX_SUCCESS when successful.
  9123. * This function is called with no lock held.
  9124. **/
  9125. int
  9126. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  9127. uint32_t timeout)
  9128. {
  9129. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9130. int retval;
  9131. unsigned long flag;
  9132. /* The caller must leave context1 empty. */
  9133. if (pmboxq->context1)
  9134. return MBX_NOT_FINISHED;
  9135. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  9136. /* setup wake call as IOCB callback */
  9137. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  9138. /* setup context field to pass wait_queue pointer to wake function */
  9139. pmboxq->context1 = &done_q;
  9140. /* now issue the command */
  9141. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  9142. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  9143. wait_event_interruptible_timeout(done_q,
  9144. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  9145. timeout * HZ);
  9146. spin_lock_irqsave(&phba->hbalock, flag);
  9147. pmboxq->context1 = NULL;
  9148. /*
  9149. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  9150. * else do not free the resources.
  9151. */
  9152. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  9153. retval = MBX_SUCCESS;
  9154. lpfc_sli4_swap_str(phba, pmboxq);
  9155. } else {
  9156. retval = MBX_TIMEOUT;
  9157. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9158. }
  9159. spin_unlock_irqrestore(&phba->hbalock, flag);
  9160. }
  9161. return retval;
  9162. }
  9163. /**
  9164. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  9165. * @phba: Pointer to HBA context.
  9166. *
  9167. * This function is called to shutdown the driver's mailbox sub-system.
  9168. * It first marks the mailbox sub-system is in a block state to prevent
  9169. * the asynchronous mailbox command from issued off the pending mailbox
  9170. * command queue. If the mailbox command sub-system shutdown is due to
  9171. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  9172. * the mailbox sub-system flush routine to forcefully bring down the
  9173. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  9174. * as with offline or HBA function reset), this routine will wait for the
  9175. * outstanding mailbox command to complete before invoking the mailbox
  9176. * sub-system flush routine to gracefully bring down mailbox sub-system.
  9177. **/
  9178. void
  9179. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
  9180. {
  9181. struct lpfc_sli *psli = &phba->sli;
  9182. unsigned long timeout;
  9183. if (mbx_action == LPFC_MBX_NO_WAIT) {
  9184. /* delay 100ms for port state */
  9185. msleep(100);
  9186. lpfc_sli_mbox_sys_flush(phba);
  9187. return;
  9188. }
  9189. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  9190. spin_lock_irq(&phba->hbalock);
  9191. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  9192. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  9193. /* Determine how long we might wait for the active mailbox
  9194. * command to be gracefully completed by firmware.
  9195. */
  9196. if (phba->sli.mbox_active)
  9197. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  9198. phba->sli.mbox_active) *
  9199. 1000) + jiffies;
  9200. spin_unlock_irq(&phba->hbalock);
  9201. while (phba->sli.mbox_active) {
  9202. /* Check active mailbox complete status every 2ms */
  9203. msleep(2);
  9204. if (time_after(jiffies, timeout))
  9205. /* Timeout, let the mailbox flush routine to
  9206. * forcefully release active mailbox command
  9207. */
  9208. break;
  9209. }
  9210. } else
  9211. spin_unlock_irq(&phba->hbalock);
  9212. lpfc_sli_mbox_sys_flush(phba);
  9213. }
  9214. /**
  9215. * lpfc_sli_eratt_read - read sli-3 error attention events
  9216. * @phba: Pointer to HBA context.
  9217. *
  9218. * This function is called to read the SLI3 device error attention registers
  9219. * for possible error attention events. The caller must hold the hostlock
  9220. * with spin_lock_irq().
  9221. *
  9222. * This function returns 1 when there is Error Attention in the Host Attention
  9223. * Register and returns 0 otherwise.
  9224. **/
  9225. static int
  9226. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  9227. {
  9228. uint32_t ha_copy;
  9229. /* Read chip Host Attention (HA) register */
  9230. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9231. goto unplug_err;
  9232. if (ha_copy & HA_ERATT) {
  9233. /* Read host status register to retrieve error event */
  9234. if (lpfc_sli_read_hs(phba))
  9235. goto unplug_err;
  9236. /* Check if there is a deferred error condition is active */
  9237. if ((HS_FFER1 & phba->work_hs) &&
  9238. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9239. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  9240. phba->hba_flag |= DEFER_ERATT;
  9241. /* Clear all interrupt enable conditions */
  9242. writel(0, phba->HCregaddr);
  9243. readl(phba->HCregaddr);
  9244. }
  9245. /* Set the driver HA work bitmap */
  9246. phba->work_ha |= HA_ERATT;
  9247. /* Indicate polling handles this ERATT */
  9248. phba->hba_flag |= HBA_ERATT_HANDLED;
  9249. return 1;
  9250. }
  9251. return 0;
  9252. unplug_err:
  9253. /* Set the driver HS work bitmap */
  9254. phba->work_hs |= UNPLUG_ERR;
  9255. /* Set the driver HA work bitmap */
  9256. phba->work_ha |= HA_ERATT;
  9257. /* Indicate polling handles this ERATT */
  9258. phba->hba_flag |= HBA_ERATT_HANDLED;
  9259. return 1;
  9260. }
  9261. /**
  9262. * lpfc_sli4_eratt_read - read sli-4 error attention events
  9263. * @phba: Pointer to HBA context.
  9264. *
  9265. * This function is called to read the SLI4 device error attention registers
  9266. * for possible error attention events. The caller must hold the hostlock
  9267. * with spin_lock_irq().
  9268. *
  9269. * This function returns 1 when there is Error Attention in the Host Attention
  9270. * Register and returns 0 otherwise.
  9271. **/
  9272. static int
  9273. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  9274. {
  9275. uint32_t uerr_sta_hi, uerr_sta_lo;
  9276. uint32_t if_type, portsmphr;
  9277. struct lpfc_register portstat_reg;
  9278. /*
  9279. * For now, use the SLI4 device internal unrecoverable error
  9280. * registers for error attention. This can be changed later.
  9281. */
  9282. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9283. switch (if_type) {
  9284. case LPFC_SLI_INTF_IF_TYPE_0:
  9285. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  9286. &uerr_sta_lo) ||
  9287. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  9288. &uerr_sta_hi)) {
  9289. phba->work_hs |= UNPLUG_ERR;
  9290. phba->work_ha |= HA_ERATT;
  9291. phba->hba_flag |= HBA_ERATT_HANDLED;
  9292. return 1;
  9293. }
  9294. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  9295. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  9296. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9297. "1423 HBA Unrecoverable error: "
  9298. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9299. "ue_mask_lo_reg=0x%x, "
  9300. "ue_mask_hi_reg=0x%x\n",
  9301. uerr_sta_lo, uerr_sta_hi,
  9302. phba->sli4_hba.ue_mask_lo,
  9303. phba->sli4_hba.ue_mask_hi);
  9304. phba->work_status[0] = uerr_sta_lo;
  9305. phba->work_status[1] = uerr_sta_hi;
  9306. phba->work_ha |= HA_ERATT;
  9307. phba->hba_flag |= HBA_ERATT_HANDLED;
  9308. return 1;
  9309. }
  9310. break;
  9311. case LPFC_SLI_INTF_IF_TYPE_2:
  9312. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9313. &portstat_reg.word0) ||
  9314. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9315. &portsmphr)){
  9316. phba->work_hs |= UNPLUG_ERR;
  9317. phba->work_ha |= HA_ERATT;
  9318. phba->hba_flag |= HBA_ERATT_HANDLED;
  9319. return 1;
  9320. }
  9321. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9322. phba->work_status[0] =
  9323. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9324. phba->work_status[1] =
  9325. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9326. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9327. "2885 Port Status Event: "
  9328. "port status reg 0x%x, "
  9329. "port smphr reg 0x%x, "
  9330. "error 1=0x%x, error 2=0x%x\n",
  9331. portstat_reg.word0,
  9332. portsmphr,
  9333. phba->work_status[0],
  9334. phba->work_status[1]);
  9335. phba->work_ha |= HA_ERATT;
  9336. phba->hba_flag |= HBA_ERATT_HANDLED;
  9337. return 1;
  9338. }
  9339. break;
  9340. case LPFC_SLI_INTF_IF_TYPE_1:
  9341. default:
  9342. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9343. "2886 HBA Error Attention on unsupported "
  9344. "if type %d.", if_type);
  9345. return 1;
  9346. }
  9347. return 0;
  9348. }
  9349. /**
  9350. * lpfc_sli_check_eratt - check error attention events
  9351. * @phba: Pointer to HBA context.
  9352. *
  9353. * This function is called from timer soft interrupt context to check HBA's
  9354. * error attention register bit for error attention events.
  9355. *
  9356. * This function returns 1 when there is Error Attention in the Host Attention
  9357. * Register and returns 0 otherwise.
  9358. **/
  9359. int
  9360. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9361. {
  9362. uint32_t ha_copy;
  9363. /* If somebody is waiting to handle an eratt, don't process it
  9364. * here. The brdkill function will do this.
  9365. */
  9366. if (phba->link_flag & LS_IGNORE_ERATT)
  9367. return 0;
  9368. /* Check if interrupt handler handles this ERATT */
  9369. spin_lock_irq(&phba->hbalock);
  9370. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  9371. /* Interrupt handler has handled ERATT */
  9372. spin_unlock_irq(&phba->hbalock);
  9373. return 0;
  9374. }
  9375. /*
  9376. * If there is deferred error attention, do not check for error
  9377. * attention
  9378. */
  9379. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9380. spin_unlock_irq(&phba->hbalock);
  9381. return 0;
  9382. }
  9383. /* If PCI channel is offline, don't process it */
  9384. if (unlikely(pci_channel_offline(phba->pcidev))) {
  9385. spin_unlock_irq(&phba->hbalock);
  9386. return 0;
  9387. }
  9388. switch (phba->sli_rev) {
  9389. case LPFC_SLI_REV2:
  9390. case LPFC_SLI_REV3:
  9391. /* Read chip Host Attention (HA) register */
  9392. ha_copy = lpfc_sli_eratt_read(phba);
  9393. break;
  9394. case LPFC_SLI_REV4:
  9395. /* Read device Uncoverable Error (UERR) registers */
  9396. ha_copy = lpfc_sli4_eratt_read(phba);
  9397. break;
  9398. default:
  9399. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9400. "0299 Invalid SLI revision (%d)\n",
  9401. phba->sli_rev);
  9402. ha_copy = 0;
  9403. break;
  9404. }
  9405. spin_unlock_irq(&phba->hbalock);
  9406. return ha_copy;
  9407. }
  9408. /**
  9409. * lpfc_intr_state_check - Check device state for interrupt handling
  9410. * @phba: Pointer to HBA context.
  9411. *
  9412. * This inline routine checks whether a device or its PCI slot is in a state
  9413. * that the interrupt should be handled.
  9414. *
  9415. * This function returns 0 if the device or the PCI slot is in a state that
  9416. * interrupt should be handled, otherwise -EIO.
  9417. */
  9418. static inline int
  9419. lpfc_intr_state_check(struct lpfc_hba *phba)
  9420. {
  9421. /* If the pci channel is offline, ignore all the interrupts */
  9422. if (unlikely(pci_channel_offline(phba->pcidev)))
  9423. return -EIO;
  9424. /* Update device level interrupt statistics */
  9425. phba->sli.slistat.sli_intr++;
  9426. /* Ignore all interrupts during initialization. */
  9427. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  9428. return -EIO;
  9429. return 0;
  9430. }
  9431. /**
  9432. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  9433. * @irq: Interrupt number.
  9434. * @dev_id: The device context pointer.
  9435. *
  9436. * This function is directly called from the PCI layer as an interrupt
  9437. * service routine when device with SLI-3 interface spec is enabled with
  9438. * MSI-X multi-message interrupt mode and there are slow-path events in
  9439. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9440. * interrupt mode, this function is called as part of the device-level
  9441. * interrupt handler. When the PCI slot is in error recovery or the HBA
  9442. * is undergoing initialization, the interrupt handler will not process
  9443. * the interrupt. The link attention and ELS ring attention events are
  9444. * handled by the worker thread. The interrupt handler signals the worker
  9445. * thread and returns for these events. This function is called without
  9446. * any lock held. It gets the hbalock to access and update SLI data
  9447. * structures.
  9448. *
  9449. * This function returns IRQ_HANDLED when interrupt is handled else it
  9450. * returns IRQ_NONE.
  9451. **/
  9452. irqreturn_t
  9453. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  9454. {
  9455. struct lpfc_hba *phba;
  9456. uint32_t ha_copy, hc_copy;
  9457. uint32_t work_ha_copy;
  9458. unsigned long status;
  9459. unsigned long iflag;
  9460. uint32_t control;
  9461. MAILBOX_t *mbox, *pmbox;
  9462. struct lpfc_vport *vport;
  9463. struct lpfc_nodelist *ndlp;
  9464. struct lpfc_dmabuf *mp;
  9465. LPFC_MBOXQ_t *pmb;
  9466. int rc;
  9467. /*
  9468. * Get the driver's phba structure from the dev_id and
  9469. * assume the HBA is not interrupting.
  9470. */
  9471. phba = (struct lpfc_hba *)dev_id;
  9472. if (unlikely(!phba))
  9473. return IRQ_NONE;
  9474. /*
  9475. * Stuff needs to be attented to when this function is invoked as an
  9476. * individual interrupt handler in MSI-X multi-message interrupt mode
  9477. */
  9478. if (phba->intr_type == MSIX) {
  9479. /* Check device state for handling interrupt */
  9480. if (lpfc_intr_state_check(phba))
  9481. return IRQ_NONE;
  9482. /* Need to read HA REG for slow-path events */
  9483. spin_lock_irqsave(&phba->hbalock, iflag);
  9484. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9485. goto unplug_error;
  9486. /* If somebody is waiting to handle an eratt don't process it
  9487. * here. The brdkill function will do this.
  9488. */
  9489. if (phba->link_flag & LS_IGNORE_ERATT)
  9490. ha_copy &= ~HA_ERATT;
  9491. /* Check the need for handling ERATT in interrupt handler */
  9492. if (ha_copy & HA_ERATT) {
  9493. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9494. /* ERATT polling has handled ERATT */
  9495. ha_copy &= ~HA_ERATT;
  9496. else
  9497. /* Indicate interrupt handler handles ERATT */
  9498. phba->hba_flag |= HBA_ERATT_HANDLED;
  9499. }
  9500. /*
  9501. * If there is deferred error attention, do not check for any
  9502. * interrupt.
  9503. */
  9504. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9505. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9506. return IRQ_NONE;
  9507. }
  9508. /* Clear up only attention source related to slow-path */
  9509. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  9510. goto unplug_error;
  9511. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  9512. HC_LAINT_ENA | HC_ERINT_ENA),
  9513. phba->HCregaddr);
  9514. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  9515. phba->HAregaddr);
  9516. writel(hc_copy, phba->HCregaddr);
  9517. readl(phba->HAregaddr); /* flush */
  9518. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9519. } else
  9520. ha_copy = phba->ha_copy;
  9521. work_ha_copy = ha_copy & phba->work_ha_mask;
  9522. if (work_ha_copy) {
  9523. if (work_ha_copy & HA_LATT) {
  9524. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  9525. /*
  9526. * Turn off Link Attention interrupts
  9527. * until CLEAR_LA done
  9528. */
  9529. spin_lock_irqsave(&phba->hbalock, iflag);
  9530. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  9531. if (lpfc_readl(phba->HCregaddr, &control))
  9532. goto unplug_error;
  9533. control &= ~HC_LAINT_ENA;
  9534. writel(control, phba->HCregaddr);
  9535. readl(phba->HCregaddr); /* flush */
  9536. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9537. }
  9538. else
  9539. work_ha_copy &= ~HA_LATT;
  9540. }
  9541. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  9542. /*
  9543. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  9544. * the only slow ring.
  9545. */
  9546. status = (work_ha_copy &
  9547. (HA_RXMASK << (4*LPFC_ELS_RING)));
  9548. status >>= (4*LPFC_ELS_RING);
  9549. if (status & HA_RXMASK) {
  9550. spin_lock_irqsave(&phba->hbalock, iflag);
  9551. if (lpfc_readl(phba->HCregaddr, &control))
  9552. goto unplug_error;
  9553. lpfc_debugfs_slow_ring_trc(phba,
  9554. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  9555. control, status,
  9556. (uint32_t)phba->sli.slistat.sli_intr);
  9557. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  9558. lpfc_debugfs_slow_ring_trc(phba,
  9559. "ISR Disable ring:"
  9560. "pwork:x%x hawork:x%x wait:x%x",
  9561. phba->work_ha, work_ha_copy,
  9562. (uint32_t)((unsigned long)
  9563. &phba->work_waitq));
  9564. control &=
  9565. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  9566. writel(control, phba->HCregaddr);
  9567. readl(phba->HCregaddr); /* flush */
  9568. }
  9569. else {
  9570. lpfc_debugfs_slow_ring_trc(phba,
  9571. "ISR slow ring: pwork:"
  9572. "x%x hawork:x%x wait:x%x",
  9573. phba->work_ha, work_ha_copy,
  9574. (uint32_t)((unsigned long)
  9575. &phba->work_waitq));
  9576. }
  9577. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9578. }
  9579. }
  9580. spin_lock_irqsave(&phba->hbalock, iflag);
  9581. if (work_ha_copy & HA_ERATT) {
  9582. if (lpfc_sli_read_hs(phba))
  9583. goto unplug_error;
  9584. /*
  9585. * Check if there is a deferred error condition
  9586. * is active
  9587. */
  9588. if ((HS_FFER1 & phba->work_hs) &&
  9589. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9590. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  9591. phba->work_hs)) {
  9592. phba->hba_flag |= DEFER_ERATT;
  9593. /* Clear all interrupt enable conditions */
  9594. writel(0, phba->HCregaddr);
  9595. readl(phba->HCregaddr);
  9596. }
  9597. }
  9598. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  9599. pmb = phba->sli.mbox_active;
  9600. pmbox = &pmb->u.mb;
  9601. mbox = phba->mbox;
  9602. vport = pmb->vport;
  9603. /* First check out the status word */
  9604. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  9605. if (pmbox->mbxOwner != OWN_HOST) {
  9606. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9607. /*
  9608. * Stray Mailbox Interrupt, mbxCommand <cmd>
  9609. * mbxStatus <status>
  9610. */
  9611. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9612. LOG_SLI,
  9613. "(%d):0304 Stray Mailbox "
  9614. "Interrupt mbxCommand x%x "
  9615. "mbxStatus x%x\n",
  9616. (vport ? vport->vpi : 0),
  9617. pmbox->mbxCommand,
  9618. pmbox->mbxStatus);
  9619. /* clear mailbox attention bit */
  9620. work_ha_copy &= ~HA_MBATT;
  9621. } else {
  9622. phba->sli.mbox_active = NULL;
  9623. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9624. phba->last_completion_time = jiffies;
  9625. del_timer(&phba->sli.mbox_tmo);
  9626. if (pmb->mbox_cmpl) {
  9627. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  9628. MAILBOX_CMD_SIZE);
  9629. if (pmb->out_ext_byte_len &&
  9630. pmb->context2)
  9631. lpfc_sli_pcimem_bcopy(
  9632. phba->mbox_ext,
  9633. pmb->context2,
  9634. pmb->out_ext_byte_len);
  9635. }
  9636. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  9637. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  9638. lpfc_debugfs_disc_trc(vport,
  9639. LPFC_DISC_TRC_MBOX_VPORT,
  9640. "MBOX dflt rpi: : "
  9641. "status:x%x rpi:x%x",
  9642. (uint32_t)pmbox->mbxStatus,
  9643. pmbox->un.varWords[0], 0);
  9644. if (!pmbox->mbxStatus) {
  9645. mp = (struct lpfc_dmabuf *)
  9646. (pmb->context1);
  9647. ndlp = (struct lpfc_nodelist *)
  9648. pmb->context2;
  9649. /* Reg_LOGIN of dflt RPI was
  9650. * successful. new lets get
  9651. * rid of the RPI using the
  9652. * same mbox buffer.
  9653. */
  9654. lpfc_unreg_login(phba,
  9655. vport->vpi,
  9656. pmbox->un.varWords[0],
  9657. pmb);
  9658. pmb->mbox_cmpl =
  9659. lpfc_mbx_cmpl_dflt_rpi;
  9660. pmb->context1 = mp;
  9661. pmb->context2 = ndlp;
  9662. pmb->vport = vport;
  9663. rc = lpfc_sli_issue_mbox(phba,
  9664. pmb,
  9665. MBX_NOWAIT);
  9666. if (rc != MBX_BUSY)
  9667. lpfc_printf_log(phba,
  9668. KERN_ERR,
  9669. LOG_MBOX | LOG_SLI,
  9670. "0350 rc should have"
  9671. "been MBX_BUSY\n");
  9672. if (rc != MBX_NOT_FINISHED)
  9673. goto send_current_mbox;
  9674. }
  9675. }
  9676. spin_lock_irqsave(
  9677. &phba->pport->work_port_lock,
  9678. iflag);
  9679. phba->pport->work_port_events &=
  9680. ~WORKER_MBOX_TMO;
  9681. spin_unlock_irqrestore(
  9682. &phba->pport->work_port_lock,
  9683. iflag);
  9684. lpfc_mbox_cmpl_put(phba, pmb);
  9685. }
  9686. } else
  9687. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9688. if ((work_ha_copy & HA_MBATT) &&
  9689. (phba->sli.mbox_active == NULL)) {
  9690. send_current_mbox:
  9691. /* Process next mailbox command if there is one */
  9692. do {
  9693. rc = lpfc_sli_issue_mbox(phba, NULL,
  9694. MBX_NOWAIT);
  9695. } while (rc == MBX_NOT_FINISHED);
  9696. if (rc != MBX_SUCCESS)
  9697. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9698. LOG_SLI, "0349 rc should be "
  9699. "MBX_SUCCESS\n");
  9700. }
  9701. spin_lock_irqsave(&phba->hbalock, iflag);
  9702. phba->work_ha |= work_ha_copy;
  9703. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9704. lpfc_worker_wake_up(phba);
  9705. }
  9706. return IRQ_HANDLED;
  9707. unplug_error:
  9708. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9709. return IRQ_HANDLED;
  9710. } /* lpfc_sli_sp_intr_handler */
  9711. /**
  9712. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  9713. * @irq: Interrupt number.
  9714. * @dev_id: The device context pointer.
  9715. *
  9716. * This function is directly called from the PCI layer as an interrupt
  9717. * service routine when device with SLI-3 interface spec is enabled with
  9718. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9719. * ring event in the HBA. However, when the device is enabled with either
  9720. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9721. * device-level interrupt handler. When the PCI slot is in error recovery
  9722. * or the HBA is undergoing initialization, the interrupt handler will not
  9723. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9724. * the intrrupt context. This function is called without any lock held.
  9725. * It gets the hbalock to access and update SLI data structures.
  9726. *
  9727. * This function returns IRQ_HANDLED when interrupt is handled else it
  9728. * returns IRQ_NONE.
  9729. **/
  9730. irqreturn_t
  9731. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  9732. {
  9733. struct lpfc_hba *phba;
  9734. uint32_t ha_copy;
  9735. unsigned long status;
  9736. unsigned long iflag;
  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. /*
  9744. * Stuff needs to be attented to when this function is invoked as an
  9745. * individual interrupt handler in MSI-X multi-message interrupt mode
  9746. */
  9747. if (phba->intr_type == MSIX) {
  9748. /* Check device state for handling interrupt */
  9749. if (lpfc_intr_state_check(phba))
  9750. return IRQ_NONE;
  9751. /* Need to read HA REG for FCP ring and other ring events */
  9752. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9753. return IRQ_HANDLED;
  9754. /* Clear up only attention source related to fast-path */
  9755. spin_lock_irqsave(&phba->hbalock, iflag);
  9756. /*
  9757. * If there is deferred error attention, do not check for
  9758. * any interrupt.
  9759. */
  9760. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9761. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9762. return IRQ_NONE;
  9763. }
  9764. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  9765. phba->HAregaddr);
  9766. readl(phba->HAregaddr); /* flush */
  9767. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9768. } else
  9769. ha_copy = phba->ha_copy;
  9770. /*
  9771. * Process all events on FCP ring. Take the optimized path for FCP IO.
  9772. */
  9773. ha_copy &= ~(phba->work_ha_mask);
  9774. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9775. status >>= (4*LPFC_FCP_RING);
  9776. if (status & HA_RXMASK)
  9777. lpfc_sli_handle_fast_ring_event(phba,
  9778. &phba->sli.ring[LPFC_FCP_RING],
  9779. status);
  9780. if (phba->cfg_multi_ring_support == 2) {
  9781. /*
  9782. * Process all events on extra ring. Take the optimized path
  9783. * for extra ring IO.
  9784. */
  9785. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9786. status >>= (4*LPFC_EXTRA_RING);
  9787. if (status & HA_RXMASK) {
  9788. lpfc_sli_handle_fast_ring_event(phba,
  9789. &phba->sli.ring[LPFC_EXTRA_RING],
  9790. status);
  9791. }
  9792. }
  9793. return IRQ_HANDLED;
  9794. } /* lpfc_sli_fp_intr_handler */
  9795. /**
  9796. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  9797. * @irq: Interrupt number.
  9798. * @dev_id: The device context pointer.
  9799. *
  9800. * This function is the HBA device-level interrupt handler to device with
  9801. * SLI-3 interface spec, called from the PCI layer when either MSI or
  9802. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  9803. * requires driver attention. This function invokes the slow-path interrupt
  9804. * attention handling function and fast-path interrupt attention handling
  9805. * function in turn to process the relevant HBA attention events. This
  9806. * function is called without any lock held. It gets the hbalock to access
  9807. * and update SLI data structures.
  9808. *
  9809. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9810. * returns IRQ_NONE.
  9811. **/
  9812. irqreturn_t
  9813. lpfc_sli_intr_handler(int irq, void *dev_id)
  9814. {
  9815. struct lpfc_hba *phba;
  9816. irqreturn_t sp_irq_rc, fp_irq_rc;
  9817. unsigned long status1, status2;
  9818. uint32_t hc_copy;
  9819. /*
  9820. * Get the driver's phba structure from the dev_id and
  9821. * assume the HBA is not interrupting.
  9822. */
  9823. phba = (struct lpfc_hba *) dev_id;
  9824. if (unlikely(!phba))
  9825. return IRQ_NONE;
  9826. /* Check device state for handling interrupt */
  9827. if (lpfc_intr_state_check(phba))
  9828. return IRQ_NONE;
  9829. spin_lock(&phba->hbalock);
  9830. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  9831. spin_unlock(&phba->hbalock);
  9832. return IRQ_HANDLED;
  9833. }
  9834. if (unlikely(!phba->ha_copy)) {
  9835. spin_unlock(&phba->hbalock);
  9836. return IRQ_NONE;
  9837. } else if (phba->ha_copy & HA_ERATT) {
  9838. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9839. /* ERATT polling has handled ERATT */
  9840. phba->ha_copy &= ~HA_ERATT;
  9841. else
  9842. /* Indicate interrupt handler handles ERATT */
  9843. phba->hba_flag |= HBA_ERATT_HANDLED;
  9844. }
  9845. /*
  9846. * If there is deferred error attention, do not check for any interrupt.
  9847. */
  9848. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9849. spin_unlock(&phba->hbalock);
  9850. return IRQ_NONE;
  9851. }
  9852. /* Clear attention sources except link and error attentions */
  9853. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  9854. spin_unlock(&phba->hbalock);
  9855. return IRQ_HANDLED;
  9856. }
  9857. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  9858. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  9859. phba->HCregaddr);
  9860. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  9861. writel(hc_copy, phba->HCregaddr);
  9862. readl(phba->HAregaddr); /* flush */
  9863. spin_unlock(&phba->hbalock);
  9864. /*
  9865. * Invokes slow-path host attention interrupt handling as appropriate.
  9866. */
  9867. /* status of events with mailbox and link attention */
  9868. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  9869. /* status of events with ELS ring */
  9870. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  9871. status2 >>= (4*LPFC_ELS_RING);
  9872. if (status1 || (status2 & HA_RXMASK))
  9873. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  9874. else
  9875. sp_irq_rc = IRQ_NONE;
  9876. /*
  9877. * Invoke fast-path host attention interrupt handling as appropriate.
  9878. */
  9879. /* status of events with FCP ring */
  9880. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9881. status1 >>= (4*LPFC_FCP_RING);
  9882. /* status of events with extra ring */
  9883. if (phba->cfg_multi_ring_support == 2) {
  9884. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9885. status2 >>= (4*LPFC_EXTRA_RING);
  9886. } else
  9887. status2 = 0;
  9888. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  9889. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  9890. else
  9891. fp_irq_rc = IRQ_NONE;
  9892. /* Return device-level interrupt handling status */
  9893. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  9894. } /* lpfc_sli_intr_handler */
  9895. /**
  9896. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  9897. * @phba: pointer to lpfc hba data structure.
  9898. *
  9899. * This routine is invoked by the worker thread to process all the pending
  9900. * SLI4 FCP abort XRI events.
  9901. **/
  9902. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  9903. {
  9904. struct lpfc_cq_event *cq_event;
  9905. /* First, declare the fcp xri abort event has been handled */
  9906. spin_lock_irq(&phba->hbalock);
  9907. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  9908. spin_unlock_irq(&phba->hbalock);
  9909. /* Now, handle all the fcp xri abort events */
  9910. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  9911. /* Get the first event from the head of the event queue */
  9912. spin_lock_irq(&phba->hbalock);
  9913. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  9914. cq_event, struct lpfc_cq_event, list);
  9915. spin_unlock_irq(&phba->hbalock);
  9916. /* Notify aborted XRI for FCP work queue */
  9917. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9918. /* Free the event processed back to the free pool */
  9919. lpfc_sli4_cq_event_release(phba, cq_event);
  9920. }
  9921. }
  9922. /**
  9923. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  9924. * @phba: pointer to lpfc hba data structure.
  9925. *
  9926. * This routine is invoked by the worker thread to process all the pending
  9927. * SLI4 els abort xri events.
  9928. **/
  9929. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  9930. {
  9931. struct lpfc_cq_event *cq_event;
  9932. /* First, declare the els xri abort event has been handled */
  9933. spin_lock_irq(&phba->hbalock);
  9934. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  9935. spin_unlock_irq(&phba->hbalock);
  9936. /* Now, handle all the els xri abort events */
  9937. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  9938. /* Get the first event from the head of the event queue */
  9939. spin_lock_irq(&phba->hbalock);
  9940. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  9941. cq_event, struct lpfc_cq_event, list);
  9942. spin_unlock_irq(&phba->hbalock);
  9943. /* Notify aborted XRI for ELS work queue */
  9944. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9945. /* Free the event processed back to the free pool */
  9946. lpfc_sli4_cq_event_release(phba, cq_event);
  9947. }
  9948. }
  9949. /**
  9950. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  9951. * @phba: pointer to lpfc hba data structure
  9952. * @pIocbIn: pointer to the rspiocbq
  9953. * @pIocbOut: pointer to the cmdiocbq
  9954. * @wcqe: pointer to the complete wcqe
  9955. *
  9956. * This routine transfers the fields of a command iocbq to a response iocbq
  9957. * by copying all the IOCB fields from command iocbq and transferring the
  9958. * completion status information from the complete wcqe.
  9959. **/
  9960. static void
  9961. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  9962. struct lpfc_iocbq *pIocbIn,
  9963. struct lpfc_iocbq *pIocbOut,
  9964. struct lpfc_wcqe_complete *wcqe)
  9965. {
  9966. unsigned long iflags;
  9967. uint32_t status;
  9968. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  9969. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  9970. sizeof(struct lpfc_iocbq) - offset);
  9971. /* Map WCQE parameters into irspiocb parameters */
  9972. status = bf_get(lpfc_wcqe_c_status, wcqe);
  9973. pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
  9974. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  9975. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  9976. pIocbIn->iocb.un.fcpi.fcpi_parm =
  9977. pIocbOut->iocb.un.fcpi.fcpi_parm -
  9978. wcqe->total_data_placed;
  9979. else
  9980. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9981. else {
  9982. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9983. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  9984. }
  9985. /* Convert BG errors for completion status */
  9986. if (status == CQE_STATUS_DI_ERROR) {
  9987. pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  9988. if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
  9989. pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
  9990. else
  9991. pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
  9992. pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
  9993. if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
  9994. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9995. BGS_GUARD_ERR_MASK;
  9996. if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
  9997. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9998. BGS_APPTAG_ERR_MASK;
  9999. if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
  10000. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10001. BGS_REFTAG_ERR_MASK;
  10002. /* Check to see if there was any good data before the error */
  10003. if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
  10004. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10005. BGS_HI_WATER_MARK_PRESENT_MASK;
  10006. pIocbIn->iocb.unsli3.sli3_bg.bghm =
  10007. wcqe->total_data_placed;
  10008. }
  10009. /*
  10010. * Set ALL the error bits to indicate we don't know what
  10011. * type of error it is.
  10012. */
  10013. if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
  10014. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10015. (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
  10016. BGS_GUARD_ERR_MASK);
  10017. }
  10018. /* Pick up HBA exchange busy condition */
  10019. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  10020. spin_lock_irqsave(&phba->hbalock, iflags);
  10021. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  10022. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10023. }
  10024. }
  10025. /**
  10026. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  10027. * @phba: Pointer to HBA context object.
  10028. * @wcqe: Pointer to work-queue completion queue entry.
  10029. *
  10030. * This routine handles an ELS work-queue completion event and construct
  10031. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  10032. * discovery engine to handle.
  10033. *
  10034. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  10035. **/
  10036. static struct lpfc_iocbq *
  10037. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  10038. struct lpfc_iocbq *irspiocbq)
  10039. {
  10040. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  10041. struct lpfc_iocbq *cmdiocbq;
  10042. struct lpfc_wcqe_complete *wcqe;
  10043. unsigned long iflags;
  10044. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  10045. spin_lock_irqsave(&pring->ring_lock, iflags);
  10046. pring->stats.iocb_event++;
  10047. /* Look up the ELS command IOCB and create pseudo response IOCB */
  10048. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10049. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10050. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10051. if (unlikely(!cmdiocbq)) {
  10052. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10053. "0386 ELS complete with no corresponding "
  10054. "cmdiocb: iotag (%d)\n",
  10055. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10056. lpfc_sli_release_iocbq(phba, irspiocbq);
  10057. return NULL;
  10058. }
  10059. /* Fake the irspiocbq and copy necessary response information */
  10060. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  10061. return irspiocbq;
  10062. }
  10063. /**
  10064. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  10065. * @phba: Pointer to HBA context object.
  10066. * @cqe: Pointer to mailbox completion queue entry.
  10067. *
  10068. * This routine process a mailbox completion queue entry with asynchrous
  10069. * event.
  10070. *
  10071. * Return: true if work posted to worker thread, otherwise false.
  10072. **/
  10073. static bool
  10074. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10075. {
  10076. struct lpfc_cq_event *cq_event;
  10077. unsigned long iflags;
  10078. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  10079. "0392 Async Event: word0:x%x, word1:x%x, "
  10080. "word2:x%x, word3:x%x\n", mcqe->word0,
  10081. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  10082. /* Allocate a new internal CQ_EVENT entry */
  10083. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10084. if (!cq_event) {
  10085. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10086. "0394 Failed to allocate CQ_EVENT entry\n");
  10087. return false;
  10088. }
  10089. /* Move the CQE into an asynchronous event entry */
  10090. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  10091. spin_lock_irqsave(&phba->hbalock, iflags);
  10092. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  10093. /* Set the async event flag */
  10094. phba->hba_flag |= ASYNC_EVENT;
  10095. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10096. return true;
  10097. }
  10098. /**
  10099. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  10100. * @phba: Pointer to HBA context object.
  10101. * @cqe: Pointer to mailbox completion queue entry.
  10102. *
  10103. * This routine process a mailbox completion queue entry with mailbox
  10104. * completion event.
  10105. *
  10106. * Return: true if work posted to worker thread, otherwise false.
  10107. **/
  10108. static bool
  10109. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10110. {
  10111. uint32_t mcqe_status;
  10112. MAILBOX_t *mbox, *pmbox;
  10113. struct lpfc_mqe *mqe;
  10114. struct lpfc_vport *vport;
  10115. struct lpfc_nodelist *ndlp;
  10116. struct lpfc_dmabuf *mp;
  10117. unsigned long iflags;
  10118. LPFC_MBOXQ_t *pmb;
  10119. bool workposted = false;
  10120. int rc;
  10121. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  10122. if (!bf_get(lpfc_trailer_completed, mcqe))
  10123. goto out_no_mqe_complete;
  10124. /* Get the reference to the active mbox command */
  10125. spin_lock_irqsave(&phba->hbalock, iflags);
  10126. pmb = phba->sli.mbox_active;
  10127. if (unlikely(!pmb)) {
  10128. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10129. "1832 No pending MBOX command to handle\n");
  10130. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10131. goto out_no_mqe_complete;
  10132. }
  10133. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10134. mqe = &pmb->u.mqe;
  10135. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  10136. mbox = phba->mbox;
  10137. vport = pmb->vport;
  10138. /* Reset heartbeat timer */
  10139. phba->last_completion_time = jiffies;
  10140. del_timer(&phba->sli.mbox_tmo);
  10141. /* Move mbox data to caller's mailbox region, do endian swapping */
  10142. if (pmb->mbox_cmpl && mbox)
  10143. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  10144. /*
  10145. * For mcqe errors, conditionally move a modified error code to
  10146. * the mbox so that the error will not be missed.
  10147. */
  10148. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  10149. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  10150. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  10151. bf_set(lpfc_mqe_status, mqe,
  10152. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  10153. }
  10154. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10155. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10156. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  10157. "MBOX dflt rpi: status:x%x rpi:x%x",
  10158. mcqe_status,
  10159. pmbox->un.varWords[0], 0);
  10160. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  10161. mp = (struct lpfc_dmabuf *)(pmb->context1);
  10162. ndlp = (struct lpfc_nodelist *)pmb->context2;
  10163. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  10164. * RID of the PPI using the same mbox buffer.
  10165. */
  10166. lpfc_unreg_login(phba, vport->vpi,
  10167. pmbox->un.varWords[0], pmb);
  10168. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  10169. pmb->context1 = mp;
  10170. pmb->context2 = ndlp;
  10171. pmb->vport = vport;
  10172. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  10173. if (rc != MBX_BUSY)
  10174. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10175. LOG_SLI, "0385 rc should "
  10176. "have been MBX_BUSY\n");
  10177. if (rc != MBX_NOT_FINISHED)
  10178. goto send_current_mbox;
  10179. }
  10180. }
  10181. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  10182. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  10183. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  10184. /* There is mailbox completion work to do */
  10185. spin_lock_irqsave(&phba->hbalock, iflags);
  10186. __lpfc_mbox_cmpl_put(phba, pmb);
  10187. phba->work_ha |= HA_MBATT;
  10188. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10189. workposted = true;
  10190. send_current_mbox:
  10191. spin_lock_irqsave(&phba->hbalock, iflags);
  10192. /* Release the mailbox command posting token */
  10193. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  10194. /* Setting active mailbox pointer need to be in sync to flag clear */
  10195. phba->sli.mbox_active = NULL;
  10196. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10197. /* Wake up worker thread to post the next pending mailbox command */
  10198. lpfc_worker_wake_up(phba);
  10199. out_no_mqe_complete:
  10200. if (bf_get(lpfc_trailer_consumed, mcqe))
  10201. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  10202. return workposted;
  10203. }
  10204. /**
  10205. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  10206. * @phba: Pointer to HBA context object.
  10207. * @cqe: Pointer to mailbox completion queue entry.
  10208. *
  10209. * This routine process a mailbox completion queue entry, it invokes the
  10210. * proper mailbox complete handling or asynchrous event handling routine
  10211. * according to the MCQE's async bit.
  10212. *
  10213. * Return: true if work posted to worker thread, otherwise false.
  10214. **/
  10215. static bool
  10216. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  10217. {
  10218. struct lpfc_mcqe mcqe;
  10219. bool workposted;
  10220. /* Copy the mailbox MCQE and convert endian order as needed */
  10221. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  10222. /* Invoke the proper event handling routine */
  10223. if (!bf_get(lpfc_trailer_async, &mcqe))
  10224. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  10225. else
  10226. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  10227. return workposted;
  10228. }
  10229. /**
  10230. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  10231. * @phba: Pointer to HBA context object.
  10232. * @cq: Pointer to associated CQ
  10233. * @wcqe: Pointer to work-queue completion queue entry.
  10234. *
  10235. * This routine handles an ELS work-queue completion event.
  10236. *
  10237. * Return: true if work posted to worker thread, otherwise false.
  10238. **/
  10239. static bool
  10240. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10241. struct lpfc_wcqe_complete *wcqe)
  10242. {
  10243. struct lpfc_iocbq *irspiocbq;
  10244. unsigned long iflags;
  10245. struct lpfc_sli_ring *pring = cq->pring;
  10246. /* Get an irspiocbq for later ELS response processing use */
  10247. irspiocbq = lpfc_sli_get_iocbq(phba);
  10248. if (!irspiocbq) {
  10249. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10250. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  10251. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  10252. pring->txq_cnt, phba->iocb_cnt,
  10253. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  10254. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  10255. return false;
  10256. }
  10257. /* Save off the slow-path queue event for work thread to process */
  10258. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  10259. spin_lock_irqsave(&phba->hbalock, iflags);
  10260. list_add_tail(&irspiocbq->cq_event.list,
  10261. &phba->sli4_hba.sp_queue_event);
  10262. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10263. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10264. return true;
  10265. }
  10266. /**
  10267. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  10268. * @phba: Pointer to HBA context object.
  10269. * @wcqe: Pointer to work-queue completion queue entry.
  10270. *
  10271. * This routine handles slow-path WQ entry comsumed event by invoking the
  10272. * proper WQ release routine to the slow-path WQ.
  10273. **/
  10274. static void
  10275. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  10276. struct lpfc_wcqe_release *wcqe)
  10277. {
  10278. /* sanity check on queue memory */
  10279. if (unlikely(!phba->sli4_hba.els_wq))
  10280. return;
  10281. /* Check for the slow-path ELS work queue */
  10282. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  10283. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  10284. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10285. else
  10286. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10287. "2579 Slow-path wqe consume event carries "
  10288. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  10289. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  10290. phba->sli4_hba.els_wq->queue_id);
  10291. }
  10292. /**
  10293. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  10294. * @phba: Pointer to HBA context object.
  10295. * @cq: Pointer to a WQ completion queue.
  10296. * @wcqe: Pointer to work-queue completion queue entry.
  10297. *
  10298. * This routine handles an XRI abort event.
  10299. *
  10300. * Return: true if work posted to worker thread, otherwise false.
  10301. **/
  10302. static bool
  10303. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  10304. struct lpfc_queue *cq,
  10305. struct sli4_wcqe_xri_aborted *wcqe)
  10306. {
  10307. bool workposted = false;
  10308. struct lpfc_cq_event *cq_event;
  10309. unsigned long iflags;
  10310. /* Allocate a new internal CQ_EVENT entry */
  10311. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10312. if (!cq_event) {
  10313. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10314. "0602 Failed to allocate CQ_EVENT entry\n");
  10315. return false;
  10316. }
  10317. /* Move the CQE into the proper xri abort event list */
  10318. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  10319. switch (cq->subtype) {
  10320. case LPFC_FCP:
  10321. spin_lock_irqsave(&phba->hbalock, iflags);
  10322. list_add_tail(&cq_event->list,
  10323. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  10324. /* Set the fcp xri abort event flag */
  10325. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  10326. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10327. workposted = true;
  10328. break;
  10329. case LPFC_ELS:
  10330. spin_lock_irqsave(&phba->hbalock, iflags);
  10331. list_add_tail(&cq_event->list,
  10332. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  10333. /* Set the els xri abort event flag */
  10334. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  10335. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10336. workposted = true;
  10337. break;
  10338. default:
  10339. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10340. "0603 Invalid work queue CQE subtype (x%x)\n",
  10341. cq->subtype);
  10342. workposted = false;
  10343. break;
  10344. }
  10345. return workposted;
  10346. }
  10347. /**
  10348. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  10349. * @phba: Pointer to HBA context object.
  10350. * @rcqe: Pointer to receive-queue completion queue entry.
  10351. *
  10352. * This routine process a receive-queue completion queue entry.
  10353. *
  10354. * Return: true if work posted to worker thread, otherwise false.
  10355. **/
  10356. static bool
  10357. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  10358. {
  10359. bool workposted = false;
  10360. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  10361. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  10362. struct hbq_dmabuf *dma_buf;
  10363. uint32_t status, rq_id;
  10364. unsigned long iflags;
  10365. /* sanity check on queue memory */
  10366. if (unlikely(!hrq) || unlikely(!drq))
  10367. return workposted;
  10368. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  10369. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  10370. else
  10371. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  10372. if (rq_id != hrq->queue_id)
  10373. goto out;
  10374. status = bf_get(lpfc_rcqe_status, rcqe);
  10375. switch (status) {
  10376. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  10377. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10378. "2537 Receive Frame Truncated!!\n");
  10379. hrq->RQ_buf_trunc++;
  10380. case FC_STATUS_RQ_SUCCESS:
  10381. lpfc_sli4_rq_release(hrq, drq);
  10382. spin_lock_irqsave(&phba->hbalock, iflags);
  10383. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  10384. if (!dma_buf) {
  10385. hrq->RQ_no_buf_found++;
  10386. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10387. goto out;
  10388. }
  10389. hrq->RQ_rcv_buf++;
  10390. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  10391. /* save off the frame for the word thread to process */
  10392. list_add_tail(&dma_buf->cq_event.list,
  10393. &phba->sli4_hba.sp_queue_event);
  10394. /* Frame received */
  10395. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10396. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10397. workposted = true;
  10398. break;
  10399. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  10400. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  10401. hrq->RQ_no_posted_buf++;
  10402. /* Post more buffers if possible */
  10403. spin_lock_irqsave(&phba->hbalock, iflags);
  10404. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  10405. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10406. workposted = true;
  10407. break;
  10408. }
  10409. out:
  10410. return workposted;
  10411. }
  10412. /**
  10413. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  10414. * @phba: Pointer to HBA context object.
  10415. * @cq: Pointer to the completion queue.
  10416. * @wcqe: Pointer to a completion queue entry.
  10417. *
  10418. * This routine process a slow-path work-queue or receive queue completion queue
  10419. * entry.
  10420. *
  10421. * Return: true if work posted to worker thread, otherwise false.
  10422. **/
  10423. static bool
  10424. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10425. struct lpfc_cqe *cqe)
  10426. {
  10427. struct lpfc_cqe cqevt;
  10428. bool workposted = false;
  10429. /* Copy the work queue CQE and convert endian order if needed */
  10430. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  10431. /* Check and process for different type of WCQE and dispatch */
  10432. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  10433. case CQE_CODE_COMPL_WQE:
  10434. /* Process the WQ/RQ complete event */
  10435. phba->last_completion_time = jiffies;
  10436. workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
  10437. (struct lpfc_wcqe_complete *)&cqevt);
  10438. break;
  10439. case CQE_CODE_RELEASE_WQE:
  10440. /* Process the WQ release event */
  10441. lpfc_sli4_sp_handle_rel_wcqe(phba,
  10442. (struct lpfc_wcqe_release *)&cqevt);
  10443. break;
  10444. case CQE_CODE_XRI_ABORTED:
  10445. /* Process the WQ XRI abort event */
  10446. phba->last_completion_time = jiffies;
  10447. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10448. (struct sli4_wcqe_xri_aborted *)&cqevt);
  10449. break;
  10450. case CQE_CODE_RECEIVE:
  10451. case CQE_CODE_RECEIVE_V1:
  10452. /* Process the RQ event */
  10453. phba->last_completion_time = jiffies;
  10454. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  10455. (struct lpfc_rcqe *)&cqevt);
  10456. break;
  10457. default:
  10458. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10459. "0388 Not a valid WCQE code: x%x\n",
  10460. bf_get(lpfc_cqe_code, &cqevt));
  10461. break;
  10462. }
  10463. return workposted;
  10464. }
  10465. /**
  10466. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  10467. * @phba: Pointer to HBA context object.
  10468. * @eqe: Pointer to fast-path event queue entry.
  10469. *
  10470. * This routine process a event queue entry from the slow-path event queue.
  10471. * It will check the MajorCode and MinorCode to determine this is for a
  10472. * completion event on a completion queue, if not, an error shall be logged
  10473. * and just return. Otherwise, it will get to the corresponding completion
  10474. * queue and process all the entries on that completion queue, rearm the
  10475. * completion queue, and then return.
  10476. *
  10477. **/
  10478. static void
  10479. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10480. struct lpfc_queue *speq)
  10481. {
  10482. struct lpfc_queue *cq = NULL, *childq;
  10483. struct lpfc_cqe *cqe;
  10484. bool workposted = false;
  10485. int ecount = 0;
  10486. uint16_t cqid;
  10487. /* Get the reference to the corresponding CQ */
  10488. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10489. list_for_each_entry(childq, &speq->child_list, list) {
  10490. if (childq->queue_id == cqid) {
  10491. cq = childq;
  10492. break;
  10493. }
  10494. }
  10495. if (unlikely(!cq)) {
  10496. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10497. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10498. "0365 Slow-path CQ identifier "
  10499. "(%d) does not exist\n", cqid);
  10500. return;
  10501. }
  10502. /* Process all the entries to the CQ */
  10503. switch (cq->type) {
  10504. case LPFC_MCQ:
  10505. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10506. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  10507. if (!(++ecount % cq->entry_repost))
  10508. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10509. cq->CQ_mbox++;
  10510. }
  10511. break;
  10512. case LPFC_WCQ:
  10513. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10514. if (cq->subtype == LPFC_FCP)
  10515. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  10516. cqe);
  10517. else
  10518. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  10519. cqe);
  10520. if (!(++ecount % cq->entry_repost))
  10521. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10522. }
  10523. /* Track the max number of CQEs processed in 1 EQ */
  10524. if (ecount > cq->CQ_max_cqe)
  10525. cq->CQ_max_cqe = ecount;
  10526. break;
  10527. default:
  10528. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10529. "0370 Invalid completion queue type (%d)\n",
  10530. cq->type);
  10531. return;
  10532. }
  10533. /* Catch the no cq entry condition, log an error */
  10534. if (unlikely(ecount == 0))
  10535. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10536. "0371 No entry from the CQ: identifier "
  10537. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  10538. /* In any case, flash and re-arm the RCQ */
  10539. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10540. /* wake up worker thread if there are works to be done */
  10541. if (workposted)
  10542. lpfc_worker_wake_up(phba);
  10543. }
  10544. /**
  10545. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  10546. * @phba: Pointer to HBA context object.
  10547. * @cq: Pointer to associated CQ
  10548. * @wcqe: Pointer to work-queue completion queue entry.
  10549. *
  10550. * This routine process a fast-path work queue completion entry from fast-path
  10551. * event queue for FCP command response completion.
  10552. **/
  10553. static void
  10554. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10555. struct lpfc_wcqe_complete *wcqe)
  10556. {
  10557. struct lpfc_sli_ring *pring = cq->pring;
  10558. struct lpfc_iocbq *cmdiocbq;
  10559. struct lpfc_iocbq irspiocbq;
  10560. unsigned long iflags;
  10561. /* Check for response status */
  10562. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  10563. /* If resource errors reported from HBA, reduce queue
  10564. * depth of the SCSI device.
  10565. */
  10566. if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
  10567. IOSTAT_LOCAL_REJECT)) &&
  10568. ((wcqe->parameter & IOERR_PARAM_MASK) ==
  10569. IOERR_NO_RESOURCES))
  10570. phba->lpfc_rampdown_queue_depth(phba);
  10571. /* Log the error status */
  10572. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10573. "0373 FCP complete error: status=x%x, "
  10574. "hw_status=x%x, total_data_specified=%d, "
  10575. "parameter=x%x, word3=x%x\n",
  10576. bf_get(lpfc_wcqe_c_status, wcqe),
  10577. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  10578. wcqe->total_data_placed, wcqe->parameter,
  10579. wcqe->word3);
  10580. }
  10581. /* Look up the FCP command IOCB and create pseudo response IOCB */
  10582. spin_lock_irqsave(&pring->ring_lock, iflags);
  10583. pring->stats.iocb_event++;
  10584. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10585. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10586. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10587. if (unlikely(!cmdiocbq)) {
  10588. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10589. "0374 FCP complete with no corresponding "
  10590. "cmdiocb: iotag (%d)\n",
  10591. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10592. return;
  10593. }
  10594. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  10595. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10596. "0375 FCP cmdiocb not callback function "
  10597. "iotag: (%d)\n",
  10598. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10599. return;
  10600. }
  10601. /* Fake the irspiocb and copy necessary response information */
  10602. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  10603. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  10604. spin_lock_irqsave(&phba->hbalock, iflags);
  10605. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  10606. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10607. }
  10608. /* Pass the cmd_iocb and the rsp state to the upper layer */
  10609. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  10610. }
  10611. /**
  10612. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  10613. * @phba: Pointer to HBA context object.
  10614. * @cq: Pointer to completion queue.
  10615. * @wcqe: Pointer to work-queue completion queue entry.
  10616. *
  10617. * This routine handles an fast-path WQ entry comsumed event by invoking the
  10618. * proper WQ release routine to the slow-path WQ.
  10619. **/
  10620. static void
  10621. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10622. struct lpfc_wcqe_release *wcqe)
  10623. {
  10624. struct lpfc_queue *childwq;
  10625. bool wqid_matched = false;
  10626. uint16_t fcp_wqid;
  10627. /* Check for fast-path FCP work queue release */
  10628. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  10629. list_for_each_entry(childwq, &cq->child_list, list) {
  10630. if (childwq->queue_id == fcp_wqid) {
  10631. lpfc_sli4_wq_release(childwq,
  10632. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10633. wqid_matched = true;
  10634. break;
  10635. }
  10636. }
  10637. /* Report warning log message if no match found */
  10638. if (wqid_matched != true)
  10639. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10640. "2580 Fast-path wqe consume event carries "
  10641. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  10642. }
  10643. /**
  10644. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  10645. * @cq: Pointer to the completion queue.
  10646. * @eqe: Pointer to fast-path completion queue entry.
  10647. *
  10648. * This routine process a fast-path work queue completion entry from fast-path
  10649. * event queue for FCP command response completion.
  10650. **/
  10651. static int
  10652. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10653. struct lpfc_cqe *cqe)
  10654. {
  10655. struct lpfc_wcqe_release wcqe;
  10656. bool workposted = false;
  10657. /* Copy the work queue CQE and convert endian order if needed */
  10658. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  10659. /* Check and process for different type of WCQE and dispatch */
  10660. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  10661. case CQE_CODE_COMPL_WQE:
  10662. cq->CQ_wq++;
  10663. /* Process the WQ complete event */
  10664. phba->last_completion_time = jiffies;
  10665. lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
  10666. (struct lpfc_wcqe_complete *)&wcqe);
  10667. break;
  10668. case CQE_CODE_RELEASE_WQE:
  10669. cq->CQ_release_wqe++;
  10670. /* Process the WQ release event */
  10671. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  10672. (struct lpfc_wcqe_release *)&wcqe);
  10673. break;
  10674. case CQE_CODE_XRI_ABORTED:
  10675. cq->CQ_xri_aborted++;
  10676. /* Process the WQ XRI abort event */
  10677. phba->last_completion_time = jiffies;
  10678. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10679. (struct sli4_wcqe_xri_aborted *)&wcqe);
  10680. break;
  10681. default:
  10682. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10683. "0144 Not a valid WCQE code: x%x\n",
  10684. bf_get(lpfc_wcqe_c_code, &wcqe));
  10685. break;
  10686. }
  10687. return workposted;
  10688. }
  10689. /**
  10690. * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
  10691. * @phba: Pointer to HBA context object.
  10692. * @eqe: Pointer to fast-path event queue entry.
  10693. *
  10694. * This routine process a event queue entry from the fast-path event queue.
  10695. * It will check the MajorCode and MinorCode to determine this is for a
  10696. * completion event on a completion queue, if not, an error shall be logged
  10697. * and just return. Otherwise, it will get to the corresponding completion
  10698. * queue and process all the entries on the completion queue, rearm the
  10699. * completion queue, and then return.
  10700. **/
  10701. static void
  10702. lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10703. uint32_t qidx)
  10704. {
  10705. struct lpfc_queue *cq;
  10706. struct lpfc_cqe *cqe;
  10707. bool workposted = false;
  10708. uint16_t cqid;
  10709. int ecount = 0;
  10710. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  10711. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10712. "0366 Not a valid completion "
  10713. "event: majorcode=x%x, minorcode=x%x\n",
  10714. bf_get_le32(lpfc_eqe_major_code, eqe),
  10715. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10716. return;
  10717. }
  10718. /* Get the reference to the corresponding CQ */
  10719. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10720. /* Check if this is a Slow path event */
  10721. if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) {
  10722. lpfc_sli4_sp_handle_eqe(phba, eqe,
  10723. phba->sli4_hba.hba_eq[qidx]);
  10724. return;
  10725. }
  10726. if (unlikely(!phba->sli4_hba.fcp_cq)) {
  10727. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10728. "3146 Fast-path completion queues "
  10729. "does not exist\n");
  10730. return;
  10731. }
  10732. cq = phba->sli4_hba.fcp_cq[qidx];
  10733. if (unlikely(!cq)) {
  10734. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10735. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10736. "0367 Fast-path completion queue "
  10737. "(%d) does not exist\n", qidx);
  10738. return;
  10739. }
  10740. if (unlikely(cqid != cq->queue_id)) {
  10741. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10742. "0368 Miss-matched fast-path completion "
  10743. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  10744. cqid, cq->queue_id);
  10745. return;
  10746. }
  10747. /* Process all the entries to the CQ */
  10748. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10749. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  10750. if (!(++ecount % cq->entry_repost))
  10751. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10752. }
  10753. /* Track the max number of CQEs processed in 1 EQ */
  10754. if (ecount > cq->CQ_max_cqe)
  10755. cq->CQ_max_cqe = ecount;
  10756. /* Catch the no cq entry condition */
  10757. if (unlikely(ecount == 0))
  10758. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10759. "0369 No entry from fast-path completion "
  10760. "queue fcpcqid=%d\n", cq->queue_id);
  10761. /* In any case, flash and re-arm the CQ */
  10762. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10763. /* wake up worker thread if there are works to be done */
  10764. if (workposted)
  10765. lpfc_worker_wake_up(phba);
  10766. }
  10767. static void
  10768. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10769. {
  10770. struct lpfc_eqe *eqe;
  10771. /* walk all the EQ entries and drop on the floor */
  10772. while ((eqe = lpfc_sli4_eq_get(eq)))
  10773. ;
  10774. /* Clear and re-arm the EQ */
  10775. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  10776. }
  10777. /**
  10778. * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
  10779. * @irq: Interrupt number.
  10780. * @dev_id: The device context pointer.
  10781. *
  10782. * This function is directly called from the PCI layer as an interrupt
  10783. * service routine when device with SLI-4 interface spec is enabled with
  10784. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10785. * ring event in the HBA. However, when the device is enabled with either
  10786. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10787. * device-level interrupt handler. When the PCI slot is in error recovery
  10788. * or the HBA is undergoing initialization, the interrupt handler will not
  10789. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10790. * the intrrupt context. This function is called without any lock held.
  10791. * It gets the hbalock to access and update SLI data structures. Note that,
  10792. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  10793. * equal to that of FCP CQ index.
  10794. *
  10795. * The link attention and ELS ring attention events are handled
  10796. * by the worker thread. The interrupt handler signals the worker thread
  10797. * and returns for these events. This function is called without any lock
  10798. * held. It gets the hbalock to access and update SLI data structures.
  10799. *
  10800. * This function returns IRQ_HANDLED when interrupt is handled else it
  10801. * returns IRQ_NONE.
  10802. **/
  10803. irqreturn_t
  10804. lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
  10805. {
  10806. struct lpfc_hba *phba;
  10807. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  10808. struct lpfc_queue *fpeq;
  10809. struct lpfc_eqe *eqe;
  10810. unsigned long iflag;
  10811. int ecount = 0;
  10812. uint32_t fcp_eqidx;
  10813. /* Get the driver's phba structure from the dev_id */
  10814. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  10815. phba = fcp_eq_hdl->phba;
  10816. fcp_eqidx = fcp_eq_hdl->idx;
  10817. if (unlikely(!phba))
  10818. return IRQ_NONE;
  10819. if (unlikely(!phba->sli4_hba.hba_eq))
  10820. return IRQ_NONE;
  10821. /* Get to the EQ struct associated with this vector */
  10822. fpeq = phba->sli4_hba.hba_eq[fcp_eqidx];
  10823. if (unlikely(!fpeq))
  10824. return IRQ_NONE;
  10825. if (lpfc_fcp_look_ahead) {
  10826. if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use))
  10827. lpfc_sli4_eq_clr_intr(fpeq);
  10828. else {
  10829. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10830. return IRQ_NONE;
  10831. }
  10832. }
  10833. /* Check device state for handling interrupt */
  10834. if (unlikely(lpfc_intr_state_check(phba))) {
  10835. fpeq->EQ_badstate++;
  10836. /* Check again for link_state with lock held */
  10837. spin_lock_irqsave(&phba->hbalock, iflag);
  10838. if (phba->link_state < LPFC_LINK_DOWN)
  10839. /* Flush, clear interrupt, and rearm the EQ */
  10840. lpfc_sli4_eq_flush(phba, fpeq);
  10841. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10842. if (lpfc_fcp_look_ahead)
  10843. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10844. return IRQ_NONE;
  10845. }
  10846. /*
  10847. * Process all the event on FCP fast-path EQ
  10848. */
  10849. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  10850. lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx);
  10851. if (!(++ecount % fpeq->entry_repost))
  10852. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  10853. fpeq->EQ_processed++;
  10854. }
  10855. /* Track the max number of EQEs processed in 1 intr */
  10856. if (ecount > fpeq->EQ_max_eqe)
  10857. fpeq->EQ_max_eqe = ecount;
  10858. /* Always clear and re-arm the fast-path EQ */
  10859. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  10860. if (unlikely(ecount == 0)) {
  10861. fpeq->EQ_no_entry++;
  10862. if (lpfc_fcp_look_ahead) {
  10863. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10864. return IRQ_NONE;
  10865. }
  10866. if (phba->intr_type == MSIX)
  10867. /* MSI-X treated interrupt served as no EQ share INT */
  10868. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10869. "0358 MSI-X interrupt with no EQE\n");
  10870. else
  10871. /* Non MSI-X treated on interrupt as EQ share INT */
  10872. return IRQ_NONE;
  10873. }
  10874. if (lpfc_fcp_look_ahead)
  10875. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10876. return IRQ_HANDLED;
  10877. } /* lpfc_sli4_fp_intr_handler */
  10878. /**
  10879. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  10880. * @irq: Interrupt number.
  10881. * @dev_id: The device context pointer.
  10882. *
  10883. * This function is the device-level interrupt handler to device with SLI-4
  10884. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  10885. * interrupt mode is enabled and there is an event in the HBA which requires
  10886. * driver attention. This function invokes the slow-path interrupt attention
  10887. * handling function and fast-path interrupt attention handling function in
  10888. * turn to process the relevant HBA attention events. This function is called
  10889. * without any lock held. It gets the hbalock to access and update SLI data
  10890. * structures.
  10891. *
  10892. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10893. * returns IRQ_NONE.
  10894. **/
  10895. irqreturn_t
  10896. lpfc_sli4_intr_handler(int irq, void *dev_id)
  10897. {
  10898. struct lpfc_hba *phba;
  10899. irqreturn_t hba_irq_rc;
  10900. bool hba_handled = false;
  10901. uint32_t fcp_eqidx;
  10902. /* Get the driver's phba structure from the dev_id */
  10903. phba = (struct lpfc_hba *)dev_id;
  10904. if (unlikely(!phba))
  10905. return IRQ_NONE;
  10906. /*
  10907. * Invoke fast-path host attention interrupt handling as appropriate.
  10908. */
  10909. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
  10910. hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
  10911. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  10912. if (hba_irq_rc == IRQ_HANDLED)
  10913. hba_handled |= true;
  10914. }
  10915. return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
  10916. } /* lpfc_sli4_intr_handler */
  10917. /**
  10918. * lpfc_sli4_queue_free - free a queue structure and associated memory
  10919. * @queue: The queue structure to free.
  10920. *
  10921. * This function frees a queue structure and the DMAable memory used for
  10922. * the host resident queue. This function must be called after destroying the
  10923. * queue on the HBA.
  10924. **/
  10925. void
  10926. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  10927. {
  10928. struct lpfc_dmabuf *dmabuf;
  10929. if (!queue)
  10930. return;
  10931. while (!list_empty(&queue->page_list)) {
  10932. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  10933. list);
  10934. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  10935. dmabuf->virt, dmabuf->phys);
  10936. kfree(dmabuf);
  10937. }
  10938. kfree(queue);
  10939. return;
  10940. }
  10941. /**
  10942. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  10943. * @phba: The HBA that this queue is being created on.
  10944. * @entry_size: The size of each queue entry for this queue.
  10945. * @entry count: The number of entries that this queue will handle.
  10946. *
  10947. * This function allocates a queue structure and the DMAable memory used for
  10948. * the host resident queue. This function must be called before creating the
  10949. * queue on the HBA.
  10950. **/
  10951. struct lpfc_queue *
  10952. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  10953. uint32_t entry_count)
  10954. {
  10955. struct lpfc_queue *queue;
  10956. struct lpfc_dmabuf *dmabuf;
  10957. int x, total_qe_count;
  10958. void *dma_pointer;
  10959. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10960. if (!phba->sli4_hba.pc_sli4_params.supported)
  10961. hw_page_size = SLI4_PAGE_SIZE;
  10962. queue = kzalloc(sizeof(struct lpfc_queue) +
  10963. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  10964. if (!queue)
  10965. return NULL;
  10966. queue->page_count = (ALIGN(entry_size * entry_count,
  10967. hw_page_size))/hw_page_size;
  10968. INIT_LIST_HEAD(&queue->list);
  10969. INIT_LIST_HEAD(&queue->page_list);
  10970. INIT_LIST_HEAD(&queue->child_list);
  10971. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  10972. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  10973. if (!dmabuf)
  10974. goto out_fail;
  10975. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  10976. hw_page_size, &dmabuf->phys,
  10977. GFP_KERNEL);
  10978. if (!dmabuf->virt) {
  10979. kfree(dmabuf);
  10980. goto out_fail;
  10981. }
  10982. memset(dmabuf->virt, 0, hw_page_size);
  10983. dmabuf->buffer_tag = x;
  10984. list_add_tail(&dmabuf->list, &queue->page_list);
  10985. /* initialize queue's entry array */
  10986. dma_pointer = dmabuf->virt;
  10987. for (; total_qe_count < entry_count &&
  10988. dma_pointer < (hw_page_size + dmabuf->virt);
  10989. total_qe_count++, dma_pointer += entry_size) {
  10990. queue->qe[total_qe_count].address = dma_pointer;
  10991. }
  10992. }
  10993. queue->entry_size = entry_size;
  10994. queue->entry_count = entry_count;
  10995. /*
  10996. * entry_repost is calculated based on the number of entries in the
  10997. * queue. This works out except for RQs. If buffers are NOT initially
  10998. * posted for every RQE, entry_repost should be adjusted accordingly.
  10999. */
  11000. queue->entry_repost = (entry_count >> 3);
  11001. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  11002. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  11003. queue->phba = phba;
  11004. return queue;
  11005. out_fail:
  11006. lpfc_sli4_queue_free(queue);
  11007. return NULL;
  11008. }
  11009. /**
  11010. * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
  11011. * @phba: HBA structure that indicates port to create a queue on.
  11012. * @startq: The starting FCP EQ to modify
  11013. *
  11014. * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
  11015. *
  11016. * The @phba struct is used to send mailbox command to HBA. The @startq
  11017. * is used to get the starting FCP EQ to change.
  11018. * This function is asynchronous and will wait for the mailbox
  11019. * command to finish before continuing.
  11020. *
  11021. * On success this function will return a zero. If unable to allocate enough
  11022. * memory this function will return -ENOMEM. If the queue create mailbox command
  11023. * fails this function will return -ENXIO.
  11024. **/
  11025. uint32_t
  11026. lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq)
  11027. {
  11028. struct lpfc_mbx_modify_eq_delay *eq_delay;
  11029. LPFC_MBOXQ_t *mbox;
  11030. struct lpfc_queue *eq;
  11031. int cnt, rc, length, status = 0;
  11032. uint32_t shdr_status, shdr_add_status;
  11033. uint32_t result;
  11034. int fcp_eqidx;
  11035. union lpfc_sli4_cfg_shdr *shdr;
  11036. uint16_t dmult;
  11037. if (startq >= phba->cfg_fcp_io_channel)
  11038. return 0;
  11039. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11040. if (!mbox)
  11041. return -ENOMEM;
  11042. length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
  11043. sizeof(struct lpfc_sli4_cfg_mhdr));
  11044. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11045. LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
  11046. length, LPFC_SLI4_MBX_EMBED);
  11047. eq_delay = &mbox->u.mqe.un.eq_delay;
  11048. /* Calculate delay multiper from maximum interrupt per second */
  11049. result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel;
  11050. if (result > LPFC_DMULT_CONST)
  11051. dmult = 0;
  11052. else
  11053. dmult = LPFC_DMULT_CONST/result - 1;
  11054. cnt = 0;
  11055. for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel;
  11056. fcp_eqidx++) {
  11057. eq = phba->sli4_hba.hba_eq[fcp_eqidx];
  11058. if (!eq)
  11059. continue;
  11060. eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
  11061. eq_delay->u.request.eq[cnt].phase = 0;
  11062. eq_delay->u.request.eq[cnt].delay_multi = dmult;
  11063. cnt++;
  11064. if (cnt >= LPFC_MAX_EQ_DELAY)
  11065. break;
  11066. }
  11067. eq_delay->u.request.num_eq = cnt;
  11068. mbox->vport = phba->pport;
  11069. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11070. mbox->context1 = NULL;
  11071. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11072. shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
  11073. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11074. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11075. if (shdr_status || shdr_add_status || rc) {
  11076. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11077. "2512 MODIFY_EQ_DELAY mailbox failed with "
  11078. "status x%x add_status x%x, mbx status x%x\n",
  11079. shdr_status, shdr_add_status, rc);
  11080. status = -ENXIO;
  11081. }
  11082. mempool_free(mbox, phba->mbox_mem_pool);
  11083. return status;
  11084. }
  11085. /**
  11086. * lpfc_eq_create - Create an Event Queue on the HBA
  11087. * @phba: HBA structure that indicates port to create a queue on.
  11088. * @eq: The queue structure to use to create the event queue.
  11089. * @imax: The maximum interrupt per second limit.
  11090. *
  11091. * This function creates an event queue, as detailed in @eq, on a port,
  11092. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  11093. *
  11094. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  11095. * is used to get the entry count and entry size that are necessary to
  11096. * determine the number of pages to allocate and use for this queue. This
  11097. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  11098. * event queue. This function is asynchronous and will wait for the mailbox
  11099. * command to finish before continuing.
  11100. *
  11101. * On success this function will return a zero. If unable to allocate enough
  11102. * memory this function will return -ENOMEM. If the queue create mailbox command
  11103. * fails this function will return -ENXIO.
  11104. **/
  11105. uint32_t
  11106. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
  11107. {
  11108. struct lpfc_mbx_eq_create *eq_create;
  11109. LPFC_MBOXQ_t *mbox;
  11110. int rc, length, status = 0;
  11111. struct lpfc_dmabuf *dmabuf;
  11112. uint32_t shdr_status, shdr_add_status;
  11113. union lpfc_sli4_cfg_shdr *shdr;
  11114. uint16_t dmult;
  11115. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11116. /* sanity check on queue memory */
  11117. if (!eq)
  11118. return -ENODEV;
  11119. if (!phba->sli4_hba.pc_sli4_params.supported)
  11120. hw_page_size = SLI4_PAGE_SIZE;
  11121. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11122. if (!mbox)
  11123. return -ENOMEM;
  11124. length = (sizeof(struct lpfc_mbx_eq_create) -
  11125. sizeof(struct lpfc_sli4_cfg_mhdr));
  11126. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11127. LPFC_MBOX_OPCODE_EQ_CREATE,
  11128. length, LPFC_SLI4_MBX_EMBED);
  11129. eq_create = &mbox->u.mqe.un.eq_create;
  11130. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  11131. eq->page_count);
  11132. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  11133. LPFC_EQE_SIZE);
  11134. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  11135. /* Calculate delay multiper from maximum interrupt per second */
  11136. if (imax > LPFC_DMULT_CONST)
  11137. dmult = 0;
  11138. else
  11139. dmult = LPFC_DMULT_CONST/imax - 1;
  11140. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  11141. dmult);
  11142. switch (eq->entry_count) {
  11143. default:
  11144. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11145. "0360 Unsupported EQ count. (%d)\n",
  11146. eq->entry_count);
  11147. if (eq->entry_count < 256)
  11148. return -EINVAL;
  11149. /* otherwise default to smallest count (drop through) */
  11150. case 256:
  11151. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11152. LPFC_EQ_CNT_256);
  11153. break;
  11154. case 512:
  11155. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11156. LPFC_EQ_CNT_512);
  11157. break;
  11158. case 1024:
  11159. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11160. LPFC_EQ_CNT_1024);
  11161. break;
  11162. case 2048:
  11163. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11164. LPFC_EQ_CNT_2048);
  11165. break;
  11166. case 4096:
  11167. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11168. LPFC_EQ_CNT_4096);
  11169. break;
  11170. }
  11171. list_for_each_entry(dmabuf, &eq->page_list, list) {
  11172. memset(dmabuf->virt, 0, hw_page_size);
  11173. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11174. putPaddrLow(dmabuf->phys);
  11175. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11176. putPaddrHigh(dmabuf->phys);
  11177. }
  11178. mbox->vport = phba->pport;
  11179. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11180. mbox->context1 = NULL;
  11181. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11182. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  11183. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11184. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11185. if (shdr_status || shdr_add_status || rc) {
  11186. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11187. "2500 EQ_CREATE mailbox failed with "
  11188. "status x%x add_status x%x, mbx status x%x\n",
  11189. shdr_status, shdr_add_status, rc);
  11190. status = -ENXIO;
  11191. }
  11192. eq->type = LPFC_EQ;
  11193. eq->subtype = LPFC_NONE;
  11194. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  11195. if (eq->queue_id == 0xFFFF)
  11196. status = -ENXIO;
  11197. eq->host_index = 0;
  11198. eq->hba_index = 0;
  11199. mempool_free(mbox, phba->mbox_mem_pool);
  11200. return status;
  11201. }
  11202. /**
  11203. * lpfc_cq_create - Create a Completion Queue on the HBA
  11204. * @phba: HBA structure that indicates port to create a queue on.
  11205. * @cq: The queue structure to use to create the completion queue.
  11206. * @eq: The event queue to bind this completion queue to.
  11207. *
  11208. * This function creates a completion queue, as detailed in @wq, on a port,
  11209. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  11210. *
  11211. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11212. * is used to get the entry count and entry size that are necessary to
  11213. * determine the number of pages to allocate and use for this queue. The @eq
  11214. * is used to indicate which event queue to bind this completion queue to. This
  11215. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  11216. * completion queue. This function is asynchronous and will wait for the mailbox
  11217. * command to finish before continuing.
  11218. *
  11219. * On success this function will return a zero. If unable to allocate enough
  11220. * memory this function will return -ENOMEM. If the queue create mailbox command
  11221. * fails this function will return -ENXIO.
  11222. **/
  11223. uint32_t
  11224. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11225. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  11226. {
  11227. struct lpfc_mbx_cq_create *cq_create;
  11228. struct lpfc_dmabuf *dmabuf;
  11229. LPFC_MBOXQ_t *mbox;
  11230. int rc, length, status = 0;
  11231. uint32_t shdr_status, shdr_add_status;
  11232. union lpfc_sli4_cfg_shdr *shdr;
  11233. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11234. /* sanity check on queue memory */
  11235. if (!cq || !eq)
  11236. return -ENODEV;
  11237. if (!phba->sli4_hba.pc_sli4_params.supported)
  11238. hw_page_size = SLI4_PAGE_SIZE;
  11239. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11240. if (!mbox)
  11241. return -ENOMEM;
  11242. length = (sizeof(struct lpfc_mbx_cq_create) -
  11243. sizeof(struct lpfc_sli4_cfg_mhdr));
  11244. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11245. LPFC_MBOX_OPCODE_CQ_CREATE,
  11246. length, LPFC_SLI4_MBX_EMBED);
  11247. cq_create = &mbox->u.mqe.un.cq_create;
  11248. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  11249. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  11250. cq->page_count);
  11251. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  11252. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  11253. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11254. phba->sli4_hba.pc_sli4_params.cqv);
  11255. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  11256. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  11257. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  11258. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  11259. eq->queue_id);
  11260. } else {
  11261. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  11262. eq->queue_id);
  11263. }
  11264. switch (cq->entry_count) {
  11265. default:
  11266. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11267. "0361 Unsupported CQ count. (%d)\n",
  11268. cq->entry_count);
  11269. if (cq->entry_count < 256) {
  11270. status = -EINVAL;
  11271. goto out;
  11272. }
  11273. /* otherwise default to smallest count (drop through) */
  11274. case 256:
  11275. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11276. LPFC_CQ_CNT_256);
  11277. break;
  11278. case 512:
  11279. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11280. LPFC_CQ_CNT_512);
  11281. break;
  11282. case 1024:
  11283. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11284. LPFC_CQ_CNT_1024);
  11285. break;
  11286. }
  11287. list_for_each_entry(dmabuf, &cq->page_list, list) {
  11288. memset(dmabuf->virt, 0, hw_page_size);
  11289. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11290. putPaddrLow(dmabuf->phys);
  11291. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11292. putPaddrHigh(dmabuf->phys);
  11293. }
  11294. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11295. /* The IOCTL status is embedded in the mailbox subheader. */
  11296. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11297. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11298. if (shdr_status || shdr_add_status || rc) {
  11299. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11300. "2501 CQ_CREATE mailbox failed with "
  11301. "status x%x add_status x%x, mbx status x%x\n",
  11302. shdr_status, shdr_add_status, rc);
  11303. status = -ENXIO;
  11304. goto out;
  11305. }
  11306. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11307. if (cq->queue_id == 0xFFFF) {
  11308. status = -ENXIO;
  11309. goto out;
  11310. }
  11311. /* link the cq onto the parent eq child list */
  11312. list_add_tail(&cq->list, &eq->child_list);
  11313. /* Set up completion queue's type and subtype */
  11314. cq->type = type;
  11315. cq->subtype = subtype;
  11316. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11317. cq->assoc_qid = eq->queue_id;
  11318. cq->host_index = 0;
  11319. cq->hba_index = 0;
  11320. out:
  11321. mempool_free(mbox, phba->mbox_mem_pool);
  11322. return status;
  11323. }
  11324. /**
  11325. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  11326. * @phba: HBA structure that indicates port to create a queue on.
  11327. * @mq: The queue structure to use to create the mailbox queue.
  11328. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  11329. * @cq: The completion queue to associate with this cq.
  11330. *
  11331. * This function provides failback (fb) functionality when the
  11332. * mq_create_ext fails on older FW generations. It's purpose is identical
  11333. * to mq_create_ext otherwise.
  11334. *
  11335. * This routine cannot fail as all attributes were previously accessed and
  11336. * initialized in mq_create_ext.
  11337. **/
  11338. static void
  11339. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11340. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  11341. {
  11342. struct lpfc_mbx_mq_create *mq_create;
  11343. struct lpfc_dmabuf *dmabuf;
  11344. int length;
  11345. length = (sizeof(struct lpfc_mbx_mq_create) -
  11346. sizeof(struct lpfc_sli4_cfg_mhdr));
  11347. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11348. LPFC_MBOX_OPCODE_MQ_CREATE,
  11349. length, LPFC_SLI4_MBX_EMBED);
  11350. mq_create = &mbox->u.mqe.un.mq_create;
  11351. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  11352. mq->page_count);
  11353. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  11354. cq->queue_id);
  11355. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  11356. switch (mq->entry_count) {
  11357. case 16:
  11358. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11359. LPFC_MQ_RING_SIZE_16);
  11360. break;
  11361. case 32:
  11362. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11363. LPFC_MQ_RING_SIZE_32);
  11364. break;
  11365. case 64:
  11366. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11367. LPFC_MQ_RING_SIZE_64);
  11368. break;
  11369. case 128:
  11370. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11371. LPFC_MQ_RING_SIZE_128);
  11372. break;
  11373. }
  11374. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11375. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11376. putPaddrLow(dmabuf->phys);
  11377. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11378. putPaddrHigh(dmabuf->phys);
  11379. }
  11380. }
  11381. /**
  11382. * lpfc_mq_create - Create a mailbox Queue on the HBA
  11383. * @phba: HBA structure that indicates port to create a queue on.
  11384. * @mq: The queue structure to use to create the mailbox queue.
  11385. * @cq: The completion queue to associate with this cq.
  11386. * @subtype: The queue's subtype.
  11387. *
  11388. * This function creates a mailbox queue, as detailed in @mq, on a port,
  11389. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  11390. *
  11391. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11392. * is used to get the entry count and entry size that are necessary to
  11393. * determine the number of pages to allocate and use for this queue. This
  11394. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  11395. * mailbox queue. This function is asynchronous and will wait for the mailbox
  11396. * command to finish before continuing.
  11397. *
  11398. * On success this function will return a zero. If unable to allocate enough
  11399. * memory this function will return -ENOMEM. If the queue create mailbox command
  11400. * fails this function will return -ENXIO.
  11401. **/
  11402. int32_t
  11403. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11404. struct lpfc_queue *cq, uint32_t subtype)
  11405. {
  11406. struct lpfc_mbx_mq_create *mq_create;
  11407. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  11408. struct lpfc_dmabuf *dmabuf;
  11409. LPFC_MBOXQ_t *mbox;
  11410. int rc, length, status = 0;
  11411. uint32_t shdr_status, shdr_add_status;
  11412. union lpfc_sli4_cfg_shdr *shdr;
  11413. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11414. /* sanity check on queue memory */
  11415. if (!mq || !cq)
  11416. return -ENODEV;
  11417. if (!phba->sli4_hba.pc_sli4_params.supported)
  11418. hw_page_size = SLI4_PAGE_SIZE;
  11419. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11420. if (!mbox)
  11421. return -ENOMEM;
  11422. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  11423. sizeof(struct lpfc_sli4_cfg_mhdr));
  11424. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11425. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  11426. length, LPFC_SLI4_MBX_EMBED);
  11427. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  11428. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  11429. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  11430. &mq_create_ext->u.request, mq->page_count);
  11431. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  11432. &mq_create_ext->u.request, 1);
  11433. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  11434. &mq_create_ext->u.request, 1);
  11435. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  11436. &mq_create_ext->u.request, 1);
  11437. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  11438. &mq_create_ext->u.request, 1);
  11439. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  11440. &mq_create_ext->u.request, 1);
  11441. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  11442. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11443. phba->sli4_hba.pc_sli4_params.mqv);
  11444. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  11445. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  11446. cq->queue_id);
  11447. else
  11448. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  11449. cq->queue_id);
  11450. switch (mq->entry_count) {
  11451. default:
  11452. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11453. "0362 Unsupported MQ count. (%d)\n",
  11454. mq->entry_count);
  11455. if (mq->entry_count < 16) {
  11456. status = -EINVAL;
  11457. goto out;
  11458. }
  11459. /* otherwise default to smallest count (drop through) */
  11460. case 16:
  11461. bf_set(lpfc_mq_context_ring_size,
  11462. &mq_create_ext->u.request.context,
  11463. LPFC_MQ_RING_SIZE_16);
  11464. break;
  11465. case 32:
  11466. bf_set(lpfc_mq_context_ring_size,
  11467. &mq_create_ext->u.request.context,
  11468. LPFC_MQ_RING_SIZE_32);
  11469. break;
  11470. case 64:
  11471. bf_set(lpfc_mq_context_ring_size,
  11472. &mq_create_ext->u.request.context,
  11473. LPFC_MQ_RING_SIZE_64);
  11474. break;
  11475. case 128:
  11476. bf_set(lpfc_mq_context_ring_size,
  11477. &mq_create_ext->u.request.context,
  11478. LPFC_MQ_RING_SIZE_128);
  11479. break;
  11480. }
  11481. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11482. memset(dmabuf->virt, 0, hw_page_size);
  11483. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  11484. putPaddrLow(dmabuf->phys);
  11485. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  11486. putPaddrHigh(dmabuf->phys);
  11487. }
  11488. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11489. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11490. &mq_create_ext->u.response);
  11491. if (rc != MBX_SUCCESS) {
  11492. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11493. "2795 MQ_CREATE_EXT failed with "
  11494. "status x%x. Failback to MQ_CREATE.\n",
  11495. rc);
  11496. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  11497. mq_create = &mbox->u.mqe.un.mq_create;
  11498. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11499. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  11500. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11501. &mq_create->u.response);
  11502. }
  11503. /* The IOCTL status is embedded in the mailbox subheader. */
  11504. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11505. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11506. if (shdr_status || shdr_add_status || rc) {
  11507. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11508. "2502 MQ_CREATE mailbox failed with "
  11509. "status x%x add_status x%x, mbx status x%x\n",
  11510. shdr_status, shdr_add_status, rc);
  11511. status = -ENXIO;
  11512. goto out;
  11513. }
  11514. if (mq->queue_id == 0xFFFF) {
  11515. status = -ENXIO;
  11516. goto out;
  11517. }
  11518. mq->type = LPFC_MQ;
  11519. mq->assoc_qid = cq->queue_id;
  11520. mq->subtype = subtype;
  11521. mq->host_index = 0;
  11522. mq->hba_index = 0;
  11523. /* link the mq onto the parent cq child list */
  11524. list_add_tail(&mq->list, &cq->child_list);
  11525. out:
  11526. mempool_free(mbox, phba->mbox_mem_pool);
  11527. return status;
  11528. }
  11529. /**
  11530. * lpfc_wq_create - Create a Work Queue on the HBA
  11531. * @phba: HBA structure that indicates port to create a queue on.
  11532. * @wq: The queue structure to use to create the work queue.
  11533. * @cq: The completion queue to bind this work queue to.
  11534. * @subtype: The subtype of the work queue indicating its functionality.
  11535. *
  11536. * This function creates a work queue, as detailed in @wq, on a port, described
  11537. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  11538. *
  11539. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  11540. * is used to get the entry count and entry size that are necessary to
  11541. * determine the number of pages to allocate and use for this queue. The @cq
  11542. * is used to indicate which completion queue to bind this work queue to. This
  11543. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  11544. * work queue. This function is asynchronous and will wait for the mailbox
  11545. * command to finish before continuing.
  11546. *
  11547. * On success this function will return a zero. If unable to allocate enough
  11548. * memory this function will return -ENOMEM. If the queue create mailbox command
  11549. * fails this function will return -ENXIO.
  11550. **/
  11551. uint32_t
  11552. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  11553. struct lpfc_queue *cq, uint32_t subtype)
  11554. {
  11555. struct lpfc_mbx_wq_create *wq_create;
  11556. struct lpfc_dmabuf *dmabuf;
  11557. LPFC_MBOXQ_t *mbox;
  11558. int rc, length, status = 0;
  11559. uint32_t shdr_status, shdr_add_status;
  11560. union lpfc_sli4_cfg_shdr *shdr;
  11561. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11562. struct dma_address *page;
  11563. /* sanity check on queue memory */
  11564. if (!wq || !cq)
  11565. return -ENODEV;
  11566. if (!phba->sli4_hba.pc_sli4_params.supported)
  11567. hw_page_size = SLI4_PAGE_SIZE;
  11568. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11569. if (!mbox)
  11570. return -ENOMEM;
  11571. length = (sizeof(struct lpfc_mbx_wq_create) -
  11572. sizeof(struct lpfc_sli4_cfg_mhdr));
  11573. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11574. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  11575. length, LPFC_SLI4_MBX_EMBED);
  11576. wq_create = &mbox->u.mqe.un.wq_create;
  11577. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  11578. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  11579. wq->page_count);
  11580. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  11581. cq->queue_id);
  11582. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11583. phba->sli4_hba.pc_sli4_params.wqv);
  11584. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  11585. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  11586. wq->entry_count);
  11587. switch (wq->entry_size) {
  11588. default:
  11589. case 64:
  11590. bf_set(lpfc_mbx_wq_create_wqe_size,
  11591. &wq_create->u.request_1,
  11592. LPFC_WQ_WQE_SIZE_64);
  11593. break;
  11594. case 128:
  11595. bf_set(lpfc_mbx_wq_create_wqe_size,
  11596. &wq_create->u.request_1,
  11597. LPFC_WQ_WQE_SIZE_128);
  11598. break;
  11599. }
  11600. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  11601. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11602. page = wq_create->u.request_1.page;
  11603. } else {
  11604. page = wq_create->u.request.page;
  11605. }
  11606. list_for_each_entry(dmabuf, &wq->page_list, list) {
  11607. memset(dmabuf->virt, 0, hw_page_size);
  11608. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  11609. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  11610. }
  11611. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11612. /* The IOCTL status is embedded in the mailbox subheader. */
  11613. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11614. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11615. if (shdr_status || shdr_add_status || rc) {
  11616. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11617. "2503 WQ_CREATE mailbox failed with "
  11618. "status x%x add_status x%x, mbx status x%x\n",
  11619. shdr_status, shdr_add_status, rc);
  11620. status = -ENXIO;
  11621. goto out;
  11622. }
  11623. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  11624. if (wq->queue_id == 0xFFFF) {
  11625. status = -ENXIO;
  11626. goto out;
  11627. }
  11628. wq->type = LPFC_WQ;
  11629. wq->assoc_qid = cq->queue_id;
  11630. wq->subtype = subtype;
  11631. wq->host_index = 0;
  11632. wq->hba_index = 0;
  11633. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  11634. /* link the wq onto the parent cq child list */
  11635. list_add_tail(&wq->list, &cq->child_list);
  11636. out:
  11637. mempool_free(mbox, phba->mbox_mem_pool);
  11638. return status;
  11639. }
  11640. /**
  11641. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  11642. * @phba: HBA structure that indicates port to create a queue on.
  11643. * @rq: The queue structure to use for the receive queue.
  11644. * @qno: The associated HBQ number
  11645. *
  11646. *
  11647. * For SLI4 we need to adjust the RQ repost value based on
  11648. * the number of buffers that are initially posted to the RQ.
  11649. */
  11650. void
  11651. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  11652. {
  11653. uint32_t cnt;
  11654. /* sanity check on queue memory */
  11655. if (!rq)
  11656. return;
  11657. cnt = lpfc_hbq_defs[qno]->entry_count;
  11658. /* Recalc repost for RQs based on buffers initially posted */
  11659. cnt = (cnt >> 3);
  11660. if (cnt < LPFC_QUEUE_MIN_REPOST)
  11661. cnt = LPFC_QUEUE_MIN_REPOST;
  11662. rq->entry_repost = cnt;
  11663. }
  11664. /**
  11665. * lpfc_rq_create - Create a Receive Queue on the HBA
  11666. * @phba: HBA structure that indicates port to create a queue on.
  11667. * @hrq: The queue structure to use to create the header receive queue.
  11668. * @drq: The queue structure to use to create the data receive queue.
  11669. * @cq: The completion queue to bind this work queue to.
  11670. *
  11671. * This function creates a receive buffer queue pair , as detailed in @hrq and
  11672. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  11673. * to the HBA.
  11674. *
  11675. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  11676. * struct is used to get the entry count that is necessary to determine the
  11677. * number of pages to use for this queue. The @cq is used to indicate which
  11678. * completion queue to bind received buffers that are posted to these queues to.
  11679. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  11680. * receive queue pair. This function is asynchronous and will wait for the
  11681. * mailbox command to finish before continuing.
  11682. *
  11683. * On success this function will return a zero. If unable to allocate enough
  11684. * memory this function will return -ENOMEM. If the queue create mailbox command
  11685. * fails this function will return -ENXIO.
  11686. **/
  11687. uint32_t
  11688. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11689. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  11690. {
  11691. struct lpfc_mbx_rq_create *rq_create;
  11692. struct lpfc_dmabuf *dmabuf;
  11693. LPFC_MBOXQ_t *mbox;
  11694. int rc, length, status = 0;
  11695. uint32_t shdr_status, shdr_add_status;
  11696. union lpfc_sli4_cfg_shdr *shdr;
  11697. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11698. /* sanity check on queue memory */
  11699. if (!hrq || !drq || !cq)
  11700. return -ENODEV;
  11701. if (!phba->sli4_hba.pc_sli4_params.supported)
  11702. hw_page_size = SLI4_PAGE_SIZE;
  11703. if (hrq->entry_count != drq->entry_count)
  11704. return -EINVAL;
  11705. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11706. if (!mbox)
  11707. return -ENOMEM;
  11708. length = (sizeof(struct lpfc_mbx_rq_create) -
  11709. sizeof(struct lpfc_sli4_cfg_mhdr));
  11710. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11711. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11712. length, LPFC_SLI4_MBX_EMBED);
  11713. rq_create = &mbox->u.mqe.un.rq_create;
  11714. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11715. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11716. phba->sli4_hba.pc_sli4_params.rqv);
  11717. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11718. bf_set(lpfc_rq_context_rqe_count_1,
  11719. &rq_create->u.request.context,
  11720. hrq->entry_count);
  11721. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  11722. bf_set(lpfc_rq_context_rqe_size,
  11723. &rq_create->u.request.context,
  11724. LPFC_RQE_SIZE_8);
  11725. bf_set(lpfc_rq_context_page_size,
  11726. &rq_create->u.request.context,
  11727. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11728. } else {
  11729. switch (hrq->entry_count) {
  11730. default:
  11731. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11732. "2535 Unsupported RQ count. (%d)\n",
  11733. hrq->entry_count);
  11734. if (hrq->entry_count < 512) {
  11735. status = -EINVAL;
  11736. goto out;
  11737. }
  11738. /* otherwise default to smallest count (drop through) */
  11739. case 512:
  11740. bf_set(lpfc_rq_context_rqe_count,
  11741. &rq_create->u.request.context,
  11742. LPFC_RQ_RING_SIZE_512);
  11743. break;
  11744. case 1024:
  11745. bf_set(lpfc_rq_context_rqe_count,
  11746. &rq_create->u.request.context,
  11747. LPFC_RQ_RING_SIZE_1024);
  11748. break;
  11749. case 2048:
  11750. bf_set(lpfc_rq_context_rqe_count,
  11751. &rq_create->u.request.context,
  11752. LPFC_RQ_RING_SIZE_2048);
  11753. break;
  11754. case 4096:
  11755. bf_set(lpfc_rq_context_rqe_count,
  11756. &rq_create->u.request.context,
  11757. LPFC_RQ_RING_SIZE_4096);
  11758. break;
  11759. }
  11760. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11761. LPFC_HDR_BUF_SIZE);
  11762. }
  11763. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11764. cq->queue_id);
  11765. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11766. hrq->page_count);
  11767. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  11768. memset(dmabuf->virt, 0, hw_page_size);
  11769. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11770. putPaddrLow(dmabuf->phys);
  11771. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11772. putPaddrHigh(dmabuf->phys);
  11773. }
  11774. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11775. /* The IOCTL status is embedded in the mailbox subheader. */
  11776. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11777. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11778. if (shdr_status || shdr_add_status || rc) {
  11779. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11780. "2504 RQ_CREATE mailbox failed with "
  11781. "status x%x add_status x%x, mbx status x%x\n",
  11782. shdr_status, shdr_add_status, rc);
  11783. status = -ENXIO;
  11784. goto out;
  11785. }
  11786. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11787. if (hrq->queue_id == 0xFFFF) {
  11788. status = -ENXIO;
  11789. goto out;
  11790. }
  11791. hrq->type = LPFC_HRQ;
  11792. hrq->assoc_qid = cq->queue_id;
  11793. hrq->subtype = subtype;
  11794. hrq->host_index = 0;
  11795. hrq->hba_index = 0;
  11796. /* now create the data queue */
  11797. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11798. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11799. length, LPFC_SLI4_MBX_EMBED);
  11800. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11801. phba->sli4_hba.pc_sli4_params.rqv);
  11802. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11803. bf_set(lpfc_rq_context_rqe_count_1,
  11804. &rq_create->u.request.context, hrq->entry_count);
  11805. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  11806. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  11807. LPFC_RQE_SIZE_8);
  11808. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  11809. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11810. } else {
  11811. switch (drq->entry_count) {
  11812. default:
  11813. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11814. "2536 Unsupported RQ count. (%d)\n",
  11815. drq->entry_count);
  11816. if (drq->entry_count < 512) {
  11817. status = -EINVAL;
  11818. goto out;
  11819. }
  11820. /* otherwise default to smallest count (drop through) */
  11821. case 512:
  11822. bf_set(lpfc_rq_context_rqe_count,
  11823. &rq_create->u.request.context,
  11824. LPFC_RQ_RING_SIZE_512);
  11825. break;
  11826. case 1024:
  11827. bf_set(lpfc_rq_context_rqe_count,
  11828. &rq_create->u.request.context,
  11829. LPFC_RQ_RING_SIZE_1024);
  11830. break;
  11831. case 2048:
  11832. bf_set(lpfc_rq_context_rqe_count,
  11833. &rq_create->u.request.context,
  11834. LPFC_RQ_RING_SIZE_2048);
  11835. break;
  11836. case 4096:
  11837. bf_set(lpfc_rq_context_rqe_count,
  11838. &rq_create->u.request.context,
  11839. LPFC_RQ_RING_SIZE_4096);
  11840. break;
  11841. }
  11842. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11843. LPFC_DATA_BUF_SIZE);
  11844. }
  11845. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11846. cq->queue_id);
  11847. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11848. drq->page_count);
  11849. list_for_each_entry(dmabuf, &drq->page_list, list) {
  11850. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11851. putPaddrLow(dmabuf->phys);
  11852. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11853. putPaddrHigh(dmabuf->phys);
  11854. }
  11855. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11856. /* The IOCTL status is embedded in the mailbox subheader. */
  11857. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11858. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11859. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11860. if (shdr_status || shdr_add_status || rc) {
  11861. status = -ENXIO;
  11862. goto out;
  11863. }
  11864. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11865. if (drq->queue_id == 0xFFFF) {
  11866. status = -ENXIO;
  11867. goto out;
  11868. }
  11869. drq->type = LPFC_DRQ;
  11870. drq->assoc_qid = cq->queue_id;
  11871. drq->subtype = subtype;
  11872. drq->host_index = 0;
  11873. drq->hba_index = 0;
  11874. /* link the header and data RQs onto the parent cq child list */
  11875. list_add_tail(&hrq->list, &cq->child_list);
  11876. list_add_tail(&drq->list, &cq->child_list);
  11877. out:
  11878. mempool_free(mbox, phba->mbox_mem_pool);
  11879. return status;
  11880. }
  11881. /**
  11882. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  11883. * @eq: The queue structure associated with the queue to destroy.
  11884. *
  11885. * This function destroys a queue, as detailed in @eq by sending an mailbox
  11886. * command, specific to the type of queue, to the HBA.
  11887. *
  11888. * The @eq struct is used to get the queue ID of the queue to destroy.
  11889. *
  11890. * On success this function will return a zero. If the queue destroy mailbox
  11891. * command fails this function will return -ENXIO.
  11892. **/
  11893. uint32_t
  11894. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  11895. {
  11896. LPFC_MBOXQ_t *mbox;
  11897. int rc, length, status = 0;
  11898. uint32_t shdr_status, shdr_add_status;
  11899. union lpfc_sli4_cfg_shdr *shdr;
  11900. /* sanity check on queue memory */
  11901. if (!eq)
  11902. return -ENODEV;
  11903. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  11904. if (!mbox)
  11905. return -ENOMEM;
  11906. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  11907. sizeof(struct lpfc_sli4_cfg_mhdr));
  11908. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11909. LPFC_MBOX_OPCODE_EQ_DESTROY,
  11910. length, LPFC_SLI4_MBX_EMBED);
  11911. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  11912. eq->queue_id);
  11913. mbox->vport = eq->phba->pport;
  11914. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11915. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  11916. /* The IOCTL status is embedded in the mailbox subheader. */
  11917. shdr = (union lpfc_sli4_cfg_shdr *)
  11918. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  11919. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11920. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11921. if (shdr_status || shdr_add_status || rc) {
  11922. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11923. "2505 EQ_DESTROY mailbox failed with "
  11924. "status x%x add_status x%x, mbx status x%x\n",
  11925. shdr_status, shdr_add_status, rc);
  11926. status = -ENXIO;
  11927. }
  11928. /* Remove eq from any list */
  11929. list_del_init(&eq->list);
  11930. mempool_free(mbox, eq->phba->mbox_mem_pool);
  11931. return status;
  11932. }
  11933. /**
  11934. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  11935. * @cq: The queue structure associated with the queue to destroy.
  11936. *
  11937. * This function destroys a queue, as detailed in @cq by sending an mailbox
  11938. * command, specific to the type of queue, to the HBA.
  11939. *
  11940. * The @cq struct is used to get the queue ID of the queue to destroy.
  11941. *
  11942. * On success this function will return a zero. If the queue destroy mailbox
  11943. * command fails this function will return -ENXIO.
  11944. **/
  11945. uint32_t
  11946. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  11947. {
  11948. LPFC_MBOXQ_t *mbox;
  11949. int rc, length, status = 0;
  11950. uint32_t shdr_status, shdr_add_status;
  11951. union lpfc_sli4_cfg_shdr *shdr;
  11952. /* sanity check on queue memory */
  11953. if (!cq)
  11954. return -ENODEV;
  11955. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  11956. if (!mbox)
  11957. return -ENOMEM;
  11958. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  11959. sizeof(struct lpfc_sli4_cfg_mhdr));
  11960. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11961. LPFC_MBOX_OPCODE_CQ_DESTROY,
  11962. length, LPFC_SLI4_MBX_EMBED);
  11963. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  11964. cq->queue_id);
  11965. mbox->vport = cq->phba->pport;
  11966. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11967. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  11968. /* The IOCTL status is embedded in the mailbox subheader. */
  11969. shdr = (union lpfc_sli4_cfg_shdr *)
  11970. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  11971. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11972. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11973. if (shdr_status || shdr_add_status || rc) {
  11974. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11975. "2506 CQ_DESTROY mailbox failed with "
  11976. "status x%x add_status x%x, mbx status x%x\n",
  11977. shdr_status, shdr_add_status, rc);
  11978. status = -ENXIO;
  11979. }
  11980. /* Remove cq from any list */
  11981. list_del_init(&cq->list);
  11982. mempool_free(mbox, cq->phba->mbox_mem_pool);
  11983. return status;
  11984. }
  11985. /**
  11986. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  11987. * @qm: The queue structure associated with the queue to destroy.
  11988. *
  11989. * This function destroys a queue, as detailed in @mq by sending an mailbox
  11990. * command, specific to the type of queue, to the HBA.
  11991. *
  11992. * The @mq struct is used to get the queue ID of the queue to destroy.
  11993. *
  11994. * On success this function will return a zero. If the queue destroy mailbox
  11995. * command fails this function will return -ENXIO.
  11996. **/
  11997. uint32_t
  11998. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  11999. {
  12000. LPFC_MBOXQ_t *mbox;
  12001. int rc, length, status = 0;
  12002. uint32_t shdr_status, shdr_add_status;
  12003. union lpfc_sli4_cfg_shdr *shdr;
  12004. /* sanity check on queue memory */
  12005. if (!mq)
  12006. return -ENODEV;
  12007. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  12008. if (!mbox)
  12009. return -ENOMEM;
  12010. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  12011. sizeof(struct lpfc_sli4_cfg_mhdr));
  12012. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12013. LPFC_MBOX_OPCODE_MQ_DESTROY,
  12014. length, LPFC_SLI4_MBX_EMBED);
  12015. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  12016. mq->queue_id);
  12017. mbox->vport = mq->phba->pport;
  12018. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12019. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  12020. /* The IOCTL status is embedded in the mailbox subheader. */
  12021. shdr = (union lpfc_sli4_cfg_shdr *)
  12022. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  12023. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12024. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12025. if (shdr_status || shdr_add_status || rc) {
  12026. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12027. "2507 MQ_DESTROY mailbox failed with "
  12028. "status x%x add_status x%x, mbx status x%x\n",
  12029. shdr_status, shdr_add_status, rc);
  12030. status = -ENXIO;
  12031. }
  12032. /* Remove mq from any list */
  12033. list_del_init(&mq->list);
  12034. mempool_free(mbox, mq->phba->mbox_mem_pool);
  12035. return status;
  12036. }
  12037. /**
  12038. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  12039. * @wq: The queue structure associated with the queue to destroy.
  12040. *
  12041. * This function destroys a queue, as detailed in @wq by sending an mailbox
  12042. * command, specific to the type of queue, to the HBA.
  12043. *
  12044. * The @wq struct is used to get the queue ID of the queue to destroy.
  12045. *
  12046. * On success this function will return a zero. If the queue destroy mailbox
  12047. * command fails this function will return -ENXIO.
  12048. **/
  12049. uint32_t
  12050. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  12051. {
  12052. LPFC_MBOXQ_t *mbox;
  12053. int rc, length, status = 0;
  12054. uint32_t shdr_status, shdr_add_status;
  12055. union lpfc_sli4_cfg_shdr *shdr;
  12056. /* sanity check on queue memory */
  12057. if (!wq)
  12058. return -ENODEV;
  12059. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  12060. if (!mbox)
  12061. return -ENOMEM;
  12062. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  12063. sizeof(struct lpfc_sli4_cfg_mhdr));
  12064. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12065. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  12066. length, LPFC_SLI4_MBX_EMBED);
  12067. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  12068. wq->queue_id);
  12069. mbox->vport = wq->phba->pport;
  12070. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12071. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  12072. shdr = (union lpfc_sli4_cfg_shdr *)
  12073. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  12074. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12075. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12076. if (shdr_status || shdr_add_status || rc) {
  12077. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12078. "2508 WQ_DESTROY mailbox failed with "
  12079. "status x%x add_status x%x, mbx status x%x\n",
  12080. shdr_status, shdr_add_status, rc);
  12081. status = -ENXIO;
  12082. }
  12083. /* Remove wq from any list */
  12084. list_del_init(&wq->list);
  12085. mempool_free(mbox, wq->phba->mbox_mem_pool);
  12086. return status;
  12087. }
  12088. /**
  12089. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  12090. * @rq: The queue structure associated with the queue to destroy.
  12091. *
  12092. * This function destroys a queue, as detailed in @rq by sending an mailbox
  12093. * command, specific to the type of queue, to the HBA.
  12094. *
  12095. * The @rq struct is used to get the queue ID of the queue to destroy.
  12096. *
  12097. * On success this function will return a zero. If the queue destroy mailbox
  12098. * command fails this function will return -ENXIO.
  12099. **/
  12100. uint32_t
  12101. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  12102. struct lpfc_queue *drq)
  12103. {
  12104. LPFC_MBOXQ_t *mbox;
  12105. int rc, length, status = 0;
  12106. uint32_t shdr_status, shdr_add_status;
  12107. union lpfc_sli4_cfg_shdr *shdr;
  12108. /* sanity check on queue memory */
  12109. if (!hrq || !drq)
  12110. return -ENODEV;
  12111. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  12112. if (!mbox)
  12113. return -ENOMEM;
  12114. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  12115. sizeof(struct lpfc_sli4_cfg_mhdr));
  12116. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12117. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  12118. length, LPFC_SLI4_MBX_EMBED);
  12119. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12120. hrq->queue_id);
  12121. mbox->vport = hrq->phba->pport;
  12122. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12123. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  12124. /* The IOCTL status is embedded in the mailbox subheader. */
  12125. shdr = (union lpfc_sli4_cfg_shdr *)
  12126. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12127. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12128. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12129. if (shdr_status || shdr_add_status || rc) {
  12130. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12131. "2509 RQ_DESTROY mailbox failed with "
  12132. "status x%x add_status x%x, mbx status x%x\n",
  12133. shdr_status, shdr_add_status, rc);
  12134. if (rc != MBX_TIMEOUT)
  12135. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12136. return -ENXIO;
  12137. }
  12138. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12139. drq->queue_id);
  12140. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  12141. shdr = (union lpfc_sli4_cfg_shdr *)
  12142. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12143. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12144. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12145. if (shdr_status || shdr_add_status || rc) {
  12146. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12147. "2510 RQ_DESTROY mailbox failed with "
  12148. "status x%x add_status x%x, mbx status x%x\n",
  12149. shdr_status, shdr_add_status, rc);
  12150. status = -ENXIO;
  12151. }
  12152. list_del_init(&hrq->list);
  12153. list_del_init(&drq->list);
  12154. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12155. return status;
  12156. }
  12157. /**
  12158. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  12159. * @phba: The virtual port for which this call being executed.
  12160. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  12161. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  12162. * @xritag: the xritag that ties this io to the SGL pages.
  12163. *
  12164. * This routine will post the sgl pages for the IO that has the xritag
  12165. * that is in the iocbq structure. The xritag is assigned during iocbq
  12166. * creation and persists for as long as the driver is loaded.
  12167. * if the caller has fewer than 256 scatter gather segments to map then
  12168. * pdma_phys_addr1 should be 0.
  12169. * If the caller needs to map more than 256 scatter gather segment then
  12170. * pdma_phys_addr1 should be a valid physical address.
  12171. * physical address for SGLs must be 64 byte aligned.
  12172. * If you are going to map 2 SGL's then the first one must have 256 entries
  12173. * the second sgl can have between 1 and 256 entries.
  12174. *
  12175. * Return codes:
  12176. * 0 - Success
  12177. * -ENXIO, -ENOMEM - Failure
  12178. **/
  12179. int
  12180. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  12181. dma_addr_t pdma_phys_addr0,
  12182. dma_addr_t pdma_phys_addr1,
  12183. uint16_t xritag)
  12184. {
  12185. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  12186. LPFC_MBOXQ_t *mbox;
  12187. int rc;
  12188. uint32_t shdr_status, shdr_add_status;
  12189. uint32_t mbox_tmo;
  12190. union lpfc_sli4_cfg_shdr *shdr;
  12191. if (xritag == NO_XRI) {
  12192. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12193. "0364 Invalid param:\n");
  12194. return -EINVAL;
  12195. }
  12196. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12197. if (!mbox)
  12198. return -ENOMEM;
  12199. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12200. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  12201. sizeof(struct lpfc_mbx_post_sgl_pages) -
  12202. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  12203. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  12204. &mbox->u.mqe.un.post_sgl_pages;
  12205. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  12206. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  12207. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  12208. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  12209. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  12210. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  12211. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  12212. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  12213. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  12214. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  12215. if (!phba->sli4_hba.intr_enable)
  12216. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12217. else {
  12218. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12219. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12220. }
  12221. /* The IOCTL status is embedded in the mailbox subheader. */
  12222. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  12223. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12224. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12225. if (rc != MBX_TIMEOUT)
  12226. mempool_free(mbox, phba->mbox_mem_pool);
  12227. if (shdr_status || shdr_add_status || rc) {
  12228. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12229. "2511 POST_SGL mailbox failed with "
  12230. "status x%x add_status x%x, mbx status x%x\n",
  12231. shdr_status, shdr_add_status, rc);
  12232. rc = -ENXIO;
  12233. }
  12234. return 0;
  12235. }
  12236. /**
  12237. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  12238. * @phba: pointer to lpfc hba data structure.
  12239. *
  12240. * This routine is invoked to post rpi header templates to the
  12241. * HBA consistent with the SLI-4 interface spec. This routine
  12242. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  12243. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  12244. *
  12245. * Returns
  12246. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  12247. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  12248. **/
  12249. uint16_t
  12250. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  12251. {
  12252. unsigned long xri;
  12253. /*
  12254. * Fetch the next logical xri. Because this index is logical,
  12255. * the driver starts at 0 each time.
  12256. */
  12257. spin_lock_irq(&phba->hbalock);
  12258. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  12259. phba->sli4_hba.max_cfg_param.max_xri, 0);
  12260. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  12261. spin_unlock_irq(&phba->hbalock);
  12262. return NO_XRI;
  12263. } else {
  12264. set_bit(xri, phba->sli4_hba.xri_bmask);
  12265. phba->sli4_hba.max_cfg_param.xri_used++;
  12266. }
  12267. spin_unlock_irq(&phba->hbalock);
  12268. return xri;
  12269. }
  12270. /**
  12271. * lpfc_sli4_free_xri - Release an xri for reuse.
  12272. * @phba: pointer to lpfc hba data structure.
  12273. *
  12274. * This routine is invoked to release an xri to the pool of
  12275. * available rpis maintained by the driver.
  12276. **/
  12277. void
  12278. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12279. {
  12280. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  12281. phba->sli4_hba.max_cfg_param.xri_used--;
  12282. }
  12283. }
  12284. /**
  12285. * lpfc_sli4_free_xri - Release an xri for reuse.
  12286. * @phba: pointer to lpfc hba data structure.
  12287. *
  12288. * This routine is invoked to release an xri to the pool of
  12289. * available rpis maintained by the driver.
  12290. **/
  12291. void
  12292. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12293. {
  12294. spin_lock_irq(&phba->hbalock);
  12295. __lpfc_sli4_free_xri(phba, xri);
  12296. spin_unlock_irq(&phba->hbalock);
  12297. }
  12298. /**
  12299. * lpfc_sli4_next_xritag - Get an xritag for the io
  12300. * @phba: Pointer to HBA context object.
  12301. *
  12302. * This function gets an xritag for the iocb. If there is no unused xritag
  12303. * it will return 0xffff.
  12304. * The function returns the allocated xritag if successful, else returns zero.
  12305. * Zero is not a valid xritag.
  12306. * The caller is not required to hold any lock.
  12307. **/
  12308. uint16_t
  12309. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  12310. {
  12311. uint16_t xri_index;
  12312. xri_index = lpfc_sli4_alloc_xri(phba);
  12313. if (xri_index == NO_XRI)
  12314. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  12315. "2004 Failed to allocate XRI.last XRITAG is %d"
  12316. " Max XRI is %d, Used XRI is %d\n",
  12317. xri_index,
  12318. phba->sli4_hba.max_cfg_param.max_xri,
  12319. phba->sli4_hba.max_cfg_param.xri_used);
  12320. return xri_index;
  12321. }
  12322. /**
  12323. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  12324. * @phba: pointer to lpfc hba data structure.
  12325. * @post_sgl_list: pointer to els sgl entry list.
  12326. * @count: number of els sgl entries on the list.
  12327. *
  12328. * This routine is invoked to post a block of driver's sgl pages to the
  12329. * HBA using non-embedded mailbox command. No Lock is held. This routine
  12330. * is only called when the driver is loading and after all IO has been
  12331. * stopped.
  12332. **/
  12333. static int
  12334. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
  12335. struct list_head *post_sgl_list,
  12336. int post_cnt)
  12337. {
  12338. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  12339. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12340. struct sgl_page_pairs *sgl_pg_pairs;
  12341. void *viraddr;
  12342. LPFC_MBOXQ_t *mbox;
  12343. uint32_t reqlen, alloclen, pg_pairs;
  12344. uint32_t mbox_tmo;
  12345. uint16_t xritag_start = 0;
  12346. int rc = 0;
  12347. uint32_t shdr_status, shdr_add_status;
  12348. union lpfc_sli4_cfg_shdr *shdr;
  12349. reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
  12350. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12351. if (reqlen > SLI4_PAGE_SIZE) {
  12352. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12353. "2559 Block sgl registration required DMA "
  12354. "size (%d) great than a page\n", reqlen);
  12355. return -ENOMEM;
  12356. }
  12357. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12358. if (!mbox)
  12359. return -ENOMEM;
  12360. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12361. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12362. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12363. LPFC_SLI4_MBX_NEMBED);
  12364. if (alloclen < reqlen) {
  12365. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12366. "0285 Allocated DMA memory size (%d) is "
  12367. "less than the requested DMA memory "
  12368. "size (%d)\n", alloclen, reqlen);
  12369. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12370. return -ENOMEM;
  12371. }
  12372. /* Set up the SGL pages in the non-embedded DMA pages */
  12373. viraddr = mbox->sge_array->addr[0];
  12374. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12375. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12376. pg_pairs = 0;
  12377. list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
  12378. /* Set up the sge entry */
  12379. sgl_pg_pairs->sgl_pg0_addr_lo =
  12380. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  12381. sgl_pg_pairs->sgl_pg0_addr_hi =
  12382. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  12383. sgl_pg_pairs->sgl_pg1_addr_lo =
  12384. cpu_to_le32(putPaddrLow(0));
  12385. sgl_pg_pairs->sgl_pg1_addr_hi =
  12386. cpu_to_le32(putPaddrHigh(0));
  12387. /* Keep the first xritag on the list */
  12388. if (pg_pairs == 0)
  12389. xritag_start = sglq_entry->sli4_xritag;
  12390. sgl_pg_pairs++;
  12391. pg_pairs++;
  12392. }
  12393. /* Complete initialization and perform endian conversion. */
  12394. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12395. bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
  12396. sgl->word0 = cpu_to_le32(sgl->word0);
  12397. if (!phba->sli4_hba.intr_enable)
  12398. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12399. else {
  12400. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12401. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12402. }
  12403. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12404. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12405. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12406. if (rc != MBX_TIMEOUT)
  12407. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12408. if (shdr_status || shdr_add_status || rc) {
  12409. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12410. "2513 POST_SGL_BLOCK mailbox command failed "
  12411. "status x%x add_status x%x mbx status x%x\n",
  12412. shdr_status, shdr_add_status, rc);
  12413. rc = -ENXIO;
  12414. }
  12415. return rc;
  12416. }
  12417. /**
  12418. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  12419. * @phba: pointer to lpfc hba data structure.
  12420. * @sblist: pointer to scsi buffer list.
  12421. * @count: number of scsi buffers on the list.
  12422. *
  12423. * This routine is invoked to post a block of @count scsi sgl pages from a
  12424. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  12425. * No Lock is held.
  12426. *
  12427. **/
  12428. int
  12429. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
  12430. struct list_head *sblist,
  12431. int count)
  12432. {
  12433. struct lpfc_scsi_buf *psb;
  12434. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12435. struct sgl_page_pairs *sgl_pg_pairs;
  12436. void *viraddr;
  12437. LPFC_MBOXQ_t *mbox;
  12438. uint32_t reqlen, alloclen, pg_pairs;
  12439. uint32_t mbox_tmo;
  12440. uint16_t xritag_start = 0;
  12441. int rc = 0;
  12442. uint32_t shdr_status, shdr_add_status;
  12443. dma_addr_t pdma_phys_bpl1;
  12444. union lpfc_sli4_cfg_shdr *shdr;
  12445. /* Calculate the requested length of the dma memory */
  12446. reqlen = count * sizeof(struct sgl_page_pairs) +
  12447. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12448. if (reqlen > SLI4_PAGE_SIZE) {
  12449. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12450. "0217 Block sgl registration required DMA "
  12451. "size (%d) great than a page\n", reqlen);
  12452. return -ENOMEM;
  12453. }
  12454. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12455. if (!mbox) {
  12456. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12457. "0283 Failed to allocate mbox cmd memory\n");
  12458. return -ENOMEM;
  12459. }
  12460. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12461. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12462. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12463. LPFC_SLI4_MBX_NEMBED);
  12464. if (alloclen < reqlen) {
  12465. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12466. "2561 Allocated DMA memory size (%d) is "
  12467. "less than the requested DMA memory "
  12468. "size (%d)\n", alloclen, reqlen);
  12469. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12470. return -ENOMEM;
  12471. }
  12472. /* Get the first SGE entry from the non-embedded DMA memory */
  12473. viraddr = mbox->sge_array->addr[0];
  12474. /* Set up the SGL pages in the non-embedded DMA pages */
  12475. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12476. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12477. pg_pairs = 0;
  12478. list_for_each_entry(psb, sblist, list) {
  12479. /* Set up the sge entry */
  12480. sgl_pg_pairs->sgl_pg0_addr_lo =
  12481. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  12482. sgl_pg_pairs->sgl_pg0_addr_hi =
  12483. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  12484. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  12485. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  12486. else
  12487. pdma_phys_bpl1 = 0;
  12488. sgl_pg_pairs->sgl_pg1_addr_lo =
  12489. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  12490. sgl_pg_pairs->sgl_pg1_addr_hi =
  12491. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  12492. /* Keep the first xritag on the list */
  12493. if (pg_pairs == 0)
  12494. xritag_start = psb->cur_iocbq.sli4_xritag;
  12495. sgl_pg_pairs++;
  12496. pg_pairs++;
  12497. }
  12498. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12499. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  12500. /* Perform endian conversion if necessary */
  12501. sgl->word0 = cpu_to_le32(sgl->word0);
  12502. if (!phba->sli4_hba.intr_enable)
  12503. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12504. else {
  12505. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12506. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12507. }
  12508. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12509. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12510. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12511. if (rc != MBX_TIMEOUT)
  12512. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12513. if (shdr_status || shdr_add_status || rc) {
  12514. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12515. "2564 POST_SGL_BLOCK mailbox command failed "
  12516. "status x%x add_status x%x mbx status x%x\n",
  12517. shdr_status, shdr_add_status, rc);
  12518. rc = -ENXIO;
  12519. }
  12520. return rc;
  12521. }
  12522. /**
  12523. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  12524. * @phba: pointer to lpfc_hba struct that the frame was received on
  12525. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12526. *
  12527. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  12528. * valid type of frame that the LPFC driver will handle. This function will
  12529. * return a zero if the frame is a valid frame or a non zero value when the
  12530. * frame does not pass the check.
  12531. **/
  12532. static int
  12533. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  12534. {
  12535. /* make rctl_names static to save stack space */
  12536. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  12537. char *type_names[] = FC_TYPE_NAMES_INIT;
  12538. struct fc_vft_header *fc_vft_hdr;
  12539. uint32_t *header = (uint32_t *) fc_hdr;
  12540. switch (fc_hdr->fh_r_ctl) {
  12541. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  12542. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  12543. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  12544. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  12545. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  12546. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  12547. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  12548. case FC_RCTL_DD_CMD_STATUS: /* command status */
  12549. case FC_RCTL_ELS_REQ: /* extended link services request */
  12550. case FC_RCTL_ELS_REP: /* extended link services reply */
  12551. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  12552. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  12553. case FC_RCTL_BA_NOP: /* basic link service NOP */
  12554. case FC_RCTL_BA_ABTS: /* basic link service abort */
  12555. case FC_RCTL_BA_RMC: /* remove connection */
  12556. case FC_RCTL_BA_ACC: /* basic accept */
  12557. case FC_RCTL_BA_RJT: /* basic reject */
  12558. case FC_RCTL_BA_PRMT:
  12559. case FC_RCTL_ACK_1: /* acknowledge_1 */
  12560. case FC_RCTL_ACK_0: /* acknowledge_0 */
  12561. case FC_RCTL_P_RJT: /* port reject */
  12562. case FC_RCTL_F_RJT: /* fabric reject */
  12563. case FC_RCTL_P_BSY: /* port busy */
  12564. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  12565. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  12566. case FC_RCTL_LCR: /* link credit reset */
  12567. case FC_RCTL_END: /* end */
  12568. break;
  12569. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  12570. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12571. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  12572. return lpfc_fc_frame_check(phba, fc_hdr);
  12573. default:
  12574. goto drop;
  12575. }
  12576. switch (fc_hdr->fh_type) {
  12577. case FC_TYPE_BLS:
  12578. case FC_TYPE_ELS:
  12579. case FC_TYPE_FCP:
  12580. case FC_TYPE_CT:
  12581. break;
  12582. case FC_TYPE_IP:
  12583. case FC_TYPE_ILS:
  12584. default:
  12585. goto drop;
  12586. }
  12587. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12588. "2538 Received frame rctl:%s type:%s "
  12589. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  12590. rctl_names[fc_hdr->fh_r_ctl],
  12591. type_names[fc_hdr->fh_type],
  12592. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  12593. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  12594. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  12595. return 0;
  12596. drop:
  12597. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12598. "2539 Dropped frame rctl:%s type:%s\n",
  12599. rctl_names[fc_hdr->fh_r_ctl],
  12600. type_names[fc_hdr->fh_type]);
  12601. return 1;
  12602. }
  12603. /**
  12604. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  12605. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12606. *
  12607. * This function processes the FC header to retrieve the VFI from the VF
  12608. * header, if one exists. This function will return the VFI if one exists
  12609. * or 0 if no VSAN Header exists.
  12610. **/
  12611. static uint32_t
  12612. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  12613. {
  12614. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12615. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  12616. return 0;
  12617. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  12618. }
  12619. /**
  12620. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  12621. * @phba: Pointer to the HBA structure to search for the vport on
  12622. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12623. * @fcfi: The FC Fabric ID that the frame came from
  12624. *
  12625. * This function searches the @phba for a vport that matches the content of the
  12626. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  12627. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  12628. * returns the matching vport pointer or NULL if unable to match frame to a
  12629. * vport.
  12630. **/
  12631. static struct lpfc_vport *
  12632. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  12633. uint16_t fcfi)
  12634. {
  12635. struct lpfc_vport **vports;
  12636. struct lpfc_vport *vport = NULL;
  12637. int i;
  12638. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  12639. fc_hdr->fh_d_id[1] << 8 |
  12640. fc_hdr->fh_d_id[2]);
  12641. if (did == Fabric_DID)
  12642. return phba->pport;
  12643. if ((phba->pport->fc_flag & FC_PT2PT) &&
  12644. !(phba->link_state == LPFC_HBA_READY))
  12645. return phba->pport;
  12646. vports = lpfc_create_vport_work_array(phba);
  12647. if (vports != NULL)
  12648. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  12649. if (phba->fcf.fcfi == fcfi &&
  12650. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  12651. vports[i]->fc_myDID == did) {
  12652. vport = vports[i];
  12653. break;
  12654. }
  12655. }
  12656. lpfc_destroy_vport_work_array(phba, vports);
  12657. return vport;
  12658. }
  12659. /**
  12660. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  12661. * @vport: The vport to work on.
  12662. *
  12663. * This function updates the receive sequence time stamp for this vport. The
  12664. * receive sequence time stamp indicates the time that the last frame of the
  12665. * the sequence that has been idle for the longest amount of time was received.
  12666. * the driver uses this time stamp to indicate if any received sequences have
  12667. * timed out.
  12668. **/
  12669. void
  12670. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  12671. {
  12672. struct lpfc_dmabuf *h_buf;
  12673. struct hbq_dmabuf *dmabuf = NULL;
  12674. /* get the oldest sequence on the rcv list */
  12675. h_buf = list_get_first(&vport->rcv_buffer_list,
  12676. struct lpfc_dmabuf, list);
  12677. if (!h_buf)
  12678. return;
  12679. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12680. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  12681. }
  12682. /**
  12683. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  12684. * @vport: The vport that the received sequences were sent to.
  12685. *
  12686. * This function cleans up all outstanding received sequences. This is called
  12687. * by the driver when a link event or user action invalidates all the received
  12688. * sequences.
  12689. **/
  12690. void
  12691. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  12692. {
  12693. struct lpfc_dmabuf *h_buf, *hnext;
  12694. struct lpfc_dmabuf *d_buf, *dnext;
  12695. struct hbq_dmabuf *dmabuf = NULL;
  12696. /* start with the oldest sequence on the rcv list */
  12697. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12698. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12699. list_del_init(&dmabuf->hbuf.list);
  12700. list_for_each_entry_safe(d_buf, dnext,
  12701. &dmabuf->dbuf.list, list) {
  12702. list_del_init(&d_buf->list);
  12703. lpfc_in_buf_free(vport->phba, d_buf);
  12704. }
  12705. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12706. }
  12707. }
  12708. /**
  12709. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  12710. * @vport: The vport that the received sequences were sent to.
  12711. *
  12712. * This function determines whether any received sequences have timed out by
  12713. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  12714. * indicates that there is at least one timed out sequence this routine will
  12715. * go through the received sequences one at a time from most inactive to most
  12716. * active to determine which ones need to be cleaned up. Once it has determined
  12717. * that a sequence needs to be cleaned up it will simply free up the resources
  12718. * without sending an abort.
  12719. **/
  12720. void
  12721. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  12722. {
  12723. struct lpfc_dmabuf *h_buf, *hnext;
  12724. struct lpfc_dmabuf *d_buf, *dnext;
  12725. struct hbq_dmabuf *dmabuf = NULL;
  12726. unsigned long timeout;
  12727. int abort_count = 0;
  12728. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12729. vport->rcv_buffer_time_stamp);
  12730. if (list_empty(&vport->rcv_buffer_list) ||
  12731. time_before(jiffies, timeout))
  12732. return;
  12733. /* start with the oldest sequence on the rcv list */
  12734. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12735. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12736. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12737. dmabuf->time_stamp);
  12738. if (time_before(jiffies, timeout))
  12739. break;
  12740. abort_count++;
  12741. list_del_init(&dmabuf->hbuf.list);
  12742. list_for_each_entry_safe(d_buf, dnext,
  12743. &dmabuf->dbuf.list, list) {
  12744. list_del_init(&d_buf->list);
  12745. lpfc_in_buf_free(vport->phba, d_buf);
  12746. }
  12747. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12748. }
  12749. if (abort_count)
  12750. lpfc_update_rcv_time_stamp(vport);
  12751. }
  12752. /**
  12753. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  12754. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  12755. *
  12756. * This function searches through the existing incomplete sequences that have
  12757. * been sent to this @vport. If the frame matches one of the incomplete
  12758. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  12759. * make up that sequence. If no sequence is found that matches this frame then
  12760. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  12761. * This function returns a pointer to the first dmabuf in the sequence list that
  12762. * the frame was linked to.
  12763. **/
  12764. static struct hbq_dmabuf *
  12765. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  12766. {
  12767. struct fc_frame_header *new_hdr;
  12768. struct fc_frame_header *temp_hdr;
  12769. struct lpfc_dmabuf *d_buf;
  12770. struct lpfc_dmabuf *h_buf;
  12771. struct hbq_dmabuf *seq_dmabuf = NULL;
  12772. struct hbq_dmabuf *temp_dmabuf = NULL;
  12773. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12774. dmabuf->time_stamp = jiffies;
  12775. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12776. /* Use the hdr_buf to find the sequence that this frame belongs to */
  12777. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12778. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12779. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12780. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12781. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12782. continue;
  12783. /* found a pending sequence that matches this frame */
  12784. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12785. break;
  12786. }
  12787. if (!seq_dmabuf) {
  12788. /*
  12789. * This indicates first frame received for this sequence.
  12790. * Queue the buffer on the vport's rcv_buffer_list.
  12791. */
  12792. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12793. lpfc_update_rcv_time_stamp(vport);
  12794. return dmabuf;
  12795. }
  12796. temp_hdr = seq_dmabuf->hbuf.virt;
  12797. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  12798. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12799. list_del_init(&seq_dmabuf->hbuf.list);
  12800. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12801. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12802. lpfc_update_rcv_time_stamp(vport);
  12803. return dmabuf;
  12804. }
  12805. /* move this sequence to the tail to indicate a young sequence */
  12806. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12807. seq_dmabuf->time_stamp = jiffies;
  12808. lpfc_update_rcv_time_stamp(vport);
  12809. if (list_empty(&seq_dmabuf->dbuf.list)) {
  12810. temp_hdr = dmabuf->hbuf.virt;
  12811. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12812. return seq_dmabuf;
  12813. }
  12814. /* find the correct place in the sequence to insert this frame */
  12815. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  12816. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  12817. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  12818. /*
  12819. * If the frame's sequence count is greater than the frame on
  12820. * the list then insert the frame right after this frame
  12821. */
  12822. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  12823. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12824. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  12825. return seq_dmabuf;
  12826. }
  12827. }
  12828. return NULL;
  12829. }
  12830. /**
  12831. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  12832. * @vport: pointer to a vitural port
  12833. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12834. *
  12835. * This function tries to abort from the partially assembed sequence, described
  12836. * by the information from basic abbort @dmabuf. It checks to see whether such
  12837. * partially assembled sequence held by the driver. If so, it shall free up all
  12838. * the frames from the partially assembled sequence.
  12839. *
  12840. * Return
  12841. * true -- if there is matching partially assembled sequence present and all
  12842. * the frames freed with the sequence;
  12843. * false -- if there is no matching partially assembled sequence present so
  12844. * nothing got aborted in the lower layer driver
  12845. **/
  12846. static bool
  12847. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  12848. struct hbq_dmabuf *dmabuf)
  12849. {
  12850. struct fc_frame_header *new_hdr;
  12851. struct fc_frame_header *temp_hdr;
  12852. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  12853. struct hbq_dmabuf *seq_dmabuf = NULL;
  12854. /* Use the hdr_buf to find the sequence that matches this frame */
  12855. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12856. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  12857. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12858. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12859. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12860. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12861. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12862. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12863. continue;
  12864. /* found a pending sequence that matches this frame */
  12865. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12866. break;
  12867. }
  12868. /* Free up all the frames from the partially assembled sequence */
  12869. if (seq_dmabuf) {
  12870. list_for_each_entry_safe(d_buf, n_buf,
  12871. &seq_dmabuf->dbuf.list, list) {
  12872. list_del_init(&d_buf->list);
  12873. lpfc_in_buf_free(vport->phba, d_buf);
  12874. }
  12875. return true;
  12876. }
  12877. return false;
  12878. }
  12879. /**
  12880. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  12881. * @phba: Pointer to HBA context object.
  12882. * @cmd_iocbq: pointer to the command iocbq structure.
  12883. * @rsp_iocbq: pointer to the response iocbq structure.
  12884. *
  12885. * This function handles the sequence abort response iocb command complete
  12886. * event. It properly releases the memory allocated to the sequence abort
  12887. * accept iocb.
  12888. **/
  12889. static void
  12890. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  12891. struct lpfc_iocbq *cmd_iocbq,
  12892. struct lpfc_iocbq *rsp_iocbq)
  12893. {
  12894. if (cmd_iocbq)
  12895. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  12896. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  12897. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  12898. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12899. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  12900. rsp_iocbq->iocb.ulpStatus,
  12901. rsp_iocbq->iocb.un.ulpWord[4]);
  12902. }
  12903. /**
  12904. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  12905. * @phba: Pointer to HBA context object.
  12906. * @xri: xri id in transaction.
  12907. *
  12908. * This function validates the xri maps to the known range of XRIs allocated an
  12909. * used by the driver.
  12910. **/
  12911. uint16_t
  12912. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  12913. uint16_t xri)
  12914. {
  12915. int i;
  12916. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  12917. if (xri == phba->sli4_hba.xri_ids[i])
  12918. return i;
  12919. }
  12920. return NO_XRI;
  12921. }
  12922. /**
  12923. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  12924. * @phba: Pointer to HBA context object.
  12925. * @fc_hdr: pointer to a FC frame header.
  12926. *
  12927. * This function sends a basic response to a previous unsol sequence abort
  12928. * event after aborting the sequence handling.
  12929. **/
  12930. static void
  12931. lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba,
  12932. struct fc_frame_header *fc_hdr)
  12933. {
  12934. struct lpfc_iocbq *ctiocb = NULL;
  12935. struct lpfc_nodelist *ndlp;
  12936. uint16_t oxid, rxid, xri, lxri;
  12937. uint32_t sid, fctl;
  12938. IOCB_t *icmd;
  12939. int rc;
  12940. if (!lpfc_is_link_up(phba))
  12941. return;
  12942. sid = sli4_sid_from_fc_hdr(fc_hdr);
  12943. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  12944. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  12945. ndlp = lpfc_findnode_did(phba->pport, sid);
  12946. if (!ndlp) {
  12947. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12948. "1268 Find ndlp returned NULL for oxid:x%x "
  12949. "SID:x%x\n", oxid, sid);
  12950. return;
  12951. }
  12952. /* Allocate buffer for rsp iocb */
  12953. ctiocb = lpfc_sli_get_iocbq(phba);
  12954. if (!ctiocb)
  12955. return;
  12956. /* Extract the F_CTL field from FC_HDR */
  12957. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  12958. icmd = &ctiocb->iocb;
  12959. icmd->un.xseq64.bdl.bdeSize = 0;
  12960. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  12961. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  12962. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  12963. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  12964. /* Fill in the rest of iocb fields */
  12965. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  12966. icmd->ulpBdeCount = 0;
  12967. icmd->ulpLe = 1;
  12968. icmd->ulpClass = CLASS3;
  12969. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  12970. ctiocb->context1 = ndlp;
  12971. ctiocb->iocb_cmpl = NULL;
  12972. ctiocb->vport = phba->pport;
  12973. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  12974. ctiocb->sli4_lxritag = NO_XRI;
  12975. ctiocb->sli4_xritag = NO_XRI;
  12976. if (fctl & FC_FC_EX_CTX)
  12977. /* Exchange responder sent the abort so we
  12978. * own the oxid.
  12979. */
  12980. xri = oxid;
  12981. else
  12982. xri = rxid;
  12983. lxri = lpfc_sli4_xri_inrange(phba, xri);
  12984. if (lxri != NO_XRI)
  12985. lpfc_set_rrq_active(phba, ndlp, lxri,
  12986. (xri == oxid) ? rxid : oxid, 0);
  12987. /* If the oxid maps to the FCP XRI range or if it is out of range,
  12988. * send a BLS_RJT. The driver no longer has that exchange.
  12989. * Override the IOCB for a BA_RJT.
  12990. */
  12991. if (xri > (phba->sli4_hba.max_cfg_param.max_xri +
  12992. phba->sli4_hba.max_cfg_param.xri_base) ||
  12993. xri > (lpfc_sli4_get_els_iocb_cnt(phba) +
  12994. phba->sli4_hba.max_cfg_param.xri_base)) {
  12995. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  12996. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  12997. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  12998. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  12999. }
  13000. if (fctl & FC_FC_EX_CTX) {
  13001. /* ABTS sent by responder to CT exchange, construction
  13002. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  13003. * field and RX_ID from ABTS for RX_ID field.
  13004. */
  13005. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  13006. } else {
  13007. /* ABTS sent by initiator to CT exchange, construction
  13008. * of BA_ACC will need to allocate a new XRI as for the
  13009. * XRI_TAG field.
  13010. */
  13011. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  13012. }
  13013. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  13014. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  13015. /* Xmit CT abts response on exchange <xid> */
  13016. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  13017. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  13018. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  13019. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  13020. if (rc == IOCB_ERROR) {
  13021. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  13022. "2925 Failed to issue CT ABTS RSP x%x on "
  13023. "xri x%x, Data x%x\n",
  13024. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  13025. phba->link_state);
  13026. lpfc_sli_release_iocbq(phba, ctiocb);
  13027. }
  13028. }
  13029. /**
  13030. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  13031. * @vport: Pointer to the vport on which this sequence was received
  13032. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13033. *
  13034. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  13035. * receive sequence is only partially assembed by the driver, it shall abort
  13036. * the partially assembled frames for the sequence. Otherwise, if the
  13037. * unsolicited receive sequence has been completely assembled and passed to
  13038. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  13039. * unsolicited sequence has been aborted. After that, it will issue a basic
  13040. * accept to accept the abort.
  13041. **/
  13042. void
  13043. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  13044. struct hbq_dmabuf *dmabuf)
  13045. {
  13046. struct lpfc_hba *phba = vport->phba;
  13047. struct fc_frame_header fc_hdr;
  13048. uint32_t fctl;
  13049. bool abts_par;
  13050. /* Make a copy of fc_hdr before the dmabuf being released */
  13051. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  13052. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  13053. if (fctl & FC_FC_EX_CTX) {
  13054. /*
  13055. * ABTS sent by responder to exchange, just free the buffer
  13056. */
  13057. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13058. } else {
  13059. /*
  13060. * ABTS sent by initiator to exchange, need to do cleanup
  13061. */
  13062. /* Try to abort partially assembled seq */
  13063. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  13064. /* Send abort to ULP if partially seq abort failed */
  13065. if (abts_par == false)
  13066. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  13067. else
  13068. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13069. }
  13070. /* Send basic accept (BA_ACC) to the abort requester */
  13071. lpfc_sli4_seq_abort_rsp(phba, &fc_hdr);
  13072. }
  13073. /**
  13074. * lpfc_seq_complete - Indicates if a sequence is complete
  13075. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13076. *
  13077. * This function checks the sequence, starting with the frame described by
  13078. * @dmabuf, to see if all the frames associated with this sequence are present.
  13079. * the frames associated with this sequence are linked to the @dmabuf using the
  13080. * dbuf list. This function looks for two major things. 1) That the first frame
  13081. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  13082. * set. 3) That there are no holes in the sequence count. The function will
  13083. * return 1 when the sequence is complete, otherwise it will return 0.
  13084. **/
  13085. static int
  13086. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  13087. {
  13088. struct fc_frame_header *hdr;
  13089. struct lpfc_dmabuf *d_buf;
  13090. struct hbq_dmabuf *seq_dmabuf;
  13091. uint32_t fctl;
  13092. int seq_count = 0;
  13093. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13094. /* make sure first fame of sequence has a sequence count of zero */
  13095. if (hdr->fh_seq_cnt != seq_count)
  13096. return 0;
  13097. fctl = (hdr->fh_f_ctl[0] << 16 |
  13098. hdr->fh_f_ctl[1] << 8 |
  13099. hdr->fh_f_ctl[2]);
  13100. /* If last frame of sequence we can return success. */
  13101. if (fctl & FC_FC_END_SEQ)
  13102. return 1;
  13103. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  13104. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13105. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13106. /* If there is a hole in the sequence count then fail. */
  13107. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  13108. return 0;
  13109. fctl = (hdr->fh_f_ctl[0] << 16 |
  13110. hdr->fh_f_ctl[1] << 8 |
  13111. hdr->fh_f_ctl[2]);
  13112. /* If last frame of sequence we can return success. */
  13113. if (fctl & FC_FC_END_SEQ)
  13114. return 1;
  13115. }
  13116. return 0;
  13117. }
  13118. /**
  13119. * lpfc_prep_seq - Prep sequence for ULP processing
  13120. * @vport: Pointer to the vport on which this sequence was received
  13121. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13122. *
  13123. * This function takes a sequence, described by a list of frames, and creates
  13124. * a list of iocbq structures to describe the sequence. This iocbq list will be
  13125. * used to issue to the generic unsolicited sequence handler. This routine
  13126. * returns a pointer to the first iocbq in the list. If the function is unable
  13127. * to allocate an iocbq then it throw out the received frames that were not
  13128. * able to be described and return a pointer to the first iocbq. If unable to
  13129. * allocate any iocbqs (including the first) this function will return NULL.
  13130. **/
  13131. static struct lpfc_iocbq *
  13132. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  13133. {
  13134. struct hbq_dmabuf *hbq_buf;
  13135. struct lpfc_dmabuf *d_buf, *n_buf;
  13136. struct lpfc_iocbq *first_iocbq, *iocbq;
  13137. struct fc_frame_header *fc_hdr;
  13138. uint32_t sid;
  13139. uint32_t len, tot_len;
  13140. struct ulp_bde64 *pbde;
  13141. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13142. /* remove from receive buffer list */
  13143. list_del_init(&seq_dmabuf->hbuf.list);
  13144. lpfc_update_rcv_time_stamp(vport);
  13145. /* get the Remote Port's SID */
  13146. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13147. tot_len = 0;
  13148. /* Get an iocbq struct to fill in. */
  13149. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  13150. if (first_iocbq) {
  13151. /* Initialize the first IOCB. */
  13152. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  13153. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  13154. /* Check FC Header to see what TYPE of frame we are rcv'ing */
  13155. if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
  13156. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
  13157. first_iocbq->iocb.un.rcvels.parmRo =
  13158. sli4_did_from_fc_hdr(fc_hdr);
  13159. first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
  13160. } else
  13161. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  13162. first_iocbq->iocb.ulpContext = NO_XRI;
  13163. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  13164. be16_to_cpu(fc_hdr->fh_ox_id);
  13165. /* iocbq is prepped for internal consumption. Physical vpi. */
  13166. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  13167. vport->phba->vpi_ids[vport->vpi];
  13168. /* put the first buffer into the first IOCBq */
  13169. first_iocbq->context2 = &seq_dmabuf->dbuf;
  13170. first_iocbq->context3 = NULL;
  13171. first_iocbq->iocb.ulpBdeCount = 1;
  13172. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13173. LPFC_DATA_BUF_SIZE;
  13174. first_iocbq->iocb.un.rcvels.remoteID = sid;
  13175. tot_len = bf_get(lpfc_rcqe_length,
  13176. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  13177. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13178. }
  13179. iocbq = first_iocbq;
  13180. /*
  13181. * Each IOCBq can have two Buffers assigned, so go through the list
  13182. * of buffers for this sequence and save two buffers in each IOCBq
  13183. */
  13184. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  13185. if (!iocbq) {
  13186. lpfc_in_buf_free(vport->phba, d_buf);
  13187. continue;
  13188. }
  13189. if (!iocbq->context3) {
  13190. iocbq->context3 = d_buf;
  13191. iocbq->iocb.ulpBdeCount++;
  13192. pbde = (struct ulp_bde64 *)
  13193. &iocbq->iocb.unsli3.sli3Words[4];
  13194. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  13195. /* We need to get the size out of the right CQE */
  13196. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13197. len = bf_get(lpfc_rcqe_length,
  13198. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13199. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  13200. tot_len += len;
  13201. } else {
  13202. iocbq = lpfc_sli_get_iocbq(vport->phba);
  13203. if (!iocbq) {
  13204. if (first_iocbq) {
  13205. first_iocbq->iocb.ulpStatus =
  13206. IOSTAT_FCP_RSP_ERROR;
  13207. first_iocbq->iocb.un.ulpWord[4] =
  13208. IOERR_NO_RESOURCES;
  13209. }
  13210. lpfc_in_buf_free(vport->phba, d_buf);
  13211. continue;
  13212. }
  13213. iocbq->context2 = d_buf;
  13214. iocbq->context3 = NULL;
  13215. iocbq->iocb.ulpBdeCount = 1;
  13216. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13217. LPFC_DATA_BUF_SIZE;
  13218. /* We need to get the size out of the right CQE */
  13219. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13220. len = bf_get(lpfc_rcqe_length,
  13221. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13222. tot_len += len;
  13223. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13224. iocbq->iocb.un.rcvels.remoteID = sid;
  13225. list_add_tail(&iocbq->list, &first_iocbq->list);
  13226. }
  13227. }
  13228. return first_iocbq;
  13229. }
  13230. static void
  13231. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  13232. struct hbq_dmabuf *seq_dmabuf)
  13233. {
  13234. struct fc_frame_header *fc_hdr;
  13235. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  13236. struct lpfc_hba *phba = vport->phba;
  13237. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13238. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  13239. if (!iocbq) {
  13240. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13241. "2707 Ring %d handler: Failed to allocate "
  13242. "iocb Rctl x%x Type x%x received\n",
  13243. LPFC_ELS_RING,
  13244. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13245. return;
  13246. }
  13247. if (!lpfc_complete_unsol_iocb(phba,
  13248. &phba->sli.ring[LPFC_ELS_RING],
  13249. iocbq, fc_hdr->fh_r_ctl,
  13250. fc_hdr->fh_type))
  13251. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13252. "2540 Ring %d handler: unexpected Rctl "
  13253. "x%x Type x%x received\n",
  13254. LPFC_ELS_RING,
  13255. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13256. /* Free iocb created in lpfc_prep_seq */
  13257. list_for_each_entry_safe(curr_iocb, next_iocb,
  13258. &iocbq->list, list) {
  13259. list_del_init(&curr_iocb->list);
  13260. lpfc_sli_release_iocbq(phba, curr_iocb);
  13261. }
  13262. lpfc_sli_release_iocbq(phba, iocbq);
  13263. }
  13264. /**
  13265. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  13266. * @phba: Pointer to HBA context object.
  13267. *
  13268. * This function is called with no lock held. This function processes all
  13269. * the received buffers and gives it to upper layers when a received buffer
  13270. * indicates that it is the final frame in the sequence. The interrupt
  13271. * service routine processes received buffers at interrupt contexts and adds
  13272. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  13273. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  13274. * appropriate receive function when the final frame in a sequence is received.
  13275. **/
  13276. void
  13277. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  13278. struct hbq_dmabuf *dmabuf)
  13279. {
  13280. struct hbq_dmabuf *seq_dmabuf;
  13281. struct fc_frame_header *fc_hdr;
  13282. struct lpfc_vport *vport;
  13283. uint32_t fcfi;
  13284. uint32_t did;
  13285. /* Process each received buffer */
  13286. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13287. /* check to see if this a valid type of frame */
  13288. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  13289. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13290. return;
  13291. }
  13292. if ((bf_get(lpfc_cqe_code,
  13293. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  13294. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  13295. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13296. else
  13297. fcfi = bf_get(lpfc_rcqe_fcf_id,
  13298. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13299. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  13300. if (!vport) {
  13301. /* throw out the frame */
  13302. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13303. return;
  13304. }
  13305. /* d_id this frame is directed to */
  13306. did = sli4_did_from_fc_hdr(fc_hdr);
  13307. /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
  13308. if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
  13309. (did != Fabric_DID)) {
  13310. /*
  13311. * Throw out the frame if we are not pt2pt.
  13312. * The pt2pt protocol allows for discovery frames
  13313. * to be received without a registered VPI.
  13314. */
  13315. if (!(vport->fc_flag & FC_PT2PT) ||
  13316. (phba->link_state == LPFC_HBA_READY)) {
  13317. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13318. return;
  13319. }
  13320. }
  13321. /* Handle the basic abort sequence (BA_ABTS) event */
  13322. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  13323. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  13324. return;
  13325. }
  13326. /* Link this frame */
  13327. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  13328. if (!seq_dmabuf) {
  13329. /* unable to add frame to vport - throw it out */
  13330. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13331. return;
  13332. }
  13333. /* If not last frame in sequence continue processing frames. */
  13334. if (!lpfc_seq_complete(seq_dmabuf))
  13335. return;
  13336. /* Send the complete sequence to the upper layer protocol */
  13337. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  13338. }
  13339. /**
  13340. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  13341. * @phba: pointer to lpfc hba data structure.
  13342. *
  13343. * This routine is invoked to post rpi header templates to the
  13344. * HBA consistent with the SLI-4 interface spec. This routine
  13345. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13346. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13347. *
  13348. * This routine does not require any locks. It's usage is expected
  13349. * to be driver load or reset recovery when the driver is
  13350. * sequential.
  13351. *
  13352. * Return codes
  13353. * 0 - successful
  13354. * -EIO - The mailbox failed to complete successfully.
  13355. * When this error occurs, the driver is not guaranteed
  13356. * to have any rpi regions posted to the device and
  13357. * must either attempt to repost the regions or take a
  13358. * fatal error.
  13359. **/
  13360. int
  13361. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  13362. {
  13363. struct lpfc_rpi_hdr *rpi_page;
  13364. uint32_t rc = 0;
  13365. uint16_t lrpi = 0;
  13366. /* SLI4 ports that support extents do not require RPI headers. */
  13367. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13368. goto exit;
  13369. if (phba->sli4_hba.extents_in_use)
  13370. return -EIO;
  13371. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  13372. /*
  13373. * Assign the rpi headers a physical rpi only if the driver
  13374. * has not initialized those resources. A port reset only
  13375. * needs the headers posted.
  13376. */
  13377. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  13378. LPFC_RPI_RSRC_RDY)
  13379. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13380. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  13381. if (rc != MBX_SUCCESS) {
  13382. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13383. "2008 Error %d posting all rpi "
  13384. "headers\n", rc);
  13385. rc = -EIO;
  13386. break;
  13387. }
  13388. }
  13389. exit:
  13390. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  13391. LPFC_RPI_RSRC_RDY);
  13392. return rc;
  13393. }
  13394. /**
  13395. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  13396. * @phba: pointer to lpfc hba data structure.
  13397. * @rpi_page: pointer to the rpi memory region.
  13398. *
  13399. * This routine is invoked to post a single rpi header to the
  13400. * HBA consistent with the SLI-4 interface spec. This memory region
  13401. * maps up to 64 rpi context regions.
  13402. *
  13403. * Return codes
  13404. * 0 - successful
  13405. * -ENOMEM - No available memory
  13406. * -EIO - The mailbox failed to complete successfully.
  13407. **/
  13408. int
  13409. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  13410. {
  13411. LPFC_MBOXQ_t *mboxq;
  13412. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  13413. uint32_t rc = 0;
  13414. uint32_t shdr_status, shdr_add_status;
  13415. union lpfc_sli4_cfg_shdr *shdr;
  13416. /* SLI4 ports that support extents do not require RPI headers. */
  13417. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13418. return rc;
  13419. if (phba->sli4_hba.extents_in_use)
  13420. return -EIO;
  13421. /* The port is notified of the header region via a mailbox command. */
  13422. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13423. if (!mboxq) {
  13424. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13425. "2001 Unable to allocate memory for issuing "
  13426. "SLI_CONFIG_SPECIAL mailbox command\n");
  13427. return -ENOMEM;
  13428. }
  13429. /* Post all rpi memory regions to the port. */
  13430. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  13431. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13432. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  13433. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  13434. sizeof(struct lpfc_sli4_cfg_mhdr),
  13435. LPFC_SLI4_MBX_EMBED);
  13436. /* Post the physical rpi to the port for this rpi header. */
  13437. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  13438. rpi_page->start_rpi);
  13439. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  13440. hdr_tmpl, rpi_page->page_count);
  13441. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  13442. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  13443. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  13444. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  13445. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13446. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13447. if (rc != MBX_TIMEOUT)
  13448. mempool_free(mboxq, phba->mbox_mem_pool);
  13449. if (shdr_status || shdr_add_status || rc) {
  13450. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13451. "2514 POST_RPI_HDR mailbox failed with "
  13452. "status x%x add_status x%x, mbx status x%x\n",
  13453. shdr_status, shdr_add_status, rc);
  13454. rc = -ENXIO;
  13455. }
  13456. return rc;
  13457. }
  13458. /**
  13459. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  13460. * @phba: pointer to lpfc hba data structure.
  13461. *
  13462. * This routine is invoked to post rpi header templates to the
  13463. * HBA consistent with the SLI-4 interface spec. This routine
  13464. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13465. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13466. *
  13467. * Returns
  13468. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13469. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13470. **/
  13471. int
  13472. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  13473. {
  13474. unsigned long rpi;
  13475. uint16_t max_rpi, rpi_limit;
  13476. uint16_t rpi_remaining, lrpi = 0;
  13477. struct lpfc_rpi_hdr *rpi_hdr;
  13478. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  13479. rpi_limit = phba->sli4_hba.next_rpi;
  13480. /*
  13481. * Fetch the next logical rpi. Because this index is logical,
  13482. * the driver starts at 0 each time.
  13483. */
  13484. spin_lock_irq(&phba->hbalock);
  13485. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  13486. if (rpi >= rpi_limit)
  13487. rpi = LPFC_RPI_ALLOC_ERROR;
  13488. else {
  13489. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  13490. phba->sli4_hba.max_cfg_param.rpi_used++;
  13491. phba->sli4_hba.rpi_count++;
  13492. }
  13493. /*
  13494. * Don't try to allocate more rpi header regions if the device limit
  13495. * has been exhausted.
  13496. */
  13497. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  13498. (phba->sli4_hba.rpi_count >= max_rpi)) {
  13499. spin_unlock_irq(&phba->hbalock);
  13500. return rpi;
  13501. }
  13502. /*
  13503. * RPI header postings are not required for SLI4 ports capable of
  13504. * extents.
  13505. */
  13506. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  13507. spin_unlock_irq(&phba->hbalock);
  13508. return rpi;
  13509. }
  13510. /*
  13511. * If the driver is running low on rpi resources, allocate another
  13512. * page now. Note that the next_rpi value is used because
  13513. * it represents how many are actually in use whereas max_rpi notes
  13514. * how many are supported max by the device.
  13515. */
  13516. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  13517. spin_unlock_irq(&phba->hbalock);
  13518. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  13519. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  13520. if (!rpi_hdr) {
  13521. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13522. "2002 Error Could not grow rpi "
  13523. "count\n");
  13524. } else {
  13525. lrpi = rpi_hdr->start_rpi;
  13526. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13527. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  13528. }
  13529. }
  13530. return rpi;
  13531. }
  13532. /**
  13533. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13534. * @phba: pointer to lpfc hba data structure.
  13535. *
  13536. * This routine is invoked to release an rpi to the pool of
  13537. * available rpis maintained by the driver.
  13538. **/
  13539. void
  13540. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13541. {
  13542. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  13543. phba->sli4_hba.rpi_count--;
  13544. phba->sli4_hba.max_cfg_param.rpi_used--;
  13545. }
  13546. }
  13547. /**
  13548. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13549. * @phba: pointer to lpfc hba data structure.
  13550. *
  13551. * This routine is invoked to release an rpi to the pool of
  13552. * available rpis maintained by the driver.
  13553. **/
  13554. void
  13555. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13556. {
  13557. spin_lock_irq(&phba->hbalock);
  13558. __lpfc_sli4_free_rpi(phba, rpi);
  13559. spin_unlock_irq(&phba->hbalock);
  13560. }
  13561. /**
  13562. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  13563. * @phba: pointer to lpfc hba data structure.
  13564. *
  13565. * This routine is invoked to remove the memory region that
  13566. * provided rpi via a bitmask.
  13567. **/
  13568. void
  13569. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  13570. {
  13571. kfree(phba->sli4_hba.rpi_bmask);
  13572. kfree(phba->sli4_hba.rpi_ids);
  13573. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  13574. }
  13575. /**
  13576. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  13577. * @phba: pointer to lpfc hba data structure.
  13578. *
  13579. * This routine is invoked to remove the memory region that
  13580. * provided rpi via a bitmask.
  13581. **/
  13582. int
  13583. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  13584. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  13585. {
  13586. LPFC_MBOXQ_t *mboxq;
  13587. struct lpfc_hba *phba = ndlp->phba;
  13588. int rc;
  13589. /* The port is notified of the header region via a mailbox command. */
  13590. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13591. if (!mboxq)
  13592. return -ENOMEM;
  13593. /* Post all rpi memory regions to the port. */
  13594. lpfc_resume_rpi(mboxq, ndlp);
  13595. if (cmpl) {
  13596. mboxq->mbox_cmpl = cmpl;
  13597. mboxq->context1 = arg;
  13598. mboxq->context2 = ndlp;
  13599. } else
  13600. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13601. mboxq->vport = ndlp->vport;
  13602. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13603. if (rc == MBX_NOT_FINISHED) {
  13604. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13605. "2010 Resume RPI Mailbox failed "
  13606. "status %d, mbxStatus x%x\n", rc,
  13607. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13608. mempool_free(mboxq, phba->mbox_mem_pool);
  13609. return -EIO;
  13610. }
  13611. return 0;
  13612. }
  13613. /**
  13614. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  13615. * @vport: Pointer to the vport for which the vpi is being initialized
  13616. *
  13617. * This routine is invoked to activate a vpi with the port.
  13618. *
  13619. * Returns:
  13620. * 0 success
  13621. * -Evalue otherwise
  13622. **/
  13623. int
  13624. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  13625. {
  13626. LPFC_MBOXQ_t *mboxq;
  13627. int rc = 0;
  13628. int retval = MBX_SUCCESS;
  13629. uint32_t mbox_tmo;
  13630. struct lpfc_hba *phba = vport->phba;
  13631. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13632. if (!mboxq)
  13633. return -ENOMEM;
  13634. lpfc_init_vpi(phba, mboxq, vport->vpi);
  13635. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  13636. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  13637. if (rc != MBX_SUCCESS) {
  13638. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  13639. "2022 INIT VPI Mailbox failed "
  13640. "status %d, mbxStatus x%x\n", rc,
  13641. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13642. retval = -EIO;
  13643. }
  13644. if (rc != MBX_TIMEOUT)
  13645. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  13646. return retval;
  13647. }
  13648. /**
  13649. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  13650. * @phba: pointer to lpfc hba data structure.
  13651. * @mboxq: Pointer to mailbox object.
  13652. *
  13653. * This routine is invoked to manually add a single FCF record. The caller
  13654. * must pass a completely initialized FCF_Record. This routine takes
  13655. * care of the nonembedded mailbox operations.
  13656. **/
  13657. static void
  13658. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  13659. {
  13660. void *virt_addr;
  13661. union lpfc_sli4_cfg_shdr *shdr;
  13662. uint32_t shdr_status, shdr_add_status;
  13663. virt_addr = mboxq->sge_array->addr[0];
  13664. /* The IOCTL status is embedded in the mailbox subheader. */
  13665. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  13666. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13667. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13668. if ((shdr_status || shdr_add_status) &&
  13669. (shdr_status != STATUS_FCF_IN_USE))
  13670. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13671. "2558 ADD_FCF_RECORD mailbox failed with "
  13672. "status x%x add_status x%x\n",
  13673. shdr_status, shdr_add_status);
  13674. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13675. }
  13676. /**
  13677. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  13678. * @phba: pointer to lpfc hba data structure.
  13679. * @fcf_record: pointer to the initialized fcf record to add.
  13680. *
  13681. * This routine is invoked to manually add a single FCF record. The caller
  13682. * must pass a completely initialized FCF_Record. This routine takes
  13683. * care of the nonembedded mailbox operations.
  13684. **/
  13685. int
  13686. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  13687. {
  13688. int rc = 0;
  13689. LPFC_MBOXQ_t *mboxq;
  13690. uint8_t *bytep;
  13691. void *virt_addr;
  13692. dma_addr_t phys_addr;
  13693. struct lpfc_mbx_sge sge;
  13694. uint32_t alloc_len, req_len;
  13695. uint32_t fcfindex;
  13696. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13697. if (!mboxq) {
  13698. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13699. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  13700. return -ENOMEM;
  13701. }
  13702. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  13703. sizeof(uint32_t);
  13704. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13705. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13706. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  13707. req_len, LPFC_SLI4_MBX_NEMBED);
  13708. if (alloc_len < req_len) {
  13709. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13710. "2523 Allocated DMA memory size (x%x) is "
  13711. "less than the requested DMA memory "
  13712. "size (x%x)\n", alloc_len, req_len);
  13713. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13714. return -ENOMEM;
  13715. }
  13716. /*
  13717. * Get the first SGE entry from the non-embedded DMA memory. This
  13718. * routine only uses a single SGE.
  13719. */
  13720. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  13721. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  13722. virt_addr = mboxq->sge_array->addr[0];
  13723. /*
  13724. * Configure the FCF record for FCFI 0. This is the driver's
  13725. * hardcoded default and gets used in nonFIP mode.
  13726. */
  13727. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  13728. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  13729. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  13730. /*
  13731. * Copy the fcf_index and the FCF Record Data. The data starts after
  13732. * the FCoE header plus word10. The data copy needs to be endian
  13733. * correct.
  13734. */
  13735. bytep += sizeof(uint32_t);
  13736. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  13737. mboxq->vport = phba->pport;
  13738. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  13739. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13740. if (rc == MBX_NOT_FINISHED) {
  13741. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13742. "2515 ADD_FCF_RECORD mailbox failed with "
  13743. "status 0x%x\n", rc);
  13744. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13745. rc = -EIO;
  13746. } else
  13747. rc = 0;
  13748. return rc;
  13749. }
  13750. /**
  13751. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  13752. * @phba: pointer to lpfc hba data structure.
  13753. * @fcf_record: pointer to the fcf record to write the default data.
  13754. * @fcf_index: FCF table entry index.
  13755. *
  13756. * This routine is invoked to build the driver's default FCF record. The
  13757. * values used are hardcoded. This routine handles memory initialization.
  13758. *
  13759. **/
  13760. void
  13761. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  13762. struct fcf_record *fcf_record,
  13763. uint16_t fcf_index)
  13764. {
  13765. memset(fcf_record, 0, sizeof(struct fcf_record));
  13766. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  13767. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  13768. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  13769. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  13770. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  13771. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  13772. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  13773. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  13774. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  13775. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  13776. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  13777. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  13778. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  13779. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  13780. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  13781. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  13782. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  13783. /* Set the VLAN bit map */
  13784. if (phba->valid_vlan) {
  13785. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  13786. = 1 << (phba->vlan_id % 8);
  13787. }
  13788. }
  13789. /**
  13790. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  13791. * @phba: pointer to lpfc hba data structure.
  13792. * @fcf_index: FCF table entry offset.
  13793. *
  13794. * This routine is invoked to scan the entire FCF table by reading FCF
  13795. * record and processing it one at a time starting from the @fcf_index
  13796. * for initial FCF discovery or fast FCF failover rediscovery.
  13797. *
  13798. * Return 0 if the mailbox command is submitted successfully, none 0
  13799. * otherwise.
  13800. **/
  13801. int
  13802. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13803. {
  13804. int rc = 0, error;
  13805. LPFC_MBOXQ_t *mboxq;
  13806. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  13807. phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
  13808. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13809. if (!mboxq) {
  13810. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13811. "2000 Failed to allocate mbox for "
  13812. "READ_FCF cmd\n");
  13813. error = -ENOMEM;
  13814. goto fail_fcf_scan;
  13815. }
  13816. /* Construct the read FCF record mailbox command */
  13817. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13818. if (rc) {
  13819. error = -EINVAL;
  13820. goto fail_fcf_scan;
  13821. }
  13822. /* Issue the mailbox command asynchronously */
  13823. mboxq->vport = phba->pport;
  13824. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  13825. spin_lock_irq(&phba->hbalock);
  13826. phba->hba_flag |= FCF_TS_INPROG;
  13827. spin_unlock_irq(&phba->hbalock);
  13828. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13829. if (rc == MBX_NOT_FINISHED)
  13830. error = -EIO;
  13831. else {
  13832. /* Reset eligible FCF count for new scan */
  13833. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  13834. phba->fcf.eligible_fcf_cnt = 0;
  13835. error = 0;
  13836. }
  13837. fail_fcf_scan:
  13838. if (error) {
  13839. if (mboxq)
  13840. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13841. /* FCF scan failed, clear FCF_TS_INPROG flag */
  13842. spin_lock_irq(&phba->hbalock);
  13843. phba->hba_flag &= ~FCF_TS_INPROG;
  13844. spin_unlock_irq(&phba->hbalock);
  13845. }
  13846. return error;
  13847. }
  13848. /**
  13849. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  13850. * @phba: pointer to lpfc hba data structure.
  13851. * @fcf_index: FCF table entry offset.
  13852. *
  13853. * This routine is invoked to read an FCF record indicated by @fcf_index
  13854. * and to use it for FLOGI roundrobin FCF failover.
  13855. *
  13856. * Return 0 if the mailbox command is submitted successfully, none 0
  13857. * otherwise.
  13858. **/
  13859. int
  13860. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13861. {
  13862. int rc = 0, error;
  13863. LPFC_MBOXQ_t *mboxq;
  13864. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13865. if (!mboxq) {
  13866. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13867. "2763 Failed to allocate mbox for "
  13868. "READ_FCF cmd\n");
  13869. error = -ENOMEM;
  13870. goto fail_fcf_read;
  13871. }
  13872. /* Construct the read FCF record mailbox command */
  13873. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13874. if (rc) {
  13875. error = -EINVAL;
  13876. goto fail_fcf_read;
  13877. }
  13878. /* Issue the mailbox command asynchronously */
  13879. mboxq->vport = phba->pport;
  13880. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  13881. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13882. if (rc == MBX_NOT_FINISHED)
  13883. error = -EIO;
  13884. else
  13885. error = 0;
  13886. fail_fcf_read:
  13887. if (error && mboxq)
  13888. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13889. return error;
  13890. }
  13891. /**
  13892. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  13893. * @phba: pointer to lpfc hba data structure.
  13894. * @fcf_index: FCF table entry offset.
  13895. *
  13896. * This routine is invoked to read an FCF record indicated by @fcf_index to
  13897. * determine whether it's eligible for FLOGI roundrobin failover list.
  13898. *
  13899. * Return 0 if the mailbox command is submitted successfully, none 0
  13900. * otherwise.
  13901. **/
  13902. int
  13903. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13904. {
  13905. int rc = 0, error;
  13906. LPFC_MBOXQ_t *mboxq;
  13907. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13908. if (!mboxq) {
  13909. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13910. "2758 Failed to allocate mbox for "
  13911. "READ_FCF cmd\n");
  13912. error = -ENOMEM;
  13913. goto fail_fcf_read;
  13914. }
  13915. /* Construct the read FCF record mailbox command */
  13916. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13917. if (rc) {
  13918. error = -EINVAL;
  13919. goto fail_fcf_read;
  13920. }
  13921. /* Issue the mailbox command asynchronously */
  13922. mboxq->vport = phba->pport;
  13923. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  13924. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13925. if (rc == MBX_NOT_FINISHED)
  13926. error = -EIO;
  13927. else
  13928. error = 0;
  13929. fail_fcf_read:
  13930. if (error && mboxq)
  13931. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13932. return error;
  13933. }
  13934. /**
  13935. * lpfc_check_next_fcf_pri
  13936. * phba pointer to the lpfc_hba struct for this port.
  13937. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  13938. * routine when the rr_bmask is empty. The FCF indecies are put into the
  13939. * rr_bmask based on their priority level. Starting from the highest priority
  13940. * to the lowest. The most likely FCF candidate will be in the highest
  13941. * priority group. When this routine is called it searches the fcf_pri list for
  13942. * next lowest priority group and repopulates the rr_bmask with only those
  13943. * fcf_indexes.
  13944. * returns:
  13945. * 1=success 0=failure
  13946. **/
  13947. int
  13948. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  13949. {
  13950. uint16_t next_fcf_pri;
  13951. uint16_t last_index;
  13952. struct lpfc_fcf_pri *fcf_pri;
  13953. int rc;
  13954. int ret = 0;
  13955. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  13956. LPFC_SLI4_FCF_TBL_INDX_MAX);
  13957. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13958. "3060 Last IDX %d\n", last_index);
  13959. if (list_empty(&phba->fcf.fcf_pri_list)) {
  13960. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13961. "3061 Last IDX %d\n", last_index);
  13962. return 0; /* Empty rr list */
  13963. }
  13964. next_fcf_pri = 0;
  13965. /*
  13966. * Clear the rr_bmask and set all of the bits that are at this
  13967. * priority.
  13968. */
  13969. memset(phba->fcf.fcf_rr_bmask, 0,
  13970. sizeof(*phba->fcf.fcf_rr_bmask));
  13971. spin_lock_irq(&phba->hbalock);
  13972. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13973. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  13974. continue;
  13975. /*
  13976. * the 1st priority that has not FLOGI failed
  13977. * will be the highest.
  13978. */
  13979. if (!next_fcf_pri)
  13980. next_fcf_pri = fcf_pri->fcf_rec.priority;
  13981. spin_unlock_irq(&phba->hbalock);
  13982. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  13983. rc = lpfc_sli4_fcf_rr_index_set(phba,
  13984. fcf_pri->fcf_rec.fcf_index);
  13985. if (rc)
  13986. return 0;
  13987. }
  13988. spin_lock_irq(&phba->hbalock);
  13989. }
  13990. /*
  13991. * if next_fcf_pri was not set above and the list is not empty then
  13992. * we have failed flogis on all of them. So reset flogi failed
  13993. * and start at the beginning.
  13994. */
  13995. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  13996. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13997. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  13998. /*
  13999. * the 1st priority that has not FLOGI failed
  14000. * will be the highest.
  14001. */
  14002. if (!next_fcf_pri)
  14003. next_fcf_pri = fcf_pri->fcf_rec.priority;
  14004. spin_unlock_irq(&phba->hbalock);
  14005. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  14006. rc = lpfc_sli4_fcf_rr_index_set(phba,
  14007. fcf_pri->fcf_rec.fcf_index);
  14008. if (rc)
  14009. return 0;
  14010. }
  14011. spin_lock_irq(&phba->hbalock);
  14012. }
  14013. } else
  14014. ret = 1;
  14015. spin_unlock_irq(&phba->hbalock);
  14016. return ret;
  14017. }
  14018. /**
  14019. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  14020. * @phba: pointer to lpfc hba data structure.
  14021. *
  14022. * This routine is to get the next eligible FCF record index in a round
  14023. * robin fashion. If the next eligible FCF record index equals to the
  14024. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  14025. * shall be returned, otherwise, the next eligible FCF record's index
  14026. * shall be returned.
  14027. **/
  14028. uint16_t
  14029. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  14030. {
  14031. uint16_t next_fcf_index;
  14032. /* Search start from next bit of currently registered FCF index */
  14033. next_priority:
  14034. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  14035. LPFC_SLI4_FCF_TBL_INDX_MAX;
  14036. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14037. LPFC_SLI4_FCF_TBL_INDX_MAX,
  14038. next_fcf_index);
  14039. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  14040. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14041. /*
  14042. * If we have wrapped then we need to clear the bits that
  14043. * have been tested so that we can detect when we should
  14044. * change the priority level.
  14045. */
  14046. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14047. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  14048. }
  14049. /* Check roundrobin failover list empty condition */
  14050. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  14051. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  14052. /*
  14053. * If next fcf index is not found check if there are lower
  14054. * Priority level fcf's in the fcf_priority list.
  14055. * Set up the rr_bmask with all of the avaiable fcf bits
  14056. * at that level and continue the selection process.
  14057. */
  14058. if (lpfc_check_next_fcf_pri_level(phba))
  14059. goto next_priority;
  14060. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14061. "2844 No roundrobin failover FCF available\n");
  14062. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  14063. return LPFC_FCOE_FCF_NEXT_NONE;
  14064. else {
  14065. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14066. "3063 Only FCF available idx %d, flag %x\n",
  14067. next_fcf_index,
  14068. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  14069. return next_fcf_index;
  14070. }
  14071. }
  14072. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  14073. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  14074. LPFC_FCF_FLOGI_FAILED)
  14075. goto next_priority;
  14076. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14077. "2845 Get next roundrobin failover FCF (x%x)\n",
  14078. next_fcf_index);
  14079. return next_fcf_index;
  14080. }
  14081. /**
  14082. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  14083. * @phba: pointer to lpfc hba data structure.
  14084. *
  14085. * This routine sets the FCF record index in to the eligible bmask for
  14086. * roundrobin failover search. It checks to make sure that the index
  14087. * does not go beyond the range of the driver allocated bmask dimension
  14088. * before setting the bit.
  14089. *
  14090. * Returns 0 if the index bit successfully set, otherwise, it returns
  14091. * -EINVAL.
  14092. **/
  14093. int
  14094. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  14095. {
  14096. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14097. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14098. "2610 FCF (x%x) reached driver's book "
  14099. "keeping dimension:x%x\n",
  14100. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14101. return -EINVAL;
  14102. }
  14103. /* Set the eligible FCF record index bmask */
  14104. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14105. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14106. "2790 Set FCF (x%x) to roundrobin FCF failover "
  14107. "bmask\n", fcf_index);
  14108. return 0;
  14109. }
  14110. /**
  14111. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  14112. * @phba: pointer to lpfc hba data structure.
  14113. *
  14114. * This routine clears the FCF record index from the eligible bmask for
  14115. * roundrobin failover search. It checks to make sure that the index
  14116. * does not go beyond the range of the driver allocated bmask dimension
  14117. * before clearing the bit.
  14118. **/
  14119. void
  14120. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  14121. {
  14122. struct lpfc_fcf_pri *fcf_pri;
  14123. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14124. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14125. "2762 FCF (x%x) reached driver's book "
  14126. "keeping dimension:x%x\n",
  14127. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14128. return;
  14129. }
  14130. /* Clear the eligible FCF record index bmask */
  14131. spin_lock_irq(&phba->hbalock);
  14132. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14133. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  14134. list_del_init(&fcf_pri->list);
  14135. break;
  14136. }
  14137. }
  14138. spin_unlock_irq(&phba->hbalock);
  14139. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14140. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14141. "2791 Clear FCF (x%x) from roundrobin failover "
  14142. "bmask\n", fcf_index);
  14143. }
  14144. /**
  14145. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  14146. * @phba: pointer to lpfc hba data structure.
  14147. *
  14148. * This routine is the completion routine for the rediscover FCF table mailbox
  14149. * command. If the mailbox command returned failure, it will try to stop the
  14150. * FCF rediscover wait timer.
  14151. **/
  14152. void
  14153. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  14154. {
  14155. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14156. uint32_t shdr_status, shdr_add_status;
  14157. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14158. shdr_status = bf_get(lpfc_mbox_hdr_status,
  14159. &redisc_fcf->header.cfg_shdr.response);
  14160. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  14161. &redisc_fcf->header.cfg_shdr.response);
  14162. if (shdr_status || shdr_add_status) {
  14163. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14164. "2746 Requesting for FCF rediscovery failed "
  14165. "status x%x add_status x%x\n",
  14166. shdr_status, shdr_add_status);
  14167. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  14168. spin_lock_irq(&phba->hbalock);
  14169. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  14170. spin_unlock_irq(&phba->hbalock);
  14171. /*
  14172. * CVL event triggered FCF rediscover request failed,
  14173. * last resort to re-try current registered FCF entry.
  14174. */
  14175. lpfc_retry_pport_discovery(phba);
  14176. } else {
  14177. spin_lock_irq(&phba->hbalock);
  14178. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  14179. spin_unlock_irq(&phba->hbalock);
  14180. /*
  14181. * DEAD FCF event triggered FCF rediscover request
  14182. * failed, last resort to fail over as a link down
  14183. * to FCF registration.
  14184. */
  14185. lpfc_sli4_fcf_dead_failthrough(phba);
  14186. }
  14187. } else {
  14188. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14189. "2775 Start FCF rediscover quiescent timer\n");
  14190. /*
  14191. * Start FCF rediscovery wait timer for pending FCF
  14192. * before rescan FCF record table.
  14193. */
  14194. lpfc_fcf_redisc_wait_start_timer(phba);
  14195. }
  14196. mempool_free(mbox, phba->mbox_mem_pool);
  14197. }
  14198. /**
  14199. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  14200. * @phba: pointer to lpfc hba data structure.
  14201. *
  14202. * This routine is invoked to request for rediscovery of the entire FCF table
  14203. * by the port.
  14204. **/
  14205. int
  14206. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  14207. {
  14208. LPFC_MBOXQ_t *mbox;
  14209. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14210. int rc, length;
  14211. /* Cancel retry delay timers to all vports before FCF rediscover */
  14212. lpfc_cancel_all_vport_retry_delay_timer(phba);
  14213. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14214. if (!mbox) {
  14215. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14216. "2745 Failed to allocate mbox for "
  14217. "requesting FCF rediscover.\n");
  14218. return -ENOMEM;
  14219. }
  14220. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  14221. sizeof(struct lpfc_sli4_cfg_mhdr));
  14222. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  14223. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  14224. length, LPFC_SLI4_MBX_EMBED);
  14225. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14226. /* Set count to 0 for invalidating the entire FCF database */
  14227. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  14228. /* Issue the mailbox command asynchronously */
  14229. mbox->vport = phba->pport;
  14230. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  14231. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  14232. if (rc == MBX_NOT_FINISHED) {
  14233. mempool_free(mbox, phba->mbox_mem_pool);
  14234. return -EIO;
  14235. }
  14236. return 0;
  14237. }
  14238. /**
  14239. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  14240. * @phba: pointer to lpfc hba data structure.
  14241. *
  14242. * This function is the failover routine as a last resort to the FCF DEAD
  14243. * event when driver failed to perform fast FCF failover.
  14244. **/
  14245. void
  14246. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  14247. {
  14248. uint32_t link_state;
  14249. /*
  14250. * Last resort as FCF DEAD event failover will treat this as
  14251. * a link down, but save the link state because we don't want
  14252. * it to be changed to Link Down unless it is already down.
  14253. */
  14254. link_state = phba->link_state;
  14255. lpfc_linkdown(phba);
  14256. phba->link_state = link_state;
  14257. /* Unregister FCF if no devices connected to it */
  14258. lpfc_unregister_unused_fcf(phba);
  14259. }
  14260. /**
  14261. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  14262. * @phba: pointer to lpfc hba data structure.
  14263. * @rgn23_data: pointer to configure region 23 data.
  14264. *
  14265. * This function gets SLI3 port configure region 23 data through memory dump
  14266. * mailbox command. When it successfully retrieves data, the size of the data
  14267. * will be returned, otherwise, 0 will be returned.
  14268. **/
  14269. static uint32_t
  14270. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14271. {
  14272. LPFC_MBOXQ_t *pmb = NULL;
  14273. MAILBOX_t *mb;
  14274. uint32_t offset = 0;
  14275. int rc;
  14276. if (!rgn23_data)
  14277. return 0;
  14278. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14279. if (!pmb) {
  14280. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14281. "2600 failed to allocate mailbox memory\n");
  14282. return 0;
  14283. }
  14284. mb = &pmb->u.mb;
  14285. do {
  14286. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  14287. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  14288. if (rc != MBX_SUCCESS) {
  14289. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  14290. "2601 failed to read config "
  14291. "region 23, rc 0x%x Status 0x%x\n",
  14292. rc, mb->mbxStatus);
  14293. mb->un.varDmp.word_cnt = 0;
  14294. }
  14295. /*
  14296. * dump mem may return a zero when finished or we got a
  14297. * mailbox error, either way we are done.
  14298. */
  14299. if (mb->un.varDmp.word_cnt == 0)
  14300. break;
  14301. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  14302. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  14303. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  14304. rgn23_data + offset,
  14305. mb->un.varDmp.word_cnt);
  14306. offset += mb->un.varDmp.word_cnt;
  14307. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  14308. mempool_free(pmb, phba->mbox_mem_pool);
  14309. return offset;
  14310. }
  14311. /**
  14312. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  14313. * @phba: pointer to lpfc hba data structure.
  14314. * @rgn23_data: pointer to configure region 23 data.
  14315. *
  14316. * This function gets SLI4 port configure region 23 data through memory dump
  14317. * mailbox command. When it successfully retrieves data, the size of the data
  14318. * will be returned, otherwise, 0 will be returned.
  14319. **/
  14320. static uint32_t
  14321. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14322. {
  14323. LPFC_MBOXQ_t *mboxq = NULL;
  14324. struct lpfc_dmabuf *mp = NULL;
  14325. struct lpfc_mqe *mqe;
  14326. uint32_t data_length = 0;
  14327. int rc;
  14328. if (!rgn23_data)
  14329. return 0;
  14330. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14331. if (!mboxq) {
  14332. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14333. "3105 failed to allocate mailbox memory\n");
  14334. return 0;
  14335. }
  14336. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  14337. goto out;
  14338. mqe = &mboxq->u.mqe;
  14339. mp = (struct lpfc_dmabuf *) mboxq->context1;
  14340. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14341. if (rc)
  14342. goto out;
  14343. data_length = mqe->un.mb_words[5];
  14344. if (data_length == 0)
  14345. goto out;
  14346. if (data_length > DMP_RGN23_SIZE) {
  14347. data_length = 0;
  14348. goto out;
  14349. }
  14350. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  14351. out:
  14352. mempool_free(mboxq, phba->mbox_mem_pool);
  14353. if (mp) {
  14354. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14355. kfree(mp);
  14356. }
  14357. return data_length;
  14358. }
  14359. /**
  14360. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  14361. * @phba: pointer to lpfc hba data structure.
  14362. *
  14363. * This function read region 23 and parse TLV for port status to
  14364. * decide if the user disaled the port. If the TLV indicates the
  14365. * port is disabled, the hba_flag is set accordingly.
  14366. **/
  14367. void
  14368. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  14369. {
  14370. uint8_t *rgn23_data = NULL;
  14371. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  14372. uint32_t offset = 0;
  14373. /* Get adapter Region 23 data */
  14374. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  14375. if (!rgn23_data)
  14376. goto out;
  14377. if (phba->sli_rev < LPFC_SLI_REV4)
  14378. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  14379. else {
  14380. if_type = bf_get(lpfc_sli_intf_if_type,
  14381. &phba->sli4_hba.sli_intf);
  14382. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  14383. goto out;
  14384. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  14385. }
  14386. if (!data_size)
  14387. goto out;
  14388. /* Check the region signature first */
  14389. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  14390. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14391. "2619 Config region 23 has bad signature\n");
  14392. goto out;
  14393. }
  14394. offset += 4;
  14395. /* Check the data structure version */
  14396. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  14397. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14398. "2620 Config region 23 has bad version\n");
  14399. goto out;
  14400. }
  14401. offset += 4;
  14402. /* Parse TLV entries in the region */
  14403. while (offset < data_size) {
  14404. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  14405. break;
  14406. /*
  14407. * If the TLV is not driver specific TLV or driver id is
  14408. * not linux driver id, skip the record.
  14409. */
  14410. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  14411. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  14412. (rgn23_data[offset + 3] != 0)) {
  14413. offset += rgn23_data[offset + 1] * 4 + 4;
  14414. continue;
  14415. }
  14416. /* Driver found a driver specific TLV in the config region */
  14417. sub_tlv_len = rgn23_data[offset + 1] * 4;
  14418. offset += 4;
  14419. tlv_offset = 0;
  14420. /*
  14421. * Search for configured port state sub-TLV.
  14422. */
  14423. while ((offset < data_size) &&
  14424. (tlv_offset < sub_tlv_len)) {
  14425. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  14426. offset += 4;
  14427. tlv_offset += 4;
  14428. break;
  14429. }
  14430. if (rgn23_data[offset] != PORT_STE_TYPE) {
  14431. offset += rgn23_data[offset + 1] * 4 + 4;
  14432. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  14433. continue;
  14434. }
  14435. /* This HBA contains PORT_STE configured */
  14436. if (!rgn23_data[offset + 2])
  14437. phba->hba_flag |= LINK_DISABLED;
  14438. goto out;
  14439. }
  14440. }
  14441. out:
  14442. kfree(rgn23_data);
  14443. return;
  14444. }
  14445. /**
  14446. * lpfc_wr_object - write an object to the firmware
  14447. * @phba: HBA structure that indicates port to create a queue on.
  14448. * @dmabuf_list: list of dmabufs to write to the port.
  14449. * @size: the total byte value of the objects to write to the port.
  14450. * @offset: the current offset to be used to start the transfer.
  14451. *
  14452. * This routine will create a wr_object mailbox command to send to the port.
  14453. * the mailbox command will be constructed using the dma buffers described in
  14454. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  14455. * BDEs that the imbedded mailbox can support. The @offset variable will be
  14456. * used to indicate the starting offset of the transfer and will also return
  14457. * the offset after the write object mailbox has completed. @size is used to
  14458. * determine the end of the object and whether the eof bit should be set.
  14459. *
  14460. * Return 0 is successful and offset will contain the the new offset to use
  14461. * for the next write.
  14462. * Return negative value for error cases.
  14463. **/
  14464. int
  14465. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  14466. uint32_t size, uint32_t *offset)
  14467. {
  14468. struct lpfc_mbx_wr_object *wr_object;
  14469. LPFC_MBOXQ_t *mbox;
  14470. int rc = 0, i = 0;
  14471. uint32_t shdr_status, shdr_add_status;
  14472. uint32_t mbox_tmo;
  14473. union lpfc_sli4_cfg_shdr *shdr;
  14474. struct lpfc_dmabuf *dmabuf;
  14475. uint32_t written = 0;
  14476. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14477. if (!mbox)
  14478. return -ENOMEM;
  14479. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14480. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  14481. sizeof(struct lpfc_mbx_wr_object) -
  14482. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  14483. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  14484. wr_object->u.request.write_offset = *offset;
  14485. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  14486. wr_object->u.request.object_name[0] =
  14487. cpu_to_le32(wr_object->u.request.object_name[0]);
  14488. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  14489. list_for_each_entry(dmabuf, dmabuf_list, list) {
  14490. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  14491. break;
  14492. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  14493. wr_object->u.request.bde[i].addrHigh =
  14494. putPaddrHigh(dmabuf->phys);
  14495. if (written + SLI4_PAGE_SIZE >= size) {
  14496. wr_object->u.request.bde[i].tus.f.bdeSize =
  14497. (size - written);
  14498. written += (size - written);
  14499. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  14500. } else {
  14501. wr_object->u.request.bde[i].tus.f.bdeSize =
  14502. SLI4_PAGE_SIZE;
  14503. written += SLI4_PAGE_SIZE;
  14504. }
  14505. i++;
  14506. }
  14507. wr_object->u.request.bde_count = i;
  14508. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  14509. if (!phba->sli4_hba.intr_enable)
  14510. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14511. else {
  14512. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  14513. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  14514. }
  14515. /* The IOCTL status is embedded in the mailbox subheader. */
  14516. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  14517. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14518. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14519. if (rc != MBX_TIMEOUT)
  14520. mempool_free(mbox, phba->mbox_mem_pool);
  14521. if (shdr_status || shdr_add_status || rc) {
  14522. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14523. "3025 Write Object mailbox failed with "
  14524. "status x%x add_status x%x, mbx status x%x\n",
  14525. shdr_status, shdr_add_status, rc);
  14526. rc = -ENXIO;
  14527. } else
  14528. *offset += wr_object->u.response.actual_write_length;
  14529. return rc;
  14530. }
  14531. /**
  14532. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  14533. * @vport: pointer to vport data structure.
  14534. *
  14535. * This function iterate through the mailboxq and clean up all REG_LOGIN
  14536. * and REG_VPI mailbox commands associated with the vport. This function
  14537. * is called when driver want to restart discovery of the vport due to
  14538. * a Clear Virtual Link event.
  14539. **/
  14540. void
  14541. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  14542. {
  14543. struct lpfc_hba *phba = vport->phba;
  14544. LPFC_MBOXQ_t *mb, *nextmb;
  14545. struct lpfc_dmabuf *mp;
  14546. struct lpfc_nodelist *ndlp;
  14547. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  14548. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  14549. LIST_HEAD(mbox_cmd_list);
  14550. uint8_t restart_loop;
  14551. /* Clean up internally queued mailbox commands with the vport */
  14552. spin_lock_irq(&phba->hbalock);
  14553. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  14554. if (mb->vport != vport)
  14555. continue;
  14556. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14557. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14558. continue;
  14559. list_del(&mb->list);
  14560. list_add_tail(&mb->list, &mbox_cmd_list);
  14561. }
  14562. /* Clean up active mailbox command with the vport */
  14563. mb = phba->sli.mbox_active;
  14564. if (mb && (mb->vport == vport)) {
  14565. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  14566. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  14567. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14568. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14569. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  14570. /* Put reference count for delayed processing */
  14571. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  14572. /* Unregister the RPI when mailbox complete */
  14573. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14574. }
  14575. }
  14576. /* Cleanup any mailbox completions which are not yet processed */
  14577. do {
  14578. restart_loop = 0;
  14579. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  14580. /*
  14581. * If this mailox is already processed or it is
  14582. * for another vport ignore it.
  14583. */
  14584. if ((mb->vport != vport) ||
  14585. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  14586. continue;
  14587. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14588. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14589. continue;
  14590. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14591. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14592. ndlp = (struct lpfc_nodelist *)mb->context2;
  14593. /* Unregister the RPI when mailbox complete */
  14594. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14595. restart_loop = 1;
  14596. spin_unlock_irq(&phba->hbalock);
  14597. spin_lock(shost->host_lock);
  14598. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14599. spin_unlock(shost->host_lock);
  14600. spin_lock_irq(&phba->hbalock);
  14601. break;
  14602. }
  14603. }
  14604. } while (restart_loop);
  14605. spin_unlock_irq(&phba->hbalock);
  14606. /* Release the cleaned-up mailbox commands */
  14607. while (!list_empty(&mbox_cmd_list)) {
  14608. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  14609. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14610. mp = (struct lpfc_dmabuf *) (mb->context1);
  14611. if (mp) {
  14612. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14613. kfree(mp);
  14614. }
  14615. ndlp = (struct lpfc_nodelist *) mb->context2;
  14616. mb->context2 = NULL;
  14617. if (ndlp) {
  14618. spin_lock(shost->host_lock);
  14619. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14620. spin_unlock(shost->host_lock);
  14621. lpfc_nlp_put(ndlp);
  14622. }
  14623. }
  14624. mempool_free(mb, phba->mbox_mem_pool);
  14625. }
  14626. /* Release the ndlp with the cleaned-up active mailbox command */
  14627. if (act_mbx_ndlp) {
  14628. spin_lock(shost->host_lock);
  14629. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14630. spin_unlock(shost->host_lock);
  14631. lpfc_nlp_put(act_mbx_ndlp);
  14632. }
  14633. }
  14634. /**
  14635. * lpfc_drain_txq - Drain the txq
  14636. * @phba: Pointer to HBA context object.
  14637. *
  14638. * This function attempt to submit IOCBs on the txq
  14639. * to the adapter. For SLI4 adapters, the txq contains
  14640. * ELS IOCBs that have been deferred because the there
  14641. * are no SGLs. This congestion can occur with large
  14642. * vport counts during node discovery.
  14643. **/
  14644. uint32_t
  14645. lpfc_drain_txq(struct lpfc_hba *phba)
  14646. {
  14647. LIST_HEAD(completions);
  14648. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  14649. struct lpfc_iocbq *piocbq = 0;
  14650. unsigned long iflags = 0;
  14651. char *fail_msg = NULL;
  14652. struct lpfc_sglq *sglq;
  14653. union lpfc_wqe wqe;
  14654. spin_lock_irqsave(&phba->hbalock, iflags);
  14655. if (pring->txq_cnt > pring->txq_max)
  14656. pring->txq_max = pring->txq_cnt;
  14657. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14658. while (pring->txq_cnt) {
  14659. spin_lock_irqsave(&phba->hbalock, iflags);
  14660. piocbq = lpfc_sli_ringtx_get(phba, pring);
  14661. if (!piocbq) {
  14662. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14663. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14664. "2823 txq empty and txq_cnt is %d\n ",
  14665. pring->txq_cnt);
  14666. break;
  14667. }
  14668. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  14669. if (!sglq) {
  14670. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  14671. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14672. break;
  14673. }
  14674. /* The xri and iocb resources secured,
  14675. * attempt to issue request
  14676. */
  14677. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  14678. piocbq->sli4_xritag = sglq->sli4_xritag;
  14679. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  14680. fail_msg = "to convert bpl to sgl";
  14681. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  14682. fail_msg = "to convert iocb to wqe";
  14683. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  14684. fail_msg = " - Wq is full";
  14685. else
  14686. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  14687. if (fail_msg) {
  14688. /* Failed means we can't issue and need to cancel */
  14689. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14690. "2822 IOCB failed %s iotag 0x%x "
  14691. "xri 0x%x\n",
  14692. fail_msg,
  14693. piocbq->iotag, piocbq->sli4_xritag);
  14694. list_add_tail(&piocbq->list, &completions);
  14695. }
  14696. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14697. }
  14698. /* Cancel all the IOCBs that cannot be issued */
  14699. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  14700. IOERR_SLI_ABORTED);
  14701. return pring->txq_cnt;
  14702. }