lpfc_sli.c 416 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 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 IOCB_t *
  63. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  64. {
  65. return &iocbq->iocb;
  66. }
  67. /**
  68. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  69. * @q: The Work Queue to operate on.
  70. * @wqe: The work Queue Entry to put on the Work queue.
  71. *
  72. * This routine will copy the contents of @wqe to the next available entry on
  73. * the @q. This function will then ring the Work Queue Doorbell to signal the
  74. * HBA to start processing the Work Queue Entry. This function returns 0 if
  75. * successful. If no entries are available on @q then this function will return
  76. * -ENOMEM.
  77. * The caller is expected to hold the hbalock when calling this routine.
  78. **/
  79. static uint32_t
  80. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  81. {
  82. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  83. struct lpfc_register doorbell;
  84. uint32_t host_index;
  85. /* If the host has not yet processed the next entry then we are done */
  86. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  87. return -ENOMEM;
  88. /* set consumption flag every once in a while */
  89. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  90. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  91. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  92. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  93. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  94. /* Update the host index before invoking device */
  95. host_index = q->host_index;
  96. q->host_index = ((q->host_index + 1) % q->entry_count);
  97. /* Ring Doorbell */
  98. doorbell.word0 = 0;
  99. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  100. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  101. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  102. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  103. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  104. return 0;
  105. }
  106. /**
  107. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  108. * @q: The Work Queue to operate on.
  109. * @index: The index to advance the hba index to.
  110. *
  111. * This routine will update the HBA index of a queue to reflect consumption of
  112. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  113. * an entry the host calls this function to update the queue's internal
  114. * pointers. This routine returns the number of entries that were consumed by
  115. * the HBA.
  116. **/
  117. static uint32_t
  118. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  119. {
  120. uint32_t released = 0;
  121. if (q->hba_index == index)
  122. return 0;
  123. do {
  124. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  125. released++;
  126. } while (q->hba_index != index);
  127. return released;
  128. }
  129. /**
  130. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  131. * @q: The Mailbox Queue to operate on.
  132. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  133. *
  134. * This routine will copy the contents of @mqe to the next available entry on
  135. * the @q. This function will then ring the Work Queue Doorbell to signal the
  136. * HBA to start processing the Work Queue Entry. This function returns 0 if
  137. * successful. If no entries are available on @q then this function will return
  138. * -ENOMEM.
  139. * The caller is expected to hold the hbalock when calling this routine.
  140. **/
  141. static uint32_t
  142. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  143. {
  144. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  145. struct lpfc_register doorbell;
  146. uint32_t host_index;
  147. /* If the host has not yet processed the next entry then we are done */
  148. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  149. return -ENOMEM;
  150. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  151. /* Save off the mailbox pointer for completion */
  152. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  153. /* Update the host index before invoking device */
  154. host_index = q->host_index;
  155. q->host_index = ((q->host_index + 1) % q->entry_count);
  156. /* Ring Doorbell */
  157. doorbell.word0 = 0;
  158. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  159. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  160. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  161. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  162. return 0;
  163. }
  164. /**
  165. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  166. * @q: The Mailbox Queue to operate on.
  167. *
  168. * This routine will update the HBA index of a queue to reflect consumption of
  169. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  170. * an entry the host calls this function to update the queue's internal
  171. * pointers. This routine returns the number of entries that were consumed by
  172. * the HBA.
  173. **/
  174. static uint32_t
  175. lpfc_sli4_mq_release(struct lpfc_queue *q)
  176. {
  177. /* Clear the mailbox pointer for completion */
  178. q->phba->mbox = NULL;
  179. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  180. return 1;
  181. }
  182. /**
  183. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  184. * @q: The Event Queue to get the first valid EQE from
  185. *
  186. * This routine will get the first valid Event Queue Entry from @q, update
  187. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  188. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  189. * processed, but not popped back to the HBA then this routine will return NULL.
  190. **/
  191. static struct lpfc_eqe *
  192. lpfc_sli4_eq_get(struct lpfc_queue *q)
  193. {
  194. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  195. /* If the next EQE is not valid then we are done */
  196. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  197. return NULL;
  198. /* If the host has not yet processed the next entry then we are done */
  199. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  200. return NULL;
  201. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  202. return eqe;
  203. }
  204. /**
  205. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  206. * @q: The Event Queue that the host has completed processing for.
  207. * @arm: Indicates whether the host wants to arms this CQ.
  208. *
  209. * This routine will mark all Event Queue Entries on @q, from the last
  210. * known completed entry to the last entry that was processed, as completed
  211. * by clearing the valid bit for each completion queue entry. Then it will
  212. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  213. * The internal host index in the @q will be updated by this routine to indicate
  214. * that the host has finished processing the entries. The @arm parameter
  215. * indicates that the queue should be rearmed when ringing the doorbell.
  216. *
  217. * This function will return the number of EQEs that were popped.
  218. **/
  219. uint32_t
  220. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  221. {
  222. uint32_t released = 0;
  223. struct lpfc_eqe *temp_eqe;
  224. struct lpfc_register doorbell;
  225. /* while there are valid entries */
  226. while (q->hba_index != q->host_index) {
  227. temp_eqe = q->qe[q->host_index].eqe;
  228. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  229. released++;
  230. q->host_index = ((q->host_index + 1) % q->entry_count);
  231. }
  232. if (unlikely(released == 0 && !arm))
  233. return 0;
  234. /* ring doorbell for number popped */
  235. doorbell.word0 = 0;
  236. if (arm) {
  237. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  238. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  239. }
  240. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  241. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  242. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  243. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  244. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  245. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  246. readl(q->phba->sli4_hba.EQCQDBregaddr);
  247. return released;
  248. }
  249. /**
  250. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  251. * @q: The Completion Queue to get the first valid CQE from
  252. *
  253. * This routine will get the first valid Completion Queue Entry from @q, update
  254. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  255. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  256. * processed, but not popped back to the HBA then this routine will return NULL.
  257. **/
  258. static struct lpfc_cqe *
  259. lpfc_sli4_cq_get(struct lpfc_queue *q)
  260. {
  261. struct lpfc_cqe *cqe;
  262. /* If the next CQE is not valid then we are done */
  263. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  264. return NULL;
  265. /* If the host has not yet processed the next entry then we are done */
  266. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  267. return NULL;
  268. cqe = q->qe[q->hba_index].cqe;
  269. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  270. return cqe;
  271. }
  272. /**
  273. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  274. * @q: The Completion Queue that the host has completed processing for.
  275. * @arm: Indicates whether the host wants to arms this CQ.
  276. *
  277. * This routine will mark all Completion queue entries on @q, from the last
  278. * known completed entry to the last entry that was processed, as completed
  279. * by clearing the valid bit for each completion queue entry. Then it will
  280. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  281. * The internal host index in the @q will be updated by this routine to indicate
  282. * that the host has finished processing the entries. The @arm parameter
  283. * indicates that the queue should be rearmed when ringing the doorbell.
  284. *
  285. * This function will return the number of CQEs that were released.
  286. **/
  287. uint32_t
  288. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  289. {
  290. uint32_t released = 0;
  291. struct lpfc_cqe *temp_qe;
  292. struct lpfc_register doorbell;
  293. /* while there are valid entries */
  294. while (q->hba_index != q->host_index) {
  295. temp_qe = q->qe[q->host_index].cqe;
  296. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  297. released++;
  298. q->host_index = ((q->host_index + 1) % q->entry_count);
  299. }
  300. if (unlikely(released == 0 && !arm))
  301. return 0;
  302. /* ring doorbell for number popped */
  303. doorbell.word0 = 0;
  304. if (arm)
  305. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  306. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  307. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  308. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  309. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  310. return released;
  311. }
  312. /**
  313. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  314. * @q: The Header Receive Queue to operate on.
  315. * @wqe: The Receive Queue Entry to put on the Receive queue.
  316. *
  317. * This routine will copy the contents of @wqe to the next available entry on
  318. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  319. * HBA to start processing the Receive Queue Entry. This function returns the
  320. * index that the rqe was copied to if successful. If no entries are available
  321. * on @q then this function will return -ENOMEM.
  322. * The caller is expected to hold the hbalock when calling this routine.
  323. **/
  324. static int
  325. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  326. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  327. {
  328. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  329. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  330. struct lpfc_register doorbell;
  331. int put_index = hq->host_index;
  332. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  333. return -EINVAL;
  334. if (hq->host_index != dq->host_index)
  335. return -EINVAL;
  336. /* If the host has not yet processed the next entry then we are done */
  337. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  338. return -EBUSY;
  339. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  340. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  341. /* Update the host index to point to the next slot */
  342. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  343. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  344. /* Ring The Header Receive Queue Doorbell */
  345. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  346. doorbell.word0 = 0;
  347. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  348. LPFC_RQ_POST_BATCH);
  349. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  350. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  351. }
  352. return put_index;
  353. }
  354. /**
  355. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  356. * @q: The Header Receive Queue to operate on.
  357. *
  358. * This routine will update the HBA index of a queue to reflect consumption of
  359. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  360. * consumed an entry the host calls this function to update the queue's
  361. * internal pointers. This routine returns the number of entries that were
  362. * consumed by the HBA.
  363. **/
  364. static uint32_t
  365. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  366. {
  367. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  368. return 0;
  369. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  370. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  371. return 1;
  372. }
  373. /**
  374. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  375. * @phba: Pointer to HBA context object.
  376. * @pring: Pointer to driver SLI ring object.
  377. *
  378. * This function returns pointer to next command iocb entry
  379. * in the command ring. The caller must hold hbalock to prevent
  380. * other threads consume the next command iocb.
  381. * SLI-2/SLI-3 provide different sized iocbs.
  382. **/
  383. static inline IOCB_t *
  384. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  385. {
  386. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  387. pring->cmdidx * phba->iocb_cmd_size);
  388. }
  389. /**
  390. * lpfc_resp_iocb - Get next response iocb entry in the ring
  391. * @phba: Pointer to HBA context object.
  392. * @pring: Pointer to driver SLI ring object.
  393. *
  394. * This function returns pointer to next response iocb entry
  395. * in the response ring. The caller must hold hbalock to make sure
  396. * that no other thread consume the next response iocb.
  397. * SLI-2/SLI-3 provide different sized iocbs.
  398. **/
  399. static inline IOCB_t *
  400. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  401. {
  402. return (IOCB_t *) (((char *) pring->rspringaddr) +
  403. pring->rspidx * phba->iocb_rsp_size);
  404. }
  405. /**
  406. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  407. * @phba: Pointer to HBA context object.
  408. *
  409. * This function is called with hbalock held. This function
  410. * allocates a new driver iocb object from the iocb pool. If the
  411. * allocation is successful, it returns pointer to the newly
  412. * allocated iocb object else it returns NULL.
  413. **/
  414. static struct lpfc_iocbq *
  415. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  416. {
  417. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  418. struct lpfc_iocbq * iocbq = NULL;
  419. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  420. if (iocbq)
  421. phba->iocb_cnt++;
  422. if (phba->iocb_cnt > phba->iocb_max)
  423. phba->iocb_max = phba->iocb_cnt;
  424. return iocbq;
  425. }
  426. /**
  427. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  428. * @phba: Pointer to HBA context object.
  429. * @xritag: XRI value.
  430. *
  431. * This function clears the sglq pointer from the array of acive
  432. * sglq's. The xritag that is passed in is used to index into the
  433. * array. Before the xritag can be used it needs to be adjusted
  434. * by subtracting the xribase.
  435. *
  436. * Returns sglq ponter = success, NULL = Failure.
  437. **/
  438. static struct lpfc_sglq *
  439. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  440. {
  441. uint16_t adj_xri;
  442. struct lpfc_sglq *sglq;
  443. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  444. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  445. return NULL;
  446. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  447. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  448. return sglq;
  449. }
  450. /**
  451. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  452. * @phba: Pointer to HBA context object.
  453. * @xritag: XRI value.
  454. *
  455. * This function returns the sglq pointer from the array of acive
  456. * sglq's. The xritag that is passed in is used to index into the
  457. * array. Before the xritag can be used it needs to be adjusted
  458. * by subtracting the xribase.
  459. *
  460. * Returns sglq ponter = success, NULL = Failure.
  461. **/
  462. struct lpfc_sglq *
  463. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  464. {
  465. uint16_t adj_xri;
  466. struct lpfc_sglq *sglq;
  467. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  468. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  469. return NULL;
  470. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  471. return sglq;
  472. }
  473. /**
  474. * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
  475. * @phba: Pointer to HBA context object.
  476. * @ndlp: nodelist pointer for this target.
  477. * @xritag: xri used in this exchange.
  478. * @rxid: Remote Exchange ID.
  479. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  480. *
  481. * This function is called with hbalock held.
  482. * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
  483. * rrq struct and adds it to the active_rrq_list.
  484. *
  485. * returns 0 for rrq slot for this xri
  486. * < 0 Were not able to get rrq mem or invalid parameter.
  487. **/
  488. static int
  489. __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  490. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  491. {
  492. uint16_t adj_xri;
  493. struct lpfc_node_rrq *rrq;
  494. int empty;
  495. uint32_t did = 0;
  496. if (!ndlp)
  497. return -EINVAL;
  498. if (!phba->cfg_enable_rrq)
  499. return -EINVAL;
  500. if (phba->pport->load_flag & FC_UNLOADING) {
  501. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  502. goto out;
  503. }
  504. did = ndlp->nlp_DID;
  505. /*
  506. * set the active bit even if there is no mem available.
  507. */
  508. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  509. if (NLP_CHK_FREE_REQ(ndlp))
  510. goto out;
  511. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  512. goto out;
  513. if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  514. goto out;
  515. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  516. if (rrq) {
  517. rrq->send_rrq = send_rrq;
  518. rrq->xritag = xritag;
  519. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  520. rrq->ndlp = ndlp;
  521. rrq->nlp_DID = ndlp->nlp_DID;
  522. rrq->vport = ndlp->vport;
  523. rrq->rxid = rxid;
  524. empty = list_empty(&phba->active_rrq_list);
  525. rrq->send_rrq = send_rrq;
  526. list_add_tail(&rrq->list, &phba->active_rrq_list);
  527. if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
  528. phba->hba_flag |= HBA_RRQ_ACTIVE;
  529. if (empty)
  530. lpfc_worker_wake_up(phba);
  531. }
  532. return 0;
  533. }
  534. out:
  535. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  536. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  537. " DID:0x%x Send:%d\n",
  538. xritag, rxid, did, send_rrq);
  539. return -EINVAL;
  540. }
  541. /**
  542. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  543. * @phba: Pointer to HBA context object.
  544. * @xritag: xri used in this exchange.
  545. * @rrq: The RRQ to be cleared.
  546. *
  547. **/
  548. void
  549. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  550. uint16_t xritag,
  551. struct lpfc_node_rrq *rrq)
  552. {
  553. uint16_t adj_xri;
  554. struct lpfc_nodelist *ndlp = NULL;
  555. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  556. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  557. /* The target DID could have been swapped (cable swap)
  558. * we should use the ndlp from the findnode if it is
  559. * available.
  560. */
  561. if ((!ndlp) && rrq->ndlp)
  562. ndlp = rrq->ndlp;
  563. if (!ndlp)
  564. goto out;
  565. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  566. if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) {
  567. rrq->send_rrq = 0;
  568. rrq->xritag = 0;
  569. rrq->rrq_stop_time = 0;
  570. }
  571. out:
  572. mempool_free(rrq, phba->rrq_pool);
  573. }
  574. /**
  575. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  576. * @phba: Pointer to HBA context object.
  577. *
  578. * This function is called with hbalock held. This function
  579. * Checks if stop_time (ratov from setting rrq active) has
  580. * been reached, if it has and the send_rrq flag is set then
  581. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  582. * then it will just call the routine to clear the rrq and
  583. * free the rrq resource.
  584. * The timer is set to the next rrq that is going to expire before
  585. * leaving the routine.
  586. *
  587. **/
  588. void
  589. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  590. {
  591. struct lpfc_node_rrq *rrq;
  592. struct lpfc_node_rrq *nextrrq;
  593. unsigned long next_time;
  594. unsigned long iflags;
  595. LIST_HEAD(send_rrq);
  596. spin_lock_irqsave(&phba->hbalock, iflags);
  597. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  598. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  599. list_for_each_entry_safe(rrq, nextrrq,
  600. &phba->active_rrq_list, list) {
  601. if (time_after(jiffies, rrq->rrq_stop_time))
  602. list_move(&rrq->list, &send_rrq);
  603. else if (time_before(rrq->rrq_stop_time, next_time))
  604. next_time = rrq->rrq_stop_time;
  605. }
  606. spin_unlock_irqrestore(&phba->hbalock, iflags);
  607. if (!list_empty(&phba->active_rrq_list))
  608. mod_timer(&phba->rrq_tmr, next_time);
  609. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  610. list_del(&rrq->list);
  611. if (!rrq->send_rrq)
  612. /* this call will free the rrq */
  613. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  614. else if (lpfc_send_rrq(phba, rrq)) {
  615. /* if we send the rrq then the completion handler
  616. * will clear the bit in the xribitmap.
  617. */
  618. lpfc_clr_rrq_active(phba, rrq->xritag,
  619. rrq);
  620. }
  621. }
  622. }
  623. /**
  624. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  625. * @vport: Pointer to vport context object.
  626. * @xri: The xri used in the exchange.
  627. * @did: The targets DID for this exchange.
  628. *
  629. * returns NULL = rrq not found in the phba->active_rrq_list.
  630. * rrq = rrq for this xri and target.
  631. **/
  632. struct lpfc_node_rrq *
  633. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  634. {
  635. struct lpfc_hba *phba = vport->phba;
  636. struct lpfc_node_rrq *rrq;
  637. struct lpfc_node_rrq *nextrrq;
  638. unsigned long iflags;
  639. if (phba->sli_rev != LPFC_SLI_REV4)
  640. return NULL;
  641. spin_lock_irqsave(&phba->hbalock, iflags);
  642. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  643. if (rrq->vport == vport && rrq->xritag == xri &&
  644. rrq->nlp_DID == did){
  645. list_del(&rrq->list);
  646. spin_unlock_irqrestore(&phba->hbalock, iflags);
  647. return rrq;
  648. }
  649. }
  650. spin_unlock_irqrestore(&phba->hbalock, iflags);
  651. return NULL;
  652. }
  653. /**
  654. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  655. * @vport: Pointer to vport context object.
  656. * @ndlp: Pointer to the lpfc_node_list structure.
  657. * If ndlp is NULL Remove all active RRQs for this vport from the
  658. * phba->active_rrq_list and clear the rrq.
  659. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  660. **/
  661. void
  662. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  663. {
  664. struct lpfc_hba *phba = vport->phba;
  665. struct lpfc_node_rrq *rrq;
  666. struct lpfc_node_rrq *nextrrq;
  667. unsigned long iflags;
  668. LIST_HEAD(rrq_list);
  669. if (phba->sli_rev != LPFC_SLI_REV4)
  670. return;
  671. if (!ndlp) {
  672. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  673. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  674. }
  675. spin_lock_irqsave(&phba->hbalock, iflags);
  676. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  677. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  678. list_move(&rrq->list, &rrq_list);
  679. spin_unlock_irqrestore(&phba->hbalock, iflags);
  680. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  681. list_del(&rrq->list);
  682. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  683. }
  684. }
  685. /**
  686. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  687. * @phba: Pointer to HBA context object.
  688. *
  689. * Remove all rrqs from the phba->active_rrq_list and free them by
  690. * calling __lpfc_clr_active_rrq
  691. *
  692. **/
  693. void
  694. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  695. {
  696. struct lpfc_node_rrq *rrq;
  697. struct lpfc_node_rrq *nextrrq;
  698. unsigned long next_time;
  699. unsigned long iflags;
  700. LIST_HEAD(rrq_list);
  701. if (phba->sli_rev != LPFC_SLI_REV4)
  702. return;
  703. spin_lock_irqsave(&phba->hbalock, iflags);
  704. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  705. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  706. list_splice_init(&phba->active_rrq_list, &rrq_list);
  707. spin_unlock_irqrestore(&phba->hbalock, iflags);
  708. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  709. list_del(&rrq->list);
  710. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  711. }
  712. if (!list_empty(&phba->active_rrq_list))
  713. mod_timer(&phba->rrq_tmr, next_time);
  714. }
  715. /**
  716. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  717. * @phba: Pointer to HBA context object.
  718. * @ndlp: Targets nodelist pointer for this exchange.
  719. * @xritag the xri in the bitmap to test.
  720. *
  721. * This function is called with hbalock held. This function
  722. * returns 0 = rrq not active for this xri
  723. * 1 = rrq is valid for this xri.
  724. **/
  725. int
  726. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  727. uint16_t xritag)
  728. {
  729. uint16_t adj_xri;
  730. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  731. if (!ndlp)
  732. return 0;
  733. if (test_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  734. return 1;
  735. else
  736. return 0;
  737. }
  738. /**
  739. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  740. * @phba: Pointer to HBA context object.
  741. * @ndlp: nodelist pointer for this target.
  742. * @xritag: xri used in this exchange.
  743. * @rxid: Remote Exchange ID.
  744. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  745. *
  746. * This function takes the hbalock.
  747. * The active bit is always set in the active rrq xri_bitmap even
  748. * if there is no slot avaiable for the other rrq information.
  749. *
  750. * returns 0 rrq actived for this xri
  751. * < 0 No memory or invalid ndlp.
  752. **/
  753. int
  754. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  755. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  756. {
  757. int ret;
  758. unsigned long iflags;
  759. spin_lock_irqsave(&phba->hbalock, iflags);
  760. ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq);
  761. spin_unlock_irqrestore(&phba->hbalock, iflags);
  762. return ret;
  763. }
  764. /**
  765. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  766. * @phba: Pointer to HBA context object.
  767. * @piocb: Pointer to the iocbq.
  768. *
  769. * This function is called with hbalock held. This function
  770. * Gets a new driver sglq object from the sglq list. If the
  771. * list is not empty then it is successful, it returns pointer to the newly
  772. * allocated sglq object else it returns NULL.
  773. **/
  774. static struct lpfc_sglq *
  775. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  776. {
  777. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  778. struct lpfc_sglq *sglq = NULL;
  779. struct lpfc_sglq *start_sglq = NULL;
  780. uint16_t adj_xri;
  781. struct lpfc_scsi_buf *lpfc_cmd;
  782. struct lpfc_nodelist *ndlp;
  783. int found = 0;
  784. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  785. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  786. ndlp = lpfc_cmd->rdata->pnode;
  787. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  788. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  789. ndlp = piocbq->context_un.ndlp;
  790. else
  791. ndlp = piocbq->context1;
  792. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  793. start_sglq = sglq;
  794. while (!found) {
  795. if (!sglq)
  796. return NULL;
  797. adj_xri = sglq->sli4_xritag -
  798. phba->sli4_hba.max_cfg_param.xri_base;
  799. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
  800. /* This xri has an rrq outstanding for this DID.
  801. * put it back in the list and get another xri.
  802. */
  803. list_add_tail(&sglq->list, lpfc_sgl_list);
  804. sglq = NULL;
  805. list_remove_head(lpfc_sgl_list, sglq,
  806. struct lpfc_sglq, list);
  807. if (sglq == start_sglq) {
  808. sglq = NULL;
  809. break;
  810. } else
  811. continue;
  812. }
  813. sglq->ndlp = ndlp;
  814. found = 1;
  815. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  816. sglq->state = SGL_ALLOCATED;
  817. }
  818. return sglq;
  819. }
  820. /**
  821. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  822. * @phba: Pointer to HBA context object.
  823. *
  824. * This function is called with no lock held. This function
  825. * allocates a new driver iocb object from the iocb pool. If the
  826. * allocation is successful, it returns pointer to the newly
  827. * allocated iocb object else it returns NULL.
  828. **/
  829. struct lpfc_iocbq *
  830. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  831. {
  832. struct lpfc_iocbq * iocbq = NULL;
  833. unsigned long iflags;
  834. spin_lock_irqsave(&phba->hbalock, iflags);
  835. iocbq = __lpfc_sli_get_iocbq(phba);
  836. spin_unlock_irqrestore(&phba->hbalock, iflags);
  837. return iocbq;
  838. }
  839. /**
  840. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  841. * @phba: Pointer to HBA context object.
  842. * @iocbq: Pointer to driver iocb object.
  843. *
  844. * This function is called with hbalock held to release driver
  845. * iocb object to the iocb pool. The iotag in the iocb object
  846. * does not change for each use of the iocb object. This function
  847. * clears all other fields of the iocb object when it is freed.
  848. * The sqlq structure that holds the xritag and phys and virtual
  849. * mappings for the scatter gather list is retrieved from the
  850. * active array of sglq. The get of the sglq pointer also clears
  851. * the entry in the array. If the status of the IO indiactes that
  852. * this IO was aborted then the sglq entry it put on the
  853. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  854. * IO has good status or fails for any other reason then the sglq
  855. * entry is added to the free list (lpfc_sgl_list).
  856. **/
  857. static void
  858. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  859. {
  860. struct lpfc_sglq *sglq;
  861. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  862. unsigned long iflag = 0;
  863. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  864. if (iocbq->sli4_xritag == NO_XRI)
  865. sglq = NULL;
  866. else
  867. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  868. if (sglq) {
  869. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  870. (sglq->state != SGL_XRI_ABORTED)) {
  871. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  872. iflag);
  873. list_add(&sglq->list,
  874. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  875. spin_unlock_irqrestore(
  876. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  877. } else {
  878. sglq->state = SGL_FREED;
  879. sglq->ndlp = NULL;
  880. list_add_tail(&sglq->list,
  881. &phba->sli4_hba.lpfc_sgl_list);
  882. /* Check if TXQ queue needs to be serviced */
  883. if (pring->txq_cnt)
  884. lpfc_worker_wake_up(phba);
  885. }
  886. }
  887. /*
  888. * Clean all volatile data fields, preserve iotag and node struct.
  889. */
  890. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  891. iocbq->sli4_xritag = NO_XRI;
  892. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  893. }
  894. /**
  895. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  896. * @phba: Pointer to HBA context object.
  897. * @iocbq: Pointer to driver iocb object.
  898. *
  899. * This function is called with hbalock held to release driver
  900. * iocb object to the iocb pool. The iotag in the iocb object
  901. * does not change for each use of the iocb object. This function
  902. * clears all other fields of the iocb object when it is freed.
  903. **/
  904. static void
  905. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  906. {
  907. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  908. /*
  909. * Clean all volatile data fields, preserve iotag and node struct.
  910. */
  911. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  912. iocbq->sli4_xritag = NO_XRI;
  913. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  914. }
  915. /**
  916. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  917. * @phba: Pointer to HBA context object.
  918. * @iocbq: Pointer to driver iocb object.
  919. *
  920. * This function is called with hbalock held to release driver
  921. * iocb object to the iocb pool. The iotag in the iocb object
  922. * does not change for each use of the iocb object. This function
  923. * clears all other fields of the iocb object when it is freed.
  924. **/
  925. static void
  926. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  927. {
  928. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  929. phba->iocb_cnt--;
  930. }
  931. /**
  932. * lpfc_sli_release_iocbq - 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 no lock held to release the iocb to
  937. * iocb pool.
  938. **/
  939. void
  940. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  941. {
  942. unsigned long iflags;
  943. /*
  944. * Clean all volatile data fields, preserve iotag and node struct.
  945. */
  946. spin_lock_irqsave(&phba->hbalock, iflags);
  947. __lpfc_sli_release_iocbq(phba, iocbq);
  948. spin_unlock_irqrestore(&phba->hbalock, iflags);
  949. }
  950. /**
  951. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  952. * @phba: Pointer to HBA context object.
  953. * @iocblist: List of IOCBs.
  954. * @ulpstatus: ULP status in IOCB command field.
  955. * @ulpWord4: ULP word-4 in IOCB command field.
  956. *
  957. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  958. * on the list by invoking the complete callback function associated with the
  959. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  960. * fields.
  961. **/
  962. void
  963. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  964. uint32_t ulpstatus, uint32_t ulpWord4)
  965. {
  966. struct lpfc_iocbq *piocb;
  967. while (!list_empty(iocblist)) {
  968. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  969. if (!piocb->iocb_cmpl)
  970. lpfc_sli_release_iocbq(phba, piocb);
  971. else {
  972. piocb->iocb.ulpStatus = ulpstatus;
  973. piocb->iocb.un.ulpWord[4] = ulpWord4;
  974. (piocb->iocb_cmpl) (phba, piocb, piocb);
  975. }
  976. }
  977. return;
  978. }
  979. /**
  980. * lpfc_sli_iocb_cmd_type - Get the iocb type
  981. * @iocb_cmnd: iocb command code.
  982. *
  983. * This function is called by ring event handler function to get the iocb type.
  984. * This function translates the iocb command to an iocb command type used to
  985. * decide the final disposition of each completed IOCB.
  986. * The function returns
  987. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  988. * LPFC_SOL_IOCB if it is a solicited iocb completion
  989. * LPFC_ABORT_IOCB if it is an abort iocb
  990. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  991. *
  992. * The caller is not required to hold any lock.
  993. **/
  994. static lpfc_iocb_type
  995. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  996. {
  997. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  998. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  999. return 0;
  1000. switch (iocb_cmnd) {
  1001. case CMD_XMIT_SEQUENCE_CR:
  1002. case CMD_XMIT_SEQUENCE_CX:
  1003. case CMD_XMIT_BCAST_CN:
  1004. case CMD_XMIT_BCAST_CX:
  1005. case CMD_ELS_REQUEST_CR:
  1006. case CMD_ELS_REQUEST_CX:
  1007. case CMD_CREATE_XRI_CR:
  1008. case CMD_CREATE_XRI_CX:
  1009. case CMD_GET_RPI_CN:
  1010. case CMD_XMIT_ELS_RSP_CX:
  1011. case CMD_GET_RPI_CR:
  1012. case CMD_FCP_IWRITE_CR:
  1013. case CMD_FCP_IWRITE_CX:
  1014. case CMD_FCP_IREAD_CR:
  1015. case CMD_FCP_IREAD_CX:
  1016. case CMD_FCP_ICMND_CR:
  1017. case CMD_FCP_ICMND_CX:
  1018. case CMD_FCP_TSEND_CX:
  1019. case CMD_FCP_TRSP_CX:
  1020. case CMD_FCP_TRECEIVE_CX:
  1021. case CMD_FCP_AUTO_TRSP_CX:
  1022. case CMD_ADAPTER_MSG:
  1023. case CMD_ADAPTER_DUMP:
  1024. case CMD_XMIT_SEQUENCE64_CR:
  1025. case CMD_XMIT_SEQUENCE64_CX:
  1026. case CMD_XMIT_BCAST64_CN:
  1027. case CMD_XMIT_BCAST64_CX:
  1028. case CMD_ELS_REQUEST64_CR:
  1029. case CMD_ELS_REQUEST64_CX:
  1030. case CMD_FCP_IWRITE64_CR:
  1031. case CMD_FCP_IWRITE64_CX:
  1032. case CMD_FCP_IREAD64_CR:
  1033. case CMD_FCP_IREAD64_CX:
  1034. case CMD_FCP_ICMND64_CR:
  1035. case CMD_FCP_ICMND64_CX:
  1036. case CMD_FCP_TSEND64_CX:
  1037. case CMD_FCP_TRSP64_CX:
  1038. case CMD_FCP_TRECEIVE64_CX:
  1039. case CMD_GEN_REQUEST64_CR:
  1040. case CMD_GEN_REQUEST64_CX:
  1041. case CMD_XMIT_ELS_RSP64_CX:
  1042. case DSSCMD_IWRITE64_CR:
  1043. case DSSCMD_IWRITE64_CX:
  1044. case DSSCMD_IREAD64_CR:
  1045. case DSSCMD_IREAD64_CX:
  1046. type = LPFC_SOL_IOCB;
  1047. break;
  1048. case CMD_ABORT_XRI_CN:
  1049. case CMD_ABORT_XRI_CX:
  1050. case CMD_CLOSE_XRI_CN:
  1051. case CMD_CLOSE_XRI_CX:
  1052. case CMD_XRI_ABORTED_CX:
  1053. case CMD_ABORT_MXRI64_CN:
  1054. case CMD_XMIT_BLS_RSP64_CX:
  1055. type = LPFC_ABORT_IOCB;
  1056. break;
  1057. case CMD_RCV_SEQUENCE_CX:
  1058. case CMD_RCV_ELS_REQ_CX:
  1059. case CMD_RCV_SEQUENCE64_CX:
  1060. case CMD_RCV_ELS_REQ64_CX:
  1061. case CMD_ASYNC_STATUS:
  1062. case CMD_IOCB_RCV_SEQ64_CX:
  1063. case CMD_IOCB_RCV_ELS64_CX:
  1064. case CMD_IOCB_RCV_CONT64_CX:
  1065. case CMD_IOCB_RET_XRI64_CX:
  1066. type = LPFC_UNSOL_IOCB;
  1067. break;
  1068. case CMD_IOCB_XMIT_MSEQ64_CR:
  1069. case CMD_IOCB_XMIT_MSEQ64_CX:
  1070. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1071. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1072. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1073. case CMD_IOCB_ABORT_EXTENDED_CN:
  1074. case CMD_IOCB_RET_HBQE64_CN:
  1075. case CMD_IOCB_FCP_IBIDIR64_CR:
  1076. case CMD_IOCB_FCP_IBIDIR64_CX:
  1077. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1078. case CMD_IOCB_LOGENTRY_CN:
  1079. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1080. printk("%s - Unhandled SLI-3 Command x%x\n",
  1081. __func__, iocb_cmnd);
  1082. type = LPFC_UNKNOWN_IOCB;
  1083. break;
  1084. default:
  1085. type = LPFC_UNKNOWN_IOCB;
  1086. break;
  1087. }
  1088. return type;
  1089. }
  1090. /**
  1091. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1092. * @phba: Pointer to HBA context object.
  1093. *
  1094. * This function is called from SLI initialization code
  1095. * to configure every ring of the HBA's SLI interface. The
  1096. * caller is not required to hold any lock. This function issues
  1097. * a config_ring mailbox command for each ring.
  1098. * This function returns zero if successful else returns a negative
  1099. * error code.
  1100. **/
  1101. static int
  1102. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1103. {
  1104. struct lpfc_sli *psli = &phba->sli;
  1105. LPFC_MBOXQ_t *pmb;
  1106. MAILBOX_t *pmbox;
  1107. int i, rc, ret = 0;
  1108. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1109. if (!pmb)
  1110. return -ENOMEM;
  1111. pmbox = &pmb->u.mb;
  1112. phba->link_state = LPFC_INIT_MBX_CMDS;
  1113. for (i = 0; i < psli->num_rings; i++) {
  1114. lpfc_config_ring(phba, i, pmb);
  1115. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1116. if (rc != MBX_SUCCESS) {
  1117. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1118. "0446 Adapter failed to init (%d), "
  1119. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1120. "ring %d\n",
  1121. rc, pmbox->mbxCommand,
  1122. pmbox->mbxStatus, i);
  1123. phba->link_state = LPFC_HBA_ERROR;
  1124. ret = -ENXIO;
  1125. break;
  1126. }
  1127. }
  1128. mempool_free(pmb, phba->mbox_mem_pool);
  1129. return ret;
  1130. }
  1131. /**
  1132. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1133. * @phba: Pointer to HBA context object.
  1134. * @pring: Pointer to driver SLI ring object.
  1135. * @piocb: Pointer to the driver iocb object.
  1136. *
  1137. * This function is called with hbalock held. The function adds the
  1138. * new iocb to txcmplq of the given ring. This function always returns
  1139. * 0. If this function is called for ELS ring, this function checks if
  1140. * there is a vport associated with the ELS command. This function also
  1141. * starts els_tmofunc timer if this is an ELS command.
  1142. **/
  1143. static int
  1144. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1145. struct lpfc_iocbq *piocb)
  1146. {
  1147. list_add_tail(&piocb->list, &pring->txcmplq);
  1148. piocb->iocb_flag |= LPFC_IO_ON_Q;
  1149. pring->txcmplq_cnt++;
  1150. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1151. pring->txcmplq_max = pring->txcmplq_cnt;
  1152. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1153. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1154. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1155. if (!piocb->vport)
  1156. BUG();
  1157. else
  1158. mod_timer(&piocb->vport->els_tmofunc,
  1159. jiffies + HZ * (phba->fc_ratov << 1));
  1160. }
  1161. return 0;
  1162. }
  1163. /**
  1164. * lpfc_sli_ringtx_get - Get first element of the txq
  1165. * @phba: Pointer to HBA context object.
  1166. * @pring: Pointer to driver SLI ring object.
  1167. *
  1168. * This function is called with hbalock held to get next
  1169. * iocb in txq of the given ring. If there is any iocb in
  1170. * the txq, the function returns first iocb in the list after
  1171. * removing the iocb from the list, else it returns NULL.
  1172. **/
  1173. struct lpfc_iocbq *
  1174. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1175. {
  1176. struct lpfc_iocbq *cmd_iocb;
  1177. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1178. if (cmd_iocb != NULL)
  1179. pring->txq_cnt--;
  1180. return cmd_iocb;
  1181. }
  1182. /**
  1183. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1184. * @phba: Pointer to HBA context object.
  1185. * @pring: Pointer to driver SLI ring object.
  1186. *
  1187. * This function is called with hbalock held and the caller must post the
  1188. * iocb without releasing the lock. If the caller releases the lock,
  1189. * iocb slot returned by the function is not guaranteed to be available.
  1190. * The function returns pointer to the next available iocb slot if there
  1191. * is available slot in the ring, else it returns NULL.
  1192. * If the get index of the ring is ahead of the put index, the function
  1193. * will post an error attention event to the worker thread to take the
  1194. * HBA to offline state.
  1195. **/
  1196. static IOCB_t *
  1197. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1198. {
  1199. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1200. uint32_t max_cmd_idx = pring->numCiocb;
  1201. if ((pring->next_cmdidx == pring->cmdidx) &&
  1202. (++pring->next_cmdidx >= max_cmd_idx))
  1203. pring->next_cmdidx = 0;
  1204. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1205. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1206. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1207. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1208. "0315 Ring %d issue: portCmdGet %d "
  1209. "is bigger than cmd ring %d\n",
  1210. pring->ringno,
  1211. pring->local_getidx, max_cmd_idx);
  1212. phba->link_state = LPFC_HBA_ERROR;
  1213. /*
  1214. * All error attention handlers are posted to
  1215. * worker thread
  1216. */
  1217. phba->work_ha |= HA_ERATT;
  1218. phba->work_hs = HS_FFER3;
  1219. lpfc_worker_wake_up(phba);
  1220. return NULL;
  1221. }
  1222. if (pring->local_getidx == pring->next_cmdidx)
  1223. return NULL;
  1224. }
  1225. return lpfc_cmd_iocb(phba, pring);
  1226. }
  1227. /**
  1228. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1229. * @phba: Pointer to HBA context object.
  1230. * @iocbq: Pointer to driver iocb object.
  1231. *
  1232. * This function gets an iotag for the iocb. If there is no unused iotag and
  1233. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1234. * array and assigns a new iotag.
  1235. * The function returns the allocated iotag if successful, else returns zero.
  1236. * Zero is not a valid iotag.
  1237. * The caller is not required to hold any lock.
  1238. **/
  1239. uint16_t
  1240. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1241. {
  1242. struct lpfc_iocbq **new_arr;
  1243. struct lpfc_iocbq **old_arr;
  1244. size_t new_len;
  1245. struct lpfc_sli *psli = &phba->sli;
  1246. uint16_t iotag;
  1247. spin_lock_irq(&phba->hbalock);
  1248. iotag = psli->last_iotag;
  1249. if(++iotag < psli->iocbq_lookup_len) {
  1250. psli->last_iotag = iotag;
  1251. psli->iocbq_lookup[iotag] = iocbq;
  1252. spin_unlock_irq(&phba->hbalock);
  1253. iocbq->iotag = iotag;
  1254. return iotag;
  1255. } else if (psli->iocbq_lookup_len < (0xffff
  1256. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1257. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1258. spin_unlock_irq(&phba->hbalock);
  1259. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1260. GFP_KERNEL);
  1261. if (new_arr) {
  1262. spin_lock_irq(&phba->hbalock);
  1263. old_arr = psli->iocbq_lookup;
  1264. if (new_len <= psli->iocbq_lookup_len) {
  1265. /* highly unprobable case */
  1266. kfree(new_arr);
  1267. iotag = psli->last_iotag;
  1268. if(++iotag < psli->iocbq_lookup_len) {
  1269. psli->last_iotag = iotag;
  1270. psli->iocbq_lookup[iotag] = iocbq;
  1271. spin_unlock_irq(&phba->hbalock);
  1272. iocbq->iotag = iotag;
  1273. return iotag;
  1274. }
  1275. spin_unlock_irq(&phba->hbalock);
  1276. return 0;
  1277. }
  1278. if (psli->iocbq_lookup)
  1279. memcpy(new_arr, old_arr,
  1280. ((psli->last_iotag + 1) *
  1281. sizeof (struct lpfc_iocbq *)));
  1282. psli->iocbq_lookup = new_arr;
  1283. psli->iocbq_lookup_len = new_len;
  1284. psli->last_iotag = iotag;
  1285. psli->iocbq_lookup[iotag] = iocbq;
  1286. spin_unlock_irq(&phba->hbalock);
  1287. iocbq->iotag = iotag;
  1288. kfree(old_arr);
  1289. return iotag;
  1290. }
  1291. } else
  1292. spin_unlock_irq(&phba->hbalock);
  1293. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1294. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1295. psli->last_iotag);
  1296. return 0;
  1297. }
  1298. /**
  1299. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1300. * @phba: Pointer to HBA context object.
  1301. * @pring: Pointer to driver SLI ring object.
  1302. * @iocb: Pointer to iocb slot in the ring.
  1303. * @nextiocb: Pointer to driver iocb object which need to be
  1304. * posted to firmware.
  1305. *
  1306. * This function is called with hbalock held to post a new iocb to
  1307. * the firmware. This function copies the new iocb to ring iocb slot and
  1308. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1309. * a completion call back for this iocb else the function will free the
  1310. * iocb object.
  1311. **/
  1312. static void
  1313. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1314. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1315. {
  1316. /*
  1317. * Set up an iotag
  1318. */
  1319. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1320. if (pring->ringno == LPFC_ELS_RING) {
  1321. lpfc_debugfs_slow_ring_trc(phba,
  1322. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1323. *(((uint32_t *) &nextiocb->iocb) + 4),
  1324. *(((uint32_t *) &nextiocb->iocb) + 6),
  1325. *(((uint32_t *) &nextiocb->iocb) + 7));
  1326. }
  1327. /*
  1328. * Issue iocb command to adapter
  1329. */
  1330. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1331. wmb();
  1332. pring->stats.iocb_cmd++;
  1333. /*
  1334. * If there is no completion routine to call, we can release the
  1335. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1336. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1337. */
  1338. if (nextiocb->iocb_cmpl)
  1339. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1340. else
  1341. __lpfc_sli_release_iocbq(phba, nextiocb);
  1342. /*
  1343. * Let the HBA know what IOCB slot will be the next one the
  1344. * driver will put a command into.
  1345. */
  1346. pring->cmdidx = pring->next_cmdidx;
  1347. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1348. }
  1349. /**
  1350. * lpfc_sli_update_full_ring - Update the chip attention register
  1351. * @phba: Pointer to HBA context object.
  1352. * @pring: Pointer to driver SLI ring object.
  1353. *
  1354. * The caller is not required to hold any lock for calling this function.
  1355. * This function updates the chip attention bits for the ring to inform firmware
  1356. * that there are pending work to be done for this ring and requests an
  1357. * interrupt when there is space available in the ring. This function is
  1358. * called when the driver is unable to post more iocbs to the ring due
  1359. * to unavailability of space in the ring.
  1360. **/
  1361. static void
  1362. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1363. {
  1364. int ringno = pring->ringno;
  1365. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1366. wmb();
  1367. /*
  1368. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1369. * The HBA will tell us when an IOCB entry is available.
  1370. */
  1371. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1372. readl(phba->CAregaddr); /* flush */
  1373. pring->stats.iocb_cmd_full++;
  1374. }
  1375. /**
  1376. * lpfc_sli_update_ring - Update chip attention register
  1377. * @phba: Pointer to HBA context object.
  1378. * @pring: Pointer to driver SLI ring object.
  1379. *
  1380. * This function updates the chip attention register bit for the
  1381. * given ring to inform HBA that there is more work to be done
  1382. * in this ring. The caller is not required to hold any lock.
  1383. **/
  1384. static void
  1385. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1386. {
  1387. int ringno = pring->ringno;
  1388. /*
  1389. * Tell the HBA that there is work to do in this ring.
  1390. */
  1391. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1392. wmb();
  1393. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1394. readl(phba->CAregaddr); /* flush */
  1395. }
  1396. }
  1397. /**
  1398. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1399. * @phba: Pointer to HBA context object.
  1400. * @pring: Pointer to driver SLI ring object.
  1401. *
  1402. * This function is called with hbalock held to post pending iocbs
  1403. * in the txq to the firmware. This function is called when driver
  1404. * detects space available in the ring.
  1405. **/
  1406. static void
  1407. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1408. {
  1409. IOCB_t *iocb;
  1410. struct lpfc_iocbq *nextiocb;
  1411. /*
  1412. * Check to see if:
  1413. * (a) there is anything on the txq to send
  1414. * (b) link is up
  1415. * (c) link attention events can be processed (fcp ring only)
  1416. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1417. */
  1418. if (pring->txq_cnt &&
  1419. lpfc_is_link_up(phba) &&
  1420. (pring->ringno != phba->sli.fcp_ring ||
  1421. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1422. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1423. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1424. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1425. if (iocb)
  1426. lpfc_sli_update_ring(phba, pring);
  1427. else
  1428. lpfc_sli_update_full_ring(phba, pring);
  1429. }
  1430. return;
  1431. }
  1432. /**
  1433. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1434. * @phba: Pointer to HBA context object.
  1435. * @hbqno: HBQ number.
  1436. *
  1437. * This function is called with hbalock held to get the next
  1438. * available slot for the given HBQ. If there is free slot
  1439. * available for the HBQ it will return pointer to the next available
  1440. * HBQ entry else it will return NULL.
  1441. **/
  1442. static struct lpfc_hbq_entry *
  1443. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1444. {
  1445. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1446. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1447. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1448. hbqp->next_hbqPutIdx = 0;
  1449. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1450. uint32_t raw_index = phba->hbq_get[hbqno];
  1451. uint32_t getidx = le32_to_cpu(raw_index);
  1452. hbqp->local_hbqGetIdx = getidx;
  1453. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1454. lpfc_printf_log(phba, KERN_ERR,
  1455. LOG_SLI | LOG_VPORT,
  1456. "1802 HBQ %d: local_hbqGetIdx "
  1457. "%u is > than hbqp->entry_count %u\n",
  1458. hbqno, hbqp->local_hbqGetIdx,
  1459. hbqp->entry_count);
  1460. phba->link_state = LPFC_HBA_ERROR;
  1461. return NULL;
  1462. }
  1463. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1464. return NULL;
  1465. }
  1466. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1467. hbqp->hbqPutIdx;
  1468. }
  1469. /**
  1470. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1471. * @phba: Pointer to HBA context object.
  1472. *
  1473. * This function is called with no lock held to free all the
  1474. * hbq buffers while uninitializing the SLI interface. It also
  1475. * frees the HBQ buffers returned by the firmware but not yet
  1476. * processed by the upper layers.
  1477. **/
  1478. void
  1479. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1480. {
  1481. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1482. struct hbq_dmabuf *hbq_buf;
  1483. unsigned long flags;
  1484. int i, hbq_count;
  1485. uint32_t hbqno;
  1486. hbq_count = lpfc_sli_hbq_count();
  1487. /* Return all memory used by all HBQs */
  1488. spin_lock_irqsave(&phba->hbalock, flags);
  1489. for (i = 0; i < hbq_count; ++i) {
  1490. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1491. &phba->hbqs[i].hbq_buffer_list, list) {
  1492. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1493. list_del(&hbq_buf->dbuf.list);
  1494. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1495. }
  1496. phba->hbqs[i].buffer_count = 0;
  1497. }
  1498. /* Return all HBQ buffer that are in-fly */
  1499. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1500. list) {
  1501. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1502. list_del(&hbq_buf->dbuf.list);
  1503. if (hbq_buf->tag == -1) {
  1504. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1505. (phba, hbq_buf);
  1506. } else {
  1507. hbqno = hbq_buf->tag >> 16;
  1508. if (hbqno >= LPFC_MAX_HBQS)
  1509. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1510. (phba, hbq_buf);
  1511. else
  1512. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1513. hbq_buf);
  1514. }
  1515. }
  1516. /* Mark the HBQs not in use */
  1517. phba->hbq_in_use = 0;
  1518. spin_unlock_irqrestore(&phba->hbalock, flags);
  1519. }
  1520. /**
  1521. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1522. * @phba: Pointer to HBA context object.
  1523. * @hbqno: HBQ number.
  1524. * @hbq_buf: Pointer to HBQ buffer.
  1525. *
  1526. * This function is called with the hbalock held to post a
  1527. * hbq buffer to the firmware. If the function finds an empty
  1528. * slot in the HBQ, it will post the buffer. The function will return
  1529. * pointer to the hbq entry if it successfully post the buffer
  1530. * else it will return NULL.
  1531. **/
  1532. static int
  1533. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1534. struct hbq_dmabuf *hbq_buf)
  1535. {
  1536. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1537. }
  1538. /**
  1539. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1540. * @phba: Pointer to HBA context object.
  1541. * @hbqno: HBQ number.
  1542. * @hbq_buf: Pointer to HBQ buffer.
  1543. *
  1544. * This function is called with the hbalock held to post a hbq buffer to the
  1545. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1546. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1547. * it successfully post the buffer else it will return an error.
  1548. **/
  1549. static int
  1550. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1551. struct hbq_dmabuf *hbq_buf)
  1552. {
  1553. struct lpfc_hbq_entry *hbqe;
  1554. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1555. /* Get next HBQ entry slot to use */
  1556. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1557. if (hbqe) {
  1558. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1559. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1560. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1561. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1562. hbqe->bde.tus.f.bdeFlags = 0;
  1563. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1564. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1565. /* Sync SLIM */
  1566. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1567. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1568. /* flush */
  1569. readl(phba->hbq_put + hbqno);
  1570. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1571. return 0;
  1572. } else
  1573. return -ENOMEM;
  1574. }
  1575. /**
  1576. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1577. * @phba: Pointer to HBA context object.
  1578. * @hbqno: HBQ number.
  1579. * @hbq_buf: Pointer to HBQ buffer.
  1580. *
  1581. * This function is called with the hbalock held to post an RQE to the SLI4
  1582. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1583. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1584. **/
  1585. static int
  1586. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1587. struct hbq_dmabuf *hbq_buf)
  1588. {
  1589. int rc;
  1590. struct lpfc_rqe hrqe;
  1591. struct lpfc_rqe drqe;
  1592. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1593. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1594. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1595. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1596. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1597. &hrqe, &drqe);
  1598. if (rc < 0)
  1599. return rc;
  1600. hbq_buf->tag = rc;
  1601. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1602. return 0;
  1603. }
  1604. /* HBQ for ELS and CT traffic. */
  1605. static struct lpfc_hbq_init lpfc_els_hbq = {
  1606. .rn = 1,
  1607. .entry_count = 256,
  1608. .mask_count = 0,
  1609. .profile = 0,
  1610. .ring_mask = (1 << LPFC_ELS_RING),
  1611. .buffer_count = 0,
  1612. .init_count = 40,
  1613. .add_count = 40,
  1614. };
  1615. /* HBQ for the extra ring if needed */
  1616. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1617. .rn = 1,
  1618. .entry_count = 200,
  1619. .mask_count = 0,
  1620. .profile = 0,
  1621. .ring_mask = (1 << LPFC_EXTRA_RING),
  1622. .buffer_count = 0,
  1623. .init_count = 0,
  1624. .add_count = 5,
  1625. };
  1626. /* Array of HBQs */
  1627. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1628. &lpfc_els_hbq,
  1629. &lpfc_extra_hbq,
  1630. };
  1631. /**
  1632. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1633. * @phba: Pointer to HBA context object.
  1634. * @hbqno: HBQ number.
  1635. * @count: Number of HBQ buffers to be posted.
  1636. *
  1637. * This function is called with no lock held to post more hbq buffers to the
  1638. * given HBQ. The function returns the number of HBQ buffers successfully
  1639. * posted.
  1640. **/
  1641. static int
  1642. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1643. {
  1644. uint32_t i, posted = 0;
  1645. unsigned long flags;
  1646. struct hbq_dmabuf *hbq_buffer;
  1647. LIST_HEAD(hbq_buf_list);
  1648. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1649. return 0;
  1650. if ((phba->hbqs[hbqno].buffer_count + count) >
  1651. lpfc_hbq_defs[hbqno]->entry_count)
  1652. count = lpfc_hbq_defs[hbqno]->entry_count -
  1653. phba->hbqs[hbqno].buffer_count;
  1654. if (!count)
  1655. return 0;
  1656. /* Allocate HBQ entries */
  1657. for (i = 0; i < count; i++) {
  1658. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1659. if (!hbq_buffer)
  1660. break;
  1661. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1662. }
  1663. /* Check whether HBQ is still in use */
  1664. spin_lock_irqsave(&phba->hbalock, flags);
  1665. if (!phba->hbq_in_use)
  1666. goto err;
  1667. while (!list_empty(&hbq_buf_list)) {
  1668. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1669. dbuf.list);
  1670. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1671. (hbqno << 16));
  1672. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1673. phba->hbqs[hbqno].buffer_count++;
  1674. posted++;
  1675. } else
  1676. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1677. }
  1678. spin_unlock_irqrestore(&phba->hbalock, flags);
  1679. return posted;
  1680. err:
  1681. spin_unlock_irqrestore(&phba->hbalock, flags);
  1682. while (!list_empty(&hbq_buf_list)) {
  1683. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1684. dbuf.list);
  1685. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1686. }
  1687. return 0;
  1688. }
  1689. /**
  1690. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1691. * @phba: Pointer to HBA context object.
  1692. * @qno: HBQ number.
  1693. *
  1694. * This function posts more buffers to the HBQ. This function
  1695. * is called with no lock held. The function returns the number of HBQ entries
  1696. * successfully allocated.
  1697. **/
  1698. int
  1699. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1700. {
  1701. if (phba->sli_rev == LPFC_SLI_REV4)
  1702. return 0;
  1703. else
  1704. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1705. lpfc_hbq_defs[qno]->add_count);
  1706. }
  1707. /**
  1708. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1709. * @phba: Pointer to HBA context object.
  1710. * @qno: HBQ queue number.
  1711. *
  1712. * This function is called from SLI initialization code path with
  1713. * no lock held to post initial HBQ buffers to firmware. The
  1714. * function returns the number of HBQ entries successfully allocated.
  1715. **/
  1716. static int
  1717. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1718. {
  1719. if (phba->sli_rev == LPFC_SLI_REV4)
  1720. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1721. lpfc_hbq_defs[qno]->entry_count);
  1722. else
  1723. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1724. lpfc_hbq_defs[qno]->init_count);
  1725. }
  1726. /**
  1727. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1728. * @phba: Pointer to HBA context object.
  1729. * @hbqno: HBQ number.
  1730. *
  1731. * This function removes the first hbq buffer on an hbq list and returns a
  1732. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1733. **/
  1734. static struct hbq_dmabuf *
  1735. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1736. {
  1737. struct lpfc_dmabuf *d_buf;
  1738. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1739. if (!d_buf)
  1740. return NULL;
  1741. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1742. }
  1743. /**
  1744. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1745. * @phba: Pointer to HBA context object.
  1746. * @tag: Tag of the hbq buffer.
  1747. *
  1748. * This function is called with hbalock held. This function searches
  1749. * for the hbq buffer associated with the given tag in the hbq buffer
  1750. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1751. * it returns NULL.
  1752. **/
  1753. static struct hbq_dmabuf *
  1754. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1755. {
  1756. struct lpfc_dmabuf *d_buf;
  1757. struct hbq_dmabuf *hbq_buf;
  1758. uint32_t hbqno;
  1759. hbqno = tag >> 16;
  1760. if (hbqno >= LPFC_MAX_HBQS)
  1761. return NULL;
  1762. spin_lock_irq(&phba->hbalock);
  1763. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1764. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1765. if (hbq_buf->tag == tag) {
  1766. spin_unlock_irq(&phba->hbalock);
  1767. return hbq_buf;
  1768. }
  1769. }
  1770. spin_unlock_irq(&phba->hbalock);
  1771. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1772. "1803 Bad hbq tag. Data: x%x x%x\n",
  1773. tag, phba->hbqs[tag >> 16].buffer_count);
  1774. return NULL;
  1775. }
  1776. /**
  1777. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1778. * @phba: Pointer to HBA context object.
  1779. * @hbq_buffer: Pointer to HBQ buffer.
  1780. *
  1781. * This function is called with hbalock. This function gives back
  1782. * the hbq buffer to firmware. If the HBQ does not have space to
  1783. * post the buffer, it will free the buffer.
  1784. **/
  1785. void
  1786. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1787. {
  1788. uint32_t hbqno;
  1789. if (hbq_buffer) {
  1790. hbqno = hbq_buffer->tag >> 16;
  1791. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1792. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1793. }
  1794. }
  1795. /**
  1796. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1797. * @mbxCommand: mailbox command code.
  1798. *
  1799. * This function is called by the mailbox event handler function to verify
  1800. * that the completed mailbox command is a legitimate mailbox command. If the
  1801. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1802. * and the mailbox event handler will take the HBA offline.
  1803. **/
  1804. static int
  1805. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1806. {
  1807. uint8_t ret;
  1808. switch (mbxCommand) {
  1809. case MBX_LOAD_SM:
  1810. case MBX_READ_NV:
  1811. case MBX_WRITE_NV:
  1812. case MBX_WRITE_VPARMS:
  1813. case MBX_RUN_BIU_DIAG:
  1814. case MBX_INIT_LINK:
  1815. case MBX_DOWN_LINK:
  1816. case MBX_CONFIG_LINK:
  1817. case MBX_CONFIG_RING:
  1818. case MBX_RESET_RING:
  1819. case MBX_READ_CONFIG:
  1820. case MBX_READ_RCONFIG:
  1821. case MBX_READ_SPARM:
  1822. case MBX_READ_STATUS:
  1823. case MBX_READ_RPI:
  1824. case MBX_READ_XRI:
  1825. case MBX_READ_REV:
  1826. case MBX_READ_LNK_STAT:
  1827. case MBX_REG_LOGIN:
  1828. case MBX_UNREG_LOGIN:
  1829. case MBX_CLEAR_LA:
  1830. case MBX_DUMP_MEMORY:
  1831. case MBX_DUMP_CONTEXT:
  1832. case MBX_RUN_DIAGS:
  1833. case MBX_RESTART:
  1834. case MBX_UPDATE_CFG:
  1835. case MBX_DOWN_LOAD:
  1836. case MBX_DEL_LD_ENTRY:
  1837. case MBX_RUN_PROGRAM:
  1838. case MBX_SET_MASK:
  1839. case MBX_SET_VARIABLE:
  1840. case MBX_UNREG_D_ID:
  1841. case MBX_KILL_BOARD:
  1842. case MBX_CONFIG_FARP:
  1843. case MBX_BEACON:
  1844. case MBX_LOAD_AREA:
  1845. case MBX_RUN_BIU_DIAG64:
  1846. case MBX_CONFIG_PORT:
  1847. case MBX_READ_SPARM64:
  1848. case MBX_READ_RPI64:
  1849. case MBX_REG_LOGIN64:
  1850. case MBX_READ_TOPOLOGY:
  1851. case MBX_WRITE_WWN:
  1852. case MBX_SET_DEBUG:
  1853. case MBX_LOAD_EXP_ROM:
  1854. case MBX_ASYNCEVT_ENABLE:
  1855. case MBX_REG_VPI:
  1856. case MBX_UNREG_VPI:
  1857. case MBX_HEARTBEAT:
  1858. case MBX_PORT_CAPABILITIES:
  1859. case MBX_PORT_IOV_CONTROL:
  1860. case MBX_SLI4_CONFIG:
  1861. case MBX_SLI4_REQ_FTRS:
  1862. case MBX_REG_FCFI:
  1863. case MBX_UNREG_FCFI:
  1864. case MBX_REG_VFI:
  1865. case MBX_UNREG_VFI:
  1866. case MBX_INIT_VPI:
  1867. case MBX_INIT_VFI:
  1868. case MBX_RESUME_RPI:
  1869. case MBX_READ_EVENT_LOG_STATUS:
  1870. case MBX_READ_EVENT_LOG:
  1871. case MBX_SECURITY_MGMT:
  1872. case MBX_AUTH_PORT:
  1873. ret = mbxCommand;
  1874. break;
  1875. default:
  1876. ret = MBX_SHUTDOWN;
  1877. break;
  1878. }
  1879. return ret;
  1880. }
  1881. /**
  1882. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1883. * @phba: Pointer to HBA context object.
  1884. * @pmboxq: Pointer to mailbox command.
  1885. *
  1886. * This is completion handler function for mailbox commands issued from
  1887. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1888. * mailbox event handler function with no lock held. This function
  1889. * will wake up thread waiting on the wait queue pointed by context1
  1890. * of the mailbox.
  1891. **/
  1892. void
  1893. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1894. {
  1895. wait_queue_head_t *pdone_q;
  1896. unsigned long drvr_flag;
  1897. /*
  1898. * If pdone_q is empty, the driver thread gave up waiting and
  1899. * continued running.
  1900. */
  1901. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1902. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1903. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1904. if (pdone_q)
  1905. wake_up_interruptible(pdone_q);
  1906. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1907. return;
  1908. }
  1909. /**
  1910. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1911. * @phba: Pointer to HBA context object.
  1912. * @pmb: Pointer to mailbox object.
  1913. *
  1914. * This function is the default mailbox completion handler. It
  1915. * frees the memory resources associated with the completed mailbox
  1916. * command. If the completed command is a REG_LOGIN mailbox command,
  1917. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1918. **/
  1919. void
  1920. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1921. {
  1922. struct lpfc_vport *vport = pmb->vport;
  1923. struct lpfc_dmabuf *mp;
  1924. struct lpfc_nodelist *ndlp;
  1925. struct Scsi_Host *shost;
  1926. uint16_t rpi, vpi;
  1927. int rc;
  1928. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1929. if (mp) {
  1930. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1931. kfree(mp);
  1932. }
  1933. /*
  1934. * If a REG_LOGIN succeeded after node is destroyed or node
  1935. * is in re-discovery driver need to cleanup the RPI.
  1936. */
  1937. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1938. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1939. !pmb->u.mb.mbxStatus) {
  1940. rpi = pmb->u.mb.un.varWords[0];
  1941. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1942. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1943. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1944. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1945. if (rc != MBX_NOT_FINISHED)
  1946. return;
  1947. }
  1948. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1949. !(phba->pport->load_flag & FC_UNLOADING) &&
  1950. !pmb->u.mb.mbxStatus) {
  1951. shost = lpfc_shost_from_vport(vport);
  1952. spin_lock_irq(shost->host_lock);
  1953. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1954. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1955. spin_unlock_irq(shost->host_lock);
  1956. }
  1957. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1958. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1959. lpfc_nlp_put(ndlp);
  1960. pmb->context2 = NULL;
  1961. }
  1962. /* Check security permission status on INIT_LINK mailbox command */
  1963. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1964. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1965. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1966. "2860 SLI authentication is required "
  1967. "for INIT_LINK but has not done yet\n");
  1968. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1969. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1970. else
  1971. mempool_free(pmb, phba->mbox_mem_pool);
  1972. }
  1973. /**
  1974. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1975. * @phba: Pointer to HBA context object.
  1976. *
  1977. * This function is called with no lock held. This function processes all
  1978. * the completed mailbox commands and gives it to upper layers. The interrupt
  1979. * service routine processes mailbox completion interrupt and adds completed
  1980. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1981. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1982. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1983. * function returns the mailbox commands to the upper layer by calling the
  1984. * completion handler function of each mailbox.
  1985. **/
  1986. int
  1987. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1988. {
  1989. MAILBOX_t *pmbox;
  1990. LPFC_MBOXQ_t *pmb;
  1991. int rc;
  1992. LIST_HEAD(cmplq);
  1993. phba->sli.slistat.mbox_event++;
  1994. /* Get all completed mailboxe buffers into the cmplq */
  1995. spin_lock_irq(&phba->hbalock);
  1996. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1997. spin_unlock_irq(&phba->hbalock);
  1998. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1999. do {
  2000. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2001. if (pmb == NULL)
  2002. break;
  2003. pmbox = &pmb->u.mb;
  2004. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2005. if (pmb->vport) {
  2006. lpfc_debugfs_disc_trc(pmb->vport,
  2007. LPFC_DISC_TRC_MBOX_VPORT,
  2008. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2009. (uint32_t)pmbox->mbxCommand,
  2010. pmbox->un.varWords[0],
  2011. pmbox->un.varWords[1]);
  2012. }
  2013. else {
  2014. lpfc_debugfs_disc_trc(phba->pport,
  2015. LPFC_DISC_TRC_MBOX,
  2016. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2017. (uint32_t)pmbox->mbxCommand,
  2018. pmbox->un.varWords[0],
  2019. pmbox->un.varWords[1]);
  2020. }
  2021. }
  2022. /*
  2023. * It is a fatal error if unknown mbox command completion.
  2024. */
  2025. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2026. MBX_SHUTDOWN) {
  2027. /* Unknown mailbox command compl */
  2028. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2029. "(%d):0323 Unknown Mailbox command "
  2030. "x%x (x%x) Cmpl\n",
  2031. pmb->vport ? pmb->vport->vpi : 0,
  2032. pmbox->mbxCommand,
  2033. lpfc_sli4_mbox_opcode_get(phba, pmb));
  2034. phba->link_state = LPFC_HBA_ERROR;
  2035. phba->work_hs = HS_FFER3;
  2036. lpfc_handle_eratt(phba);
  2037. continue;
  2038. }
  2039. if (pmbox->mbxStatus) {
  2040. phba->sli.slistat.mbox_stat_err++;
  2041. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2042. /* Mbox cmd cmpl error - RETRYing */
  2043. lpfc_printf_log(phba, KERN_INFO,
  2044. LOG_MBOX | LOG_SLI,
  2045. "(%d):0305 Mbox cmd cmpl "
  2046. "error - RETRYing Data: x%x "
  2047. "(x%x) x%x x%x x%x\n",
  2048. pmb->vport ? pmb->vport->vpi :0,
  2049. pmbox->mbxCommand,
  2050. lpfc_sli4_mbox_opcode_get(phba,
  2051. pmb),
  2052. pmbox->mbxStatus,
  2053. pmbox->un.varWords[0],
  2054. pmb->vport->port_state);
  2055. pmbox->mbxStatus = 0;
  2056. pmbox->mbxOwner = OWN_HOST;
  2057. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2058. if (rc != MBX_NOT_FINISHED)
  2059. continue;
  2060. }
  2061. }
  2062. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2063. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2064. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  2065. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2066. pmb->vport ? pmb->vport->vpi : 0,
  2067. pmbox->mbxCommand,
  2068. lpfc_sli4_mbox_opcode_get(phba, pmb),
  2069. pmb->mbox_cmpl,
  2070. *((uint32_t *) pmbox),
  2071. pmbox->un.varWords[0],
  2072. pmbox->un.varWords[1],
  2073. pmbox->un.varWords[2],
  2074. pmbox->un.varWords[3],
  2075. pmbox->un.varWords[4],
  2076. pmbox->un.varWords[5],
  2077. pmbox->un.varWords[6],
  2078. pmbox->un.varWords[7]);
  2079. if (pmb->mbox_cmpl)
  2080. pmb->mbox_cmpl(phba,pmb);
  2081. } while (1);
  2082. return 0;
  2083. }
  2084. /**
  2085. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2086. * @phba: Pointer to HBA context object.
  2087. * @pring: Pointer to driver SLI ring object.
  2088. * @tag: buffer tag.
  2089. *
  2090. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2091. * is set in the tag the buffer is posted for a particular exchange,
  2092. * the function will return the buffer without replacing the buffer.
  2093. * If the buffer is for unsolicited ELS or CT traffic, this function
  2094. * returns the buffer and also posts another buffer to the firmware.
  2095. **/
  2096. static struct lpfc_dmabuf *
  2097. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2098. struct lpfc_sli_ring *pring,
  2099. uint32_t tag)
  2100. {
  2101. struct hbq_dmabuf *hbq_entry;
  2102. if (tag & QUE_BUFTAG_BIT)
  2103. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2104. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2105. if (!hbq_entry)
  2106. return NULL;
  2107. return &hbq_entry->dbuf;
  2108. }
  2109. /**
  2110. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2111. * @phba: Pointer to HBA context object.
  2112. * @pring: Pointer to driver SLI ring object.
  2113. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2114. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2115. * @fch_type: the type for the first frame of the sequence.
  2116. *
  2117. * This function is called with no lock held. This function uses the r_ctl and
  2118. * type of the received sequence to find the correct callback function to call
  2119. * to process the sequence.
  2120. **/
  2121. static int
  2122. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2123. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2124. uint32_t fch_type)
  2125. {
  2126. int i;
  2127. /* unSolicited Responses */
  2128. if (pring->prt[0].profile) {
  2129. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2130. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2131. saveq);
  2132. return 1;
  2133. }
  2134. /* We must search, based on rctl / type
  2135. for the right routine */
  2136. for (i = 0; i < pring->num_mask; i++) {
  2137. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2138. (pring->prt[i].type == fch_type)) {
  2139. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2140. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2141. (phba, pring, saveq);
  2142. return 1;
  2143. }
  2144. }
  2145. return 0;
  2146. }
  2147. /**
  2148. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2149. * @phba: Pointer to HBA context object.
  2150. * @pring: Pointer to driver SLI ring object.
  2151. * @saveq: Pointer to the unsolicited iocb.
  2152. *
  2153. * This function is called with no lock held by the ring event handler
  2154. * when there is an unsolicited iocb posted to the response ring by the
  2155. * firmware. This function gets the buffer associated with the iocbs
  2156. * and calls the event handler for the ring. This function handles both
  2157. * qring buffers and hbq buffers.
  2158. * When the function returns 1 the caller can free the iocb object otherwise
  2159. * upper layer functions will free the iocb objects.
  2160. **/
  2161. static int
  2162. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2163. struct lpfc_iocbq *saveq)
  2164. {
  2165. IOCB_t * irsp;
  2166. WORD5 * w5p;
  2167. uint32_t Rctl, Type;
  2168. uint32_t match;
  2169. struct lpfc_iocbq *iocbq;
  2170. struct lpfc_dmabuf *dmzbuf;
  2171. match = 0;
  2172. irsp = &(saveq->iocb);
  2173. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2174. if (pring->lpfc_sli_rcv_async_status)
  2175. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2176. else
  2177. lpfc_printf_log(phba,
  2178. KERN_WARNING,
  2179. LOG_SLI,
  2180. "0316 Ring %d handler: unexpected "
  2181. "ASYNC_STATUS iocb received evt_code "
  2182. "0x%x\n",
  2183. pring->ringno,
  2184. irsp->un.asyncstat.evt_code);
  2185. return 1;
  2186. }
  2187. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2188. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2189. if (irsp->ulpBdeCount > 0) {
  2190. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2191. irsp->un.ulpWord[3]);
  2192. lpfc_in_buf_free(phba, dmzbuf);
  2193. }
  2194. if (irsp->ulpBdeCount > 1) {
  2195. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2196. irsp->unsli3.sli3Words[3]);
  2197. lpfc_in_buf_free(phba, dmzbuf);
  2198. }
  2199. if (irsp->ulpBdeCount > 2) {
  2200. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2201. irsp->unsli3.sli3Words[7]);
  2202. lpfc_in_buf_free(phba, dmzbuf);
  2203. }
  2204. return 1;
  2205. }
  2206. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2207. if (irsp->ulpBdeCount != 0) {
  2208. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2209. irsp->un.ulpWord[3]);
  2210. if (!saveq->context2)
  2211. lpfc_printf_log(phba,
  2212. KERN_ERR,
  2213. LOG_SLI,
  2214. "0341 Ring %d Cannot find buffer for "
  2215. "an unsolicited iocb. tag 0x%x\n",
  2216. pring->ringno,
  2217. irsp->un.ulpWord[3]);
  2218. }
  2219. if (irsp->ulpBdeCount == 2) {
  2220. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2221. irsp->unsli3.sli3Words[7]);
  2222. if (!saveq->context3)
  2223. lpfc_printf_log(phba,
  2224. KERN_ERR,
  2225. LOG_SLI,
  2226. "0342 Ring %d Cannot find buffer for an"
  2227. " unsolicited iocb. tag 0x%x\n",
  2228. pring->ringno,
  2229. irsp->unsli3.sli3Words[7]);
  2230. }
  2231. list_for_each_entry(iocbq, &saveq->list, list) {
  2232. irsp = &(iocbq->iocb);
  2233. if (irsp->ulpBdeCount != 0) {
  2234. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2235. irsp->un.ulpWord[3]);
  2236. if (!iocbq->context2)
  2237. lpfc_printf_log(phba,
  2238. KERN_ERR,
  2239. LOG_SLI,
  2240. "0343 Ring %d Cannot find "
  2241. "buffer for an unsolicited iocb"
  2242. ". tag 0x%x\n", pring->ringno,
  2243. irsp->un.ulpWord[3]);
  2244. }
  2245. if (irsp->ulpBdeCount == 2) {
  2246. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2247. irsp->unsli3.sli3Words[7]);
  2248. if (!iocbq->context3)
  2249. lpfc_printf_log(phba,
  2250. KERN_ERR,
  2251. LOG_SLI,
  2252. "0344 Ring %d Cannot find "
  2253. "buffer for an unsolicited "
  2254. "iocb. tag 0x%x\n",
  2255. pring->ringno,
  2256. irsp->unsli3.sli3Words[7]);
  2257. }
  2258. }
  2259. }
  2260. if (irsp->ulpBdeCount != 0 &&
  2261. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2262. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2263. int found = 0;
  2264. /* search continue save q for same XRI */
  2265. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2266. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  2267. list_add_tail(&saveq->list, &iocbq->list);
  2268. found = 1;
  2269. break;
  2270. }
  2271. }
  2272. if (!found)
  2273. list_add_tail(&saveq->clist,
  2274. &pring->iocb_continue_saveq);
  2275. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2276. list_del_init(&iocbq->clist);
  2277. saveq = iocbq;
  2278. irsp = &(saveq->iocb);
  2279. } else
  2280. return 0;
  2281. }
  2282. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2283. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2284. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2285. Rctl = FC_RCTL_ELS_REQ;
  2286. Type = FC_TYPE_ELS;
  2287. } else {
  2288. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2289. Rctl = w5p->hcsw.Rctl;
  2290. Type = w5p->hcsw.Type;
  2291. /* Firmware Workaround */
  2292. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2293. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2294. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2295. Rctl = FC_RCTL_ELS_REQ;
  2296. Type = FC_TYPE_ELS;
  2297. w5p->hcsw.Rctl = Rctl;
  2298. w5p->hcsw.Type = Type;
  2299. }
  2300. }
  2301. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2302. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2303. "0313 Ring %d handler: unexpected Rctl x%x "
  2304. "Type x%x received\n",
  2305. pring->ringno, Rctl, Type);
  2306. return 1;
  2307. }
  2308. /**
  2309. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2310. * @phba: Pointer to HBA context object.
  2311. * @pring: Pointer to driver SLI ring object.
  2312. * @prspiocb: Pointer to response iocb object.
  2313. *
  2314. * This function looks up the iocb_lookup table to get the command iocb
  2315. * corresponding to the given response iocb using the iotag of the
  2316. * response iocb. This function is called with the hbalock held.
  2317. * This function returns the command iocb object if it finds the command
  2318. * iocb else returns NULL.
  2319. **/
  2320. static struct lpfc_iocbq *
  2321. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2322. struct lpfc_sli_ring *pring,
  2323. struct lpfc_iocbq *prspiocb)
  2324. {
  2325. struct lpfc_iocbq *cmd_iocb = NULL;
  2326. uint16_t iotag;
  2327. iotag = prspiocb->iocb.ulpIoTag;
  2328. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2329. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2330. list_del_init(&cmd_iocb->list);
  2331. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2332. pring->txcmplq_cnt--;
  2333. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2334. }
  2335. return cmd_iocb;
  2336. }
  2337. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2338. "0317 iotag x%x is out off "
  2339. "range: max iotag x%x wd0 x%x\n",
  2340. iotag, phba->sli.last_iotag,
  2341. *(((uint32_t *) &prspiocb->iocb) + 7));
  2342. return NULL;
  2343. }
  2344. /**
  2345. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2346. * @phba: Pointer to HBA context object.
  2347. * @pring: Pointer to driver SLI ring object.
  2348. * @iotag: IOCB tag.
  2349. *
  2350. * This function looks up the iocb_lookup table to get the command iocb
  2351. * corresponding to the given iotag. This function is called with the
  2352. * hbalock held.
  2353. * This function returns the command iocb object if it finds the command
  2354. * iocb else returns NULL.
  2355. **/
  2356. static struct lpfc_iocbq *
  2357. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2358. struct lpfc_sli_ring *pring, uint16_t iotag)
  2359. {
  2360. struct lpfc_iocbq *cmd_iocb;
  2361. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2362. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2363. list_del_init(&cmd_iocb->list);
  2364. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2365. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2366. pring->txcmplq_cnt--;
  2367. }
  2368. return cmd_iocb;
  2369. }
  2370. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2371. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2372. iotag, phba->sli.last_iotag);
  2373. return NULL;
  2374. }
  2375. /**
  2376. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2377. * @phba: Pointer to HBA context object.
  2378. * @pring: Pointer to driver SLI ring object.
  2379. * @saveq: Pointer to the response iocb to be processed.
  2380. *
  2381. * This function is called by the ring event handler for non-fcp
  2382. * rings when there is a new response iocb in the response ring.
  2383. * The caller is not required to hold any locks. This function
  2384. * gets the command iocb associated with the response iocb and
  2385. * calls the completion handler for the command iocb. If there
  2386. * is no completion handler, the function will free the resources
  2387. * associated with command iocb. If the response iocb is for
  2388. * an already aborted command iocb, the status of the completion
  2389. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2390. * This function always returns 1.
  2391. **/
  2392. static int
  2393. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2394. struct lpfc_iocbq *saveq)
  2395. {
  2396. struct lpfc_iocbq *cmdiocbp;
  2397. int rc = 1;
  2398. unsigned long iflag;
  2399. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2400. spin_lock_irqsave(&phba->hbalock, iflag);
  2401. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2402. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2403. if (cmdiocbp) {
  2404. if (cmdiocbp->iocb_cmpl) {
  2405. /*
  2406. * If an ELS command failed send an event to mgmt
  2407. * application.
  2408. */
  2409. if (saveq->iocb.ulpStatus &&
  2410. (pring->ringno == LPFC_ELS_RING) &&
  2411. (cmdiocbp->iocb.ulpCommand ==
  2412. CMD_ELS_REQUEST64_CR))
  2413. lpfc_send_els_failure_event(phba,
  2414. cmdiocbp, saveq);
  2415. /*
  2416. * Post all ELS completions to the worker thread.
  2417. * All other are passed to the completion callback.
  2418. */
  2419. if (pring->ringno == LPFC_ELS_RING) {
  2420. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2421. (cmdiocbp->iocb_flag &
  2422. LPFC_DRIVER_ABORTED)) {
  2423. spin_lock_irqsave(&phba->hbalock,
  2424. iflag);
  2425. cmdiocbp->iocb_flag &=
  2426. ~LPFC_DRIVER_ABORTED;
  2427. spin_unlock_irqrestore(&phba->hbalock,
  2428. iflag);
  2429. saveq->iocb.ulpStatus =
  2430. IOSTAT_LOCAL_REJECT;
  2431. saveq->iocb.un.ulpWord[4] =
  2432. IOERR_SLI_ABORTED;
  2433. /* Firmware could still be in progress
  2434. * of DMAing payload, so don't free data
  2435. * buffer till after a hbeat.
  2436. */
  2437. spin_lock_irqsave(&phba->hbalock,
  2438. iflag);
  2439. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2440. spin_unlock_irqrestore(&phba->hbalock,
  2441. iflag);
  2442. }
  2443. if (phba->sli_rev == LPFC_SLI_REV4) {
  2444. if (saveq->iocb_flag &
  2445. LPFC_EXCHANGE_BUSY) {
  2446. /* Set cmdiocb flag for the
  2447. * exchange busy so sgl (xri)
  2448. * will not be released until
  2449. * the abort xri is received
  2450. * from hba.
  2451. */
  2452. spin_lock_irqsave(
  2453. &phba->hbalock, iflag);
  2454. cmdiocbp->iocb_flag |=
  2455. LPFC_EXCHANGE_BUSY;
  2456. spin_unlock_irqrestore(
  2457. &phba->hbalock, iflag);
  2458. }
  2459. if (cmdiocbp->iocb_flag &
  2460. LPFC_DRIVER_ABORTED) {
  2461. /*
  2462. * Clear LPFC_DRIVER_ABORTED
  2463. * bit in case it was driver
  2464. * initiated abort.
  2465. */
  2466. spin_lock_irqsave(
  2467. &phba->hbalock, iflag);
  2468. cmdiocbp->iocb_flag &=
  2469. ~LPFC_DRIVER_ABORTED;
  2470. spin_unlock_irqrestore(
  2471. &phba->hbalock, iflag);
  2472. cmdiocbp->iocb.ulpStatus =
  2473. IOSTAT_LOCAL_REJECT;
  2474. cmdiocbp->iocb.un.ulpWord[4] =
  2475. IOERR_ABORT_REQUESTED;
  2476. /*
  2477. * For SLI4, irsiocb contains
  2478. * NO_XRI in sli_xritag, it
  2479. * shall not affect releasing
  2480. * sgl (xri) process.
  2481. */
  2482. saveq->iocb.ulpStatus =
  2483. IOSTAT_LOCAL_REJECT;
  2484. saveq->iocb.un.ulpWord[4] =
  2485. IOERR_SLI_ABORTED;
  2486. spin_lock_irqsave(
  2487. &phba->hbalock, iflag);
  2488. saveq->iocb_flag |=
  2489. LPFC_DELAY_MEM_FREE;
  2490. spin_unlock_irqrestore(
  2491. &phba->hbalock, iflag);
  2492. }
  2493. }
  2494. }
  2495. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2496. } else
  2497. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2498. } else {
  2499. /*
  2500. * Unknown initiating command based on the response iotag.
  2501. * This could be the case on the ELS ring because of
  2502. * lpfc_els_abort().
  2503. */
  2504. if (pring->ringno != LPFC_ELS_RING) {
  2505. /*
  2506. * Ring <ringno> handler: unexpected completion IoTag
  2507. * <IoTag>
  2508. */
  2509. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2510. "0322 Ring %d handler: "
  2511. "unexpected completion IoTag x%x "
  2512. "Data: x%x x%x x%x x%x\n",
  2513. pring->ringno,
  2514. saveq->iocb.ulpIoTag,
  2515. saveq->iocb.ulpStatus,
  2516. saveq->iocb.un.ulpWord[4],
  2517. saveq->iocb.ulpCommand,
  2518. saveq->iocb.ulpContext);
  2519. }
  2520. }
  2521. return rc;
  2522. }
  2523. /**
  2524. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2525. * @phba: Pointer to HBA context object.
  2526. * @pring: Pointer to driver SLI ring object.
  2527. *
  2528. * This function is called from the iocb ring event handlers when
  2529. * put pointer is ahead of the get pointer for a ring. This function signal
  2530. * an error attention condition to the worker thread and the worker
  2531. * thread will transition the HBA to offline state.
  2532. **/
  2533. static void
  2534. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2535. {
  2536. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2537. /*
  2538. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2539. * rsp ring <portRspMax>
  2540. */
  2541. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2542. "0312 Ring %d handler: portRspPut %d "
  2543. "is bigger than rsp ring %d\n",
  2544. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2545. pring->numRiocb);
  2546. phba->link_state = LPFC_HBA_ERROR;
  2547. /*
  2548. * All error attention handlers are posted to
  2549. * worker thread
  2550. */
  2551. phba->work_ha |= HA_ERATT;
  2552. phba->work_hs = HS_FFER3;
  2553. lpfc_worker_wake_up(phba);
  2554. return;
  2555. }
  2556. /**
  2557. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2558. * @ptr: Pointer to address of HBA context object.
  2559. *
  2560. * This function is invoked by the Error Attention polling timer when the
  2561. * timer times out. It will check the SLI Error Attention register for
  2562. * possible attention events. If so, it will post an Error Attention event
  2563. * and wake up worker thread to process it. Otherwise, it will set up the
  2564. * Error Attention polling timer for the next poll.
  2565. **/
  2566. void lpfc_poll_eratt(unsigned long ptr)
  2567. {
  2568. struct lpfc_hba *phba;
  2569. uint32_t eratt = 0;
  2570. phba = (struct lpfc_hba *)ptr;
  2571. /* Check chip HA register for error event */
  2572. eratt = lpfc_sli_check_eratt(phba);
  2573. if (eratt)
  2574. /* Tell the worker thread there is work to do */
  2575. lpfc_worker_wake_up(phba);
  2576. else
  2577. /* Restart the timer for next eratt poll */
  2578. mod_timer(&phba->eratt_poll, jiffies +
  2579. HZ * LPFC_ERATT_POLL_INTERVAL);
  2580. return;
  2581. }
  2582. /**
  2583. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2584. * @phba: Pointer to HBA context object.
  2585. * @pring: Pointer to driver SLI ring object.
  2586. * @mask: Host attention register mask for this ring.
  2587. *
  2588. * This function is called from the interrupt context when there is a ring
  2589. * event for the fcp ring. The caller does not hold any lock.
  2590. * The function processes each response iocb in the response ring until it
  2591. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2592. * LE bit set. The function will call the completion handler of the command iocb
  2593. * if the response iocb indicates a completion for a command iocb or it is
  2594. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2595. * function if this is an unsolicited iocb.
  2596. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2597. * to check it explicitly.
  2598. */
  2599. int
  2600. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2601. struct lpfc_sli_ring *pring, uint32_t mask)
  2602. {
  2603. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2604. IOCB_t *irsp = NULL;
  2605. IOCB_t *entry = NULL;
  2606. struct lpfc_iocbq *cmdiocbq = NULL;
  2607. struct lpfc_iocbq rspiocbq;
  2608. uint32_t status;
  2609. uint32_t portRspPut, portRspMax;
  2610. int rc = 1;
  2611. lpfc_iocb_type type;
  2612. unsigned long iflag;
  2613. uint32_t rsp_cmpl = 0;
  2614. spin_lock_irqsave(&phba->hbalock, iflag);
  2615. pring->stats.iocb_event++;
  2616. /*
  2617. * The next available response entry should never exceed the maximum
  2618. * entries. If it does, treat it as an adapter hardware error.
  2619. */
  2620. portRspMax = pring->numRiocb;
  2621. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2622. if (unlikely(portRspPut >= portRspMax)) {
  2623. lpfc_sli_rsp_pointers_error(phba, pring);
  2624. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2625. return 1;
  2626. }
  2627. if (phba->fcp_ring_in_use) {
  2628. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2629. return 1;
  2630. } else
  2631. phba->fcp_ring_in_use = 1;
  2632. rmb();
  2633. while (pring->rspidx != portRspPut) {
  2634. /*
  2635. * Fetch an entry off the ring and copy it into a local data
  2636. * structure. The copy involves a byte-swap since the
  2637. * network byte order and pci byte orders are different.
  2638. */
  2639. entry = lpfc_resp_iocb(phba, pring);
  2640. phba->last_completion_time = jiffies;
  2641. if (++pring->rspidx >= portRspMax)
  2642. pring->rspidx = 0;
  2643. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2644. (uint32_t *) &rspiocbq.iocb,
  2645. phba->iocb_rsp_size);
  2646. INIT_LIST_HEAD(&(rspiocbq.list));
  2647. irsp = &rspiocbq.iocb;
  2648. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2649. pring->stats.iocb_rsp++;
  2650. rsp_cmpl++;
  2651. if (unlikely(irsp->ulpStatus)) {
  2652. /*
  2653. * If resource errors reported from HBA, reduce
  2654. * queuedepths of the SCSI device.
  2655. */
  2656. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2657. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2658. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2659. phba->lpfc_rampdown_queue_depth(phba);
  2660. spin_lock_irqsave(&phba->hbalock, iflag);
  2661. }
  2662. /* Rsp ring <ringno> error: IOCB */
  2663. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2664. "0336 Rsp Ring %d error: IOCB Data: "
  2665. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2666. pring->ringno,
  2667. irsp->un.ulpWord[0],
  2668. irsp->un.ulpWord[1],
  2669. irsp->un.ulpWord[2],
  2670. irsp->un.ulpWord[3],
  2671. irsp->un.ulpWord[4],
  2672. irsp->un.ulpWord[5],
  2673. *(uint32_t *)&irsp->un1,
  2674. *((uint32_t *)&irsp->un1 + 1));
  2675. }
  2676. switch (type) {
  2677. case LPFC_ABORT_IOCB:
  2678. case LPFC_SOL_IOCB:
  2679. /*
  2680. * Idle exchange closed via ABTS from port. No iocb
  2681. * resources need to be recovered.
  2682. */
  2683. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2684. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2685. "0333 IOCB cmd 0x%x"
  2686. " processed. Skipping"
  2687. " completion\n",
  2688. irsp->ulpCommand);
  2689. break;
  2690. }
  2691. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2692. &rspiocbq);
  2693. if (unlikely(!cmdiocbq))
  2694. break;
  2695. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2696. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2697. if (cmdiocbq->iocb_cmpl) {
  2698. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2699. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2700. &rspiocbq);
  2701. spin_lock_irqsave(&phba->hbalock, iflag);
  2702. }
  2703. break;
  2704. case LPFC_UNSOL_IOCB:
  2705. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2706. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2707. spin_lock_irqsave(&phba->hbalock, iflag);
  2708. break;
  2709. default:
  2710. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2711. char adaptermsg[LPFC_MAX_ADPTMSG];
  2712. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2713. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2714. MAX_MSG_DATA);
  2715. dev_warn(&((phba->pcidev)->dev),
  2716. "lpfc%d: %s\n",
  2717. phba->brd_no, adaptermsg);
  2718. } else {
  2719. /* Unknown IOCB command */
  2720. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2721. "0334 Unknown IOCB command "
  2722. "Data: x%x, x%x x%x x%x x%x\n",
  2723. type, irsp->ulpCommand,
  2724. irsp->ulpStatus,
  2725. irsp->ulpIoTag,
  2726. irsp->ulpContext);
  2727. }
  2728. break;
  2729. }
  2730. /*
  2731. * The response IOCB has been processed. Update the ring
  2732. * pointer in SLIM. If the port response put pointer has not
  2733. * been updated, sync the pgp->rspPutInx and fetch the new port
  2734. * response put pointer.
  2735. */
  2736. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2737. if (pring->rspidx == portRspPut)
  2738. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2739. }
  2740. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2741. pring->stats.iocb_rsp_full++;
  2742. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2743. writel(status, phba->CAregaddr);
  2744. readl(phba->CAregaddr);
  2745. }
  2746. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2747. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2748. pring->stats.iocb_cmd_empty++;
  2749. /* Force update of the local copy of cmdGetInx */
  2750. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2751. lpfc_sli_resume_iocb(phba, pring);
  2752. if ((pring->lpfc_sli_cmd_available))
  2753. (pring->lpfc_sli_cmd_available) (phba, pring);
  2754. }
  2755. phba->fcp_ring_in_use = 0;
  2756. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2757. return rc;
  2758. }
  2759. /**
  2760. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2761. * @phba: Pointer to HBA context object.
  2762. * @pring: Pointer to driver SLI ring object.
  2763. * @rspiocbp: Pointer to driver response IOCB object.
  2764. *
  2765. * This function is called from the worker thread when there is a slow-path
  2766. * response IOCB to process. This function chains all the response iocbs until
  2767. * seeing the iocb with the LE bit set. The function will call
  2768. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2769. * completion of a command iocb. The function will call the
  2770. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2771. * The function frees the resources or calls the completion handler if this
  2772. * iocb is an abort completion. The function returns NULL when the response
  2773. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2774. * this function shall chain the iocb on to the iocb_continueq and return the
  2775. * response iocb passed in.
  2776. **/
  2777. static struct lpfc_iocbq *
  2778. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2779. struct lpfc_iocbq *rspiocbp)
  2780. {
  2781. struct lpfc_iocbq *saveq;
  2782. struct lpfc_iocbq *cmdiocbp;
  2783. struct lpfc_iocbq *next_iocb;
  2784. IOCB_t *irsp = NULL;
  2785. uint32_t free_saveq;
  2786. uint8_t iocb_cmd_type;
  2787. lpfc_iocb_type type;
  2788. unsigned long iflag;
  2789. int rc;
  2790. spin_lock_irqsave(&phba->hbalock, iflag);
  2791. /* First add the response iocb to the countinueq list */
  2792. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2793. pring->iocb_continueq_cnt++;
  2794. /* Now, determine whetehr the list is completed for processing */
  2795. irsp = &rspiocbp->iocb;
  2796. if (irsp->ulpLe) {
  2797. /*
  2798. * By default, the driver expects to free all resources
  2799. * associated with this iocb completion.
  2800. */
  2801. free_saveq = 1;
  2802. saveq = list_get_first(&pring->iocb_continueq,
  2803. struct lpfc_iocbq, list);
  2804. irsp = &(saveq->iocb);
  2805. list_del_init(&pring->iocb_continueq);
  2806. pring->iocb_continueq_cnt = 0;
  2807. pring->stats.iocb_rsp++;
  2808. /*
  2809. * If resource errors reported from HBA, reduce
  2810. * queuedepths of the SCSI device.
  2811. */
  2812. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2813. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2814. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2815. phba->lpfc_rampdown_queue_depth(phba);
  2816. spin_lock_irqsave(&phba->hbalock, iflag);
  2817. }
  2818. if (irsp->ulpStatus) {
  2819. /* Rsp ring <ringno> error: IOCB */
  2820. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2821. "0328 Rsp Ring %d error: "
  2822. "IOCB Data: "
  2823. "x%x x%x x%x x%x "
  2824. "x%x x%x x%x x%x "
  2825. "x%x x%x x%x x%x "
  2826. "x%x x%x x%x x%x\n",
  2827. pring->ringno,
  2828. irsp->un.ulpWord[0],
  2829. irsp->un.ulpWord[1],
  2830. irsp->un.ulpWord[2],
  2831. irsp->un.ulpWord[3],
  2832. irsp->un.ulpWord[4],
  2833. irsp->un.ulpWord[5],
  2834. *(((uint32_t *) irsp) + 6),
  2835. *(((uint32_t *) irsp) + 7),
  2836. *(((uint32_t *) irsp) + 8),
  2837. *(((uint32_t *) irsp) + 9),
  2838. *(((uint32_t *) irsp) + 10),
  2839. *(((uint32_t *) irsp) + 11),
  2840. *(((uint32_t *) irsp) + 12),
  2841. *(((uint32_t *) irsp) + 13),
  2842. *(((uint32_t *) irsp) + 14),
  2843. *(((uint32_t *) irsp) + 15));
  2844. }
  2845. /*
  2846. * Fetch the IOCB command type and call the correct completion
  2847. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2848. * get freed back to the lpfc_iocb_list by the discovery
  2849. * kernel thread.
  2850. */
  2851. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2852. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2853. switch (type) {
  2854. case LPFC_SOL_IOCB:
  2855. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2856. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2857. spin_lock_irqsave(&phba->hbalock, iflag);
  2858. break;
  2859. case LPFC_UNSOL_IOCB:
  2860. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2861. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2862. spin_lock_irqsave(&phba->hbalock, iflag);
  2863. if (!rc)
  2864. free_saveq = 0;
  2865. break;
  2866. case LPFC_ABORT_IOCB:
  2867. cmdiocbp = NULL;
  2868. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2869. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2870. saveq);
  2871. if (cmdiocbp) {
  2872. /* Call the specified completion routine */
  2873. if (cmdiocbp->iocb_cmpl) {
  2874. spin_unlock_irqrestore(&phba->hbalock,
  2875. iflag);
  2876. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2877. saveq);
  2878. spin_lock_irqsave(&phba->hbalock,
  2879. iflag);
  2880. } else
  2881. __lpfc_sli_release_iocbq(phba,
  2882. cmdiocbp);
  2883. }
  2884. break;
  2885. case LPFC_UNKNOWN_IOCB:
  2886. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2887. char adaptermsg[LPFC_MAX_ADPTMSG];
  2888. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2889. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2890. MAX_MSG_DATA);
  2891. dev_warn(&((phba->pcidev)->dev),
  2892. "lpfc%d: %s\n",
  2893. phba->brd_no, adaptermsg);
  2894. } else {
  2895. /* Unknown IOCB command */
  2896. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2897. "0335 Unknown IOCB "
  2898. "command Data: x%x "
  2899. "x%x x%x x%x\n",
  2900. irsp->ulpCommand,
  2901. irsp->ulpStatus,
  2902. irsp->ulpIoTag,
  2903. irsp->ulpContext);
  2904. }
  2905. break;
  2906. }
  2907. if (free_saveq) {
  2908. list_for_each_entry_safe(rspiocbp, next_iocb,
  2909. &saveq->list, list) {
  2910. list_del(&rspiocbp->list);
  2911. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2912. }
  2913. __lpfc_sli_release_iocbq(phba, saveq);
  2914. }
  2915. rspiocbp = NULL;
  2916. }
  2917. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2918. return rspiocbp;
  2919. }
  2920. /**
  2921. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2922. * @phba: Pointer to HBA context object.
  2923. * @pring: Pointer to driver SLI ring object.
  2924. * @mask: Host attention register mask for this ring.
  2925. *
  2926. * This routine wraps the actual slow_ring event process routine from the
  2927. * API jump table function pointer from the lpfc_hba struct.
  2928. **/
  2929. void
  2930. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2931. struct lpfc_sli_ring *pring, uint32_t mask)
  2932. {
  2933. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2934. }
  2935. /**
  2936. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2937. * @phba: Pointer to HBA context object.
  2938. * @pring: Pointer to driver SLI ring object.
  2939. * @mask: Host attention register mask for this ring.
  2940. *
  2941. * This function is called from the worker thread when there is a ring event
  2942. * for non-fcp rings. The caller does not hold any lock. The function will
  2943. * remove each response iocb in the response ring and calls the handle
  2944. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2945. **/
  2946. static void
  2947. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2948. struct lpfc_sli_ring *pring, uint32_t mask)
  2949. {
  2950. struct lpfc_pgp *pgp;
  2951. IOCB_t *entry;
  2952. IOCB_t *irsp = NULL;
  2953. struct lpfc_iocbq *rspiocbp = NULL;
  2954. uint32_t portRspPut, portRspMax;
  2955. unsigned long iflag;
  2956. uint32_t status;
  2957. pgp = &phba->port_gp[pring->ringno];
  2958. spin_lock_irqsave(&phba->hbalock, iflag);
  2959. pring->stats.iocb_event++;
  2960. /*
  2961. * The next available response entry should never exceed the maximum
  2962. * entries. If it does, treat it as an adapter hardware error.
  2963. */
  2964. portRspMax = pring->numRiocb;
  2965. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2966. if (portRspPut >= portRspMax) {
  2967. /*
  2968. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2969. * rsp ring <portRspMax>
  2970. */
  2971. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2972. "0303 Ring %d handler: portRspPut %d "
  2973. "is bigger than rsp ring %d\n",
  2974. pring->ringno, portRspPut, portRspMax);
  2975. phba->link_state = LPFC_HBA_ERROR;
  2976. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2977. phba->work_hs = HS_FFER3;
  2978. lpfc_handle_eratt(phba);
  2979. return;
  2980. }
  2981. rmb();
  2982. while (pring->rspidx != portRspPut) {
  2983. /*
  2984. * Build a completion list and call the appropriate handler.
  2985. * The process is to get the next available response iocb, get
  2986. * a free iocb from the list, copy the response data into the
  2987. * free iocb, insert to the continuation list, and update the
  2988. * next response index to slim. This process makes response
  2989. * iocb's in the ring available to DMA as fast as possible but
  2990. * pays a penalty for a copy operation. Since the iocb is
  2991. * only 32 bytes, this penalty is considered small relative to
  2992. * the PCI reads for register values and a slim write. When
  2993. * the ulpLe field is set, the entire Command has been
  2994. * received.
  2995. */
  2996. entry = lpfc_resp_iocb(phba, pring);
  2997. phba->last_completion_time = jiffies;
  2998. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2999. if (rspiocbp == NULL) {
  3000. printk(KERN_ERR "%s: out of buffers! Failing "
  3001. "completion.\n", __func__);
  3002. break;
  3003. }
  3004. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3005. phba->iocb_rsp_size);
  3006. irsp = &rspiocbp->iocb;
  3007. if (++pring->rspidx >= portRspMax)
  3008. pring->rspidx = 0;
  3009. if (pring->ringno == LPFC_ELS_RING) {
  3010. lpfc_debugfs_slow_ring_trc(phba,
  3011. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3012. *(((uint32_t *) irsp) + 4),
  3013. *(((uint32_t *) irsp) + 6),
  3014. *(((uint32_t *) irsp) + 7));
  3015. }
  3016. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3017. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3018. /* Handle the response IOCB */
  3019. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3020. spin_lock_irqsave(&phba->hbalock, iflag);
  3021. /*
  3022. * If the port response put pointer has not been updated, sync
  3023. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3024. * response put pointer.
  3025. */
  3026. if (pring->rspidx == portRspPut) {
  3027. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3028. }
  3029. } /* while (pring->rspidx != portRspPut) */
  3030. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3031. /* At least one response entry has been freed */
  3032. pring->stats.iocb_rsp_full++;
  3033. /* SET RxRE_RSP in Chip Att register */
  3034. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3035. writel(status, phba->CAregaddr);
  3036. readl(phba->CAregaddr); /* flush */
  3037. }
  3038. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3039. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3040. pring->stats.iocb_cmd_empty++;
  3041. /* Force update of the local copy of cmdGetInx */
  3042. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3043. lpfc_sli_resume_iocb(phba, pring);
  3044. if ((pring->lpfc_sli_cmd_available))
  3045. (pring->lpfc_sli_cmd_available) (phba, pring);
  3046. }
  3047. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3048. return;
  3049. }
  3050. /**
  3051. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3052. * @phba: Pointer to HBA context object.
  3053. * @pring: Pointer to driver SLI ring object.
  3054. * @mask: Host attention register mask for this ring.
  3055. *
  3056. * This function is called from the worker thread when there is a pending
  3057. * ELS response iocb on the driver internal slow-path response iocb worker
  3058. * queue. The caller does not hold any lock. The function will remove each
  3059. * response iocb from the response worker queue and calls the handle
  3060. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3061. **/
  3062. static void
  3063. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3064. struct lpfc_sli_ring *pring, uint32_t mask)
  3065. {
  3066. struct lpfc_iocbq *irspiocbq;
  3067. struct hbq_dmabuf *dmabuf;
  3068. struct lpfc_cq_event *cq_event;
  3069. unsigned long iflag;
  3070. spin_lock_irqsave(&phba->hbalock, iflag);
  3071. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3072. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3073. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3074. /* Get the response iocb from the head of work queue */
  3075. spin_lock_irqsave(&phba->hbalock, iflag);
  3076. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3077. cq_event, struct lpfc_cq_event, list);
  3078. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3079. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3080. case CQE_CODE_COMPL_WQE:
  3081. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3082. cq_event);
  3083. /* Translate ELS WCQE to response IOCBQ */
  3084. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3085. irspiocbq);
  3086. if (irspiocbq)
  3087. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3088. irspiocbq);
  3089. break;
  3090. case CQE_CODE_RECEIVE:
  3091. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3092. cq_event);
  3093. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3094. break;
  3095. default:
  3096. break;
  3097. }
  3098. }
  3099. }
  3100. /**
  3101. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3102. * @phba: Pointer to HBA context object.
  3103. * @pring: Pointer to driver SLI ring object.
  3104. *
  3105. * This function aborts all iocbs in the given ring and frees all the iocb
  3106. * objects in txq. This function issues an abort iocb for all the iocb commands
  3107. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3108. * the return of this function. The caller is not required to hold any locks.
  3109. **/
  3110. void
  3111. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3112. {
  3113. LIST_HEAD(completions);
  3114. struct lpfc_iocbq *iocb, *next_iocb;
  3115. if (pring->ringno == LPFC_ELS_RING) {
  3116. lpfc_fabric_abort_hba(phba);
  3117. }
  3118. /* Error everything on txq and txcmplq
  3119. * First do the txq.
  3120. */
  3121. spin_lock_irq(&phba->hbalock);
  3122. list_splice_init(&pring->txq, &completions);
  3123. pring->txq_cnt = 0;
  3124. /* Next issue ABTS for everything on the txcmplq */
  3125. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3126. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3127. spin_unlock_irq(&phba->hbalock);
  3128. /* Cancel all the IOCBs from the completions list */
  3129. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3130. IOERR_SLI_ABORTED);
  3131. }
  3132. /**
  3133. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3134. * @phba: Pointer to HBA context object.
  3135. *
  3136. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3137. * objects in txq and txcmplq. This function will not issue abort iocbs
  3138. * for all the iocb commands in txcmplq, they will just be returned with
  3139. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3140. * slot has been permanently disabled.
  3141. **/
  3142. void
  3143. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3144. {
  3145. LIST_HEAD(txq);
  3146. LIST_HEAD(txcmplq);
  3147. struct lpfc_sli *psli = &phba->sli;
  3148. struct lpfc_sli_ring *pring;
  3149. /* Currently, only one fcp ring */
  3150. pring = &psli->ring[psli->fcp_ring];
  3151. spin_lock_irq(&phba->hbalock);
  3152. /* Retrieve everything on txq */
  3153. list_splice_init(&pring->txq, &txq);
  3154. pring->txq_cnt = 0;
  3155. /* Retrieve everything on the txcmplq */
  3156. list_splice_init(&pring->txcmplq, &txcmplq);
  3157. pring->txcmplq_cnt = 0;
  3158. spin_unlock_irq(&phba->hbalock);
  3159. /* Flush the txq */
  3160. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3161. IOERR_SLI_DOWN);
  3162. /* Flush the txcmpq */
  3163. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3164. IOERR_SLI_DOWN);
  3165. }
  3166. /**
  3167. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3168. * @phba: Pointer to HBA context object.
  3169. * @mask: Bit mask to be checked.
  3170. *
  3171. * This function reads the host status register and compares
  3172. * with the provided bit mask to check if HBA completed
  3173. * the restart. This function will wait in a loop for the
  3174. * HBA to complete restart. If the HBA does not restart within
  3175. * 15 iterations, the function will reset the HBA again. The
  3176. * function returns 1 when HBA fail to restart otherwise returns
  3177. * zero.
  3178. **/
  3179. static int
  3180. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3181. {
  3182. uint32_t status;
  3183. int i = 0;
  3184. int retval = 0;
  3185. /* Read the HBA Host Status Register */
  3186. status = readl(phba->HSregaddr);
  3187. /*
  3188. * Check status register every 100ms for 5 retries, then every
  3189. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3190. * every 2.5 sec for 4.
  3191. * Break our of the loop if errors occurred during init.
  3192. */
  3193. while (((status & mask) != mask) &&
  3194. !(status & HS_FFERM) &&
  3195. i++ < 20) {
  3196. if (i <= 5)
  3197. msleep(10);
  3198. else if (i <= 10)
  3199. msleep(500);
  3200. else
  3201. msleep(2500);
  3202. if (i == 15) {
  3203. /* Do post */
  3204. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3205. lpfc_sli_brdrestart(phba);
  3206. }
  3207. /* Read the HBA Host Status Register */
  3208. status = readl(phba->HSregaddr);
  3209. }
  3210. /* Check to see if any errors occurred during init */
  3211. if ((status & HS_FFERM) || (i >= 20)) {
  3212. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3213. "2751 Adapter failed to restart, "
  3214. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3215. status,
  3216. readl(phba->MBslimaddr + 0xa8),
  3217. readl(phba->MBslimaddr + 0xac));
  3218. phba->link_state = LPFC_HBA_ERROR;
  3219. retval = 1;
  3220. }
  3221. return retval;
  3222. }
  3223. /**
  3224. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3225. * @phba: Pointer to HBA context object.
  3226. * @mask: Bit mask to be checked.
  3227. *
  3228. * This function checks the host status register to check if HBA is
  3229. * ready. This function will wait in a loop for the HBA to be ready
  3230. * If the HBA is not ready , the function will will reset the HBA PCI
  3231. * function again. The function returns 1 when HBA fail to be ready
  3232. * otherwise returns zero.
  3233. **/
  3234. static int
  3235. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3236. {
  3237. uint32_t status;
  3238. int retval = 0;
  3239. /* Read the HBA Host Status Register */
  3240. status = lpfc_sli4_post_status_check(phba);
  3241. if (status) {
  3242. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3243. lpfc_sli_brdrestart(phba);
  3244. status = lpfc_sli4_post_status_check(phba);
  3245. }
  3246. /* Check to see if any errors occurred during init */
  3247. if (status) {
  3248. phba->link_state = LPFC_HBA_ERROR;
  3249. retval = 1;
  3250. } else
  3251. phba->sli4_hba.intr_enable = 0;
  3252. return retval;
  3253. }
  3254. /**
  3255. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3256. * @phba: Pointer to HBA context object.
  3257. * @mask: Bit mask to be checked.
  3258. *
  3259. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3260. * from the API jump table function pointer from the lpfc_hba struct.
  3261. **/
  3262. int
  3263. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3264. {
  3265. return phba->lpfc_sli_brdready(phba, mask);
  3266. }
  3267. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3268. /**
  3269. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3270. * @phba: Pointer to HBA context object.
  3271. *
  3272. * This function is called before resetting an HBA. This
  3273. * function requests HBA to quiesce DMAs before a reset.
  3274. **/
  3275. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3276. {
  3277. uint32_t __iomem *resp_buf;
  3278. uint32_t __iomem *mbox_buf;
  3279. volatile uint32_t mbox;
  3280. uint32_t hc_copy;
  3281. int i;
  3282. uint8_t hdrtype;
  3283. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3284. if (hdrtype != 0x80 ||
  3285. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3286. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3287. return;
  3288. /*
  3289. * Tell the other part of the chip to suspend temporarily all
  3290. * its DMA activity.
  3291. */
  3292. resp_buf = phba->MBslimaddr;
  3293. /* Disable the error attention */
  3294. hc_copy = readl(phba->HCregaddr);
  3295. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3296. readl(phba->HCregaddr); /* flush */
  3297. phba->link_flag |= LS_IGNORE_ERATT;
  3298. if (readl(phba->HAregaddr) & HA_ERATT) {
  3299. /* Clear Chip error bit */
  3300. writel(HA_ERATT, phba->HAregaddr);
  3301. phba->pport->stopped = 1;
  3302. }
  3303. mbox = 0;
  3304. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3305. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3306. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3307. mbox_buf = phba->MBslimaddr;
  3308. writel(mbox, mbox_buf);
  3309. for (i = 0;
  3310. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  3311. mdelay(1);
  3312. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  3313. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3314. phba->pport->stopped)
  3315. goto restore_hc;
  3316. else
  3317. goto clear_errat;
  3318. }
  3319. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3320. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  3321. mdelay(1);
  3322. clear_errat:
  3323. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  3324. mdelay(1);
  3325. if (readl(phba->HAregaddr) & HA_ERATT) {
  3326. writel(HA_ERATT, phba->HAregaddr);
  3327. phba->pport->stopped = 1;
  3328. }
  3329. restore_hc:
  3330. phba->link_flag &= ~LS_IGNORE_ERATT;
  3331. writel(hc_copy, phba->HCregaddr);
  3332. readl(phba->HCregaddr); /* flush */
  3333. }
  3334. /**
  3335. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3336. * @phba: Pointer to HBA context object.
  3337. *
  3338. * This function issues a kill_board mailbox command and waits for
  3339. * the error attention interrupt. This function is called for stopping
  3340. * the firmware processing. The caller is not required to hold any
  3341. * locks. This function calls lpfc_hba_down_post function to free
  3342. * any pending commands after the kill. The function will return 1 when it
  3343. * fails to kill the board else will return 0.
  3344. **/
  3345. int
  3346. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3347. {
  3348. struct lpfc_sli *psli;
  3349. LPFC_MBOXQ_t *pmb;
  3350. uint32_t status;
  3351. uint32_t ha_copy;
  3352. int retval;
  3353. int i = 0;
  3354. psli = &phba->sli;
  3355. /* Kill HBA */
  3356. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3357. "0329 Kill HBA Data: x%x x%x\n",
  3358. phba->pport->port_state, psli->sli_flag);
  3359. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3360. if (!pmb)
  3361. return 1;
  3362. /* Disable the error attention */
  3363. spin_lock_irq(&phba->hbalock);
  3364. status = readl(phba->HCregaddr);
  3365. status &= ~HC_ERINT_ENA;
  3366. writel(status, phba->HCregaddr);
  3367. readl(phba->HCregaddr); /* flush */
  3368. phba->link_flag |= LS_IGNORE_ERATT;
  3369. spin_unlock_irq(&phba->hbalock);
  3370. lpfc_kill_board(phba, pmb);
  3371. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3372. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3373. if (retval != MBX_SUCCESS) {
  3374. if (retval != MBX_BUSY)
  3375. mempool_free(pmb, phba->mbox_mem_pool);
  3376. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3377. "2752 KILL_BOARD command failed retval %d\n",
  3378. retval);
  3379. spin_lock_irq(&phba->hbalock);
  3380. phba->link_flag &= ~LS_IGNORE_ERATT;
  3381. spin_unlock_irq(&phba->hbalock);
  3382. return 1;
  3383. }
  3384. spin_lock_irq(&phba->hbalock);
  3385. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3386. spin_unlock_irq(&phba->hbalock);
  3387. mempool_free(pmb, phba->mbox_mem_pool);
  3388. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3389. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3390. * 3 seconds we still set HBA_ERROR state because the status of the
  3391. * board is now undefined.
  3392. */
  3393. ha_copy = readl(phba->HAregaddr);
  3394. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3395. mdelay(100);
  3396. ha_copy = readl(phba->HAregaddr);
  3397. }
  3398. del_timer_sync(&psli->mbox_tmo);
  3399. if (ha_copy & HA_ERATT) {
  3400. writel(HA_ERATT, phba->HAregaddr);
  3401. phba->pport->stopped = 1;
  3402. }
  3403. spin_lock_irq(&phba->hbalock);
  3404. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3405. psli->mbox_active = NULL;
  3406. phba->link_flag &= ~LS_IGNORE_ERATT;
  3407. spin_unlock_irq(&phba->hbalock);
  3408. lpfc_hba_down_post(phba);
  3409. phba->link_state = LPFC_HBA_ERROR;
  3410. return ha_copy & HA_ERATT ? 0 : 1;
  3411. }
  3412. /**
  3413. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3414. * @phba: Pointer to HBA context object.
  3415. *
  3416. * This function resets the HBA by writing HC_INITFF to the control
  3417. * register. After the HBA resets, this function resets all the iocb ring
  3418. * indices. This function disables PCI layer parity checking during
  3419. * the reset.
  3420. * This function returns 0 always.
  3421. * The caller is not required to hold any locks.
  3422. **/
  3423. int
  3424. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3425. {
  3426. struct lpfc_sli *psli;
  3427. struct lpfc_sli_ring *pring;
  3428. uint16_t cfg_value;
  3429. int i;
  3430. psli = &phba->sli;
  3431. /* Reset HBA */
  3432. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3433. "0325 Reset HBA Data: x%x x%x\n",
  3434. phba->pport->port_state, psli->sli_flag);
  3435. /* perform board reset */
  3436. phba->fc_eventTag = 0;
  3437. phba->link_events = 0;
  3438. phba->pport->fc_myDID = 0;
  3439. phba->pport->fc_prevDID = 0;
  3440. /* Turn off parity checking and serr during the physical reset */
  3441. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3442. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3443. (cfg_value &
  3444. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3445. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3446. /* Now toggle INITFF bit in the Host Control Register */
  3447. writel(HC_INITFF, phba->HCregaddr);
  3448. mdelay(1);
  3449. readl(phba->HCregaddr); /* flush */
  3450. writel(0, phba->HCregaddr);
  3451. readl(phba->HCregaddr); /* flush */
  3452. /* Restore PCI cmd register */
  3453. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3454. /* Initialize relevant SLI info */
  3455. for (i = 0; i < psli->num_rings; i++) {
  3456. pring = &psli->ring[i];
  3457. pring->flag = 0;
  3458. pring->rspidx = 0;
  3459. pring->next_cmdidx = 0;
  3460. pring->local_getidx = 0;
  3461. pring->cmdidx = 0;
  3462. pring->missbufcnt = 0;
  3463. }
  3464. phba->link_state = LPFC_WARM_START;
  3465. return 0;
  3466. }
  3467. /**
  3468. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3469. * @phba: Pointer to HBA context object.
  3470. *
  3471. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3472. * checking during resets the device. The caller is not required to hold
  3473. * any locks.
  3474. *
  3475. * This function returns 0 always.
  3476. **/
  3477. int
  3478. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3479. {
  3480. struct lpfc_sli *psli = &phba->sli;
  3481. uint16_t cfg_value;
  3482. uint8_t qindx;
  3483. /* Reset HBA */
  3484. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3485. "0295 Reset HBA Data: x%x x%x\n",
  3486. phba->pport->port_state, psli->sli_flag);
  3487. /* perform board reset */
  3488. phba->fc_eventTag = 0;
  3489. phba->link_events = 0;
  3490. phba->pport->fc_myDID = 0;
  3491. phba->pport->fc_prevDID = 0;
  3492. spin_lock_irq(&phba->hbalock);
  3493. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3494. phba->fcf.fcf_flag = 0;
  3495. /* Clean up the child queue list for the CQs */
  3496. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3497. list_del_init(&phba->sli4_hba.els_wq->list);
  3498. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3499. list_del_init(&phba->sli4_hba.dat_rq->list);
  3500. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3501. list_del_init(&phba->sli4_hba.els_cq->list);
  3502. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3503. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3504. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3505. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3506. spin_unlock_irq(&phba->hbalock);
  3507. /* Now physically reset the device */
  3508. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3509. "0389 Performing PCI function reset!\n");
  3510. /* Turn off parity checking and serr during the physical reset */
  3511. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3512. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3513. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3514. /* Perform FCoE PCI function reset */
  3515. lpfc_pci_function_reset(phba);
  3516. /* Restore PCI cmd register */
  3517. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3518. return 0;
  3519. }
  3520. /**
  3521. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3522. * @phba: Pointer to HBA context object.
  3523. *
  3524. * This function is called in the SLI initialization code path to
  3525. * restart the HBA. The caller is not required to hold any lock.
  3526. * This function writes MBX_RESTART mailbox command to the SLIM and
  3527. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3528. * function to free any pending commands. The function enables
  3529. * POST only during the first initialization. The function returns zero.
  3530. * The function does not guarantee completion of MBX_RESTART mailbox
  3531. * command before the return of this function.
  3532. **/
  3533. static int
  3534. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3535. {
  3536. MAILBOX_t *mb;
  3537. struct lpfc_sli *psli;
  3538. volatile uint32_t word0;
  3539. void __iomem *to_slim;
  3540. uint32_t hba_aer_enabled;
  3541. spin_lock_irq(&phba->hbalock);
  3542. /* Take PCIe device Advanced Error Reporting (AER) state */
  3543. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3544. psli = &phba->sli;
  3545. /* Restart HBA */
  3546. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3547. "0337 Restart HBA Data: x%x x%x\n",
  3548. phba->pport->port_state, psli->sli_flag);
  3549. word0 = 0;
  3550. mb = (MAILBOX_t *) &word0;
  3551. mb->mbxCommand = MBX_RESTART;
  3552. mb->mbxHc = 1;
  3553. lpfc_reset_barrier(phba);
  3554. to_slim = phba->MBslimaddr;
  3555. writel(*(uint32_t *) mb, to_slim);
  3556. readl(to_slim); /* flush */
  3557. /* Only skip post after fc_ffinit is completed */
  3558. if (phba->pport->port_state)
  3559. word0 = 1; /* This is really setting up word1 */
  3560. else
  3561. word0 = 0; /* This is really setting up word1 */
  3562. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3563. writel(*(uint32_t *) mb, to_slim);
  3564. readl(to_slim); /* flush */
  3565. lpfc_sli_brdreset(phba);
  3566. phba->pport->stopped = 0;
  3567. phba->link_state = LPFC_INIT_START;
  3568. phba->hba_flag = 0;
  3569. spin_unlock_irq(&phba->hbalock);
  3570. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3571. psli->stats_start = get_seconds();
  3572. /* Give the INITFF and Post time to settle. */
  3573. mdelay(100);
  3574. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3575. if (hba_aer_enabled)
  3576. pci_disable_pcie_error_reporting(phba->pcidev);
  3577. lpfc_hba_down_post(phba);
  3578. return 0;
  3579. }
  3580. /**
  3581. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3582. * @phba: Pointer to HBA context object.
  3583. *
  3584. * This function is called in the SLI initialization code path to restart
  3585. * a SLI4 HBA. The caller is not required to hold any lock.
  3586. * At the end of the function, it calls lpfc_hba_down_post function to
  3587. * free any pending commands.
  3588. **/
  3589. static int
  3590. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3591. {
  3592. struct lpfc_sli *psli = &phba->sli;
  3593. uint32_t hba_aer_enabled;
  3594. /* Restart HBA */
  3595. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3596. "0296 Restart HBA Data: x%x x%x\n",
  3597. phba->pport->port_state, psli->sli_flag);
  3598. /* Take PCIe device Advanced Error Reporting (AER) state */
  3599. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3600. lpfc_sli4_brdreset(phba);
  3601. spin_lock_irq(&phba->hbalock);
  3602. phba->pport->stopped = 0;
  3603. phba->link_state = LPFC_INIT_START;
  3604. phba->hba_flag = 0;
  3605. spin_unlock_irq(&phba->hbalock);
  3606. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3607. psli->stats_start = get_seconds();
  3608. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3609. if (hba_aer_enabled)
  3610. pci_disable_pcie_error_reporting(phba->pcidev);
  3611. lpfc_hba_down_post(phba);
  3612. return 0;
  3613. }
  3614. /**
  3615. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3616. * @phba: Pointer to HBA context object.
  3617. *
  3618. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3619. * API jump table function pointer from the lpfc_hba struct.
  3620. **/
  3621. int
  3622. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3623. {
  3624. return phba->lpfc_sli_brdrestart(phba);
  3625. }
  3626. /**
  3627. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3628. * @phba: Pointer to HBA context object.
  3629. *
  3630. * This function is called after a HBA restart to wait for successful
  3631. * restart of the HBA. Successful restart of the HBA is indicated by
  3632. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3633. * iteration, the function will restart the HBA again. The function returns
  3634. * zero if HBA successfully restarted else returns negative error code.
  3635. **/
  3636. static int
  3637. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3638. {
  3639. uint32_t status, i = 0;
  3640. /* Read the HBA Host Status Register */
  3641. status = readl(phba->HSregaddr);
  3642. /* Check status register to see what current state is */
  3643. i = 0;
  3644. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3645. /* Check every 10ms for 10 retries, then every 100ms for 90
  3646. * retries, then every 1 sec for 50 retires for a total of
  3647. * ~60 seconds before reset the board again and check every
  3648. * 1 sec for 50 retries. The up to 60 seconds before the
  3649. * board ready is required by the Falcon FIPS zeroization
  3650. * complete, and any reset the board in between shall cause
  3651. * restart of zeroization, further delay the board ready.
  3652. */
  3653. if (i++ >= 200) {
  3654. /* Adapter failed to init, timeout, status reg
  3655. <status> */
  3656. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3657. "0436 Adapter failed to init, "
  3658. "timeout, status reg x%x, "
  3659. "FW Data: A8 x%x AC x%x\n", status,
  3660. readl(phba->MBslimaddr + 0xa8),
  3661. readl(phba->MBslimaddr + 0xac));
  3662. phba->link_state = LPFC_HBA_ERROR;
  3663. return -ETIMEDOUT;
  3664. }
  3665. /* Check to see if any errors occurred during init */
  3666. if (status & HS_FFERM) {
  3667. /* ERROR: During chipset initialization */
  3668. /* Adapter failed to init, chipset, status reg
  3669. <status> */
  3670. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3671. "0437 Adapter failed to init, "
  3672. "chipset, status reg x%x, "
  3673. "FW Data: A8 x%x AC x%x\n", status,
  3674. readl(phba->MBslimaddr + 0xa8),
  3675. readl(phba->MBslimaddr + 0xac));
  3676. phba->link_state = LPFC_HBA_ERROR;
  3677. return -EIO;
  3678. }
  3679. if (i <= 10)
  3680. msleep(10);
  3681. else if (i <= 100)
  3682. msleep(100);
  3683. else
  3684. msleep(1000);
  3685. if (i == 150) {
  3686. /* Do post */
  3687. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3688. lpfc_sli_brdrestart(phba);
  3689. }
  3690. /* Read the HBA Host Status Register */
  3691. status = readl(phba->HSregaddr);
  3692. }
  3693. /* Check to see if any errors occurred during init */
  3694. if (status & HS_FFERM) {
  3695. /* ERROR: During chipset initialization */
  3696. /* Adapter failed to init, chipset, status reg <status> */
  3697. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3698. "0438 Adapter failed to init, chipset, "
  3699. "status reg x%x, "
  3700. "FW Data: A8 x%x AC x%x\n", status,
  3701. readl(phba->MBslimaddr + 0xa8),
  3702. readl(phba->MBslimaddr + 0xac));
  3703. phba->link_state = LPFC_HBA_ERROR;
  3704. return -EIO;
  3705. }
  3706. /* Clear all interrupt enable conditions */
  3707. writel(0, phba->HCregaddr);
  3708. readl(phba->HCregaddr); /* flush */
  3709. /* setup host attn register */
  3710. writel(0xffffffff, phba->HAregaddr);
  3711. readl(phba->HAregaddr); /* flush */
  3712. return 0;
  3713. }
  3714. /**
  3715. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3716. *
  3717. * This function calculates and returns the number of HBQs required to be
  3718. * configured.
  3719. **/
  3720. int
  3721. lpfc_sli_hbq_count(void)
  3722. {
  3723. return ARRAY_SIZE(lpfc_hbq_defs);
  3724. }
  3725. /**
  3726. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3727. *
  3728. * This function adds the number of hbq entries in every HBQ to get
  3729. * the total number of hbq entries required for the HBA and returns
  3730. * the total count.
  3731. **/
  3732. static int
  3733. lpfc_sli_hbq_entry_count(void)
  3734. {
  3735. int hbq_count = lpfc_sli_hbq_count();
  3736. int count = 0;
  3737. int i;
  3738. for (i = 0; i < hbq_count; ++i)
  3739. count += lpfc_hbq_defs[i]->entry_count;
  3740. return count;
  3741. }
  3742. /**
  3743. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3744. *
  3745. * This function calculates amount of memory required for all hbq entries
  3746. * to be configured and returns the total memory required.
  3747. **/
  3748. int
  3749. lpfc_sli_hbq_size(void)
  3750. {
  3751. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3752. }
  3753. /**
  3754. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3755. * @phba: Pointer to HBA context object.
  3756. *
  3757. * This function is called during the SLI initialization to configure
  3758. * all the HBQs and post buffers to the HBQ. The caller is not
  3759. * required to hold any locks. This function will return zero if successful
  3760. * else it will return negative error code.
  3761. **/
  3762. static int
  3763. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3764. {
  3765. int hbq_count = lpfc_sli_hbq_count();
  3766. LPFC_MBOXQ_t *pmb;
  3767. MAILBOX_t *pmbox;
  3768. uint32_t hbqno;
  3769. uint32_t hbq_entry_index;
  3770. /* Get a Mailbox buffer to setup mailbox
  3771. * commands for HBA initialization
  3772. */
  3773. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3774. if (!pmb)
  3775. return -ENOMEM;
  3776. pmbox = &pmb->u.mb;
  3777. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3778. phba->link_state = LPFC_INIT_MBX_CMDS;
  3779. phba->hbq_in_use = 1;
  3780. hbq_entry_index = 0;
  3781. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3782. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3783. phba->hbqs[hbqno].hbqPutIdx = 0;
  3784. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3785. phba->hbqs[hbqno].entry_count =
  3786. lpfc_hbq_defs[hbqno]->entry_count;
  3787. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3788. hbq_entry_index, pmb);
  3789. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3790. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3791. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3792. mbxStatus <status>, ring <num> */
  3793. lpfc_printf_log(phba, KERN_ERR,
  3794. LOG_SLI | LOG_VPORT,
  3795. "1805 Adapter failed to init. "
  3796. "Data: x%x x%x x%x\n",
  3797. pmbox->mbxCommand,
  3798. pmbox->mbxStatus, hbqno);
  3799. phba->link_state = LPFC_HBA_ERROR;
  3800. mempool_free(pmb, phba->mbox_mem_pool);
  3801. return -ENXIO;
  3802. }
  3803. }
  3804. phba->hbq_count = hbq_count;
  3805. mempool_free(pmb, phba->mbox_mem_pool);
  3806. /* Initially populate or replenish the HBQs */
  3807. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3808. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3809. return 0;
  3810. }
  3811. /**
  3812. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3813. * @phba: Pointer to HBA context object.
  3814. *
  3815. * This function is called during the SLI initialization to configure
  3816. * all the HBQs and post buffers to the HBQ. The caller is not
  3817. * required to hold any locks. This function will return zero if successful
  3818. * else it will return negative error code.
  3819. **/
  3820. static int
  3821. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3822. {
  3823. phba->hbq_in_use = 1;
  3824. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3825. phba->hbq_count = 1;
  3826. /* Initially populate or replenish the HBQs */
  3827. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3828. return 0;
  3829. }
  3830. /**
  3831. * lpfc_sli_config_port - Issue config port mailbox command
  3832. * @phba: Pointer to HBA context object.
  3833. * @sli_mode: sli mode - 2/3
  3834. *
  3835. * This function is called by the sli intialization code path
  3836. * to issue config_port mailbox command. This function restarts the
  3837. * HBA firmware and issues a config_port mailbox command to configure
  3838. * the SLI interface in the sli mode specified by sli_mode
  3839. * variable. The caller is not required to hold any locks.
  3840. * The function returns 0 if successful, else returns negative error
  3841. * code.
  3842. **/
  3843. int
  3844. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3845. {
  3846. LPFC_MBOXQ_t *pmb;
  3847. uint32_t resetcount = 0, rc = 0, done = 0;
  3848. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3849. if (!pmb) {
  3850. phba->link_state = LPFC_HBA_ERROR;
  3851. return -ENOMEM;
  3852. }
  3853. phba->sli_rev = sli_mode;
  3854. while (resetcount < 2 && !done) {
  3855. spin_lock_irq(&phba->hbalock);
  3856. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3857. spin_unlock_irq(&phba->hbalock);
  3858. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3859. lpfc_sli_brdrestart(phba);
  3860. rc = lpfc_sli_chipset_init(phba);
  3861. if (rc)
  3862. break;
  3863. spin_lock_irq(&phba->hbalock);
  3864. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3865. spin_unlock_irq(&phba->hbalock);
  3866. resetcount++;
  3867. /* Call pre CONFIG_PORT mailbox command initialization. A
  3868. * value of 0 means the call was successful. Any other
  3869. * nonzero value is a failure, but if ERESTART is returned,
  3870. * the driver may reset the HBA and try again.
  3871. */
  3872. rc = lpfc_config_port_prep(phba);
  3873. if (rc == -ERESTART) {
  3874. phba->link_state = LPFC_LINK_UNKNOWN;
  3875. continue;
  3876. } else if (rc)
  3877. break;
  3878. phba->link_state = LPFC_INIT_MBX_CMDS;
  3879. lpfc_config_port(phba, pmb);
  3880. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3881. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3882. LPFC_SLI3_HBQ_ENABLED |
  3883. LPFC_SLI3_CRP_ENABLED |
  3884. LPFC_SLI3_BG_ENABLED |
  3885. LPFC_SLI3_DSS_ENABLED);
  3886. if (rc != MBX_SUCCESS) {
  3887. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3888. "0442 Adapter failed to init, mbxCmd x%x "
  3889. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3890. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3891. spin_lock_irq(&phba->hbalock);
  3892. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3893. spin_unlock_irq(&phba->hbalock);
  3894. rc = -ENXIO;
  3895. } else {
  3896. /* Allow asynchronous mailbox command to go through */
  3897. spin_lock_irq(&phba->hbalock);
  3898. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3899. spin_unlock_irq(&phba->hbalock);
  3900. done = 1;
  3901. }
  3902. }
  3903. if (!done) {
  3904. rc = -EINVAL;
  3905. goto do_prep_failed;
  3906. }
  3907. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3908. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3909. rc = -ENXIO;
  3910. goto do_prep_failed;
  3911. }
  3912. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3913. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3914. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3915. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3916. phba->max_vpi : phba->max_vports;
  3917. } else
  3918. phba->max_vpi = 0;
  3919. phba->fips_level = 0;
  3920. phba->fips_spec_rev = 0;
  3921. if (pmb->u.mb.un.varCfgPort.gdss) {
  3922. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3923. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3924. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3925. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3926. "2850 Security Crypto Active. FIPS x%d "
  3927. "(Spec Rev: x%d)",
  3928. phba->fips_level, phba->fips_spec_rev);
  3929. }
  3930. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3931. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3932. "2856 Config Port Security Crypto "
  3933. "Error: x%x ",
  3934. pmb->u.mb.un.varCfgPort.sec_err);
  3935. }
  3936. if (pmb->u.mb.un.varCfgPort.gerbm)
  3937. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3938. if (pmb->u.mb.un.varCfgPort.gcrp)
  3939. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3940. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3941. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3942. if (phba->cfg_enable_bg) {
  3943. if (pmb->u.mb.un.varCfgPort.gbg)
  3944. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3945. else
  3946. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3947. "0443 Adapter did not grant "
  3948. "BlockGuard\n");
  3949. }
  3950. } else {
  3951. phba->hbq_get = NULL;
  3952. phba->port_gp = phba->mbox->us.s2.port;
  3953. phba->max_vpi = 0;
  3954. }
  3955. do_prep_failed:
  3956. mempool_free(pmb, phba->mbox_mem_pool);
  3957. return rc;
  3958. }
  3959. /**
  3960. * lpfc_sli_hba_setup - SLI intialization function
  3961. * @phba: Pointer to HBA context object.
  3962. *
  3963. * This function is the main SLI intialization function. This function
  3964. * is called by the HBA intialization code, HBA reset code and HBA
  3965. * error attention handler code. Caller is not required to hold any
  3966. * locks. This function issues config_port mailbox command to configure
  3967. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3968. * calls the config_port_post function to issue init_link mailbox
  3969. * command and to start the discovery. The function will return zero
  3970. * if successful, else it will return negative error code.
  3971. **/
  3972. int
  3973. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3974. {
  3975. uint32_t rc;
  3976. int mode = 3;
  3977. switch (lpfc_sli_mode) {
  3978. case 2:
  3979. if (phba->cfg_enable_npiv) {
  3980. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3981. "1824 NPIV enabled: Override lpfc_sli_mode "
  3982. "parameter (%d) to auto (0).\n",
  3983. lpfc_sli_mode);
  3984. break;
  3985. }
  3986. mode = 2;
  3987. break;
  3988. case 0:
  3989. case 3:
  3990. break;
  3991. default:
  3992. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3993. "1819 Unrecognized lpfc_sli_mode "
  3994. "parameter: %d.\n", lpfc_sli_mode);
  3995. break;
  3996. }
  3997. rc = lpfc_sli_config_port(phba, mode);
  3998. if (rc && lpfc_sli_mode == 3)
  3999. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4000. "1820 Unable to select SLI-3. "
  4001. "Not supported by adapter.\n");
  4002. if (rc && mode != 2)
  4003. rc = lpfc_sli_config_port(phba, 2);
  4004. if (rc)
  4005. goto lpfc_sli_hba_setup_error;
  4006. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4007. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4008. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4009. if (!rc) {
  4010. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4011. "2709 This device supports "
  4012. "Advanced Error Reporting (AER)\n");
  4013. spin_lock_irq(&phba->hbalock);
  4014. phba->hba_flag |= HBA_AER_ENABLED;
  4015. spin_unlock_irq(&phba->hbalock);
  4016. } else {
  4017. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4018. "2708 This device does not support "
  4019. "Advanced Error Reporting (AER)\n");
  4020. phba->cfg_aer_support = 0;
  4021. }
  4022. }
  4023. if (phba->sli_rev == 3) {
  4024. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4025. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4026. } else {
  4027. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4028. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4029. phba->sli3_options = 0;
  4030. }
  4031. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4032. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4033. phba->sli_rev, phba->max_vpi);
  4034. rc = lpfc_sli_ring_map(phba);
  4035. if (rc)
  4036. goto lpfc_sli_hba_setup_error;
  4037. /* Init HBQs */
  4038. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4039. rc = lpfc_sli_hbq_setup(phba);
  4040. if (rc)
  4041. goto lpfc_sli_hba_setup_error;
  4042. }
  4043. spin_lock_irq(&phba->hbalock);
  4044. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4045. spin_unlock_irq(&phba->hbalock);
  4046. rc = lpfc_config_port_post(phba);
  4047. if (rc)
  4048. goto lpfc_sli_hba_setup_error;
  4049. return rc;
  4050. lpfc_sli_hba_setup_error:
  4051. phba->link_state = LPFC_HBA_ERROR;
  4052. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4053. "0445 Firmware initialization failed\n");
  4054. return rc;
  4055. }
  4056. /**
  4057. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4058. * @phba: Pointer to HBA context object.
  4059. * @mboxq: mailbox pointer.
  4060. * This function issue a dump mailbox command to read config region
  4061. * 23 and parse the records in the region and populate driver
  4062. * data structure.
  4063. **/
  4064. static int
  4065. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  4066. LPFC_MBOXQ_t *mboxq)
  4067. {
  4068. struct lpfc_dmabuf *mp;
  4069. struct lpfc_mqe *mqe;
  4070. uint32_t data_length;
  4071. int rc;
  4072. /* Program the default value of vlan_id and fc_map */
  4073. phba->valid_vlan = 0;
  4074. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4075. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4076. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4077. mqe = &mboxq->u.mqe;
  4078. if (lpfc_dump_fcoe_param(phba, mboxq))
  4079. return -ENOMEM;
  4080. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4081. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4082. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4083. "(%d):2571 Mailbox cmd x%x Status x%x "
  4084. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4085. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4086. "CQ: x%x x%x x%x x%x\n",
  4087. mboxq->vport ? mboxq->vport->vpi : 0,
  4088. bf_get(lpfc_mqe_command, mqe),
  4089. bf_get(lpfc_mqe_status, mqe),
  4090. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4091. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4092. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4093. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4094. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4095. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4096. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4097. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4098. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4099. mboxq->mcqe.word0,
  4100. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4101. mboxq->mcqe.trailer);
  4102. if (rc) {
  4103. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4104. kfree(mp);
  4105. return -EIO;
  4106. }
  4107. data_length = mqe->un.mb_words[5];
  4108. if (data_length > DMP_RGN23_SIZE) {
  4109. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4110. kfree(mp);
  4111. return -EIO;
  4112. }
  4113. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4114. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4115. kfree(mp);
  4116. return 0;
  4117. }
  4118. /**
  4119. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4120. * @phba: pointer to lpfc hba data structure.
  4121. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4122. * @vpd: pointer to the memory to hold resulting port vpd data.
  4123. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4124. * On output, the number of data bytes in @vpd.
  4125. *
  4126. * This routine executes a READ_REV SLI4 mailbox command. In
  4127. * addition, this routine gets the port vpd data.
  4128. *
  4129. * Return codes
  4130. * 0 - successful
  4131. * -ENOMEM - could not allocated memory.
  4132. **/
  4133. static int
  4134. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4135. uint8_t *vpd, uint32_t *vpd_size)
  4136. {
  4137. int rc = 0;
  4138. uint32_t dma_size;
  4139. struct lpfc_dmabuf *dmabuf;
  4140. struct lpfc_mqe *mqe;
  4141. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4142. if (!dmabuf)
  4143. return -ENOMEM;
  4144. /*
  4145. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4146. * mailbox command.
  4147. */
  4148. dma_size = *vpd_size;
  4149. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4150. dma_size,
  4151. &dmabuf->phys,
  4152. GFP_KERNEL);
  4153. if (!dmabuf->virt) {
  4154. kfree(dmabuf);
  4155. return -ENOMEM;
  4156. }
  4157. memset(dmabuf->virt, 0, dma_size);
  4158. /*
  4159. * The SLI4 implementation of READ_REV conflicts at word1,
  4160. * bits 31:16 and SLI4 adds vpd functionality not present
  4161. * in SLI3. This code corrects the conflicts.
  4162. */
  4163. lpfc_read_rev(phba, mboxq);
  4164. mqe = &mboxq->u.mqe;
  4165. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4166. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4167. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4168. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4169. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4170. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4171. if (rc) {
  4172. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4173. dmabuf->virt, dmabuf->phys);
  4174. kfree(dmabuf);
  4175. return -EIO;
  4176. }
  4177. /*
  4178. * The available vpd length cannot be bigger than the
  4179. * DMA buffer passed to the port. Catch the less than
  4180. * case and update the caller's size.
  4181. */
  4182. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4183. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4184. memcpy(vpd, dmabuf->virt, *vpd_size);
  4185. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4186. dmabuf->virt, dmabuf->phys);
  4187. kfree(dmabuf);
  4188. return 0;
  4189. }
  4190. /**
  4191. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4192. * @phba: pointer to lpfc hba data structure.
  4193. *
  4194. * This routine is called to explicitly arm the SLI4 device's completion and
  4195. * event queues
  4196. **/
  4197. static void
  4198. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4199. {
  4200. uint8_t fcp_eqidx;
  4201. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4202. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4203. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4204. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4205. LPFC_QUEUE_REARM);
  4206. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4207. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4208. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4209. LPFC_QUEUE_REARM);
  4210. }
  4211. /**
  4212. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  4213. * @phba: Pointer to HBA context object.
  4214. *
  4215. * This function is the main SLI4 device intialization PCI function. This
  4216. * function is called by the HBA intialization code, HBA reset code and
  4217. * HBA error attention handler code. Caller is not required to hold any
  4218. * locks.
  4219. **/
  4220. int
  4221. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  4222. {
  4223. int rc;
  4224. LPFC_MBOXQ_t *mboxq;
  4225. struct lpfc_mqe *mqe;
  4226. uint8_t *vpd;
  4227. uint32_t vpd_size;
  4228. uint32_t ftr_rsp = 0;
  4229. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  4230. struct lpfc_vport *vport = phba->pport;
  4231. struct lpfc_dmabuf *mp;
  4232. /*
  4233. * TODO: Why does this routine execute these task in a different
  4234. * order from probe?
  4235. */
  4236. /* Perform a PCI function reset to start from clean */
  4237. rc = lpfc_pci_function_reset(phba);
  4238. if (unlikely(rc))
  4239. return -ENODEV;
  4240. /* Check the HBA Host Status Register for readyness */
  4241. rc = lpfc_sli4_post_status_check(phba);
  4242. if (unlikely(rc))
  4243. return -ENODEV;
  4244. else {
  4245. spin_lock_irq(&phba->hbalock);
  4246. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  4247. spin_unlock_irq(&phba->hbalock);
  4248. }
  4249. /*
  4250. * Allocate a single mailbox container for initializing the
  4251. * port.
  4252. */
  4253. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4254. if (!mboxq)
  4255. return -ENOMEM;
  4256. /*
  4257. * Continue initialization with default values even if driver failed
  4258. * to read FCoE param config regions
  4259. */
  4260. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  4261. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4262. "2570 Failed to read FCoE parameters\n");
  4263. /* Issue READ_REV to collect vpd and FW information. */
  4264. vpd_size = SLI4_PAGE_SIZE;
  4265. vpd = kzalloc(vpd_size, GFP_KERNEL);
  4266. if (!vpd) {
  4267. rc = -ENOMEM;
  4268. goto out_free_mbox;
  4269. }
  4270. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  4271. if (unlikely(rc)) {
  4272. kfree(vpd);
  4273. goto out_free_mbox;
  4274. }
  4275. mqe = &mboxq->u.mqe;
  4276. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  4277. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  4278. phba->hba_flag |= HBA_FCOE_MODE;
  4279. else
  4280. phba->hba_flag &= ~HBA_FCOE_MODE;
  4281. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  4282. LPFC_DCBX_CEE_MODE)
  4283. phba->hba_flag |= HBA_FIP_SUPPORT;
  4284. else
  4285. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  4286. if (phba->sli_rev != LPFC_SLI_REV4 ||
  4287. !(phba->hba_flag & HBA_FCOE_MODE)) {
  4288. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4289. "0376 READ_REV Error. SLI Level %d "
  4290. "FCoE enabled %d\n",
  4291. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  4292. rc = -EIO;
  4293. kfree(vpd);
  4294. goto out_free_mbox;
  4295. }
  4296. /*
  4297. * Evaluate the read rev and vpd data. Populate the driver
  4298. * state with the results. If this routine fails, the failure
  4299. * is not fatal as the driver will use generic values.
  4300. */
  4301. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  4302. if (unlikely(!rc)) {
  4303. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4304. "0377 Error %d parsing vpd. "
  4305. "Using defaults.\n", rc);
  4306. rc = 0;
  4307. }
  4308. kfree(vpd);
  4309. /* Save information as VPD data */
  4310. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  4311. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  4312. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  4313. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  4314. &mqe->un.read_rev);
  4315. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  4316. &mqe->un.read_rev);
  4317. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  4318. &mqe->un.read_rev);
  4319. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  4320. &mqe->un.read_rev);
  4321. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  4322. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  4323. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  4324. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  4325. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  4326. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  4327. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4328. "(%d):0380 READ_REV Status x%x "
  4329. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  4330. mboxq->vport ? mboxq->vport->vpi : 0,
  4331. bf_get(lpfc_mqe_status, mqe),
  4332. phba->vpd.rev.opFwName,
  4333. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  4334. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  4335. /*
  4336. * Discover the port's supported feature set and match it against the
  4337. * hosts requests.
  4338. */
  4339. lpfc_request_features(phba, mboxq);
  4340. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4341. if (unlikely(rc)) {
  4342. rc = -EIO;
  4343. goto out_free_mbox;
  4344. }
  4345. /*
  4346. * The port must support FCP initiator mode as this is the
  4347. * only mode running in the host.
  4348. */
  4349. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  4350. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4351. "0378 No support for fcpi mode.\n");
  4352. ftr_rsp++;
  4353. }
  4354. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  4355. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  4356. else
  4357. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  4358. /*
  4359. * If the port cannot support the host's requested features
  4360. * then turn off the global config parameters to disable the
  4361. * feature in the driver. This is not a fatal error.
  4362. */
  4363. if ((phba->cfg_enable_bg) &&
  4364. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4365. ftr_rsp++;
  4366. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4367. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4368. ftr_rsp++;
  4369. if (ftr_rsp) {
  4370. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4371. "0379 Feature Mismatch Data: x%08x %08x "
  4372. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4373. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4374. phba->cfg_enable_npiv, phba->max_vpi);
  4375. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4376. phba->cfg_enable_bg = 0;
  4377. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4378. phba->cfg_enable_npiv = 0;
  4379. }
  4380. /* These SLI3 features are assumed in SLI4 */
  4381. spin_lock_irq(&phba->hbalock);
  4382. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4383. spin_unlock_irq(&phba->hbalock);
  4384. /* Read the port's service parameters. */
  4385. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4386. if (rc) {
  4387. phba->link_state = LPFC_HBA_ERROR;
  4388. rc = -ENOMEM;
  4389. goto out_free_mbox;
  4390. }
  4391. mboxq->vport = vport;
  4392. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4393. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4394. if (rc == MBX_SUCCESS) {
  4395. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4396. rc = 0;
  4397. }
  4398. /*
  4399. * This memory was allocated by the lpfc_read_sparam routine. Release
  4400. * it to the mbuf pool.
  4401. */
  4402. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4403. kfree(mp);
  4404. mboxq->context1 = NULL;
  4405. if (unlikely(rc)) {
  4406. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4407. "0382 READ_SPARAM command failed "
  4408. "status %d, mbxStatus x%x\n",
  4409. rc, bf_get(lpfc_mqe_status, mqe));
  4410. phba->link_state = LPFC_HBA_ERROR;
  4411. rc = -EIO;
  4412. goto out_free_mbox;
  4413. }
  4414. if (phba->cfg_soft_wwnn)
  4415. u64_to_wwn(phba->cfg_soft_wwnn,
  4416. vport->fc_sparam.nodeName.u.wwn);
  4417. if (phba->cfg_soft_wwpn)
  4418. u64_to_wwn(phba->cfg_soft_wwpn,
  4419. vport->fc_sparam.portName.u.wwn);
  4420. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4421. sizeof(struct lpfc_name));
  4422. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4423. sizeof(struct lpfc_name));
  4424. /* Update the fc_host data structures with new wwn. */
  4425. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4426. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4427. /* Register SGL pool to the device using non-embedded mailbox command */
  4428. rc = lpfc_sli4_post_sgl_list(phba);
  4429. if (unlikely(rc)) {
  4430. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4431. "0582 Error %d during sgl post operation\n",
  4432. rc);
  4433. rc = -ENODEV;
  4434. goto out_free_mbox;
  4435. }
  4436. /* Register SCSI SGL pool to the device */
  4437. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4438. if (unlikely(rc)) {
  4439. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4440. "0383 Error %d during scsi sgl post "
  4441. "operation\n", rc);
  4442. /* Some Scsi buffers were moved to the abort scsi list */
  4443. /* A pci function reset will repost them */
  4444. rc = -ENODEV;
  4445. goto out_free_mbox;
  4446. }
  4447. /* Post the rpi header region to the device. */
  4448. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4449. if (unlikely(rc)) {
  4450. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4451. "0393 Error %d during rpi post operation\n",
  4452. rc);
  4453. rc = -ENODEV;
  4454. goto out_free_mbox;
  4455. }
  4456. /* Set up all the queues to the device */
  4457. rc = lpfc_sli4_queue_setup(phba);
  4458. if (unlikely(rc)) {
  4459. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4460. "0381 Error %d during queue setup.\n ", rc);
  4461. goto out_stop_timers;
  4462. }
  4463. /* Arm the CQs and then EQs on device */
  4464. lpfc_sli4_arm_cqeq_intr(phba);
  4465. /* Indicate device interrupt mode */
  4466. phba->sli4_hba.intr_enable = 1;
  4467. /* Allow asynchronous mailbox command to go through */
  4468. spin_lock_irq(&phba->hbalock);
  4469. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4470. spin_unlock_irq(&phba->hbalock);
  4471. /* Post receive buffers to the device */
  4472. lpfc_sli4_rb_setup(phba);
  4473. /* Reset HBA FCF states after HBA reset */
  4474. phba->fcf.fcf_flag = 0;
  4475. phba->fcf.current_rec.flag = 0;
  4476. /* Start the ELS watchdog timer */
  4477. mod_timer(&vport->els_tmofunc,
  4478. jiffies + HZ * (phba->fc_ratov * 2));
  4479. /* Start heart beat timer */
  4480. mod_timer(&phba->hb_tmofunc,
  4481. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4482. phba->hb_outstanding = 0;
  4483. phba->last_completion_time = jiffies;
  4484. /* Start error attention (ERATT) polling timer */
  4485. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4486. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4487. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4488. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4489. if (!rc) {
  4490. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4491. "2829 This device supports "
  4492. "Advanced Error Reporting (AER)\n");
  4493. spin_lock_irq(&phba->hbalock);
  4494. phba->hba_flag |= HBA_AER_ENABLED;
  4495. spin_unlock_irq(&phba->hbalock);
  4496. } else {
  4497. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4498. "2830 This device does not support "
  4499. "Advanced Error Reporting (AER)\n");
  4500. phba->cfg_aer_support = 0;
  4501. }
  4502. }
  4503. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  4504. /*
  4505. * The FC Port needs to register FCFI (index 0)
  4506. */
  4507. lpfc_reg_fcfi(phba, mboxq);
  4508. mboxq->vport = phba->pport;
  4509. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4510. if (rc == MBX_SUCCESS)
  4511. rc = 0;
  4512. else
  4513. goto out_unset_queue;
  4514. }
  4515. /*
  4516. * The port is ready, set the host's link state to LINK_DOWN
  4517. * in preparation for link interrupts.
  4518. */
  4519. spin_lock_irq(&phba->hbalock);
  4520. phba->link_state = LPFC_LINK_DOWN;
  4521. spin_unlock_irq(&phba->hbalock);
  4522. if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK)
  4523. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  4524. out_unset_queue:
  4525. /* Unset all the queues set up in this routine when error out */
  4526. if (rc)
  4527. lpfc_sli4_queue_unset(phba);
  4528. out_stop_timers:
  4529. if (rc)
  4530. lpfc_stop_hba_timers(phba);
  4531. out_free_mbox:
  4532. mempool_free(mboxq, phba->mbox_mem_pool);
  4533. return rc;
  4534. }
  4535. /**
  4536. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4537. * @ptr: context object - pointer to hba structure.
  4538. *
  4539. * This is the callback function for mailbox timer. The mailbox
  4540. * timer is armed when a new mailbox command is issued and the timer
  4541. * is deleted when the mailbox complete. The function is called by
  4542. * the kernel timer code when a mailbox does not complete within
  4543. * expected time. This function wakes up the worker thread to
  4544. * process the mailbox timeout and returns. All the processing is
  4545. * done by the worker thread function lpfc_mbox_timeout_handler.
  4546. **/
  4547. void
  4548. lpfc_mbox_timeout(unsigned long ptr)
  4549. {
  4550. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4551. unsigned long iflag;
  4552. uint32_t tmo_posted;
  4553. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4554. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4555. if (!tmo_posted)
  4556. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4557. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4558. if (!tmo_posted)
  4559. lpfc_worker_wake_up(phba);
  4560. return;
  4561. }
  4562. /**
  4563. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4564. * @phba: Pointer to HBA context object.
  4565. *
  4566. * This function is called from worker thread when a mailbox command times out.
  4567. * The caller is not required to hold any locks. This function will reset the
  4568. * HBA and recover all the pending commands.
  4569. **/
  4570. void
  4571. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4572. {
  4573. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4574. MAILBOX_t *mb = &pmbox->u.mb;
  4575. struct lpfc_sli *psli = &phba->sli;
  4576. struct lpfc_sli_ring *pring;
  4577. /* Check the pmbox pointer first. There is a race condition
  4578. * between the mbox timeout handler getting executed in the
  4579. * worklist and the mailbox actually completing. When this
  4580. * race condition occurs, the mbox_active will be NULL.
  4581. */
  4582. spin_lock_irq(&phba->hbalock);
  4583. if (pmbox == NULL) {
  4584. lpfc_printf_log(phba, KERN_WARNING,
  4585. LOG_MBOX | LOG_SLI,
  4586. "0353 Active Mailbox cleared - mailbox timeout "
  4587. "exiting\n");
  4588. spin_unlock_irq(&phba->hbalock);
  4589. return;
  4590. }
  4591. /* Mbox cmd <mbxCommand> timeout */
  4592. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4593. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4594. mb->mbxCommand,
  4595. phba->pport->port_state,
  4596. phba->sli.sli_flag,
  4597. phba->sli.mbox_active);
  4598. spin_unlock_irq(&phba->hbalock);
  4599. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4600. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4601. * it to fail all oustanding SCSI IO.
  4602. */
  4603. spin_lock_irq(&phba->pport->work_port_lock);
  4604. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4605. spin_unlock_irq(&phba->pport->work_port_lock);
  4606. spin_lock_irq(&phba->hbalock);
  4607. phba->link_state = LPFC_LINK_UNKNOWN;
  4608. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4609. spin_unlock_irq(&phba->hbalock);
  4610. pring = &psli->ring[psli->fcp_ring];
  4611. lpfc_sli_abort_iocb_ring(phba, pring);
  4612. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4613. "0345 Resetting board due to mailbox timeout\n");
  4614. /* Reset the HBA device */
  4615. lpfc_reset_hba(phba);
  4616. }
  4617. /**
  4618. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4619. * @phba: Pointer to HBA context object.
  4620. * @pmbox: Pointer to mailbox object.
  4621. * @flag: Flag indicating how the mailbox need to be processed.
  4622. *
  4623. * This function is called by discovery code and HBA management code
  4624. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4625. * function gets the hbalock to protect the data structures.
  4626. * The mailbox command can be submitted in polling mode, in which case
  4627. * this function will wait in a polling loop for the completion of the
  4628. * mailbox.
  4629. * If the mailbox is submitted in no_wait mode (not polling) the
  4630. * function will submit the command and returns immediately without waiting
  4631. * for the mailbox completion. The no_wait is supported only when HBA
  4632. * is in SLI2/SLI3 mode - interrupts are enabled.
  4633. * The SLI interface allows only one mailbox pending at a time. If the
  4634. * mailbox is issued in polling mode and there is already a mailbox
  4635. * pending, then the function will return an error. If the mailbox is issued
  4636. * in NO_WAIT mode and there is a mailbox pending already, the function
  4637. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4638. * The sli layer owns the mailbox object until the completion of mailbox
  4639. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4640. * return codes the caller owns the mailbox command after the return of
  4641. * the function.
  4642. **/
  4643. static int
  4644. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4645. uint32_t flag)
  4646. {
  4647. MAILBOX_t *mb;
  4648. struct lpfc_sli *psli = &phba->sli;
  4649. uint32_t status, evtctr;
  4650. uint32_t ha_copy;
  4651. int i;
  4652. unsigned long timeout;
  4653. unsigned long drvr_flag = 0;
  4654. uint32_t word0, ldata;
  4655. void __iomem *to_slim;
  4656. int processing_queue = 0;
  4657. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4658. if (!pmbox) {
  4659. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4660. /* processing mbox queue from intr_handler */
  4661. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4662. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4663. return MBX_SUCCESS;
  4664. }
  4665. processing_queue = 1;
  4666. pmbox = lpfc_mbox_get(phba);
  4667. if (!pmbox) {
  4668. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4669. return MBX_SUCCESS;
  4670. }
  4671. }
  4672. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4673. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4674. if(!pmbox->vport) {
  4675. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4676. lpfc_printf_log(phba, KERN_ERR,
  4677. LOG_MBOX | LOG_VPORT,
  4678. "1806 Mbox x%x failed. No vport\n",
  4679. pmbox->u.mb.mbxCommand);
  4680. dump_stack();
  4681. goto out_not_finished;
  4682. }
  4683. }
  4684. /* If the PCI channel is in offline state, do not post mbox. */
  4685. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4686. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4687. goto out_not_finished;
  4688. }
  4689. /* If HBA has a deferred error attention, fail the iocb. */
  4690. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4691. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4692. goto out_not_finished;
  4693. }
  4694. psli = &phba->sli;
  4695. mb = &pmbox->u.mb;
  4696. status = MBX_SUCCESS;
  4697. if (phba->link_state == LPFC_HBA_ERROR) {
  4698. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4699. /* Mbox command <mbxCommand> cannot issue */
  4700. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4701. "(%d):0311 Mailbox command x%x cannot "
  4702. "issue Data: x%x x%x\n",
  4703. pmbox->vport ? pmbox->vport->vpi : 0,
  4704. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4705. goto out_not_finished;
  4706. }
  4707. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4708. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4709. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4710. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4711. "(%d):2528 Mailbox command x%x cannot "
  4712. "issue Data: x%x x%x\n",
  4713. pmbox->vport ? pmbox->vport->vpi : 0,
  4714. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4715. goto out_not_finished;
  4716. }
  4717. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4718. /* Polling for a mbox command when another one is already active
  4719. * is not allowed in SLI. Also, the driver must have established
  4720. * SLI2 mode to queue and process multiple mbox commands.
  4721. */
  4722. if (flag & MBX_POLL) {
  4723. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4724. /* Mbox command <mbxCommand> cannot issue */
  4725. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4726. "(%d):2529 Mailbox command x%x "
  4727. "cannot issue Data: x%x x%x\n",
  4728. pmbox->vport ? pmbox->vport->vpi : 0,
  4729. pmbox->u.mb.mbxCommand,
  4730. psli->sli_flag, flag);
  4731. goto out_not_finished;
  4732. }
  4733. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4734. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4735. /* Mbox command <mbxCommand> cannot issue */
  4736. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4737. "(%d):2530 Mailbox command x%x "
  4738. "cannot issue Data: x%x x%x\n",
  4739. pmbox->vport ? pmbox->vport->vpi : 0,
  4740. pmbox->u.mb.mbxCommand,
  4741. psli->sli_flag, flag);
  4742. goto out_not_finished;
  4743. }
  4744. /* Another mailbox command is still being processed, queue this
  4745. * command to be processed later.
  4746. */
  4747. lpfc_mbox_put(phba, pmbox);
  4748. /* Mbox cmd issue - BUSY */
  4749. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4750. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4751. "x%x x%x x%x x%x\n",
  4752. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4753. mb->mbxCommand, phba->pport->port_state,
  4754. psli->sli_flag, flag);
  4755. psli->slistat.mbox_busy++;
  4756. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4757. if (pmbox->vport) {
  4758. lpfc_debugfs_disc_trc(pmbox->vport,
  4759. LPFC_DISC_TRC_MBOX_VPORT,
  4760. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4761. (uint32_t)mb->mbxCommand,
  4762. mb->un.varWords[0], mb->un.varWords[1]);
  4763. }
  4764. else {
  4765. lpfc_debugfs_disc_trc(phba->pport,
  4766. LPFC_DISC_TRC_MBOX,
  4767. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4768. (uint32_t)mb->mbxCommand,
  4769. mb->un.varWords[0], mb->un.varWords[1]);
  4770. }
  4771. return MBX_BUSY;
  4772. }
  4773. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4774. /* If we are not polling, we MUST be in SLI2 mode */
  4775. if (flag != MBX_POLL) {
  4776. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4777. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4778. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4779. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4780. /* Mbox command <mbxCommand> cannot issue */
  4781. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4782. "(%d):2531 Mailbox command x%x "
  4783. "cannot issue Data: x%x x%x\n",
  4784. pmbox->vport ? pmbox->vport->vpi : 0,
  4785. pmbox->u.mb.mbxCommand,
  4786. psli->sli_flag, flag);
  4787. goto out_not_finished;
  4788. }
  4789. /* timeout active mbox command */
  4790. mod_timer(&psli->mbox_tmo, (jiffies +
  4791. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4792. }
  4793. /* Mailbox cmd <cmd> issue */
  4794. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4795. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4796. "x%x\n",
  4797. pmbox->vport ? pmbox->vport->vpi : 0,
  4798. mb->mbxCommand, phba->pport->port_state,
  4799. psli->sli_flag, flag);
  4800. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4801. if (pmbox->vport) {
  4802. lpfc_debugfs_disc_trc(pmbox->vport,
  4803. LPFC_DISC_TRC_MBOX_VPORT,
  4804. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4805. (uint32_t)mb->mbxCommand,
  4806. mb->un.varWords[0], mb->un.varWords[1]);
  4807. }
  4808. else {
  4809. lpfc_debugfs_disc_trc(phba->pport,
  4810. LPFC_DISC_TRC_MBOX,
  4811. "MBOX Send: cmd:x%x mb:x%x x%x",
  4812. (uint32_t)mb->mbxCommand,
  4813. mb->un.varWords[0], mb->un.varWords[1]);
  4814. }
  4815. }
  4816. psli->slistat.mbox_cmd++;
  4817. evtctr = psli->slistat.mbox_event;
  4818. /* next set own bit for the adapter and copy over command word */
  4819. mb->mbxOwner = OWN_CHIP;
  4820. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4821. /* Populate mbox extension offset word. */
  4822. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4823. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4824. = (uint8_t *)phba->mbox_ext
  4825. - (uint8_t *)phba->mbox;
  4826. }
  4827. /* Copy the mailbox extension data */
  4828. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4829. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4830. (uint8_t *)phba->mbox_ext,
  4831. pmbox->in_ext_byte_len);
  4832. }
  4833. /* Copy command data to host SLIM area */
  4834. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4835. } else {
  4836. /* Populate mbox extension offset word. */
  4837. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4838. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4839. = MAILBOX_HBA_EXT_OFFSET;
  4840. /* Copy the mailbox extension data */
  4841. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4842. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4843. MAILBOX_HBA_EXT_OFFSET,
  4844. pmbox->context2, pmbox->in_ext_byte_len);
  4845. }
  4846. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4847. /* copy command data into host mbox for cmpl */
  4848. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4849. }
  4850. /* First copy mbox command data to HBA SLIM, skip past first
  4851. word */
  4852. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4853. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4854. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4855. /* Next copy over first word, with mbxOwner set */
  4856. ldata = *((uint32_t *)mb);
  4857. to_slim = phba->MBslimaddr;
  4858. writel(ldata, to_slim);
  4859. readl(to_slim); /* flush */
  4860. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4861. /* switch over to host mailbox */
  4862. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4863. }
  4864. }
  4865. wmb();
  4866. switch (flag) {
  4867. case MBX_NOWAIT:
  4868. /* Set up reference to mailbox command */
  4869. psli->mbox_active = pmbox;
  4870. /* Interrupt board to do it */
  4871. writel(CA_MBATT, phba->CAregaddr);
  4872. readl(phba->CAregaddr); /* flush */
  4873. /* Don't wait for it to finish, just return */
  4874. break;
  4875. case MBX_POLL:
  4876. /* Set up null reference to mailbox command */
  4877. psli->mbox_active = NULL;
  4878. /* Interrupt board to do it */
  4879. writel(CA_MBATT, phba->CAregaddr);
  4880. readl(phba->CAregaddr); /* flush */
  4881. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4882. /* First read mbox status word */
  4883. word0 = *((uint32_t *)phba->mbox);
  4884. word0 = le32_to_cpu(word0);
  4885. } else {
  4886. /* First read mbox status word */
  4887. word0 = readl(phba->MBslimaddr);
  4888. }
  4889. /* Read the HBA Host Attention Register */
  4890. ha_copy = readl(phba->HAregaddr);
  4891. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4892. mb->mbxCommand) *
  4893. 1000) + jiffies;
  4894. i = 0;
  4895. /* Wait for command to complete */
  4896. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4897. (!(ha_copy & HA_MBATT) &&
  4898. (phba->link_state > LPFC_WARM_START))) {
  4899. if (time_after(jiffies, timeout)) {
  4900. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4901. spin_unlock_irqrestore(&phba->hbalock,
  4902. drvr_flag);
  4903. goto out_not_finished;
  4904. }
  4905. /* Check if we took a mbox interrupt while we were
  4906. polling */
  4907. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4908. && (evtctr != psli->slistat.mbox_event))
  4909. break;
  4910. if (i++ > 10) {
  4911. spin_unlock_irqrestore(&phba->hbalock,
  4912. drvr_flag);
  4913. msleep(1);
  4914. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4915. }
  4916. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4917. /* First copy command data */
  4918. word0 = *((uint32_t *)phba->mbox);
  4919. word0 = le32_to_cpu(word0);
  4920. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4921. MAILBOX_t *slimmb;
  4922. uint32_t slimword0;
  4923. /* Check real SLIM for any errors */
  4924. slimword0 = readl(phba->MBslimaddr);
  4925. slimmb = (MAILBOX_t *) & slimword0;
  4926. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4927. && slimmb->mbxStatus) {
  4928. psli->sli_flag &=
  4929. ~LPFC_SLI_ACTIVE;
  4930. word0 = slimword0;
  4931. }
  4932. }
  4933. } else {
  4934. /* First copy command data */
  4935. word0 = readl(phba->MBslimaddr);
  4936. }
  4937. /* Read the HBA Host Attention Register */
  4938. ha_copy = readl(phba->HAregaddr);
  4939. }
  4940. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4941. /* copy results back to user */
  4942. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4943. /* Copy the mailbox extension data */
  4944. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4945. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4946. pmbox->context2,
  4947. pmbox->out_ext_byte_len);
  4948. }
  4949. } else {
  4950. /* First copy command data */
  4951. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4952. MAILBOX_CMD_SIZE);
  4953. /* Copy the mailbox extension data */
  4954. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4955. lpfc_memcpy_from_slim(pmbox->context2,
  4956. phba->MBslimaddr +
  4957. MAILBOX_HBA_EXT_OFFSET,
  4958. pmbox->out_ext_byte_len);
  4959. }
  4960. }
  4961. writel(HA_MBATT, phba->HAregaddr);
  4962. readl(phba->HAregaddr); /* flush */
  4963. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4964. status = mb->mbxStatus;
  4965. }
  4966. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4967. return status;
  4968. out_not_finished:
  4969. if (processing_queue) {
  4970. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4971. lpfc_mbox_cmpl_put(phba, pmbox);
  4972. }
  4973. return MBX_NOT_FINISHED;
  4974. }
  4975. /**
  4976. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4977. * @phba: Pointer to HBA context object.
  4978. *
  4979. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4980. * the driver internal pending mailbox queue. It will then try to wait out the
  4981. * possible outstanding mailbox command before return.
  4982. *
  4983. * Returns:
  4984. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4985. * the outstanding mailbox command timed out.
  4986. **/
  4987. static int
  4988. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4989. {
  4990. struct lpfc_sli *psli = &phba->sli;
  4991. uint8_t actcmd = MBX_HEARTBEAT;
  4992. int rc = 0;
  4993. unsigned long timeout;
  4994. /* Mark the asynchronous mailbox command posting as blocked */
  4995. spin_lock_irq(&phba->hbalock);
  4996. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4997. if (phba->sli.mbox_active)
  4998. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4999. spin_unlock_irq(&phba->hbalock);
  5000. /* Determine how long we might wait for the active mailbox
  5001. * command to be gracefully completed by firmware.
  5002. */
  5003. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  5004. jiffies;
  5005. /* Wait for the outstnading mailbox command to complete */
  5006. while (phba->sli.mbox_active) {
  5007. /* Check active mailbox complete status every 2ms */
  5008. msleep(2);
  5009. if (time_after(jiffies, timeout)) {
  5010. /* Timeout, marked the outstanding cmd not complete */
  5011. rc = 1;
  5012. break;
  5013. }
  5014. }
  5015. /* Can not cleanly block async mailbox command, fails it */
  5016. if (rc) {
  5017. spin_lock_irq(&phba->hbalock);
  5018. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5019. spin_unlock_irq(&phba->hbalock);
  5020. }
  5021. return rc;
  5022. }
  5023. /**
  5024. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  5025. * @phba: Pointer to HBA context object.
  5026. *
  5027. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  5028. * commands from the driver internal pending mailbox queue. It makes sure
  5029. * that there is no outstanding mailbox command before resuming posting
  5030. * asynchronous mailbox commands. If, for any reason, there is outstanding
  5031. * mailbox command, it will try to wait it out before resuming asynchronous
  5032. * mailbox command posting.
  5033. **/
  5034. static void
  5035. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  5036. {
  5037. struct lpfc_sli *psli = &phba->sli;
  5038. spin_lock_irq(&phba->hbalock);
  5039. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5040. /* Asynchronous mailbox posting is not blocked, do nothing */
  5041. spin_unlock_irq(&phba->hbalock);
  5042. return;
  5043. }
  5044. /* Outstanding synchronous mailbox command is guaranteed to be done,
  5045. * successful or timeout, after timing-out the outstanding mailbox
  5046. * command shall always be removed, so just unblock posting async
  5047. * mailbox command and resume
  5048. */
  5049. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5050. spin_unlock_irq(&phba->hbalock);
  5051. /* wake up worker thread to post asynchronlous mailbox command */
  5052. lpfc_worker_wake_up(phba);
  5053. }
  5054. /**
  5055. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  5056. * @phba: Pointer to HBA context object.
  5057. * @mboxq: Pointer to mailbox object.
  5058. *
  5059. * The function posts a mailbox to the port. The mailbox is expected
  5060. * to be comletely filled in and ready for the port to operate on it.
  5061. * This routine executes a synchronous completion operation on the
  5062. * mailbox by polling for its completion.
  5063. *
  5064. * The caller must not be holding any locks when calling this routine.
  5065. *
  5066. * Returns:
  5067. * MBX_SUCCESS - mailbox posted successfully
  5068. * Any of the MBX error values.
  5069. **/
  5070. static int
  5071. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5072. {
  5073. int rc = MBX_SUCCESS;
  5074. unsigned long iflag;
  5075. uint32_t db_ready;
  5076. uint32_t mcqe_status;
  5077. uint32_t mbx_cmnd;
  5078. unsigned long timeout;
  5079. struct lpfc_sli *psli = &phba->sli;
  5080. struct lpfc_mqe *mb = &mboxq->u.mqe;
  5081. struct lpfc_bmbx_create *mbox_rgn;
  5082. struct dma_address *dma_address;
  5083. struct lpfc_register bmbx_reg;
  5084. /*
  5085. * Only one mailbox can be active to the bootstrap mailbox region
  5086. * at a time and there is no queueing provided.
  5087. */
  5088. spin_lock_irqsave(&phba->hbalock, iflag);
  5089. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5090. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5091. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5092. "(%d):2532 Mailbox command x%x (x%x) "
  5093. "cannot issue Data: x%x x%x\n",
  5094. mboxq->vport ? mboxq->vport->vpi : 0,
  5095. mboxq->u.mb.mbxCommand,
  5096. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5097. psli->sli_flag, MBX_POLL);
  5098. return MBXERR_ERROR;
  5099. }
  5100. /* The server grabs the token and owns it until release */
  5101. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5102. phba->sli.mbox_active = mboxq;
  5103. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5104. /*
  5105. * Initialize the bootstrap memory region to avoid stale data areas
  5106. * in the mailbox post. Then copy the caller's mailbox contents to
  5107. * the bmbx mailbox region.
  5108. */
  5109. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  5110. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  5111. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  5112. sizeof(struct lpfc_mqe));
  5113. /* Post the high mailbox dma address to the port and wait for ready. */
  5114. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5115. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  5116. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5117. * 1000) + jiffies;
  5118. do {
  5119. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5120. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5121. if (!db_ready)
  5122. msleep(2);
  5123. if (time_after(jiffies, timeout)) {
  5124. rc = MBXERR_ERROR;
  5125. goto exit;
  5126. }
  5127. } while (!db_ready);
  5128. /* Post the low mailbox dma address to the port. */
  5129. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  5130. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5131. * 1000) + jiffies;
  5132. do {
  5133. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5134. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5135. if (!db_ready)
  5136. msleep(2);
  5137. if (time_after(jiffies, timeout)) {
  5138. rc = MBXERR_ERROR;
  5139. goto exit;
  5140. }
  5141. } while (!db_ready);
  5142. /*
  5143. * Read the CQ to ensure the mailbox has completed.
  5144. * If so, update the mailbox status so that the upper layers
  5145. * can complete the request normally.
  5146. */
  5147. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  5148. sizeof(struct lpfc_mqe));
  5149. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  5150. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  5151. sizeof(struct lpfc_mcqe));
  5152. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  5153. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  5154. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  5155. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  5156. rc = MBXERR_ERROR;
  5157. } else
  5158. lpfc_sli4_swap_str(phba, mboxq);
  5159. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5160. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  5161. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  5162. " x%x x%x CQ: x%x x%x x%x x%x\n",
  5163. mboxq->vport ? mboxq->vport->vpi : 0,
  5164. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5165. bf_get(lpfc_mqe_status, mb),
  5166. mb->un.mb_words[0], mb->un.mb_words[1],
  5167. mb->un.mb_words[2], mb->un.mb_words[3],
  5168. mb->un.mb_words[4], mb->un.mb_words[5],
  5169. mb->un.mb_words[6], mb->un.mb_words[7],
  5170. mb->un.mb_words[8], mb->un.mb_words[9],
  5171. mb->un.mb_words[10], mb->un.mb_words[11],
  5172. mb->un.mb_words[12], mboxq->mcqe.word0,
  5173. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  5174. mboxq->mcqe.trailer);
  5175. exit:
  5176. /* We are holding the token, no needed for lock when release */
  5177. spin_lock_irqsave(&phba->hbalock, iflag);
  5178. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5179. phba->sli.mbox_active = NULL;
  5180. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5181. return rc;
  5182. }
  5183. /**
  5184. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  5185. * @phba: Pointer to HBA context object.
  5186. * @pmbox: Pointer to mailbox object.
  5187. * @flag: Flag indicating how the mailbox need to be processed.
  5188. *
  5189. * This function is called by discovery code and HBA management code to submit
  5190. * a mailbox command to firmware with SLI-4 interface spec.
  5191. *
  5192. * Return codes the caller owns the mailbox command after the return of the
  5193. * function.
  5194. **/
  5195. static int
  5196. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  5197. uint32_t flag)
  5198. {
  5199. struct lpfc_sli *psli = &phba->sli;
  5200. unsigned long iflags;
  5201. int rc;
  5202. rc = lpfc_mbox_dev_check(phba);
  5203. if (unlikely(rc)) {
  5204. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5205. "(%d):2544 Mailbox command x%x (x%x) "
  5206. "cannot issue Data: x%x x%x\n",
  5207. mboxq->vport ? mboxq->vport->vpi : 0,
  5208. mboxq->u.mb.mbxCommand,
  5209. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5210. psli->sli_flag, flag);
  5211. goto out_not_finished;
  5212. }
  5213. /* Detect polling mode and jump to a handler */
  5214. if (!phba->sli4_hba.intr_enable) {
  5215. if (flag == MBX_POLL)
  5216. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5217. else
  5218. rc = -EIO;
  5219. if (rc != MBX_SUCCESS)
  5220. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5221. "(%d):2541 Mailbox command x%x "
  5222. "(x%x) cannot issue Data: x%x x%x\n",
  5223. mboxq->vport ? mboxq->vport->vpi : 0,
  5224. mboxq->u.mb.mbxCommand,
  5225. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5226. psli->sli_flag, flag);
  5227. return rc;
  5228. } else if (flag == MBX_POLL) {
  5229. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5230. "(%d):2542 Try to issue mailbox command "
  5231. "x%x (x%x) synchronously ahead of async"
  5232. "mailbox command queue: x%x x%x\n",
  5233. mboxq->vport ? mboxq->vport->vpi : 0,
  5234. mboxq->u.mb.mbxCommand,
  5235. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5236. psli->sli_flag, flag);
  5237. /* Try to block the asynchronous mailbox posting */
  5238. rc = lpfc_sli4_async_mbox_block(phba);
  5239. if (!rc) {
  5240. /* Successfully blocked, now issue sync mbox cmd */
  5241. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5242. if (rc != MBX_SUCCESS)
  5243. lpfc_printf_log(phba, KERN_ERR,
  5244. LOG_MBOX | LOG_SLI,
  5245. "(%d):2597 Mailbox command "
  5246. "x%x (x%x) cannot issue "
  5247. "Data: x%x x%x\n",
  5248. mboxq->vport ?
  5249. mboxq->vport->vpi : 0,
  5250. mboxq->u.mb.mbxCommand,
  5251. lpfc_sli4_mbox_opcode_get(phba,
  5252. mboxq),
  5253. psli->sli_flag, flag);
  5254. /* Unblock the async mailbox posting afterward */
  5255. lpfc_sli4_async_mbox_unblock(phba);
  5256. }
  5257. return rc;
  5258. }
  5259. /* Now, interrupt mode asynchrous mailbox command */
  5260. rc = lpfc_mbox_cmd_check(phba, mboxq);
  5261. if (rc) {
  5262. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5263. "(%d):2543 Mailbox command x%x (x%x) "
  5264. "cannot issue Data: x%x x%x\n",
  5265. mboxq->vport ? mboxq->vport->vpi : 0,
  5266. mboxq->u.mb.mbxCommand,
  5267. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5268. psli->sli_flag, flag);
  5269. goto out_not_finished;
  5270. }
  5271. /* Put the mailbox command to the driver internal FIFO */
  5272. psli->slistat.mbox_busy++;
  5273. spin_lock_irqsave(&phba->hbalock, iflags);
  5274. lpfc_mbox_put(phba, mboxq);
  5275. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5276. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5277. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  5278. "x%x (x%x) x%x x%x x%x\n",
  5279. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  5280. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  5281. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5282. phba->pport->port_state,
  5283. psli->sli_flag, MBX_NOWAIT);
  5284. /* Wake up worker thread to transport mailbox command from head */
  5285. lpfc_worker_wake_up(phba);
  5286. return MBX_BUSY;
  5287. out_not_finished:
  5288. return MBX_NOT_FINISHED;
  5289. }
  5290. /**
  5291. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  5292. * @phba: Pointer to HBA context object.
  5293. *
  5294. * This function is called by worker thread to send a mailbox command to
  5295. * SLI4 HBA firmware.
  5296. *
  5297. **/
  5298. int
  5299. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  5300. {
  5301. struct lpfc_sli *psli = &phba->sli;
  5302. LPFC_MBOXQ_t *mboxq;
  5303. int rc = MBX_SUCCESS;
  5304. unsigned long iflags;
  5305. struct lpfc_mqe *mqe;
  5306. uint32_t mbx_cmnd;
  5307. /* Check interrupt mode before post async mailbox command */
  5308. if (unlikely(!phba->sli4_hba.intr_enable))
  5309. return MBX_NOT_FINISHED;
  5310. /* Check for mailbox command service token */
  5311. spin_lock_irqsave(&phba->hbalock, iflags);
  5312. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5313. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5314. return MBX_NOT_FINISHED;
  5315. }
  5316. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5317. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5318. return MBX_NOT_FINISHED;
  5319. }
  5320. if (unlikely(phba->sli.mbox_active)) {
  5321. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5322. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5323. "0384 There is pending active mailbox cmd\n");
  5324. return MBX_NOT_FINISHED;
  5325. }
  5326. /* Take the mailbox command service token */
  5327. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5328. /* Get the next mailbox command from head of queue */
  5329. mboxq = lpfc_mbox_get(phba);
  5330. /* If no more mailbox command waiting for post, we're done */
  5331. if (!mboxq) {
  5332. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5333. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5334. return MBX_SUCCESS;
  5335. }
  5336. phba->sli.mbox_active = mboxq;
  5337. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5338. /* Check device readiness for posting mailbox command */
  5339. rc = lpfc_mbox_dev_check(phba);
  5340. if (unlikely(rc))
  5341. /* Driver clean routine will clean up pending mailbox */
  5342. goto out_not_finished;
  5343. /* Prepare the mbox command to be posted */
  5344. mqe = &mboxq->u.mqe;
  5345. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  5346. /* Start timer for the mbox_tmo and log some mailbox post messages */
  5347. mod_timer(&psli->mbox_tmo, (jiffies +
  5348. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  5349. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5350. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  5351. "x%x x%x\n",
  5352. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  5353. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5354. phba->pport->port_state, psli->sli_flag);
  5355. if (mbx_cmnd != MBX_HEARTBEAT) {
  5356. if (mboxq->vport) {
  5357. lpfc_debugfs_disc_trc(mboxq->vport,
  5358. LPFC_DISC_TRC_MBOX_VPORT,
  5359. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5360. mbx_cmnd, mqe->un.mb_words[0],
  5361. mqe->un.mb_words[1]);
  5362. } else {
  5363. lpfc_debugfs_disc_trc(phba->pport,
  5364. LPFC_DISC_TRC_MBOX,
  5365. "MBOX Send: cmd:x%x mb:x%x x%x",
  5366. mbx_cmnd, mqe->un.mb_words[0],
  5367. mqe->un.mb_words[1]);
  5368. }
  5369. }
  5370. psli->slistat.mbox_cmd++;
  5371. /* Post the mailbox command to the port */
  5372. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5373. if (rc != MBX_SUCCESS) {
  5374. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5375. "(%d):2533 Mailbox command x%x (x%x) "
  5376. "cannot issue Data: x%x x%x\n",
  5377. mboxq->vport ? mboxq->vport->vpi : 0,
  5378. mboxq->u.mb.mbxCommand,
  5379. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5380. psli->sli_flag, MBX_NOWAIT);
  5381. goto out_not_finished;
  5382. }
  5383. return rc;
  5384. out_not_finished:
  5385. spin_lock_irqsave(&phba->hbalock, iflags);
  5386. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5387. __lpfc_mbox_cmpl_put(phba, mboxq);
  5388. /* Release the token */
  5389. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5390. phba->sli.mbox_active = NULL;
  5391. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5392. return MBX_NOT_FINISHED;
  5393. }
  5394. /**
  5395. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5396. * @phba: Pointer to HBA context object.
  5397. * @pmbox: Pointer to mailbox object.
  5398. * @flag: Flag indicating how the mailbox need to be processed.
  5399. *
  5400. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5401. * the API jump table function pointer from the lpfc_hba struct.
  5402. *
  5403. * Return codes the caller owns the mailbox command after the return of the
  5404. * function.
  5405. **/
  5406. int
  5407. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5408. {
  5409. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5410. }
  5411. /**
  5412. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5413. * @phba: The hba struct for which this call is being executed.
  5414. * @dev_grp: The HBA PCI-Device group number.
  5415. *
  5416. * This routine sets up the mbox interface API function jump table in @phba
  5417. * struct.
  5418. * Returns: 0 - success, -ENODEV - failure.
  5419. **/
  5420. int
  5421. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5422. {
  5423. switch (dev_grp) {
  5424. case LPFC_PCI_DEV_LP:
  5425. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5426. phba->lpfc_sli_handle_slow_ring_event =
  5427. lpfc_sli_handle_slow_ring_event_s3;
  5428. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5429. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5430. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5431. break;
  5432. case LPFC_PCI_DEV_OC:
  5433. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5434. phba->lpfc_sli_handle_slow_ring_event =
  5435. lpfc_sli_handle_slow_ring_event_s4;
  5436. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5437. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5438. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5439. break;
  5440. default:
  5441. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5442. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5443. dev_grp);
  5444. return -ENODEV;
  5445. break;
  5446. }
  5447. return 0;
  5448. }
  5449. /**
  5450. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5451. * @phba: Pointer to HBA context object.
  5452. * @pring: Pointer to driver SLI ring object.
  5453. * @piocb: Pointer to address of newly added command iocb.
  5454. *
  5455. * This function is called with hbalock held to add a command
  5456. * iocb to the txq when SLI layer cannot submit the command iocb
  5457. * to the ring.
  5458. **/
  5459. void
  5460. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5461. struct lpfc_iocbq *piocb)
  5462. {
  5463. /* Insert the caller's iocb in the txq tail for later processing. */
  5464. list_add_tail(&piocb->list, &pring->txq);
  5465. pring->txq_cnt++;
  5466. }
  5467. /**
  5468. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5469. * @phba: Pointer to HBA context object.
  5470. * @pring: Pointer to driver SLI ring object.
  5471. * @piocb: Pointer to address of newly added command iocb.
  5472. *
  5473. * This function is called with hbalock held before a new
  5474. * iocb is submitted to the firmware. This function checks
  5475. * txq to flush the iocbs in txq to Firmware before
  5476. * submitting new iocbs to the Firmware.
  5477. * If there are iocbs in the txq which need to be submitted
  5478. * to firmware, lpfc_sli_next_iocb returns the first element
  5479. * of the txq after dequeuing it from txq.
  5480. * If there is no iocb in the txq then the function will return
  5481. * *piocb and *piocb is set to NULL. Caller needs to check
  5482. * *piocb to find if there are more commands in the txq.
  5483. **/
  5484. static struct lpfc_iocbq *
  5485. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5486. struct lpfc_iocbq **piocb)
  5487. {
  5488. struct lpfc_iocbq * nextiocb;
  5489. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5490. if (!nextiocb) {
  5491. nextiocb = *piocb;
  5492. *piocb = NULL;
  5493. }
  5494. return nextiocb;
  5495. }
  5496. /**
  5497. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5498. * @phba: Pointer to HBA context object.
  5499. * @ring_number: SLI ring number to issue iocb on.
  5500. * @piocb: Pointer to command iocb.
  5501. * @flag: Flag indicating if this command can be put into txq.
  5502. *
  5503. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5504. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5505. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5506. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5507. * this function allows only iocbs for posting buffers. This function finds
  5508. * next available slot in the command ring and posts the command to the
  5509. * available slot and writes the port attention register to request HBA start
  5510. * processing new iocb. If there is no slot available in the ring and
  5511. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5512. * the function returns IOCB_BUSY.
  5513. *
  5514. * This function is called with hbalock held. The function will return success
  5515. * after it successfully submit the iocb to firmware or after adding to the
  5516. * txq.
  5517. **/
  5518. static int
  5519. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5520. struct lpfc_iocbq *piocb, uint32_t flag)
  5521. {
  5522. struct lpfc_iocbq *nextiocb;
  5523. IOCB_t *iocb;
  5524. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5525. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5526. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5527. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5528. lpfc_printf_log(phba, KERN_ERR,
  5529. LOG_SLI | LOG_VPORT,
  5530. "1807 IOCB x%x failed. No vport\n",
  5531. piocb->iocb.ulpCommand);
  5532. dump_stack();
  5533. return IOCB_ERROR;
  5534. }
  5535. /* If the PCI channel is in offline state, do not post iocbs. */
  5536. if (unlikely(pci_channel_offline(phba->pcidev)))
  5537. return IOCB_ERROR;
  5538. /* If HBA has a deferred error attention, fail the iocb. */
  5539. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5540. return IOCB_ERROR;
  5541. /*
  5542. * We should never get an IOCB if we are in a < LINK_DOWN state
  5543. */
  5544. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5545. return IOCB_ERROR;
  5546. /*
  5547. * Check to see if we are blocking IOCB processing because of a
  5548. * outstanding event.
  5549. */
  5550. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5551. goto iocb_busy;
  5552. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5553. /*
  5554. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5555. * can be issued if the link is not up.
  5556. */
  5557. switch (piocb->iocb.ulpCommand) {
  5558. case CMD_GEN_REQUEST64_CR:
  5559. case CMD_GEN_REQUEST64_CX:
  5560. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5561. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5562. FC_RCTL_DD_UNSOL_CMD) ||
  5563. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5564. MENLO_TRANSPORT_TYPE))
  5565. goto iocb_busy;
  5566. break;
  5567. case CMD_QUE_RING_BUF_CN:
  5568. case CMD_QUE_RING_BUF64_CN:
  5569. /*
  5570. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5571. * completion, iocb_cmpl MUST be 0.
  5572. */
  5573. if (piocb->iocb_cmpl)
  5574. piocb->iocb_cmpl = NULL;
  5575. /*FALLTHROUGH*/
  5576. case CMD_CREATE_XRI_CR:
  5577. case CMD_CLOSE_XRI_CN:
  5578. case CMD_CLOSE_XRI_CX:
  5579. break;
  5580. default:
  5581. goto iocb_busy;
  5582. }
  5583. /*
  5584. * For FCP commands, we must be in a state where we can process link
  5585. * attention events.
  5586. */
  5587. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5588. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5589. goto iocb_busy;
  5590. }
  5591. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5592. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5593. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5594. if (iocb)
  5595. lpfc_sli_update_ring(phba, pring);
  5596. else
  5597. lpfc_sli_update_full_ring(phba, pring);
  5598. if (!piocb)
  5599. return IOCB_SUCCESS;
  5600. goto out_busy;
  5601. iocb_busy:
  5602. pring->stats.iocb_cmd_delay++;
  5603. out_busy:
  5604. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5605. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5606. return IOCB_SUCCESS;
  5607. }
  5608. return IOCB_BUSY;
  5609. }
  5610. /**
  5611. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5612. * @phba: Pointer to HBA context object.
  5613. * @piocb: Pointer to command iocb.
  5614. * @sglq: Pointer to the scatter gather queue object.
  5615. *
  5616. * This routine converts the bpl or bde that is in the IOCB
  5617. * to a sgl list for the sli4 hardware. The physical address
  5618. * of the bpl/bde is converted back to a virtual address.
  5619. * If the IOCB contains a BPL then the list of BDE's is
  5620. * converted to sli4_sge's. If the IOCB contains a single
  5621. * BDE then it is converted to a single sli_sge.
  5622. * The IOCB is still in cpu endianess so the contents of
  5623. * the bpl can be used without byte swapping.
  5624. *
  5625. * Returns valid XRI = Success, NO_XRI = Failure.
  5626. **/
  5627. static uint16_t
  5628. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5629. struct lpfc_sglq *sglq)
  5630. {
  5631. uint16_t xritag = NO_XRI;
  5632. struct ulp_bde64 *bpl = NULL;
  5633. struct ulp_bde64 bde;
  5634. struct sli4_sge *sgl = NULL;
  5635. IOCB_t *icmd;
  5636. int numBdes = 0;
  5637. int i = 0;
  5638. uint32_t offset = 0; /* accumulated offset in the sg request list */
  5639. int inbound = 0; /* number of sg reply entries inbound from firmware */
  5640. if (!piocbq || !sglq)
  5641. return xritag;
  5642. sgl = (struct sli4_sge *)sglq->sgl;
  5643. icmd = &piocbq->iocb;
  5644. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5645. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5646. sizeof(struct ulp_bde64);
  5647. /* The addrHigh and addrLow fields within the IOCB
  5648. * have not been byteswapped yet so there is no
  5649. * need to swap them back.
  5650. */
  5651. bpl = (struct ulp_bde64 *)
  5652. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5653. if (!bpl)
  5654. return xritag;
  5655. for (i = 0; i < numBdes; i++) {
  5656. /* Should already be byte swapped. */
  5657. sgl->addr_hi = bpl->addrHigh;
  5658. sgl->addr_lo = bpl->addrLow;
  5659. if ((i+1) == numBdes)
  5660. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5661. else
  5662. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5663. sgl->word2 = cpu_to_le32(sgl->word2);
  5664. /* swap the size field back to the cpu so we
  5665. * can assign it to the sgl.
  5666. */
  5667. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5668. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5669. /* The offsets in the sgl need to be accumulated
  5670. * separately for the request and reply lists.
  5671. * The request is always first, the reply follows.
  5672. */
  5673. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  5674. /* add up the reply sg entries */
  5675. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  5676. inbound++;
  5677. /* first inbound? reset the offset */
  5678. if (inbound == 1)
  5679. offset = 0;
  5680. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  5681. offset += bde.tus.f.bdeSize;
  5682. }
  5683. bpl++;
  5684. sgl++;
  5685. }
  5686. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5687. /* The addrHigh and addrLow fields of the BDE have not
  5688. * been byteswapped yet so they need to be swapped
  5689. * before putting them in the sgl.
  5690. */
  5691. sgl->addr_hi =
  5692. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5693. sgl->addr_lo =
  5694. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5695. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5696. sgl->word2 = cpu_to_le32(sgl->word2);
  5697. sgl->sge_len =
  5698. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5699. }
  5700. return sglq->sli4_xritag;
  5701. }
  5702. /**
  5703. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5704. * @phba: Pointer to HBA context object.
  5705. *
  5706. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  5707. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5708. * held.
  5709. *
  5710. * Return: index into SLI4 fast-path FCP queue index.
  5711. **/
  5712. static uint32_t
  5713. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5714. {
  5715. ++phba->fcp_qidx;
  5716. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5717. phba->fcp_qidx = 0;
  5718. return phba->fcp_qidx;
  5719. }
  5720. /**
  5721. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5722. * @phba: Pointer to HBA context object.
  5723. * @piocb: Pointer to command iocb.
  5724. * @wqe: Pointer to the work queue entry.
  5725. *
  5726. * This routine converts the iocb command to its Work Queue Entry
  5727. * equivalent. The wqe pointer should not have any fields set when
  5728. * this routine is called because it will memcpy over them.
  5729. * This routine does not set the CQ_ID or the WQEC bits in the
  5730. * wqe.
  5731. *
  5732. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5733. **/
  5734. static int
  5735. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5736. union lpfc_wqe *wqe)
  5737. {
  5738. uint32_t xmit_len = 0, total_len = 0;
  5739. uint8_t ct = 0;
  5740. uint32_t fip;
  5741. uint32_t abort_tag;
  5742. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5743. uint8_t cmnd;
  5744. uint16_t xritag;
  5745. uint16_t abrt_iotag;
  5746. struct lpfc_iocbq *abrtiocbq;
  5747. struct ulp_bde64 *bpl = NULL;
  5748. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  5749. int numBdes, i;
  5750. struct ulp_bde64 bde;
  5751. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5752. /* The fcp commands will set command type */
  5753. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5754. command_type = FCP_COMMAND;
  5755. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5756. command_type = ELS_COMMAND_FIP;
  5757. else
  5758. command_type = ELS_COMMAND_NON_FIP;
  5759. /* Some of the fields are in the right position already */
  5760. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5761. abort_tag = (uint32_t) iocbq->iotag;
  5762. xritag = iocbq->sli4_xritag;
  5763. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  5764. /* words0-2 bpl convert bde */
  5765. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5766. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5767. sizeof(struct ulp_bde64);
  5768. bpl = (struct ulp_bde64 *)
  5769. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5770. if (!bpl)
  5771. return IOCB_ERROR;
  5772. /* Should already be byte swapped. */
  5773. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5774. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5775. /* swap the size field back to the cpu so we
  5776. * can assign it to the sgl.
  5777. */
  5778. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5779. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5780. total_len = 0;
  5781. for (i = 0; i < numBdes; i++) {
  5782. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5783. total_len += bde.tus.f.bdeSize;
  5784. }
  5785. } else
  5786. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5787. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5788. cmnd = iocbq->iocb.ulpCommand;
  5789. switch (iocbq->iocb.ulpCommand) {
  5790. case CMD_ELS_REQUEST64_CR:
  5791. if (!iocbq->iocb.ulpLe) {
  5792. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5793. "2007 Only Limited Edition cmd Format"
  5794. " supported 0x%x\n",
  5795. iocbq->iocb.ulpCommand);
  5796. return IOCB_ERROR;
  5797. }
  5798. wqe->els_req.payload_len = xmit_len;
  5799. /* Els_reguest64 has a TMO */
  5800. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5801. iocbq->iocb.ulpTimeout);
  5802. /* Need a VF for word 4 set the vf bit*/
  5803. bf_set(els_req64_vf, &wqe->els_req, 0);
  5804. /* And a VFID for word 12 */
  5805. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5806. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5807. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  5808. iocbq->iocb.ulpContext);
  5809. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  5810. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  5811. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5812. if (command_type == ELS_COMMAND_FIP) {
  5813. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5814. >> LPFC_FIP_ELS_ID_SHIFT);
  5815. }
  5816. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  5817. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  5818. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  5819. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  5820. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5821. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  5822. break;
  5823. case CMD_XMIT_SEQUENCE64_CX:
  5824. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  5825. iocbq->iocb.un.ulpWord[3]);
  5826. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  5827. iocbq->iocb.ulpContext);
  5828. /* The entire sequence is transmitted for this IOCB */
  5829. xmit_len = total_len;
  5830. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5831. case CMD_XMIT_SEQUENCE64_CR:
  5832. /* word3 iocb=io_tag32 wqe=reserved */
  5833. wqe->xmit_sequence.rsvd3 = 0;
  5834. /* word4 relative_offset memcpy */
  5835. /* word5 r_ctl/df_ctl memcpy */
  5836. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  5837. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  5838. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  5839. LPFC_WQE_IOD_WRITE);
  5840. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  5841. LPFC_WQE_LENLOC_WORD12);
  5842. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  5843. wqe->xmit_sequence.xmit_len = xmit_len;
  5844. command_type = OTHER_COMMAND;
  5845. break;
  5846. case CMD_XMIT_BCAST64_CN:
  5847. /* word3 iocb=iotag32 wqe=seq_payload_len */
  5848. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  5849. /* word4 iocb=rsvd wqe=rsvd */
  5850. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5851. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5852. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  5853. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5854. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  5855. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  5856. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  5857. LPFC_WQE_LENLOC_WORD3);
  5858. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  5859. break;
  5860. case CMD_FCP_IWRITE64_CR:
  5861. command_type = FCP_COMMAND_DATA_OUT;
  5862. /* word3 iocb=iotag wqe=payload_offset_len */
  5863. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5864. wqe->fcp_iwrite.payload_offset_len =
  5865. xmit_len + sizeof(struct fcp_rsp);
  5866. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5867. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5868. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  5869. iocbq->iocb.ulpFCP2Rcvy);
  5870. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  5871. /* Always open the exchange */
  5872. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  5873. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  5874. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  5875. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  5876. LPFC_WQE_LENLOC_WORD4);
  5877. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  5878. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  5879. break;
  5880. case CMD_FCP_IREAD64_CR:
  5881. /* word3 iocb=iotag wqe=payload_offset_len */
  5882. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5883. wqe->fcp_iread.payload_offset_len =
  5884. xmit_len + sizeof(struct fcp_rsp);
  5885. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5886. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5887. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  5888. iocbq->iocb.ulpFCP2Rcvy);
  5889. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  5890. /* Always open the exchange */
  5891. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5892. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  5893. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  5894. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  5895. LPFC_WQE_LENLOC_WORD4);
  5896. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  5897. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  5898. break;
  5899. case CMD_FCP_ICMND64_CR:
  5900. /* word3 iocb=IO_TAG wqe=reserved */
  5901. wqe->fcp_icmd.rsrvd3 = 0;
  5902. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  5903. /* Always open the exchange */
  5904. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  5905. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  5906. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  5907. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  5908. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  5909. LPFC_WQE_LENLOC_NONE);
  5910. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  5911. break;
  5912. case CMD_GEN_REQUEST64_CR:
  5913. /* For this command calculate the xmit length of the
  5914. * request bde.
  5915. */
  5916. xmit_len = 0;
  5917. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5918. sizeof(struct ulp_bde64);
  5919. for (i = 0; i < numBdes; i++) {
  5920. if (bpl[i].tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  5921. break;
  5922. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5923. xmit_len += bde.tus.f.bdeSize;
  5924. }
  5925. /* word3 iocb=IO_TAG wqe=request_payload_len */
  5926. wqe->gen_req.request_payload_len = xmit_len;
  5927. /* word4 iocb=parameter wqe=relative_offset memcpy */
  5928. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  5929. /* word6 context tag copied in memcpy */
  5930. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5931. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5932. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5933. "2015 Invalid CT %x command 0x%x\n",
  5934. ct, iocbq->iocb.ulpCommand);
  5935. return IOCB_ERROR;
  5936. }
  5937. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  5938. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  5939. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  5940. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  5941. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  5942. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  5943. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5944. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  5945. command_type = OTHER_COMMAND;
  5946. break;
  5947. case CMD_XMIT_ELS_RSP64_CX:
  5948. /* words0-2 BDE memcpy */
  5949. /* word3 iocb=iotag32 wqe=response_payload_len */
  5950. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  5951. /* word4 iocb=did wge=rsvd. */
  5952. wqe->xmit_els_rsp.rsvd4 = 0;
  5953. /* word5 iocb=rsvd wge=did */
  5954. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5955. iocbq->iocb.un.elsreq64.remoteID);
  5956. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  5957. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5958. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  5959. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5960. iocbq->iocb.ulpContext);
  5961. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5962. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  5963. iocbq->vport->vpi + phba->vpi_base);
  5964. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  5965. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  5966. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  5967. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  5968. LPFC_WQE_LENLOC_WORD3);
  5969. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  5970. command_type = OTHER_COMMAND;
  5971. break;
  5972. case CMD_CLOSE_XRI_CN:
  5973. case CMD_ABORT_XRI_CN:
  5974. case CMD_ABORT_XRI_CX:
  5975. /* words 0-2 memcpy should be 0 rserved */
  5976. /* port will send abts */
  5977. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  5978. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  5979. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  5980. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  5981. } else
  5982. fip = 0;
  5983. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  5984. /*
  5985. * The link is down, or the command was ELS_FIP
  5986. * so the fw does not need to send abts
  5987. * on the wire.
  5988. */
  5989. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5990. else
  5991. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5992. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5993. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  5994. wqe->abort_cmd.rsrvd5 = 0;
  5995. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  5996. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5997. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5998. /*
  5999. * The abort handler will send us CMD_ABORT_XRI_CN or
  6000. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  6001. */
  6002. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  6003. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  6004. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  6005. LPFC_WQE_LENLOC_NONE);
  6006. cmnd = CMD_ABORT_XRI_CX;
  6007. command_type = OTHER_COMMAND;
  6008. xritag = 0;
  6009. break;
  6010. case CMD_XMIT_BLS_RSP64_CX:
  6011. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  6012. * we re-construct this WQE here based on information in
  6013. * iocbq from scratch.
  6014. */
  6015. memset(wqe, 0, sizeof(union lpfc_wqe));
  6016. /* OX_ID is invariable to who sent ABTS to CT exchange */
  6017. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  6018. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  6019. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  6020. LPFC_ABTS_UNSOL_INT) {
  6021. /* ABTS sent by initiator to CT exchange, the
  6022. * RX_ID field will be filled with the newly
  6023. * allocated responder XRI.
  6024. */
  6025. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6026. iocbq->sli4_xritag);
  6027. } else {
  6028. /* ABTS sent by responder to CT exchange, the
  6029. * RX_ID field will be filled with the responder
  6030. * RX_ID from ABTS.
  6031. */
  6032. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6033. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  6034. }
  6035. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  6036. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  6037. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  6038. iocbq->iocb.ulpContext);
  6039. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  6040. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  6041. LPFC_WQE_LENLOC_NONE);
  6042. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  6043. command_type = OTHER_COMMAND;
  6044. break;
  6045. case CMD_XRI_ABORTED_CX:
  6046. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  6047. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  6048. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  6049. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  6050. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  6051. default:
  6052. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6053. "2014 Invalid command 0x%x\n",
  6054. iocbq->iocb.ulpCommand);
  6055. return IOCB_ERROR;
  6056. break;
  6057. }
  6058. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  6059. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  6060. wqe->generic.wqe_com.abort_tag = abort_tag;
  6061. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  6062. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  6063. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  6064. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  6065. return 0;
  6066. }
  6067. /**
  6068. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  6069. * @phba: Pointer to HBA context object.
  6070. * @ring_number: SLI ring number to issue iocb on.
  6071. * @piocb: Pointer to command iocb.
  6072. * @flag: Flag indicating if this command can be put into txq.
  6073. *
  6074. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  6075. * an iocb command to an HBA with SLI-4 interface spec.
  6076. *
  6077. * This function is called with hbalock held. The function will return success
  6078. * after it successfully submit the iocb to firmware or after adding to the
  6079. * txq.
  6080. **/
  6081. static int
  6082. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  6083. struct lpfc_iocbq *piocb, uint32_t flag)
  6084. {
  6085. struct lpfc_sglq *sglq;
  6086. union lpfc_wqe wqe;
  6087. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6088. if (piocb->sli4_xritag == NO_XRI) {
  6089. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  6090. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  6091. sglq = NULL;
  6092. else {
  6093. if (pring->txq_cnt) {
  6094. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6095. __lpfc_sli_ringtx_put(phba,
  6096. pring, piocb);
  6097. return IOCB_SUCCESS;
  6098. } else {
  6099. return IOCB_BUSY;
  6100. }
  6101. } else {
  6102. sglq = __lpfc_sli_get_sglq(phba, piocb);
  6103. if (!sglq) {
  6104. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6105. __lpfc_sli_ringtx_put(phba,
  6106. pring,
  6107. piocb);
  6108. return IOCB_SUCCESS;
  6109. } else
  6110. return IOCB_BUSY;
  6111. }
  6112. }
  6113. }
  6114. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  6115. sglq = NULL; /* These IO's already have an XRI and
  6116. * a mapped sgl.
  6117. */
  6118. } else {
  6119. /* This is a continuation of a commandi,(CX) so this
  6120. * sglq is on the active list
  6121. */
  6122. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  6123. if (!sglq)
  6124. return IOCB_ERROR;
  6125. }
  6126. if (sglq) {
  6127. piocb->sli4_xritag = sglq->sli4_xritag;
  6128. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  6129. return IOCB_ERROR;
  6130. }
  6131. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  6132. return IOCB_ERROR;
  6133. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  6134. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  6135. /*
  6136. * For FCP command IOCB, get a new WQ index to distribute
  6137. * WQE across the WQsr. On the other hand, for abort IOCB,
  6138. * it carries the same WQ index to the original command
  6139. * IOCB.
  6140. */
  6141. if (piocb->iocb_flag & LPFC_IO_FCP)
  6142. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  6143. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  6144. &wqe))
  6145. return IOCB_ERROR;
  6146. } else {
  6147. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  6148. return IOCB_ERROR;
  6149. }
  6150. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  6151. return 0;
  6152. }
  6153. /**
  6154. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  6155. *
  6156. * This routine wraps the actual lockless version for issusing IOCB function
  6157. * pointer from the lpfc_hba struct.
  6158. *
  6159. * Return codes:
  6160. * IOCB_ERROR - Error
  6161. * IOCB_SUCCESS - Success
  6162. * IOCB_BUSY - Busy
  6163. **/
  6164. int
  6165. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6166. struct lpfc_iocbq *piocb, uint32_t flag)
  6167. {
  6168. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6169. }
  6170. /**
  6171. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  6172. * @phba: The hba struct for which this call is being executed.
  6173. * @dev_grp: The HBA PCI-Device group number.
  6174. *
  6175. * This routine sets up the SLI interface API function jump table in @phba
  6176. * struct.
  6177. * Returns: 0 - success, -ENODEV - failure.
  6178. **/
  6179. int
  6180. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6181. {
  6182. switch (dev_grp) {
  6183. case LPFC_PCI_DEV_LP:
  6184. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  6185. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  6186. break;
  6187. case LPFC_PCI_DEV_OC:
  6188. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  6189. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  6190. break;
  6191. default:
  6192. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6193. "1419 Invalid HBA PCI-device group: 0x%x\n",
  6194. dev_grp);
  6195. return -ENODEV;
  6196. break;
  6197. }
  6198. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  6199. return 0;
  6200. }
  6201. /**
  6202. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  6203. * @phba: Pointer to HBA context object.
  6204. * @pring: Pointer to driver SLI ring object.
  6205. * @piocb: Pointer to command iocb.
  6206. * @flag: Flag indicating if this command can be put into txq.
  6207. *
  6208. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  6209. * function. This function gets the hbalock and calls
  6210. * __lpfc_sli_issue_iocb function and will return the error returned
  6211. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  6212. * functions which do not hold hbalock.
  6213. **/
  6214. int
  6215. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6216. struct lpfc_iocbq *piocb, uint32_t flag)
  6217. {
  6218. unsigned long iflags;
  6219. int rc;
  6220. spin_lock_irqsave(&phba->hbalock, iflags);
  6221. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6222. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6223. return rc;
  6224. }
  6225. /**
  6226. * lpfc_extra_ring_setup - Extra ring setup function
  6227. * @phba: Pointer to HBA context object.
  6228. *
  6229. * This function is called while driver attaches with the
  6230. * HBA to setup the extra ring. The extra ring is used
  6231. * only when driver needs to support target mode functionality
  6232. * or IP over FC functionalities.
  6233. *
  6234. * This function is called with no lock held.
  6235. **/
  6236. static int
  6237. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  6238. {
  6239. struct lpfc_sli *psli;
  6240. struct lpfc_sli_ring *pring;
  6241. psli = &phba->sli;
  6242. /* Adjust cmd/rsp ring iocb entries more evenly */
  6243. /* Take some away from the FCP ring */
  6244. pring = &psli->ring[psli->fcp_ring];
  6245. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6246. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6247. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6248. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6249. /* and give them to the extra ring */
  6250. pring = &psli->ring[psli->extra_ring];
  6251. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6252. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6253. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6254. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6255. /* Setup default profile for this ring */
  6256. pring->iotag_max = 4096;
  6257. pring->num_mask = 1;
  6258. pring->prt[0].profile = 0; /* Mask 0 */
  6259. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  6260. pring->prt[0].type = phba->cfg_multi_ring_type;
  6261. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  6262. return 0;
  6263. }
  6264. /**
  6265. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  6266. * @phba: Pointer to HBA context object.
  6267. * @pring: Pointer to driver SLI ring object.
  6268. * @iocbq: Pointer to iocb object.
  6269. *
  6270. * This function is called by the slow ring event handler
  6271. * function when there is an ASYNC event iocb in the ring.
  6272. * This function is called with no lock held.
  6273. * Currently this function handles only temperature related
  6274. * ASYNC events. The function decodes the temperature sensor
  6275. * event message and posts events for the management applications.
  6276. **/
  6277. static void
  6278. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  6279. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  6280. {
  6281. IOCB_t *icmd;
  6282. uint16_t evt_code;
  6283. uint16_t temp;
  6284. struct temp_event temp_event_data;
  6285. struct Scsi_Host *shost;
  6286. uint32_t *iocb_w;
  6287. icmd = &iocbq->iocb;
  6288. evt_code = icmd->un.asyncstat.evt_code;
  6289. temp = icmd->ulpContext;
  6290. if ((evt_code != ASYNC_TEMP_WARN) &&
  6291. (evt_code != ASYNC_TEMP_SAFE)) {
  6292. iocb_w = (uint32_t *) icmd;
  6293. lpfc_printf_log(phba,
  6294. KERN_ERR,
  6295. LOG_SLI,
  6296. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  6297. " evt_code 0x%x\n"
  6298. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  6299. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  6300. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  6301. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  6302. pring->ringno,
  6303. icmd->un.asyncstat.evt_code,
  6304. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  6305. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  6306. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  6307. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  6308. return;
  6309. }
  6310. temp_event_data.data = (uint32_t)temp;
  6311. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  6312. if (evt_code == ASYNC_TEMP_WARN) {
  6313. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  6314. lpfc_printf_log(phba,
  6315. KERN_ERR,
  6316. LOG_TEMP,
  6317. "0347 Adapter is very hot, please take "
  6318. "corrective action. temperature : %d Celsius\n",
  6319. temp);
  6320. }
  6321. if (evt_code == ASYNC_TEMP_SAFE) {
  6322. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  6323. lpfc_printf_log(phba,
  6324. KERN_ERR,
  6325. LOG_TEMP,
  6326. "0340 Adapter temperature is OK now. "
  6327. "temperature : %d Celsius\n",
  6328. temp);
  6329. }
  6330. /* Send temperature change event to applications */
  6331. shost = lpfc_shost_from_vport(phba->pport);
  6332. fc_host_post_vendor_event(shost, fc_get_event_number(),
  6333. sizeof(temp_event_data), (char *) &temp_event_data,
  6334. LPFC_NL_VENDOR_ID);
  6335. }
  6336. /**
  6337. * lpfc_sli_setup - SLI ring setup function
  6338. * @phba: Pointer to HBA context object.
  6339. *
  6340. * lpfc_sli_setup sets up rings of the SLI interface with
  6341. * number of iocbs per ring and iotags. This function is
  6342. * called while driver attach to the HBA and before the
  6343. * interrupts are enabled. So there is no need for locking.
  6344. *
  6345. * This function always returns 0.
  6346. **/
  6347. int
  6348. lpfc_sli_setup(struct lpfc_hba *phba)
  6349. {
  6350. int i, totiocbsize = 0;
  6351. struct lpfc_sli *psli = &phba->sli;
  6352. struct lpfc_sli_ring *pring;
  6353. psli->num_rings = MAX_CONFIGURED_RINGS;
  6354. psli->sli_flag = 0;
  6355. psli->fcp_ring = LPFC_FCP_RING;
  6356. psli->next_ring = LPFC_FCP_NEXT_RING;
  6357. psli->extra_ring = LPFC_EXTRA_RING;
  6358. psli->iocbq_lookup = NULL;
  6359. psli->iocbq_lookup_len = 0;
  6360. psli->last_iotag = 0;
  6361. for (i = 0; i < psli->num_rings; i++) {
  6362. pring = &psli->ring[i];
  6363. switch (i) {
  6364. case LPFC_FCP_RING: /* ring 0 - FCP */
  6365. /* numCiocb and numRiocb are used in config_port */
  6366. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  6367. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  6368. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6369. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6370. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6371. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6372. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6373. SLI3_IOCB_CMD_SIZE :
  6374. SLI2_IOCB_CMD_SIZE;
  6375. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6376. SLI3_IOCB_RSP_SIZE :
  6377. SLI2_IOCB_RSP_SIZE;
  6378. pring->iotag_ctr = 0;
  6379. pring->iotag_max =
  6380. (phba->cfg_hba_queue_depth * 2);
  6381. pring->fast_iotag = pring->iotag_max;
  6382. pring->num_mask = 0;
  6383. break;
  6384. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  6385. /* numCiocb and numRiocb are used in config_port */
  6386. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  6387. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  6388. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6389. SLI3_IOCB_CMD_SIZE :
  6390. SLI2_IOCB_CMD_SIZE;
  6391. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6392. SLI3_IOCB_RSP_SIZE :
  6393. SLI2_IOCB_RSP_SIZE;
  6394. pring->iotag_max = phba->cfg_hba_queue_depth;
  6395. pring->num_mask = 0;
  6396. break;
  6397. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  6398. /* numCiocb and numRiocb are used in config_port */
  6399. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  6400. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  6401. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6402. SLI3_IOCB_CMD_SIZE :
  6403. SLI2_IOCB_CMD_SIZE;
  6404. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6405. SLI3_IOCB_RSP_SIZE :
  6406. SLI2_IOCB_RSP_SIZE;
  6407. pring->fast_iotag = 0;
  6408. pring->iotag_ctr = 0;
  6409. pring->iotag_max = 4096;
  6410. pring->lpfc_sli_rcv_async_status =
  6411. lpfc_sli_async_event_handler;
  6412. pring->num_mask = LPFC_MAX_RING_MASK;
  6413. pring->prt[0].profile = 0; /* Mask 0 */
  6414. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  6415. pring->prt[0].type = FC_TYPE_ELS;
  6416. pring->prt[0].lpfc_sli_rcv_unsol_event =
  6417. lpfc_els_unsol_event;
  6418. pring->prt[1].profile = 0; /* Mask 1 */
  6419. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  6420. pring->prt[1].type = FC_TYPE_ELS;
  6421. pring->prt[1].lpfc_sli_rcv_unsol_event =
  6422. lpfc_els_unsol_event;
  6423. pring->prt[2].profile = 0; /* Mask 2 */
  6424. /* NameServer Inquiry */
  6425. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  6426. /* NameServer */
  6427. pring->prt[2].type = FC_TYPE_CT;
  6428. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6429. lpfc_ct_unsol_event;
  6430. pring->prt[3].profile = 0; /* Mask 3 */
  6431. /* NameServer response */
  6432. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6433. /* NameServer */
  6434. pring->prt[3].type = FC_TYPE_CT;
  6435. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6436. lpfc_ct_unsol_event;
  6437. /* abort unsolicited sequence */
  6438. pring->prt[4].profile = 0; /* Mask 4 */
  6439. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6440. pring->prt[4].type = FC_TYPE_BLS;
  6441. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6442. lpfc_sli4_ct_abort_unsol_event;
  6443. break;
  6444. }
  6445. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6446. (pring->numRiocb * pring->sizeRiocb);
  6447. }
  6448. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6449. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6450. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6451. "SLI2 SLIM Data: x%x x%lx\n",
  6452. phba->brd_no, totiocbsize,
  6453. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6454. }
  6455. if (phba->cfg_multi_ring_support == 2)
  6456. lpfc_extra_ring_setup(phba);
  6457. return 0;
  6458. }
  6459. /**
  6460. * lpfc_sli_queue_setup - Queue initialization function
  6461. * @phba: Pointer to HBA context object.
  6462. *
  6463. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6464. * ring. This function also initializes ring indices of each ring.
  6465. * This function is called during the initialization of the SLI
  6466. * interface of an HBA.
  6467. * This function is called with no lock held and always returns
  6468. * 1.
  6469. **/
  6470. int
  6471. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6472. {
  6473. struct lpfc_sli *psli;
  6474. struct lpfc_sli_ring *pring;
  6475. int i;
  6476. psli = &phba->sli;
  6477. spin_lock_irq(&phba->hbalock);
  6478. INIT_LIST_HEAD(&psli->mboxq);
  6479. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6480. /* Initialize list headers for txq and txcmplq as double linked lists */
  6481. for (i = 0; i < psli->num_rings; i++) {
  6482. pring = &psli->ring[i];
  6483. pring->ringno = i;
  6484. pring->next_cmdidx = 0;
  6485. pring->local_getidx = 0;
  6486. pring->cmdidx = 0;
  6487. INIT_LIST_HEAD(&pring->txq);
  6488. INIT_LIST_HEAD(&pring->txcmplq);
  6489. INIT_LIST_HEAD(&pring->iocb_continueq);
  6490. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6491. INIT_LIST_HEAD(&pring->postbufq);
  6492. }
  6493. spin_unlock_irq(&phba->hbalock);
  6494. return 1;
  6495. }
  6496. /**
  6497. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6498. * @phba: Pointer to HBA context object.
  6499. *
  6500. * This routine flushes the mailbox command subsystem. It will unconditionally
  6501. * flush all the mailbox commands in the three possible stages in the mailbox
  6502. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6503. * command; and completed mailbox command queue. It is caller's responsibility
  6504. * to make sure that the driver is in the proper state to flush the mailbox
  6505. * command sub-system. Namely, the posting of mailbox commands into the
  6506. * pending mailbox command queue from the various clients must be stopped;
  6507. * either the HBA is in a state that it will never works on the outstanding
  6508. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6509. * mailbox command has been completed.
  6510. **/
  6511. static void
  6512. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6513. {
  6514. LIST_HEAD(completions);
  6515. struct lpfc_sli *psli = &phba->sli;
  6516. LPFC_MBOXQ_t *pmb;
  6517. unsigned long iflag;
  6518. /* Flush all the mailbox commands in the mbox system */
  6519. spin_lock_irqsave(&phba->hbalock, iflag);
  6520. /* The pending mailbox command queue */
  6521. list_splice_init(&phba->sli.mboxq, &completions);
  6522. /* The outstanding active mailbox command */
  6523. if (psli->mbox_active) {
  6524. list_add_tail(&psli->mbox_active->list, &completions);
  6525. psli->mbox_active = NULL;
  6526. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6527. }
  6528. /* The completed mailbox command queue */
  6529. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6530. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6531. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6532. while (!list_empty(&completions)) {
  6533. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6534. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6535. if (pmb->mbox_cmpl)
  6536. pmb->mbox_cmpl(phba, pmb);
  6537. }
  6538. }
  6539. /**
  6540. * lpfc_sli_host_down - Vport cleanup function
  6541. * @vport: Pointer to virtual port object.
  6542. *
  6543. * lpfc_sli_host_down is called to clean up the resources
  6544. * associated with a vport before destroying virtual
  6545. * port data structures.
  6546. * This function does following operations:
  6547. * - Free discovery resources associated with this virtual
  6548. * port.
  6549. * - Free iocbs associated with this virtual port in
  6550. * the txq.
  6551. * - Send abort for all iocb commands associated with this
  6552. * vport in txcmplq.
  6553. *
  6554. * This function is called with no lock held and always returns 1.
  6555. **/
  6556. int
  6557. lpfc_sli_host_down(struct lpfc_vport *vport)
  6558. {
  6559. LIST_HEAD(completions);
  6560. struct lpfc_hba *phba = vport->phba;
  6561. struct lpfc_sli *psli = &phba->sli;
  6562. struct lpfc_sli_ring *pring;
  6563. struct lpfc_iocbq *iocb, *next_iocb;
  6564. int i;
  6565. unsigned long flags = 0;
  6566. uint16_t prev_pring_flag;
  6567. lpfc_cleanup_discovery_resources(vport);
  6568. spin_lock_irqsave(&phba->hbalock, flags);
  6569. for (i = 0; i < psli->num_rings; i++) {
  6570. pring = &psli->ring[i];
  6571. prev_pring_flag = pring->flag;
  6572. /* Only slow rings */
  6573. if (pring->ringno == LPFC_ELS_RING) {
  6574. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6575. /* Set the lpfc data pending flag */
  6576. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6577. }
  6578. /*
  6579. * Error everything on the txq since these iocbs have not been
  6580. * given to the FW yet.
  6581. */
  6582. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6583. if (iocb->vport != vport)
  6584. continue;
  6585. list_move_tail(&iocb->list, &completions);
  6586. pring->txq_cnt--;
  6587. }
  6588. /* Next issue ABTS for everything on the txcmplq */
  6589. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6590. list) {
  6591. if (iocb->vport != vport)
  6592. continue;
  6593. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6594. }
  6595. pring->flag = prev_pring_flag;
  6596. }
  6597. spin_unlock_irqrestore(&phba->hbalock, flags);
  6598. /* Cancel all the IOCBs from the completions list */
  6599. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6600. IOERR_SLI_DOWN);
  6601. return 1;
  6602. }
  6603. /**
  6604. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6605. * @phba: Pointer to HBA context object.
  6606. *
  6607. * This function cleans up all iocb, buffers, mailbox commands
  6608. * while shutting down the HBA. This function is called with no
  6609. * lock held and always returns 1.
  6610. * This function does the following to cleanup driver resources:
  6611. * - Free discovery resources for each virtual port
  6612. * - Cleanup any pending fabric iocbs
  6613. * - Iterate through the iocb txq and free each entry
  6614. * in the list.
  6615. * - Free up any buffer posted to the HBA
  6616. * - Free mailbox commands in the mailbox queue.
  6617. **/
  6618. int
  6619. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6620. {
  6621. LIST_HEAD(completions);
  6622. struct lpfc_sli *psli = &phba->sli;
  6623. struct lpfc_sli_ring *pring;
  6624. struct lpfc_dmabuf *buf_ptr;
  6625. unsigned long flags = 0;
  6626. int i;
  6627. /* Shutdown the mailbox command sub-system */
  6628. lpfc_sli_mbox_sys_shutdown(phba);
  6629. lpfc_hba_down_prep(phba);
  6630. lpfc_fabric_abort_hba(phba);
  6631. spin_lock_irqsave(&phba->hbalock, flags);
  6632. for (i = 0; i < psli->num_rings; i++) {
  6633. pring = &psli->ring[i];
  6634. /* Only slow rings */
  6635. if (pring->ringno == LPFC_ELS_RING) {
  6636. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6637. /* Set the lpfc data pending flag */
  6638. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6639. }
  6640. /*
  6641. * Error everything on the txq since these iocbs have not been
  6642. * given to the FW yet.
  6643. */
  6644. list_splice_init(&pring->txq, &completions);
  6645. pring->txq_cnt = 0;
  6646. }
  6647. spin_unlock_irqrestore(&phba->hbalock, flags);
  6648. /* Cancel all the IOCBs from the completions list */
  6649. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6650. IOERR_SLI_DOWN);
  6651. spin_lock_irqsave(&phba->hbalock, flags);
  6652. list_splice_init(&phba->elsbuf, &completions);
  6653. phba->elsbuf_cnt = 0;
  6654. phba->elsbuf_prev_cnt = 0;
  6655. spin_unlock_irqrestore(&phba->hbalock, flags);
  6656. while (!list_empty(&completions)) {
  6657. list_remove_head(&completions, buf_ptr,
  6658. struct lpfc_dmabuf, list);
  6659. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6660. kfree(buf_ptr);
  6661. }
  6662. /* Return any active mbox cmds */
  6663. del_timer_sync(&psli->mbox_tmo);
  6664. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6665. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6666. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6667. return 1;
  6668. }
  6669. /**
  6670. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6671. * @srcp: Source memory pointer.
  6672. * @destp: Destination memory pointer.
  6673. * @cnt: Number of words required to be copied.
  6674. *
  6675. * This function is used for copying data between driver memory
  6676. * and the SLI memory. This function also changes the endianness
  6677. * of each word if native endianness is different from SLI
  6678. * endianness. This function can be called with or without
  6679. * lock.
  6680. **/
  6681. void
  6682. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6683. {
  6684. uint32_t *src = srcp;
  6685. uint32_t *dest = destp;
  6686. uint32_t ldata;
  6687. int i;
  6688. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6689. ldata = *src;
  6690. ldata = le32_to_cpu(ldata);
  6691. *dest = ldata;
  6692. src++;
  6693. dest++;
  6694. }
  6695. }
  6696. /**
  6697. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6698. * @srcp: Source memory pointer.
  6699. * @destp: Destination memory pointer.
  6700. * @cnt: Number of words required to be copied.
  6701. *
  6702. * This function is used for copying data between a data structure
  6703. * with big endian representation to local endianness.
  6704. * This function can be called with or without lock.
  6705. **/
  6706. void
  6707. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6708. {
  6709. uint32_t *src = srcp;
  6710. uint32_t *dest = destp;
  6711. uint32_t ldata;
  6712. int i;
  6713. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6714. ldata = *src;
  6715. ldata = be32_to_cpu(ldata);
  6716. *dest = ldata;
  6717. src++;
  6718. dest++;
  6719. }
  6720. }
  6721. /**
  6722. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6723. * @phba: Pointer to HBA context object.
  6724. * @pring: Pointer to driver SLI ring object.
  6725. * @mp: Pointer to driver buffer object.
  6726. *
  6727. * This function is called with no lock held.
  6728. * It always return zero after adding the buffer to the postbufq
  6729. * buffer list.
  6730. **/
  6731. int
  6732. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6733. struct lpfc_dmabuf *mp)
  6734. {
  6735. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6736. later */
  6737. spin_lock_irq(&phba->hbalock);
  6738. list_add_tail(&mp->list, &pring->postbufq);
  6739. pring->postbufq_cnt++;
  6740. spin_unlock_irq(&phba->hbalock);
  6741. return 0;
  6742. }
  6743. /**
  6744. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6745. * @phba: Pointer to HBA context object.
  6746. *
  6747. * When HBQ is enabled, buffers are searched based on tags. This function
  6748. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6749. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6750. * does not conflict with tags of buffer posted for unsolicited events.
  6751. * The function returns the allocated tag. The function is called with
  6752. * no locks held.
  6753. **/
  6754. uint32_t
  6755. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6756. {
  6757. spin_lock_irq(&phba->hbalock);
  6758. phba->buffer_tag_count++;
  6759. /*
  6760. * Always set the QUE_BUFTAG_BIT to distiguish between
  6761. * a tag assigned by HBQ.
  6762. */
  6763. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6764. spin_unlock_irq(&phba->hbalock);
  6765. return phba->buffer_tag_count;
  6766. }
  6767. /**
  6768. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6769. * @phba: Pointer to HBA context object.
  6770. * @pring: Pointer to driver SLI ring object.
  6771. * @tag: Buffer tag.
  6772. *
  6773. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6774. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6775. * iocb is posted to the response ring with the tag of the buffer.
  6776. * This function searches the pring->postbufq list using the tag
  6777. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6778. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6779. * buffer is returned to the caller else NULL is returned.
  6780. * This function is called with no lock held.
  6781. **/
  6782. struct lpfc_dmabuf *
  6783. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6784. uint32_t tag)
  6785. {
  6786. struct lpfc_dmabuf *mp, *next_mp;
  6787. struct list_head *slp = &pring->postbufq;
  6788. /* Search postbufq, from the begining, looking for a match on tag */
  6789. spin_lock_irq(&phba->hbalock);
  6790. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6791. if (mp->buffer_tag == tag) {
  6792. list_del_init(&mp->list);
  6793. pring->postbufq_cnt--;
  6794. spin_unlock_irq(&phba->hbalock);
  6795. return mp;
  6796. }
  6797. }
  6798. spin_unlock_irq(&phba->hbalock);
  6799. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6800. "0402 Cannot find virtual addr for buffer tag on "
  6801. "ring %d Data x%lx x%p x%p x%x\n",
  6802. pring->ringno, (unsigned long) tag,
  6803. slp->next, slp->prev, pring->postbufq_cnt);
  6804. return NULL;
  6805. }
  6806. /**
  6807. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6808. * @phba: Pointer to HBA context object.
  6809. * @pring: Pointer to driver SLI ring object.
  6810. * @phys: DMA address of the buffer.
  6811. *
  6812. * This function searches the buffer list using the dma_address
  6813. * of unsolicited event to find the driver's lpfc_dmabuf object
  6814. * corresponding to the dma_address. The function returns the
  6815. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6816. * This function is called by the ct and els unsolicited event
  6817. * handlers to get the buffer associated with the unsolicited
  6818. * event.
  6819. *
  6820. * This function is called with no lock held.
  6821. **/
  6822. struct lpfc_dmabuf *
  6823. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6824. dma_addr_t phys)
  6825. {
  6826. struct lpfc_dmabuf *mp, *next_mp;
  6827. struct list_head *slp = &pring->postbufq;
  6828. /* Search postbufq, from the begining, looking for a match on phys */
  6829. spin_lock_irq(&phba->hbalock);
  6830. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6831. if (mp->phys == phys) {
  6832. list_del_init(&mp->list);
  6833. pring->postbufq_cnt--;
  6834. spin_unlock_irq(&phba->hbalock);
  6835. return mp;
  6836. }
  6837. }
  6838. spin_unlock_irq(&phba->hbalock);
  6839. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6840. "0410 Cannot find virtual addr for mapped buf on "
  6841. "ring %d Data x%llx x%p x%p x%x\n",
  6842. pring->ringno, (unsigned long long)phys,
  6843. slp->next, slp->prev, pring->postbufq_cnt);
  6844. return NULL;
  6845. }
  6846. /**
  6847. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6848. * @phba: Pointer to HBA context object.
  6849. * @cmdiocb: Pointer to driver command iocb object.
  6850. * @rspiocb: Pointer to driver response iocb object.
  6851. *
  6852. * This function is the completion handler for the abort iocbs for
  6853. * ELS commands. This function is called from the ELS ring event
  6854. * handler with no lock held. This function frees memory resources
  6855. * associated with the abort iocb.
  6856. **/
  6857. static void
  6858. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6859. struct lpfc_iocbq *rspiocb)
  6860. {
  6861. IOCB_t *irsp = &rspiocb->iocb;
  6862. uint16_t abort_iotag, abort_context;
  6863. struct lpfc_iocbq *abort_iocb;
  6864. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6865. abort_iocb = NULL;
  6866. if (irsp->ulpStatus) {
  6867. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6868. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6869. spin_lock_irq(&phba->hbalock);
  6870. if (phba->sli_rev < LPFC_SLI_REV4) {
  6871. if (abort_iotag != 0 &&
  6872. abort_iotag <= phba->sli.last_iotag)
  6873. abort_iocb =
  6874. phba->sli.iocbq_lookup[abort_iotag];
  6875. } else
  6876. /* For sli4 the abort_tag is the XRI,
  6877. * so the abort routine puts the iotag of the iocb
  6878. * being aborted in the context field of the abort
  6879. * IOCB.
  6880. */
  6881. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6882. /*
  6883. * If the iocb is not found in Firmware queue the iocb
  6884. * might have completed already. Do not free it again.
  6885. */
  6886. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6887. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6888. spin_unlock_irq(&phba->hbalock);
  6889. lpfc_sli_release_iocbq(phba, cmdiocb);
  6890. return;
  6891. }
  6892. /* For SLI4 the ulpContext field for abort IOCB
  6893. * holds the iotag of the IOCB being aborted so
  6894. * the local abort_context needs to be reset to
  6895. * match the aborted IOCBs ulpContext.
  6896. */
  6897. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6898. abort_context = abort_iocb->iocb.ulpContext;
  6899. }
  6900. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6901. "0327 Cannot abort els iocb %p "
  6902. "with tag %x context %x, abort status %x, "
  6903. "abort code %x\n",
  6904. abort_iocb, abort_iotag, abort_context,
  6905. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6906. /*
  6907. * make sure we have the right iocbq before taking it
  6908. * off the txcmplq and try to call completion routine.
  6909. */
  6910. if (!abort_iocb ||
  6911. abort_iocb->iocb.ulpContext != abort_context ||
  6912. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6913. spin_unlock_irq(&phba->hbalock);
  6914. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6915. /*
  6916. * leave the SLI4 aborted command on the txcmplq
  6917. * list and the command complete WCQE's XB bit
  6918. * will tell whether the SGL (XRI) can be released
  6919. * immediately or to the aborted SGL list for the
  6920. * following abort XRI from the HBA.
  6921. */
  6922. list_del_init(&abort_iocb->list);
  6923. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6924. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6925. pring->txcmplq_cnt--;
  6926. }
  6927. /* Firmware could still be in progress of DMAing
  6928. * payload, so don't free data buffer till after
  6929. * a hbeat.
  6930. */
  6931. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6932. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6933. spin_unlock_irq(&phba->hbalock);
  6934. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6935. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6936. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6937. } else
  6938. spin_unlock_irq(&phba->hbalock);
  6939. }
  6940. lpfc_sli_release_iocbq(phba, cmdiocb);
  6941. return;
  6942. }
  6943. /**
  6944. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6945. * @phba: Pointer to HBA context object.
  6946. * @cmdiocb: Pointer to driver command iocb object.
  6947. * @rspiocb: Pointer to driver response iocb object.
  6948. *
  6949. * The function is called from SLI ring event handler with no
  6950. * lock held. This function is the completion handler for ELS commands
  6951. * which are aborted. The function frees memory resources used for
  6952. * the aborted ELS commands.
  6953. **/
  6954. static void
  6955. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6956. struct lpfc_iocbq *rspiocb)
  6957. {
  6958. IOCB_t *irsp = &rspiocb->iocb;
  6959. /* ELS cmd tag <ulpIoTag> completes */
  6960. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6961. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6962. "x%x x%x x%x\n",
  6963. irsp->ulpIoTag, irsp->ulpStatus,
  6964. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6965. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6966. lpfc_ct_free_iocb(phba, cmdiocb);
  6967. else
  6968. lpfc_els_free_iocb(phba, cmdiocb);
  6969. return;
  6970. }
  6971. /**
  6972. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  6973. * @phba: Pointer to HBA context object.
  6974. * @pring: Pointer to driver SLI ring object.
  6975. * @cmdiocb: Pointer to driver command iocb object.
  6976. *
  6977. * This function issues an abort iocb for the provided command iocb down to
  6978. * the port. Other than the case the outstanding command iocb is an abort
  6979. * request, this function issues abort out unconditionally. This function is
  6980. * called with hbalock held. The function returns 0 when it fails due to
  6981. * memory allocation failure or when the command iocb is an abort request.
  6982. **/
  6983. static int
  6984. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6985. struct lpfc_iocbq *cmdiocb)
  6986. {
  6987. struct lpfc_vport *vport = cmdiocb->vport;
  6988. struct lpfc_iocbq *abtsiocbp;
  6989. IOCB_t *icmd = NULL;
  6990. IOCB_t *iabt = NULL;
  6991. int retval;
  6992. /*
  6993. * There are certain command types we don't want to abort. And we
  6994. * don't want to abort commands that are already in the process of
  6995. * being aborted.
  6996. */
  6997. icmd = &cmdiocb->iocb;
  6998. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6999. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7000. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7001. return 0;
  7002. /* issue ABTS for this IOCB based on iotag */
  7003. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  7004. if (abtsiocbp == NULL)
  7005. return 0;
  7006. /* This signals the response to set the correct status
  7007. * before calling the completion handler
  7008. */
  7009. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  7010. iabt = &abtsiocbp->iocb;
  7011. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  7012. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  7013. if (phba->sli_rev == LPFC_SLI_REV4) {
  7014. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  7015. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  7016. }
  7017. else
  7018. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  7019. iabt->ulpLe = 1;
  7020. iabt->ulpClass = icmd->ulpClass;
  7021. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7022. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  7023. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  7024. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  7025. if (phba->link_state >= LPFC_LINK_UP)
  7026. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  7027. else
  7028. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  7029. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  7030. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  7031. "0339 Abort xri x%x, original iotag x%x, "
  7032. "abort cmd iotag x%x\n",
  7033. iabt->un.acxri.abortIoTag,
  7034. iabt->un.acxri.abortContextTag,
  7035. abtsiocbp->iotag);
  7036. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  7037. if (retval)
  7038. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  7039. /*
  7040. * Caller to this routine should check for IOCB_ERROR
  7041. * and handle it properly. This routine no longer removes
  7042. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7043. */
  7044. return retval;
  7045. }
  7046. /**
  7047. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  7048. * @phba: Pointer to HBA context object.
  7049. * @pring: Pointer to driver SLI ring object.
  7050. * @cmdiocb: Pointer to driver command iocb object.
  7051. *
  7052. * This function issues an abort iocb for the provided command iocb. In case
  7053. * of unloading, the abort iocb will not be issued to commands on the ELS
  7054. * ring. Instead, the callback function shall be changed to those commands
  7055. * so that nothing happens when them finishes. This function is called with
  7056. * hbalock held. The function returns 0 when the command iocb is an abort
  7057. * request.
  7058. **/
  7059. int
  7060. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7061. struct lpfc_iocbq *cmdiocb)
  7062. {
  7063. struct lpfc_vport *vport = cmdiocb->vport;
  7064. int retval = IOCB_ERROR;
  7065. IOCB_t *icmd = NULL;
  7066. /*
  7067. * There are certain command types we don't want to abort. And we
  7068. * don't want to abort commands that are already in the process of
  7069. * being aborted.
  7070. */
  7071. icmd = &cmdiocb->iocb;
  7072. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7073. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7074. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7075. return 0;
  7076. /*
  7077. * If we're unloading, don't abort iocb on the ELS ring, but change
  7078. * the callback so that nothing happens when it finishes.
  7079. */
  7080. if ((vport->load_flag & FC_UNLOADING) &&
  7081. (pring->ringno == LPFC_ELS_RING)) {
  7082. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  7083. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  7084. else
  7085. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  7086. goto abort_iotag_exit;
  7087. }
  7088. /* Now, we try to issue the abort to the cmdiocb out */
  7089. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  7090. abort_iotag_exit:
  7091. /*
  7092. * Caller to this routine should check for IOCB_ERROR
  7093. * and handle it properly. This routine no longer removes
  7094. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7095. */
  7096. return retval;
  7097. }
  7098. /**
  7099. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  7100. * @phba: Pointer to HBA context object.
  7101. * @pring: Pointer to driver SLI ring object.
  7102. *
  7103. * This function aborts all iocbs in the given ring and frees all the iocb
  7104. * objects in txq. This function issues abort iocbs unconditionally for all
  7105. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  7106. * to complete before the return of this function. The caller is not required
  7107. * to hold any locks.
  7108. **/
  7109. static void
  7110. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  7111. {
  7112. LIST_HEAD(completions);
  7113. struct lpfc_iocbq *iocb, *next_iocb;
  7114. if (pring->ringno == LPFC_ELS_RING)
  7115. lpfc_fabric_abort_hba(phba);
  7116. spin_lock_irq(&phba->hbalock);
  7117. /* Take off all the iocbs on txq for cancelling */
  7118. list_splice_init(&pring->txq, &completions);
  7119. pring->txq_cnt = 0;
  7120. /* Next issue ABTS for everything on the txcmplq */
  7121. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  7122. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  7123. spin_unlock_irq(&phba->hbalock);
  7124. /* Cancel all the IOCBs from the completions list */
  7125. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7126. IOERR_SLI_ABORTED);
  7127. }
  7128. /**
  7129. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  7130. * @phba: pointer to lpfc HBA data structure.
  7131. *
  7132. * This routine will abort all pending and outstanding iocbs to an HBA.
  7133. **/
  7134. void
  7135. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  7136. {
  7137. struct lpfc_sli *psli = &phba->sli;
  7138. struct lpfc_sli_ring *pring;
  7139. int i;
  7140. for (i = 0; i < psli->num_rings; i++) {
  7141. pring = &psli->ring[i];
  7142. lpfc_sli_iocb_ring_abort(phba, pring);
  7143. }
  7144. }
  7145. /**
  7146. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  7147. * @iocbq: Pointer to driver iocb object.
  7148. * @vport: Pointer to driver virtual port object.
  7149. * @tgt_id: SCSI ID of the target.
  7150. * @lun_id: LUN ID of the scsi device.
  7151. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  7152. *
  7153. * This function acts as an iocb filter for functions which abort or count
  7154. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  7155. * 0 if the filtering criteria is met for the given iocb and will return
  7156. * 1 if the filtering criteria is not met.
  7157. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  7158. * given iocb is for the SCSI device specified by vport, tgt_id and
  7159. * lun_id parameter.
  7160. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  7161. * given iocb is for the SCSI target specified by vport and tgt_id
  7162. * parameters.
  7163. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  7164. * given iocb is for the SCSI host associated with the given vport.
  7165. * This function is called with no locks held.
  7166. **/
  7167. static int
  7168. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  7169. uint16_t tgt_id, uint64_t lun_id,
  7170. lpfc_ctx_cmd ctx_cmd)
  7171. {
  7172. struct lpfc_scsi_buf *lpfc_cmd;
  7173. int rc = 1;
  7174. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  7175. return rc;
  7176. if (iocbq->vport != vport)
  7177. return rc;
  7178. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  7179. if (lpfc_cmd->pCmd == NULL)
  7180. return rc;
  7181. switch (ctx_cmd) {
  7182. case LPFC_CTX_LUN:
  7183. if ((lpfc_cmd->rdata->pnode) &&
  7184. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  7185. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  7186. rc = 0;
  7187. break;
  7188. case LPFC_CTX_TGT:
  7189. if ((lpfc_cmd->rdata->pnode) &&
  7190. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  7191. rc = 0;
  7192. break;
  7193. case LPFC_CTX_HOST:
  7194. rc = 0;
  7195. break;
  7196. default:
  7197. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  7198. __func__, ctx_cmd);
  7199. break;
  7200. }
  7201. return rc;
  7202. }
  7203. /**
  7204. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  7205. * @vport: Pointer to virtual port.
  7206. * @tgt_id: SCSI ID of the target.
  7207. * @lun_id: LUN ID of the scsi device.
  7208. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7209. *
  7210. * This function returns number of FCP commands pending for the vport.
  7211. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  7212. * commands pending on the vport associated with SCSI device specified
  7213. * by tgt_id and lun_id parameters.
  7214. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  7215. * commands pending on the vport associated with SCSI target specified
  7216. * by tgt_id parameter.
  7217. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  7218. * commands pending on the vport.
  7219. * This function returns the number of iocbs which satisfy the filter.
  7220. * This function is called without any lock held.
  7221. **/
  7222. int
  7223. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  7224. lpfc_ctx_cmd ctx_cmd)
  7225. {
  7226. struct lpfc_hba *phba = vport->phba;
  7227. struct lpfc_iocbq *iocbq;
  7228. int sum, i;
  7229. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  7230. iocbq = phba->sli.iocbq_lookup[i];
  7231. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  7232. ctx_cmd) == 0)
  7233. sum++;
  7234. }
  7235. return sum;
  7236. }
  7237. /**
  7238. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  7239. * @phba: Pointer to HBA context object
  7240. * @cmdiocb: Pointer to command iocb object.
  7241. * @rspiocb: Pointer to response iocb object.
  7242. *
  7243. * This function is called when an aborted FCP iocb completes. This
  7244. * function is called by the ring event handler with no lock held.
  7245. * This function frees the iocb.
  7246. **/
  7247. void
  7248. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7249. struct lpfc_iocbq *rspiocb)
  7250. {
  7251. lpfc_sli_release_iocbq(phba, cmdiocb);
  7252. return;
  7253. }
  7254. /**
  7255. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  7256. * @vport: Pointer to virtual port.
  7257. * @pring: Pointer to driver SLI ring object.
  7258. * @tgt_id: SCSI ID of the target.
  7259. * @lun_id: LUN ID of the scsi device.
  7260. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7261. *
  7262. * This function sends an abort command for every SCSI command
  7263. * associated with the given virtual port pending on the ring
  7264. * filtered by lpfc_sli_validate_fcp_iocb function.
  7265. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  7266. * FCP iocbs associated with lun specified by tgt_id and lun_id
  7267. * parameters
  7268. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  7269. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  7270. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  7271. * FCP iocbs associated with virtual port.
  7272. * This function returns number of iocbs it failed to abort.
  7273. * This function is called with no locks held.
  7274. **/
  7275. int
  7276. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  7277. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  7278. {
  7279. struct lpfc_hba *phba = vport->phba;
  7280. struct lpfc_iocbq *iocbq;
  7281. struct lpfc_iocbq *abtsiocb;
  7282. IOCB_t *cmd = NULL;
  7283. int errcnt = 0, ret_val = 0;
  7284. int i;
  7285. for (i = 1; i <= phba->sli.last_iotag; i++) {
  7286. iocbq = phba->sli.iocbq_lookup[i];
  7287. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  7288. abort_cmd) != 0)
  7289. continue;
  7290. /* issue ABTS for this IOCB based on iotag */
  7291. abtsiocb = lpfc_sli_get_iocbq(phba);
  7292. if (abtsiocb == NULL) {
  7293. errcnt++;
  7294. continue;
  7295. }
  7296. cmd = &iocbq->iocb;
  7297. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  7298. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  7299. if (phba->sli_rev == LPFC_SLI_REV4)
  7300. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  7301. else
  7302. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  7303. abtsiocb->iocb.ulpLe = 1;
  7304. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  7305. abtsiocb->vport = phba->pport;
  7306. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7307. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  7308. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7309. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  7310. if (lpfc_is_link_up(phba))
  7311. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  7312. else
  7313. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  7314. /* Setup callback routine and issue the command. */
  7315. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  7316. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  7317. abtsiocb, 0);
  7318. if (ret_val == IOCB_ERROR) {
  7319. lpfc_sli_release_iocbq(phba, abtsiocb);
  7320. errcnt++;
  7321. continue;
  7322. }
  7323. }
  7324. return errcnt;
  7325. }
  7326. /**
  7327. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  7328. * @phba: Pointer to HBA context object.
  7329. * @cmdiocbq: Pointer to command iocb.
  7330. * @rspiocbq: Pointer to response iocb.
  7331. *
  7332. * This function is the completion handler for iocbs issued using
  7333. * lpfc_sli_issue_iocb_wait function. This function is called by the
  7334. * ring event handler function without any lock held. This function
  7335. * can be called from both worker thread context and interrupt
  7336. * context. This function also can be called from other thread which
  7337. * cleans up the SLI layer objects.
  7338. * This function copy the contents of the response iocb to the
  7339. * response iocb memory object provided by the caller of
  7340. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  7341. * sleeps for the iocb completion.
  7342. **/
  7343. static void
  7344. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  7345. struct lpfc_iocbq *cmdiocbq,
  7346. struct lpfc_iocbq *rspiocbq)
  7347. {
  7348. wait_queue_head_t *pdone_q;
  7349. unsigned long iflags;
  7350. struct lpfc_scsi_buf *lpfc_cmd;
  7351. spin_lock_irqsave(&phba->hbalock, iflags);
  7352. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  7353. if (cmdiocbq->context2 && rspiocbq)
  7354. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  7355. &rspiocbq->iocb, sizeof(IOCB_t));
  7356. /* Set the exchange busy flag for task management commands */
  7357. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  7358. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  7359. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  7360. cur_iocbq);
  7361. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  7362. }
  7363. pdone_q = cmdiocbq->context_un.wait_queue;
  7364. if (pdone_q)
  7365. wake_up(pdone_q);
  7366. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7367. return;
  7368. }
  7369. /**
  7370. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  7371. * @phba: Pointer to HBA context object..
  7372. * @piocbq: Pointer to command iocb.
  7373. * @flag: Flag to test.
  7374. *
  7375. * This routine grabs the hbalock and then test the iocb_flag to
  7376. * see if the passed in flag is set.
  7377. * Returns:
  7378. * 1 if flag is set.
  7379. * 0 if flag is not set.
  7380. **/
  7381. static int
  7382. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  7383. struct lpfc_iocbq *piocbq, uint32_t flag)
  7384. {
  7385. unsigned long iflags;
  7386. int ret;
  7387. spin_lock_irqsave(&phba->hbalock, iflags);
  7388. ret = piocbq->iocb_flag & flag;
  7389. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7390. return ret;
  7391. }
  7392. /**
  7393. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  7394. * @phba: Pointer to HBA context object..
  7395. * @pring: Pointer to sli ring.
  7396. * @piocb: Pointer to command iocb.
  7397. * @prspiocbq: Pointer to response iocb.
  7398. * @timeout: Timeout in number of seconds.
  7399. *
  7400. * This function issues the iocb to firmware and waits for the
  7401. * iocb to complete. If the iocb command is not
  7402. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  7403. * Caller should not free the iocb resources if this function
  7404. * returns IOCB_TIMEDOUT.
  7405. * The function waits for the iocb completion using an
  7406. * non-interruptible wait.
  7407. * This function will sleep while waiting for iocb completion.
  7408. * So, this function should not be called from any context which
  7409. * does not allow sleeping. Due to the same reason, this function
  7410. * cannot be called with interrupt disabled.
  7411. * This function assumes that the iocb completions occur while
  7412. * this function sleep. So, this function cannot be called from
  7413. * the thread which process iocb completion for this ring.
  7414. * This function clears the iocb_flag of the iocb object before
  7415. * issuing the iocb and the iocb completion handler sets this
  7416. * flag and wakes this thread when the iocb completes.
  7417. * The contents of the response iocb will be copied to prspiocbq
  7418. * by the completion handler when the command completes.
  7419. * This function returns IOCB_SUCCESS when success.
  7420. * This function is called with no lock held.
  7421. **/
  7422. int
  7423. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  7424. uint32_t ring_number,
  7425. struct lpfc_iocbq *piocb,
  7426. struct lpfc_iocbq *prspiocbq,
  7427. uint32_t timeout)
  7428. {
  7429. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7430. long timeleft, timeout_req = 0;
  7431. int retval = IOCB_SUCCESS;
  7432. uint32_t creg_val;
  7433. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7434. /*
  7435. * If the caller has provided a response iocbq buffer, then context2
  7436. * is NULL or its an error.
  7437. */
  7438. if (prspiocbq) {
  7439. if (piocb->context2)
  7440. return IOCB_ERROR;
  7441. piocb->context2 = prspiocbq;
  7442. }
  7443. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  7444. piocb->context_un.wait_queue = &done_q;
  7445. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  7446. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7447. creg_val = readl(phba->HCregaddr);
  7448. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  7449. writel(creg_val, phba->HCregaddr);
  7450. readl(phba->HCregaddr); /* flush */
  7451. }
  7452. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7453. SLI_IOCB_RET_IOCB);
  7454. if (retval == IOCB_SUCCESS) {
  7455. timeout_req = timeout * HZ;
  7456. timeleft = wait_event_timeout(done_q,
  7457. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  7458. timeout_req);
  7459. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  7460. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7461. "0331 IOCB wake signaled\n");
  7462. } else if (timeleft == 0) {
  7463. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7464. "0338 IOCB wait timeout error - no "
  7465. "wake response Data x%x\n", timeout);
  7466. retval = IOCB_TIMEDOUT;
  7467. } else {
  7468. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7469. "0330 IOCB wake NOT set, "
  7470. "Data x%x x%lx\n",
  7471. timeout, (timeleft / jiffies));
  7472. retval = IOCB_TIMEDOUT;
  7473. }
  7474. } else if (retval == IOCB_BUSY) {
  7475. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7476. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  7477. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  7478. return retval;
  7479. } else {
  7480. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7481. "0332 IOCB wait issue failed, Data x%x\n",
  7482. retval);
  7483. retval = IOCB_ERROR;
  7484. }
  7485. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7486. creg_val = readl(phba->HCregaddr);
  7487. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  7488. writel(creg_val, phba->HCregaddr);
  7489. readl(phba->HCregaddr); /* flush */
  7490. }
  7491. if (prspiocbq)
  7492. piocb->context2 = NULL;
  7493. piocb->context_un.wait_queue = NULL;
  7494. piocb->iocb_cmpl = NULL;
  7495. return retval;
  7496. }
  7497. /**
  7498. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7499. * @phba: Pointer to HBA context object.
  7500. * @pmboxq: Pointer to driver mailbox object.
  7501. * @timeout: Timeout in number of seconds.
  7502. *
  7503. * This function issues the mailbox to firmware and waits for the
  7504. * mailbox command to complete. If the mailbox command is not
  7505. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7506. * The function waits for the mailbox completion using an
  7507. * interruptible wait. If the thread is woken up due to a
  7508. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7509. * should not free the mailbox resources, if this function returns
  7510. * MBX_TIMEOUT.
  7511. * This function will sleep while waiting for mailbox completion.
  7512. * So, this function should not be called from any context which
  7513. * does not allow sleeping. Due to the same reason, this function
  7514. * cannot be called with interrupt disabled.
  7515. * This function assumes that the mailbox completion occurs while
  7516. * this function sleep. So, this function cannot be called from
  7517. * the worker thread which processes mailbox completion.
  7518. * This function is called in the context of HBA management
  7519. * applications.
  7520. * This function returns MBX_SUCCESS when successful.
  7521. * This function is called with no lock held.
  7522. **/
  7523. int
  7524. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7525. uint32_t timeout)
  7526. {
  7527. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7528. int retval;
  7529. unsigned long flag;
  7530. /* The caller must leave context1 empty. */
  7531. if (pmboxq->context1)
  7532. return MBX_NOT_FINISHED;
  7533. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7534. /* setup wake call as IOCB callback */
  7535. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7536. /* setup context field to pass wait_queue pointer to wake function */
  7537. pmboxq->context1 = &done_q;
  7538. /* now issue the command */
  7539. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7540. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7541. wait_event_interruptible_timeout(done_q,
  7542. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7543. timeout * HZ);
  7544. spin_lock_irqsave(&phba->hbalock, flag);
  7545. pmboxq->context1 = NULL;
  7546. /*
  7547. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7548. * else do not free the resources.
  7549. */
  7550. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7551. retval = MBX_SUCCESS;
  7552. lpfc_sli4_swap_str(phba, pmboxq);
  7553. } else {
  7554. retval = MBX_TIMEOUT;
  7555. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7556. }
  7557. spin_unlock_irqrestore(&phba->hbalock, flag);
  7558. }
  7559. return retval;
  7560. }
  7561. /**
  7562. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7563. * @phba: Pointer to HBA context.
  7564. *
  7565. * This function is called to shutdown the driver's mailbox sub-system.
  7566. * It first marks the mailbox sub-system is in a block state to prevent
  7567. * the asynchronous mailbox command from issued off the pending mailbox
  7568. * command queue. If the mailbox command sub-system shutdown is due to
  7569. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7570. * the mailbox sub-system flush routine to forcefully bring down the
  7571. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7572. * as with offline or HBA function reset), this routine will wait for the
  7573. * outstanding mailbox command to complete before invoking the mailbox
  7574. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7575. **/
  7576. void
  7577. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7578. {
  7579. struct lpfc_sli *psli = &phba->sli;
  7580. uint8_t actcmd = MBX_HEARTBEAT;
  7581. unsigned long timeout;
  7582. spin_lock_irq(&phba->hbalock);
  7583. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7584. spin_unlock_irq(&phba->hbalock);
  7585. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7586. spin_lock_irq(&phba->hbalock);
  7587. if (phba->sli.mbox_active)
  7588. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7589. spin_unlock_irq(&phba->hbalock);
  7590. /* Determine how long we might wait for the active mailbox
  7591. * command to be gracefully completed by firmware.
  7592. */
  7593. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7594. 1000) + jiffies;
  7595. while (phba->sli.mbox_active) {
  7596. /* Check active mailbox complete status every 2ms */
  7597. msleep(2);
  7598. if (time_after(jiffies, timeout))
  7599. /* Timeout, let the mailbox flush routine to
  7600. * forcefully release active mailbox command
  7601. */
  7602. break;
  7603. }
  7604. }
  7605. lpfc_sli_mbox_sys_flush(phba);
  7606. }
  7607. /**
  7608. * lpfc_sli_eratt_read - read sli-3 error attention events
  7609. * @phba: Pointer to HBA context.
  7610. *
  7611. * This function is called to read the SLI3 device error attention registers
  7612. * for possible error attention events. The caller must hold the hostlock
  7613. * with spin_lock_irq().
  7614. *
  7615. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7616. * Register and returns 0 otherwise.
  7617. **/
  7618. static int
  7619. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7620. {
  7621. uint32_t ha_copy;
  7622. /* Read chip Host Attention (HA) register */
  7623. ha_copy = readl(phba->HAregaddr);
  7624. if (ha_copy & HA_ERATT) {
  7625. /* Read host status register to retrieve error event */
  7626. lpfc_sli_read_hs(phba);
  7627. /* Check if there is a deferred error condition is active */
  7628. if ((HS_FFER1 & phba->work_hs) &&
  7629. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7630. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  7631. phba->hba_flag |= DEFER_ERATT;
  7632. /* Clear all interrupt enable conditions */
  7633. writel(0, phba->HCregaddr);
  7634. readl(phba->HCregaddr);
  7635. }
  7636. /* Set the driver HA work bitmap */
  7637. phba->work_ha |= HA_ERATT;
  7638. /* Indicate polling handles this ERATT */
  7639. phba->hba_flag |= HBA_ERATT_HANDLED;
  7640. return 1;
  7641. }
  7642. return 0;
  7643. }
  7644. /**
  7645. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7646. * @phba: Pointer to HBA context.
  7647. *
  7648. * This function is called to read the SLI4 device error attention registers
  7649. * for possible error attention events. The caller must hold the hostlock
  7650. * with spin_lock_irq().
  7651. *
  7652. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7653. * Register and returns 0 otherwise.
  7654. **/
  7655. static int
  7656. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7657. {
  7658. uint32_t uerr_sta_hi, uerr_sta_lo;
  7659. uint32_t if_type, portsmphr;
  7660. struct lpfc_register portstat_reg;
  7661. /*
  7662. * For now, use the SLI4 device internal unrecoverable error
  7663. * registers for error attention. This can be changed later.
  7664. */
  7665. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7666. switch (if_type) {
  7667. case LPFC_SLI_INTF_IF_TYPE_0:
  7668. uerr_sta_lo = readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
  7669. uerr_sta_hi = readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
  7670. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7671. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7672. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7673. "1423 HBA Unrecoverable error: "
  7674. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7675. "ue_mask_lo_reg=0x%x, "
  7676. "ue_mask_hi_reg=0x%x\n",
  7677. uerr_sta_lo, uerr_sta_hi,
  7678. phba->sli4_hba.ue_mask_lo,
  7679. phba->sli4_hba.ue_mask_hi);
  7680. phba->work_status[0] = uerr_sta_lo;
  7681. phba->work_status[1] = uerr_sta_hi;
  7682. phba->work_ha |= HA_ERATT;
  7683. phba->hba_flag |= HBA_ERATT_HANDLED;
  7684. return 1;
  7685. }
  7686. break;
  7687. case LPFC_SLI_INTF_IF_TYPE_2:
  7688. portstat_reg.word0 =
  7689. readl(phba->sli4_hba.u.if_type2.STATUSregaddr);
  7690. portsmphr = readl(phba->sli4_hba.PSMPHRregaddr);
  7691. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  7692. phba->work_status[0] =
  7693. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  7694. phba->work_status[1] =
  7695. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  7696. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7697. "2885 Port Error Detected: "
  7698. "port status reg 0x%x, "
  7699. "port smphr reg 0x%x, "
  7700. "error 1=0x%x, error 2=0x%x\n",
  7701. portstat_reg.word0,
  7702. portsmphr,
  7703. phba->work_status[0],
  7704. phba->work_status[1]);
  7705. phba->work_ha |= HA_ERATT;
  7706. phba->hba_flag |= HBA_ERATT_HANDLED;
  7707. return 1;
  7708. }
  7709. break;
  7710. case LPFC_SLI_INTF_IF_TYPE_1:
  7711. default:
  7712. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7713. "2886 HBA Error Attention on unsupported "
  7714. "if type %d.", if_type);
  7715. return 1;
  7716. }
  7717. return 0;
  7718. }
  7719. /**
  7720. * lpfc_sli_check_eratt - check error attention events
  7721. * @phba: Pointer to HBA context.
  7722. *
  7723. * This function is called from timer soft interrupt context to check HBA's
  7724. * error attention register bit for error attention events.
  7725. *
  7726. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7727. * Register and returns 0 otherwise.
  7728. **/
  7729. int
  7730. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7731. {
  7732. uint32_t ha_copy;
  7733. /* If somebody is waiting to handle an eratt, don't process it
  7734. * here. The brdkill function will do this.
  7735. */
  7736. if (phba->link_flag & LS_IGNORE_ERATT)
  7737. return 0;
  7738. /* Check if interrupt handler handles this ERATT */
  7739. spin_lock_irq(&phba->hbalock);
  7740. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7741. /* Interrupt handler has handled ERATT */
  7742. spin_unlock_irq(&phba->hbalock);
  7743. return 0;
  7744. }
  7745. /*
  7746. * If there is deferred error attention, do not check for error
  7747. * attention
  7748. */
  7749. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7750. spin_unlock_irq(&phba->hbalock);
  7751. return 0;
  7752. }
  7753. /* If PCI channel is offline, don't process it */
  7754. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7755. spin_unlock_irq(&phba->hbalock);
  7756. return 0;
  7757. }
  7758. switch (phba->sli_rev) {
  7759. case LPFC_SLI_REV2:
  7760. case LPFC_SLI_REV3:
  7761. /* Read chip Host Attention (HA) register */
  7762. ha_copy = lpfc_sli_eratt_read(phba);
  7763. break;
  7764. case LPFC_SLI_REV4:
  7765. /* Read device Uncoverable Error (UERR) registers */
  7766. ha_copy = lpfc_sli4_eratt_read(phba);
  7767. break;
  7768. default:
  7769. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7770. "0299 Invalid SLI revision (%d)\n",
  7771. phba->sli_rev);
  7772. ha_copy = 0;
  7773. break;
  7774. }
  7775. spin_unlock_irq(&phba->hbalock);
  7776. return ha_copy;
  7777. }
  7778. /**
  7779. * lpfc_intr_state_check - Check device state for interrupt handling
  7780. * @phba: Pointer to HBA context.
  7781. *
  7782. * This inline routine checks whether a device or its PCI slot is in a state
  7783. * that the interrupt should be handled.
  7784. *
  7785. * This function returns 0 if the device or the PCI slot is in a state that
  7786. * interrupt should be handled, otherwise -EIO.
  7787. */
  7788. static inline int
  7789. lpfc_intr_state_check(struct lpfc_hba *phba)
  7790. {
  7791. /* If the pci channel is offline, ignore all the interrupts */
  7792. if (unlikely(pci_channel_offline(phba->pcidev)))
  7793. return -EIO;
  7794. /* Update device level interrupt statistics */
  7795. phba->sli.slistat.sli_intr++;
  7796. /* Ignore all interrupts during initialization. */
  7797. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7798. return -EIO;
  7799. return 0;
  7800. }
  7801. /**
  7802. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7803. * @irq: Interrupt number.
  7804. * @dev_id: The device context pointer.
  7805. *
  7806. * This function is directly called from the PCI layer as an interrupt
  7807. * service routine when device with SLI-3 interface spec is enabled with
  7808. * MSI-X multi-message interrupt mode and there are slow-path events in
  7809. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7810. * interrupt mode, this function is called as part of the device-level
  7811. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7812. * is undergoing initialization, the interrupt handler will not process
  7813. * the interrupt. The link attention and ELS ring attention events are
  7814. * handled by the worker thread. The interrupt handler signals the worker
  7815. * thread and returns for these events. This function is called without
  7816. * any lock held. It gets the hbalock to access and update SLI data
  7817. * structures.
  7818. *
  7819. * This function returns IRQ_HANDLED when interrupt is handled else it
  7820. * returns IRQ_NONE.
  7821. **/
  7822. irqreturn_t
  7823. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7824. {
  7825. struct lpfc_hba *phba;
  7826. uint32_t ha_copy, hc_copy;
  7827. uint32_t work_ha_copy;
  7828. unsigned long status;
  7829. unsigned long iflag;
  7830. uint32_t control;
  7831. MAILBOX_t *mbox, *pmbox;
  7832. struct lpfc_vport *vport;
  7833. struct lpfc_nodelist *ndlp;
  7834. struct lpfc_dmabuf *mp;
  7835. LPFC_MBOXQ_t *pmb;
  7836. int rc;
  7837. /*
  7838. * Get the driver's phba structure from the dev_id and
  7839. * assume the HBA is not interrupting.
  7840. */
  7841. phba = (struct lpfc_hba *)dev_id;
  7842. if (unlikely(!phba))
  7843. return IRQ_NONE;
  7844. /*
  7845. * Stuff needs to be attented to when this function is invoked as an
  7846. * individual interrupt handler in MSI-X multi-message interrupt mode
  7847. */
  7848. if (phba->intr_type == MSIX) {
  7849. /* Check device state for handling interrupt */
  7850. if (lpfc_intr_state_check(phba))
  7851. return IRQ_NONE;
  7852. /* Need to read HA REG for slow-path events */
  7853. spin_lock_irqsave(&phba->hbalock, iflag);
  7854. ha_copy = readl(phba->HAregaddr);
  7855. /* If somebody is waiting to handle an eratt don't process it
  7856. * here. The brdkill function will do this.
  7857. */
  7858. if (phba->link_flag & LS_IGNORE_ERATT)
  7859. ha_copy &= ~HA_ERATT;
  7860. /* Check the need for handling ERATT in interrupt handler */
  7861. if (ha_copy & HA_ERATT) {
  7862. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7863. /* ERATT polling has handled ERATT */
  7864. ha_copy &= ~HA_ERATT;
  7865. else
  7866. /* Indicate interrupt handler handles ERATT */
  7867. phba->hba_flag |= HBA_ERATT_HANDLED;
  7868. }
  7869. /*
  7870. * If there is deferred error attention, do not check for any
  7871. * interrupt.
  7872. */
  7873. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7874. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7875. return IRQ_NONE;
  7876. }
  7877. /* Clear up only attention source related to slow-path */
  7878. hc_copy = readl(phba->HCregaddr);
  7879. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7880. HC_LAINT_ENA | HC_ERINT_ENA),
  7881. phba->HCregaddr);
  7882. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7883. phba->HAregaddr);
  7884. writel(hc_copy, phba->HCregaddr);
  7885. readl(phba->HAregaddr); /* flush */
  7886. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7887. } else
  7888. ha_copy = phba->ha_copy;
  7889. work_ha_copy = ha_copy & phba->work_ha_mask;
  7890. if (work_ha_copy) {
  7891. if (work_ha_copy & HA_LATT) {
  7892. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7893. /*
  7894. * Turn off Link Attention interrupts
  7895. * until CLEAR_LA done
  7896. */
  7897. spin_lock_irqsave(&phba->hbalock, iflag);
  7898. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7899. control = readl(phba->HCregaddr);
  7900. control &= ~HC_LAINT_ENA;
  7901. writel(control, phba->HCregaddr);
  7902. readl(phba->HCregaddr); /* flush */
  7903. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7904. }
  7905. else
  7906. work_ha_copy &= ~HA_LATT;
  7907. }
  7908. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7909. /*
  7910. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7911. * the only slow ring.
  7912. */
  7913. status = (work_ha_copy &
  7914. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7915. status >>= (4*LPFC_ELS_RING);
  7916. if (status & HA_RXMASK) {
  7917. spin_lock_irqsave(&phba->hbalock, iflag);
  7918. control = readl(phba->HCregaddr);
  7919. lpfc_debugfs_slow_ring_trc(phba,
  7920. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7921. control, status,
  7922. (uint32_t)phba->sli.slistat.sli_intr);
  7923. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7924. lpfc_debugfs_slow_ring_trc(phba,
  7925. "ISR Disable ring:"
  7926. "pwork:x%x hawork:x%x wait:x%x",
  7927. phba->work_ha, work_ha_copy,
  7928. (uint32_t)((unsigned long)
  7929. &phba->work_waitq));
  7930. control &=
  7931. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7932. writel(control, phba->HCregaddr);
  7933. readl(phba->HCregaddr); /* flush */
  7934. }
  7935. else {
  7936. lpfc_debugfs_slow_ring_trc(phba,
  7937. "ISR slow ring: pwork:"
  7938. "x%x hawork:x%x wait:x%x",
  7939. phba->work_ha, work_ha_copy,
  7940. (uint32_t)((unsigned long)
  7941. &phba->work_waitq));
  7942. }
  7943. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7944. }
  7945. }
  7946. spin_lock_irqsave(&phba->hbalock, iflag);
  7947. if (work_ha_copy & HA_ERATT) {
  7948. lpfc_sli_read_hs(phba);
  7949. /*
  7950. * Check if there is a deferred error condition
  7951. * is active
  7952. */
  7953. if ((HS_FFER1 & phba->work_hs) &&
  7954. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7955. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  7956. phba->work_hs)) {
  7957. phba->hba_flag |= DEFER_ERATT;
  7958. /* Clear all interrupt enable conditions */
  7959. writel(0, phba->HCregaddr);
  7960. readl(phba->HCregaddr);
  7961. }
  7962. }
  7963. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7964. pmb = phba->sli.mbox_active;
  7965. pmbox = &pmb->u.mb;
  7966. mbox = phba->mbox;
  7967. vport = pmb->vport;
  7968. /* First check out the status word */
  7969. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7970. if (pmbox->mbxOwner != OWN_HOST) {
  7971. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7972. /*
  7973. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7974. * mbxStatus <status>
  7975. */
  7976. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7977. LOG_SLI,
  7978. "(%d):0304 Stray Mailbox "
  7979. "Interrupt mbxCommand x%x "
  7980. "mbxStatus x%x\n",
  7981. (vport ? vport->vpi : 0),
  7982. pmbox->mbxCommand,
  7983. pmbox->mbxStatus);
  7984. /* clear mailbox attention bit */
  7985. work_ha_copy &= ~HA_MBATT;
  7986. } else {
  7987. phba->sli.mbox_active = NULL;
  7988. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7989. phba->last_completion_time = jiffies;
  7990. del_timer(&phba->sli.mbox_tmo);
  7991. if (pmb->mbox_cmpl) {
  7992. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7993. MAILBOX_CMD_SIZE);
  7994. if (pmb->out_ext_byte_len &&
  7995. pmb->context2)
  7996. lpfc_sli_pcimem_bcopy(
  7997. phba->mbox_ext,
  7998. pmb->context2,
  7999. pmb->out_ext_byte_len);
  8000. }
  8001. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8002. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8003. lpfc_debugfs_disc_trc(vport,
  8004. LPFC_DISC_TRC_MBOX_VPORT,
  8005. "MBOX dflt rpi: : "
  8006. "status:x%x rpi:x%x",
  8007. (uint32_t)pmbox->mbxStatus,
  8008. pmbox->un.varWords[0], 0);
  8009. if (!pmbox->mbxStatus) {
  8010. mp = (struct lpfc_dmabuf *)
  8011. (pmb->context1);
  8012. ndlp = (struct lpfc_nodelist *)
  8013. pmb->context2;
  8014. /* Reg_LOGIN of dflt RPI was
  8015. * successful. new lets get
  8016. * rid of the RPI using the
  8017. * same mbox buffer.
  8018. */
  8019. lpfc_unreg_login(phba,
  8020. vport->vpi,
  8021. pmbox->un.varWords[0],
  8022. pmb);
  8023. pmb->mbox_cmpl =
  8024. lpfc_mbx_cmpl_dflt_rpi;
  8025. pmb->context1 = mp;
  8026. pmb->context2 = ndlp;
  8027. pmb->vport = vport;
  8028. rc = lpfc_sli_issue_mbox(phba,
  8029. pmb,
  8030. MBX_NOWAIT);
  8031. if (rc != MBX_BUSY)
  8032. lpfc_printf_log(phba,
  8033. KERN_ERR,
  8034. LOG_MBOX | LOG_SLI,
  8035. "0350 rc should have"
  8036. "been MBX_BUSY\n");
  8037. if (rc != MBX_NOT_FINISHED)
  8038. goto send_current_mbox;
  8039. }
  8040. }
  8041. spin_lock_irqsave(
  8042. &phba->pport->work_port_lock,
  8043. iflag);
  8044. phba->pport->work_port_events &=
  8045. ~WORKER_MBOX_TMO;
  8046. spin_unlock_irqrestore(
  8047. &phba->pport->work_port_lock,
  8048. iflag);
  8049. lpfc_mbox_cmpl_put(phba, pmb);
  8050. }
  8051. } else
  8052. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8053. if ((work_ha_copy & HA_MBATT) &&
  8054. (phba->sli.mbox_active == NULL)) {
  8055. send_current_mbox:
  8056. /* Process next mailbox command if there is one */
  8057. do {
  8058. rc = lpfc_sli_issue_mbox(phba, NULL,
  8059. MBX_NOWAIT);
  8060. } while (rc == MBX_NOT_FINISHED);
  8061. if (rc != MBX_SUCCESS)
  8062. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8063. LOG_SLI, "0349 rc should be "
  8064. "MBX_SUCCESS\n");
  8065. }
  8066. spin_lock_irqsave(&phba->hbalock, iflag);
  8067. phba->work_ha |= work_ha_copy;
  8068. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8069. lpfc_worker_wake_up(phba);
  8070. }
  8071. return IRQ_HANDLED;
  8072. } /* lpfc_sli_sp_intr_handler */
  8073. /**
  8074. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  8075. * @irq: Interrupt number.
  8076. * @dev_id: The device context pointer.
  8077. *
  8078. * This function is directly called from the PCI layer as an interrupt
  8079. * service routine when device with SLI-3 interface spec is enabled with
  8080. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8081. * ring event in the HBA. However, when the device is enabled with either
  8082. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8083. * device-level interrupt handler. When the PCI slot is in error recovery
  8084. * or the HBA is undergoing initialization, the interrupt handler will not
  8085. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8086. * the intrrupt context. This function is called without any lock held.
  8087. * It gets the hbalock to access and update SLI data structures.
  8088. *
  8089. * This function returns IRQ_HANDLED when interrupt is handled else it
  8090. * returns IRQ_NONE.
  8091. **/
  8092. irqreturn_t
  8093. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  8094. {
  8095. struct lpfc_hba *phba;
  8096. uint32_t ha_copy;
  8097. unsigned long status;
  8098. unsigned long iflag;
  8099. /* Get the driver's phba structure from the dev_id and
  8100. * assume the HBA is not interrupting.
  8101. */
  8102. phba = (struct lpfc_hba *) dev_id;
  8103. if (unlikely(!phba))
  8104. return IRQ_NONE;
  8105. /*
  8106. * Stuff needs to be attented to when this function is invoked as an
  8107. * individual interrupt handler in MSI-X multi-message interrupt mode
  8108. */
  8109. if (phba->intr_type == MSIX) {
  8110. /* Check device state for handling interrupt */
  8111. if (lpfc_intr_state_check(phba))
  8112. return IRQ_NONE;
  8113. /* Need to read HA REG for FCP ring and other ring events */
  8114. ha_copy = readl(phba->HAregaddr);
  8115. /* Clear up only attention source related to fast-path */
  8116. spin_lock_irqsave(&phba->hbalock, iflag);
  8117. /*
  8118. * If there is deferred error attention, do not check for
  8119. * any interrupt.
  8120. */
  8121. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8122. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8123. return IRQ_NONE;
  8124. }
  8125. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  8126. phba->HAregaddr);
  8127. readl(phba->HAregaddr); /* flush */
  8128. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8129. } else
  8130. ha_copy = phba->ha_copy;
  8131. /*
  8132. * Process all events on FCP ring. Take the optimized path for FCP IO.
  8133. */
  8134. ha_copy &= ~(phba->work_ha_mask);
  8135. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8136. status >>= (4*LPFC_FCP_RING);
  8137. if (status & HA_RXMASK)
  8138. lpfc_sli_handle_fast_ring_event(phba,
  8139. &phba->sli.ring[LPFC_FCP_RING],
  8140. status);
  8141. if (phba->cfg_multi_ring_support == 2) {
  8142. /*
  8143. * Process all events on extra ring. Take the optimized path
  8144. * for extra ring IO.
  8145. */
  8146. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8147. status >>= (4*LPFC_EXTRA_RING);
  8148. if (status & HA_RXMASK) {
  8149. lpfc_sli_handle_fast_ring_event(phba,
  8150. &phba->sli.ring[LPFC_EXTRA_RING],
  8151. status);
  8152. }
  8153. }
  8154. return IRQ_HANDLED;
  8155. } /* lpfc_sli_fp_intr_handler */
  8156. /**
  8157. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  8158. * @irq: Interrupt number.
  8159. * @dev_id: The device context pointer.
  8160. *
  8161. * This function is the HBA device-level interrupt handler to device with
  8162. * SLI-3 interface spec, called from the PCI layer when either MSI or
  8163. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  8164. * requires driver attention. This function invokes the slow-path interrupt
  8165. * attention handling function and fast-path interrupt attention handling
  8166. * function in turn to process the relevant HBA attention events. This
  8167. * function is called without any lock held. It gets the hbalock to access
  8168. * and update SLI data structures.
  8169. *
  8170. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8171. * returns IRQ_NONE.
  8172. **/
  8173. irqreturn_t
  8174. lpfc_sli_intr_handler(int irq, void *dev_id)
  8175. {
  8176. struct lpfc_hba *phba;
  8177. irqreturn_t sp_irq_rc, fp_irq_rc;
  8178. unsigned long status1, status2;
  8179. uint32_t hc_copy;
  8180. /*
  8181. * Get the driver's phba structure from the dev_id and
  8182. * assume the HBA is not interrupting.
  8183. */
  8184. phba = (struct lpfc_hba *) dev_id;
  8185. if (unlikely(!phba))
  8186. return IRQ_NONE;
  8187. /* Check device state for handling interrupt */
  8188. if (lpfc_intr_state_check(phba))
  8189. return IRQ_NONE;
  8190. spin_lock(&phba->hbalock);
  8191. phba->ha_copy = readl(phba->HAregaddr);
  8192. if (unlikely(!phba->ha_copy)) {
  8193. spin_unlock(&phba->hbalock);
  8194. return IRQ_NONE;
  8195. } else if (phba->ha_copy & HA_ERATT) {
  8196. if (phba->hba_flag & HBA_ERATT_HANDLED)
  8197. /* ERATT polling has handled ERATT */
  8198. phba->ha_copy &= ~HA_ERATT;
  8199. else
  8200. /* Indicate interrupt handler handles ERATT */
  8201. phba->hba_flag |= HBA_ERATT_HANDLED;
  8202. }
  8203. /*
  8204. * If there is deferred error attention, do not check for any interrupt.
  8205. */
  8206. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8207. spin_unlock(&phba->hbalock);
  8208. return IRQ_NONE;
  8209. }
  8210. /* Clear attention sources except link and error attentions */
  8211. hc_copy = readl(phba->HCregaddr);
  8212. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  8213. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  8214. phba->HCregaddr);
  8215. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  8216. writel(hc_copy, phba->HCregaddr);
  8217. readl(phba->HAregaddr); /* flush */
  8218. spin_unlock(&phba->hbalock);
  8219. /*
  8220. * Invokes slow-path host attention interrupt handling as appropriate.
  8221. */
  8222. /* status of events with mailbox and link attention */
  8223. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  8224. /* status of events with ELS ring */
  8225. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  8226. status2 >>= (4*LPFC_ELS_RING);
  8227. if (status1 || (status2 & HA_RXMASK))
  8228. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  8229. else
  8230. sp_irq_rc = IRQ_NONE;
  8231. /*
  8232. * Invoke fast-path host attention interrupt handling as appropriate.
  8233. */
  8234. /* status of events with FCP ring */
  8235. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8236. status1 >>= (4*LPFC_FCP_RING);
  8237. /* status of events with extra ring */
  8238. if (phba->cfg_multi_ring_support == 2) {
  8239. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8240. status2 >>= (4*LPFC_EXTRA_RING);
  8241. } else
  8242. status2 = 0;
  8243. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  8244. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  8245. else
  8246. fp_irq_rc = IRQ_NONE;
  8247. /* Return device-level interrupt handling status */
  8248. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  8249. } /* lpfc_sli_intr_handler */
  8250. /**
  8251. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  8252. * @phba: pointer to lpfc hba data structure.
  8253. *
  8254. * This routine is invoked by the worker thread to process all the pending
  8255. * SLI4 FCP abort XRI events.
  8256. **/
  8257. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  8258. {
  8259. struct lpfc_cq_event *cq_event;
  8260. /* First, declare the fcp xri abort event has been handled */
  8261. spin_lock_irq(&phba->hbalock);
  8262. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  8263. spin_unlock_irq(&phba->hbalock);
  8264. /* Now, handle all the fcp xri abort events */
  8265. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  8266. /* Get the first event from the head of the event queue */
  8267. spin_lock_irq(&phba->hbalock);
  8268. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  8269. cq_event, struct lpfc_cq_event, list);
  8270. spin_unlock_irq(&phba->hbalock);
  8271. /* Notify aborted XRI for FCP work queue */
  8272. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8273. /* Free the event processed back to the free pool */
  8274. lpfc_sli4_cq_event_release(phba, cq_event);
  8275. }
  8276. }
  8277. /**
  8278. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  8279. * @phba: pointer to lpfc hba data structure.
  8280. *
  8281. * This routine is invoked by the worker thread to process all the pending
  8282. * SLI4 els abort xri events.
  8283. **/
  8284. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  8285. {
  8286. struct lpfc_cq_event *cq_event;
  8287. /* First, declare the els xri abort event has been handled */
  8288. spin_lock_irq(&phba->hbalock);
  8289. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  8290. spin_unlock_irq(&phba->hbalock);
  8291. /* Now, handle all the els xri abort events */
  8292. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  8293. /* Get the first event from the head of the event queue */
  8294. spin_lock_irq(&phba->hbalock);
  8295. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  8296. cq_event, struct lpfc_cq_event, list);
  8297. spin_unlock_irq(&phba->hbalock);
  8298. /* Notify aborted XRI for ELS work queue */
  8299. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8300. /* Free the event processed back to the free pool */
  8301. lpfc_sli4_cq_event_release(phba, cq_event);
  8302. }
  8303. }
  8304. /**
  8305. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  8306. * @phba: pointer to lpfc hba data structure
  8307. * @pIocbIn: pointer to the rspiocbq
  8308. * @pIocbOut: pointer to the cmdiocbq
  8309. * @wcqe: pointer to the complete wcqe
  8310. *
  8311. * This routine transfers the fields of a command iocbq to a response iocbq
  8312. * by copying all the IOCB fields from command iocbq and transferring the
  8313. * completion status information from the complete wcqe.
  8314. **/
  8315. static void
  8316. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  8317. struct lpfc_iocbq *pIocbIn,
  8318. struct lpfc_iocbq *pIocbOut,
  8319. struct lpfc_wcqe_complete *wcqe)
  8320. {
  8321. unsigned long iflags;
  8322. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  8323. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  8324. sizeof(struct lpfc_iocbq) - offset);
  8325. /* Map WCQE parameters into irspiocb parameters */
  8326. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  8327. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  8328. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  8329. pIocbIn->iocb.un.fcpi.fcpi_parm =
  8330. pIocbOut->iocb.un.fcpi.fcpi_parm -
  8331. wcqe->total_data_placed;
  8332. else
  8333. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8334. else {
  8335. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8336. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  8337. }
  8338. /* Pick up HBA exchange busy condition */
  8339. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  8340. spin_lock_irqsave(&phba->hbalock, iflags);
  8341. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  8342. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8343. }
  8344. }
  8345. /**
  8346. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  8347. * @phba: Pointer to HBA context object.
  8348. * @wcqe: Pointer to work-queue completion queue entry.
  8349. *
  8350. * This routine handles an ELS work-queue completion event and construct
  8351. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  8352. * discovery engine to handle.
  8353. *
  8354. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  8355. **/
  8356. static struct lpfc_iocbq *
  8357. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  8358. struct lpfc_iocbq *irspiocbq)
  8359. {
  8360. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8361. struct lpfc_iocbq *cmdiocbq;
  8362. struct lpfc_wcqe_complete *wcqe;
  8363. unsigned long iflags;
  8364. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  8365. spin_lock_irqsave(&phba->hbalock, iflags);
  8366. pring->stats.iocb_event++;
  8367. /* Look up the ELS command IOCB and create pseudo response IOCB */
  8368. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8369. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8370. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8371. if (unlikely(!cmdiocbq)) {
  8372. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8373. "0386 ELS complete with no corresponding "
  8374. "cmdiocb: iotag (%d)\n",
  8375. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8376. lpfc_sli_release_iocbq(phba, irspiocbq);
  8377. return NULL;
  8378. }
  8379. /* Fake the irspiocbq and copy necessary response information */
  8380. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  8381. return irspiocbq;
  8382. }
  8383. /**
  8384. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  8385. * @phba: Pointer to HBA context object.
  8386. * @cqe: Pointer to mailbox completion queue entry.
  8387. *
  8388. * This routine process a mailbox completion queue entry with asynchrous
  8389. * event.
  8390. *
  8391. * Return: true if work posted to worker thread, otherwise false.
  8392. **/
  8393. static bool
  8394. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8395. {
  8396. struct lpfc_cq_event *cq_event;
  8397. unsigned long iflags;
  8398. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8399. "0392 Async Event: word0:x%x, word1:x%x, "
  8400. "word2:x%x, word3:x%x\n", mcqe->word0,
  8401. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  8402. /* Allocate a new internal CQ_EVENT entry */
  8403. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8404. if (!cq_event) {
  8405. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8406. "0394 Failed to allocate CQ_EVENT entry\n");
  8407. return false;
  8408. }
  8409. /* Move the CQE into an asynchronous event entry */
  8410. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  8411. spin_lock_irqsave(&phba->hbalock, iflags);
  8412. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  8413. /* Set the async event flag */
  8414. phba->hba_flag |= ASYNC_EVENT;
  8415. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8416. return true;
  8417. }
  8418. /**
  8419. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  8420. * @phba: Pointer to HBA context object.
  8421. * @cqe: Pointer to mailbox completion queue entry.
  8422. *
  8423. * This routine process a mailbox completion queue entry with mailbox
  8424. * completion event.
  8425. *
  8426. * Return: true if work posted to worker thread, otherwise false.
  8427. **/
  8428. static bool
  8429. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8430. {
  8431. uint32_t mcqe_status;
  8432. MAILBOX_t *mbox, *pmbox;
  8433. struct lpfc_mqe *mqe;
  8434. struct lpfc_vport *vport;
  8435. struct lpfc_nodelist *ndlp;
  8436. struct lpfc_dmabuf *mp;
  8437. unsigned long iflags;
  8438. LPFC_MBOXQ_t *pmb;
  8439. bool workposted = false;
  8440. int rc;
  8441. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  8442. if (!bf_get(lpfc_trailer_completed, mcqe))
  8443. goto out_no_mqe_complete;
  8444. /* Get the reference to the active mbox command */
  8445. spin_lock_irqsave(&phba->hbalock, iflags);
  8446. pmb = phba->sli.mbox_active;
  8447. if (unlikely(!pmb)) {
  8448. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  8449. "1832 No pending MBOX command to handle\n");
  8450. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8451. goto out_no_mqe_complete;
  8452. }
  8453. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8454. mqe = &pmb->u.mqe;
  8455. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  8456. mbox = phba->mbox;
  8457. vport = pmb->vport;
  8458. /* Reset heartbeat timer */
  8459. phba->last_completion_time = jiffies;
  8460. del_timer(&phba->sli.mbox_tmo);
  8461. /* Move mbox data to caller's mailbox region, do endian swapping */
  8462. if (pmb->mbox_cmpl && mbox)
  8463. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  8464. /* Set the mailbox status with SLI4 range 0x4000 */
  8465. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  8466. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  8467. bf_set(lpfc_mqe_status, mqe,
  8468. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  8469. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8470. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8471. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  8472. "MBOX dflt rpi: status:x%x rpi:x%x",
  8473. mcqe_status,
  8474. pmbox->un.varWords[0], 0);
  8475. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  8476. mp = (struct lpfc_dmabuf *)(pmb->context1);
  8477. ndlp = (struct lpfc_nodelist *)pmb->context2;
  8478. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  8479. * RID of the PPI using the same mbox buffer.
  8480. */
  8481. lpfc_unreg_login(phba, vport->vpi,
  8482. pmbox->un.varWords[0], pmb);
  8483. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  8484. pmb->context1 = mp;
  8485. pmb->context2 = ndlp;
  8486. pmb->vport = vport;
  8487. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  8488. if (rc != MBX_BUSY)
  8489. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8490. LOG_SLI, "0385 rc should "
  8491. "have been MBX_BUSY\n");
  8492. if (rc != MBX_NOT_FINISHED)
  8493. goto send_current_mbox;
  8494. }
  8495. }
  8496. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  8497. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8498. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  8499. /* There is mailbox completion work to do */
  8500. spin_lock_irqsave(&phba->hbalock, iflags);
  8501. __lpfc_mbox_cmpl_put(phba, pmb);
  8502. phba->work_ha |= HA_MBATT;
  8503. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8504. workposted = true;
  8505. send_current_mbox:
  8506. spin_lock_irqsave(&phba->hbalock, iflags);
  8507. /* Release the mailbox command posting token */
  8508. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8509. /* Setting active mailbox pointer need to be in sync to flag clear */
  8510. phba->sli.mbox_active = NULL;
  8511. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8512. /* Wake up worker thread to post the next pending mailbox command */
  8513. lpfc_worker_wake_up(phba);
  8514. out_no_mqe_complete:
  8515. if (bf_get(lpfc_trailer_consumed, mcqe))
  8516. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  8517. return workposted;
  8518. }
  8519. /**
  8520. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  8521. * @phba: Pointer to HBA context object.
  8522. * @cqe: Pointer to mailbox completion queue entry.
  8523. *
  8524. * This routine process a mailbox completion queue entry, it invokes the
  8525. * proper mailbox complete handling or asynchrous event handling routine
  8526. * according to the MCQE's async bit.
  8527. *
  8528. * Return: true if work posted to worker thread, otherwise false.
  8529. **/
  8530. static bool
  8531. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8532. {
  8533. struct lpfc_mcqe mcqe;
  8534. bool workposted;
  8535. /* Copy the mailbox MCQE and convert endian order as needed */
  8536. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8537. /* Invoke the proper event handling routine */
  8538. if (!bf_get(lpfc_trailer_async, &mcqe))
  8539. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8540. else
  8541. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8542. return workposted;
  8543. }
  8544. /**
  8545. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8546. * @phba: Pointer to HBA context object.
  8547. * @wcqe: Pointer to work-queue completion queue entry.
  8548. *
  8549. * This routine handles an ELS work-queue completion event.
  8550. *
  8551. * Return: true if work posted to worker thread, otherwise false.
  8552. **/
  8553. static bool
  8554. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8555. struct lpfc_wcqe_complete *wcqe)
  8556. {
  8557. struct lpfc_iocbq *irspiocbq;
  8558. unsigned long iflags;
  8559. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8560. /* Get an irspiocbq for later ELS response processing use */
  8561. irspiocbq = lpfc_sli_get_iocbq(phba);
  8562. if (!irspiocbq) {
  8563. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8564. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8565. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8566. pring->txq_cnt, phba->iocb_cnt,
  8567. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8568. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8569. return false;
  8570. }
  8571. /* Save off the slow-path queue event for work thread to process */
  8572. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8573. spin_lock_irqsave(&phba->hbalock, iflags);
  8574. list_add_tail(&irspiocbq->cq_event.list,
  8575. &phba->sli4_hba.sp_queue_event);
  8576. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8577. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8578. return true;
  8579. }
  8580. /**
  8581. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8582. * @phba: Pointer to HBA context object.
  8583. * @wcqe: Pointer to work-queue completion queue entry.
  8584. *
  8585. * This routine handles slow-path WQ entry comsumed event by invoking the
  8586. * proper WQ release routine to the slow-path WQ.
  8587. **/
  8588. static void
  8589. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8590. struct lpfc_wcqe_release *wcqe)
  8591. {
  8592. /* Check for the slow-path ELS work queue */
  8593. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8594. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8595. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8596. else
  8597. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8598. "2579 Slow-path wqe consume event carries "
  8599. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8600. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8601. phba->sli4_hba.els_wq->queue_id);
  8602. }
  8603. /**
  8604. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8605. * @phba: Pointer to HBA context object.
  8606. * @cq: Pointer to a WQ completion queue.
  8607. * @wcqe: Pointer to work-queue completion queue entry.
  8608. *
  8609. * This routine handles an XRI abort event.
  8610. *
  8611. * Return: true if work posted to worker thread, otherwise false.
  8612. **/
  8613. static bool
  8614. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8615. struct lpfc_queue *cq,
  8616. struct sli4_wcqe_xri_aborted *wcqe)
  8617. {
  8618. bool workposted = false;
  8619. struct lpfc_cq_event *cq_event;
  8620. unsigned long iflags;
  8621. /* Allocate a new internal CQ_EVENT entry */
  8622. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8623. if (!cq_event) {
  8624. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8625. "0602 Failed to allocate CQ_EVENT entry\n");
  8626. return false;
  8627. }
  8628. /* Move the CQE into the proper xri abort event list */
  8629. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8630. switch (cq->subtype) {
  8631. case LPFC_FCP:
  8632. spin_lock_irqsave(&phba->hbalock, iflags);
  8633. list_add_tail(&cq_event->list,
  8634. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8635. /* Set the fcp xri abort event flag */
  8636. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8637. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8638. workposted = true;
  8639. break;
  8640. case LPFC_ELS:
  8641. spin_lock_irqsave(&phba->hbalock, iflags);
  8642. list_add_tail(&cq_event->list,
  8643. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8644. /* Set the els xri abort event flag */
  8645. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8646. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8647. workposted = true;
  8648. break;
  8649. default:
  8650. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8651. "0603 Invalid work queue CQE subtype (x%x)\n",
  8652. cq->subtype);
  8653. workposted = false;
  8654. break;
  8655. }
  8656. return workposted;
  8657. }
  8658. /**
  8659. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8660. * @phba: Pointer to HBA context object.
  8661. * @rcqe: Pointer to receive-queue completion queue entry.
  8662. *
  8663. * This routine process a receive-queue completion queue entry.
  8664. *
  8665. * Return: true if work posted to worker thread, otherwise false.
  8666. **/
  8667. static bool
  8668. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8669. {
  8670. bool workposted = false;
  8671. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8672. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8673. struct hbq_dmabuf *dma_buf;
  8674. uint32_t status;
  8675. unsigned long iflags;
  8676. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8677. goto out;
  8678. status = bf_get(lpfc_rcqe_status, rcqe);
  8679. switch (status) {
  8680. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8681. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8682. "2537 Receive Frame Truncated!!\n");
  8683. case FC_STATUS_RQ_SUCCESS:
  8684. lpfc_sli4_rq_release(hrq, drq);
  8685. spin_lock_irqsave(&phba->hbalock, iflags);
  8686. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8687. if (!dma_buf) {
  8688. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8689. goto out;
  8690. }
  8691. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8692. /* save off the frame for the word thread to process */
  8693. list_add_tail(&dma_buf->cq_event.list,
  8694. &phba->sli4_hba.sp_queue_event);
  8695. /* Frame received */
  8696. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8697. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8698. workposted = true;
  8699. break;
  8700. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8701. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8702. /* Post more buffers if possible */
  8703. spin_lock_irqsave(&phba->hbalock, iflags);
  8704. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8705. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8706. workposted = true;
  8707. break;
  8708. }
  8709. out:
  8710. return workposted;
  8711. }
  8712. /**
  8713. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8714. * @phba: Pointer to HBA context object.
  8715. * @cq: Pointer to the completion queue.
  8716. * @wcqe: Pointer to a completion queue entry.
  8717. *
  8718. * This routine process a slow-path work-queue or recieve queue completion queue
  8719. * entry.
  8720. *
  8721. * Return: true if work posted to worker thread, otherwise false.
  8722. **/
  8723. static bool
  8724. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8725. struct lpfc_cqe *cqe)
  8726. {
  8727. struct lpfc_cqe cqevt;
  8728. bool workposted = false;
  8729. /* Copy the work queue CQE and convert endian order if needed */
  8730. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8731. /* Check and process for different type of WCQE and dispatch */
  8732. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8733. case CQE_CODE_COMPL_WQE:
  8734. /* Process the WQ/RQ complete event */
  8735. phba->last_completion_time = jiffies;
  8736. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8737. (struct lpfc_wcqe_complete *)&cqevt);
  8738. break;
  8739. case CQE_CODE_RELEASE_WQE:
  8740. /* Process the WQ release event */
  8741. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8742. (struct lpfc_wcqe_release *)&cqevt);
  8743. break;
  8744. case CQE_CODE_XRI_ABORTED:
  8745. /* Process the WQ XRI abort event */
  8746. phba->last_completion_time = jiffies;
  8747. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8748. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8749. break;
  8750. case CQE_CODE_RECEIVE:
  8751. /* Process the RQ event */
  8752. phba->last_completion_time = jiffies;
  8753. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8754. (struct lpfc_rcqe *)&cqevt);
  8755. break;
  8756. default:
  8757. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8758. "0388 Not a valid WCQE code: x%x\n",
  8759. bf_get(lpfc_cqe_code, &cqevt));
  8760. break;
  8761. }
  8762. return workposted;
  8763. }
  8764. /**
  8765. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8766. * @phba: Pointer to HBA context object.
  8767. * @eqe: Pointer to fast-path event queue entry.
  8768. *
  8769. * This routine process a event queue entry from the slow-path event queue.
  8770. * It will check the MajorCode and MinorCode to determine this is for a
  8771. * completion event on a completion queue, if not, an error shall be logged
  8772. * and just return. Otherwise, it will get to the corresponding completion
  8773. * queue and process all the entries on that completion queue, rearm the
  8774. * completion queue, and then return.
  8775. *
  8776. **/
  8777. static void
  8778. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8779. {
  8780. struct lpfc_queue *cq = NULL, *childq, *speq;
  8781. struct lpfc_cqe *cqe;
  8782. bool workposted = false;
  8783. int ecount = 0;
  8784. uint16_t cqid;
  8785. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8786. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8787. "0359 Not a valid slow-path completion "
  8788. "event: majorcode=x%x, minorcode=x%x\n",
  8789. bf_get_le32(lpfc_eqe_major_code, eqe),
  8790. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8791. return;
  8792. }
  8793. /* Get the reference to the corresponding CQ */
  8794. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8795. /* Search for completion queue pointer matching this cqid */
  8796. speq = phba->sli4_hba.sp_eq;
  8797. list_for_each_entry(childq, &speq->child_list, list) {
  8798. if (childq->queue_id == cqid) {
  8799. cq = childq;
  8800. break;
  8801. }
  8802. }
  8803. if (unlikely(!cq)) {
  8804. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8805. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8806. "0365 Slow-path CQ identifier "
  8807. "(%d) does not exist\n", cqid);
  8808. return;
  8809. }
  8810. /* Process all the entries to the CQ */
  8811. switch (cq->type) {
  8812. case LPFC_MCQ:
  8813. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8814. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8815. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8816. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8817. }
  8818. break;
  8819. case LPFC_WCQ:
  8820. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8821. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8822. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8823. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8824. }
  8825. break;
  8826. default:
  8827. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8828. "0370 Invalid completion queue type (%d)\n",
  8829. cq->type);
  8830. return;
  8831. }
  8832. /* Catch the no cq entry condition, log an error */
  8833. if (unlikely(ecount == 0))
  8834. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8835. "0371 No entry from the CQ: identifier "
  8836. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8837. /* In any case, flash and re-arm the RCQ */
  8838. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8839. /* wake up worker thread if there are works to be done */
  8840. if (workposted)
  8841. lpfc_worker_wake_up(phba);
  8842. }
  8843. /**
  8844. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8845. * @eqe: Pointer to fast-path completion queue entry.
  8846. *
  8847. * This routine process a fast-path work queue completion entry from fast-path
  8848. * event queue for FCP command response completion.
  8849. **/
  8850. static void
  8851. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8852. struct lpfc_wcqe_complete *wcqe)
  8853. {
  8854. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8855. struct lpfc_iocbq *cmdiocbq;
  8856. struct lpfc_iocbq irspiocbq;
  8857. unsigned long iflags;
  8858. spin_lock_irqsave(&phba->hbalock, iflags);
  8859. pring->stats.iocb_event++;
  8860. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8861. /* Check for response status */
  8862. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8863. /* If resource errors reported from HBA, reduce queue
  8864. * depth of the SCSI device.
  8865. */
  8866. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8867. IOSTAT_LOCAL_REJECT) &&
  8868. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8869. phba->lpfc_rampdown_queue_depth(phba);
  8870. }
  8871. /* Log the error status */
  8872. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8873. "0373 FCP complete error: status=x%x, "
  8874. "hw_status=x%x, total_data_specified=%d, "
  8875. "parameter=x%x, word3=x%x\n",
  8876. bf_get(lpfc_wcqe_c_status, wcqe),
  8877. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8878. wcqe->total_data_placed, wcqe->parameter,
  8879. wcqe->word3);
  8880. }
  8881. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8882. spin_lock_irqsave(&phba->hbalock, iflags);
  8883. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8884. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8885. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8886. if (unlikely(!cmdiocbq)) {
  8887. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8888. "0374 FCP complete with no corresponding "
  8889. "cmdiocb: iotag (%d)\n",
  8890. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8891. return;
  8892. }
  8893. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8894. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8895. "0375 FCP cmdiocb not callback function "
  8896. "iotag: (%d)\n",
  8897. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8898. return;
  8899. }
  8900. /* Fake the irspiocb and copy necessary response information */
  8901. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8902. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8903. spin_lock_irqsave(&phba->hbalock, iflags);
  8904. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8905. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8906. }
  8907. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8908. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8909. }
  8910. /**
  8911. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8912. * @phba: Pointer to HBA context object.
  8913. * @cq: Pointer to completion queue.
  8914. * @wcqe: Pointer to work-queue completion queue entry.
  8915. *
  8916. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8917. * proper WQ release routine to the slow-path WQ.
  8918. **/
  8919. static void
  8920. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8921. struct lpfc_wcqe_release *wcqe)
  8922. {
  8923. struct lpfc_queue *childwq;
  8924. bool wqid_matched = false;
  8925. uint16_t fcp_wqid;
  8926. /* Check for fast-path FCP work queue release */
  8927. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8928. list_for_each_entry(childwq, &cq->child_list, list) {
  8929. if (childwq->queue_id == fcp_wqid) {
  8930. lpfc_sli4_wq_release(childwq,
  8931. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8932. wqid_matched = true;
  8933. break;
  8934. }
  8935. }
  8936. /* Report warning log message if no match found */
  8937. if (wqid_matched != true)
  8938. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8939. "2580 Fast-path wqe consume event carries "
  8940. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8941. }
  8942. /**
  8943. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8944. * @cq: Pointer to the completion queue.
  8945. * @eqe: Pointer to fast-path completion queue entry.
  8946. *
  8947. * This routine process a fast-path work queue completion entry from fast-path
  8948. * event queue for FCP command response completion.
  8949. **/
  8950. static int
  8951. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8952. struct lpfc_cqe *cqe)
  8953. {
  8954. struct lpfc_wcqe_release wcqe;
  8955. bool workposted = false;
  8956. /* Copy the work queue CQE and convert endian order if needed */
  8957. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8958. /* Check and process for different type of WCQE and dispatch */
  8959. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8960. case CQE_CODE_COMPL_WQE:
  8961. /* Process the WQ complete event */
  8962. phba->last_completion_time = jiffies;
  8963. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8964. (struct lpfc_wcqe_complete *)&wcqe);
  8965. break;
  8966. case CQE_CODE_RELEASE_WQE:
  8967. /* Process the WQ release event */
  8968. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8969. (struct lpfc_wcqe_release *)&wcqe);
  8970. break;
  8971. case CQE_CODE_XRI_ABORTED:
  8972. /* Process the WQ XRI abort event */
  8973. phba->last_completion_time = jiffies;
  8974. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8975. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8976. break;
  8977. default:
  8978. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8979. "0144 Not a valid WCQE code: x%x\n",
  8980. bf_get(lpfc_wcqe_c_code, &wcqe));
  8981. break;
  8982. }
  8983. return workposted;
  8984. }
  8985. /**
  8986. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8987. * @phba: Pointer to HBA context object.
  8988. * @eqe: Pointer to fast-path event queue entry.
  8989. *
  8990. * This routine process a event queue entry from the fast-path event queue.
  8991. * It will check the MajorCode and MinorCode to determine this is for a
  8992. * completion event on a completion queue, if not, an error shall be logged
  8993. * and just return. Otherwise, it will get to the corresponding completion
  8994. * queue and process all the entries on the completion queue, rearm the
  8995. * completion queue, and then return.
  8996. **/
  8997. static void
  8998. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8999. uint32_t fcp_cqidx)
  9000. {
  9001. struct lpfc_queue *cq;
  9002. struct lpfc_cqe *cqe;
  9003. bool workposted = false;
  9004. uint16_t cqid;
  9005. int ecount = 0;
  9006. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  9007. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9008. "0366 Not a valid fast-path completion "
  9009. "event: majorcode=x%x, minorcode=x%x\n",
  9010. bf_get_le32(lpfc_eqe_major_code, eqe),
  9011. bf_get_le32(lpfc_eqe_minor_code, eqe));
  9012. return;
  9013. }
  9014. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  9015. if (unlikely(!cq)) {
  9016. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  9017. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9018. "0367 Fast-path completion queue "
  9019. "does not exist\n");
  9020. return;
  9021. }
  9022. /* Get the reference to the corresponding CQ */
  9023. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  9024. if (unlikely(cqid != cq->queue_id)) {
  9025. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9026. "0368 Miss-matched fast-path completion "
  9027. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  9028. cqid, cq->queue_id);
  9029. return;
  9030. }
  9031. /* Process all the entries to the CQ */
  9032. while ((cqe = lpfc_sli4_cq_get(cq))) {
  9033. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  9034. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9035. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  9036. }
  9037. /* Catch the no cq entry condition */
  9038. if (unlikely(ecount == 0))
  9039. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9040. "0369 No entry from fast-path completion "
  9041. "queue fcpcqid=%d\n", cq->queue_id);
  9042. /* In any case, flash and re-arm the CQ */
  9043. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  9044. /* wake up worker thread if there are works to be done */
  9045. if (workposted)
  9046. lpfc_worker_wake_up(phba);
  9047. }
  9048. static void
  9049. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9050. {
  9051. struct lpfc_eqe *eqe;
  9052. /* walk all the EQ entries and drop on the floor */
  9053. while ((eqe = lpfc_sli4_eq_get(eq)))
  9054. ;
  9055. /* Clear and re-arm the EQ */
  9056. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  9057. }
  9058. /**
  9059. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  9060. * @irq: Interrupt number.
  9061. * @dev_id: The device context pointer.
  9062. *
  9063. * This function is directly called from the PCI layer as an interrupt
  9064. * service routine when device with SLI-4 interface spec is enabled with
  9065. * MSI-X multi-message interrupt mode and there are slow-path events in
  9066. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9067. * interrupt mode, this function is called as part of the device-level
  9068. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  9069. * undergoing initialization, the interrupt handler will not process the
  9070. * interrupt. The link attention and ELS ring attention events are handled
  9071. * by the worker thread. The interrupt handler signals the worker thread
  9072. * and returns for these events. This function is called without any lock
  9073. * held. It gets the hbalock to access and update SLI data structures.
  9074. *
  9075. * This function returns IRQ_HANDLED when interrupt is handled else it
  9076. * returns IRQ_NONE.
  9077. **/
  9078. irqreturn_t
  9079. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  9080. {
  9081. struct lpfc_hba *phba;
  9082. struct lpfc_queue *speq;
  9083. struct lpfc_eqe *eqe;
  9084. unsigned long iflag;
  9085. int ecount = 0;
  9086. /*
  9087. * Get the driver's phba structure from the dev_id
  9088. */
  9089. phba = (struct lpfc_hba *)dev_id;
  9090. if (unlikely(!phba))
  9091. return IRQ_NONE;
  9092. /* Get to the EQ struct associated with this vector */
  9093. speq = phba->sli4_hba.sp_eq;
  9094. /* Check device state for handling interrupt */
  9095. if (unlikely(lpfc_intr_state_check(phba))) {
  9096. /* Check again for link_state with lock held */
  9097. spin_lock_irqsave(&phba->hbalock, iflag);
  9098. if (phba->link_state < LPFC_LINK_DOWN)
  9099. /* Flush, clear interrupt, and rearm the EQ */
  9100. lpfc_sli4_eq_flush(phba, speq);
  9101. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9102. return IRQ_NONE;
  9103. }
  9104. /*
  9105. * Process all the event on FCP slow-path EQ
  9106. */
  9107. while ((eqe = lpfc_sli4_eq_get(speq))) {
  9108. lpfc_sli4_sp_handle_eqe(phba, eqe);
  9109. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9110. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  9111. }
  9112. /* Always clear and re-arm the slow-path EQ */
  9113. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  9114. /* Catch the no cq entry condition */
  9115. if (unlikely(ecount == 0)) {
  9116. if (phba->intr_type == MSIX)
  9117. /* MSI-X treated interrupt served as no EQ share INT */
  9118. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9119. "0357 MSI-X interrupt with no EQE\n");
  9120. else
  9121. /* Non MSI-X treated on interrupt as EQ share INT */
  9122. return IRQ_NONE;
  9123. }
  9124. return IRQ_HANDLED;
  9125. } /* lpfc_sli4_sp_intr_handler */
  9126. /**
  9127. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  9128. * @irq: Interrupt number.
  9129. * @dev_id: The device context pointer.
  9130. *
  9131. * This function is directly called from the PCI layer as an interrupt
  9132. * service routine when device with SLI-4 interface spec is enabled with
  9133. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9134. * ring event in the HBA. However, when the device is enabled with either
  9135. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9136. * device-level interrupt handler. When the PCI slot is in error recovery
  9137. * or the HBA is undergoing initialization, the interrupt handler will not
  9138. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9139. * the intrrupt context. This function is called without any lock held.
  9140. * It gets the hbalock to access and update SLI data structures. Note that,
  9141. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  9142. * equal to that of FCP CQ index.
  9143. *
  9144. * This function returns IRQ_HANDLED when interrupt is handled else it
  9145. * returns IRQ_NONE.
  9146. **/
  9147. irqreturn_t
  9148. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  9149. {
  9150. struct lpfc_hba *phba;
  9151. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  9152. struct lpfc_queue *fpeq;
  9153. struct lpfc_eqe *eqe;
  9154. unsigned long iflag;
  9155. int ecount = 0;
  9156. uint32_t fcp_eqidx;
  9157. /* Get the driver's phba structure from the dev_id */
  9158. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  9159. phba = fcp_eq_hdl->phba;
  9160. fcp_eqidx = fcp_eq_hdl->idx;
  9161. if (unlikely(!phba))
  9162. return IRQ_NONE;
  9163. /* Get to the EQ struct associated with this vector */
  9164. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  9165. /* Check device state for handling interrupt */
  9166. if (unlikely(lpfc_intr_state_check(phba))) {
  9167. /* Check again for link_state with lock held */
  9168. spin_lock_irqsave(&phba->hbalock, iflag);
  9169. if (phba->link_state < LPFC_LINK_DOWN)
  9170. /* Flush, clear interrupt, and rearm the EQ */
  9171. lpfc_sli4_eq_flush(phba, fpeq);
  9172. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9173. return IRQ_NONE;
  9174. }
  9175. /*
  9176. * Process all the event on FCP fast-path EQ
  9177. */
  9178. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  9179. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  9180. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9181. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  9182. }
  9183. /* Always clear and re-arm the fast-path EQ */
  9184. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  9185. if (unlikely(ecount == 0)) {
  9186. if (phba->intr_type == MSIX)
  9187. /* MSI-X treated interrupt served as no EQ share INT */
  9188. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9189. "0358 MSI-X interrupt with no EQE\n");
  9190. else
  9191. /* Non MSI-X treated on interrupt as EQ share INT */
  9192. return IRQ_NONE;
  9193. }
  9194. return IRQ_HANDLED;
  9195. } /* lpfc_sli4_fp_intr_handler */
  9196. /**
  9197. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  9198. * @irq: Interrupt number.
  9199. * @dev_id: The device context pointer.
  9200. *
  9201. * This function is the device-level interrupt handler to device with SLI-4
  9202. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  9203. * interrupt mode is enabled and there is an event in the HBA which requires
  9204. * driver attention. This function invokes the slow-path interrupt attention
  9205. * handling function and fast-path interrupt attention handling function in
  9206. * turn to process the relevant HBA attention events. This function is called
  9207. * without any lock held. It gets the hbalock to access and update SLI data
  9208. * structures.
  9209. *
  9210. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9211. * returns IRQ_NONE.
  9212. **/
  9213. irqreturn_t
  9214. lpfc_sli4_intr_handler(int irq, void *dev_id)
  9215. {
  9216. struct lpfc_hba *phba;
  9217. irqreturn_t sp_irq_rc, fp_irq_rc;
  9218. bool fp_handled = false;
  9219. uint32_t fcp_eqidx;
  9220. /* Get the driver's phba structure from the dev_id */
  9221. phba = (struct lpfc_hba *)dev_id;
  9222. if (unlikely(!phba))
  9223. return IRQ_NONE;
  9224. /*
  9225. * Invokes slow-path host attention interrupt handling as appropriate.
  9226. */
  9227. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  9228. /*
  9229. * Invoke fast-path host attention interrupt handling as appropriate.
  9230. */
  9231. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  9232. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  9233. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  9234. if (fp_irq_rc == IRQ_HANDLED)
  9235. fp_handled |= true;
  9236. }
  9237. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  9238. } /* lpfc_sli4_intr_handler */
  9239. /**
  9240. * lpfc_sli4_queue_free - free a queue structure and associated memory
  9241. * @queue: The queue structure to free.
  9242. *
  9243. * This function frees a queue structure and the DMAable memory used for
  9244. * the host resident queue. This function must be called after destroying the
  9245. * queue on the HBA.
  9246. **/
  9247. void
  9248. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  9249. {
  9250. struct lpfc_dmabuf *dmabuf;
  9251. if (!queue)
  9252. return;
  9253. while (!list_empty(&queue->page_list)) {
  9254. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  9255. list);
  9256. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  9257. dmabuf->virt, dmabuf->phys);
  9258. kfree(dmabuf);
  9259. }
  9260. kfree(queue);
  9261. return;
  9262. }
  9263. /**
  9264. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  9265. * @phba: The HBA that this queue is being created on.
  9266. * @entry_size: The size of each queue entry for this queue.
  9267. * @entry count: The number of entries that this queue will handle.
  9268. *
  9269. * This function allocates a queue structure and the DMAable memory used for
  9270. * the host resident queue. This function must be called before creating the
  9271. * queue on the HBA.
  9272. **/
  9273. struct lpfc_queue *
  9274. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  9275. uint32_t entry_count)
  9276. {
  9277. struct lpfc_queue *queue;
  9278. struct lpfc_dmabuf *dmabuf;
  9279. int x, total_qe_count;
  9280. void *dma_pointer;
  9281. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9282. if (!phba->sli4_hba.pc_sli4_params.supported)
  9283. hw_page_size = SLI4_PAGE_SIZE;
  9284. queue = kzalloc(sizeof(struct lpfc_queue) +
  9285. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  9286. if (!queue)
  9287. return NULL;
  9288. queue->page_count = (ALIGN(entry_size * entry_count,
  9289. hw_page_size))/hw_page_size;
  9290. INIT_LIST_HEAD(&queue->list);
  9291. INIT_LIST_HEAD(&queue->page_list);
  9292. INIT_LIST_HEAD(&queue->child_list);
  9293. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  9294. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  9295. if (!dmabuf)
  9296. goto out_fail;
  9297. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  9298. hw_page_size, &dmabuf->phys,
  9299. GFP_KERNEL);
  9300. if (!dmabuf->virt) {
  9301. kfree(dmabuf);
  9302. goto out_fail;
  9303. }
  9304. memset(dmabuf->virt, 0, hw_page_size);
  9305. dmabuf->buffer_tag = x;
  9306. list_add_tail(&dmabuf->list, &queue->page_list);
  9307. /* initialize queue's entry array */
  9308. dma_pointer = dmabuf->virt;
  9309. for (; total_qe_count < entry_count &&
  9310. dma_pointer < (hw_page_size + dmabuf->virt);
  9311. total_qe_count++, dma_pointer += entry_size) {
  9312. queue->qe[total_qe_count].address = dma_pointer;
  9313. }
  9314. }
  9315. queue->entry_size = entry_size;
  9316. queue->entry_count = entry_count;
  9317. queue->phba = phba;
  9318. return queue;
  9319. out_fail:
  9320. lpfc_sli4_queue_free(queue);
  9321. return NULL;
  9322. }
  9323. /**
  9324. * lpfc_eq_create - Create an Event Queue on the HBA
  9325. * @phba: HBA structure that indicates port to create a queue on.
  9326. * @eq: The queue structure to use to create the event queue.
  9327. * @imax: The maximum interrupt per second limit.
  9328. *
  9329. * This function creates an event queue, as detailed in @eq, on a port,
  9330. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  9331. *
  9332. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  9333. * is used to get the entry count and entry size that are necessary to
  9334. * determine the number of pages to allocate and use for this queue. This
  9335. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  9336. * event queue. This function is asynchronous and will wait for the mailbox
  9337. * command to finish before continuing.
  9338. *
  9339. * On success this function will return a zero. If unable to allocate enough
  9340. * memory this function will return -ENOMEM. If the queue create mailbox command
  9341. * fails this function will return -ENXIO.
  9342. **/
  9343. uint32_t
  9344. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  9345. {
  9346. struct lpfc_mbx_eq_create *eq_create;
  9347. LPFC_MBOXQ_t *mbox;
  9348. int rc, length, status = 0;
  9349. struct lpfc_dmabuf *dmabuf;
  9350. uint32_t shdr_status, shdr_add_status;
  9351. union lpfc_sli4_cfg_shdr *shdr;
  9352. uint16_t dmult;
  9353. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9354. if (!phba->sli4_hba.pc_sli4_params.supported)
  9355. hw_page_size = SLI4_PAGE_SIZE;
  9356. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9357. if (!mbox)
  9358. return -ENOMEM;
  9359. length = (sizeof(struct lpfc_mbx_eq_create) -
  9360. sizeof(struct lpfc_sli4_cfg_mhdr));
  9361. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9362. LPFC_MBOX_OPCODE_EQ_CREATE,
  9363. length, LPFC_SLI4_MBX_EMBED);
  9364. eq_create = &mbox->u.mqe.un.eq_create;
  9365. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  9366. eq->page_count);
  9367. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  9368. LPFC_EQE_SIZE);
  9369. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  9370. /* Calculate delay multiper from maximum interrupt per second */
  9371. dmult = LPFC_DMULT_CONST/imax - 1;
  9372. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  9373. dmult);
  9374. switch (eq->entry_count) {
  9375. default:
  9376. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9377. "0360 Unsupported EQ count. (%d)\n",
  9378. eq->entry_count);
  9379. if (eq->entry_count < 256)
  9380. return -EINVAL;
  9381. /* otherwise default to smallest count (drop through) */
  9382. case 256:
  9383. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9384. LPFC_EQ_CNT_256);
  9385. break;
  9386. case 512:
  9387. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9388. LPFC_EQ_CNT_512);
  9389. break;
  9390. case 1024:
  9391. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9392. LPFC_EQ_CNT_1024);
  9393. break;
  9394. case 2048:
  9395. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9396. LPFC_EQ_CNT_2048);
  9397. break;
  9398. case 4096:
  9399. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9400. LPFC_EQ_CNT_4096);
  9401. break;
  9402. }
  9403. list_for_each_entry(dmabuf, &eq->page_list, list) {
  9404. memset(dmabuf->virt, 0, hw_page_size);
  9405. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9406. putPaddrLow(dmabuf->phys);
  9407. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9408. putPaddrHigh(dmabuf->phys);
  9409. }
  9410. mbox->vport = phba->pport;
  9411. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9412. mbox->context1 = NULL;
  9413. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9414. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  9415. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9416. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9417. if (shdr_status || shdr_add_status || rc) {
  9418. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9419. "2500 EQ_CREATE mailbox failed with "
  9420. "status x%x add_status x%x, mbx status x%x\n",
  9421. shdr_status, shdr_add_status, rc);
  9422. status = -ENXIO;
  9423. }
  9424. eq->type = LPFC_EQ;
  9425. eq->subtype = LPFC_NONE;
  9426. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  9427. if (eq->queue_id == 0xFFFF)
  9428. status = -ENXIO;
  9429. eq->host_index = 0;
  9430. eq->hba_index = 0;
  9431. mempool_free(mbox, phba->mbox_mem_pool);
  9432. return status;
  9433. }
  9434. /**
  9435. * lpfc_cq_create - Create a Completion Queue on the HBA
  9436. * @phba: HBA structure that indicates port to create a queue on.
  9437. * @cq: The queue structure to use to create the completion queue.
  9438. * @eq: The event queue to bind this completion queue to.
  9439. *
  9440. * This function creates a completion queue, as detailed in @wq, on a port,
  9441. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  9442. *
  9443. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9444. * is used to get the entry count and entry size that are necessary to
  9445. * determine the number of pages to allocate and use for this queue. The @eq
  9446. * is used to indicate which event queue to bind this completion queue to. This
  9447. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  9448. * completion queue. This function is asynchronous and will wait for the mailbox
  9449. * command to finish before continuing.
  9450. *
  9451. * On success this function will return a zero. If unable to allocate enough
  9452. * memory this function will return -ENOMEM. If the queue create mailbox command
  9453. * fails this function will return -ENXIO.
  9454. **/
  9455. uint32_t
  9456. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9457. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  9458. {
  9459. struct lpfc_mbx_cq_create *cq_create;
  9460. struct lpfc_dmabuf *dmabuf;
  9461. LPFC_MBOXQ_t *mbox;
  9462. int rc, length, status = 0;
  9463. uint32_t shdr_status, shdr_add_status;
  9464. union lpfc_sli4_cfg_shdr *shdr;
  9465. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9466. if (!phba->sli4_hba.pc_sli4_params.supported)
  9467. hw_page_size = SLI4_PAGE_SIZE;
  9468. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9469. if (!mbox)
  9470. return -ENOMEM;
  9471. length = (sizeof(struct lpfc_mbx_cq_create) -
  9472. sizeof(struct lpfc_sli4_cfg_mhdr));
  9473. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9474. LPFC_MBOX_OPCODE_CQ_CREATE,
  9475. length, LPFC_SLI4_MBX_EMBED);
  9476. cq_create = &mbox->u.mqe.un.cq_create;
  9477. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  9478. cq->page_count);
  9479. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  9480. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  9481. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  9482. switch (cq->entry_count) {
  9483. default:
  9484. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9485. "0361 Unsupported CQ count. (%d)\n",
  9486. cq->entry_count);
  9487. if (cq->entry_count < 256)
  9488. return -EINVAL;
  9489. /* otherwise default to smallest count (drop through) */
  9490. case 256:
  9491. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9492. LPFC_CQ_CNT_256);
  9493. break;
  9494. case 512:
  9495. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9496. LPFC_CQ_CNT_512);
  9497. break;
  9498. case 1024:
  9499. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9500. LPFC_CQ_CNT_1024);
  9501. break;
  9502. }
  9503. list_for_each_entry(dmabuf, &cq->page_list, list) {
  9504. memset(dmabuf->virt, 0, hw_page_size);
  9505. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9506. putPaddrLow(dmabuf->phys);
  9507. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9508. putPaddrHigh(dmabuf->phys);
  9509. }
  9510. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9511. /* The IOCTL status is embedded in the mailbox subheader. */
  9512. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  9513. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9514. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9515. if (shdr_status || shdr_add_status || rc) {
  9516. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9517. "2501 CQ_CREATE mailbox failed with "
  9518. "status x%x add_status x%x, mbx status x%x\n",
  9519. shdr_status, shdr_add_status, rc);
  9520. status = -ENXIO;
  9521. goto out;
  9522. }
  9523. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9524. if (cq->queue_id == 0xFFFF) {
  9525. status = -ENXIO;
  9526. goto out;
  9527. }
  9528. /* link the cq onto the parent eq child list */
  9529. list_add_tail(&cq->list, &eq->child_list);
  9530. /* Set up completion queue's type and subtype */
  9531. cq->type = type;
  9532. cq->subtype = subtype;
  9533. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9534. cq->assoc_qid = eq->queue_id;
  9535. cq->host_index = 0;
  9536. cq->hba_index = 0;
  9537. out:
  9538. mempool_free(mbox, phba->mbox_mem_pool);
  9539. return status;
  9540. }
  9541. /**
  9542. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9543. * @phba: HBA structure that indicates port to create a queue on.
  9544. * @mq: The queue structure to use to create the mailbox queue.
  9545. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9546. * @cq: The completion queue to associate with this cq.
  9547. *
  9548. * This function provides failback (fb) functionality when the
  9549. * mq_create_ext fails on older FW generations. It's purpose is identical
  9550. * to mq_create_ext otherwise.
  9551. *
  9552. * This routine cannot fail as all attributes were previously accessed and
  9553. * initialized in mq_create_ext.
  9554. **/
  9555. static void
  9556. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9557. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9558. {
  9559. struct lpfc_mbx_mq_create *mq_create;
  9560. struct lpfc_dmabuf *dmabuf;
  9561. int length;
  9562. length = (sizeof(struct lpfc_mbx_mq_create) -
  9563. sizeof(struct lpfc_sli4_cfg_mhdr));
  9564. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9565. LPFC_MBOX_OPCODE_MQ_CREATE,
  9566. length, LPFC_SLI4_MBX_EMBED);
  9567. mq_create = &mbox->u.mqe.un.mq_create;
  9568. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9569. mq->page_count);
  9570. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9571. cq->queue_id);
  9572. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9573. switch (mq->entry_count) {
  9574. case 16:
  9575. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9576. LPFC_MQ_CNT_16);
  9577. break;
  9578. case 32:
  9579. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9580. LPFC_MQ_CNT_32);
  9581. break;
  9582. case 64:
  9583. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9584. LPFC_MQ_CNT_64);
  9585. break;
  9586. case 128:
  9587. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9588. LPFC_MQ_CNT_128);
  9589. break;
  9590. }
  9591. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9592. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9593. putPaddrLow(dmabuf->phys);
  9594. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9595. putPaddrHigh(dmabuf->phys);
  9596. }
  9597. }
  9598. /**
  9599. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9600. * @phba: HBA structure that indicates port to create a queue on.
  9601. * @mq: The queue structure to use to create the mailbox queue.
  9602. * @cq: The completion queue to associate with this cq.
  9603. * @subtype: The queue's subtype.
  9604. *
  9605. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9606. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9607. *
  9608. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9609. * is used to get the entry count and entry size that are necessary to
  9610. * determine the number of pages to allocate and use for this queue. This
  9611. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9612. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9613. * command to finish before continuing.
  9614. *
  9615. * On success this function will return a zero. If unable to allocate enough
  9616. * memory this function will return -ENOMEM. If the queue create mailbox command
  9617. * fails this function will return -ENXIO.
  9618. **/
  9619. int32_t
  9620. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9621. struct lpfc_queue *cq, uint32_t subtype)
  9622. {
  9623. struct lpfc_mbx_mq_create *mq_create;
  9624. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9625. struct lpfc_dmabuf *dmabuf;
  9626. LPFC_MBOXQ_t *mbox;
  9627. int rc, length, status = 0;
  9628. uint32_t shdr_status, shdr_add_status;
  9629. union lpfc_sli4_cfg_shdr *shdr;
  9630. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9631. if (!phba->sli4_hba.pc_sli4_params.supported)
  9632. hw_page_size = SLI4_PAGE_SIZE;
  9633. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9634. if (!mbox)
  9635. return -ENOMEM;
  9636. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9637. sizeof(struct lpfc_sli4_cfg_mhdr));
  9638. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9639. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9640. length, LPFC_SLI4_MBX_EMBED);
  9641. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9642. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  9643. &mq_create_ext->u.request, mq->page_count);
  9644. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  9645. &mq_create_ext->u.request, 1);
  9646. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  9647. &mq_create_ext->u.request, 1);
  9648. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9649. &mq_create_ext->u.request, 1);
  9650. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  9651. &mq_create_ext->u.request, 1);
  9652. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  9653. &mq_create_ext->u.request, 1);
  9654. bf_set(lpfc_mq_context_cq_id,
  9655. &mq_create_ext->u.request.context, cq->queue_id);
  9656. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9657. switch (mq->entry_count) {
  9658. default:
  9659. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9660. "0362 Unsupported MQ count. (%d)\n",
  9661. mq->entry_count);
  9662. if (mq->entry_count < 16)
  9663. return -EINVAL;
  9664. /* otherwise default to smallest count (drop through) */
  9665. case 16:
  9666. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9667. LPFC_MQ_CNT_16);
  9668. break;
  9669. case 32:
  9670. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9671. LPFC_MQ_CNT_32);
  9672. break;
  9673. case 64:
  9674. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9675. LPFC_MQ_CNT_64);
  9676. break;
  9677. case 128:
  9678. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9679. LPFC_MQ_CNT_128);
  9680. break;
  9681. }
  9682. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9683. memset(dmabuf->virt, 0, hw_page_size);
  9684. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9685. putPaddrLow(dmabuf->phys);
  9686. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9687. putPaddrHigh(dmabuf->phys);
  9688. }
  9689. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9690. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9691. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9692. &mq_create_ext->u.response);
  9693. if (rc != MBX_SUCCESS) {
  9694. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9695. "2795 MQ_CREATE_EXT failed with "
  9696. "status x%x. Failback to MQ_CREATE.\n",
  9697. rc);
  9698. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9699. mq_create = &mbox->u.mqe.un.mq_create;
  9700. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9701. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9702. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9703. &mq_create->u.response);
  9704. }
  9705. /* The IOCTL status is embedded in the mailbox subheader. */
  9706. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9707. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9708. if (shdr_status || shdr_add_status || rc) {
  9709. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9710. "2502 MQ_CREATE mailbox failed with "
  9711. "status x%x add_status x%x, mbx status x%x\n",
  9712. shdr_status, shdr_add_status, rc);
  9713. status = -ENXIO;
  9714. goto out;
  9715. }
  9716. if (mq->queue_id == 0xFFFF) {
  9717. status = -ENXIO;
  9718. goto out;
  9719. }
  9720. mq->type = LPFC_MQ;
  9721. mq->assoc_qid = cq->queue_id;
  9722. mq->subtype = subtype;
  9723. mq->host_index = 0;
  9724. mq->hba_index = 0;
  9725. /* link the mq onto the parent cq child list */
  9726. list_add_tail(&mq->list, &cq->child_list);
  9727. out:
  9728. mempool_free(mbox, phba->mbox_mem_pool);
  9729. return status;
  9730. }
  9731. /**
  9732. * lpfc_wq_create - Create a Work Queue on the HBA
  9733. * @phba: HBA structure that indicates port to create a queue on.
  9734. * @wq: The queue structure to use to create the work queue.
  9735. * @cq: The completion queue to bind this work queue to.
  9736. * @subtype: The subtype of the work queue indicating its functionality.
  9737. *
  9738. * This function creates a work queue, as detailed in @wq, on a port, described
  9739. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9740. *
  9741. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9742. * is used to get the entry count and entry size that are necessary to
  9743. * determine the number of pages to allocate and use for this queue. The @cq
  9744. * is used to indicate which completion queue to bind this work queue to. This
  9745. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9746. * work queue. This function is asynchronous and will wait for the mailbox
  9747. * command to finish before continuing.
  9748. *
  9749. * On success this function will return a zero. If unable to allocate enough
  9750. * memory this function will return -ENOMEM. If the queue create mailbox command
  9751. * fails this function will return -ENXIO.
  9752. **/
  9753. uint32_t
  9754. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9755. struct lpfc_queue *cq, uint32_t subtype)
  9756. {
  9757. struct lpfc_mbx_wq_create *wq_create;
  9758. struct lpfc_dmabuf *dmabuf;
  9759. LPFC_MBOXQ_t *mbox;
  9760. int rc, length, status = 0;
  9761. uint32_t shdr_status, shdr_add_status;
  9762. union lpfc_sli4_cfg_shdr *shdr;
  9763. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9764. if (!phba->sli4_hba.pc_sli4_params.supported)
  9765. hw_page_size = SLI4_PAGE_SIZE;
  9766. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9767. if (!mbox)
  9768. return -ENOMEM;
  9769. length = (sizeof(struct lpfc_mbx_wq_create) -
  9770. sizeof(struct lpfc_sli4_cfg_mhdr));
  9771. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9772. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9773. length, LPFC_SLI4_MBX_EMBED);
  9774. wq_create = &mbox->u.mqe.un.wq_create;
  9775. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9776. wq->page_count);
  9777. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9778. cq->queue_id);
  9779. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9780. memset(dmabuf->virt, 0, hw_page_size);
  9781. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9782. putPaddrLow(dmabuf->phys);
  9783. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9784. putPaddrHigh(dmabuf->phys);
  9785. }
  9786. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9787. /* The IOCTL status is embedded in the mailbox subheader. */
  9788. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9789. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9790. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9791. if (shdr_status || shdr_add_status || rc) {
  9792. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9793. "2503 WQ_CREATE mailbox failed with "
  9794. "status x%x add_status x%x, mbx status x%x\n",
  9795. shdr_status, shdr_add_status, rc);
  9796. status = -ENXIO;
  9797. goto out;
  9798. }
  9799. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9800. if (wq->queue_id == 0xFFFF) {
  9801. status = -ENXIO;
  9802. goto out;
  9803. }
  9804. wq->type = LPFC_WQ;
  9805. wq->assoc_qid = cq->queue_id;
  9806. wq->subtype = subtype;
  9807. wq->host_index = 0;
  9808. wq->hba_index = 0;
  9809. /* link the wq onto the parent cq child list */
  9810. list_add_tail(&wq->list, &cq->child_list);
  9811. out:
  9812. mempool_free(mbox, phba->mbox_mem_pool);
  9813. return status;
  9814. }
  9815. /**
  9816. * lpfc_rq_create - Create a Receive Queue on the HBA
  9817. * @phba: HBA structure that indicates port to create a queue on.
  9818. * @hrq: The queue structure to use to create the header receive queue.
  9819. * @drq: The queue structure to use to create the data receive queue.
  9820. * @cq: The completion queue to bind this work queue to.
  9821. *
  9822. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9823. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9824. * to the HBA.
  9825. *
  9826. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9827. * struct is used to get the entry count that is necessary to determine the
  9828. * number of pages to use for this queue. The @cq is used to indicate which
  9829. * completion queue to bind received buffers that are posted to these queues to.
  9830. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9831. * receive queue pair. This function is asynchronous and will wait for the
  9832. * mailbox command to finish before continuing.
  9833. *
  9834. * On success this function will return a zero. If unable to allocate enough
  9835. * memory this function will return -ENOMEM. If the queue create mailbox command
  9836. * fails this function will return -ENXIO.
  9837. **/
  9838. uint32_t
  9839. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9840. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9841. {
  9842. struct lpfc_mbx_rq_create *rq_create;
  9843. struct lpfc_dmabuf *dmabuf;
  9844. LPFC_MBOXQ_t *mbox;
  9845. int rc, length, status = 0;
  9846. uint32_t shdr_status, shdr_add_status;
  9847. union lpfc_sli4_cfg_shdr *shdr;
  9848. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9849. if (!phba->sli4_hba.pc_sli4_params.supported)
  9850. hw_page_size = SLI4_PAGE_SIZE;
  9851. if (hrq->entry_count != drq->entry_count)
  9852. return -EINVAL;
  9853. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9854. if (!mbox)
  9855. return -ENOMEM;
  9856. length = (sizeof(struct lpfc_mbx_rq_create) -
  9857. sizeof(struct lpfc_sli4_cfg_mhdr));
  9858. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9859. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9860. length, LPFC_SLI4_MBX_EMBED);
  9861. rq_create = &mbox->u.mqe.un.rq_create;
  9862. switch (hrq->entry_count) {
  9863. default:
  9864. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9865. "2535 Unsupported RQ count. (%d)\n",
  9866. hrq->entry_count);
  9867. if (hrq->entry_count < 512)
  9868. return -EINVAL;
  9869. /* otherwise default to smallest count (drop through) */
  9870. case 512:
  9871. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9872. LPFC_RQ_RING_SIZE_512);
  9873. break;
  9874. case 1024:
  9875. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9876. LPFC_RQ_RING_SIZE_1024);
  9877. break;
  9878. case 2048:
  9879. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9880. LPFC_RQ_RING_SIZE_2048);
  9881. break;
  9882. case 4096:
  9883. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9884. LPFC_RQ_RING_SIZE_4096);
  9885. break;
  9886. }
  9887. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9888. cq->queue_id);
  9889. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9890. hrq->page_count);
  9891. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9892. LPFC_HDR_BUF_SIZE);
  9893. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9894. memset(dmabuf->virt, 0, hw_page_size);
  9895. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9896. putPaddrLow(dmabuf->phys);
  9897. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9898. putPaddrHigh(dmabuf->phys);
  9899. }
  9900. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9901. /* The IOCTL status is embedded in the mailbox subheader. */
  9902. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9903. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9904. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9905. if (shdr_status || shdr_add_status || rc) {
  9906. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9907. "2504 RQ_CREATE mailbox failed with "
  9908. "status x%x add_status x%x, mbx status x%x\n",
  9909. shdr_status, shdr_add_status, rc);
  9910. status = -ENXIO;
  9911. goto out;
  9912. }
  9913. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9914. if (hrq->queue_id == 0xFFFF) {
  9915. status = -ENXIO;
  9916. goto out;
  9917. }
  9918. hrq->type = LPFC_HRQ;
  9919. hrq->assoc_qid = cq->queue_id;
  9920. hrq->subtype = subtype;
  9921. hrq->host_index = 0;
  9922. hrq->hba_index = 0;
  9923. /* now create the data queue */
  9924. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9925. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9926. length, LPFC_SLI4_MBX_EMBED);
  9927. switch (drq->entry_count) {
  9928. default:
  9929. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9930. "2536 Unsupported RQ count. (%d)\n",
  9931. drq->entry_count);
  9932. if (drq->entry_count < 512)
  9933. return -EINVAL;
  9934. /* otherwise default to smallest count (drop through) */
  9935. case 512:
  9936. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9937. LPFC_RQ_RING_SIZE_512);
  9938. break;
  9939. case 1024:
  9940. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9941. LPFC_RQ_RING_SIZE_1024);
  9942. break;
  9943. case 2048:
  9944. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9945. LPFC_RQ_RING_SIZE_2048);
  9946. break;
  9947. case 4096:
  9948. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9949. LPFC_RQ_RING_SIZE_4096);
  9950. break;
  9951. }
  9952. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9953. cq->queue_id);
  9954. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9955. drq->page_count);
  9956. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9957. LPFC_DATA_BUF_SIZE);
  9958. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9959. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9960. putPaddrLow(dmabuf->phys);
  9961. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9962. putPaddrHigh(dmabuf->phys);
  9963. }
  9964. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9965. /* The IOCTL status is embedded in the mailbox subheader. */
  9966. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9967. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9968. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9969. if (shdr_status || shdr_add_status || rc) {
  9970. status = -ENXIO;
  9971. goto out;
  9972. }
  9973. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9974. if (drq->queue_id == 0xFFFF) {
  9975. status = -ENXIO;
  9976. goto out;
  9977. }
  9978. drq->type = LPFC_DRQ;
  9979. drq->assoc_qid = cq->queue_id;
  9980. drq->subtype = subtype;
  9981. drq->host_index = 0;
  9982. drq->hba_index = 0;
  9983. /* link the header and data RQs onto the parent cq child list */
  9984. list_add_tail(&hrq->list, &cq->child_list);
  9985. list_add_tail(&drq->list, &cq->child_list);
  9986. out:
  9987. mempool_free(mbox, phba->mbox_mem_pool);
  9988. return status;
  9989. }
  9990. /**
  9991. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9992. * @eq: The queue structure associated with the queue to destroy.
  9993. *
  9994. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9995. * command, specific to the type of queue, to the HBA.
  9996. *
  9997. * The @eq struct is used to get the queue ID of the queue to destroy.
  9998. *
  9999. * On success this function will return a zero. If the queue destroy mailbox
  10000. * command fails this function will return -ENXIO.
  10001. **/
  10002. uint32_t
  10003. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10004. {
  10005. LPFC_MBOXQ_t *mbox;
  10006. int rc, length, status = 0;
  10007. uint32_t shdr_status, shdr_add_status;
  10008. union lpfc_sli4_cfg_shdr *shdr;
  10009. if (!eq)
  10010. return -ENODEV;
  10011. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  10012. if (!mbox)
  10013. return -ENOMEM;
  10014. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  10015. sizeof(struct lpfc_sli4_cfg_mhdr));
  10016. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10017. LPFC_MBOX_OPCODE_EQ_DESTROY,
  10018. length, LPFC_SLI4_MBX_EMBED);
  10019. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  10020. eq->queue_id);
  10021. mbox->vport = eq->phba->pport;
  10022. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10023. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  10024. /* The IOCTL status is embedded in the mailbox subheader. */
  10025. shdr = (union lpfc_sli4_cfg_shdr *)
  10026. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  10027. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10028. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10029. if (shdr_status || shdr_add_status || rc) {
  10030. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10031. "2505 EQ_DESTROY mailbox failed with "
  10032. "status x%x add_status x%x, mbx status x%x\n",
  10033. shdr_status, shdr_add_status, rc);
  10034. status = -ENXIO;
  10035. }
  10036. /* Remove eq from any list */
  10037. list_del_init(&eq->list);
  10038. mempool_free(mbox, eq->phba->mbox_mem_pool);
  10039. return status;
  10040. }
  10041. /**
  10042. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  10043. * @cq: The queue structure associated with the queue to destroy.
  10044. *
  10045. * This function destroys a queue, as detailed in @cq by sending an mailbox
  10046. * command, specific to the type of queue, to the HBA.
  10047. *
  10048. * The @cq struct is used to get the queue ID of the queue to destroy.
  10049. *
  10050. * On success this function will return a zero. If the queue destroy mailbox
  10051. * command fails this function will return -ENXIO.
  10052. **/
  10053. uint32_t
  10054. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  10055. {
  10056. LPFC_MBOXQ_t *mbox;
  10057. int rc, length, status = 0;
  10058. uint32_t shdr_status, shdr_add_status;
  10059. union lpfc_sli4_cfg_shdr *shdr;
  10060. if (!cq)
  10061. return -ENODEV;
  10062. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  10063. if (!mbox)
  10064. return -ENOMEM;
  10065. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  10066. sizeof(struct lpfc_sli4_cfg_mhdr));
  10067. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10068. LPFC_MBOX_OPCODE_CQ_DESTROY,
  10069. length, LPFC_SLI4_MBX_EMBED);
  10070. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  10071. cq->queue_id);
  10072. mbox->vport = cq->phba->pport;
  10073. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10074. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  10075. /* The IOCTL status is embedded in the mailbox subheader. */
  10076. shdr = (union lpfc_sli4_cfg_shdr *)
  10077. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  10078. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10079. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10080. if (shdr_status || shdr_add_status || rc) {
  10081. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10082. "2506 CQ_DESTROY mailbox failed with "
  10083. "status x%x add_status x%x, mbx status x%x\n",
  10084. shdr_status, shdr_add_status, rc);
  10085. status = -ENXIO;
  10086. }
  10087. /* Remove cq from any list */
  10088. list_del_init(&cq->list);
  10089. mempool_free(mbox, cq->phba->mbox_mem_pool);
  10090. return status;
  10091. }
  10092. /**
  10093. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  10094. * @qm: The queue structure associated with the queue to destroy.
  10095. *
  10096. * This function destroys a queue, as detailed in @mq by sending an mailbox
  10097. * command, specific to the type of queue, to the HBA.
  10098. *
  10099. * The @mq struct is used to get the queue ID of the queue to destroy.
  10100. *
  10101. * On success this function will return a zero. If the queue destroy mailbox
  10102. * command fails this function will return -ENXIO.
  10103. **/
  10104. uint32_t
  10105. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  10106. {
  10107. LPFC_MBOXQ_t *mbox;
  10108. int rc, length, status = 0;
  10109. uint32_t shdr_status, shdr_add_status;
  10110. union lpfc_sli4_cfg_shdr *shdr;
  10111. if (!mq)
  10112. return -ENODEV;
  10113. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  10114. if (!mbox)
  10115. return -ENOMEM;
  10116. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  10117. sizeof(struct lpfc_sli4_cfg_mhdr));
  10118. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10119. LPFC_MBOX_OPCODE_MQ_DESTROY,
  10120. length, LPFC_SLI4_MBX_EMBED);
  10121. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  10122. mq->queue_id);
  10123. mbox->vport = mq->phba->pport;
  10124. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10125. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  10126. /* The IOCTL status is embedded in the mailbox subheader. */
  10127. shdr = (union lpfc_sli4_cfg_shdr *)
  10128. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  10129. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10130. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10131. if (shdr_status || shdr_add_status || rc) {
  10132. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10133. "2507 MQ_DESTROY mailbox failed with "
  10134. "status x%x add_status x%x, mbx status x%x\n",
  10135. shdr_status, shdr_add_status, rc);
  10136. status = -ENXIO;
  10137. }
  10138. /* Remove mq from any list */
  10139. list_del_init(&mq->list);
  10140. mempool_free(mbox, mq->phba->mbox_mem_pool);
  10141. return status;
  10142. }
  10143. /**
  10144. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  10145. * @wq: The queue structure associated with the queue to destroy.
  10146. *
  10147. * This function destroys a queue, as detailed in @wq by sending an mailbox
  10148. * command, specific to the type of queue, to the HBA.
  10149. *
  10150. * The @wq struct is used to get the queue ID of the queue to destroy.
  10151. *
  10152. * On success this function will return a zero. If the queue destroy mailbox
  10153. * command fails this function will return -ENXIO.
  10154. **/
  10155. uint32_t
  10156. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  10157. {
  10158. LPFC_MBOXQ_t *mbox;
  10159. int rc, length, status = 0;
  10160. uint32_t shdr_status, shdr_add_status;
  10161. union lpfc_sli4_cfg_shdr *shdr;
  10162. if (!wq)
  10163. return -ENODEV;
  10164. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  10165. if (!mbox)
  10166. return -ENOMEM;
  10167. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  10168. sizeof(struct lpfc_sli4_cfg_mhdr));
  10169. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10170. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  10171. length, LPFC_SLI4_MBX_EMBED);
  10172. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  10173. wq->queue_id);
  10174. mbox->vport = wq->phba->pport;
  10175. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10176. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  10177. shdr = (union lpfc_sli4_cfg_shdr *)
  10178. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  10179. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10180. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10181. if (shdr_status || shdr_add_status || rc) {
  10182. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10183. "2508 WQ_DESTROY mailbox failed with "
  10184. "status x%x add_status x%x, mbx status x%x\n",
  10185. shdr_status, shdr_add_status, rc);
  10186. status = -ENXIO;
  10187. }
  10188. /* Remove wq from any list */
  10189. list_del_init(&wq->list);
  10190. mempool_free(mbox, wq->phba->mbox_mem_pool);
  10191. return status;
  10192. }
  10193. /**
  10194. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  10195. * @rq: The queue structure associated with the queue to destroy.
  10196. *
  10197. * This function destroys a queue, as detailed in @rq by sending an mailbox
  10198. * command, specific to the type of queue, to the HBA.
  10199. *
  10200. * The @rq struct is used to get the queue ID of the queue to destroy.
  10201. *
  10202. * On success this function will return a zero. If the queue destroy mailbox
  10203. * command fails this function will return -ENXIO.
  10204. **/
  10205. uint32_t
  10206. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  10207. struct lpfc_queue *drq)
  10208. {
  10209. LPFC_MBOXQ_t *mbox;
  10210. int rc, length, status = 0;
  10211. uint32_t shdr_status, shdr_add_status;
  10212. union lpfc_sli4_cfg_shdr *shdr;
  10213. if (!hrq || !drq)
  10214. return -ENODEV;
  10215. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  10216. if (!mbox)
  10217. return -ENOMEM;
  10218. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  10219. sizeof(struct lpfc_sli4_cfg_mhdr));
  10220. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10221. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  10222. length, LPFC_SLI4_MBX_EMBED);
  10223. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10224. hrq->queue_id);
  10225. mbox->vport = hrq->phba->pport;
  10226. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10227. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  10228. /* The IOCTL status is embedded in the mailbox subheader. */
  10229. shdr = (union lpfc_sli4_cfg_shdr *)
  10230. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10231. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10232. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10233. if (shdr_status || shdr_add_status || rc) {
  10234. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10235. "2509 RQ_DESTROY mailbox failed with "
  10236. "status x%x add_status x%x, mbx status x%x\n",
  10237. shdr_status, shdr_add_status, rc);
  10238. if (rc != MBX_TIMEOUT)
  10239. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10240. return -ENXIO;
  10241. }
  10242. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10243. drq->queue_id);
  10244. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  10245. shdr = (union lpfc_sli4_cfg_shdr *)
  10246. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10247. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10248. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10249. if (shdr_status || shdr_add_status || rc) {
  10250. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10251. "2510 RQ_DESTROY mailbox failed with "
  10252. "status x%x add_status x%x, mbx status x%x\n",
  10253. shdr_status, shdr_add_status, rc);
  10254. status = -ENXIO;
  10255. }
  10256. list_del_init(&hrq->list);
  10257. list_del_init(&drq->list);
  10258. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10259. return status;
  10260. }
  10261. /**
  10262. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  10263. * @phba: The virtual port for which this call being executed.
  10264. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  10265. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  10266. * @xritag: the xritag that ties this io to the SGL pages.
  10267. *
  10268. * This routine will post the sgl pages for the IO that has the xritag
  10269. * that is in the iocbq structure. The xritag is assigned during iocbq
  10270. * creation and persists for as long as the driver is loaded.
  10271. * if the caller has fewer than 256 scatter gather segments to map then
  10272. * pdma_phys_addr1 should be 0.
  10273. * If the caller needs to map more than 256 scatter gather segment then
  10274. * pdma_phys_addr1 should be a valid physical address.
  10275. * physical address for SGLs must be 64 byte aligned.
  10276. * If you are going to map 2 SGL's then the first one must have 256 entries
  10277. * the second sgl can have between 1 and 256 entries.
  10278. *
  10279. * Return codes:
  10280. * 0 - Success
  10281. * -ENXIO, -ENOMEM - Failure
  10282. **/
  10283. int
  10284. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  10285. dma_addr_t pdma_phys_addr0,
  10286. dma_addr_t pdma_phys_addr1,
  10287. uint16_t xritag)
  10288. {
  10289. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  10290. LPFC_MBOXQ_t *mbox;
  10291. int rc;
  10292. uint32_t shdr_status, shdr_add_status;
  10293. union lpfc_sli4_cfg_shdr *shdr;
  10294. if (xritag == NO_XRI) {
  10295. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10296. "0364 Invalid param:\n");
  10297. return -EINVAL;
  10298. }
  10299. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10300. if (!mbox)
  10301. return -ENOMEM;
  10302. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10303. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  10304. sizeof(struct lpfc_mbx_post_sgl_pages) -
  10305. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  10306. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  10307. &mbox->u.mqe.un.post_sgl_pages;
  10308. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  10309. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  10310. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  10311. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  10312. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  10313. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  10314. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  10315. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  10316. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  10317. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  10318. if (!phba->sli4_hba.intr_enable)
  10319. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10320. else
  10321. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  10322. /* The IOCTL status is embedded in the mailbox subheader. */
  10323. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  10324. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10325. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10326. if (rc != MBX_TIMEOUT)
  10327. mempool_free(mbox, phba->mbox_mem_pool);
  10328. if (shdr_status || shdr_add_status || rc) {
  10329. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10330. "2511 POST_SGL mailbox failed with "
  10331. "status x%x add_status x%x, mbx status x%x\n",
  10332. shdr_status, shdr_add_status, rc);
  10333. rc = -ENXIO;
  10334. }
  10335. return 0;
  10336. }
  10337. /**
  10338. * lpfc_sli4_next_xritag - Get an xritag for the io
  10339. * @phba: Pointer to HBA context object.
  10340. *
  10341. * This function gets an xritag for the iocb. If there is no unused xritag
  10342. * it will return 0xffff.
  10343. * The function returns the allocated xritag if successful, else returns zero.
  10344. * Zero is not a valid xritag.
  10345. * The caller is not required to hold any lock.
  10346. **/
  10347. uint16_t
  10348. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  10349. {
  10350. uint16_t xritag;
  10351. spin_lock_irq(&phba->hbalock);
  10352. xritag = phba->sli4_hba.next_xri;
  10353. if ((xritag != (uint16_t) -1) && xritag <
  10354. (phba->sli4_hba.max_cfg_param.max_xri
  10355. + phba->sli4_hba.max_cfg_param.xri_base)) {
  10356. phba->sli4_hba.next_xri++;
  10357. phba->sli4_hba.max_cfg_param.xri_used++;
  10358. spin_unlock_irq(&phba->hbalock);
  10359. return xritag;
  10360. }
  10361. spin_unlock_irq(&phba->hbalock);
  10362. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10363. "2004 Failed to allocate XRI.last XRITAG is %d"
  10364. " Max XRI is %d, Used XRI is %d\n",
  10365. phba->sli4_hba.next_xri,
  10366. phba->sli4_hba.max_cfg_param.max_xri,
  10367. phba->sli4_hba.max_cfg_param.xri_used);
  10368. return -1;
  10369. }
  10370. /**
  10371. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  10372. * @phba: pointer to lpfc hba data structure.
  10373. *
  10374. * This routine is invoked to post a block of driver's sgl pages to the
  10375. * HBA using non-embedded mailbox command. No Lock is held. This routine
  10376. * is only called when the driver is loading and after all IO has been
  10377. * stopped.
  10378. **/
  10379. int
  10380. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  10381. {
  10382. struct lpfc_sglq *sglq_entry;
  10383. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10384. struct sgl_page_pairs *sgl_pg_pairs;
  10385. void *viraddr;
  10386. LPFC_MBOXQ_t *mbox;
  10387. uint32_t reqlen, alloclen, pg_pairs;
  10388. uint32_t mbox_tmo;
  10389. uint16_t xritag_start = 0;
  10390. int els_xri_cnt, rc = 0;
  10391. uint32_t shdr_status, shdr_add_status;
  10392. union lpfc_sli4_cfg_shdr *shdr;
  10393. /* The number of sgls to be posted */
  10394. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  10395. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  10396. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10397. if (reqlen > SLI4_PAGE_SIZE) {
  10398. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10399. "2559 Block sgl registration required DMA "
  10400. "size (%d) great than a page\n", reqlen);
  10401. return -ENOMEM;
  10402. }
  10403. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10404. if (!mbox) {
  10405. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10406. "2560 Failed to allocate mbox cmd memory\n");
  10407. return -ENOMEM;
  10408. }
  10409. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10410. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10411. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10412. LPFC_SLI4_MBX_NEMBED);
  10413. if (alloclen < reqlen) {
  10414. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10415. "0285 Allocated DMA memory size (%d) is "
  10416. "less than the requested DMA memory "
  10417. "size (%d)\n", alloclen, reqlen);
  10418. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10419. return -ENOMEM;
  10420. }
  10421. /* Get the first SGE entry from the non-embedded DMA memory */
  10422. viraddr = mbox->sge_array->addr[0];
  10423. /* Set up the SGL pages in the non-embedded DMA pages */
  10424. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10425. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10426. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  10427. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  10428. /* Set up the sge entry */
  10429. sgl_pg_pairs->sgl_pg0_addr_lo =
  10430. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  10431. sgl_pg_pairs->sgl_pg0_addr_hi =
  10432. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  10433. sgl_pg_pairs->sgl_pg1_addr_lo =
  10434. cpu_to_le32(putPaddrLow(0));
  10435. sgl_pg_pairs->sgl_pg1_addr_hi =
  10436. cpu_to_le32(putPaddrHigh(0));
  10437. /* Keep the first xritag on the list */
  10438. if (pg_pairs == 0)
  10439. xritag_start = sglq_entry->sli4_xritag;
  10440. sgl_pg_pairs++;
  10441. }
  10442. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10443. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  10444. /* Perform endian conversion if necessary */
  10445. sgl->word0 = cpu_to_le32(sgl->word0);
  10446. if (!phba->sli4_hba.intr_enable)
  10447. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10448. else {
  10449. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10450. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10451. }
  10452. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10453. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10454. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10455. if (rc != MBX_TIMEOUT)
  10456. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10457. if (shdr_status || shdr_add_status || rc) {
  10458. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10459. "2513 POST_SGL_BLOCK mailbox command failed "
  10460. "status x%x add_status x%x mbx status x%x\n",
  10461. shdr_status, shdr_add_status, rc);
  10462. rc = -ENXIO;
  10463. }
  10464. return rc;
  10465. }
  10466. /**
  10467. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  10468. * @phba: pointer to lpfc hba data structure.
  10469. * @sblist: pointer to scsi buffer list.
  10470. * @count: number of scsi buffers on the list.
  10471. *
  10472. * This routine is invoked to post a block of @count scsi sgl pages from a
  10473. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  10474. * No Lock is held.
  10475. *
  10476. **/
  10477. int
  10478. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  10479. int cnt)
  10480. {
  10481. struct lpfc_scsi_buf *psb;
  10482. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10483. struct sgl_page_pairs *sgl_pg_pairs;
  10484. void *viraddr;
  10485. LPFC_MBOXQ_t *mbox;
  10486. uint32_t reqlen, alloclen, pg_pairs;
  10487. uint32_t mbox_tmo;
  10488. uint16_t xritag_start = 0;
  10489. int rc = 0;
  10490. uint32_t shdr_status, shdr_add_status;
  10491. dma_addr_t pdma_phys_bpl1;
  10492. union lpfc_sli4_cfg_shdr *shdr;
  10493. /* Calculate the requested length of the dma memory */
  10494. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10495. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10496. if (reqlen > SLI4_PAGE_SIZE) {
  10497. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10498. "0217 Block sgl registration required DMA "
  10499. "size (%d) great than a page\n", reqlen);
  10500. return -ENOMEM;
  10501. }
  10502. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10503. if (!mbox) {
  10504. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10505. "0283 Failed to allocate mbox cmd memory\n");
  10506. return -ENOMEM;
  10507. }
  10508. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10509. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10510. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10511. LPFC_SLI4_MBX_NEMBED);
  10512. if (alloclen < reqlen) {
  10513. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10514. "2561 Allocated DMA memory size (%d) is "
  10515. "less than the requested DMA memory "
  10516. "size (%d)\n", alloclen, reqlen);
  10517. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10518. return -ENOMEM;
  10519. }
  10520. /* Get the first SGE entry from the non-embedded DMA memory */
  10521. viraddr = mbox->sge_array->addr[0];
  10522. /* Set up the SGL pages in the non-embedded DMA pages */
  10523. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10524. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10525. pg_pairs = 0;
  10526. list_for_each_entry(psb, sblist, list) {
  10527. /* Set up the sge entry */
  10528. sgl_pg_pairs->sgl_pg0_addr_lo =
  10529. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10530. sgl_pg_pairs->sgl_pg0_addr_hi =
  10531. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10532. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10533. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10534. else
  10535. pdma_phys_bpl1 = 0;
  10536. sgl_pg_pairs->sgl_pg1_addr_lo =
  10537. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10538. sgl_pg_pairs->sgl_pg1_addr_hi =
  10539. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10540. /* Keep the first xritag on the list */
  10541. if (pg_pairs == 0)
  10542. xritag_start = psb->cur_iocbq.sli4_xritag;
  10543. sgl_pg_pairs++;
  10544. pg_pairs++;
  10545. }
  10546. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10547. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10548. /* Perform endian conversion if necessary */
  10549. sgl->word0 = cpu_to_le32(sgl->word0);
  10550. if (!phba->sli4_hba.intr_enable)
  10551. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10552. else {
  10553. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10554. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10555. }
  10556. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10557. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10558. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10559. if (rc != MBX_TIMEOUT)
  10560. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10561. if (shdr_status || shdr_add_status || rc) {
  10562. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10563. "2564 POST_SGL_BLOCK mailbox command failed "
  10564. "status x%x add_status x%x mbx status x%x\n",
  10565. shdr_status, shdr_add_status, rc);
  10566. rc = -ENXIO;
  10567. }
  10568. return rc;
  10569. }
  10570. /**
  10571. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10572. * @phba: pointer to lpfc_hba struct that the frame was received on
  10573. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10574. *
  10575. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10576. * valid type of frame that the LPFC driver will handle. This function will
  10577. * return a zero if the frame is a valid frame or a non zero value when the
  10578. * frame does not pass the check.
  10579. **/
  10580. static int
  10581. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10582. {
  10583. /* make rctl_names static to save stack space */
  10584. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10585. char *type_names[] = FC_TYPE_NAMES_INIT;
  10586. struct fc_vft_header *fc_vft_hdr;
  10587. switch (fc_hdr->fh_r_ctl) {
  10588. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10589. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10590. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10591. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10592. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10593. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10594. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10595. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10596. case FC_RCTL_ELS_REQ: /* extended link services request */
  10597. case FC_RCTL_ELS_REP: /* extended link services reply */
  10598. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10599. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10600. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10601. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10602. case FC_RCTL_BA_RMC: /* remove connection */
  10603. case FC_RCTL_BA_ACC: /* basic accept */
  10604. case FC_RCTL_BA_RJT: /* basic reject */
  10605. case FC_RCTL_BA_PRMT:
  10606. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10607. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10608. case FC_RCTL_P_RJT: /* port reject */
  10609. case FC_RCTL_F_RJT: /* fabric reject */
  10610. case FC_RCTL_P_BSY: /* port busy */
  10611. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10612. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10613. case FC_RCTL_LCR: /* link credit reset */
  10614. case FC_RCTL_END: /* end */
  10615. break;
  10616. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10617. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10618. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10619. return lpfc_fc_frame_check(phba, fc_hdr);
  10620. default:
  10621. goto drop;
  10622. }
  10623. switch (fc_hdr->fh_type) {
  10624. case FC_TYPE_BLS:
  10625. case FC_TYPE_ELS:
  10626. case FC_TYPE_FCP:
  10627. case FC_TYPE_CT:
  10628. break;
  10629. case FC_TYPE_IP:
  10630. case FC_TYPE_ILS:
  10631. default:
  10632. goto drop;
  10633. }
  10634. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10635. "2538 Received frame rctl:%s type:%s\n",
  10636. rctl_names[fc_hdr->fh_r_ctl],
  10637. type_names[fc_hdr->fh_type]);
  10638. return 0;
  10639. drop:
  10640. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10641. "2539 Dropped frame rctl:%s type:%s\n",
  10642. rctl_names[fc_hdr->fh_r_ctl],
  10643. type_names[fc_hdr->fh_type]);
  10644. return 1;
  10645. }
  10646. /**
  10647. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10648. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10649. *
  10650. * This function processes the FC header to retrieve the VFI from the VF
  10651. * header, if one exists. This function will return the VFI if one exists
  10652. * or 0 if no VSAN Header exists.
  10653. **/
  10654. static uint32_t
  10655. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10656. {
  10657. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10658. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10659. return 0;
  10660. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10661. }
  10662. /**
  10663. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10664. * @phba: Pointer to the HBA structure to search for the vport on
  10665. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10666. * @fcfi: The FC Fabric ID that the frame came from
  10667. *
  10668. * This function searches the @phba for a vport that matches the content of the
  10669. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10670. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10671. * returns the matching vport pointer or NULL if unable to match frame to a
  10672. * vport.
  10673. **/
  10674. static struct lpfc_vport *
  10675. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10676. uint16_t fcfi)
  10677. {
  10678. struct lpfc_vport **vports;
  10679. struct lpfc_vport *vport = NULL;
  10680. int i;
  10681. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10682. fc_hdr->fh_d_id[1] << 8 |
  10683. fc_hdr->fh_d_id[2]);
  10684. vports = lpfc_create_vport_work_array(phba);
  10685. if (vports != NULL)
  10686. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10687. if (phba->fcf.fcfi == fcfi &&
  10688. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10689. vports[i]->fc_myDID == did) {
  10690. vport = vports[i];
  10691. break;
  10692. }
  10693. }
  10694. lpfc_destroy_vport_work_array(phba, vports);
  10695. return vport;
  10696. }
  10697. /**
  10698. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10699. * @vport: The vport to work on.
  10700. *
  10701. * This function updates the receive sequence time stamp for this vport. The
  10702. * receive sequence time stamp indicates the time that the last frame of the
  10703. * the sequence that has been idle for the longest amount of time was received.
  10704. * the driver uses this time stamp to indicate if any received sequences have
  10705. * timed out.
  10706. **/
  10707. void
  10708. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10709. {
  10710. struct lpfc_dmabuf *h_buf;
  10711. struct hbq_dmabuf *dmabuf = NULL;
  10712. /* get the oldest sequence on the rcv list */
  10713. h_buf = list_get_first(&vport->rcv_buffer_list,
  10714. struct lpfc_dmabuf, list);
  10715. if (!h_buf)
  10716. return;
  10717. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10718. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10719. }
  10720. /**
  10721. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10722. * @vport: The vport that the received sequences were sent to.
  10723. *
  10724. * This function cleans up all outstanding received sequences. This is called
  10725. * by the driver when a link event or user action invalidates all the received
  10726. * sequences.
  10727. **/
  10728. void
  10729. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10730. {
  10731. struct lpfc_dmabuf *h_buf, *hnext;
  10732. struct lpfc_dmabuf *d_buf, *dnext;
  10733. struct hbq_dmabuf *dmabuf = NULL;
  10734. /* start with the oldest sequence on the rcv list */
  10735. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10736. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10737. list_del_init(&dmabuf->hbuf.list);
  10738. list_for_each_entry_safe(d_buf, dnext,
  10739. &dmabuf->dbuf.list, list) {
  10740. list_del_init(&d_buf->list);
  10741. lpfc_in_buf_free(vport->phba, d_buf);
  10742. }
  10743. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10744. }
  10745. }
  10746. /**
  10747. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10748. * @vport: The vport that the received sequences were sent to.
  10749. *
  10750. * This function determines whether any received sequences have timed out by
  10751. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10752. * indicates that there is at least one timed out sequence this routine will
  10753. * go through the received sequences one at a time from most inactive to most
  10754. * active to determine which ones need to be cleaned up. Once it has determined
  10755. * that a sequence needs to be cleaned up it will simply free up the resources
  10756. * without sending an abort.
  10757. **/
  10758. void
  10759. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10760. {
  10761. struct lpfc_dmabuf *h_buf, *hnext;
  10762. struct lpfc_dmabuf *d_buf, *dnext;
  10763. struct hbq_dmabuf *dmabuf = NULL;
  10764. unsigned long timeout;
  10765. int abort_count = 0;
  10766. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10767. vport->rcv_buffer_time_stamp);
  10768. if (list_empty(&vport->rcv_buffer_list) ||
  10769. time_before(jiffies, timeout))
  10770. return;
  10771. /* start with the oldest sequence on the rcv list */
  10772. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10773. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10774. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10775. dmabuf->time_stamp);
  10776. if (time_before(jiffies, timeout))
  10777. break;
  10778. abort_count++;
  10779. list_del_init(&dmabuf->hbuf.list);
  10780. list_for_each_entry_safe(d_buf, dnext,
  10781. &dmabuf->dbuf.list, list) {
  10782. list_del_init(&d_buf->list);
  10783. lpfc_in_buf_free(vport->phba, d_buf);
  10784. }
  10785. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10786. }
  10787. if (abort_count)
  10788. lpfc_update_rcv_time_stamp(vport);
  10789. }
  10790. /**
  10791. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10792. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10793. *
  10794. * This function searches through the existing incomplete sequences that have
  10795. * been sent to this @vport. If the frame matches one of the incomplete
  10796. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10797. * make up that sequence. If no sequence is found that matches this frame then
  10798. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10799. * This function returns a pointer to the first dmabuf in the sequence list that
  10800. * the frame was linked to.
  10801. **/
  10802. static struct hbq_dmabuf *
  10803. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10804. {
  10805. struct fc_frame_header *new_hdr;
  10806. struct fc_frame_header *temp_hdr;
  10807. struct lpfc_dmabuf *d_buf;
  10808. struct lpfc_dmabuf *h_buf;
  10809. struct hbq_dmabuf *seq_dmabuf = NULL;
  10810. struct hbq_dmabuf *temp_dmabuf = NULL;
  10811. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10812. dmabuf->time_stamp = jiffies;
  10813. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10814. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10815. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10816. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10817. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10818. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10819. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10820. continue;
  10821. /* found a pending sequence that matches this frame */
  10822. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10823. break;
  10824. }
  10825. if (!seq_dmabuf) {
  10826. /*
  10827. * This indicates first frame received for this sequence.
  10828. * Queue the buffer on the vport's rcv_buffer_list.
  10829. */
  10830. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10831. lpfc_update_rcv_time_stamp(vport);
  10832. return dmabuf;
  10833. }
  10834. temp_hdr = seq_dmabuf->hbuf.virt;
  10835. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10836. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10837. list_del_init(&seq_dmabuf->hbuf.list);
  10838. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10839. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10840. lpfc_update_rcv_time_stamp(vport);
  10841. return dmabuf;
  10842. }
  10843. /* move this sequence to the tail to indicate a young sequence */
  10844. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10845. seq_dmabuf->time_stamp = jiffies;
  10846. lpfc_update_rcv_time_stamp(vport);
  10847. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10848. temp_hdr = dmabuf->hbuf.virt;
  10849. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10850. return seq_dmabuf;
  10851. }
  10852. /* find the correct place in the sequence to insert this frame */
  10853. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10854. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10855. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10856. /*
  10857. * If the frame's sequence count is greater than the frame on
  10858. * the list then insert the frame right after this frame
  10859. */
  10860. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10861. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10862. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10863. return seq_dmabuf;
  10864. }
  10865. }
  10866. return NULL;
  10867. }
  10868. /**
  10869. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10870. * @vport: pointer to a vitural port
  10871. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10872. *
  10873. * This function tries to abort from the partially assembed sequence, described
  10874. * by the information from basic abbort @dmabuf. It checks to see whether such
  10875. * partially assembled sequence held by the driver. If so, it shall free up all
  10876. * the frames from the partially assembled sequence.
  10877. *
  10878. * Return
  10879. * true -- if there is matching partially assembled sequence present and all
  10880. * the frames freed with the sequence;
  10881. * false -- if there is no matching partially assembled sequence present so
  10882. * nothing got aborted in the lower layer driver
  10883. **/
  10884. static bool
  10885. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10886. struct hbq_dmabuf *dmabuf)
  10887. {
  10888. struct fc_frame_header *new_hdr;
  10889. struct fc_frame_header *temp_hdr;
  10890. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10891. struct hbq_dmabuf *seq_dmabuf = NULL;
  10892. /* Use the hdr_buf to find the sequence that matches this frame */
  10893. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10894. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10895. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10896. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10897. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10898. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10899. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10900. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10901. continue;
  10902. /* found a pending sequence that matches this frame */
  10903. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10904. break;
  10905. }
  10906. /* Free up all the frames from the partially assembled sequence */
  10907. if (seq_dmabuf) {
  10908. list_for_each_entry_safe(d_buf, n_buf,
  10909. &seq_dmabuf->dbuf.list, list) {
  10910. list_del_init(&d_buf->list);
  10911. lpfc_in_buf_free(vport->phba, d_buf);
  10912. }
  10913. return true;
  10914. }
  10915. return false;
  10916. }
  10917. /**
  10918. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10919. * @phba: Pointer to HBA context object.
  10920. * @cmd_iocbq: pointer to the command iocbq structure.
  10921. * @rsp_iocbq: pointer to the response iocbq structure.
  10922. *
  10923. * This function handles the sequence abort accept iocb command complete
  10924. * event. It properly releases the memory allocated to the sequence abort
  10925. * accept iocb.
  10926. **/
  10927. static void
  10928. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10929. struct lpfc_iocbq *cmd_iocbq,
  10930. struct lpfc_iocbq *rsp_iocbq)
  10931. {
  10932. if (cmd_iocbq)
  10933. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10934. }
  10935. /**
  10936. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10937. * @phba: Pointer to HBA context object.
  10938. * @fc_hdr: pointer to a FC frame header.
  10939. *
  10940. * This function sends a basic accept to a previous unsol sequence abort
  10941. * event after aborting the sequence handling.
  10942. **/
  10943. static void
  10944. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10945. struct fc_frame_header *fc_hdr)
  10946. {
  10947. struct lpfc_iocbq *ctiocb = NULL;
  10948. struct lpfc_nodelist *ndlp;
  10949. uint16_t oxid, rxid;
  10950. uint32_t sid, fctl;
  10951. IOCB_t *icmd;
  10952. if (!lpfc_is_link_up(phba))
  10953. return;
  10954. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10955. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10956. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10957. ndlp = lpfc_findnode_did(phba->pport, sid);
  10958. if (!ndlp) {
  10959. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10960. "1268 Find ndlp returned NULL for oxid:x%x "
  10961. "SID:x%x\n", oxid, sid);
  10962. return;
  10963. }
  10964. if (rxid >= phba->sli4_hba.max_cfg_param.xri_base
  10965. && rxid <= (phba->sli4_hba.max_cfg_param.max_xri
  10966. + phba->sli4_hba.max_cfg_param.xri_base))
  10967. lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
  10968. /* Allocate buffer for acc iocb */
  10969. ctiocb = lpfc_sli_get_iocbq(phba);
  10970. if (!ctiocb)
  10971. return;
  10972. /* Extract the F_CTL field from FC_HDR */
  10973. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10974. icmd = &ctiocb->iocb;
  10975. icmd->un.xseq64.bdl.bdeSize = 0;
  10976. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10977. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10978. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10979. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10980. /* Fill in the rest of iocb fields */
  10981. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10982. icmd->ulpBdeCount = 0;
  10983. icmd->ulpLe = 1;
  10984. icmd->ulpClass = CLASS3;
  10985. icmd->ulpContext = ndlp->nlp_rpi;
  10986. ctiocb->context1 = ndlp;
  10987. ctiocb->iocb_cmpl = NULL;
  10988. ctiocb->vport = phba->pport;
  10989. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10990. if (fctl & FC_FC_EX_CTX) {
  10991. /* ABTS sent by responder to CT exchange, construction
  10992. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10993. * field and RX_ID from ABTS for RX_ID field.
  10994. */
  10995. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10996. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10997. ctiocb->sli4_xritag = oxid;
  10998. } else {
  10999. /* ABTS sent by initiator to CT exchange, construction
  11000. * of BA_ACC will need to allocate a new XRI as for the
  11001. * XRI_TAG and RX_ID fields.
  11002. */
  11003. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  11004. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  11005. ctiocb->sli4_xritag = NO_XRI;
  11006. }
  11007. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  11008. /* Xmit CT abts accept on exchange <xid> */
  11009. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  11010. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  11011. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  11012. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  11013. }
  11014. /**
  11015. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  11016. * @vport: Pointer to the vport on which this sequence was received
  11017. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11018. *
  11019. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  11020. * receive sequence is only partially assembed by the driver, it shall abort
  11021. * the partially assembled frames for the sequence. Otherwise, if the
  11022. * unsolicited receive sequence has been completely assembled and passed to
  11023. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  11024. * unsolicited sequence has been aborted. After that, it will issue a basic
  11025. * accept to accept the abort.
  11026. **/
  11027. void
  11028. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  11029. struct hbq_dmabuf *dmabuf)
  11030. {
  11031. struct lpfc_hba *phba = vport->phba;
  11032. struct fc_frame_header fc_hdr;
  11033. uint32_t fctl;
  11034. bool abts_par;
  11035. /* Make a copy of fc_hdr before the dmabuf being released */
  11036. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  11037. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  11038. if (fctl & FC_FC_EX_CTX) {
  11039. /*
  11040. * ABTS sent by responder to exchange, just free the buffer
  11041. */
  11042. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11043. } else {
  11044. /*
  11045. * ABTS sent by initiator to exchange, need to do cleanup
  11046. */
  11047. /* Try to abort partially assembled seq */
  11048. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  11049. /* Send abort to ULP if partially seq abort failed */
  11050. if (abts_par == false)
  11051. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  11052. else
  11053. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11054. }
  11055. /* Send basic accept (BA_ACC) to the abort requester */
  11056. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  11057. }
  11058. /**
  11059. * lpfc_seq_complete - Indicates if a sequence is complete
  11060. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11061. *
  11062. * This function checks the sequence, starting with the frame described by
  11063. * @dmabuf, to see if all the frames associated with this sequence are present.
  11064. * the frames associated with this sequence are linked to the @dmabuf using the
  11065. * dbuf list. This function looks for two major things. 1) That the first frame
  11066. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  11067. * set. 3) That there are no holes in the sequence count. The function will
  11068. * return 1 when the sequence is complete, otherwise it will return 0.
  11069. **/
  11070. static int
  11071. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  11072. {
  11073. struct fc_frame_header *hdr;
  11074. struct lpfc_dmabuf *d_buf;
  11075. struct hbq_dmabuf *seq_dmabuf;
  11076. uint32_t fctl;
  11077. int seq_count = 0;
  11078. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11079. /* make sure first fame of sequence has a sequence count of zero */
  11080. if (hdr->fh_seq_cnt != seq_count)
  11081. return 0;
  11082. fctl = (hdr->fh_f_ctl[0] << 16 |
  11083. hdr->fh_f_ctl[1] << 8 |
  11084. hdr->fh_f_ctl[2]);
  11085. /* If last frame of sequence we can return success. */
  11086. if (fctl & FC_FC_END_SEQ)
  11087. return 1;
  11088. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  11089. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  11090. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11091. /* If there is a hole in the sequence count then fail. */
  11092. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  11093. return 0;
  11094. fctl = (hdr->fh_f_ctl[0] << 16 |
  11095. hdr->fh_f_ctl[1] << 8 |
  11096. hdr->fh_f_ctl[2]);
  11097. /* If last frame of sequence we can return success. */
  11098. if (fctl & FC_FC_END_SEQ)
  11099. return 1;
  11100. }
  11101. return 0;
  11102. }
  11103. /**
  11104. * lpfc_prep_seq - Prep sequence for ULP processing
  11105. * @vport: Pointer to the vport on which this sequence was received
  11106. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11107. *
  11108. * This function takes a sequence, described by a list of frames, and creates
  11109. * a list of iocbq structures to describe the sequence. This iocbq list will be
  11110. * used to issue to the generic unsolicited sequence handler. This routine
  11111. * returns a pointer to the first iocbq in the list. If the function is unable
  11112. * to allocate an iocbq then it throw out the received frames that were not
  11113. * able to be described and return a pointer to the first iocbq. If unable to
  11114. * allocate any iocbqs (including the first) this function will return NULL.
  11115. **/
  11116. static struct lpfc_iocbq *
  11117. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  11118. {
  11119. struct lpfc_dmabuf *d_buf, *n_buf;
  11120. struct lpfc_iocbq *first_iocbq, *iocbq;
  11121. struct fc_frame_header *fc_hdr;
  11122. uint32_t sid;
  11123. struct ulp_bde64 *pbde;
  11124. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11125. /* remove from receive buffer list */
  11126. list_del_init(&seq_dmabuf->hbuf.list);
  11127. lpfc_update_rcv_time_stamp(vport);
  11128. /* get the Remote Port's SID */
  11129. sid = sli4_sid_from_fc_hdr(fc_hdr);
  11130. /* Get an iocbq struct to fill in. */
  11131. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  11132. if (first_iocbq) {
  11133. /* Initialize the first IOCB. */
  11134. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  11135. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  11136. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  11137. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  11138. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  11139. vport->vpi + vport->phba->vpi_base;
  11140. /* put the first buffer into the first IOCBq */
  11141. first_iocbq->context2 = &seq_dmabuf->dbuf;
  11142. first_iocbq->context3 = NULL;
  11143. first_iocbq->iocb.ulpBdeCount = 1;
  11144. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11145. LPFC_DATA_BUF_SIZE;
  11146. first_iocbq->iocb.un.rcvels.remoteID = sid;
  11147. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11148. bf_get(lpfc_rcqe_length,
  11149. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11150. }
  11151. iocbq = first_iocbq;
  11152. /*
  11153. * Each IOCBq can have two Buffers assigned, so go through the list
  11154. * of buffers for this sequence and save two buffers in each IOCBq
  11155. */
  11156. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  11157. if (!iocbq) {
  11158. lpfc_in_buf_free(vport->phba, d_buf);
  11159. continue;
  11160. }
  11161. if (!iocbq->context3) {
  11162. iocbq->context3 = d_buf;
  11163. iocbq->iocb.ulpBdeCount++;
  11164. pbde = (struct ulp_bde64 *)
  11165. &iocbq->iocb.unsli3.sli3Words[4];
  11166. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  11167. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11168. bf_get(lpfc_rcqe_length,
  11169. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11170. } else {
  11171. iocbq = lpfc_sli_get_iocbq(vport->phba);
  11172. if (!iocbq) {
  11173. if (first_iocbq) {
  11174. first_iocbq->iocb.ulpStatus =
  11175. IOSTAT_FCP_RSP_ERROR;
  11176. first_iocbq->iocb.un.ulpWord[4] =
  11177. IOERR_NO_RESOURCES;
  11178. }
  11179. lpfc_in_buf_free(vport->phba, d_buf);
  11180. continue;
  11181. }
  11182. iocbq->context2 = d_buf;
  11183. iocbq->context3 = NULL;
  11184. iocbq->iocb.ulpBdeCount = 1;
  11185. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11186. LPFC_DATA_BUF_SIZE;
  11187. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11188. bf_get(lpfc_rcqe_length,
  11189. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11190. iocbq->iocb.un.rcvels.remoteID = sid;
  11191. list_add_tail(&iocbq->list, &first_iocbq->list);
  11192. }
  11193. }
  11194. return first_iocbq;
  11195. }
  11196. static void
  11197. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  11198. struct hbq_dmabuf *seq_dmabuf)
  11199. {
  11200. struct fc_frame_header *fc_hdr;
  11201. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  11202. struct lpfc_hba *phba = vport->phba;
  11203. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11204. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  11205. if (!iocbq) {
  11206. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11207. "2707 Ring %d handler: Failed to allocate "
  11208. "iocb Rctl x%x Type x%x received\n",
  11209. LPFC_ELS_RING,
  11210. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11211. return;
  11212. }
  11213. if (!lpfc_complete_unsol_iocb(phba,
  11214. &phba->sli.ring[LPFC_ELS_RING],
  11215. iocbq, fc_hdr->fh_r_ctl,
  11216. fc_hdr->fh_type))
  11217. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11218. "2540 Ring %d handler: unexpected Rctl "
  11219. "x%x Type x%x received\n",
  11220. LPFC_ELS_RING,
  11221. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11222. /* Free iocb created in lpfc_prep_seq */
  11223. list_for_each_entry_safe(curr_iocb, next_iocb,
  11224. &iocbq->list, list) {
  11225. list_del_init(&curr_iocb->list);
  11226. lpfc_sli_release_iocbq(phba, curr_iocb);
  11227. }
  11228. lpfc_sli_release_iocbq(phba, iocbq);
  11229. }
  11230. /**
  11231. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  11232. * @phba: Pointer to HBA context object.
  11233. *
  11234. * This function is called with no lock held. This function processes all
  11235. * the received buffers and gives it to upper layers when a received buffer
  11236. * indicates that it is the final frame in the sequence. The interrupt
  11237. * service routine processes received buffers at interrupt contexts and adds
  11238. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  11239. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  11240. * appropriate receive function when the final frame in a sequence is received.
  11241. **/
  11242. void
  11243. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  11244. struct hbq_dmabuf *dmabuf)
  11245. {
  11246. struct hbq_dmabuf *seq_dmabuf;
  11247. struct fc_frame_header *fc_hdr;
  11248. struct lpfc_vport *vport;
  11249. uint32_t fcfi;
  11250. /* Process each received buffer */
  11251. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11252. /* check to see if this a valid type of frame */
  11253. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  11254. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11255. return;
  11256. }
  11257. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  11258. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  11259. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  11260. /* throw out the frame */
  11261. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11262. return;
  11263. }
  11264. /* Handle the basic abort sequence (BA_ABTS) event */
  11265. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  11266. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  11267. return;
  11268. }
  11269. /* Link this frame */
  11270. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  11271. if (!seq_dmabuf) {
  11272. /* unable to add frame to vport - throw it out */
  11273. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11274. return;
  11275. }
  11276. /* If not last frame in sequence continue processing frames. */
  11277. if (!lpfc_seq_complete(seq_dmabuf))
  11278. return;
  11279. /* Send the complete sequence to the upper layer protocol */
  11280. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  11281. }
  11282. /**
  11283. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  11284. * @phba: pointer to lpfc hba data structure.
  11285. *
  11286. * This routine is invoked to post rpi header templates to the
  11287. * HBA consistent with the SLI-4 interface spec. This routine
  11288. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11289. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11290. *
  11291. * This routine does not require any locks. It's usage is expected
  11292. * to be driver load or reset recovery when the driver is
  11293. * sequential.
  11294. *
  11295. * Return codes
  11296. * 0 - successful
  11297. * -EIO - The mailbox failed to complete successfully.
  11298. * When this error occurs, the driver is not guaranteed
  11299. * to have any rpi regions posted to the device and
  11300. * must either attempt to repost the regions or take a
  11301. * fatal error.
  11302. **/
  11303. int
  11304. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  11305. {
  11306. struct lpfc_rpi_hdr *rpi_page;
  11307. uint32_t rc = 0;
  11308. /* Post all rpi memory regions to the port. */
  11309. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  11310. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  11311. if (rc != MBX_SUCCESS) {
  11312. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11313. "2008 Error %d posting all rpi "
  11314. "headers\n", rc);
  11315. rc = -EIO;
  11316. break;
  11317. }
  11318. }
  11319. return rc;
  11320. }
  11321. /**
  11322. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  11323. * @phba: pointer to lpfc hba data structure.
  11324. * @rpi_page: pointer to the rpi memory region.
  11325. *
  11326. * This routine is invoked to post a single rpi header to the
  11327. * HBA consistent with the SLI-4 interface spec. This memory region
  11328. * maps up to 64 rpi context regions.
  11329. *
  11330. * Return codes
  11331. * 0 - successful
  11332. * -ENOMEM - No available memory
  11333. * -EIO - The mailbox failed to complete successfully.
  11334. **/
  11335. int
  11336. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  11337. {
  11338. LPFC_MBOXQ_t *mboxq;
  11339. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  11340. uint32_t rc = 0;
  11341. uint32_t mbox_tmo;
  11342. uint32_t shdr_status, shdr_add_status;
  11343. union lpfc_sli4_cfg_shdr *shdr;
  11344. /* The port is notified of the header region via a mailbox command. */
  11345. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11346. if (!mboxq) {
  11347. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11348. "2001 Unable to allocate memory for issuing "
  11349. "SLI_CONFIG_SPECIAL mailbox command\n");
  11350. return -ENOMEM;
  11351. }
  11352. /* Post all rpi memory regions to the port. */
  11353. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  11354. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  11355. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11356. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  11357. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  11358. sizeof(struct lpfc_sli4_cfg_mhdr),
  11359. LPFC_SLI4_MBX_EMBED);
  11360. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  11361. hdr_tmpl, rpi_page->page_count);
  11362. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  11363. rpi_page->start_rpi);
  11364. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  11365. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  11366. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  11367. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  11368. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11369. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11370. if (rc != MBX_TIMEOUT)
  11371. mempool_free(mboxq, phba->mbox_mem_pool);
  11372. if (shdr_status || shdr_add_status || rc) {
  11373. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11374. "2514 POST_RPI_HDR mailbox failed with "
  11375. "status x%x add_status x%x, mbx status x%x\n",
  11376. shdr_status, shdr_add_status, rc);
  11377. rc = -ENXIO;
  11378. }
  11379. return rc;
  11380. }
  11381. /**
  11382. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  11383. * @phba: pointer to lpfc hba data structure.
  11384. *
  11385. * This routine is invoked to post rpi header templates to the
  11386. * HBA consistent with the SLI-4 interface spec. This routine
  11387. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11388. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11389. *
  11390. * Returns
  11391. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  11392. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  11393. **/
  11394. int
  11395. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  11396. {
  11397. int rpi;
  11398. uint16_t max_rpi, rpi_base, rpi_limit;
  11399. uint16_t rpi_remaining;
  11400. struct lpfc_rpi_hdr *rpi_hdr;
  11401. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  11402. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  11403. rpi_limit = phba->sli4_hba.next_rpi;
  11404. /*
  11405. * The valid rpi range is not guaranteed to be zero-based. Start
  11406. * the search at the rpi_base as reported by the port.
  11407. */
  11408. spin_lock_irq(&phba->hbalock);
  11409. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  11410. if (rpi >= rpi_limit || rpi < rpi_base)
  11411. rpi = LPFC_RPI_ALLOC_ERROR;
  11412. else {
  11413. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  11414. phba->sli4_hba.max_cfg_param.rpi_used++;
  11415. phba->sli4_hba.rpi_count++;
  11416. }
  11417. /*
  11418. * Don't try to allocate more rpi header regions if the device limit
  11419. * on available rpis max has been exhausted.
  11420. */
  11421. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  11422. (phba->sli4_hba.rpi_count >= max_rpi)) {
  11423. spin_unlock_irq(&phba->hbalock);
  11424. return rpi;
  11425. }
  11426. /*
  11427. * If the driver is running low on rpi resources, allocate another
  11428. * page now. Note that the next_rpi value is used because
  11429. * it represents how many are actually in use whereas max_rpi notes
  11430. * how many are supported max by the device.
  11431. */
  11432. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  11433. phba->sli4_hba.rpi_count;
  11434. spin_unlock_irq(&phba->hbalock);
  11435. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  11436. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  11437. if (!rpi_hdr) {
  11438. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11439. "2002 Error Could not grow rpi "
  11440. "count\n");
  11441. } else {
  11442. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  11443. }
  11444. }
  11445. return rpi;
  11446. }
  11447. /**
  11448. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11449. * @phba: pointer to lpfc hba data structure.
  11450. *
  11451. * This routine is invoked to release an rpi to the pool of
  11452. * available rpis maintained by the driver.
  11453. **/
  11454. void
  11455. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11456. {
  11457. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  11458. phba->sli4_hba.rpi_count--;
  11459. phba->sli4_hba.max_cfg_param.rpi_used--;
  11460. }
  11461. }
  11462. /**
  11463. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11464. * @phba: pointer to lpfc hba data structure.
  11465. *
  11466. * This routine is invoked to release an rpi to the pool of
  11467. * available rpis maintained by the driver.
  11468. **/
  11469. void
  11470. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11471. {
  11472. spin_lock_irq(&phba->hbalock);
  11473. __lpfc_sli4_free_rpi(phba, rpi);
  11474. spin_unlock_irq(&phba->hbalock);
  11475. }
  11476. /**
  11477. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  11478. * @phba: pointer to lpfc hba data structure.
  11479. *
  11480. * This routine is invoked to remove the memory region that
  11481. * provided rpi via a bitmask.
  11482. **/
  11483. void
  11484. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  11485. {
  11486. kfree(phba->sli4_hba.rpi_bmask);
  11487. }
  11488. /**
  11489. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  11490. * @phba: pointer to lpfc hba data structure.
  11491. *
  11492. * This routine is invoked to remove the memory region that
  11493. * provided rpi via a bitmask.
  11494. **/
  11495. int
  11496. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  11497. {
  11498. LPFC_MBOXQ_t *mboxq;
  11499. struct lpfc_hba *phba = ndlp->phba;
  11500. int rc;
  11501. /* The port is notified of the header region via a mailbox command. */
  11502. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11503. if (!mboxq)
  11504. return -ENOMEM;
  11505. /* Post all rpi memory regions to the port. */
  11506. lpfc_resume_rpi(mboxq, ndlp);
  11507. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11508. if (rc == MBX_NOT_FINISHED) {
  11509. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11510. "2010 Resume RPI Mailbox failed "
  11511. "status %d, mbxStatus x%x\n", rc,
  11512. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11513. mempool_free(mboxq, phba->mbox_mem_pool);
  11514. return -EIO;
  11515. }
  11516. return 0;
  11517. }
  11518. /**
  11519. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11520. * @vport: Pointer to the vport for which the vpi is being initialized
  11521. *
  11522. * This routine is invoked to activate a vpi with the port.
  11523. *
  11524. * Returns:
  11525. * 0 success
  11526. * -Evalue otherwise
  11527. **/
  11528. int
  11529. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  11530. {
  11531. LPFC_MBOXQ_t *mboxq;
  11532. int rc = 0;
  11533. int retval = MBX_SUCCESS;
  11534. uint32_t mbox_tmo;
  11535. struct lpfc_hba *phba = vport->phba;
  11536. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11537. if (!mboxq)
  11538. return -ENOMEM;
  11539. lpfc_init_vpi(phba, mboxq, vport->vpi);
  11540. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11541. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11542. if (rc != MBX_SUCCESS) {
  11543. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  11544. "2022 INIT VPI Mailbox failed "
  11545. "status %d, mbxStatus x%x\n", rc,
  11546. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11547. retval = -EIO;
  11548. }
  11549. if (rc != MBX_TIMEOUT)
  11550. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  11551. return retval;
  11552. }
  11553. /**
  11554. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11555. * @phba: pointer to lpfc hba data structure.
  11556. * @mboxq: Pointer to mailbox object.
  11557. *
  11558. * This routine is invoked to manually add a single FCF record. The caller
  11559. * must pass a completely initialized FCF_Record. This routine takes
  11560. * care of the nonembedded mailbox operations.
  11561. **/
  11562. static void
  11563. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11564. {
  11565. void *virt_addr;
  11566. union lpfc_sli4_cfg_shdr *shdr;
  11567. uint32_t shdr_status, shdr_add_status;
  11568. virt_addr = mboxq->sge_array->addr[0];
  11569. /* The IOCTL status is embedded in the mailbox subheader. */
  11570. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11571. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11572. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11573. if ((shdr_status || shdr_add_status) &&
  11574. (shdr_status != STATUS_FCF_IN_USE))
  11575. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11576. "2558 ADD_FCF_RECORD mailbox failed with "
  11577. "status x%x add_status x%x\n",
  11578. shdr_status, shdr_add_status);
  11579. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11580. }
  11581. /**
  11582. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11583. * @phba: pointer to lpfc hba data structure.
  11584. * @fcf_record: pointer to the initialized fcf record to add.
  11585. *
  11586. * This routine is invoked to manually add a single FCF record. The caller
  11587. * must pass a completely initialized FCF_Record. This routine takes
  11588. * care of the nonembedded mailbox operations.
  11589. **/
  11590. int
  11591. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11592. {
  11593. int rc = 0;
  11594. LPFC_MBOXQ_t *mboxq;
  11595. uint8_t *bytep;
  11596. void *virt_addr;
  11597. dma_addr_t phys_addr;
  11598. struct lpfc_mbx_sge sge;
  11599. uint32_t alloc_len, req_len;
  11600. uint32_t fcfindex;
  11601. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11602. if (!mboxq) {
  11603. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11604. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11605. return -ENOMEM;
  11606. }
  11607. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11608. sizeof(uint32_t);
  11609. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11610. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11611. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11612. req_len, LPFC_SLI4_MBX_NEMBED);
  11613. if (alloc_len < req_len) {
  11614. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11615. "2523 Allocated DMA memory size (x%x) is "
  11616. "less than the requested DMA memory "
  11617. "size (x%x)\n", alloc_len, req_len);
  11618. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11619. return -ENOMEM;
  11620. }
  11621. /*
  11622. * Get the first SGE entry from the non-embedded DMA memory. This
  11623. * routine only uses a single SGE.
  11624. */
  11625. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11626. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11627. virt_addr = mboxq->sge_array->addr[0];
  11628. /*
  11629. * Configure the FCF record for FCFI 0. This is the driver's
  11630. * hardcoded default and gets used in nonFIP mode.
  11631. */
  11632. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11633. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11634. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11635. /*
  11636. * Copy the fcf_index and the FCF Record Data. The data starts after
  11637. * the FCoE header plus word10. The data copy needs to be endian
  11638. * correct.
  11639. */
  11640. bytep += sizeof(uint32_t);
  11641. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11642. mboxq->vport = phba->pport;
  11643. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11644. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11645. if (rc == MBX_NOT_FINISHED) {
  11646. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11647. "2515 ADD_FCF_RECORD mailbox failed with "
  11648. "status 0x%x\n", rc);
  11649. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11650. rc = -EIO;
  11651. } else
  11652. rc = 0;
  11653. return rc;
  11654. }
  11655. /**
  11656. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11657. * @phba: pointer to lpfc hba data structure.
  11658. * @fcf_record: pointer to the fcf record to write the default data.
  11659. * @fcf_index: FCF table entry index.
  11660. *
  11661. * This routine is invoked to build the driver's default FCF record. The
  11662. * values used are hardcoded. This routine handles memory initialization.
  11663. *
  11664. **/
  11665. void
  11666. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11667. struct fcf_record *fcf_record,
  11668. uint16_t fcf_index)
  11669. {
  11670. memset(fcf_record, 0, sizeof(struct fcf_record));
  11671. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11672. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11673. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11674. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11675. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11676. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11677. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11678. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11679. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11680. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11681. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11682. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11683. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11684. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11685. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11686. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11687. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11688. /* Set the VLAN bit map */
  11689. if (phba->valid_vlan) {
  11690. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11691. = 1 << (phba->vlan_id % 8);
  11692. }
  11693. }
  11694. /**
  11695. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11696. * @phba: pointer to lpfc hba data structure.
  11697. * @fcf_index: FCF table entry offset.
  11698. *
  11699. * This routine is invoked to scan the entire FCF table by reading FCF
  11700. * record and processing it one at a time starting from the @fcf_index
  11701. * for initial FCF discovery or fast FCF failover rediscovery.
  11702. *
  11703. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11704. * otherwise.
  11705. **/
  11706. int
  11707. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11708. {
  11709. int rc = 0, error;
  11710. LPFC_MBOXQ_t *mboxq;
  11711. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11712. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11713. if (!mboxq) {
  11714. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11715. "2000 Failed to allocate mbox for "
  11716. "READ_FCF cmd\n");
  11717. error = -ENOMEM;
  11718. goto fail_fcf_scan;
  11719. }
  11720. /* Construct the read FCF record mailbox command */
  11721. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11722. if (rc) {
  11723. error = -EINVAL;
  11724. goto fail_fcf_scan;
  11725. }
  11726. /* Issue the mailbox command asynchronously */
  11727. mboxq->vport = phba->pport;
  11728. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11729. spin_lock_irq(&phba->hbalock);
  11730. phba->hba_flag |= FCF_TS_INPROG;
  11731. spin_unlock_irq(&phba->hbalock);
  11732. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11733. if (rc == MBX_NOT_FINISHED)
  11734. error = -EIO;
  11735. else {
  11736. /* Reset eligible FCF count for new scan */
  11737. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11738. phba->fcf.eligible_fcf_cnt = 0;
  11739. error = 0;
  11740. }
  11741. fail_fcf_scan:
  11742. if (error) {
  11743. if (mboxq)
  11744. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11745. /* FCF scan failed, clear FCF_TS_INPROG flag */
  11746. spin_lock_irq(&phba->hbalock);
  11747. phba->hba_flag &= ~FCF_TS_INPROG;
  11748. spin_unlock_irq(&phba->hbalock);
  11749. }
  11750. return error;
  11751. }
  11752. /**
  11753. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  11754. * @phba: pointer to lpfc hba data structure.
  11755. * @fcf_index: FCF table entry offset.
  11756. *
  11757. * This routine is invoked to read an FCF record indicated by @fcf_index
  11758. * and to use it for FLOGI roundrobin FCF failover.
  11759. *
  11760. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11761. * otherwise.
  11762. **/
  11763. int
  11764. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11765. {
  11766. int rc = 0, error;
  11767. LPFC_MBOXQ_t *mboxq;
  11768. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11769. if (!mboxq) {
  11770. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11771. "2763 Failed to allocate mbox for "
  11772. "READ_FCF cmd\n");
  11773. error = -ENOMEM;
  11774. goto fail_fcf_read;
  11775. }
  11776. /* Construct the read FCF record mailbox command */
  11777. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11778. if (rc) {
  11779. error = -EINVAL;
  11780. goto fail_fcf_read;
  11781. }
  11782. /* Issue the mailbox command asynchronously */
  11783. mboxq->vport = phba->pport;
  11784. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11785. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11786. if (rc == MBX_NOT_FINISHED)
  11787. error = -EIO;
  11788. else
  11789. error = 0;
  11790. fail_fcf_read:
  11791. if (error && mboxq)
  11792. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11793. return error;
  11794. }
  11795. /**
  11796. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11797. * @phba: pointer to lpfc hba data structure.
  11798. * @fcf_index: FCF table entry offset.
  11799. *
  11800. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11801. * determine whether it's eligible for FLOGI roundrobin failover list.
  11802. *
  11803. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11804. * otherwise.
  11805. **/
  11806. int
  11807. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11808. {
  11809. int rc = 0, error;
  11810. LPFC_MBOXQ_t *mboxq;
  11811. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11812. if (!mboxq) {
  11813. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11814. "2758 Failed to allocate mbox for "
  11815. "READ_FCF cmd\n");
  11816. error = -ENOMEM;
  11817. goto fail_fcf_read;
  11818. }
  11819. /* Construct the read FCF record mailbox command */
  11820. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11821. if (rc) {
  11822. error = -EINVAL;
  11823. goto fail_fcf_read;
  11824. }
  11825. /* Issue the mailbox command asynchronously */
  11826. mboxq->vport = phba->pport;
  11827. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11828. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11829. if (rc == MBX_NOT_FINISHED)
  11830. error = -EIO;
  11831. else
  11832. error = 0;
  11833. fail_fcf_read:
  11834. if (error && mboxq)
  11835. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11836. return error;
  11837. }
  11838. /**
  11839. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11840. * @phba: pointer to lpfc hba data structure.
  11841. *
  11842. * This routine is to get the next eligible FCF record index in a round
  11843. * robin fashion. If the next eligible FCF record index equals to the
  11844. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11845. * shall be returned, otherwise, the next eligible FCF record's index
  11846. * shall be returned.
  11847. **/
  11848. uint16_t
  11849. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11850. {
  11851. uint16_t next_fcf_index;
  11852. /* Search start from next bit of currently registered FCF index */
  11853. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  11854. LPFC_SLI4_FCF_TBL_INDX_MAX;
  11855. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11856. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11857. next_fcf_index);
  11858. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11859. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11860. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11861. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11862. /* Check roundrobin failover list empty condition */
  11863. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11864. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  11865. "2844 No roundrobin failover FCF available\n");
  11866. return LPFC_FCOE_FCF_NEXT_NONE;
  11867. }
  11868. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11869. "2845 Get next roundrobin failover FCF (x%x)\n",
  11870. next_fcf_index);
  11871. return next_fcf_index;
  11872. }
  11873. /**
  11874. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11875. * @phba: pointer to lpfc hba data structure.
  11876. *
  11877. * This routine sets the FCF record index in to the eligible bmask for
  11878. * roundrobin failover search. It checks to make sure that the index
  11879. * does not go beyond the range of the driver allocated bmask dimension
  11880. * before setting the bit.
  11881. *
  11882. * Returns 0 if the index bit successfully set, otherwise, it returns
  11883. * -EINVAL.
  11884. **/
  11885. int
  11886. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11887. {
  11888. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11889. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11890. "2610 FCF (x%x) reached driver's book "
  11891. "keeping dimension:x%x\n",
  11892. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11893. return -EINVAL;
  11894. }
  11895. /* Set the eligible FCF record index bmask */
  11896. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11897. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11898. "2790 Set FCF (x%x) to roundrobin FCF failover "
  11899. "bmask\n", fcf_index);
  11900. return 0;
  11901. }
  11902. /**
  11903. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  11904. * @phba: pointer to lpfc hba data structure.
  11905. *
  11906. * This routine clears the FCF record index from the eligible bmask for
  11907. * roundrobin failover search. It checks to make sure that the index
  11908. * does not go beyond the range of the driver allocated bmask dimension
  11909. * before clearing the bit.
  11910. **/
  11911. void
  11912. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11913. {
  11914. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11915. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11916. "2762 FCF (x%x) reached driver's book "
  11917. "keeping dimension:x%x\n",
  11918. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11919. return;
  11920. }
  11921. /* Clear the eligible FCF record index bmask */
  11922. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11923. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11924. "2791 Clear FCF (x%x) from roundrobin failover "
  11925. "bmask\n", fcf_index);
  11926. }
  11927. /**
  11928. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11929. * @phba: pointer to lpfc hba data structure.
  11930. *
  11931. * This routine is the completion routine for the rediscover FCF table mailbox
  11932. * command. If the mailbox command returned failure, it will try to stop the
  11933. * FCF rediscover wait timer.
  11934. **/
  11935. void
  11936. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11937. {
  11938. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11939. uint32_t shdr_status, shdr_add_status;
  11940. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11941. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11942. &redisc_fcf->header.cfg_shdr.response);
  11943. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11944. &redisc_fcf->header.cfg_shdr.response);
  11945. if (shdr_status || shdr_add_status) {
  11946. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11947. "2746 Requesting for FCF rediscovery failed "
  11948. "status x%x add_status x%x\n",
  11949. shdr_status, shdr_add_status);
  11950. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11951. spin_lock_irq(&phba->hbalock);
  11952. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11953. spin_unlock_irq(&phba->hbalock);
  11954. /*
  11955. * CVL event triggered FCF rediscover request failed,
  11956. * last resort to re-try current registered FCF entry.
  11957. */
  11958. lpfc_retry_pport_discovery(phba);
  11959. } else {
  11960. spin_lock_irq(&phba->hbalock);
  11961. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11962. spin_unlock_irq(&phba->hbalock);
  11963. /*
  11964. * DEAD FCF event triggered FCF rediscover request
  11965. * failed, last resort to fail over as a link down
  11966. * to FCF registration.
  11967. */
  11968. lpfc_sli4_fcf_dead_failthrough(phba);
  11969. }
  11970. } else {
  11971. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11972. "2775 Start FCF rediscover quiescent timer\n");
  11973. /*
  11974. * Start FCF rediscovery wait timer for pending FCF
  11975. * before rescan FCF record table.
  11976. */
  11977. lpfc_fcf_redisc_wait_start_timer(phba);
  11978. }
  11979. mempool_free(mbox, phba->mbox_mem_pool);
  11980. }
  11981. /**
  11982. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  11983. * @phba: pointer to lpfc hba data structure.
  11984. *
  11985. * This routine is invoked to request for rediscovery of the entire FCF table
  11986. * by the port.
  11987. **/
  11988. int
  11989. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11990. {
  11991. LPFC_MBOXQ_t *mbox;
  11992. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11993. int rc, length;
  11994. /* Cancel retry delay timers to all vports before FCF rediscover */
  11995. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11996. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11997. if (!mbox) {
  11998. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11999. "2745 Failed to allocate mbox for "
  12000. "requesting FCF rediscover.\n");
  12001. return -ENOMEM;
  12002. }
  12003. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  12004. sizeof(struct lpfc_sli4_cfg_mhdr));
  12005. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12006. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  12007. length, LPFC_SLI4_MBX_EMBED);
  12008. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  12009. /* Set count to 0 for invalidating the entire FCF database */
  12010. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  12011. /* Issue the mailbox command asynchronously */
  12012. mbox->vport = phba->pport;
  12013. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  12014. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  12015. if (rc == MBX_NOT_FINISHED) {
  12016. mempool_free(mbox, phba->mbox_mem_pool);
  12017. return -EIO;
  12018. }
  12019. return 0;
  12020. }
  12021. /**
  12022. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  12023. * @phba: pointer to lpfc hba data structure.
  12024. *
  12025. * This function is the failover routine as a last resort to the FCF DEAD
  12026. * event when driver failed to perform fast FCF failover.
  12027. **/
  12028. void
  12029. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  12030. {
  12031. uint32_t link_state;
  12032. /*
  12033. * Last resort as FCF DEAD event failover will treat this as
  12034. * a link down, but save the link state because we don't want
  12035. * it to be changed to Link Down unless it is already down.
  12036. */
  12037. link_state = phba->link_state;
  12038. lpfc_linkdown(phba);
  12039. phba->link_state = link_state;
  12040. /* Unregister FCF if no devices connected to it */
  12041. lpfc_unregister_unused_fcf(phba);
  12042. }
  12043. /**
  12044. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  12045. * @phba: pointer to lpfc hba data structure.
  12046. *
  12047. * This function read region 23 and parse TLV for port status to
  12048. * decide if the user disaled the port. If the TLV indicates the
  12049. * port is disabled, the hba_flag is set accordingly.
  12050. **/
  12051. void
  12052. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  12053. {
  12054. LPFC_MBOXQ_t *pmb = NULL;
  12055. MAILBOX_t *mb;
  12056. uint8_t *rgn23_data = NULL;
  12057. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  12058. int rc;
  12059. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12060. if (!pmb) {
  12061. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12062. "2600 lpfc_sli_read_serdes_param failed to"
  12063. " allocate mailbox memory\n");
  12064. goto out;
  12065. }
  12066. mb = &pmb->u.mb;
  12067. /* Get adapter Region 23 data */
  12068. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  12069. if (!rgn23_data)
  12070. goto out;
  12071. do {
  12072. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  12073. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  12074. if (rc != MBX_SUCCESS) {
  12075. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12076. "2601 lpfc_sli_read_link_ste failed to"
  12077. " read config region 23 rc 0x%x Status 0x%x\n",
  12078. rc, mb->mbxStatus);
  12079. mb->un.varDmp.word_cnt = 0;
  12080. }
  12081. /*
  12082. * dump mem may return a zero when finished or we got a
  12083. * mailbox error, either way we are done.
  12084. */
  12085. if (mb->un.varDmp.word_cnt == 0)
  12086. break;
  12087. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  12088. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  12089. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  12090. rgn23_data + offset,
  12091. mb->un.varDmp.word_cnt);
  12092. offset += mb->un.varDmp.word_cnt;
  12093. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  12094. data_size = offset;
  12095. offset = 0;
  12096. if (!data_size)
  12097. goto out;
  12098. /* Check the region signature first */
  12099. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  12100. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12101. "2619 Config region 23 has bad signature\n");
  12102. goto out;
  12103. }
  12104. offset += 4;
  12105. /* Check the data structure version */
  12106. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  12107. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12108. "2620 Config region 23 has bad version\n");
  12109. goto out;
  12110. }
  12111. offset += 4;
  12112. /* Parse TLV entries in the region */
  12113. while (offset < data_size) {
  12114. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  12115. break;
  12116. /*
  12117. * If the TLV is not driver specific TLV or driver id is
  12118. * not linux driver id, skip the record.
  12119. */
  12120. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  12121. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  12122. (rgn23_data[offset + 3] != 0)) {
  12123. offset += rgn23_data[offset + 1] * 4 + 4;
  12124. continue;
  12125. }
  12126. /* Driver found a driver specific TLV in the config region */
  12127. sub_tlv_len = rgn23_data[offset + 1] * 4;
  12128. offset += 4;
  12129. tlv_offset = 0;
  12130. /*
  12131. * Search for configured port state sub-TLV.
  12132. */
  12133. while ((offset < data_size) &&
  12134. (tlv_offset < sub_tlv_len)) {
  12135. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  12136. offset += 4;
  12137. tlv_offset += 4;
  12138. break;
  12139. }
  12140. if (rgn23_data[offset] != PORT_STE_TYPE) {
  12141. offset += rgn23_data[offset + 1] * 4 + 4;
  12142. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  12143. continue;
  12144. }
  12145. /* This HBA contains PORT_STE configured */
  12146. if (!rgn23_data[offset + 2])
  12147. phba->hba_flag |= LINK_DISABLED;
  12148. goto out;
  12149. }
  12150. }
  12151. out:
  12152. if (pmb)
  12153. mempool_free(pmb, phba->mbox_mem_pool);
  12154. kfree(rgn23_data);
  12155. return;
  12156. }
  12157. /**
  12158. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  12159. * @vport: pointer to vport data structure.
  12160. *
  12161. * This function iterate through the mailboxq and clean up all REG_LOGIN
  12162. * and REG_VPI mailbox commands associated with the vport. This function
  12163. * is called when driver want to restart discovery of the vport due to
  12164. * a Clear Virtual Link event.
  12165. **/
  12166. void
  12167. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  12168. {
  12169. struct lpfc_hba *phba = vport->phba;
  12170. LPFC_MBOXQ_t *mb, *nextmb;
  12171. struct lpfc_dmabuf *mp;
  12172. struct lpfc_nodelist *ndlp;
  12173. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  12174. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  12175. LIST_HEAD(mbox_cmd_list);
  12176. uint8_t restart_loop;
  12177. /* Clean up internally queued mailbox commands with the vport */
  12178. spin_lock_irq(&phba->hbalock);
  12179. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  12180. if (mb->vport != vport)
  12181. continue;
  12182. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12183. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12184. continue;
  12185. list_del(&mb->list);
  12186. list_add_tail(&mb->list, &mbox_cmd_list);
  12187. }
  12188. /* Clean up active mailbox command with the vport */
  12189. mb = phba->sli.mbox_active;
  12190. if (mb && (mb->vport == vport)) {
  12191. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  12192. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  12193. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12194. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12195. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  12196. /* Put reference count for delayed processing */
  12197. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  12198. /* Unregister the RPI when mailbox complete */
  12199. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12200. }
  12201. }
  12202. /* Cleanup any mailbox completions which are not yet processed */
  12203. do {
  12204. restart_loop = 0;
  12205. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  12206. /*
  12207. * If this mailox is already processed or it is
  12208. * for another vport ignore it.
  12209. */
  12210. if ((mb->vport != vport) ||
  12211. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  12212. continue;
  12213. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12214. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12215. continue;
  12216. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12217. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12218. ndlp = (struct lpfc_nodelist *)mb->context2;
  12219. /* Unregister the RPI when mailbox complete */
  12220. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12221. restart_loop = 1;
  12222. spin_unlock_irq(&phba->hbalock);
  12223. spin_lock(shost->host_lock);
  12224. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12225. spin_unlock(shost->host_lock);
  12226. spin_lock_irq(&phba->hbalock);
  12227. break;
  12228. }
  12229. }
  12230. } while (restart_loop);
  12231. spin_unlock_irq(&phba->hbalock);
  12232. /* Release the cleaned-up mailbox commands */
  12233. while (!list_empty(&mbox_cmd_list)) {
  12234. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  12235. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12236. mp = (struct lpfc_dmabuf *) (mb->context1);
  12237. if (mp) {
  12238. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  12239. kfree(mp);
  12240. }
  12241. ndlp = (struct lpfc_nodelist *) mb->context2;
  12242. mb->context2 = NULL;
  12243. if (ndlp) {
  12244. spin_lock(shost->host_lock);
  12245. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12246. spin_unlock(shost->host_lock);
  12247. lpfc_nlp_put(ndlp);
  12248. }
  12249. }
  12250. mempool_free(mb, phba->mbox_mem_pool);
  12251. }
  12252. /* Release the ndlp with the cleaned-up active mailbox command */
  12253. if (act_mbx_ndlp) {
  12254. spin_lock(shost->host_lock);
  12255. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12256. spin_unlock(shost->host_lock);
  12257. lpfc_nlp_put(act_mbx_ndlp);
  12258. }
  12259. }
  12260. /**
  12261. * lpfc_drain_txq - Drain the txq
  12262. * @phba: Pointer to HBA context object.
  12263. *
  12264. * This function attempt to submit IOCBs on the txq
  12265. * to the adapter. For SLI4 adapters, the txq contains
  12266. * ELS IOCBs that have been deferred because the there
  12267. * are no SGLs. This congestion can occur with large
  12268. * vport counts during node discovery.
  12269. **/
  12270. uint32_t
  12271. lpfc_drain_txq(struct lpfc_hba *phba)
  12272. {
  12273. LIST_HEAD(completions);
  12274. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  12275. struct lpfc_iocbq *piocbq = 0;
  12276. unsigned long iflags = 0;
  12277. char *fail_msg = NULL;
  12278. struct lpfc_sglq *sglq;
  12279. union lpfc_wqe wqe;
  12280. spin_lock_irqsave(&phba->hbalock, iflags);
  12281. if (pring->txq_cnt > pring->txq_max)
  12282. pring->txq_max = pring->txq_cnt;
  12283. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12284. while (pring->txq_cnt) {
  12285. spin_lock_irqsave(&phba->hbalock, iflags);
  12286. piocbq = lpfc_sli_ringtx_get(phba, pring);
  12287. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  12288. if (!sglq) {
  12289. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  12290. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12291. break;
  12292. } else {
  12293. if (!piocbq) {
  12294. /* The txq_cnt out of sync. This should
  12295. * never happen
  12296. */
  12297. sglq = __lpfc_clear_active_sglq(phba,
  12298. sglq->sli4_xritag);
  12299. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12300. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12301. "2823 txq empty and txq_cnt is %d\n ",
  12302. pring->txq_cnt);
  12303. break;
  12304. }
  12305. }
  12306. /* The xri and iocb resources secured,
  12307. * attempt to issue request
  12308. */
  12309. piocbq->sli4_xritag = sglq->sli4_xritag;
  12310. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  12311. fail_msg = "to convert bpl to sgl";
  12312. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  12313. fail_msg = "to convert iocb to wqe";
  12314. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  12315. fail_msg = " - Wq is full";
  12316. else
  12317. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  12318. if (fail_msg) {
  12319. /* Failed means we can't issue and need to cancel */
  12320. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12321. "2822 IOCB failed %s iotag 0x%x "
  12322. "xri 0x%x\n",
  12323. fail_msg,
  12324. piocbq->iotag, piocbq->sli4_xritag);
  12325. list_add_tail(&piocbq->list, &completions);
  12326. }
  12327. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12328. }
  12329. /* Cancel all the IOCBs that cannot be issued */
  12330. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  12331. IOERR_SLI_ABORTED);
  12332. return pring->txq_cnt;
  12333. }