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. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  92. /* Update the host index before invoking device */
  93. host_index = q->host_index;
  94. q->host_index = ((q->host_index + 1) % q->entry_count);
  95. /* Ring Doorbell */
  96. doorbell.word0 = 0;
  97. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  98. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  99. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  100. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  101. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  102. return 0;
  103. }
  104. /**
  105. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  106. * @q: The Work Queue to operate on.
  107. * @index: The index to advance the hba index to.
  108. *
  109. * This routine will update the HBA index of a queue to reflect consumption of
  110. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  111. * an entry the host calls this function to update the queue's internal
  112. * pointers. This routine returns the number of entries that were consumed by
  113. * the HBA.
  114. **/
  115. static uint32_t
  116. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  117. {
  118. uint32_t released = 0;
  119. if (q->hba_index == index)
  120. return 0;
  121. do {
  122. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  123. released++;
  124. } while (q->hba_index != index);
  125. return released;
  126. }
  127. /**
  128. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  129. * @q: The Mailbox Queue to operate on.
  130. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  131. *
  132. * This routine will copy the contents of @mqe to the next available entry on
  133. * the @q. This function will then ring the Work Queue Doorbell to signal the
  134. * HBA to start processing the Work Queue Entry. This function returns 0 if
  135. * successful. If no entries are available on @q then this function will return
  136. * -ENOMEM.
  137. * The caller is expected to hold the hbalock when calling this routine.
  138. **/
  139. static uint32_t
  140. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  141. {
  142. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  143. struct lpfc_register doorbell;
  144. uint32_t host_index;
  145. /* If the host has not yet processed the next entry then we are done */
  146. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  147. return -ENOMEM;
  148. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  149. /* Save off the mailbox pointer for completion */
  150. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  151. /* Update the host index before invoking device */
  152. host_index = q->host_index;
  153. q->host_index = ((q->host_index + 1) % q->entry_count);
  154. /* Ring Doorbell */
  155. doorbell.word0 = 0;
  156. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  157. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  158. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  159. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  160. return 0;
  161. }
  162. /**
  163. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  164. * @q: The Mailbox Queue to operate on.
  165. *
  166. * This routine will update the HBA index of a queue to reflect consumption of
  167. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  168. * an entry the host calls this function to update the queue's internal
  169. * pointers. This routine returns the number of entries that were consumed by
  170. * the HBA.
  171. **/
  172. static uint32_t
  173. lpfc_sli4_mq_release(struct lpfc_queue *q)
  174. {
  175. /* Clear the mailbox pointer for completion */
  176. q->phba->mbox = NULL;
  177. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  178. return 1;
  179. }
  180. /**
  181. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  182. * @q: The Event Queue to get the first valid EQE from
  183. *
  184. * This routine will get the first valid Event Queue Entry from @q, update
  185. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  186. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  187. * processed, but not popped back to the HBA then this routine will return NULL.
  188. **/
  189. static struct lpfc_eqe *
  190. lpfc_sli4_eq_get(struct lpfc_queue *q)
  191. {
  192. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  193. /* If the next EQE is not valid then we are done */
  194. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  195. return NULL;
  196. /* If the host has not yet processed the next entry then we are done */
  197. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  198. return NULL;
  199. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  200. return eqe;
  201. }
  202. /**
  203. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  204. * @q: The Event Queue that the host has completed processing for.
  205. * @arm: Indicates whether the host wants to arms this CQ.
  206. *
  207. * This routine will mark all Event Queue Entries on @q, from the last
  208. * known completed entry to the last entry that was processed, as completed
  209. * by clearing the valid bit for each completion queue entry. Then it will
  210. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  211. * The internal host index in the @q will be updated by this routine to indicate
  212. * that the host has finished processing the entries. The @arm parameter
  213. * indicates that the queue should be rearmed when ringing the doorbell.
  214. *
  215. * This function will return the number of EQEs that were popped.
  216. **/
  217. uint32_t
  218. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  219. {
  220. uint32_t released = 0;
  221. struct lpfc_eqe *temp_eqe;
  222. struct lpfc_register doorbell;
  223. /* while there are valid entries */
  224. while (q->hba_index != q->host_index) {
  225. temp_eqe = q->qe[q->host_index].eqe;
  226. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  227. released++;
  228. q->host_index = ((q->host_index + 1) % q->entry_count);
  229. }
  230. if (unlikely(released == 0 && !arm))
  231. return 0;
  232. /* ring doorbell for number popped */
  233. doorbell.word0 = 0;
  234. if (arm) {
  235. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  236. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  237. }
  238. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  239. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  240. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  241. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  242. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  243. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  244. readl(q->phba->sli4_hba.EQCQDBregaddr);
  245. return released;
  246. }
  247. /**
  248. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  249. * @q: The Completion Queue to get the first valid CQE from
  250. *
  251. * This routine will get the first valid Completion Queue Entry from @q, update
  252. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  253. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  254. * processed, but not popped back to the HBA then this routine will return NULL.
  255. **/
  256. static struct lpfc_cqe *
  257. lpfc_sli4_cq_get(struct lpfc_queue *q)
  258. {
  259. struct lpfc_cqe *cqe;
  260. /* If the next CQE is not valid then we are done */
  261. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  262. return NULL;
  263. /* If the host has not yet processed the next entry then we are done */
  264. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  265. return NULL;
  266. cqe = q->qe[q->hba_index].cqe;
  267. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  268. return cqe;
  269. }
  270. /**
  271. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  272. * @q: The Completion Queue that the host has completed processing for.
  273. * @arm: Indicates whether the host wants to arms this CQ.
  274. *
  275. * This routine will mark all Completion queue entries on @q, from the last
  276. * known completed entry to the last entry that was processed, as completed
  277. * by clearing the valid bit for each completion queue entry. Then it will
  278. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  279. * The internal host index in the @q will be updated by this routine to indicate
  280. * that the host has finished processing the entries. The @arm parameter
  281. * indicates that the queue should be rearmed when ringing the doorbell.
  282. *
  283. * This function will return the number of CQEs that were released.
  284. **/
  285. uint32_t
  286. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  287. {
  288. uint32_t released = 0;
  289. struct lpfc_cqe *temp_qe;
  290. struct lpfc_register doorbell;
  291. /* while there are valid entries */
  292. while (q->hba_index != q->host_index) {
  293. temp_qe = q->qe[q->host_index].cqe;
  294. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  295. released++;
  296. q->host_index = ((q->host_index + 1) % q->entry_count);
  297. }
  298. if (unlikely(released == 0 && !arm))
  299. return 0;
  300. /* ring doorbell for number popped */
  301. doorbell.word0 = 0;
  302. if (arm)
  303. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  304. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  305. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  306. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  307. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  308. return released;
  309. }
  310. /**
  311. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  312. * @q: The Header Receive Queue to operate on.
  313. * @wqe: The Receive Queue Entry to put on the Receive queue.
  314. *
  315. * This routine will copy the contents of @wqe to the next available entry on
  316. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  317. * HBA to start processing the Receive Queue Entry. This function returns the
  318. * index that the rqe was copied to if successful. If no entries are available
  319. * on @q then this function will return -ENOMEM.
  320. * The caller is expected to hold the hbalock when calling this routine.
  321. **/
  322. static int
  323. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  324. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  325. {
  326. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  327. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  328. struct lpfc_register doorbell;
  329. int put_index = hq->host_index;
  330. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  331. return -EINVAL;
  332. if (hq->host_index != dq->host_index)
  333. return -EINVAL;
  334. /* If the host has not yet processed the next entry then we are done */
  335. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  336. return -EBUSY;
  337. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  338. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  339. /* Update the host index to point to the next slot */
  340. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  341. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  342. /* Ring The Header Receive Queue Doorbell */
  343. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  344. doorbell.word0 = 0;
  345. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  346. LPFC_RQ_POST_BATCH);
  347. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  348. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  349. }
  350. return put_index;
  351. }
  352. /**
  353. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  354. * @q: The Header Receive Queue to operate on.
  355. *
  356. * This routine will update the HBA index of a queue to reflect consumption of
  357. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  358. * consumed an entry the host calls this function to update the queue's
  359. * internal pointers. This routine returns the number of entries that were
  360. * consumed by the HBA.
  361. **/
  362. static uint32_t
  363. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  364. {
  365. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  366. return 0;
  367. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  368. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  369. return 1;
  370. }
  371. /**
  372. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  373. * @phba: Pointer to HBA context object.
  374. * @pring: Pointer to driver SLI ring object.
  375. *
  376. * This function returns pointer to next command iocb entry
  377. * in the command ring. The caller must hold hbalock to prevent
  378. * other threads consume the next command iocb.
  379. * SLI-2/SLI-3 provide different sized iocbs.
  380. **/
  381. static inline IOCB_t *
  382. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  383. {
  384. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  385. pring->cmdidx * phba->iocb_cmd_size);
  386. }
  387. /**
  388. * lpfc_resp_iocb - Get next response iocb entry in the ring
  389. * @phba: Pointer to HBA context object.
  390. * @pring: Pointer to driver SLI ring object.
  391. *
  392. * This function returns pointer to next response iocb entry
  393. * in the response ring. The caller must hold hbalock to make sure
  394. * that no other thread consume the next response iocb.
  395. * SLI-2/SLI-3 provide different sized iocbs.
  396. **/
  397. static inline IOCB_t *
  398. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  399. {
  400. return (IOCB_t *) (((char *) pring->rspringaddr) +
  401. pring->rspidx * phba->iocb_rsp_size);
  402. }
  403. /**
  404. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  405. * @phba: Pointer to HBA context object.
  406. *
  407. * This function is called with hbalock held. This function
  408. * allocates a new driver iocb object from the iocb pool. If the
  409. * allocation is successful, it returns pointer to the newly
  410. * allocated iocb object else it returns NULL.
  411. **/
  412. static struct lpfc_iocbq *
  413. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  414. {
  415. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  416. struct lpfc_iocbq * iocbq = NULL;
  417. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  418. if (iocbq)
  419. phba->iocb_cnt++;
  420. if (phba->iocb_cnt > phba->iocb_max)
  421. phba->iocb_max = phba->iocb_cnt;
  422. return iocbq;
  423. }
  424. /**
  425. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  426. * @phba: Pointer to HBA context object.
  427. * @xritag: XRI value.
  428. *
  429. * This function clears the sglq pointer from the array of acive
  430. * sglq's. The xritag that is passed in is used to index into the
  431. * array. Before the xritag can be used it needs to be adjusted
  432. * by subtracting the xribase.
  433. *
  434. * Returns sglq ponter = success, NULL = Failure.
  435. **/
  436. static struct lpfc_sglq *
  437. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  438. {
  439. uint16_t adj_xri;
  440. struct lpfc_sglq *sglq;
  441. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  442. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  443. return NULL;
  444. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  445. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  446. return sglq;
  447. }
  448. /**
  449. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  450. * @phba: Pointer to HBA context object.
  451. * @xritag: XRI value.
  452. *
  453. * This function returns the sglq pointer from the array of acive
  454. * sglq's. The xritag that is passed in is used to index into the
  455. * array. Before the xritag can be used it needs to be adjusted
  456. * by subtracting the xribase.
  457. *
  458. * Returns sglq ponter = success, NULL = Failure.
  459. **/
  460. struct lpfc_sglq *
  461. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  462. {
  463. uint16_t adj_xri;
  464. struct lpfc_sglq *sglq;
  465. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  466. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  467. return NULL;
  468. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  469. return sglq;
  470. }
  471. /**
  472. * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
  473. * @phba: Pointer to HBA context object.
  474. * @ndlp: nodelist pointer for this target.
  475. * @xritag: xri used in this exchange.
  476. * @rxid: Remote Exchange ID.
  477. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  478. *
  479. * This function is called with hbalock held.
  480. * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
  481. * rrq struct and adds it to the active_rrq_list.
  482. *
  483. * returns 0 for rrq slot for this xri
  484. * < 0 Were not able to get rrq mem or invalid parameter.
  485. **/
  486. static int
  487. __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  488. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  489. {
  490. uint16_t adj_xri;
  491. struct lpfc_node_rrq *rrq;
  492. int empty;
  493. /*
  494. * set the active bit even if there is no mem available.
  495. */
  496. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  497. if (!ndlp)
  498. return -EINVAL;
  499. if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  500. return -EINVAL;
  501. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  502. if (rrq) {
  503. rrq->send_rrq = send_rrq;
  504. rrq->xritag = xritag;
  505. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  506. rrq->ndlp = ndlp;
  507. rrq->nlp_DID = ndlp->nlp_DID;
  508. rrq->vport = ndlp->vport;
  509. rrq->rxid = rxid;
  510. empty = list_empty(&phba->active_rrq_list);
  511. if (phba->cfg_enable_rrq && send_rrq)
  512. /*
  513. * We need the xri before we can add this to the
  514. * phba active rrq list.
  515. */
  516. rrq->send_rrq = send_rrq;
  517. else
  518. rrq->send_rrq = 0;
  519. list_add_tail(&rrq->list, &phba->active_rrq_list);
  520. if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
  521. phba->hba_flag |= HBA_RRQ_ACTIVE;
  522. if (empty)
  523. lpfc_worker_wake_up(phba);
  524. }
  525. return 0;
  526. }
  527. return -ENOMEM;
  528. }
  529. /**
  530. * __lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  531. * @phba: Pointer to HBA context object.
  532. * @xritag: xri used in this exchange.
  533. * @rrq: The RRQ to be cleared.
  534. *
  535. * This function is called with hbalock held. This function
  536. **/
  537. static void
  538. __lpfc_clr_rrq_active(struct lpfc_hba *phba,
  539. uint16_t xritag,
  540. struct lpfc_node_rrq *rrq)
  541. {
  542. uint16_t adj_xri;
  543. struct lpfc_nodelist *ndlp;
  544. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  545. /* The target DID could have been swapped (cable swap)
  546. * we should use the ndlp from the findnode if it is
  547. * available.
  548. */
  549. if (!ndlp)
  550. ndlp = rrq->ndlp;
  551. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  552. if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) {
  553. rrq->send_rrq = 0;
  554. rrq->xritag = 0;
  555. rrq->rrq_stop_time = 0;
  556. }
  557. mempool_free(rrq, phba->rrq_pool);
  558. }
  559. /**
  560. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  561. * @phba: Pointer to HBA context object.
  562. *
  563. * This function is called with hbalock held. This function
  564. * Checks if stop_time (ratov from setting rrq active) has
  565. * been reached, if it has and the send_rrq flag is set then
  566. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  567. * then it will just call the routine to clear the rrq and
  568. * free the rrq resource.
  569. * The timer is set to the next rrq that is going to expire before
  570. * leaving the routine.
  571. *
  572. **/
  573. void
  574. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  575. {
  576. struct lpfc_node_rrq *rrq;
  577. struct lpfc_node_rrq *nextrrq;
  578. unsigned long next_time;
  579. unsigned long iflags;
  580. spin_lock_irqsave(&phba->hbalock, iflags);
  581. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  582. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  583. list_for_each_entry_safe(rrq, nextrrq,
  584. &phba->active_rrq_list, list) {
  585. if (time_after(jiffies, rrq->rrq_stop_time)) {
  586. list_del(&rrq->list);
  587. if (!rrq->send_rrq)
  588. /* this call will free the rrq */
  589. __lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  590. else {
  591. /* if we send the rrq then the completion handler
  592. * will clear the bit in the xribitmap.
  593. */
  594. spin_unlock_irqrestore(&phba->hbalock, iflags);
  595. if (lpfc_send_rrq(phba, rrq)) {
  596. lpfc_clr_rrq_active(phba, rrq->xritag,
  597. rrq);
  598. }
  599. spin_lock_irqsave(&phba->hbalock, iflags);
  600. }
  601. } else if (time_before(rrq->rrq_stop_time, next_time))
  602. next_time = rrq->rrq_stop_time;
  603. }
  604. spin_unlock_irqrestore(&phba->hbalock, iflags);
  605. if (!list_empty(&phba->active_rrq_list))
  606. mod_timer(&phba->rrq_tmr, next_time);
  607. }
  608. /**
  609. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  610. * @vport: Pointer to vport context object.
  611. * @xri: The xri used in the exchange.
  612. * @did: The targets DID for this exchange.
  613. *
  614. * returns NULL = rrq not found in the phba->active_rrq_list.
  615. * rrq = rrq for this xri and target.
  616. **/
  617. struct lpfc_node_rrq *
  618. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  619. {
  620. struct lpfc_hba *phba = vport->phba;
  621. struct lpfc_node_rrq *rrq;
  622. struct lpfc_node_rrq *nextrrq;
  623. unsigned long iflags;
  624. if (phba->sli_rev != LPFC_SLI_REV4)
  625. return NULL;
  626. spin_lock_irqsave(&phba->hbalock, iflags);
  627. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  628. if (rrq->vport == vport && rrq->xritag == xri &&
  629. rrq->nlp_DID == did){
  630. list_del(&rrq->list);
  631. spin_unlock_irqrestore(&phba->hbalock, iflags);
  632. return rrq;
  633. }
  634. }
  635. spin_unlock_irqrestore(&phba->hbalock, iflags);
  636. return NULL;
  637. }
  638. /**
  639. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  640. * @vport: Pointer to vport context object.
  641. *
  642. * Remove all active RRQs for this vport from the phba->active_rrq_list and
  643. * clear the rrq.
  644. **/
  645. void
  646. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport)
  647. {
  648. struct lpfc_hba *phba = vport->phba;
  649. struct lpfc_node_rrq *rrq;
  650. struct lpfc_node_rrq *nextrrq;
  651. unsigned long iflags;
  652. if (phba->sli_rev != LPFC_SLI_REV4)
  653. return;
  654. spin_lock_irqsave(&phba->hbalock, iflags);
  655. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  656. if (rrq->vport == vport) {
  657. list_del(&rrq->list);
  658. __lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  659. }
  660. }
  661. spin_unlock_irqrestore(&phba->hbalock, iflags);
  662. }
  663. /**
  664. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  665. * @phba: Pointer to HBA context object.
  666. *
  667. * Remove all rrqs from the phba->active_rrq_list and free them by
  668. * calling __lpfc_clr_active_rrq
  669. *
  670. **/
  671. void
  672. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  673. {
  674. struct lpfc_node_rrq *rrq;
  675. struct lpfc_node_rrq *nextrrq;
  676. unsigned long next_time;
  677. unsigned long iflags;
  678. if (phba->sli_rev != LPFC_SLI_REV4)
  679. return;
  680. spin_lock_irqsave(&phba->hbalock, iflags);
  681. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  682. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  683. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  684. list_del(&rrq->list);
  685. __lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  686. }
  687. spin_unlock_irqrestore(&phba->hbalock, iflags);
  688. if (!list_empty(&phba->active_rrq_list))
  689. mod_timer(&phba->rrq_tmr, next_time);
  690. }
  691. /**
  692. * __lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  693. * @phba: Pointer to HBA context object.
  694. * @ndlp: Targets nodelist pointer for this exchange.
  695. * @xritag the xri in the bitmap to test.
  696. *
  697. * This function is called with hbalock held. This function
  698. * returns 0 = rrq not active for this xri
  699. * 1 = rrq is valid for this xri.
  700. **/
  701. static int
  702. __lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  703. uint16_t xritag)
  704. {
  705. uint16_t adj_xri;
  706. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  707. if (!ndlp)
  708. return 0;
  709. if (test_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  710. return 1;
  711. else
  712. return 0;
  713. }
  714. /**
  715. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  716. * @phba: Pointer to HBA context object.
  717. * @ndlp: nodelist pointer for this target.
  718. * @xritag: xri used in this exchange.
  719. * @rxid: Remote Exchange ID.
  720. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  721. *
  722. * This function takes the hbalock.
  723. * The active bit is always set in the active rrq xri_bitmap even
  724. * if there is no slot avaiable for the other rrq information.
  725. *
  726. * returns 0 rrq actived for this xri
  727. * < 0 No memory or invalid ndlp.
  728. **/
  729. int
  730. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  731. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  732. {
  733. int ret;
  734. unsigned long iflags;
  735. spin_lock_irqsave(&phba->hbalock, iflags);
  736. ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq);
  737. spin_unlock_irqrestore(&phba->hbalock, iflags);
  738. return ret;
  739. }
  740. /**
  741. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  742. * @phba: Pointer to HBA context object.
  743. * @xritag: xri used in this exchange.
  744. * @rrq: The RRQ to be cleared.
  745. *
  746. * This function is takes the hbalock.
  747. **/
  748. void
  749. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  750. uint16_t xritag,
  751. struct lpfc_node_rrq *rrq)
  752. {
  753. unsigned long iflags;
  754. spin_lock_irqsave(&phba->hbalock, iflags);
  755. __lpfc_clr_rrq_active(phba, xritag, rrq);
  756. spin_unlock_irqrestore(&phba->hbalock, iflags);
  757. return;
  758. }
  759. /**
  760. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  761. * @phba: Pointer to HBA context object.
  762. * @ndlp: Targets nodelist pointer for this exchange.
  763. * @xritag the xri in the bitmap to test.
  764. *
  765. * This function takes the hbalock.
  766. * returns 0 = rrq not active for this xri
  767. * 1 = rrq is valid for this xri.
  768. **/
  769. int
  770. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  771. uint16_t xritag)
  772. {
  773. int ret;
  774. unsigned long iflags;
  775. spin_lock_irqsave(&phba->hbalock, iflags);
  776. ret = __lpfc_test_rrq_active(phba, ndlp, xritag);
  777. spin_unlock_irqrestore(&phba->hbalock, iflags);
  778. return ret;
  779. }
  780. /**
  781. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  782. * @phba: Pointer to HBA context object.
  783. * @piocb: Pointer to the iocbq.
  784. *
  785. * This function is called with hbalock held. This function
  786. * Gets a new driver sglq object from the sglq list. If the
  787. * list is not empty then it is successful, it returns pointer to the newly
  788. * allocated sglq object else it returns NULL.
  789. **/
  790. static struct lpfc_sglq *
  791. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  792. {
  793. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  794. struct lpfc_sglq *sglq = NULL;
  795. struct lpfc_sglq *start_sglq = NULL;
  796. uint16_t adj_xri;
  797. struct lpfc_scsi_buf *lpfc_cmd;
  798. struct lpfc_nodelist *ndlp;
  799. int found = 0;
  800. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  801. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  802. ndlp = lpfc_cmd->rdata->pnode;
  803. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  804. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  805. ndlp = piocbq->context_un.ndlp;
  806. else
  807. ndlp = piocbq->context1;
  808. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  809. start_sglq = sglq;
  810. while (!found) {
  811. if (!sglq)
  812. return NULL;
  813. adj_xri = sglq->sli4_xritag -
  814. phba->sli4_hba.max_cfg_param.xri_base;
  815. if (__lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
  816. /* This xri has an rrq outstanding for this DID.
  817. * put it back in the list and get another xri.
  818. */
  819. list_add_tail(&sglq->list, lpfc_sgl_list);
  820. sglq = NULL;
  821. list_remove_head(lpfc_sgl_list, sglq,
  822. struct lpfc_sglq, list);
  823. if (sglq == start_sglq) {
  824. sglq = NULL;
  825. break;
  826. } else
  827. continue;
  828. }
  829. sglq->ndlp = ndlp;
  830. found = 1;
  831. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  832. sglq->state = SGL_ALLOCATED;
  833. }
  834. return sglq;
  835. }
  836. /**
  837. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  838. * @phba: Pointer to HBA context object.
  839. *
  840. * This function is called with no lock held. This function
  841. * allocates a new driver iocb object from the iocb pool. If the
  842. * allocation is successful, it returns pointer to the newly
  843. * allocated iocb object else it returns NULL.
  844. **/
  845. struct lpfc_iocbq *
  846. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  847. {
  848. struct lpfc_iocbq * iocbq = NULL;
  849. unsigned long iflags;
  850. spin_lock_irqsave(&phba->hbalock, iflags);
  851. iocbq = __lpfc_sli_get_iocbq(phba);
  852. spin_unlock_irqrestore(&phba->hbalock, iflags);
  853. return iocbq;
  854. }
  855. /**
  856. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  857. * @phba: Pointer to HBA context object.
  858. * @iocbq: Pointer to driver iocb object.
  859. *
  860. * This function is called with hbalock held to release driver
  861. * iocb object to the iocb pool. The iotag in the iocb object
  862. * does not change for each use of the iocb object. This function
  863. * clears all other fields of the iocb object when it is freed.
  864. * The sqlq structure that holds the xritag and phys and virtual
  865. * mappings for the scatter gather list is retrieved from the
  866. * active array of sglq. The get of the sglq pointer also clears
  867. * the entry in the array. If the status of the IO indiactes that
  868. * this IO was aborted then the sglq entry it put on the
  869. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  870. * IO has good status or fails for any other reason then the sglq
  871. * entry is added to the free list (lpfc_sgl_list).
  872. **/
  873. static void
  874. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  875. {
  876. struct lpfc_sglq *sglq;
  877. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  878. unsigned long iflag = 0;
  879. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  880. if (iocbq->sli4_xritag == NO_XRI)
  881. sglq = NULL;
  882. else
  883. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  884. if (sglq) {
  885. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  886. (sglq->state != SGL_XRI_ABORTED)) {
  887. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  888. iflag);
  889. list_add(&sglq->list,
  890. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  891. spin_unlock_irqrestore(
  892. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  893. } else {
  894. sglq->state = SGL_FREED;
  895. sglq->ndlp = NULL;
  896. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  897. /* Check if TXQ queue needs to be serviced */
  898. if (pring->txq_cnt)
  899. lpfc_worker_wake_up(phba);
  900. }
  901. }
  902. /*
  903. * Clean all volatile data fields, preserve iotag and node struct.
  904. */
  905. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  906. iocbq->sli4_xritag = NO_XRI;
  907. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  908. }
  909. /**
  910. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  911. * @phba: Pointer to HBA context object.
  912. * @iocbq: Pointer to driver iocb object.
  913. *
  914. * This function is called with hbalock held to release driver
  915. * iocb object to the iocb pool. The iotag in the iocb object
  916. * does not change for each use of the iocb object. This function
  917. * clears all other fields of the iocb object when it is freed.
  918. **/
  919. static void
  920. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  921. {
  922. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  923. /*
  924. * Clean all volatile data fields, preserve iotag and node struct.
  925. */
  926. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  927. iocbq->sli4_xritag = NO_XRI;
  928. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  929. }
  930. /**
  931. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  932. * @phba: Pointer to HBA context object.
  933. * @iocbq: Pointer to driver iocb object.
  934. *
  935. * This function is called with hbalock held to release driver
  936. * iocb object to the iocb pool. The iotag in the iocb object
  937. * does not change for each use of the iocb object. This function
  938. * clears all other fields of the iocb object when it is freed.
  939. **/
  940. static void
  941. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  942. {
  943. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  944. phba->iocb_cnt--;
  945. }
  946. /**
  947. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  948. * @phba: Pointer to HBA context object.
  949. * @iocbq: Pointer to driver iocb object.
  950. *
  951. * This function is called with no lock held to release the iocb to
  952. * iocb pool.
  953. **/
  954. void
  955. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  956. {
  957. unsigned long iflags;
  958. /*
  959. * Clean all volatile data fields, preserve iotag and node struct.
  960. */
  961. spin_lock_irqsave(&phba->hbalock, iflags);
  962. __lpfc_sli_release_iocbq(phba, iocbq);
  963. spin_unlock_irqrestore(&phba->hbalock, iflags);
  964. }
  965. /**
  966. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  967. * @phba: Pointer to HBA context object.
  968. * @iocblist: List of IOCBs.
  969. * @ulpstatus: ULP status in IOCB command field.
  970. * @ulpWord4: ULP word-4 in IOCB command field.
  971. *
  972. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  973. * on the list by invoking the complete callback function associated with the
  974. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  975. * fields.
  976. **/
  977. void
  978. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  979. uint32_t ulpstatus, uint32_t ulpWord4)
  980. {
  981. struct lpfc_iocbq *piocb;
  982. while (!list_empty(iocblist)) {
  983. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  984. if (!piocb->iocb_cmpl)
  985. lpfc_sli_release_iocbq(phba, piocb);
  986. else {
  987. piocb->iocb.ulpStatus = ulpstatus;
  988. piocb->iocb.un.ulpWord[4] = ulpWord4;
  989. (piocb->iocb_cmpl) (phba, piocb, piocb);
  990. }
  991. }
  992. return;
  993. }
  994. /**
  995. * lpfc_sli_iocb_cmd_type - Get the iocb type
  996. * @iocb_cmnd: iocb command code.
  997. *
  998. * This function is called by ring event handler function to get the iocb type.
  999. * This function translates the iocb command to an iocb command type used to
  1000. * decide the final disposition of each completed IOCB.
  1001. * The function returns
  1002. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1003. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1004. * LPFC_ABORT_IOCB if it is an abort iocb
  1005. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1006. *
  1007. * The caller is not required to hold any lock.
  1008. **/
  1009. static lpfc_iocb_type
  1010. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1011. {
  1012. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1013. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1014. return 0;
  1015. switch (iocb_cmnd) {
  1016. case CMD_XMIT_SEQUENCE_CR:
  1017. case CMD_XMIT_SEQUENCE_CX:
  1018. case CMD_XMIT_BCAST_CN:
  1019. case CMD_XMIT_BCAST_CX:
  1020. case CMD_ELS_REQUEST_CR:
  1021. case CMD_ELS_REQUEST_CX:
  1022. case CMD_CREATE_XRI_CR:
  1023. case CMD_CREATE_XRI_CX:
  1024. case CMD_GET_RPI_CN:
  1025. case CMD_XMIT_ELS_RSP_CX:
  1026. case CMD_GET_RPI_CR:
  1027. case CMD_FCP_IWRITE_CR:
  1028. case CMD_FCP_IWRITE_CX:
  1029. case CMD_FCP_IREAD_CR:
  1030. case CMD_FCP_IREAD_CX:
  1031. case CMD_FCP_ICMND_CR:
  1032. case CMD_FCP_ICMND_CX:
  1033. case CMD_FCP_TSEND_CX:
  1034. case CMD_FCP_TRSP_CX:
  1035. case CMD_FCP_TRECEIVE_CX:
  1036. case CMD_FCP_AUTO_TRSP_CX:
  1037. case CMD_ADAPTER_MSG:
  1038. case CMD_ADAPTER_DUMP:
  1039. case CMD_XMIT_SEQUENCE64_CR:
  1040. case CMD_XMIT_SEQUENCE64_CX:
  1041. case CMD_XMIT_BCAST64_CN:
  1042. case CMD_XMIT_BCAST64_CX:
  1043. case CMD_ELS_REQUEST64_CR:
  1044. case CMD_ELS_REQUEST64_CX:
  1045. case CMD_FCP_IWRITE64_CR:
  1046. case CMD_FCP_IWRITE64_CX:
  1047. case CMD_FCP_IREAD64_CR:
  1048. case CMD_FCP_IREAD64_CX:
  1049. case CMD_FCP_ICMND64_CR:
  1050. case CMD_FCP_ICMND64_CX:
  1051. case CMD_FCP_TSEND64_CX:
  1052. case CMD_FCP_TRSP64_CX:
  1053. case CMD_FCP_TRECEIVE64_CX:
  1054. case CMD_GEN_REQUEST64_CR:
  1055. case CMD_GEN_REQUEST64_CX:
  1056. case CMD_XMIT_ELS_RSP64_CX:
  1057. case DSSCMD_IWRITE64_CR:
  1058. case DSSCMD_IWRITE64_CX:
  1059. case DSSCMD_IREAD64_CR:
  1060. case DSSCMD_IREAD64_CX:
  1061. type = LPFC_SOL_IOCB;
  1062. break;
  1063. case CMD_ABORT_XRI_CN:
  1064. case CMD_ABORT_XRI_CX:
  1065. case CMD_CLOSE_XRI_CN:
  1066. case CMD_CLOSE_XRI_CX:
  1067. case CMD_XRI_ABORTED_CX:
  1068. case CMD_ABORT_MXRI64_CN:
  1069. case CMD_XMIT_BLS_RSP64_CX:
  1070. type = LPFC_ABORT_IOCB;
  1071. break;
  1072. case CMD_RCV_SEQUENCE_CX:
  1073. case CMD_RCV_ELS_REQ_CX:
  1074. case CMD_RCV_SEQUENCE64_CX:
  1075. case CMD_RCV_ELS_REQ64_CX:
  1076. case CMD_ASYNC_STATUS:
  1077. case CMD_IOCB_RCV_SEQ64_CX:
  1078. case CMD_IOCB_RCV_ELS64_CX:
  1079. case CMD_IOCB_RCV_CONT64_CX:
  1080. case CMD_IOCB_RET_XRI64_CX:
  1081. type = LPFC_UNSOL_IOCB;
  1082. break;
  1083. case CMD_IOCB_XMIT_MSEQ64_CR:
  1084. case CMD_IOCB_XMIT_MSEQ64_CX:
  1085. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1086. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1087. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1088. case CMD_IOCB_ABORT_EXTENDED_CN:
  1089. case CMD_IOCB_RET_HBQE64_CN:
  1090. case CMD_IOCB_FCP_IBIDIR64_CR:
  1091. case CMD_IOCB_FCP_IBIDIR64_CX:
  1092. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1093. case CMD_IOCB_LOGENTRY_CN:
  1094. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1095. printk("%s - Unhandled SLI-3 Command x%x\n",
  1096. __func__, iocb_cmnd);
  1097. type = LPFC_UNKNOWN_IOCB;
  1098. break;
  1099. default:
  1100. type = LPFC_UNKNOWN_IOCB;
  1101. break;
  1102. }
  1103. return type;
  1104. }
  1105. /**
  1106. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1107. * @phba: Pointer to HBA context object.
  1108. *
  1109. * This function is called from SLI initialization code
  1110. * to configure every ring of the HBA's SLI interface. The
  1111. * caller is not required to hold any lock. This function issues
  1112. * a config_ring mailbox command for each ring.
  1113. * This function returns zero if successful else returns a negative
  1114. * error code.
  1115. **/
  1116. static int
  1117. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1118. {
  1119. struct lpfc_sli *psli = &phba->sli;
  1120. LPFC_MBOXQ_t *pmb;
  1121. MAILBOX_t *pmbox;
  1122. int i, rc, ret = 0;
  1123. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1124. if (!pmb)
  1125. return -ENOMEM;
  1126. pmbox = &pmb->u.mb;
  1127. phba->link_state = LPFC_INIT_MBX_CMDS;
  1128. for (i = 0; i < psli->num_rings; i++) {
  1129. lpfc_config_ring(phba, i, pmb);
  1130. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1131. if (rc != MBX_SUCCESS) {
  1132. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1133. "0446 Adapter failed to init (%d), "
  1134. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1135. "ring %d\n",
  1136. rc, pmbox->mbxCommand,
  1137. pmbox->mbxStatus, i);
  1138. phba->link_state = LPFC_HBA_ERROR;
  1139. ret = -ENXIO;
  1140. break;
  1141. }
  1142. }
  1143. mempool_free(pmb, phba->mbox_mem_pool);
  1144. return ret;
  1145. }
  1146. /**
  1147. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1148. * @phba: Pointer to HBA context object.
  1149. * @pring: Pointer to driver SLI ring object.
  1150. * @piocb: Pointer to the driver iocb object.
  1151. *
  1152. * This function is called with hbalock held. The function adds the
  1153. * new iocb to txcmplq of the given ring. This function always returns
  1154. * 0. If this function is called for ELS ring, this function checks if
  1155. * there is a vport associated with the ELS command. This function also
  1156. * starts els_tmofunc timer if this is an ELS command.
  1157. **/
  1158. static int
  1159. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1160. struct lpfc_iocbq *piocb)
  1161. {
  1162. list_add_tail(&piocb->list, &pring->txcmplq);
  1163. piocb->iocb_flag |= LPFC_IO_ON_Q;
  1164. pring->txcmplq_cnt++;
  1165. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1166. pring->txcmplq_max = pring->txcmplq_cnt;
  1167. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1168. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1169. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1170. if (!piocb->vport)
  1171. BUG();
  1172. else
  1173. mod_timer(&piocb->vport->els_tmofunc,
  1174. jiffies + HZ * (phba->fc_ratov << 1));
  1175. }
  1176. return 0;
  1177. }
  1178. /**
  1179. * lpfc_sli_ringtx_get - Get first element of the txq
  1180. * @phba: Pointer to HBA context object.
  1181. * @pring: Pointer to driver SLI ring object.
  1182. *
  1183. * This function is called with hbalock held to get next
  1184. * iocb in txq of the given ring. If there is any iocb in
  1185. * the txq, the function returns first iocb in the list after
  1186. * removing the iocb from the list, else it returns NULL.
  1187. **/
  1188. struct lpfc_iocbq *
  1189. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1190. {
  1191. struct lpfc_iocbq *cmd_iocb;
  1192. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1193. if (cmd_iocb != NULL)
  1194. pring->txq_cnt--;
  1195. return cmd_iocb;
  1196. }
  1197. /**
  1198. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1199. * @phba: Pointer to HBA context object.
  1200. * @pring: Pointer to driver SLI ring object.
  1201. *
  1202. * This function is called with hbalock held and the caller must post the
  1203. * iocb without releasing the lock. If the caller releases the lock,
  1204. * iocb slot returned by the function is not guaranteed to be available.
  1205. * The function returns pointer to the next available iocb slot if there
  1206. * is available slot in the ring, else it returns NULL.
  1207. * If the get index of the ring is ahead of the put index, the function
  1208. * will post an error attention event to the worker thread to take the
  1209. * HBA to offline state.
  1210. **/
  1211. static IOCB_t *
  1212. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1213. {
  1214. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1215. uint32_t max_cmd_idx = pring->numCiocb;
  1216. if ((pring->next_cmdidx == pring->cmdidx) &&
  1217. (++pring->next_cmdidx >= max_cmd_idx))
  1218. pring->next_cmdidx = 0;
  1219. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1220. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1221. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1222. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1223. "0315 Ring %d issue: portCmdGet %d "
  1224. "is bigger than cmd ring %d\n",
  1225. pring->ringno,
  1226. pring->local_getidx, max_cmd_idx);
  1227. phba->link_state = LPFC_HBA_ERROR;
  1228. /*
  1229. * All error attention handlers are posted to
  1230. * worker thread
  1231. */
  1232. phba->work_ha |= HA_ERATT;
  1233. phba->work_hs = HS_FFER3;
  1234. lpfc_worker_wake_up(phba);
  1235. return NULL;
  1236. }
  1237. if (pring->local_getidx == pring->next_cmdidx)
  1238. return NULL;
  1239. }
  1240. return lpfc_cmd_iocb(phba, pring);
  1241. }
  1242. /**
  1243. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1244. * @phba: Pointer to HBA context object.
  1245. * @iocbq: Pointer to driver iocb object.
  1246. *
  1247. * This function gets an iotag for the iocb. If there is no unused iotag and
  1248. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1249. * array and assigns a new iotag.
  1250. * The function returns the allocated iotag if successful, else returns zero.
  1251. * Zero is not a valid iotag.
  1252. * The caller is not required to hold any lock.
  1253. **/
  1254. uint16_t
  1255. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1256. {
  1257. struct lpfc_iocbq **new_arr;
  1258. struct lpfc_iocbq **old_arr;
  1259. size_t new_len;
  1260. struct lpfc_sli *psli = &phba->sli;
  1261. uint16_t iotag;
  1262. spin_lock_irq(&phba->hbalock);
  1263. iotag = psli->last_iotag;
  1264. if(++iotag < psli->iocbq_lookup_len) {
  1265. psli->last_iotag = iotag;
  1266. psli->iocbq_lookup[iotag] = iocbq;
  1267. spin_unlock_irq(&phba->hbalock);
  1268. iocbq->iotag = iotag;
  1269. return iotag;
  1270. } else if (psli->iocbq_lookup_len < (0xffff
  1271. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1272. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1273. spin_unlock_irq(&phba->hbalock);
  1274. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1275. GFP_KERNEL);
  1276. if (new_arr) {
  1277. spin_lock_irq(&phba->hbalock);
  1278. old_arr = psli->iocbq_lookup;
  1279. if (new_len <= psli->iocbq_lookup_len) {
  1280. /* highly unprobable case */
  1281. kfree(new_arr);
  1282. iotag = psli->last_iotag;
  1283. if(++iotag < psli->iocbq_lookup_len) {
  1284. psli->last_iotag = iotag;
  1285. psli->iocbq_lookup[iotag] = iocbq;
  1286. spin_unlock_irq(&phba->hbalock);
  1287. iocbq->iotag = iotag;
  1288. return iotag;
  1289. }
  1290. spin_unlock_irq(&phba->hbalock);
  1291. return 0;
  1292. }
  1293. if (psli->iocbq_lookup)
  1294. memcpy(new_arr, old_arr,
  1295. ((psli->last_iotag + 1) *
  1296. sizeof (struct lpfc_iocbq *)));
  1297. psli->iocbq_lookup = new_arr;
  1298. psli->iocbq_lookup_len = new_len;
  1299. psli->last_iotag = iotag;
  1300. psli->iocbq_lookup[iotag] = iocbq;
  1301. spin_unlock_irq(&phba->hbalock);
  1302. iocbq->iotag = iotag;
  1303. kfree(old_arr);
  1304. return iotag;
  1305. }
  1306. } else
  1307. spin_unlock_irq(&phba->hbalock);
  1308. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1309. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1310. psli->last_iotag);
  1311. return 0;
  1312. }
  1313. /**
  1314. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1315. * @phba: Pointer to HBA context object.
  1316. * @pring: Pointer to driver SLI ring object.
  1317. * @iocb: Pointer to iocb slot in the ring.
  1318. * @nextiocb: Pointer to driver iocb object which need to be
  1319. * posted to firmware.
  1320. *
  1321. * This function is called with hbalock held to post a new iocb to
  1322. * the firmware. This function copies the new iocb to ring iocb slot and
  1323. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1324. * a completion call back for this iocb else the function will free the
  1325. * iocb object.
  1326. **/
  1327. static void
  1328. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1329. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1330. {
  1331. /*
  1332. * Set up an iotag
  1333. */
  1334. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1335. if (pring->ringno == LPFC_ELS_RING) {
  1336. lpfc_debugfs_slow_ring_trc(phba,
  1337. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1338. *(((uint32_t *) &nextiocb->iocb) + 4),
  1339. *(((uint32_t *) &nextiocb->iocb) + 6),
  1340. *(((uint32_t *) &nextiocb->iocb) + 7));
  1341. }
  1342. /*
  1343. * Issue iocb command to adapter
  1344. */
  1345. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1346. wmb();
  1347. pring->stats.iocb_cmd++;
  1348. /*
  1349. * If there is no completion routine to call, we can release the
  1350. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1351. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1352. */
  1353. if (nextiocb->iocb_cmpl)
  1354. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1355. else
  1356. __lpfc_sli_release_iocbq(phba, nextiocb);
  1357. /*
  1358. * Let the HBA know what IOCB slot will be the next one the
  1359. * driver will put a command into.
  1360. */
  1361. pring->cmdidx = pring->next_cmdidx;
  1362. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1363. }
  1364. /**
  1365. * lpfc_sli_update_full_ring - Update the chip attention register
  1366. * @phba: Pointer to HBA context object.
  1367. * @pring: Pointer to driver SLI ring object.
  1368. *
  1369. * The caller is not required to hold any lock for calling this function.
  1370. * This function updates the chip attention bits for the ring to inform firmware
  1371. * that there are pending work to be done for this ring and requests an
  1372. * interrupt when there is space available in the ring. This function is
  1373. * called when the driver is unable to post more iocbs to the ring due
  1374. * to unavailability of space in the ring.
  1375. **/
  1376. static void
  1377. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1378. {
  1379. int ringno = pring->ringno;
  1380. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1381. wmb();
  1382. /*
  1383. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1384. * The HBA will tell us when an IOCB entry is available.
  1385. */
  1386. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1387. readl(phba->CAregaddr); /* flush */
  1388. pring->stats.iocb_cmd_full++;
  1389. }
  1390. /**
  1391. * lpfc_sli_update_ring - Update chip attention register
  1392. * @phba: Pointer to HBA context object.
  1393. * @pring: Pointer to driver SLI ring object.
  1394. *
  1395. * This function updates the chip attention register bit for the
  1396. * given ring to inform HBA that there is more work to be done
  1397. * in this ring. The caller is not required to hold any lock.
  1398. **/
  1399. static void
  1400. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1401. {
  1402. int ringno = pring->ringno;
  1403. /*
  1404. * Tell the HBA that there is work to do in this ring.
  1405. */
  1406. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1407. wmb();
  1408. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1409. readl(phba->CAregaddr); /* flush */
  1410. }
  1411. }
  1412. /**
  1413. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1414. * @phba: Pointer to HBA context object.
  1415. * @pring: Pointer to driver SLI ring object.
  1416. *
  1417. * This function is called with hbalock held to post pending iocbs
  1418. * in the txq to the firmware. This function is called when driver
  1419. * detects space available in the ring.
  1420. **/
  1421. static void
  1422. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1423. {
  1424. IOCB_t *iocb;
  1425. struct lpfc_iocbq *nextiocb;
  1426. /*
  1427. * Check to see if:
  1428. * (a) there is anything on the txq to send
  1429. * (b) link is up
  1430. * (c) link attention events can be processed (fcp ring only)
  1431. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1432. */
  1433. if (pring->txq_cnt &&
  1434. lpfc_is_link_up(phba) &&
  1435. (pring->ringno != phba->sli.fcp_ring ||
  1436. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1437. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1438. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1439. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1440. if (iocb)
  1441. lpfc_sli_update_ring(phba, pring);
  1442. else
  1443. lpfc_sli_update_full_ring(phba, pring);
  1444. }
  1445. return;
  1446. }
  1447. /**
  1448. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1449. * @phba: Pointer to HBA context object.
  1450. * @hbqno: HBQ number.
  1451. *
  1452. * This function is called with hbalock held to get the next
  1453. * available slot for the given HBQ. If there is free slot
  1454. * available for the HBQ it will return pointer to the next available
  1455. * HBQ entry else it will return NULL.
  1456. **/
  1457. static struct lpfc_hbq_entry *
  1458. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1459. {
  1460. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1461. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1462. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1463. hbqp->next_hbqPutIdx = 0;
  1464. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1465. uint32_t raw_index = phba->hbq_get[hbqno];
  1466. uint32_t getidx = le32_to_cpu(raw_index);
  1467. hbqp->local_hbqGetIdx = getidx;
  1468. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1469. lpfc_printf_log(phba, KERN_ERR,
  1470. LOG_SLI | LOG_VPORT,
  1471. "1802 HBQ %d: local_hbqGetIdx "
  1472. "%u is > than hbqp->entry_count %u\n",
  1473. hbqno, hbqp->local_hbqGetIdx,
  1474. hbqp->entry_count);
  1475. phba->link_state = LPFC_HBA_ERROR;
  1476. return NULL;
  1477. }
  1478. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1479. return NULL;
  1480. }
  1481. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1482. hbqp->hbqPutIdx;
  1483. }
  1484. /**
  1485. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1486. * @phba: Pointer to HBA context object.
  1487. *
  1488. * This function is called with no lock held to free all the
  1489. * hbq buffers while uninitializing the SLI interface. It also
  1490. * frees the HBQ buffers returned by the firmware but not yet
  1491. * processed by the upper layers.
  1492. **/
  1493. void
  1494. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1495. {
  1496. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1497. struct hbq_dmabuf *hbq_buf;
  1498. unsigned long flags;
  1499. int i, hbq_count;
  1500. uint32_t hbqno;
  1501. hbq_count = lpfc_sli_hbq_count();
  1502. /* Return all memory used by all HBQs */
  1503. spin_lock_irqsave(&phba->hbalock, flags);
  1504. for (i = 0; i < hbq_count; ++i) {
  1505. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1506. &phba->hbqs[i].hbq_buffer_list, list) {
  1507. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1508. list_del(&hbq_buf->dbuf.list);
  1509. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1510. }
  1511. phba->hbqs[i].buffer_count = 0;
  1512. }
  1513. /* Return all HBQ buffer that are in-fly */
  1514. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1515. list) {
  1516. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1517. list_del(&hbq_buf->dbuf.list);
  1518. if (hbq_buf->tag == -1) {
  1519. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1520. (phba, hbq_buf);
  1521. } else {
  1522. hbqno = hbq_buf->tag >> 16;
  1523. if (hbqno >= LPFC_MAX_HBQS)
  1524. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1525. (phba, hbq_buf);
  1526. else
  1527. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1528. hbq_buf);
  1529. }
  1530. }
  1531. /* Mark the HBQs not in use */
  1532. phba->hbq_in_use = 0;
  1533. spin_unlock_irqrestore(&phba->hbalock, flags);
  1534. }
  1535. /**
  1536. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1537. * @phba: Pointer to HBA context object.
  1538. * @hbqno: HBQ number.
  1539. * @hbq_buf: Pointer to HBQ buffer.
  1540. *
  1541. * This function is called with the hbalock held to post a
  1542. * hbq buffer to the firmware. If the function finds an empty
  1543. * slot in the HBQ, it will post the buffer. The function will return
  1544. * pointer to the hbq entry if it successfully post the buffer
  1545. * else it will return NULL.
  1546. **/
  1547. static int
  1548. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1549. struct hbq_dmabuf *hbq_buf)
  1550. {
  1551. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1552. }
  1553. /**
  1554. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1555. * @phba: Pointer to HBA context object.
  1556. * @hbqno: HBQ number.
  1557. * @hbq_buf: Pointer to HBQ buffer.
  1558. *
  1559. * This function is called with the hbalock held to post a hbq buffer to the
  1560. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1561. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1562. * it successfully post the buffer else it will return an error.
  1563. **/
  1564. static int
  1565. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1566. struct hbq_dmabuf *hbq_buf)
  1567. {
  1568. struct lpfc_hbq_entry *hbqe;
  1569. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1570. /* Get next HBQ entry slot to use */
  1571. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1572. if (hbqe) {
  1573. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1574. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1575. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1576. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1577. hbqe->bde.tus.f.bdeFlags = 0;
  1578. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1579. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1580. /* Sync SLIM */
  1581. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1582. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1583. /* flush */
  1584. readl(phba->hbq_put + hbqno);
  1585. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1586. return 0;
  1587. } else
  1588. return -ENOMEM;
  1589. }
  1590. /**
  1591. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1592. * @phba: Pointer to HBA context object.
  1593. * @hbqno: HBQ number.
  1594. * @hbq_buf: Pointer to HBQ buffer.
  1595. *
  1596. * This function is called with the hbalock held to post an RQE to the SLI4
  1597. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1598. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1599. **/
  1600. static int
  1601. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1602. struct hbq_dmabuf *hbq_buf)
  1603. {
  1604. int rc;
  1605. struct lpfc_rqe hrqe;
  1606. struct lpfc_rqe drqe;
  1607. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1608. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1609. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1610. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1611. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1612. &hrqe, &drqe);
  1613. if (rc < 0)
  1614. return rc;
  1615. hbq_buf->tag = rc;
  1616. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1617. return 0;
  1618. }
  1619. /* HBQ for ELS and CT traffic. */
  1620. static struct lpfc_hbq_init lpfc_els_hbq = {
  1621. .rn = 1,
  1622. .entry_count = 256,
  1623. .mask_count = 0,
  1624. .profile = 0,
  1625. .ring_mask = (1 << LPFC_ELS_RING),
  1626. .buffer_count = 0,
  1627. .init_count = 40,
  1628. .add_count = 40,
  1629. };
  1630. /* HBQ for the extra ring if needed */
  1631. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1632. .rn = 1,
  1633. .entry_count = 200,
  1634. .mask_count = 0,
  1635. .profile = 0,
  1636. .ring_mask = (1 << LPFC_EXTRA_RING),
  1637. .buffer_count = 0,
  1638. .init_count = 0,
  1639. .add_count = 5,
  1640. };
  1641. /* Array of HBQs */
  1642. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1643. &lpfc_els_hbq,
  1644. &lpfc_extra_hbq,
  1645. };
  1646. /**
  1647. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1648. * @phba: Pointer to HBA context object.
  1649. * @hbqno: HBQ number.
  1650. * @count: Number of HBQ buffers to be posted.
  1651. *
  1652. * This function is called with no lock held to post more hbq buffers to the
  1653. * given HBQ. The function returns the number of HBQ buffers successfully
  1654. * posted.
  1655. **/
  1656. static int
  1657. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1658. {
  1659. uint32_t i, posted = 0;
  1660. unsigned long flags;
  1661. struct hbq_dmabuf *hbq_buffer;
  1662. LIST_HEAD(hbq_buf_list);
  1663. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1664. return 0;
  1665. if ((phba->hbqs[hbqno].buffer_count + count) >
  1666. lpfc_hbq_defs[hbqno]->entry_count)
  1667. count = lpfc_hbq_defs[hbqno]->entry_count -
  1668. phba->hbqs[hbqno].buffer_count;
  1669. if (!count)
  1670. return 0;
  1671. /* Allocate HBQ entries */
  1672. for (i = 0; i < count; i++) {
  1673. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1674. if (!hbq_buffer)
  1675. break;
  1676. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1677. }
  1678. /* Check whether HBQ is still in use */
  1679. spin_lock_irqsave(&phba->hbalock, flags);
  1680. if (!phba->hbq_in_use)
  1681. goto err;
  1682. while (!list_empty(&hbq_buf_list)) {
  1683. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1684. dbuf.list);
  1685. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1686. (hbqno << 16));
  1687. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1688. phba->hbqs[hbqno].buffer_count++;
  1689. posted++;
  1690. } else
  1691. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1692. }
  1693. spin_unlock_irqrestore(&phba->hbalock, flags);
  1694. return posted;
  1695. err:
  1696. spin_unlock_irqrestore(&phba->hbalock, flags);
  1697. while (!list_empty(&hbq_buf_list)) {
  1698. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1699. dbuf.list);
  1700. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1701. }
  1702. return 0;
  1703. }
  1704. /**
  1705. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1706. * @phba: Pointer to HBA context object.
  1707. * @qno: HBQ number.
  1708. *
  1709. * This function posts more buffers to the HBQ. This function
  1710. * is called with no lock held. The function returns the number of HBQ entries
  1711. * successfully allocated.
  1712. **/
  1713. int
  1714. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1715. {
  1716. if (phba->sli_rev == LPFC_SLI_REV4)
  1717. return 0;
  1718. else
  1719. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1720. lpfc_hbq_defs[qno]->add_count);
  1721. }
  1722. /**
  1723. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1724. * @phba: Pointer to HBA context object.
  1725. * @qno: HBQ queue number.
  1726. *
  1727. * This function is called from SLI initialization code path with
  1728. * no lock held to post initial HBQ buffers to firmware. The
  1729. * function returns the number of HBQ entries successfully allocated.
  1730. **/
  1731. static int
  1732. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1733. {
  1734. if (phba->sli_rev == LPFC_SLI_REV4)
  1735. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1736. lpfc_hbq_defs[qno]->entry_count);
  1737. else
  1738. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1739. lpfc_hbq_defs[qno]->init_count);
  1740. }
  1741. /**
  1742. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1743. * @phba: Pointer to HBA context object.
  1744. * @hbqno: HBQ number.
  1745. *
  1746. * This function removes the first hbq buffer on an hbq list and returns a
  1747. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1748. **/
  1749. static struct hbq_dmabuf *
  1750. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1751. {
  1752. struct lpfc_dmabuf *d_buf;
  1753. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1754. if (!d_buf)
  1755. return NULL;
  1756. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1757. }
  1758. /**
  1759. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1760. * @phba: Pointer to HBA context object.
  1761. * @tag: Tag of the hbq buffer.
  1762. *
  1763. * This function is called with hbalock held. This function searches
  1764. * for the hbq buffer associated with the given tag in the hbq buffer
  1765. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1766. * it returns NULL.
  1767. **/
  1768. static struct hbq_dmabuf *
  1769. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1770. {
  1771. struct lpfc_dmabuf *d_buf;
  1772. struct hbq_dmabuf *hbq_buf;
  1773. uint32_t hbqno;
  1774. hbqno = tag >> 16;
  1775. if (hbqno >= LPFC_MAX_HBQS)
  1776. return NULL;
  1777. spin_lock_irq(&phba->hbalock);
  1778. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1779. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1780. if (hbq_buf->tag == tag) {
  1781. spin_unlock_irq(&phba->hbalock);
  1782. return hbq_buf;
  1783. }
  1784. }
  1785. spin_unlock_irq(&phba->hbalock);
  1786. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1787. "1803 Bad hbq tag. Data: x%x x%x\n",
  1788. tag, phba->hbqs[tag >> 16].buffer_count);
  1789. return NULL;
  1790. }
  1791. /**
  1792. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1793. * @phba: Pointer to HBA context object.
  1794. * @hbq_buffer: Pointer to HBQ buffer.
  1795. *
  1796. * This function is called with hbalock. This function gives back
  1797. * the hbq buffer to firmware. If the HBQ does not have space to
  1798. * post the buffer, it will free the buffer.
  1799. **/
  1800. void
  1801. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1802. {
  1803. uint32_t hbqno;
  1804. if (hbq_buffer) {
  1805. hbqno = hbq_buffer->tag >> 16;
  1806. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1807. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1808. }
  1809. }
  1810. /**
  1811. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1812. * @mbxCommand: mailbox command code.
  1813. *
  1814. * This function is called by the mailbox event handler function to verify
  1815. * that the completed mailbox command is a legitimate mailbox command. If the
  1816. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1817. * and the mailbox event handler will take the HBA offline.
  1818. **/
  1819. static int
  1820. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1821. {
  1822. uint8_t ret;
  1823. switch (mbxCommand) {
  1824. case MBX_LOAD_SM:
  1825. case MBX_READ_NV:
  1826. case MBX_WRITE_NV:
  1827. case MBX_WRITE_VPARMS:
  1828. case MBX_RUN_BIU_DIAG:
  1829. case MBX_INIT_LINK:
  1830. case MBX_DOWN_LINK:
  1831. case MBX_CONFIG_LINK:
  1832. case MBX_CONFIG_RING:
  1833. case MBX_RESET_RING:
  1834. case MBX_READ_CONFIG:
  1835. case MBX_READ_RCONFIG:
  1836. case MBX_READ_SPARM:
  1837. case MBX_READ_STATUS:
  1838. case MBX_READ_RPI:
  1839. case MBX_READ_XRI:
  1840. case MBX_READ_REV:
  1841. case MBX_READ_LNK_STAT:
  1842. case MBX_REG_LOGIN:
  1843. case MBX_UNREG_LOGIN:
  1844. case MBX_CLEAR_LA:
  1845. case MBX_DUMP_MEMORY:
  1846. case MBX_DUMP_CONTEXT:
  1847. case MBX_RUN_DIAGS:
  1848. case MBX_RESTART:
  1849. case MBX_UPDATE_CFG:
  1850. case MBX_DOWN_LOAD:
  1851. case MBX_DEL_LD_ENTRY:
  1852. case MBX_RUN_PROGRAM:
  1853. case MBX_SET_MASK:
  1854. case MBX_SET_VARIABLE:
  1855. case MBX_UNREG_D_ID:
  1856. case MBX_KILL_BOARD:
  1857. case MBX_CONFIG_FARP:
  1858. case MBX_BEACON:
  1859. case MBX_LOAD_AREA:
  1860. case MBX_RUN_BIU_DIAG64:
  1861. case MBX_CONFIG_PORT:
  1862. case MBX_READ_SPARM64:
  1863. case MBX_READ_RPI64:
  1864. case MBX_REG_LOGIN64:
  1865. case MBX_READ_TOPOLOGY:
  1866. case MBX_WRITE_WWN:
  1867. case MBX_SET_DEBUG:
  1868. case MBX_LOAD_EXP_ROM:
  1869. case MBX_ASYNCEVT_ENABLE:
  1870. case MBX_REG_VPI:
  1871. case MBX_UNREG_VPI:
  1872. case MBX_HEARTBEAT:
  1873. case MBX_PORT_CAPABILITIES:
  1874. case MBX_PORT_IOV_CONTROL:
  1875. case MBX_SLI4_CONFIG:
  1876. case MBX_SLI4_REQ_FTRS:
  1877. case MBX_REG_FCFI:
  1878. case MBX_UNREG_FCFI:
  1879. case MBX_REG_VFI:
  1880. case MBX_UNREG_VFI:
  1881. case MBX_INIT_VPI:
  1882. case MBX_INIT_VFI:
  1883. case MBX_RESUME_RPI:
  1884. case MBX_READ_EVENT_LOG_STATUS:
  1885. case MBX_READ_EVENT_LOG:
  1886. case MBX_SECURITY_MGMT:
  1887. case MBX_AUTH_PORT:
  1888. ret = mbxCommand;
  1889. break;
  1890. default:
  1891. ret = MBX_SHUTDOWN;
  1892. break;
  1893. }
  1894. return ret;
  1895. }
  1896. /**
  1897. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1898. * @phba: Pointer to HBA context object.
  1899. * @pmboxq: Pointer to mailbox command.
  1900. *
  1901. * This is completion handler function for mailbox commands issued from
  1902. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1903. * mailbox event handler function with no lock held. This function
  1904. * will wake up thread waiting on the wait queue pointed by context1
  1905. * of the mailbox.
  1906. **/
  1907. void
  1908. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1909. {
  1910. wait_queue_head_t *pdone_q;
  1911. unsigned long drvr_flag;
  1912. /*
  1913. * If pdone_q is empty, the driver thread gave up waiting and
  1914. * continued running.
  1915. */
  1916. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1917. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1918. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1919. if (pdone_q)
  1920. wake_up_interruptible(pdone_q);
  1921. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1922. return;
  1923. }
  1924. /**
  1925. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1926. * @phba: Pointer to HBA context object.
  1927. * @pmb: Pointer to mailbox object.
  1928. *
  1929. * This function is the default mailbox completion handler. It
  1930. * frees the memory resources associated with the completed mailbox
  1931. * command. If the completed command is a REG_LOGIN mailbox command,
  1932. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1933. **/
  1934. void
  1935. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1936. {
  1937. struct lpfc_vport *vport = pmb->vport;
  1938. struct lpfc_dmabuf *mp;
  1939. struct lpfc_nodelist *ndlp;
  1940. struct Scsi_Host *shost;
  1941. uint16_t rpi, vpi;
  1942. int rc;
  1943. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1944. if (mp) {
  1945. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1946. kfree(mp);
  1947. }
  1948. /*
  1949. * If a REG_LOGIN succeeded after node is destroyed or node
  1950. * is in re-discovery driver need to cleanup the RPI.
  1951. */
  1952. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1953. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1954. !pmb->u.mb.mbxStatus) {
  1955. rpi = pmb->u.mb.un.varWords[0];
  1956. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1957. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1958. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1959. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1960. if (rc != MBX_NOT_FINISHED)
  1961. return;
  1962. }
  1963. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1964. !(phba->pport->load_flag & FC_UNLOADING) &&
  1965. !pmb->u.mb.mbxStatus) {
  1966. shost = lpfc_shost_from_vport(vport);
  1967. spin_lock_irq(shost->host_lock);
  1968. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1969. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1970. spin_unlock_irq(shost->host_lock);
  1971. }
  1972. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1973. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1974. lpfc_nlp_put(ndlp);
  1975. pmb->context2 = NULL;
  1976. }
  1977. /* Check security permission status on INIT_LINK mailbox command */
  1978. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1979. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1980. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1981. "2860 SLI authentication is required "
  1982. "for INIT_LINK but has not done yet\n");
  1983. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1984. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1985. else
  1986. mempool_free(pmb, phba->mbox_mem_pool);
  1987. }
  1988. /**
  1989. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1990. * @phba: Pointer to HBA context object.
  1991. *
  1992. * This function is called with no lock held. This function processes all
  1993. * the completed mailbox commands and gives it to upper layers. The interrupt
  1994. * service routine processes mailbox completion interrupt and adds completed
  1995. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1996. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1997. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1998. * function returns the mailbox commands to the upper layer by calling the
  1999. * completion handler function of each mailbox.
  2000. **/
  2001. int
  2002. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2003. {
  2004. MAILBOX_t *pmbox;
  2005. LPFC_MBOXQ_t *pmb;
  2006. int rc;
  2007. LIST_HEAD(cmplq);
  2008. phba->sli.slistat.mbox_event++;
  2009. /* Get all completed mailboxe buffers into the cmplq */
  2010. spin_lock_irq(&phba->hbalock);
  2011. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2012. spin_unlock_irq(&phba->hbalock);
  2013. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2014. do {
  2015. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2016. if (pmb == NULL)
  2017. break;
  2018. pmbox = &pmb->u.mb;
  2019. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2020. if (pmb->vport) {
  2021. lpfc_debugfs_disc_trc(pmb->vport,
  2022. LPFC_DISC_TRC_MBOX_VPORT,
  2023. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2024. (uint32_t)pmbox->mbxCommand,
  2025. pmbox->un.varWords[0],
  2026. pmbox->un.varWords[1]);
  2027. }
  2028. else {
  2029. lpfc_debugfs_disc_trc(phba->pport,
  2030. LPFC_DISC_TRC_MBOX,
  2031. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2032. (uint32_t)pmbox->mbxCommand,
  2033. pmbox->un.varWords[0],
  2034. pmbox->un.varWords[1]);
  2035. }
  2036. }
  2037. /*
  2038. * It is a fatal error if unknown mbox command completion.
  2039. */
  2040. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2041. MBX_SHUTDOWN) {
  2042. /* Unknown mailbox command compl */
  2043. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2044. "(%d):0323 Unknown Mailbox command "
  2045. "x%x (x%x) Cmpl\n",
  2046. pmb->vport ? pmb->vport->vpi : 0,
  2047. pmbox->mbxCommand,
  2048. lpfc_sli4_mbox_opcode_get(phba, pmb));
  2049. phba->link_state = LPFC_HBA_ERROR;
  2050. phba->work_hs = HS_FFER3;
  2051. lpfc_handle_eratt(phba);
  2052. continue;
  2053. }
  2054. if (pmbox->mbxStatus) {
  2055. phba->sli.slistat.mbox_stat_err++;
  2056. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2057. /* Mbox cmd cmpl error - RETRYing */
  2058. lpfc_printf_log(phba, KERN_INFO,
  2059. LOG_MBOX | LOG_SLI,
  2060. "(%d):0305 Mbox cmd cmpl "
  2061. "error - RETRYing Data: x%x "
  2062. "(x%x) x%x x%x x%x\n",
  2063. pmb->vport ? pmb->vport->vpi :0,
  2064. pmbox->mbxCommand,
  2065. lpfc_sli4_mbox_opcode_get(phba,
  2066. pmb),
  2067. pmbox->mbxStatus,
  2068. pmbox->un.varWords[0],
  2069. pmb->vport->port_state);
  2070. pmbox->mbxStatus = 0;
  2071. pmbox->mbxOwner = OWN_HOST;
  2072. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2073. if (rc != MBX_NOT_FINISHED)
  2074. continue;
  2075. }
  2076. }
  2077. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2078. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2079. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  2080. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2081. pmb->vport ? pmb->vport->vpi : 0,
  2082. pmbox->mbxCommand,
  2083. lpfc_sli4_mbox_opcode_get(phba, pmb),
  2084. pmb->mbox_cmpl,
  2085. *((uint32_t *) pmbox),
  2086. pmbox->un.varWords[0],
  2087. pmbox->un.varWords[1],
  2088. pmbox->un.varWords[2],
  2089. pmbox->un.varWords[3],
  2090. pmbox->un.varWords[4],
  2091. pmbox->un.varWords[5],
  2092. pmbox->un.varWords[6],
  2093. pmbox->un.varWords[7]);
  2094. if (pmb->mbox_cmpl)
  2095. pmb->mbox_cmpl(phba,pmb);
  2096. } while (1);
  2097. return 0;
  2098. }
  2099. /**
  2100. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2101. * @phba: Pointer to HBA context object.
  2102. * @pring: Pointer to driver SLI ring object.
  2103. * @tag: buffer tag.
  2104. *
  2105. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2106. * is set in the tag the buffer is posted for a particular exchange,
  2107. * the function will return the buffer without replacing the buffer.
  2108. * If the buffer is for unsolicited ELS or CT traffic, this function
  2109. * returns the buffer and also posts another buffer to the firmware.
  2110. **/
  2111. static struct lpfc_dmabuf *
  2112. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2113. struct lpfc_sli_ring *pring,
  2114. uint32_t tag)
  2115. {
  2116. struct hbq_dmabuf *hbq_entry;
  2117. if (tag & QUE_BUFTAG_BIT)
  2118. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2119. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2120. if (!hbq_entry)
  2121. return NULL;
  2122. return &hbq_entry->dbuf;
  2123. }
  2124. /**
  2125. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2126. * @phba: Pointer to HBA context object.
  2127. * @pring: Pointer to driver SLI ring object.
  2128. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2129. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2130. * @fch_type: the type for the first frame of the sequence.
  2131. *
  2132. * This function is called with no lock held. This function uses the r_ctl and
  2133. * type of the received sequence to find the correct callback function to call
  2134. * to process the sequence.
  2135. **/
  2136. static int
  2137. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2138. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2139. uint32_t fch_type)
  2140. {
  2141. int i;
  2142. /* unSolicited Responses */
  2143. if (pring->prt[0].profile) {
  2144. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2145. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2146. saveq);
  2147. return 1;
  2148. }
  2149. /* We must search, based on rctl / type
  2150. for the right routine */
  2151. for (i = 0; i < pring->num_mask; i++) {
  2152. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2153. (pring->prt[i].type == fch_type)) {
  2154. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2155. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2156. (phba, pring, saveq);
  2157. return 1;
  2158. }
  2159. }
  2160. return 0;
  2161. }
  2162. /**
  2163. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2164. * @phba: Pointer to HBA context object.
  2165. * @pring: Pointer to driver SLI ring object.
  2166. * @saveq: Pointer to the unsolicited iocb.
  2167. *
  2168. * This function is called with no lock held by the ring event handler
  2169. * when there is an unsolicited iocb posted to the response ring by the
  2170. * firmware. This function gets the buffer associated with the iocbs
  2171. * and calls the event handler for the ring. This function handles both
  2172. * qring buffers and hbq buffers.
  2173. * When the function returns 1 the caller can free the iocb object otherwise
  2174. * upper layer functions will free the iocb objects.
  2175. **/
  2176. static int
  2177. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2178. struct lpfc_iocbq *saveq)
  2179. {
  2180. IOCB_t * irsp;
  2181. WORD5 * w5p;
  2182. uint32_t Rctl, Type;
  2183. uint32_t match;
  2184. struct lpfc_iocbq *iocbq;
  2185. struct lpfc_dmabuf *dmzbuf;
  2186. match = 0;
  2187. irsp = &(saveq->iocb);
  2188. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2189. if (pring->lpfc_sli_rcv_async_status)
  2190. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2191. else
  2192. lpfc_printf_log(phba,
  2193. KERN_WARNING,
  2194. LOG_SLI,
  2195. "0316 Ring %d handler: unexpected "
  2196. "ASYNC_STATUS iocb received evt_code "
  2197. "0x%x\n",
  2198. pring->ringno,
  2199. irsp->un.asyncstat.evt_code);
  2200. return 1;
  2201. }
  2202. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2203. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2204. if (irsp->ulpBdeCount > 0) {
  2205. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2206. irsp->un.ulpWord[3]);
  2207. lpfc_in_buf_free(phba, dmzbuf);
  2208. }
  2209. if (irsp->ulpBdeCount > 1) {
  2210. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2211. irsp->unsli3.sli3Words[3]);
  2212. lpfc_in_buf_free(phba, dmzbuf);
  2213. }
  2214. if (irsp->ulpBdeCount > 2) {
  2215. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2216. irsp->unsli3.sli3Words[7]);
  2217. lpfc_in_buf_free(phba, dmzbuf);
  2218. }
  2219. return 1;
  2220. }
  2221. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2222. if (irsp->ulpBdeCount != 0) {
  2223. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2224. irsp->un.ulpWord[3]);
  2225. if (!saveq->context2)
  2226. lpfc_printf_log(phba,
  2227. KERN_ERR,
  2228. LOG_SLI,
  2229. "0341 Ring %d Cannot find buffer for "
  2230. "an unsolicited iocb. tag 0x%x\n",
  2231. pring->ringno,
  2232. irsp->un.ulpWord[3]);
  2233. }
  2234. if (irsp->ulpBdeCount == 2) {
  2235. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2236. irsp->unsli3.sli3Words[7]);
  2237. if (!saveq->context3)
  2238. lpfc_printf_log(phba,
  2239. KERN_ERR,
  2240. LOG_SLI,
  2241. "0342 Ring %d Cannot find buffer for an"
  2242. " unsolicited iocb. tag 0x%x\n",
  2243. pring->ringno,
  2244. irsp->unsli3.sli3Words[7]);
  2245. }
  2246. list_for_each_entry(iocbq, &saveq->list, list) {
  2247. irsp = &(iocbq->iocb);
  2248. if (irsp->ulpBdeCount != 0) {
  2249. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2250. irsp->un.ulpWord[3]);
  2251. if (!iocbq->context2)
  2252. lpfc_printf_log(phba,
  2253. KERN_ERR,
  2254. LOG_SLI,
  2255. "0343 Ring %d Cannot find "
  2256. "buffer for an unsolicited iocb"
  2257. ". tag 0x%x\n", pring->ringno,
  2258. irsp->un.ulpWord[3]);
  2259. }
  2260. if (irsp->ulpBdeCount == 2) {
  2261. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2262. irsp->unsli3.sli3Words[7]);
  2263. if (!iocbq->context3)
  2264. lpfc_printf_log(phba,
  2265. KERN_ERR,
  2266. LOG_SLI,
  2267. "0344 Ring %d Cannot find "
  2268. "buffer for an unsolicited "
  2269. "iocb. tag 0x%x\n",
  2270. pring->ringno,
  2271. irsp->unsli3.sli3Words[7]);
  2272. }
  2273. }
  2274. }
  2275. if (irsp->ulpBdeCount != 0 &&
  2276. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2277. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2278. int found = 0;
  2279. /* search continue save q for same XRI */
  2280. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2281. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  2282. list_add_tail(&saveq->list, &iocbq->list);
  2283. found = 1;
  2284. break;
  2285. }
  2286. }
  2287. if (!found)
  2288. list_add_tail(&saveq->clist,
  2289. &pring->iocb_continue_saveq);
  2290. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2291. list_del_init(&iocbq->clist);
  2292. saveq = iocbq;
  2293. irsp = &(saveq->iocb);
  2294. } else
  2295. return 0;
  2296. }
  2297. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2298. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2299. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2300. Rctl = FC_RCTL_ELS_REQ;
  2301. Type = FC_TYPE_ELS;
  2302. } else {
  2303. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2304. Rctl = w5p->hcsw.Rctl;
  2305. Type = w5p->hcsw.Type;
  2306. /* Firmware Workaround */
  2307. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2308. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2309. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2310. Rctl = FC_RCTL_ELS_REQ;
  2311. Type = FC_TYPE_ELS;
  2312. w5p->hcsw.Rctl = Rctl;
  2313. w5p->hcsw.Type = Type;
  2314. }
  2315. }
  2316. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2317. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2318. "0313 Ring %d handler: unexpected Rctl x%x "
  2319. "Type x%x received\n",
  2320. pring->ringno, Rctl, Type);
  2321. return 1;
  2322. }
  2323. /**
  2324. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2325. * @phba: Pointer to HBA context object.
  2326. * @pring: Pointer to driver SLI ring object.
  2327. * @prspiocb: Pointer to response iocb object.
  2328. *
  2329. * This function looks up the iocb_lookup table to get the command iocb
  2330. * corresponding to the given response iocb using the iotag of the
  2331. * response iocb. This function is called with the hbalock held.
  2332. * This function returns the command iocb object if it finds the command
  2333. * iocb else returns NULL.
  2334. **/
  2335. static struct lpfc_iocbq *
  2336. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2337. struct lpfc_sli_ring *pring,
  2338. struct lpfc_iocbq *prspiocb)
  2339. {
  2340. struct lpfc_iocbq *cmd_iocb = NULL;
  2341. uint16_t iotag;
  2342. iotag = prspiocb->iocb.ulpIoTag;
  2343. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2344. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2345. list_del_init(&cmd_iocb->list);
  2346. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2347. pring->txcmplq_cnt--;
  2348. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2349. }
  2350. return cmd_iocb;
  2351. }
  2352. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2353. "0317 iotag x%x is out off "
  2354. "range: max iotag x%x wd0 x%x\n",
  2355. iotag, phba->sli.last_iotag,
  2356. *(((uint32_t *) &prspiocb->iocb) + 7));
  2357. return NULL;
  2358. }
  2359. /**
  2360. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2361. * @phba: Pointer to HBA context object.
  2362. * @pring: Pointer to driver SLI ring object.
  2363. * @iotag: IOCB tag.
  2364. *
  2365. * This function looks up the iocb_lookup table to get the command iocb
  2366. * corresponding to the given iotag. This function is called with the
  2367. * hbalock held.
  2368. * This function returns the command iocb object if it finds the command
  2369. * iocb else returns NULL.
  2370. **/
  2371. static struct lpfc_iocbq *
  2372. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2373. struct lpfc_sli_ring *pring, uint16_t iotag)
  2374. {
  2375. struct lpfc_iocbq *cmd_iocb;
  2376. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2377. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2378. list_del_init(&cmd_iocb->list);
  2379. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2380. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2381. pring->txcmplq_cnt--;
  2382. }
  2383. return cmd_iocb;
  2384. }
  2385. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2386. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2387. iotag, phba->sli.last_iotag);
  2388. return NULL;
  2389. }
  2390. /**
  2391. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2392. * @phba: Pointer to HBA context object.
  2393. * @pring: Pointer to driver SLI ring object.
  2394. * @saveq: Pointer to the response iocb to be processed.
  2395. *
  2396. * This function is called by the ring event handler for non-fcp
  2397. * rings when there is a new response iocb in the response ring.
  2398. * The caller is not required to hold any locks. This function
  2399. * gets the command iocb associated with the response iocb and
  2400. * calls the completion handler for the command iocb. If there
  2401. * is no completion handler, the function will free the resources
  2402. * associated with command iocb. If the response iocb is for
  2403. * an already aborted command iocb, the status of the completion
  2404. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2405. * This function always returns 1.
  2406. **/
  2407. static int
  2408. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2409. struct lpfc_iocbq *saveq)
  2410. {
  2411. struct lpfc_iocbq *cmdiocbp;
  2412. int rc = 1;
  2413. unsigned long iflag;
  2414. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2415. spin_lock_irqsave(&phba->hbalock, iflag);
  2416. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2417. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2418. if (cmdiocbp) {
  2419. if (cmdiocbp->iocb_cmpl) {
  2420. /*
  2421. * If an ELS command failed send an event to mgmt
  2422. * application.
  2423. */
  2424. if (saveq->iocb.ulpStatus &&
  2425. (pring->ringno == LPFC_ELS_RING) &&
  2426. (cmdiocbp->iocb.ulpCommand ==
  2427. CMD_ELS_REQUEST64_CR))
  2428. lpfc_send_els_failure_event(phba,
  2429. cmdiocbp, saveq);
  2430. /*
  2431. * Post all ELS completions to the worker thread.
  2432. * All other are passed to the completion callback.
  2433. */
  2434. if (pring->ringno == LPFC_ELS_RING) {
  2435. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2436. (cmdiocbp->iocb_flag &
  2437. LPFC_DRIVER_ABORTED)) {
  2438. spin_lock_irqsave(&phba->hbalock,
  2439. iflag);
  2440. cmdiocbp->iocb_flag &=
  2441. ~LPFC_DRIVER_ABORTED;
  2442. spin_unlock_irqrestore(&phba->hbalock,
  2443. iflag);
  2444. saveq->iocb.ulpStatus =
  2445. IOSTAT_LOCAL_REJECT;
  2446. saveq->iocb.un.ulpWord[4] =
  2447. IOERR_SLI_ABORTED;
  2448. /* Firmware could still be in progress
  2449. * of DMAing payload, so don't free data
  2450. * buffer till after a hbeat.
  2451. */
  2452. spin_lock_irqsave(&phba->hbalock,
  2453. iflag);
  2454. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2455. spin_unlock_irqrestore(&phba->hbalock,
  2456. iflag);
  2457. }
  2458. if (phba->sli_rev == LPFC_SLI_REV4) {
  2459. if (saveq->iocb_flag &
  2460. LPFC_EXCHANGE_BUSY) {
  2461. /* Set cmdiocb flag for the
  2462. * exchange busy so sgl (xri)
  2463. * will not be released until
  2464. * the abort xri is received
  2465. * from hba.
  2466. */
  2467. spin_lock_irqsave(
  2468. &phba->hbalock, iflag);
  2469. cmdiocbp->iocb_flag |=
  2470. LPFC_EXCHANGE_BUSY;
  2471. spin_unlock_irqrestore(
  2472. &phba->hbalock, iflag);
  2473. }
  2474. if (cmdiocbp->iocb_flag &
  2475. LPFC_DRIVER_ABORTED) {
  2476. /*
  2477. * Clear LPFC_DRIVER_ABORTED
  2478. * bit in case it was driver
  2479. * initiated abort.
  2480. */
  2481. spin_lock_irqsave(
  2482. &phba->hbalock, iflag);
  2483. cmdiocbp->iocb_flag &=
  2484. ~LPFC_DRIVER_ABORTED;
  2485. spin_unlock_irqrestore(
  2486. &phba->hbalock, iflag);
  2487. cmdiocbp->iocb.ulpStatus =
  2488. IOSTAT_LOCAL_REJECT;
  2489. cmdiocbp->iocb.un.ulpWord[4] =
  2490. IOERR_ABORT_REQUESTED;
  2491. /*
  2492. * For SLI4, irsiocb contains
  2493. * NO_XRI in sli_xritag, it
  2494. * shall not affect releasing
  2495. * sgl (xri) process.
  2496. */
  2497. saveq->iocb.ulpStatus =
  2498. IOSTAT_LOCAL_REJECT;
  2499. saveq->iocb.un.ulpWord[4] =
  2500. IOERR_SLI_ABORTED;
  2501. spin_lock_irqsave(
  2502. &phba->hbalock, iflag);
  2503. saveq->iocb_flag |=
  2504. LPFC_DELAY_MEM_FREE;
  2505. spin_unlock_irqrestore(
  2506. &phba->hbalock, iflag);
  2507. }
  2508. }
  2509. }
  2510. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2511. } else
  2512. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2513. } else {
  2514. /*
  2515. * Unknown initiating command based on the response iotag.
  2516. * This could be the case on the ELS ring because of
  2517. * lpfc_els_abort().
  2518. */
  2519. if (pring->ringno != LPFC_ELS_RING) {
  2520. /*
  2521. * Ring <ringno> handler: unexpected completion IoTag
  2522. * <IoTag>
  2523. */
  2524. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2525. "0322 Ring %d handler: "
  2526. "unexpected completion IoTag x%x "
  2527. "Data: x%x x%x x%x x%x\n",
  2528. pring->ringno,
  2529. saveq->iocb.ulpIoTag,
  2530. saveq->iocb.ulpStatus,
  2531. saveq->iocb.un.ulpWord[4],
  2532. saveq->iocb.ulpCommand,
  2533. saveq->iocb.ulpContext);
  2534. }
  2535. }
  2536. return rc;
  2537. }
  2538. /**
  2539. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2540. * @phba: Pointer to HBA context object.
  2541. * @pring: Pointer to driver SLI ring object.
  2542. *
  2543. * This function is called from the iocb ring event handlers when
  2544. * put pointer is ahead of the get pointer for a ring. This function signal
  2545. * an error attention condition to the worker thread and the worker
  2546. * thread will transition the HBA to offline state.
  2547. **/
  2548. static void
  2549. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2550. {
  2551. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2552. /*
  2553. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2554. * rsp ring <portRspMax>
  2555. */
  2556. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2557. "0312 Ring %d handler: portRspPut %d "
  2558. "is bigger than rsp ring %d\n",
  2559. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2560. pring->numRiocb);
  2561. phba->link_state = LPFC_HBA_ERROR;
  2562. /*
  2563. * All error attention handlers are posted to
  2564. * worker thread
  2565. */
  2566. phba->work_ha |= HA_ERATT;
  2567. phba->work_hs = HS_FFER3;
  2568. lpfc_worker_wake_up(phba);
  2569. return;
  2570. }
  2571. /**
  2572. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2573. * @ptr: Pointer to address of HBA context object.
  2574. *
  2575. * This function is invoked by the Error Attention polling timer when the
  2576. * timer times out. It will check the SLI Error Attention register for
  2577. * possible attention events. If so, it will post an Error Attention event
  2578. * and wake up worker thread to process it. Otherwise, it will set up the
  2579. * Error Attention polling timer for the next poll.
  2580. **/
  2581. void lpfc_poll_eratt(unsigned long ptr)
  2582. {
  2583. struct lpfc_hba *phba;
  2584. uint32_t eratt = 0;
  2585. phba = (struct lpfc_hba *)ptr;
  2586. /* Check chip HA register for error event */
  2587. eratt = lpfc_sli_check_eratt(phba);
  2588. if (eratt)
  2589. /* Tell the worker thread there is work to do */
  2590. lpfc_worker_wake_up(phba);
  2591. else
  2592. /* Restart the timer for next eratt poll */
  2593. mod_timer(&phba->eratt_poll, jiffies +
  2594. HZ * LPFC_ERATT_POLL_INTERVAL);
  2595. return;
  2596. }
  2597. /**
  2598. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2599. * @phba: Pointer to HBA context object.
  2600. * @pring: Pointer to driver SLI ring object.
  2601. * @mask: Host attention register mask for this ring.
  2602. *
  2603. * This function is called from the interrupt context when there is a ring
  2604. * event for the fcp ring. The caller does not hold any lock.
  2605. * The function processes each response iocb in the response ring until it
  2606. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2607. * LE bit set. The function will call the completion handler of the command iocb
  2608. * if the response iocb indicates a completion for a command iocb or it is
  2609. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2610. * function if this is an unsolicited iocb.
  2611. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2612. * to check it explicitly.
  2613. */
  2614. int
  2615. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2616. struct lpfc_sli_ring *pring, uint32_t mask)
  2617. {
  2618. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2619. IOCB_t *irsp = NULL;
  2620. IOCB_t *entry = NULL;
  2621. struct lpfc_iocbq *cmdiocbq = NULL;
  2622. struct lpfc_iocbq rspiocbq;
  2623. uint32_t status;
  2624. uint32_t portRspPut, portRspMax;
  2625. int rc = 1;
  2626. lpfc_iocb_type type;
  2627. unsigned long iflag;
  2628. uint32_t rsp_cmpl = 0;
  2629. spin_lock_irqsave(&phba->hbalock, iflag);
  2630. pring->stats.iocb_event++;
  2631. /*
  2632. * The next available response entry should never exceed the maximum
  2633. * entries. If it does, treat it as an adapter hardware error.
  2634. */
  2635. portRspMax = pring->numRiocb;
  2636. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2637. if (unlikely(portRspPut >= portRspMax)) {
  2638. lpfc_sli_rsp_pointers_error(phba, pring);
  2639. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2640. return 1;
  2641. }
  2642. if (phba->fcp_ring_in_use) {
  2643. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2644. return 1;
  2645. } else
  2646. phba->fcp_ring_in_use = 1;
  2647. rmb();
  2648. while (pring->rspidx != portRspPut) {
  2649. /*
  2650. * Fetch an entry off the ring and copy it into a local data
  2651. * structure. The copy involves a byte-swap since the
  2652. * network byte order and pci byte orders are different.
  2653. */
  2654. entry = lpfc_resp_iocb(phba, pring);
  2655. phba->last_completion_time = jiffies;
  2656. if (++pring->rspidx >= portRspMax)
  2657. pring->rspidx = 0;
  2658. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2659. (uint32_t *) &rspiocbq.iocb,
  2660. phba->iocb_rsp_size);
  2661. INIT_LIST_HEAD(&(rspiocbq.list));
  2662. irsp = &rspiocbq.iocb;
  2663. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2664. pring->stats.iocb_rsp++;
  2665. rsp_cmpl++;
  2666. if (unlikely(irsp->ulpStatus)) {
  2667. /*
  2668. * If resource errors reported from HBA, reduce
  2669. * queuedepths of the SCSI device.
  2670. */
  2671. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2672. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2673. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2674. phba->lpfc_rampdown_queue_depth(phba);
  2675. spin_lock_irqsave(&phba->hbalock, iflag);
  2676. }
  2677. /* Rsp ring <ringno> error: IOCB */
  2678. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2679. "0336 Rsp Ring %d error: IOCB Data: "
  2680. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2681. pring->ringno,
  2682. irsp->un.ulpWord[0],
  2683. irsp->un.ulpWord[1],
  2684. irsp->un.ulpWord[2],
  2685. irsp->un.ulpWord[3],
  2686. irsp->un.ulpWord[4],
  2687. irsp->un.ulpWord[5],
  2688. *(uint32_t *)&irsp->un1,
  2689. *((uint32_t *)&irsp->un1 + 1));
  2690. }
  2691. switch (type) {
  2692. case LPFC_ABORT_IOCB:
  2693. case LPFC_SOL_IOCB:
  2694. /*
  2695. * Idle exchange closed via ABTS from port. No iocb
  2696. * resources need to be recovered.
  2697. */
  2698. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2699. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2700. "0333 IOCB cmd 0x%x"
  2701. " processed. Skipping"
  2702. " completion\n",
  2703. irsp->ulpCommand);
  2704. break;
  2705. }
  2706. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2707. &rspiocbq);
  2708. if (unlikely(!cmdiocbq))
  2709. break;
  2710. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2711. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2712. if (cmdiocbq->iocb_cmpl) {
  2713. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2714. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2715. &rspiocbq);
  2716. spin_lock_irqsave(&phba->hbalock, iflag);
  2717. }
  2718. break;
  2719. case LPFC_UNSOL_IOCB:
  2720. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2721. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2722. spin_lock_irqsave(&phba->hbalock, iflag);
  2723. break;
  2724. default:
  2725. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2726. char adaptermsg[LPFC_MAX_ADPTMSG];
  2727. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2728. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2729. MAX_MSG_DATA);
  2730. dev_warn(&((phba->pcidev)->dev),
  2731. "lpfc%d: %s\n",
  2732. phba->brd_no, adaptermsg);
  2733. } else {
  2734. /* Unknown IOCB command */
  2735. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2736. "0334 Unknown IOCB command "
  2737. "Data: x%x, x%x x%x x%x x%x\n",
  2738. type, irsp->ulpCommand,
  2739. irsp->ulpStatus,
  2740. irsp->ulpIoTag,
  2741. irsp->ulpContext);
  2742. }
  2743. break;
  2744. }
  2745. /*
  2746. * The response IOCB has been processed. Update the ring
  2747. * pointer in SLIM. If the port response put pointer has not
  2748. * been updated, sync the pgp->rspPutInx and fetch the new port
  2749. * response put pointer.
  2750. */
  2751. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2752. if (pring->rspidx == portRspPut)
  2753. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2754. }
  2755. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2756. pring->stats.iocb_rsp_full++;
  2757. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2758. writel(status, phba->CAregaddr);
  2759. readl(phba->CAregaddr);
  2760. }
  2761. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2762. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2763. pring->stats.iocb_cmd_empty++;
  2764. /* Force update of the local copy of cmdGetInx */
  2765. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2766. lpfc_sli_resume_iocb(phba, pring);
  2767. if ((pring->lpfc_sli_cmd_available))
  2768. (pring->lpfc_sli_cmd_available) (phba, pring);
  2769. }
  2770. phba->fcp_ring_in_use = 0;
  2771. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2772. return rc;
  2773. }
  2774. /**
  2775. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2776. * @phba: Pointer to HBA context object.
  2777. * @pring: Pointer to driver SLI ring object.
  2778. * @rspiocbp: Pointer to driver response IOCB object.
  2779. *
  2780. * This function is called from the worker thread when there is a slow-path
  2781. * response IOCB to process. This function chains all the response iocbs until
  2782. * seeing the iocb with the LE bit set. The function will call
  2783. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2784. * completion of a command iocb. The function will call the
  2785. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2786. * The function frees the resources or calls the completion handler if this
  2787. * iocb is an abort completion. The function returns NULL when the response
  2788. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2789. * this function shall chain the iocb on to the iocb_continueq and return the
  2790. * response iocb passed in.
  2791. **/
  2792. static struct lpfc_iocbq *
  2793. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2794. struct lpfc_iocbq *rspiocbp)
  2795. {
  2796. struct lpfc_iocbq *saveq;
  2797. struct lpfc_iocbq *cmdiocbp;
  2798. struct lpfc_iocbq *next_iocb;
  2799. IOCB_t *irsp = NULL;
  2800. uint32_t free_saveq;
  2801. uint8_t iocb_cmd_type;
  2802. lpfc_iocb_type type;
  2803. unsigned long iflag;
  2804. int rc;
  2805. spin_lock_irqsave(&phba->hbalock, iflag);
  2806. /* First add the response iocb to the countinueq list */
  2807. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2808. pring->iocb_continueq_cnt++;
  2809. /* Now, determine whetehr the list is completed for processing */
  2810. irsp = &rspiocbp->iocb;
  2811. if (irsp->ulpLe) {
  2812. /*
  2813. * By default, the driver expects to free all resources
  2814. * associated with this iocb completion.
  2815. */
  2816. free_saveq = 1;
  2817. saveq = list_get_first(&pring->iocb_continueq,
  2818. struct lpfc_iocbq, list);
  2819. irsp = &(saveq->iocb);
  2820. list_del_init(&pring->iocb_continueq);
  2821. pring->iocb_continueq_cnt = 0;
  2822. pring->stats.iocb_rsp++;
  2823. /*
  2824. * If resource errors reported from HBA, reduce
  2825. * queuedepths of the SCSI device.
  2826. */
  2827. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2828. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2829. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2830. phba->lpfc_rampdown_queue_depth(phba);
  2831. spin_lock_irqsave(&phba->hbalock, iflag);
  2832. }
  2833. if (irsp->ulpStatus) {
  2834. /* Rsp ring <ringno> error: IOCB */
  2835. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2836. "0328 Rsp Ring %d error: "
  2837. "IOCB Data: "
  2838. "x%x x%x x%x x%x "
  2839. "x%x x%x x%x x%x "
  2840. "x%x x%x x%x x%x "
  2841. "x%x x%x x%x x%x\n",
  2842. pring->ringno,
  2843. irsp->un.ulpWord[0],
  2844. irsp->un.ulpWord[1],
  2845. irsp->un.ulpWord[2],
  2846. irsp->un.ulpWord[3],
  2847. irsp->un.ulpWord[4],
  2848. irsp->un.ulpWord[5],
  2849. *(((uint32_t *) irsp) + 6),
  2850. *(((uint32_t *) irsp) + 7),
  2851. *(((uint32_t *) irsp) + 8),
  2852. *(((uint32_t *) irsp) + 9),
  2853. *(((uint32_t *) irsp) + 10),
  2854. *(((uint32_t *) irsp) + 11),
  2855. *(((uint32_t *) irsp) + 12),
  2856. *(((uint32_t *) irsp) + 13),
  2857. *(((uint32_t *) irsp) + 14),
  2858. *(((uint32_t *) irsp) + 15));
  2859. }
  2860. /*
  2861. * Fetch the IOCB command type and call the correct completion
  2862. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2863. * get freed back to the lpfc_iocb_list by the discovery
  2864. * kernel thread.
  2865. */
  2866. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2867. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2868. switch (type) {
  2869. case LPFC_SOL_IOCB:
  2870. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2871. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2872. spin_lock_irqsave(&phba->hbalock, iflag);
  2873. break;
  2874. case LPFC_UNSOL_IOCB:
  2875. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2876. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2877. spin_lock_irqsave(&phba->hbalock, iflag);
  2878. if (!rc)
  2879. free_saveq = 0;
  2880. break;
  2881. case LPFC_ABORT_IOCB:
  2882. cmdiocbp = NULL;
  2883. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2884. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2885. saveq);
  2886. if (cmdiocbp) {
  2887. /* Call the specified completion routine */
  2888. if (cmdiocbp->iocb_cmpl) {
  2889. spin_unlock_irqrestore(&phba->hbalock,
  2890. iflag);
  2891. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2892. saveq);
  2893. spin_lock_irqsave(&phba->hbalock,
  2894. iflag);
  2895. } else
  2896. __lpfc_sli_release_iocbq(phba,
  2897. cmdiocbp);
  2898. }
  2899. break;
  2900. case LPFC_UNKNOWN_IOCB:
  2901. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2902. char adaptermsg[LPFC_MAX_ADPTMSG];
  2903. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2904. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2905. MAX_MSG_DATA);
  2906. dev_warn(&((phba->pcidev)->dev),
  2907. "lpfc%d: %s\n",
  2908. phba->brd_no, adaptermsg);
  2909. } else {
  2910. /* Unknown IOCB command */
  2911. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2912. "0335 Unknown IOCB "
  2913. "command Data: x%x "
  2914. "x%x x%x x%x\n",
  2915. irsp->ulpCommand,
  2916. irsp->ulpStatus,
  2917. irsp->ulpIoTag,
  2918. irsp->ulpContext);
  2919. }
  2920. break;
  2921. }
  2922. if (free_saveq) {
  2923. list_for_each_entry_safe(rspiocbp, next_iocb,
  2924. &saveq->list, list) {
  2925. list_del(&rspiocbp->list);
  2926. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2927. }
  2928. __lpfc_sli_release_iocbq(phba, saveq);
  2929. }
  2930. rspiocbp = NULL;
  2931. }
  2932. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2933. return rspiocbp;
  2934. }
  2935. /**
  2936. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  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 routine wraps the actual slow_ring event process routine from the
  2942. * API jump table function pointer from the lpfc_hba struct.
  2943. **/
  2944. void
  2945. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2946. struct lpfc_sli_ring *pring, uint32_t mask)
  2947. {
  2948. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2949. }
  2950. /**
  2951. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2952. * @phba: Pointer to HBA context object.
  2953. * @pring: Pointer to driver SLI ring object.
  2954. * @mask: Host attention register mask for this ring.
  2955. *
  2956. * This function is called from the worker thread when there is a ring event
  2957. * for non-fcp rings. The caller does not hold any lock. The function will
  2958. * remove each response iocb in the response ring and calls the handle
  2959. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2960. **/
  2961. static void
  2962. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2963. struct lpfc_sli_ring *pring, uint32_t mask)
  2964. {
  2965. struct lpfc_pgp *pgp;
  2966. IOCB_t *entry;
  2967. IOCB_t *irsp = NULL;
  2968. struct lpfc_iocbq *rspiocbp = NULL;
  2969. uint32_t portRspPut, portRspMax;
  2970. unsigned long iflag;
  2971. uint32_t status;
  2972. pgp = &phba->port_gp[pring->ringno];
  2973. spin_lock_irqsave(&phba->hbalock, iflag);
  2974. pring->stats.iocb_event++;
  2975. /*
  2976. * The next available response entry should never exceed the maximum
  2977. * entries. If it does, treat it as an adapter hardware error.
  2978. */
  2979. portRspMax = pring->numRiocb;
  2980. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2981. if (portRspPut >= portRspMax) {
  2982. /*
  2983. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2984. * rsp ring <portRspMax>
  2985. */
  2986. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2987. "0303 Ring %d handler: portRspPut %d "
  2988. "is bigger than rsp ring %d\n",
  2989. pring->ringno, portRspPut, portRspMax);
  2990. phba->link_state = LPFC_HBA_ERROR;
  2991. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2992. phba->work_hs = HS_FFER3;
  2993. lpfc_handle_eratt(phba);
  2994. return;
  2995. }
  2996. rmb();
  2997. while (pring->rspidx != portRspPut) {
  2998. /*
  2999. * Build a completion list and call the appropriate handler.
  3000. * The process is to get the next available response iocb, get
  3001. * a free iocb from the list, copy the response data into the
  3002. * free iocb, insert to the continuation list, and update the
  3003. * next response index to slim. This process makes response
  3004. * iocb's in the ring available to DMA as fast as possible but
  3005. * pays a penalty for a copy operation. Since the iocb is
  3006. * only 32 bytes, this penalty is considered small relative to
  3007. * the PCI reads for register values and a slim write. When
  3008. * the ulpLe field is set, the entire Command has been
  3009. * received.
  3010. */
  3011. entry = lpfc_resp_iocb(phba, pring);
  3012. phba->last_completion_time = jiffies;
  3013. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3014. if (rspiocbp == NULL) {
  3015. printk(KERN_ERR "%s: out of buffers! Failing "
  3016. "completion.\n", __func__);
  3017. break;
  3018. }
  3019. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3020. phba->iocb_rsp_size);
  3021. irsp = &rspiocbp->iocb;
  3022. if (++pring->rspidx >= portRspMax)
  3023. pring->rspidx = 0;
  3024. if (pring->ringno == LPFC_ELS_RING) {
  3025. lpfc_debugfs_slow_ring_trc(phba,
  3026. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3027. *(((uint32_t *) irsp) + 4),
  3028. *(((uint32_t *) irsp) + 6),
  3029. *(((uint32_t *) irsp) + 7));
  3030. }
  3031. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3032. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3033. /* Handle the response IOCB */
  3034. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3035. spin_lock_irqsave(&phba->hbalock, iflag);
  3036. /*
  3037. * If the port response put pointer has not been updated, sync
  3038. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3039. * response put pointer.
  3040. */
  3041. if (pring->rspidx == portRspPut) {
  3042. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3043. }
  3044. } /* while (pring->rspidx != portRspPut) */
  3045. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3046. /* At least one response entry has been freed */
  3047. pring->stats.iocb_rsp_full++;
  3048. /* SET RxRE_RSP in Chip Att register */
  3049. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3050. writel(status, phba->CAregaddr);
  3051. readl(phba->CAregaddr); /* flush */
  3052. }
  3053. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3054. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3055. pring->stats.iocb_cmd_empty++;
  3056. /* Force update of the local copy of cmdGetInx */
  3057. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3058. lpfc_sli_resume_iocb(phba, pring);
  3059. if ((pring->lpfc_sli_cmd_available))
  3060. (pring->lpfc_sli_cmd_available) (phba, pring);
  3061. }
  3062. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3063. return;
  3064. }
  3065. /**
  3066. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3067. * @phba: Pointer to HBA context object.
  3068. * @pring: Pointer to driver SLI ring object.
  3069. * @mask: Host attention register mask for this ring.
  3070. *
  3071. * This function is called from the worker thread when there is a pending
  3072. * ELS response iocb on the driver internal slow-path response iocb worker
  3073. * queue. The caller does not hold any lock. The function will remove each
  3074. * response iocb from the response worker queue and calls the handle
  3075. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3076. **/
  3077. static void
  3078. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3079. struct lpfc_sli_ring *pring, uint32_t mask)
  3080. {
  3081. struct lpfc_iocbq *irspiocbq;
  3082. struct hbq_dmabuf *dmabuf;
  3083. struct lpfc_cq_event *cq_event;
  3084. unsigned long iflag;
  3085. spin_lock_irqsave(&phba->hbalock, iflag);
  3086. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3087. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3088. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3089. /* Get the response iocb from the head of work queue */
  3090. spin_lock_irqsave(&phba->hbalock, iflag);
  3091. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3092. cq_event, struct lpfc_cq_event, list);
  3093. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3094. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3095. case CQE_CODE_COMPL_WQE:
  3096. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3097. cq_event);
  3098. /* Translate ELS WCQE to response IOCBQ */
  3099. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3100. irspiocbq);
  3101. if (irspiocbq)
  3102. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3103. irspiocbq);
  3104. break;
  3105. case CQE_CODE_RECEIVE:
  3106. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3107. cq_event);
  3108. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3109. break;
  3110. default:
  3111. break;
  3112. }
  3113. }
  3114. }
  3115. /**
  3116. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3117. * @phba: Pointer to HBA context object.
  3118. * @pring: Pointer to driver SLI ring object.
  3119. *
  3120. * This function aborts all iocbs in the given ring and frees all the iocb
  3121. * objects in txq. This function issues an abort iocb for all the iocb commands
  3122. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3123. * the return of this function. The caller is not required to hold any locks.
  3124. **/
  3125. void
  3126. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3127. {
  3128. LIST_HEAD(completions);
  3129. struct lpfc_iocbq *iocb, *next_iocb;
  3130. if (pring->ringno == LPFC_ELS_RING) {
  3131. lpfc_fabric_abort_hba(phba);
  3132. }
  3133. /* Error everything on txq and txcmplq
  3134. * First do the txq.
  3135. */
  3136. spin_lock_irq(&phba->hbalock);
  3137. list_splice_init(&pring->txq, &completions);
  3138. pring->txq_cnt = 0;
  3139. /* Next issue ABTS for everything on the txcmplq */
  3140. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3141. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3142. spin_unlock_irq(&phba->hbalock);
  3143. /* Cancel all the IOCBs from the completions list */
  3144. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3145. IOERR_SLI_ABORTED);
  3146. }
  3147. /**
  3148. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3149. * @phba: Pointer to HBA context object.
  3150. *
  3151. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3152. * objects in txq and txcmplq. This function will not issue abort iocbs
  3153. * for all the iocb commands in txcmplq, they will just be returned with
  3154. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3155. * slot has been permanently disabled.
  3156. **/
  3157. void
  3158. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3159. {
  3160. LIST_HEAD(txq);
  3161. LIST_HEAD(txcmplq);
  3162. struct lpfc_sli *psli = &phba->sli;
  3163. struct lpfc_sli_ring *pring;
  3164. /* Currently, only one fcp ring */
  3165. pring = &psli->ring[psli->fcp_ring];
  3166. spin_lock_irq(&phba->hbalock);
  3167. /* Retrieve everything on txq */
  3168. list_splice_init(&pring->txq, &txq);
  3169. pring->txq_cnt = 0;
  3170. /* Retrieve everything on the txcmplq */
  3171. list_splice_init(&pring->txcmplq, &txcmplq);
  3172. pring->txcmplq_cnt = 0;
  3173. spin_unlock_irq(&phba->hbalock);
  3174. /* Flush the txq */
  3175. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3176. IOERR_SLI_DOWN);
  3177. /* Flush the txcmpq */
  3178. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3179. IOERR_SLI_DOWN);
  3180. }
  3181. /**
  3182. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3183. * @phba: Pointer to HBA context object.
  3184. * @mask: Bit mask to be checked.
  3185. *
  3186. * This function reads the host status register and compares
  3187. * with the provided bit mask to check if HBA completed
  3188. * the restart. This function will wait in a loop for the
  3189. * HBA to complete restart. If the HBA does not restart within
  3190. * 15 iterations, the function will reset the HBA again. The
  3191. * function returns 1 when HBA fail to restart otherwise returns
  3192. * zero.
  3193. **/
  3194. static int
  3195. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3196. {
  3197. uint32_t status;
  3198. int i = 0;
  3199. int retval = 0;
  3200. /* Read the HBA Host Status Register */
  3201. status = readl(phba->HSregaddr);
  3202. /*
  3203. * Check status register every 100ms for 5 retries, then every
  3204. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3205. * every 2.5 sec for 4.
  3206. * Break our of the loop if errors occurred during init.
  3207. */
  3208. while (((status & mask) != mask) &&
  3209. !(status & HS_FFERM) &&
  3210. i++ < 20) {
  3211. if (i <= 5)
  3212. msleep(10);
  3213. else if (i <= 10)
  3214. msleep(500);
  3215. else
  3216. msleep(2500);
  3217. if (i == 15) {
  3218. /* Do post */
  3219. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3220. lpfc_sli_brdrestart(phba);
  3221. }
  3222. /* Read the HBA Host Status Register */
  3223. status = readl(phba->HSregaddr);
  3224. }
  3225. /* Check to see if any errors occurred during init */
  3226. if ((status & HS_FFERM) || (i >= 20)) {
  3227. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3228. "2751 Adapter failed to restart, "
  3229. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3230. status,
  3231. readl(phba->MBslimaddr + 0xa8),
  3232. readl(phba->MBslimaddr + 0xac));
  3233. phba->link_state = LPFC_HBA_ERROR;
  3234. retval = 1;
  3235. }
  3236. return retval;
  3237. }
  3238. /**
  3239. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3240. * @phba: Pointer to HBA context object.
  3241. * @mask: Bit mask to be checked.
  3242. *
  3243. * This function checks the host status register to check if HBA is
  3244. * ready. This function will wait in a loop for the HBA to be ready
  3245. * If the HBA is not ready , the function will will reset the HBA PCI
  3246. * function again. The function returns 1 when HBA fail to be ready
  3247. * otherwise returns zero.
  3248. **/
  3249. static int
  3250. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3251. {
  3252. uint32_t status;
  3253. int retval = 0;
  3254. /* Read the HBA Host Status Register */
  3255. status = lpfc_sli4_post_status_check(phba);
  3256. if (status) {
  3257. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3258. lpfc_sli_brdrestart(phba);
  3259. status = lpfc_sli4_post_status_check(phba);
  3260. }
  3261. /* Check to see if any errors occurred during init */
  3262. if (status) {
  3263. phba->link_state = LPFC_HBA_ERROR;
  3264. retval = 1;
  3265. } else
  3266. phba->sli4_hba.intr_enable = 0;
  3267. return retval;
  3268. }
  3269. /**
  3270. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3271. * @phba: Pointer to HBA context object.
  3272. * @mask: Bit mask to be checked.
  3273. *
  3274. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3275. * from the API jump table function pointer from the lpfc_hba struct.
  3276. **/
  3277. int
  3278. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3279. {
  3280. return phba->lpfc_sli_brdready(phba, mask);
  3281. }
  3282. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3283. /**
  3284. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3285. * @phba: Pointer to HBA context object.
  3286. *
  3287. * This function is called before resetting an HBA. This
  3288. * function requests HBA to quiesce DMAs before a reset.
  3289. **/
  3290. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3291. {
  3292. uint32_t __iomem *resp_buf;
  3293. uint32_t __iomem *mbox_buf;
  3294. volatile uint32_t mbox;
  3295. uint32_t hc_copy;
  3296. int i;
  3297. uint8_t hdrtype;
  3298. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3299. if (hdrtype != 0x80 ||
  3300. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3301. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3302. return;
  3303. /*
  3304. * Tell the other part of the chip to suspend temporarily all
  3305. * its DMA activity.
  3306. */
  3307. resp_buf = phba->MBslimaddr;
  3308. /* Disable the error attention */
  3309. hc_copy = readl(phba->HCregaddr);
  3310. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3311. readl(phba->HCregaddr); /* flush */
  3312. phba->link_flag |= LS_IGNORE_ERATT;
  3313. if (readl(phba->HAregaddr) & HA_ERATT) {
  3314. /* Clear Chip error bit */
  3315. writel(HA_ERATT, phba->HAregaddr);
  3316. phba->pport->stopped = 1;
  3317. }
  3318. mbox = 0;
  3319. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3320. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3321. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3322. mbox_buf = phba->MBslimaddr;
  3323. writel(mbox, mbox_buf);
  3324. for (i = 0;
  3325. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  3326. mdelay(1);
  3327. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  3328. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3329. phba->pport->stopped)
  3330. goto restore_hc;
  3331. else
  3332. goto clear_errat;
  3333. }
  3334. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3335. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  3336. mdelay(1);
  3337. clear_errat:
  3338. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  3339. mdelay(1);
  3340. if (readl(phba->HAregaddr) & HA_ERATT) {
  3341. writel(HA_ERATT, phba->HAregaddr);
  3342. phba->pport->stopped = 1;
  3343. }
  3344. restore_hc:
  3345. phba->link_flag &= ~LS_IGNORE_ERATT;
  3346. writel(hc_copy, phba->HCregaddr);
  3347. readl(phba->HCregaddr); /* flush */
  3348. }
  3349. /**
  3350. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3351. * @phba: Pointer to HBA context object.
  3352. *
  3353. * This function issues a kill_board mailbox command and waits for
  3354. * the error attention interrupt. This function is called for stopping
  3355. * the firmware processing. The caller is not required to hold any
  3356. * locks. This function calls lpfc_hba_down_post function to free
  3357. * any pending commands after the kill. The function will return 1 when it
  3358. * fails to kill the board else will return 0.
  3359. **/
  3360. int
  3361. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3362. {
  3363. struct lpfc_sli *psli;
  3364. LPFC_MBOXQ_t *pmb;
  3365. uint32_t status;
  3366. uint32_t ha_copy;
  3367. int retval;
  3368. int i = 0;
  3369. psli = &phba->sli;
  3370. /* Kill HBA */
  3371. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3372. "0329 Kill HBA Data: x%x x%x\n",
  3373. phba->pport->port_state, psli->sli_flag);
  3374. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3375. if (!pmb)
  3376. return 1;
  3377. /* Disable the error attention */
  3378. spin_lock_irq(&phba->hbalock);
  3379. status = readl(phba->HCregaddr);
  3380. status &= ~HC_ERINT_ENA;
  3381. writel(status, phba->HCregaddr);
  3382. readl(phba->HCregaddr); /* flush */
  3383. phba->link_flag |= LS_IGNORE_ERATT;
  3384. spin_unlock_irq(&phba->hbalock);
  3385. lpfc_kill_board(phba, pmb);
  3386. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3387. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3388. if (retval != MBX_SUCCESS) {
  3389. if (retval != MBX_BUSY)
  3390. mempool_free(pmb, phba->mbox_mem_pool);
  3391. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3392. "2752 KILL_BOARD command failed retval %d\n",
  3393. retval);
  3394. spin_lock_irq(&phba->hbalock);
  3395. phba->link_flag &= ~LS_IGNORE_ERATT;
  3396. spin_unlock_irq(&phba->hbalock);
  3397. return 1;
  3398. }
  3399. spin_lock_irq(&phba->hbalock);
  3400. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3401. spin_unlock_irq(&phba->hbalock);
  3402. mempool_free(pmb, phba->mbox_mem_pool);
  3403. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3404. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3405. * 3 seconds we still set HBA_ERROR state because the status of the
  3406. * board is now undefined.
  3407. */
  3408. ha_copy = readl(phba->HAregaddr);
  3409. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3410. mdelay(100);
  3411. ha_copy = readl(phba->HAregaddr);
  3412. }
  3413. del_timer_sync(&psli->mbox_tmo);
  3414. if (ha_copy & HA_ERATT) {
  3415. writel(HA_ERATT, phba->HAregaddr);
  3416. phba->pport->stopped = 1;
  3417. }
  3418. spin_lock_irq(&phba->hbalock);
  3419. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3420. psli->mbox_active = NULL;
  3421. phba->link_flag &= ~LS_IGNORE_ERATT;
  3422. spin_unlock_irq(&phba->hbalock);
  3423. lpfc_hba_down_post(phba);
  3424. phba->link_state = LPFC_HBA_ERROR;
  3425. return ha_copy & HA_ERATT ? 0 : 1;
  3426. }
  3427. /**
  3428. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3429. * @phba: Pointer to HBA context object.
  3430. *
  3431. * This function resets the HBA by writing HC_INITFF to the control
  3432. * register. After the HBA resets, this function resets all the iocb ring
  3433. * indices. This function disables PCI layer parity checking during
  3434. * the reset.
  3435. * This function returns 0 always.
  3436. * The caller is not required to hold any locks.
  3437. **/
  3438. int
  3439. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3440. {
  3441. struct lpfc_sli *psli;
  3442. struct lpfc_sli_ring *pring;
  3443. uint16_t cfg_value;
  3444. int i;
  3445. psli = &phba->sli;
  3446. /* Reset HBA */
  3447. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3448. "0325 Reset HBA Data: x%x x%x\n",
  3449. phba->pport->port_state, psli->sli_flag);
  3450. /* perform board reset */
  3451. phba->fc_eventTag = 0;
  3452. phba->link_events = 0;
  3453. phba->pport->fc_myDID = 0;
  3454. phba->pport->fc_prevDID = 0;
  3455. /* Turn off parity checking and serr during the physical reset */
  3456. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3457. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3458. (cfg_value &
  3459. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3460. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3461. /* Now toggle INITFF bit in the Host Control Register */
  3462. writel(HC_INITFF, phba->HCregaddr);
  3463. mdelay(1);
  3464. readl(phba->HCregaddr); /* flush */
  3465. writel(0, phba->HCregaddr);
  3466. readl(phba->HCregaddr); /* flush */
  3467. /* Restore PCI cmd register */
  3468. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3469. /* Initialize relevant SLI info */
  3470. for (i = 0; i < psli->num_rings; i++) {
  3471. pring = &psli->ring[i];
  3472. pring->flag = 0;
  3473. pring->rspidx = 0;
  3474. pring->next_cmdidx = 0;
  3475. pring->local_getidx = 0;
  3476. pring->cmdidx = 0;
  3477. pring->missbufcnt = 0;
  3478. }
  3479. phba->link_state = LPFC_WARM_START;
  3480. return 0;
  3481. }
  3482. /**
  3483. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3484. * @phba: Pointer to HBA context object.
  3485. *
  3486. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3487. * checking during resets the device. The caller is not required to hold
  3488. * any locks.
  3489. *
  3490. * This function returns 0 always.
  3491. **/
  3492. int
  3493. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3494. {
  3495. struct lpfc_sli *psli = &phba->sli;
  3496. uint16_t cfg_value;
  3497. uint8_t qindx;
  3498. /* Reset HBA */
  3499. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3500. "0295 Reset HBA Data: x%x x%x\n",
  3501. phba->pport->port_state, psli->sli_flag);
  3502. /* perform board reset */
  3503. phba->fc_eventTag = 0;
  3504. phba->link_events = 0;
  3505. phba->pport->fc_myDID = 0;
  3506. phba->pport->fc_prevDID = 0;
  3507. spin_lock_irq(&phba->hbalock);
  3508. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3509. phba->fcf.fcf_flag = 0;
  3510. /* Clean up the child queue list for the CQs */
  3511. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3512. list_del_init(&phba->sli4_hba.els_wq->list);
  3513. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3514. list_del_init(&phba->sli4_hba.dat_rq->list);
  3515. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3516. list_del_init(&phba->sli4_hba.els_cq->list);
  3517. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3518. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3519. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3520. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3521. spin_unlock_irq(&phba->hbalock);
  3522. /* Now physically reset the device */
  3523. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3524. "0389 Performing PCI function reset!\n");
  3525. /* Turn off parity checking and serr during the physical reset */
  3526. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3527. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3528. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3529. /* Perform FCoE PCI function reset */
  3530. lpfc_pci_function_reset(phba);
  3531. /* Restore PCI cmd register */
  3532. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3533. return 0;
  3534. }
  3535. /**
  3536. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3537. * @phba: Pointer to HBA context object.
  3538. *
  3539. * This function is called in the SLI initialization code path to
  3540. * restart the HBA. The caller is not required to hold any lock.
  3541. * This function writes MBX_RESTART mailbox command to the SLIM and
  3542. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3543. * function to free any pending commands. The function enables
  3544. * POST only during the first initialization. The function returns zero.
  3545. * The function does not guarantee completion of MBX_RESTART mailbox
  3546. * command before the return of this function.
  3547. **/
  3548. static int
  3549. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3550. {
  3551. MAILBOX_t *mb;
  3552. struct lpfc_sli *psli;
  3553. volatile uint32_t word0;
  3554. void __iomem *to_slim;
  3555. uint32_t hba_aer_enabled;
  3556. spin_lock_irq(&phba->hbalock);
  3557. /* Take PCIe device Advanced Error Reporting (AER) state */
  3558. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3559. psli = &phba->sli;
  3560. /* Restart HBA */
  3561. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3562. "0337 Restart HBA Data: x%x x%x\n",
  3563. phba->pport->port_state, psli->sli_flag);
  3564. word0 = 0;
  3565. mb = (MAILBOX_t *) &word0;
  3566. mb->mbxCommand = MBX_RESTART;
  3567. mb->mbxHc = 1;
  3568. lpfc_reset_barrier(phba);
  3569. to_slim = phba->MBslimaddr;
  3570. writel(*(uint32_t *) mb, to_slim);
  3571. readl(to_slim); /* flush */
  3572. /* Only skip post after fc_ffinit is completed */
  3573. if (phba->pport->port_state)
  3574. word0 = 1; /* This is really setting up word1 */
  3575. else
  3576. word0 = 0; /* This is really setting up word1 */
  3577. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3578. writel(*(uint32_t *) mb, to_slim);
  3579. readl(to_slim); /* flush */
  3580. lpfc_sli_brdreset(phba);
  3581. phba->pport->stopped = 0;
  3582. phba->link_state = LPFC_INIT_START;
  3583. phba->hba_flag = 0;
  3584. spin_unlock_irq(&phba->hbalock);
  3585. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3586. psli->stats_start = get_seconds();
  3587. /* Give the INITFF and Post time to settle. */
  3588. mdelay(100);
  3589. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3590. if (hba_aer_enabled)
  3591. pci_disable_pcie_error_reporting(phba->pcidev);
  3592. lpfc_hba_down_post(phba);
  3593. return 0;
  3594. }
  3595. /**
  3596. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3597. * @phba: Pointer to HBA context object.
  3598. *
  3599. * This function is called in the SLI initialization code path to restart
  3600. * a SLI4 HBA. The caller is not required to hold any lock.
  3601. * At the end of the function, it calls lpfc_hba_down_post function to
  3602. * free any pending commands.
  3603. **/
  3604. static int
  3605. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3606. {
  3607. struct lpfc_sli *psli = &phba->sli;
  3608. uint32_t hba_aer_enabled;
  3609. /* Restart HBA */
  3610. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3611. "0296 Restart HBA Data: x%x x%x\n",
  3612. phba->pport->port_state, psli->sli_flag);
  3613. /* Take PCIe device Advanced Error Reporting (AER) state */
  3614. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3615. lpfc_sli4_brdreset(phba);
  3616. spin_lock_irq(&phba->hbalock);
  3617. phba->pport->stopped = 0;
  3618. phba->link_state = LPFC_INIT_START;
  3619. phba->hba_flag = 0;
  3620. spin_unlock_irq(&phba->hbalock);
  3621. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3622. psli->stats_start = get_seconds();
  3623. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3624. if (hba_aer_enabled)
  3625. pci_disable_pcie_error_reporting(phba->pcidev);
  3626. lpfc_hba_down_post(phba);
  3627. return 0;
  3628. }
  3629. /**
  3630. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3631. * @phba: Pointer to HBA context object.
  3632. *
  3633. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3634. * API jump table function pointer from the lpfc_hba struct.
  3635. **/
  3636. int
  3637. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3638. {
  3639. return phba->lpfc_sli_brdrestart(phba);
  3640. }
  3641. /**
  3642. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3643. * @phba: Pointer to HBA context object.
  3644. *
  3645. * This function is called after a HBA restart to wait for successful
  3646. * restart of the HBA. Successful restart of the HBA is indicated by
  3647. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3648. * iteration, the function will restart the HBA again. The function returns
  3649. * zero if HBA successfully restarted else returns negative error code.
  3650. **/
  3651. static int
  3652. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3653. {
  3654. uint32_t status, i = 0;
  3655. /* Read the HBA Host Status Register */
  3656. status = readl(phba->HSregaddr);
  3657. /* Check status register to see what current state is */
  3658. i = 0;
  3659. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3660. /* Check every 10ms for 10 retries, then every 100ms for 90
  3661. * retries, then every 1 sec for 50 retires for a total of
  3662. * ~60 seconds before reset the board again and check every
  3663. * 1 sec for 50 retries. The up to 60 seconds before the
  3664. * board ready is required by the Falcon FIPS zeroization
  3665. * complete, and any reset the board in between shall cause
  3666. * restart of zeroization, further delay the board ready.
  3667. */
  3668. if (i++ >= 200) {
  3669. /* Adapter failed to init, timeout, status reg
  3670. <status> */
  3671. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3672. "0436 Adapter failed to init, "
  3673. "timeout, status reg x%x, "
  3674. "FW Data: A8 x%x AC x%x\n", status,
  3675. readl(phba->MBslimaddr + 0xa8),
  3676. readl(phba->MBslimaddr + 0xac));
  3677. phba->link_state = LPFC_HBA_ERROR;
  3678. return -ETIMEDOUT;
  3679. }
  3680. /* Check to see if any errors occurred during init */
  3681. if (status & HS_FFERM) {
  3682. /* ERROR: During chipset initialization */
  3683. /* Adapter failed to init, chipset, status reg
  3684. <status> */
  3685. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3686. "0437 Adapter failed to init, "
  3687. "chipset, status reg x%x, "
  3688. "FW Data: A8 x%x AC x%x\n", status,
  3689. readl(phba->MBslimaddr + 0xa8),
  3690. readl(phba->MBslimaddr + 0xac));
  3691. phba->link_state = LPFC_HBA_ERROR;
  3692. return -EIO;
  3693. }
  3694. if (i <= 10)
  3695. msleep(10);
  3696. else if (i <= 100)
  3697. msleep(100);
  3698. else
  3699. msleep(1000);
  3700. if (i == 150) {
  3701. /* Do post */
  3702. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3703. lpfc_sli_brdrestart(phba);
  3704. }
  3705. /* Read the HBA Host Status Register */
  3706. status = readl(phba->HSregaddr);
  3707. }
  3708. /* Check to see if any errors occurred during init */
  3709. if (status & HS_FFERM) {
  3710. /* ERROR: During chipset initialization */
  3711. /* Adapter failed to init, chipset, status reg <status> */
  3712. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3713. "0438 Adapter failed to init, chipset, "
  3714. "status reg x%x, "
  3715. "FW Data: A8 x%x AC x%x\n", status,
  3716. readl(phba->MBslimaddr + 0xa8),
  3717. readl(phba->MBslimaddr + 0xac));
  3718. phba->link_state = LPFC_HBA_ERROR;
  3719. return -EIO;
  3720. }
  3721. /* Clear all interrupt enable conditions */
  3722. writel(0, phba->HCregaddr);
  3723. readl(phba->HCregaddr); /* flush */
  3724. /* setup host attn register */
  3725. writel(0xffffffff, phba->HAregaddr);
  3726. readl(phba->HAregaddr); /* flush */
  3727. return 0;
  3728. }
  3729. /**
  3730. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3731. *
  3732. * This function calculates and returns the number of HBQs required to be
  3733. * configured.
  3734. **/
  3735. int
  3736. lpfc_sli_hbq_count(void)
  3737. {
  3738. return ARRAY_SIZE(lpfc_hbq_defs);
  3739. }
  3740. /**
  3741. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3742. *
  3743. * This function adds the number of hbq entries in every HBQ to get
  3744. * the total number of hbq entries required for the HBA and returns
  3745. * the total count.
  3746. **/
  3747. static int
  3748. lpfc_sli_hbq_entry_count(void)
  3749. {
  3750. int hbq_count = lpfc_sli_hbq_count();
  3751. int count = 0;
  3752. int i;
  3753. for (i = 0; i < hbq_count; ++i)
  3754. count += lpfc_hbq_defs[i]->entry_count;
  3755. return count;
  3756. }
  3757. /**
  3758. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3759. *
  3760. * This function calculates amount of memory required for all hbq entries
  3761. * to be configured and returns the total memory required.
  3762. **/
  3763. int
  3764. lpfc_sli_hbq_size(void)
  3765. {
  3766. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3767. }
  3768. /**
  3769. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3770. * @phba: Pointer to HBA context object.
  3771. *
  3772. * This function is called during the SLI initialization to configure
  3773. * all the HBQs and post buffers to the HBQ. The caller is not
  3774. * required to hold any locks. This function will return zero if successful
  3775. * else it will return negative error code.
  3776. **/
  3777. static int
  3778. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3779. {
  3780. int hbq_count = lpfc_sli_hbq_count();
  3781. LPFC_MBOXQ_t *pmb;
  3782. MAILBOX_t *pmbox;
  3783. uint32_t hbqno;
  3784. uint32_t hbq_entry_index;
  3785. /* Get a Mailbox buffer to setup mailbox
  3786. * commands for HBA initialization
  3787. */
  3788. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3789. if (!pmb)
  3790. return -ENOMEM;
  3791. pmbox = &pmb->u.mb;
  3792. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3793. phba->link_state = LPFC_INIT_MBX_CMDS;
  3794. phba->hbq_in_use = 1;
  3795. hbq_entry_index = 0;
  3796. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3797. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3798. phba->hbqs[hbqno].hbqPutIdx = 0;
  3799. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3800. phba->hbqs[hbqno].entry_count =
  3801. lpfc_hbq_defs[hbqno]->entry_count;
  3802. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3803. hbq_entry_index, pmb);
  3804. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3805. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3806. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3807. mbxStatus <status>, ring <num> */
  3808. lpfc_printf_log(phba, KERN_ERR,
  3809. LOG_SLI | LOG_VPORT,
  3810. "1805 Adapter failed to init. "
  3811. "Data: x%x x%x x%x\n",
  3812. pmbox->mbxCommand,
  3813. pmbox->mbxStatus, hbqno);
  3814. phba->link_state = LPFC_HBA_ERROR;
  3815. mempool_free(pmb, phba->mbox_mem_pool);
  3816. return -ENXIO;
  3817. }
  3818. }
  3819. phba->hbq_count = hbq_count;
  3820. mempool_free(pmb, phba->mbox_mem_pool);
  3821. /* Initially populate or replenish the HBQs */
  3822. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3823. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3824. return 0;
  3825. }
  3826. /**
  3827. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3828. * @phba: Pointer to HBA context object.
  3829. *
  3830. * This function is called during the SLI initialization to configure
  3831. * all the HBQs and post buffers to the HBQ. The caller is not
  3832. * required to hold any locks. This function will return zero if successful
  3833. * else it will return negative error code.
  3834. **/
  3835. static int
  3836. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3837. {
  3838. phba->hbq_in_use = 1;
  3839. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3840. phba->hbq_count = 1;
  3841. /* Initially populate or replenish the HBQs */
  3842. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3843. return 0;
  3844. }
  3845. /**
  3846. * lpfc_sli_config_port - Issue config port mailbox command
  3847. * @phba: Pointer to HBA context object.
  3848. * @sli_mode: sli mode - 2/3
  3849. *
  3850. * This function is called by the sli intialization code path
  3851. * to issue config_port mailbox command. This function restarts the
  3852. * HBA firmware and issues a config_port mailbox command to configure
  3853. * the SLI interface in the sli mode specified by sli_mode
  3854. * variable. The caller is not required to hold any locks.
  3855. * The function returns 0 if successful, else returns negative error
  3856. * code.
  3857. **/
  3858. int
  3859. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3860. {
  3861. LPFC_MBOXQ_t *pmb;
  3862. uint32_t resetcount = 0, rc = 0, done = 0;
  3863. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3864. if (!pmb) {
  3865. phba->link_state = LPFC_HBA_ERROR;
  3866. return -ENOMEM;
  3867. }
  3868. phba->sli_rev = sli_mode;
  3869. while (resetcount < 2 && !done) {
  3870. spin_lock_irq(&phba->hbalock);
  3871. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3872. spin_unlock_irq(&phba->hbalock);
  3873. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3874. lpfc_sli_brdrestart(phba);
  3875. rc = lpfc_sli_chipset_init(phba);
  3876. if (rc)
  3877. break;
  3878. spin_lock_irq(&phba->hbalock);
  3879. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3880. spin_unlock_irq(&phba->hbalock);
  3881. resetcount++;
  3882. /* Call pre CONFIG_PORT mailbox command initialization. A
  3883. * value of 0 means the call was successful. Any other
  3884. * nonzero value is a failure, but if ERESTART is returned,
  3885. * the driver may reset the HBA and try again.
  3886. */
  3887. rc = lpfc_config_port_prep(phba);
  3888. if (rc == -ERESTART) {
  3889. phba->link_state = LPFC_LINK_UNKNOWN;
  3890. continue;
  3891. } else if (rc)
  3892. break;
  3893. phba->link_state = LPFC_INIT_MBX_CMDS;
  3894. lpfc_config_port(phba, pmb);
  3895. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3896. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3897. LPFC_SLI3_HBQ_ENABLED |
  3898. LPFC_SLI3_CRP_ENABLED |
  3899. LPFC_SLI3_BG_ENABLED |
  3900. LPFC_SLI3_DSS_ENABLED);
  3901. if (rc != MBX_SUCCESS) {
  3902. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3903. "0442 Adapter failed to init, mbxCmd x%x "
  3904. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3905. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3906. spin_lock_irq(&phba->hbalock);
  3907. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3908. spin_unlock_irq(&phba->hbalock);
  3909. rc = -ENXIO;
  3910. } else {
  3911. /* Allow asynchronous mailbox command to go through */
  3912. spin_lock_irq(&phba->hbalock);
  3913. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3914. spin_unlock_irq(&phba->hbalock);
  3915. done = 1;
  3916. }
  3917. }
  3918. if (!done) {
  3919. rc = -EINVAL;
  3920. goto do_prep_failed;
  3921. }
  3922. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3923. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3924. rc = -ENXIO;
  3925. goto do_prep_failed;
  3926. }
  3927. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3928. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3929. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3930. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3931. phba->max_vpi : phba->max_vports;
  3932. } else
  3933. phba->max_vpi = 0;
  3934. phba->fips_level = 0;
  3935. phba->fips_spec_rev = 0;
  3936. if (pmb->u.mb.un.varCfgPort.gdss) {
  3937. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3938. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3939. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3940. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3941. "2850 Security Crypto Active. FIPS x%d "
  3942. "(Spec Rev: x%d)",
  3943. phba->fips_level, phba->fips_spec_rev);
  3944. }
  3945. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3946. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3947. "2856 Config Port Security Crypto "
  3948. "Error: x%x ",
  3949. pmb->u.mb.un.varCfgPort.sec_err);
  3950. }
  3951. if (pmb->u.mb.un.varCfgPort.gerbm)
  3952. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3953. if (pmb->u.mb.un.varCfgPort.gcrp)
  3954. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3955. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3956. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3957. if (phba->cfg_enable_bg) {
  3958. if (pmb->u.mb.un.varCfgPort.gbg)
  3959. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3960. else
  3961. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3962. "0443 Adapter did not grant "
  3963. "BlockGuard\n");
  3964. }
  3965. } else {
  3966. phba->hbq_get = NULL;
  3967. phba->port_gp = phba->mbox->us.s2.port;
  3968. phba->max_vpi = 0;
  3969. }
  3970. do_prep_failed:
  3971. mempool_free(pmb, phba->mbox_mem_pool);
  3972. return rc;
  3973. }
  3974. /**
  3975. * lpfc_sli_hba_setup - SLI intialization function
  3976. * @phba: Pointer to HBA context object.
  3977. *
  3978. * This function is the main SLI intialization function. This function
  3979. * is called by the HBA intialization code, HBA reset code and HBA
  3980. * error attention handler code. Caller is not required to hold any
  3981. * locks. This function issues config_port mailbox command to configure
  3982. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3983. * calls the config_port_post function to issue init_link mailbox
  3984. * command and to start the discovery. The function will return zero
  3985. * if successful, else it will return negative error code.
  3986. **/
  3987. int
  3988. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3989. {
  3990. uint32_t rc;
  3991. int mode = 3;
  3992. switch (lpfc_sli_mode) {
  3993. case 2:
  3994. if (phba->cfg_enable_npiv) {
  3995. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3996. "1824 NPIV enabled: Override lpfc_sli_mode "
  3997. "parameter (%d) to auto (0).\n",
  3998. lpfc_sli_mode);
  3999. break;
  4000. }
  4001. mode = 2;
  4002. break;
  4003. case 0:
  4004. case 3:
  4005. break;
  4006. default:
  4007. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4008. "1819 Unrecognized lpfc_sli_mode "
  4009. "parameter: %d.\n", lpfc_sli_mode);
  4010. break;
  4011. }
  4012. rc = lpfc_sli_config_port(phba, mode);
  4013. if (rc && lpfc_sli_mode == 3)
  4014. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4015. "1820 Unable to select SLI-3. "
  4016. "Not supported by adapter.\n");
  4017. if (rc && mode != 2)
  4018. rc = lpfc_sli_config_port(phba, 2);
  4019. if (rc)
  4020. goto lpfc_sli_hba_setup_error;
  4021. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4022. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4023. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4024. if (!rc) {
  4025. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4026. "2709 This device supports "
  4027. "Advanced Error Reporting (AER)\n");
  4028. spin_lock_irq(&phba->hbalock);
  4029. phba->hba_flag |= HBA_AER_ENABLED;
  4030. spin_unlock_irq(&phba->hbalock);
  4031. } else {
  4032. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4033. "2708 This device does not support "
  4034. "Advanced Error Reporting (AER)\n");
  4035. phba->cfg_aer_support = 0;
  4036. }
  4037. }
  4038. if (phba->sli_rev == 3) {
  4039. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4040. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4041. } else {
  4042. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4043. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4044. phba->sli3_options = 0;
  4045. }
  4046. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4047. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4048. phba->sli_rev, phba->max_vpi);
  4049. rc = lpfc_sli_ring_map(phba);
  4050. if (rc)
  4051. goto lpfc_sli_hba_setup_error;
  4052. /* Init HBQs */
  4053. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4054. rc = lpfc_sli_hbq_setup(phba);
  4055. if (rc)
  4056. goto lpfc_sli_hba_setup_error;
  4057. }
  4058. spin_lock_irq(&phba->hbalock);
  4059. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4060. spin_unlock_irq(&phba->hbalock);
  4061. rc = lpfc_config_port_post(phba);
  4062. if (rc)
  4063. goto lpfc_sli_hba_setup_error;
  4064. return rc;
  4065. lpfc_sli_hba_setup_error:
  4066. phba->link_state = LPFC_HBA_ERROR;
  4067. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4068. "0445 Firmware initialization failed\n");
  4069. return rc;
  4070. }
  4071. /**
  4072. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4073. * @phba: Pointer to HBA context object.
  4074. * @mboxq: mailbox pointer.
  4075. * This function issue a dump mailbox command to read config region
  4076. * 23 and parse the records in the region and populate driver
  4077. * data structure.
  4078. **/
  4079. static int
  4080. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  4081. LPFC_MBOXQ_t *mboxq)
  4082. {
  4083. struct lpfc_dmabuf *mp;
  4084. struct lpfc_mqe *mqe;
  4085. uint32_t data_length;
  4086. int rc;
  4087. /* Program the default value of vlan_id and fc_map */
  4088. phba->valid_vlan = 0;
  4089. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4090. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4091. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4092. mqe = &mboxq->u.mqe;
  4093. if (lpfc_dump_fcoe_param(phba, mboxq))
  4094. return -ENOMEM;
  4095. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4096. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4097. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4098. "(%d):2571 Mailbox cmd x%x Status x%x "
  4099. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4100. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4101. "CQ: x%x x%x x%x x%x\n",
  4102. mboxq->vport ? mboxq->vport->vpi : 0,
  4103. bf_get(lpfc_mqe_command, mqe),
  4104. bf_get(lpfc_mqe_status, mqe),
  4105. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4106. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4107. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4108. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4109. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4110. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4111. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4112. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4113. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4114. mboxq->mcqe.word0,
  4115. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4116. mboxq->mcqe.trailer);
  4117. if (rc) {
  4118. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4119. kfree(mp);
  4120. return -EIO;
  4121. }
  4122. data_length = mqe->un.mb_words[5];
  4123. if (data_length > DMP_RGN23_SIZE) {
  4124. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4125. kfree(mp);
  4126. return -EIO;
  4127. }
  4128. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4129. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4130. kfree(mp);
  4131. return 0;
  4132. }
  4133. /**
  4134. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4135. * @phba: pointer to lpfc hba data structure.
  4136. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4137. * @vpd: pointer to the memory to hold resulting port vpd data.
  4138. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4139. * On output, the number of data bytes in @vpd.
  4140. *
  4141. * This routine executes a READ_REV SLI4 mailbox command. In
  4142. * addition, this routine gets the port vpd data.
  4143. *
  4144. * Return codes
  4145. * 0 - successful
  4146. * -ENOMEM - could not allocated memory.
  4147. **/
  4148. static int
  4149. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4150. uint8_t *vpd, uint32_t *vpd_size)
  4151. {
  4152. int rc = 0;
  4153. uint32_t dma_size;
  4154. struct lpfc_dmabuf *dmabuf;
  4155. struct lpfc_mqe *mqe;
  4156. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4157. if (!dmabuf)
  4158. return -ENOMEM;
  4159. /*
  4160. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4161. * mailbox command.
  4162. */
  4163. dma_size = *vpd_size;
  4164. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4165. dma_size,
  4166. &dmabuf->phys,
  4167. GFP_KERNEL);
  4168. if (!dmabuf->virt) {
  4169. kfree(dmabuf);
  4170. return -ENOMEM;
  4171. }
  4172. memset(dmabuf->virt, 0, dma_size);
  4173. /*
  4174. * The SLI4 implementation of READ_REV conflicts at word1,
  4175. * bits 31:16 and SLI4 adds vpd functionality not present
  4176. * in SLI3. This code corrects the conflicts.
  4177. */
  4178. lpfc_read_rev(phba, mboxq);
  4179. mqe = &mboxq->u.mqe;
  4180. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4181. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4182. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4183. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4184. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4185. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4186. if (rc) {
  4187. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4188. dmabuf->virt, dmabuf->phys);
  4189. kfree(dmabuf);
  4190. return -EIO;
  4191. }
  4192. /*
  4193. * The available vpd length cannot be bigger than the
  4194. * DMA buffer passed to the port. Catch the less than
  4195. * case and update the caller's size.
  4196. */
  4197. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4198. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4199. memcpy(vpd, dmabuf->virt, *vpd_size);
  4200. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4201. dmabuf->virt, dmabuf->phys);
  4202. kfree(dmabuf);
  4203. return 0;
  4204. }
  4205. /**
  4206. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4207. * @phba: pointer to lpfc hba data structure.
  4208. *
  4209. * This routine is called to explicitly arm the SLI4 device's completion and
  4210. * event queues
  4211. **/
  4212. static void
  4213. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4214. {
  4215. uint8_t fcp_eqidx;
  4216. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4217. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4218. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4219. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4220. LPFC_QUEUE_REARM);
  4221. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4222. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4223. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4224. LPFC_QUEUE_REARM);
  4225. }
  4226. /**
  4227. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  4228. * @phba: Pointer to HBA context object.
  4229. *
  4230. * This function is the main SLI4 device intialization PCI function. This
  4231. * function is called by the HBA intialization code, HBA reset code and
  4232. * HBA error attention handler code. Caller is not required to hold any
  4233. * locks.
  4234. **/
  4235. int
  4236. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  4237. {
  4238. int rc;
  4239. LPFC_MBOXQ_t *mboxq;
  4240. struct lpfc_mqe *mqe;
  4241. uint8_t *vpd;
  4242. uint32_t vpd_size;
  4243. uint32_t ftr_rsp = 0;
  4244. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  4245. struct lpfc_vport *vport = phba->pport;
  4246. struct lpfc_dmabuf *mp;
  4247. /*
  4248. * TODO: Why does this routine execute these task in a different
  4249. * order from probe?
  4250. */
  4251. /* Perform a PCI function reset to start from clean */
  4252. rc = lpfc_pci_function_reset(phba);
  4253. if (unlikely(rc))
  4254. return -ENODEV;
  4255. /* Check the HBA Host Status Register for readyness */
  4256. rc = lpfc_sli4_post_status_check(phba);
  4257. if (unlikely(rc))
  4258. return -ENODEV;
  4259. else {
  4260. spin_lock_irq(&phba->hbalock);
  4261. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  4262. spin_unlock_irq(&phba->hbalock);
  4263. }
  4264. /*
  4265. * Allocate a single mailbox container for initializing the
  4266. * port.
  4267. */
  4268. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4269. if (!mboxq)
  4270. return -ENOMEM;
  4271. /*
  4272. * Continue initialization with default values even if driver failed
  4273. * to read FCoE param config regions
  4274. */
  4275. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  4276. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4277. "2570 Failed to read FCoE parameters\n");
  4278. /* Issue READ_REV to collect vpd and FW information. */
  4279. vpd_size = SLI4_PAGE_SIZE;
  4280. vpd = kzalloc(vpd_size, GFP_KERNEL);
  4281. if (!vpd) {
  4282. rc = -ENOMEM;
  4283. goto out_free_mbox;
  4284. }
  4285. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  4286. if (unlikely(rc)) {
  4287. kfree(vpd);
  4288. goto out_free_mbox;
  4289. }
  4290. mqe = &mboxq->u.mqe;
  4291. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  4292. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  4293. phba->hba_flag |= HBA_FCOE_MODE;
  4294. else
  4295. phba->hba_flag &= ~HBA_FCOE_MODE;
  4296. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  4297. LPFC_DCBX_CEE_MODE)
  4298. phba->hba_flag |= HBA_FIP_SUPPORT;
  4299. else
  4300. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  4301. if (phba->sli_rev != LPFC_SLI_REV4 ||
  4302. !(phba->hba_flag & HBA_FCOE_MODE)) {
  4303. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4304. "0376 READ_REV Error. SLI Level %d "
  4305. "FCoE enabled %d\n",
  4306. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  4307. rc = -EIO;
  4308. kfree(vpd);
  4309. goto out_free_mbox;
  4310. }
  4311. /*
  4312. * Evaluate the read rev and vpd data. Populate the driver
  4313. * state with the results. If this routine fails, the failure
  4314. * is not fatal as the driver will use generic values.
  4315. */
  4316. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  4317. if (unlikely(!rc)) {
  4318. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4319. "0377 Error %d parsing vpd. "
  4320. "Using defaults.\n", rc);
  4321. rc = 0;
  4322. }
  4323. kfree(vpd);
  4324. /* Save information as VPD data */
  4325. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  4326. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  4327. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  4328. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  4329. &mqe->un.read_rev);
  4330. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  4331. &mqe->un.read_rev);
  4332. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  4333. &mqe->un.read_rev);
  4334. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  4335. &mqe->un.read_rev);
  4336. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  4337. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  4338. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  4339. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  4340. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  4341. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  4342. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4343. "(%d):0380 READ_REV Status x%x "
  4344. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  4345. mboxq->vport ? mboxq->vport->vpi : 0,
  4346. bf_get(lpfc_mqe_status, mqe),
  4347. phba->vpd.rev.opFwName,
  4348. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  4349. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  4350. /*
  4351. * Discover the port's supported feature set and match it against the
  4352. * hosts requests.
  4353. */
  4354. lpfc_request_features(phba, mboxq);
  4355. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4356. if (unlikely(rc)) {
  4357. rc = -EIO;
  4358. goto out_free_mbox;
  4359. }
  4360. /*
  4361. * The port must support FCP initiator mode as this is the
  4362. * only mode running in the host.
  4363. */
  4364. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  4365. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4366. "0378 No support for fcpi mode.\n");
  4367. ftr_rsp++;
  4368. }
  4369. /*
  4370. * If the port cannot support the host's requested features
  4371. * then turn off the global config parameters to disable the
  4372. * feature in the driver. This is not a fatal error.
  4373. */
  4374. if ((phba->cfg_enable_bg) &&
  4375. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4376. ftr_rsp++;
  4377. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4378. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4379. ftr_rsp++;
  4380. if (ftr_rsp) {
  4381. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4382. "0379 Feature Mismatch Data: x%08x %08x "
  4383. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4384. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4385. phba->cfg_enable_npiv, phba->max_vpi);
  4386. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4387. phba->cfg_enable_bg = 0;
  4388. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4389. phba->cfg_enable_npiv = 0;
  4390. }
  4391. /* These SLI3 features are assumed in SLI4 */
  4392. spin_lock_irq(&phba->hbalock);
  4393. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4394. spin_unlock_irq(&phba->hbalock);
  4395. /* Read the port's service parameters. */
  4396. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4397. if (rc) {
  4398. phba->link_state = LPFC_HBA_ERROR;
  4399. rc = -ENOMEM;
  4400. goto out_free_mbox;
  4401. }
  4402. mboxq->vport = vport;
  4403. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4404. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4405. if (rc == MBX_SUCCESS) {
  4406. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4407. rc = 0;
  4408. }
  4409. /*
  4410. * This memory was allocated by the lpfc_read_sparam routine. Release
  4411. * it to the mbuf pool.
  4412. */
  4413. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4414. kfree(mp);
  4415. mboxq->context1 = NULL;
  4416. if (unlikely(rc)) {
  4417. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4418. "0382 READ_SPARAM command failed "
  4419. "status %d, mbxStatus x%x\n",
  4420. rc, bf_get(lpfc_mqe_status, mqe));
  4421. phba->link_state = LPFC_HBA_ERROR;
  4422. rc = -EIO;
  4423. goto out_free_mbox;
  4424. }
  4425. if (phba->cfg_soft_wwnn)
  4426. u64_to_wwn(phba->cfg_soft_wwnn,
  4427. vport->fc_sparam.nodeName.u.wwn);
  4428. if (phba->cfg_soft_wwpn)
  4429. u64_to_wwn(phba->cfg_soft_wwpn,
  4430. vport->fc_sparam.portName.u.wwn);
  4431. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4432. sizeof(struct lpfc_name));
  4433. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4434. sizeof(struct lpfc_name));
  4435. /* Update the fc_host data structures with new wwn. */
  4436. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4437. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4438. /* Register SGL pool to the device using non-embedded mailbox command */
  4439. rc = lpfc_sli4_post_sgl_list(phba);
  4440. if (unlikely(rc)) {
  4441. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4442. "0582 Error %d during sgl post operation\n",
  4443. rc);
  4444. rc = -ENODEV;
  4445. goto out_free_mbox;
  4446. }
  4447. /* Register SCSI SGL pool to the device */
  4448. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4449. if (unlikely(rc)) {
  4450. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4451. "0383 Error %d during scsi sgl post "
  4452. "operation\n", rc);
  4453. /* Some Scsi buffers were moved to the abort scsi list */
  4454. /* A pci function reset will repost them */
  4455. rc = -ENODEV;
  4456. goto out_free_mbox;
  4457. }
  4458. /* Post the rpi header region to the device. */
  4459. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4460. if (unlikely(rc)) {
  4461. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4462. "0393 Error %d during rpi post operation\n",
  4463. rc);
  4464. rc = -ENODEV;
  4465. goto out_free_mbox;
  4466. }
  4467. /* Set up all the queues to the device */
  4468. rc = lpfc_sli4_queue_setup(phba);
  4469. if (unlikely(rc)) {
  4470. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4471. "0381 Error %d during queue setup.\n ", rc);
  4472. goto out_stop_timers;
  4473. }
  4474. /* Arm the CQs and then EQs on device */
  4475. lpfc_sli4_arm_cqeq_intr(phba);
  4476. /* Indicate device interrupt mode */
  4477. phba->sli4_hba.intr_enable = 1;
  4478. /* Allow asynchronous mailbox command to go through */
  4479. spin_lock_irq(&phba->hbalock);
  4480. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4481. spin_unlock_irq(&phba->hbalock);
  4482. /* Post receive buffers to the device */
  4483. lpfc_sli4_rb_setup(phba);
  4484. /* Reset HBA FCF states after HBA reset */
  4485. phba->fcf.fcf_flag = 0;
  4486. phba->fcf.current_rec.flag = 0;
  4487. /* Start the ELS watchdog timer */
  4488. mod_timer(&vport->els_tmofunc,
  4489. jiffies + HZ * (phba->fc_ratov * 2));
  4490. /* Start heart beat timer */
  4491. mod_timer(&phba->hb_tmofunc,
  4492. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4493. phba->hb_outstanding = 0;
  4494. phba->last_completion_time = jiffies;
  4495. /* Start error attention (ERATT) polling timer */
  4496. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4497. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4498. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4499. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4500. if (!rc) {
  4501. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4502. "2829 This device supports "
  4503. "Advanced Error Reporting (AER)\n");
  4504. spin_lock_irq(&phba->hbalock);
  4505. phba->hba_flag |= HBA_AER_ENABLED;
  4506. spin_unlock_irq(&phba->hbalock);
  4507. } else {
  4508. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4509. "2830 This device does not support "
  4510. "Advanced Error Reporting (AER)\n");
  4511. phba->cfg_aer_support = 0;
  4512. }
  4513. }
  4514. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  4515. /*
  4516. * The FC Port needs to register FCFI (index 0)
  4517. */
  4518. lpfc_reg_fcfi(phba, mboxq);
  4519. mboxq->vport = phba->pport;
  4520. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4521. if (rc == MBX_SUCCESS)
  4522. rc = 0;
  4523. else
  4524. goto out_unset_queue;
  4525. }
  4526. /*
  4527. * The port is ready, set the host's link state to LINK_DOWN
  4528. * in preparation for link interrupts.
  4529. */
  4530. spin_lock_irq(&phba->hbalock);
  4531. phba->link_state = LPFC_LINK_DOWN;
  4532. spin_unlock_irq(&phba->hbalock);
  4533. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  4534. out_unset_queue:
  4535. /* Unset all the queues set up in this routine when error out */
  4536. if (rc)
  4537. lpfc_sli4_queue_unset(phba);
  4538. out_stop_timers:
  4539. if (rc)
  4540. lpfc_stop_hba_timers(phba);
  4541. out_free_mbox:
  4542. mempool_free(mboxq, phba->mbox_mem_pool);
  4543. return rc;
  4544. }
  4545. /**
  4546. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4547. * @ptr: context object - pointer to hba structure.
  4548. *
  4549. * This is the callback function for mailbox timer. The mailbox
  4550. * timer is armed when a new mailbox command is issued and the timer
  4551. * is deleted when the mailbox complete. The function is called by
  4552. * the kernel timer code when a mailbox does not complete within
  4553. * expected time. This function wakes up the worker thread to
  4554. * process the mailbox timeout and returns. All the processing is
  4555. * done by the worker thread function lpfc_mbox_timeout_handler.
  4556. **/
  4557. void
  4558. lpfc_mbox_timeout(unsigned long ptr)
  4559. {
  4560. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4561. unsigned long iflag;
  4562. uint32_t tmo_posted;
  4563. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4564. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4565. if (!tmo_posted)
  4566. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4567. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4568. if (!tmo_posted)
  4569. lpfc_worker_wake_up(phba);
  4570. return;
  4571. }
  4572. /**
  4573. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4574. * @phba: Pointer to HBA context object.
  4575. *
  4576. * This function is called from worker thread when a mailbox command times out.
  4577. * The caller is not required to hold any locks. This function will reset the
  4578. * HBA and recover all the pending commands.
  4579. **/
  4580. void
  4581. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4582. {
  4583. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4584. MAILBOX_t *mb = &pmbox->u.mb;
  4585. struct lpfc_sli *psli = &phba->sli;
  4586. struct lpfc_sli_ring *pring;
  4587. /* Check the pmbox pointer first. There is a race condition
  4588. * between the mbox timeout handler getting executed in the
  4589. * worklist and the mailbox actually completing. When this
  4590. * race condition occurs, the mbox_active will be NULL.
  4591. */
  4592. spin_lock_irq(&phba->hbalock);
  4593. if (pmbox == NULL) {
  4594. lpfc_printf_log(phba, KERN_WARNING,
  4595. LOG_MBOX | LOG_SLI,
  4596. "0353 Active Mailbox cleared - mailbox timeout "
  4597. "exiting\n");
  4598. spin_unlock_irq(&phba->hbalock);
  4599. return;
  4600. }
  4601. /* Mbox cmd <mbxCommand> timeout */
  4602. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4603. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4604. mb->mbxCommand,
  4605. phba->pport->port_state,
  4606. phba->sli.sli_flag,
  4607. phba->sli.mbox_active);
  4608. spin_unlock_irq(&phba->hbalock);
  4609. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4610. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4611. * it to fail all oustanding SCSI IO.
  4612. */
  4613. spin_lock_irq(&phba->pport->work_port_lock);
  4614. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4615. spin_unlock_irq(&phba->pport->work_port_lock);
  4616. spin_lock_irq(&phba->hbalock);
  4617. phba->link_state = LPFC_LINK_UNKNOWN;
  4618. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4619. spin_unlock_irq(&phba->hbalock);
  4620. pring = &psli->ring[psli->fcp_ring];
  4621. lpfc_sli_abort_iocb_ring(phba, pring);
  4622. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4623. "0345 Resetting board due to mailbox timeout\n");
  4624. /* Reset the HBA device */
  4625. lpfc_reset_hba(phba);
  4626. }
  4627. /**
  4628. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4629. * @phba: Pointer to HBA context object.
  4630. * @pmbox: Pointer to mailbox object.
  4631. * @flag: Flag indicating how the mailbox need to be processed.
  4632. *
  4633. * This function is called by discovery code and HBA management code
  4634. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4635. * function gets the hbalock to protect the data structures.
  4636. * The mailbox command can be submitted in polling mode, in which case
  4637. * this function will wait in a polling loop for the completion of the
  4638. * mailbox.
  4639. * If the mailbox is submitted in no_wait mode (not polling) the
  4640. * function will submit the command and returns immediately without waiting
  4641. * for the mailbox completion. The no_wait is supported only when HBA
  4642. * is in SLI2/SLI3 mode - interrupts are enabled.
  4643. * The SLI interface allows only one mailbox pending at a time. If the
  4644. * mailbox is issued in polling mode and there is already a mailbox
  4645. * pending, then the function will return an error. If the mailbox is issued
  4646. * in NO_WAIT mode and there is a mailbox pending already, the function
  4647. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4648. * The sli layer owns the mailbox object until the completion of mailbox
  4649. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4650. * return codes the caller owns the mailbox command after the return of
  4651. * the function.
  4652. **/
  4653. static int
  4654. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4655. uint32_t flag)
  4656. {
  4657. MAILBOX_t *mb;
  4658. struct lpfc_sli *psli = &phba->sli;
  4659. uint32_t status, evtctr;
  4660. uint32_t ha_copy;
  4661. int i;
  4662. unsigned long timeout;
  4663. unsigned long drvr_flag = 0;
  4664. uint32_t word0, ldata;
  4665. void __iomem *to_slim;
  4666. int processing_queue = 0;
  4667. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4668. if (!pmbox) {
  4669. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4670. /* processing mbox queue from intr_handler */
  4671. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4672. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4673. return MBX_SUCCESS;
  4674. }
  4675. processing_queue = 1;
  4676. pmbox = lpfc_mbox_get(phba);
  4677. if (!pmbox) {
  4678. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4679. return MBX_SUCCESS;
  4680. }
  4681. }
  4682. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4683. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4684. if(!pmbox->vport) {
  4685. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4686. lpfc_printf_log(phba, KERN_ERR,
  4687. LOG_MBOX | LOG_VPORT,
  4688. "1806 Mbox x%x failed. No vport\n",
  4689. pmbox->u.mb.mbxCommand);
  4690. dump_stack();
  4691. goto out_not_finished;
  4692. }
  4693. }
  4694. /* If the PCI channel is in offline state, do not post mbox. */
  4695. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4696. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4697. goto out_not_finished;
  4698. }
  4699. /* If HBA has a deferred error attention, fail the iocb. */
  4700. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4701. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4702. goto out_not_finished;
  4703. }
  4704. psli = &phba->sli;
  4705. mb = &pmbox->u.mb;
  4706. status = MBX_SUCCESS;
  4707. if (phba->link_state == LPFC_HBA_ERROR) {
  4708. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4709. /* Mbox command <mbxCommand> cannot issue */
  4710. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4711. "(%d):0311 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 (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4718. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4719. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4720. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4721. "(%d):2528 Mailbox command x%x cannot "
  4722. "issue Data: x%x x%x\n",
  4723. pmbox->vport ? pmbox->vport->vpi : 0,
  4724. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4725. goto out_not_finished;
  4726. }
  4727. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4728. /* Polling for a mbox command when another one is already active
  4729. * is not allowed in SLI. Also, the driver must have established
  4730. * SLI2 mode to queue and process multiple mbox commands.
  4731. */
  4732. if (flag & MBX_POLL) {
  4733. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4734. /* Mbox command <mbxCommand> cannot issue */
  4735. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4736. "(%d):2529 Mailbox command x%x "
  4737. "cannot issue Data: x%x x%x\n",
  4738. pmbox->vport ? pmbox->vport->vpi : 0,
  4739. pmbox->u.mb.mbxCommand,
  4740. psli->sli_flag, flag);
  4741. goto out_not_finished;
  4742. }
  4743. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4744. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4745. /* Mbox command <mbxCommand> cannot issue */
  4746. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4747. "(%d):2530 Mailbox command x%x "
  4748. "cannot issue Data: x%x x%x\n",
  4749. pmbox->vport ? pmbox->vport->vpi : 0,
  4750. pmbox->u.mb.mbxCommand,
  4751. psli->sli_flag, flag);
  4752. goto out_not_finished;
  4753. }
  4754. /* Another mailbox command is still being processed, queue this
  4755. * command to be processed later.
  4756. */
  4757. lpfc_mbox_put(phba, pmbox);
  4758. /* Mbox cmd issue - BUSY */
  4759. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4760. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4761. "x%x x%x x%x x%x\n",
  4762. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4763. mb->mbxCommand, phba->pport->port_state,
  4764. psli->sli_flag, flag);
  4765. psli->slistat.mbox_busy++;
  4766. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4767. if (pmbox->vport) {
  4768. lpfc_debugfs_disc_trc(pmbox->vport,
  4769. LPFC_DISC_TRC_MBOX_VPORT,
  4770. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4771. (uint32_t)mb->mbxCommand,
  4772. mb->un.varWords[0], mb->un.varWords[1]);
  4773. }
  4774. else {
  4775. lpfc_debugfs_disc_trc(phba->pport,
  4776. LPFC_DISC_TRC_MBOX,
  4777. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4778. (uint32_t)mb->mbxCommand,
  4779. mb->un.varWords[0], mb->un.varWords[1]);
  4780. }
  4781. return MBX_BUSY;
  4782. }
  4783. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4784. /* If we are not polling, we MUST be in SLI2 mode */
  4785. if (flag != MBX_POLL) {
  4786. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4787. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4788. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4789. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4790. /* Mbox command <mbxCommand> cannot issue */
  4791. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4792. "(%d):2531 Mailbox command x%x "
  4793. "cannot issue Data: x%x x%x\n",
  4794. pmbox->vport ? pmbox->vport->vpi : 0,
  4795. pmbox->u.mb.mbxCommand,
  4796. psli->sli_flag, flag);
  4797. goto out_not_finished;
  4798. }
  4799. /* timeout active mbox command */
  4800. mod_timer(&psli->mbox_tmo, (jiffies +
  4801. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4802. }
  4803. /* Mailbox cmd <cmd> issue */
  4804. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4805. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4806. "x%x\n",
  4807. pmbox->vport ? pmbox->vport->vpi : 0,
  4808. mb->mbxCommand, phba->pport->port_state,
  4809. psli->sli_flag, flag);
  4810. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4811. if (pmbox->vport) {
  4812. lpfc_debugfs_disc_trc(pmbox->vport,
  4813. LPFC_DISC_TRC_MBOX_VPORT,
  4814. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4815. (uint32_t)mb->mbxCommand,
  4816. mb->un.varWords[0], mb->un.varWords[1]);
  4817. }
  4818. else {
  4819. lpfc_debugfs_disc_trc(phba->pport,
  4820. LPFC_DISC_TRC_MBOX,
  4821. "MBOX Send: cmd:x%x mb:x%x x%x",
  4822. (uint32_t)mb->mbxCommand,
  4823. mb->un.varWords[0], mb->un.varWords[1]);
  4824. }
  4825. }
  4826. psli->slistat.mbox_cmd++;
  4827. evtctr = psli->slistat.mbox_event;
  4828. /* next set own bit for the adapter and copy over command word */
  4829. mb->mbxOwner = OWN_CHIP;
  4830. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4831. /* Populate mbox extension offset word. */
  4832. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4833. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4834. = (uint8_t *)phba->mbox_ext
  4835. - (uint8_t *)phba->mbox;
  4836. }
  4837. /* Copy the mailbox extension data */
  4838. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4839. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4840. (uint8_t *)phba->mbox_ext,
  4841. pmbox->in_ext_byte_len);
  4842. }
  4843. /* Copy command data to host SLIM area */
  4844. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4845. } else {
  4846. /* Populate mbox extension offset word. */
  4847. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4848. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4849. = MAILBOX_HBA_EXT_OFFSET;
  4850. /* Copy the mailbox extension data */
  4851. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4852. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4853. MAILBOX_HBA_EXT_OFFSET,
  4854. pmbox->context2, pmbox->in_ext_byte_len);
  4855. }
  4856. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4857. /* copy command data into host mbox for cmpl */
  4858. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4859. }
  4860. /* First copy mbox command data to HBA SLIM, skip past first
  4861. word */
  4862. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4863. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4864. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4865. /* Next copy over first word, with mbxOwner set */
  4866. ldata = *((uint32_t *)mb);
  4867. to_slim = phba->MBslimaddr;
  4868. writel(ldata, to_slim);
  4869. readl(to_slim); /* flush */
  4870. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4871. /* switch over to host mailbox */
  4872. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4873. }
  4874. }
  4875. wmb();
  4876. switch (flag) {
  4877. case MBX_NOWAIT:
  4878. /* Set up reference to mailbox command */
  4879. psli->mbox_active = pmbox;
  4880. /* Interrupt board to do it */
  4881. writel(CA_MBATT, phba->CAregaddr);
  4882. readl(phba->CAregaddr); /* flush */
  4883. /* Don't wait for it to finish, just return */
  4884. break;
  4885. case MBX_POLL:
  4886. /* Set up null reference to mailbox command */
  4887. psli->mbox_active = NULL;
  4888. /* Interrupt board to do it */
  4889. writel(CA_MBATT, phba->CAregaddr);
  4890. readl(phba->CAregaddr); /* flush */
  4891. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4892. /* First read mbox status word */
  4893. word0 = *((uint32_t *)phba->mbox);
  4894. word0 = le32_to_cpu(word0);
  4895. } else {
  4896. /* First read mbox status word */
  4897. word0 = readl(phba->MBslimaddr);
  4898. }
  4899. /* Read the HBA Host Attention Register */
  4900. ha_copy = readl(phba->HAregaddr);
  4901. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4902. mb->mbxCommand) *
  4903. 1000) + jiffies;
  4904. i = 0;
  4905. /* Wait for command to complete */
  4906. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4907. (!(ha_copy & HA_MBATT) &&
  4908. (phba->link_state > LPFC_WARM_START))) {
  4909. if (time_after(jiffies, timeout)) {
  4910. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4911. spin_unlock_irqrestore(&phba->hbalock,
  4912. drvr_flag);
  4913. goto out_not_finished;
  4914. }
  4915. /* Check if we took a mbox interrupt while we were
  4916. polling */
  4917. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4918. && (evtctr != psli->slistat.mbox_event))
  4919. break;
  4920. if (i++ > 10) {
  4921. spin_unlock_irqrestore(&phba->hbalock,
  4922. drvr_flag);
  4923. msleep(1);
  4924. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4925. }
  4926. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4927. /* First copy command data */
  4928. word0 = *((uint32_t *)phba->mbox);
  4929. word0 = le32_to_cpu(word0);
  4930. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4931. MAILBOX_t *slimmb;
  4932. uint32_t slimword0;
  4933. /* Check real SLIM for any errors */
  4934. slimword0 = readl(phba->MBslimaddr);
  4935. slimmb = (MAILBOX_t *) & slimword0;
  4936. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4937. && slimmb->mbxStatus) {
  4938. psli->sli_flag &=
  4939. ~LPFC_SLI_ACTIVE;
  4940. word0 = slimword0;
  4941. }
  4942. }
  4943. } else {
  4944. /* First copy command data */
  4945. word0 = readl(phba->MBslimaddr);
  4946. }
  4947. /* Read the HBA Host Attention Register */
  4948. ha_copy = readl(phba->HAregaddr);
  4949. }
  4950. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4951. /* copy results back to user */
  4952. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4953. /* Copy the mailbox extension data */
  4954. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4955. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4956. pmbox->context2,
  4957. pmbox->out_ext_byte_len);
  4958. }
  4959. } else {
  4960. /* First copy command data */
  4961. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4962. MAILBOX_CMD_SIZE);
  4963. /* Copy the mailbox extension data */
  4964. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4965. lpfc_memcpy_from_slim(pmbox->context2,
  4966. phba->MBslimaddr +
  4967. MAILBOX_HBA_EXT_OFFSET,
  4968. pmbox->out_ext_byte_len);
  4969. }
  4970. }
  4971. writel(HA_MBATT, phba->HAregaddr);
  4972. readl(phba->HAregaddr); /* flush */
  4973. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4974. status = mb->mbxStatus;
  4975. }
  4976. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4977. return status;
  4978. out_not_finished:
  4979. if (processing_queue) {
  4980. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4981. lpfc_mbox_cmpl_put(phba, pmbox);
  4982. }
  4983. return MBX_NOT_FINISHED;
  4984. }
  4985. /**
  4986. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4987. * @phba: Pointer to HBA context object.
  4988. *
  4989. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4990. * the driver internal pending mailbox queue. It will then try to wait out the
  4991. * possible outstanding mailbox command before return.
  4992. *
  4993. * Returns:
  4994. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4995. * the outstanding mailbox command timed out.
  4996. **/
  4997. static int
  4998. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4999. {
  5000. struct lpfc_sli *psli = &phba->sli;
  5001. uint8_t actcmd = MBX_HEARTBEAT;
  5002. int rc = 0;
  5003. unsigned long timeout;
  5004. /* Mark the asynchronous mailbox command posting as blocked */
  5005. spin_lock_irq(&phba->hbalock);
  5006. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  5007. if (phba->sli.mbox_active)
  5008. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  5009. spin_unlock_irq(&phba->hbalock);
  5010. /* Determine how long we might wait for the active mailbox
  5011. * command to be gracefully completed by firmware.
  5012. */
  5013. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  5014. jiffies;
  5015. /* Wait for the outstnading mailbox command to complete */
  5016. while (phba->sli.mbox_active) {
  5017. /* Check active mailbox complete status every 2ms */
  5018. msleep(2);
  5019. if (time_after(jiffies, timeout)) {
  5020. /* Timeout, marked the outstanding cmd not complete */
  5021. rc = 1;
  5022. break;
  5023. }
  5024. }
  5025. /* Can not cleanly block async mailbox command, fails it */
  5026. if (rc) {
  5027. spin_lock_irq(&phba->hbalock);
  5028. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5029. spin_unlock_irq(&phba->hbalock);
  5030. }
  5031. return rc;
  5032. }
  5033. /**
  5034. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  5035. * @phba: Pointer to HBA context object.
  5036. *
  5037. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  5038. * commands from the driver internal pending mailbox queue. It makes sure
  5039. * that there is no outstanding mailbox command before resuming posting
  5040. * asynchronous mailbox commands. If, for any reason, there is outstanding
  5041. * mailbox command, it will try to wait it out before resuming asynchronous
  5042. * mailbox command posting.
  5043. **/
  5044. static void
  5045. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  5046. {
  5047. struct lpfc_sli *psli = &phba->sli;
  5048. spin_lock_irq(&phba->hbalock);
  5049. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5050. /* Asynchronous mailbox posting is not blocked, do nothing */
  5051. spin_unlock_irq(&phba->hbalock);
  5052. return;
  5053. }
  5054. /* Outstanding synchronous mailbox command is guaranteed to be done,
  5055. * successful or timeout, after timing-out the outstanding mailbox
  5056. * command shall always be removed, so just unblock posting async
  5057. * mailbox command and resume
  5058. */
  5059. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5060. spin_unlock_irq(&phba->hbalock);
  5061. /* wake up worker thread to post asynchronlous mailbox command */
  5062. lpfc_worker_wake_up(phba);
  5063. }
  5064. /**
  5065. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  5066. * @phba: Pointer to HBA context object.
  5067. * @mboxq: Pointer to mailbox object.
  5068. *
  5069. * The function posts a mailbox to the port. The mailbox is expected
  5070. * to be comletely filled in and ready for the port to operate on it.
  5071. * This routine executes a synchronous completion operation on the
  5072. * mailbox by polling for its completion.
  5073. *
  5074. * The caller must not be holding any locks when calling this routine.
  5075. *
  5076. * Returns:
  5077. * MBX_SUCCESS - mailbox posted successfully
  5078. * Any of the MBX error values.
  5079. **/
  5080. static int
  5081. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5082. {
  5083. int rc = MBX_SUCCESS;
  5084. unsigned long iflag;
  5085. uint32_t db_ready;
  5086. uint32_t mcqe_status;
  5087. uint32_t mbx_cmnd;
  5088. unsigned long timeout;
  5089. struct lpfc_sli *psli = &phba->sli;
  5090. struct lpfc_mqe *mb = &mboxq->u.mqe;
  5091. struct lpfc_bmbx_create *mbox_rgn;
  5092. struct dma_address *dma_address;
  5093. struct lpfc_register bmbx_reg;
  5094. /*
  5095. * Only one mailbox can be active to the bootstrap mailbox region
  5096. * at a time and there is no queueing provided.
  5097. */
  5098. spin_lock_irqsave(&phba->hbalock, iflag);
  5099. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5100. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5101. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5102. "(%d):2532 Mailbox command x%x (x%x) "
  5103. "cannot issue Data: x%x x%x\n",
  5104. mboxq->vport ? mboxq->vport->vpi : 0,
  5105. mboxq->u.mb.mbxCommand,
  5106. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5107. psli->sli_flag, MBX_POLL);
  5108. return MBXERR_ERROR;
  5109. }
  5110. /* The server grabs the token and owns it until release */
  5111. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5112. phba->sli.mbox_active = mboxq;
  5113. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5114. /*
  5115. * Initialize the bootstrap memory region to avoid stale data areas
  5116. * in the mailbox post. Then copy the caller's mailbox contents to
  5117. * the bmbx mailbox region.
  5118. */
  5119. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  5120. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  5121. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  5122. sizeof(struct lpfc_mqe));
  5123. /* Post the high mailbox dma address to the port and wait for ready. */
  5124. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5125. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  5126. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5127. * 1000) + jiffies;
  5128. do {
  5129. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5130. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5131. if (!db_ready)
  5132. msleep(2);
  5133. if (time_after(jiffies, timeout)) {
  5134. rc = MBXERR_ERROR;
  5135. goto exit;
  5136. }
  5137. } while (!db_ready);
  5138. /* Post the low mailbox dma address to the port. */
  5139. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  5140. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5141. * 1000) + jiffies;
  5142. do {
  5143. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5144. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5145. if (!db_ready)
  5146. msleep(2);
  5147. if (time_after(jiffies, timeout)) {
  5148. rc = MBXERR_ERROR;
  5149. goto exit;
  5150. }
  5151. } while (!db_ready);
  5152. /*
  5153. * Read the CQ to ensure the mailbox has completed.
  5154. * If so, update the mailbox status so that the upper layers
  5155. * can complete the request normally.
  5156. */
  5157. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  5158. sizeof(struct lpfc_mqe));
  5159. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  5160. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  5161. sizeof(struct lpfc_mcqe));
  5162. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  5163. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  5164. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  5165. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  5166. rc = MBXERR_ERROR;
  5167. } else
  5168. lpfc_sli4_swap_str(phba, mboxq);
  5169. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5170. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  5171. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  5172. " x%x x%x CQ: x%x x%x x%x x%x\n",
  5173. mboxq->vport ? mboxq->vport->vpi : 0,
  5174. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5175. bf_get(lpfc_mqe_status, mb),
  5176. mb->un.mb_words[0], mb->un.mb_words[1],
  5177. mb->un.mb_words[2], mb->un.mb_words[3],
  5178. mb->un.mb_words[4], mb->un.mb_words[5],
  5179. mb->un.mb_words[6], mb->un.mb_words[7],
  5180. mb->un.mb_words[8], mb->un.mb_words[9],
  5181. mb->un.mb_words[10], mb->un.mb_words[11],
  5182. mb->un.mb_words[12], mboxq->mcqe.word0,
  5183. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  5184. mboxq->mcqe.trailer);
  5185. exit:
  5186. /* We are holding the token, no needed for lock when release */
  5187. spin_lock_irqsave(&phba->hbalock, iflag);
  5188. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5189. phba->sli.mbox_active = NULL;
  5190. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5191. return rc;
  5192. }
  5193. /**
  5194. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  5195. * @phba: Pointer to HBA context object.
  5196. * @pmbox: Pointer to mailbox object.
  5197. * @flag: Flag indicating how the mailbox need to be processed.
  5198. *
  5199. * This function is called by discovery code and HBA management code to submit
  5200. * a mailbox command to firmware with SLI-4 interface spec.
  5201. *
  5202. * Return codes the caller owns the mailbox command after the return of the
  5203. * function.
  5204. **/
  5205. static int
  5206. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  5207. uint32_t flag)
  5208. {
  5209. struct lpfc_sli *psli = &phba->sli;
  5210. unsigned long iflags;
  5211. int rc;
  5212. rc = lpfc_mbox_dev_check(phba);
  5213. if (unlikely(rc)) {
  5214. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5215. "(%d):2544 Mailbox command x%x (x%x) "
  5216. "cannot issue Data: x%x x%x\n",
  5217. mboxq->vport ? mboxq->vport->vpi : 0,
  5218. mboxq->u.mb.mbxCommand,
  5219. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5220. psli->sli_flag, flag);
  5221. goto out_not_finished;
  5222. }
  5223. /* Detect polling mode and jump to a handler */
  5224. if (!phba->sli4_hba.intr_enable) {
  5225. if (flag == MBX_POLL)
  5226. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5227. else
  5228. rc = -EIO;
  5229. if (rc != MBX_SUCCESS)
  5230. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5231. "(%d):2541 Mailbox command x%x "
  5232. "(x%x) cannot issue Data: 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. return rc;
  5238. } else if (flag == MBX_POLL) {
  5239. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5240. "(%d):2542 Try to issue mailbox command "
  5241. "x%x (x%x) synchronously ahead of async"
  5242. "mailbox command queue: x%x x%x\n",
  5243. mboxq->vport ? mboxq->vport->vpi : 0,
  5244. mboxq->u.mb.mbxCommand,
  5245. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5246. psli->sli_flag, flag);
  5247. /* Try to block the asynchronous mailbox posting */
  5248. rc = lpfc_sli4_async_mbox_block(phba);
  5249. if (!rc) {
  5250. /* Successfully blocked, now issue sync mbox cmd */
  5251. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5252. if (rc != MBX_SUCCESS)
  5253. lpfc_printf_log(phba, KERN_ERR,
  5254. LOG_MBOX | LOG_SLI,
  5255. "(%d):2597 Mailbox command "
  5256. "x%x (x%x) cannot issue "
  5257. "Data: x%x x%x\n",
  5258. mboxq->vport ?
  5259. mboxq->vport->vpi : 0,
  5260. mboxq->u.mb.mbxCommand,
  5261. lpfc_sli4_mbox_opcode_get(phba,
  5262. mboxq),
  5263. psli->sli_flag, flag);
  5264. /* Unblock the async mailbox posting afterward */
  5265. lpfc_sli4_async_mbox_unblock(phba);
  5266. }
  5267. return rc;
  5268. }
  5269. /* Now, interrupt mode asynchrous mailbox command */
  5270. rc = lpfc_mbox_cmd_check(phba, mboxq);
  5271. if (rc) {
  5272. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5273. "(%d):2543 Mailbox command x%x (x%x) "
  5274. "cannot issue Data: x%x x%x\n",
  5275. mboxq->vport ? mboxq->vport->vpi : 0,
  5276. mboxq->u.mb.mbxCommand,
  5277. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5278. psli->sli_flag, flag);
  5279. goto out_not_finished;
  5280. }
  5281. /* Put the mailbox command to the driver internal FIFO */
  5282. psli->slistat.mbox_busy++;
  5283. spin_lock_irqsave(&phba->hbalock, iflags);
  5284. lpfc_mbox_put(phba, mboxq);
  5285. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5286. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5287. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  5288. "x%x (x%x) x%x x%x x%x\n",
  5289. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  5290. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  5291. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5292. phba->pport->port_state,
  5293. psli->sli_flag, MBX_NOWAIT);
  5294. /* Wake up worker thread to transport mailbox command from head */
  5295. lpfc_worker_wake_up(phba);
  5296. return MBX_BUSY;
  5297. out_not_finished:
  5298. return MBX_NOT_FINISHED;
  5299. }
  5300. /**
  5301. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  5302. * @phba: Pointer to HBA context object.
  5303. *
  5304. * This function is called by worker thread to send a mailbox command to
  5305. * SLI4 HBA firmware.
  5306. *
  5307. **/
  5308. int
  5309. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  5310. {
  5311. struct lpfc_sli *psli = &phba->sli;
  5312. LPFC_MBOXQ_t *mboxq;
  5313. int rc = MBX_SUCCESS;
  5314. unsigned long iflags;
  5315. struct lpfc_mqe *mqe;
  5316. uint32_t mbx_cmnd;
  5317. /* Check interrupt mode before post async mailbox command */
  5318. if (unlikely(!phba->sli4_hba.intr_enable))
  5319. return MBX_NOT_FINISHED;
  5320. /* Check for mailbox command service token */
  5321. spin_lock_irqsave(&phba->hbalock, iflags);
  5322. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5323. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5324. return MBX_NOT_FINISHED;
  5325. }
  5326. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5327. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5328. return MBX_NOT_FINISHED;
  5329. }
  5330. if (unlikely(phba->sli.mbox_active)) {
  5331. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5332. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5333. "0384 There is pending active mailbox cmd\n");
  5334. return MBX_NOT_FINISHED;
  5335. }
  5336. /* Take the mailbox command service token */
  5337. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5338. /* Get the next mailbox command from head of queue */
  5339. mboxq = lpfc_mbox_get(phba);
  5340. /* If no more mailbox command waiting for post, we're done */
  5341. if (!mboxq) {
  5342. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5343. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5344. return MBX_SUCCESS;
  5345. }
  5346. phba->sli.mbox_active = mboxq;
  5347. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5348. /* Check device readiness for posting mailbox command */
  5349. rc = lpfc_mbox_dev_check(phba);
  5350. if (unlikely(rc))
  5351. /* Driver clean routine will clean up pending mailbox */
  5352. goto out_not_finished;
  5353. /* Prepare the mbox command to be posted */
  5354. mqe = &mboxq->u.mqe;
  5355. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  5356. /* Start timer for the mbox_tmo and log some mailbox post messages */
  5357. mod_timer(&psli->mbox_tmo, (jiffies +
  5358. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  5359. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5360. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  5361. "x%x x%x\n",
  5362. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  5363. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5364. phba->pport->port_state, psli->sli_flag);
  5365. if (mbx_cmnd != MBX_HEARTBEAT) {
  5366. if (mboxq->vport) {
  5367. lpfc_debugfs_disc_trc(mboxq->vport,
  5368. LPFC_DISC_TRC_MBOX_VPORT,
  5369. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5370. mbx_cmnd, mqe->un.mb_words[0],
  5371. mqe->un.mb_words[1]);
  5372. } else {
  5373. lpfc_debugfs_disc_trc(phba->pport,
  5374. LPFC_DISC_TRC_MBOX,
  5375. "MBOX Send: cmd:x%x mb:x%x x%x",
  5376. mbx_cmnd, mqe->un.mb_words[0],
  5377. mqe->un.mb_words[1]);
  5378. }
  5379. }
  5380. psli->slistat.mbox_cmd++;
  5381. /* Post the mailbox command to the port */
  5382. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5383. if (rc != MBX_SUCCESS) {
  5384. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5385. "(%d):2533 Mailbox command x%x (x%x) "
  5386. "cannot issue Data: x%x x%x\n",
  5387. mboxq->vport ? mboxq->vport->vpi : 0,
  5388. mboxq->u.mb.mbxCommand,
  5389. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5390. psli->sli_flag, MBX_NOWAIT);
  5391. goto out_not_finished;
  5392. }
  5393. return rc;
  5394. out_not_finished:
  5395. spin_lock_irqsave(&phba->hbalock, iflags);
  5396. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5397. __lpfc_mbox_cmpl_put(phba, mboxq);
  5398. /* Release the token */
  5399. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5400. phba->sli.mbox_active = NULL;
  5401. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5402. return MBX_NOT_FINISHED;
  5403. }
  5404. /**
  5405. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5406. * @phba: Pointer to HBA context object.
  5407. * @pmbox: Pointer to mailbox object.
  5408. * @flag: Flag indicating how the mailbox need to be processed.
  5409. *
  5410. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5411. * the API jump table function pointer from the lpfc_hba struct.
  5412. *
  5413. * Return codes the caller owns the mailbox command after the return of the
  5414. * function.
  5415. **/
  5416. int
  5417. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5418. {
  5419. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5420. }
  5421. /**
  5422. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5423. * @phba: The hba struct for which this call is being executed.
  5424. * @dev_grp: The HBA PCI-Device group number.
  5425. *
  5426. * This routine sets up the mbox interface API function jump table in @phba
  5427. * struct.
  5428. * Returns: 0 - success, -ENODEV - failure.
  5429. **/
  5430. int
  5431. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5432. {
  5433. switch (dev_grp) {
  5434. case LPFC_PCI_DEV_LP:
  5435. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5436. phba->lpfc_sli_handle_slow_ring_event =
  5437. lpfc_sli_handle_slow_ring_event_s3;
  5438. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5439. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5440. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5441. break;
  5442. case LPFC_PCI_DEV_OC:
  5443. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5444. phba->lpfc_sli_handle_slow_ring_event =
  5445. lpfc_sli_handle_slow_ring_event_s4;
  5446. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5447. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5448. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5449. break;
  5450. default:
  5451. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5452. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5453. dev_grp);
  5454. return -ENODEV;
  5455. break;
  5456. }
  5457. return 0;
  5458. }
  5459. /**
  5460. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5461. * @phba: Pointer to HBA context object.
  5462. * @pring: Pointer to driver SLI ring object.
  5463. * @piocb: Pointer to address of newly added command iocb.
  5464. *
  5465. * This function is called with hbalock held to add a command
  5466. * iocb to the txq when SLI layer cannot submit the command iocb
  5467. * to the ring.
  5468. **/
  5469. void
  5470. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5471. struct lpfc_iocbq *piocb)
  5472. {
  5473. /* Insert the caller's iocb in the txq tail for later processing. */
  5474. list_add_tail(&piocb->list, &pring->txq);
  5475. pring->txq_cnt++;
  5476. }
  5477. /**
  5478. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5479. * @phba: Pointer to HBA context object.
  5480. * @pring: Pointer to driver SLI ring object.
  5481. * @piocb: Pointer to address of newly added command iocb.
  5482. *
  5483. * This function is called with hbalock held before a new
  5484. * iocb is submitted to the firmware. This function checks
  5485. * txq to flush the iocbs in txq to Firmware before
  5486. * submitting new iocbs to the Firmware.
  5487. * If there are iocbs in the txq which need to be submitted
  5488. * to firmware, lpfc_sli_next_iocb returns the first element
  5489. * of the txq after dequeuing it from txq.
  5490. * If there is no iocb in the txq then the function will return
  5491. * *piocb and *piocb is set to NULL. Caller needs to check
  5492. * *piocb to find if there are more commands in the txq.
  5493. **/
  5494. static struct lpfc_iocbq *
  5495. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5496. struct lpfc_iocbq **piocb)
  5497. {
  5498. struct lpfc_iocbq * nextiocb;
  5499. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5500. if (!nextiocb) {
  5501. nextiocb = *piocb;
  5502. *piocb = NULL;
  5503. }
  5504. return nextiocb;
  5505. }
  5506. /**
  5507. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5508. * @phba: Pointer to HBA context object.
  5509. * @ring_number: SLI ring number to issue iocb on.
  5510. * @piocb: Pointer to command iocb.
  5511. * @flag: Flag indicating if this command can be put into txq.
  5512. *
  5513. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5514. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5515. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5516. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5517. * this function allows only iocbs for posting buffers. This function finds
  5518. * next available slot in the command ring and posts the command to the
  5519. * available slot and writes the port attention register to request HBA start
  5520. * processing new iocb. If there is no slot available in the ring and
  5521. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5522. * the function returns IOCB_BUSY.
  5523. *
  5524. * This function is called with hbalock held. The function will return success
  5525. * after it successfully submit the iocb to firmware or after adding to the
  5526. * txq.
  5527. **/
  5528. static int
  5529. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5530. struct lpfc_iocbq *piocb, uint32_t flag)
  5531. {
  5532. struct lpfc_iocbq *nextiocb;
  5533. IOCB_t *iocb;
  5534. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5535. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5536. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5537. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5538. lpfc_printf_log(phba, KERN_ERR,
  5539. LOG_SLI | LOG_VPORT,
  5540. "1807 IOCB x%x failed. No vport\n",
  5541. piocb->iocb.ulpCommand);
  5542. dump_stack();
  5543. return IOCB_ERROR;
  5544. }
  5545. /* If the PCI channel is in offline state, do not post iocbs. */
  5546. if (unlikely(pci_channel_offline(phba->pcidev)))
  5547. return IOCB_ERROR;
  5548. /* If HBA has a deferred error attention, fail the iocb. */
  5549. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5550. return IOCB_ERROR;
  5551. /*
  5552. * We should never get an IOCB if we are in a < LINK_DOWN state
  5553. */
  5554. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5555. return IOCB_ERROR;
  5556. /*
  5557. * Check to see if we are blocking IOCB processing because of a
  5558. * outstanding event.
  5559. */
  5560. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5561. goto iocb_busy;
  5562. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5563. /*
  5564. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5565. * can be issued if the link is not up.
  5566. */
  5567. switch (piocb->iocb.ulpCommand) {
  5568. case CMD_GEN_REQUEST64_CR:
  5569. case CMD_GEN_REQUEST64_CX:
  5570. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5571. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5572. FC_RCTL_DD_UNSOL_CMD) ||
  5573. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5574. MENLO_TRANSPORT_TYPE))
  5575. goto iocb_busy;
  5576. break;
  5577. case CMD_QUE_RING_BUF_CN:
  5578. case CMD_QUE_RING_BUF64_CN:
  5579. /*
  5580. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5581. * completion, iocb_cmpl MUST be 0.
  5582. */
  5583. if (piocb->iocb_cmpl)
  5584. piocb->iocb_cmpl = NULL;
  5585. /*FALLTHROUGH*/
  5586. case CMD_CREATE_XRI_CR:
  5587. case CMD_CLOSE_XRI_CN:
  5588. case CMD_CLOSE_XRI_CX:
  5589. break;
  5590. default:
  5591. goto iocb_busy;
  5592. }
  5593. /*
  5594. * For FCP commands, we must be in a state where we can process link
  5595. * attention events.
  5596. */
  5597. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5598. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5599. goto iocb_busy;
  5600. }
  5601. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5602. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5603. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5604. if (iocb)
  5605. lpfc_sli_update_ring(phba, pring);
  5606. else
  5607. lpfc_sli_update_full_ring(phba, pring);
  5608. if (!piocb)
  5609. return IOCB_SUCCESS;
  5610. goto out_busy;
  5611. iocb_busy:
  5612. pring->stats.iocb_cmd_delay++;
  5613. out_busy:
  5614. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5615. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5616. return IOCB_SUCCESS;
  5617. }
  5618. return IOCB_BUSY;
  5619. }
  5620. /**
  5621. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5622. * @phba: Pointer to HBA context object.
  5623. * @piocb: Pointer to command iocb.
  5624. * @sglq: Pointer to the scatter gather queue object.
  5625. *
  5626. * This routine converts the bpl or bde that is in the IOCB
  5627. * to a sgl list for the sli4 hardware. The physical address
  5628. * of the bpl/bde is converted back to a virtual address.
  5629. * If the IOCB contains a BPL then the list of BDE's is
  5630. * converted to sli4_sge's. If the IOCB contains a single
  5631. * BDE then it is converted to a single sli_sge.
  5632. * The IOCB is still in cpu endianess so the contents of
  5633. * the bpl can be used without byte swapping.
  5634. *
  5635. * Returns valid XRI = Success, NO_XRI = Failure.
  5636. **/
  5637. static uint16_t
  5638. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5639. struct lpfc_sglq *sglq)
  5640. {
  5641. uint16_t xritag = NO_XRI;
  5642. struct ulp_bde64 *bpl = NULL;
  5643. struct ulp_bde64 bde;
  5644. struct sli4_sge *sgl = NULL;
  5645. IOCB_t *icmd;
  5646. int numBdes = 0;
  5647. int i = 0;
  5648. uint32_t offset = 0; /* accumulated offset in the sg request list */
  5649. int inbound = 0; /* number of sg reply entries inbound from firmware */
  5650. if (!piocbq || !sglq)
  5651. return xritag;
  5652. sgl = (struct sli4_sge *)sglq->sgl;
  5653. icmd = &piocbq->iocb;
  5654. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5655. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5656. sizeof(struct ulp_bde64);
  5657. /* The addrHigh and addrLow fields within the IOCB
  5658. * have not been byteswapped yet so there is no
  5659. * need to swap them back.
  5660. */
  5661. bpl = (struct ulp_bde64 *)
  5662. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5663. if (!bpl)
  5664. return xritag;
  5665. for (i = 0; i < numBdes; i++) {
  5666. /* Should already be byte swapped. */
  5667. sgl->addr_hi = bpl->addrHigh;
  5668. sgl->addr_lo = bpl->addrLow;
  5669. if ((i+1) == numBdes)
  5670. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5671. else
  5672. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5673. sgl->word2 = cpu_to_le32(sgl->word2);
  5674. /* swap the size field back to the cpu so we
  5675. * can assign it to the sgl.
  5676. */
  5677. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5678. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5679. /* The offsets in the sgl need to be accumulated
  5680. * separately for the request and reply lists.
  5681. * The request is always first, the reply follows.
  5682. */
  5683. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  5684. /* add up the reply sg entries */
  5685. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  5686. inbound++;
  5687. /* first inbound? reset the offset */
  5688. if (inbound == 1)
  5689. offset = 0;
  5690. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  5691. offset += bde.tus.f.bdeSize;
  5692. }
  5693. bpl++;
  5694. sgl++;
  5695. }
  5696. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5697. /* The addrHigh and addrLow fields of the BDE have not
  5698. * been byteswapped yet so they need to be swapped
  5699. * before putting them in the sgl.
  5700. */
  5701. sgl->addr_hi =
  5702. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5703. sgl->addr_lo =
  5704. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5705. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5706. sgl->word2 = cpu_to_le32(sgl->word2);
  5707. sgl->sge_len =
  5708. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5709. }
  5710. return sglq->sli4_xritag;
  5711. }
  5712. /**
  5713. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5714. * @phba: Pointer to HBA context object.
  5715. *
  5716. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  5717. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5718. * held.
  5719. *
  5720. * Return: index into SLI4 fast-path FCP queue index.
  5721. **/
  5722. static uint32_t
  5723. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5724. {
  5725. ++phba->fcp_qidx;
  5726. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5727. phba->fcp_qidx = 0;
  5728. return phba->fcp_qidx;
  5729. }
  5730. /**
  5731. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5732. * @phba: Pointer to HBA context object.
  5733. * @piocb: Pointer to command iocb.
  5734. * @wqe: Pointer to the work queue entry.
  5735. *
  5736. * This routine converts the iocb command to its Work Queue Entry
  5737. * equivalent. The wqe pointer should not have any fields set when
  5738. * this routine is called because it will memcpy over them.
  5739. * This routine does not set the CQ_ID or the WQEC bits in the
  5740. * wqe.
  5741. *
  5742. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5743. **/
  5744. static int
  5745. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5746. union lpfc_wqe *wqe)
  5747. {
  5748. uint32_t xmit_len = 0, total_len = 0;
  5749. uint8_t ct = 0;
  5750. uint32_t fip;
  5751. uint32_t abort_tag;
  5752. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5753. uint8_t cmnd;
  5754. uint16_t xritag;
  5755. uint16_t abrt_iotag;
  5756. struct lpfc_iocbq *abrtiocbq;
  5757. struct ulp_bde64 *bpl = NULL;
  5758. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  5759. int numBdes, i;
  5760. struct ulp_bde64 bde;
  5761. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5762. /* The fcp commands will set command type */
  5763. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5764. command_type = FCP_COMMAND;
  5765. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5766. command_type = ELS_COMMAND_FIP;
  5767. else
  5768. command_type = ELS_COMMAND_NON_FIP;
  5769. /* Some of the fields are in the right position already */
  5770. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5771. abort_tag = (uint32_t) iocbq->iotag;
  5772. xritag = iocbq->sli4_xritag;
  5773. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  5774. /* words0-2 bpl convert bde */
  5775. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5776. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5777. sizeof(struct ulp_bde64);
  5778. bpl = (struct ulp_bde64 *)
  5779. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5780. if (!bpl)
  5781. return IOCB_ERROR;
  5782. /* Should already be byte swapped. */
  5783. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5784. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5785. /* swap the size field back to the cpu so we
  5786. * can assign it to the sgl.
  5787. */
  5788. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5789. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5790. total_len = 0;
  5791. for (i = 0; i < numBdes; i++) {
  5792. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5793. total_len += bde.tus.f.bdeSize;
  5794. }
  5795. } else
  5796. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5797. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5798. cmnd = iocbq->iocb.ulpCommand;
  5799. switch (iocbq->iocb.ulpCommand) {
  5800. case CMD_ELS_REQUEST64_CR:
  5801. if (!iocbq->iocb.ulpLe) {
  5802. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5803. "2007 Only Limited Edition cmd Format"
  5804. " supported 0x%x\n",
  5805. iocbq->iocb.ulpCommand);
  5806. return IOCB_ERROR;
  5807. }
  5808. wqe->els_req.payload_len = xmit_len;
  5809. /* Els_reguest64 has a TMO */
  5810. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5811. iocbq->iocb.ulpTimeout);
  5812. /* Need a VF for word 4 set the vf bit*/
  5813. bf_set(els_req64_vf, &wqe->els_req, 0);
  5814. /* And a VFID for word 12 */
  5815. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5816. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5817. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  5818. iocbq->iocb.ulpContext);
  5819. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  5820. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  5821. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5822. if (command_type == ELS_COMMAND_FIP) {
  5823. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5824. >> LPFC_FIP_ELS_ID_SHIFT);
  5825. }
  5826. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  5827. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  5828. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  5829. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  5830. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5831. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  5832. break;
  5833. case CMD_XMIT_SEQUENCE64_CX:
  5834. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  5835. iocbq->iocb.un.ulpWord[3]);
  5836. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  5837. iocbq->iocb.ulpContext);
  5838. /* The entire sequence is transmitted for this IOCB */
  5839. xmit_len = total_len;
  5840. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5841. case CMD_XMIT_SEQUENCE64_CR:
  5842. /* word3 iocb=io_tag32 wqe=reserved */
  5843. wqe->xmit_sequence.rsvd3 = 0;
  5844. /* word4 relative_offset memcpy */
  5845. /* word5 r_ctl/df_ctl memcpy */
  5846. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  5847. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  5848. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  5849. LPFC_WQE_IOD_WRITE);
  5850. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  5851. LPFC_WQE_LENLOC_WORD12);
  5852. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  5853. wqe->xmit_sequence.xmit_len = xmit_len;
  5854. command_type = OTHER_COMMAND;
  5855. break;
  5856. case CMD_XMIT_BCAST64_CN:
  5857. /* word3 iocb=iotag32 wqe=seq_payload_len */
  5858. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  5859. /* word4 iocb=rsvd wqe=rsvd */
  5860. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5861. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5862. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  5863. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5864. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  5865. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  5866. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  5867. LPFC_WQE_LENLOC_WORD3);
  5868. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  5869. break;
  5870. case CMD_FCP_IWRITE64_CR:
  5871. command_type = FCP_COMMAND_DATA_OUT;
  5872. /* word3 iocb=iotag wqe=payload_offset_len */
  5873. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5874. wqe->fcp_iwrite.payload_offset_len =
  5875. xmit_len + sizeof(struct fcp_rsp);
  5876. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5877. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5878. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  5879. iocbq->iocb.ulpFCP2Rcvy);
  5880. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  5881. /* Always open the exchange */
  5882. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  5883. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  5884. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  5885. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  5886. LPFC_WQE_LENLOC_WORD4);
  5887. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  5888. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  5889. break;
  5890. case CMD_FCP_IREAD64_CR:
  5891. /* word3 iocb=iotag wqe=payload_offset_len */
  5892. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5893. wqe->fcp_iread.payload_offset_len =
  5894. xmit_len + sizeof(struct fcp_rsp);
  5895. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5896. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5897. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  5898. iocbq->iocb.ulpFCP2Rcvy);
  5899. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  5900. /* Always open the exchange */
  5901. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5902. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  5903. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  5904. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  5905. LPFC_WQE_LENLOC_WORD4);
  5906. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  5907. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  5908. break;
  5909. case CMD_FCP_ICMND64_CR:
  5910. /* word3 iocb=IO_TAG wqe=reserved */
  5911. wqe->fcp_icmd.rsrvd3 = 0;
  5912. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  5913. /* Always open the exchange */
  5914. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  5915. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  5916. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  5917. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  5918. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  5919. LPFC_WQE_LENLOC_NONE);
  5920. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  5921. break;
  5922. case CMD_GEN_REQUEST64_CR:
  5923. /* For this command calculate the xmit length of the
  5924. * request bde.
  5925. */
  5926. xmit_len = 0;
  5927. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5928. sizeof(struct ulp_bde64);
  5929. for (i = 0; i < numBdes; i++) {
  5930. if (bpl[i].tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  5931. break;
  5932. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5933. xmit_len += bde.tus.f.bdeSize;
  5934. }
  5935. /* word3 iocb=IO_TAG wqe=request_payload_len */
  5936. wqe->gen_req.request_payload_len = xmit_len;
  5937. /* word4 iocb=parameter wqe=relative_offset memcpy */
  5938. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  5939. /* word6 context tag copied in memcpy */
  5940. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5941. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5942. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5943. "2015 Invalid CT %x command 0x%x\n",
  5944. ct, iocbq->iocb.ulpCommand);
  5945. return IOCB_ERROR;
  5946. }
  5947. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  5948. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  5949. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  5950. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  5951. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  5952. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  5953. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5954. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  5955. command_type = OTHER_COMMAND;
  5956. break;
  5957. case CMD_XMIT_ELS_RSP64_CX:
  5958. /* words0-2 BDE memcpy */
  5959. /* word3 iocb=iotag32 wqe=response_payload_len */
  5960. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  5961. /* word4 iocb=did wge=rsvd. */
  5962. wqe->xmit_els_rsp.rsvd4 = 0;
  5963. /* word5 iocb=rsvd wge=did */
  5964. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5965. iocbq->iocb.un.elsreq64.remoteID);
  5966. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  5967. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5968. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  5969. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5970. iocbq->iocb.ulpContext);
  5971. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5972. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  5973. iocbq->vport->vpi + phba->vpi_base);
  5974. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  5975. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  5976. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  5977. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  5978. LPFC_WQE_LENLOC_WORD3);
  5979. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  5980. command_type = OTHER_COMMAND;
  5981. break;
  5982. case CMD_CLOSE_XRI_CN:
  5983. case CMD_ABORT_XRI_CN:
  5984. case CMD_ABORT_XRI_CX:
  5985. /* words 0-2 memcpy should be 0 rserved */
  5986. /* port will send abts */
  5987. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  5988. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  5989. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  5990. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  5991. } else
  5992. fip = 0;
  5993. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  5994. /*
  5995. * The link is down, or the command was ELS_FIP
  5996. * so the fw does not need to send abts
  5997. * on the wire.
  5998. */
  5999. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  6000. else
  6001. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  6002. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  6003. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  6004. wqe->abort_cmd.rsrvd5 = 0;
  6005. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  6006. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  6007. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  6008. /*
  6009. * The abort handler will send us CMD_ABORT_XRI_CN or
  6010. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  6011. */
  6012. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  6013. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  6014. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  6015. LPFC_WQE_LENLOC_NONE);
  6016. cmnd = CMD_ABORT_XRI_CX;
  6017. command_type = OTHER_COMMAND;
  6018. xritag = 0;
  6019. break;
  6020. case CMD_XMIT_BLS_RSP64_CX:
  6021. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  6022. * we re-construct this WQE here based on information in
  6023. * iocbq from scratch.
  6024. */
  6025. memset(wqe, 0, sizeof(union lpfc_wqe));
  6026. /* OX_ID is invariable to who sent ABTS to CT exchange */
  6027. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  6028. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  6029. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  6030. LPFC_ABTS_UNSOL_INT) {
  6031. /* ABTS sent by initiator to CT exchange, the
  6032. * RX_ID field will be filled with the newly
  6033. * allocated responder XRI.
  6034. */
  6035. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6036. iocbq->sli4_xritag);
  6037. } else {
  6038. /* ABTS sent by responder to CT exchange, the
  6039. * RX_ID field will be filled with the responder
  6040. * RX_ID from ABTS.
  6041. */
  6042. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6043. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  6044. }
  6045. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  6046. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  6047. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  6048. iocbq->iocb.ulpContext);
  6049. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  6050. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  6051. LPFC_WQE_LENLOC_NONE);
  6052. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  6053. command_type = OTHER_COMMAND;
  6054. break;
  6055. case CMD_XRI_ABORTED_CX:
  6056. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  6057. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  6058. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  6059. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  6060. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  6061. default:
  6062. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6063. "2014 Invalid command 0x%x\n",
  6064. iocbq->iocb.ulpCommand);
  6065. return IOCB_ERROR;
  6066. break;
  6067. }
  6068. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  6069. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  6070. wqe->generic.wqe_com.abort_tag = abort_tag;
  6071. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  6072. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  6073. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  6074. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  6075. return 0;
  6076. }
  6077. /**
  6078. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  6079. * @phba: Pointer to HBA context object.
  6080. * @ring_number: SLI ring number to issue iocb on.
  6081. * @piocb: Pointer to command iocb.
  6082. * @flag: Flag indicating if this command can be put into txq.
  6083. *
  6084. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  6085. * an iocb command to an HBA with SLI-4 interface spec.
  6086. *
  6087. * This function is called with hbalock held. The function will return success
  6088. * after it successfully submit the iocb to firmware or after adding to the
  6089. * txq.
  6090. **/
  6091. static int
  6092. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  6093. struct lpfc_iocbq *piocb, uint32_t flag)
  6094. {
  6095. struct lpfc_sglq *sglq;
  6096. union lpfc_wqe wqe;
  6097. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6098. if (piocb->sli4_xritag == NO_XRI) {
  6099. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  6100. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  6101. sglq = NULL;
  6102. else {
  6103. if (pring->txq_cnt) {
  6104. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6105. __lpfc_sli_ringtx_put(phba,
  6106. pring, piocb);
  6107. return IOCB_SUCCESS;
  6108. } else {
  6109. return IOCB_BUSY;
  6110. }
  6111. } else {
  6112. sglq = __lpfc_sli_get_sglq(phba, piocb);
  6113. if (!sglq) {
  6114. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6115. __lpfc_sli_ringtx_put(phba,
  6116. pring,
  6117. piocb);
  6118. return IOCB_SUCCESS;
  6119. } else
  6120. return IOCB_BUSY;
  6121. }
  6122. }
  6123. }
  6124. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  6125. sglq = NULL; /* These IO's already have an XRI and
  6126. * a mapped sgl.
  6127. */
  6128. } else {
  6129. /* This is a continuation of a commandi,(CX) so this
  6130. * sglq is on the active list
  6131. */
  6132. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  6133. if (!sglq)
  6134. return IOCB_ERROR;
  6135. }
  6136. if (sglq) {
  6137. piocb->sli4_xritag = sglq->sli4_xritag;
  6138. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  6139. return IOCB_ERROR;
  6140. }
  6141. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  6142. return IOCB_ERROR;
  6143. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  6144. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  6145. /*
  6146. * For FCP command IOCB, get a new WQ index to distribute
  6147. * WQE across the WQsr. On the other hand, for abort IOCB,
  6148. * it carries the same WQ index to the original command
  6149. * IOCB.
  6150. */
  6151. if (piocb->iocb_flag & LPFC_IO_FCP)
  6152. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  6153. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  6154. &wqe))
  6155. return IOCB_ERROR;
  6156. } else {
  6157. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  6158. return IOCB_ERROR;
  6159. }
  6160. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  6161. return 0;
  6162. }
  6163. /**
  6164. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  6165. *
  6166. * This routine wraps the actual lockless version for issusing IOCB function
  6167. * pointer from the lpfc_hba struct.
  6168. *
  6169. * Return codes:
  6170. * IOCB_ERROR - Error
  6171. * IOCB_SUCCESS - Success
  6172. * IOCB_BUSY - Busy
  6173. **/
  6174. int
  6175. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6176. struct lpfc_iocbq *piocb, uint32_t flag)
  6177. {
  6178. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6179. }
  6180. /**
  6181. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  6182. * @phba: The hba struct for which this call is being executed.
  6183. * @dev_grp: The HBA PCI-Device group number.
  6184. *
  6185. * This routine sets up the SLI interface API function jump table in @phba
  6186. * struct.
  6187. * Returns: 0 - success, -ENODEV - failure.
  6188. **/
  6189. int
  6190. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6191. {
  6192. switch (dev_grp) {
  6193. case LPFC_PCI_DEV_LP:
  6194. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  6195. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  6196. break;
  6197. case LPFC_PCI_DEV_OC:
  6198. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  6199. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  6200. break;
  6201. default:
  6202. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6203. "1419 Invalid HBA PCI-device group: 0x%x\n",
  6204. dev_grp);
  6205. return -ENODEV;
  6206. break;
  6207. }
  6208. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  6209. return 0;
  6210. }
  6211. /**
  6212. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  6213. * @phba: Pointer to HBA context object.
  6214. * @pring: Pointer to driver SLI ring object.
  6215. * @piocb: Pointer to command iocb.
  6216. * @flag: Flag indicating if this command can be put into txq.
  6217. *
  6218. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  6219. * function. This function gets the hbalock and calls
  6220. * __lpfc_sli_issue_iocb function and will return the error returned
  6221. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  6222. * functions which do not hold hbalock.
  6223. **/
  6224. int
  6225. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6226. struct lpfc_iocbq *piocb, uint32_t flag)
  6227. {
  6228. unsigned long iflags;
  6229. int rc;
  6230. spin_lock_irqsave(&phba->hbalock, iflags);
  6231. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6232. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6233. return rc;
  6234. }
  6235. /**
  6236. * lpfc_extra_ring_setup - Extra ring setup function
  6237. * @phba: Pointer to HBA context object.
  6238. *
  6239. * This function is called while driver attaches with the
  6240. * HBA to setup the extra ring. The extra ring is used
  6241. * only when driver needs to support target mode functionality
  6242. * or IP over FC functionalities.
  6243. *
  6244. * This function is called with no lock held.
  6245. **/
  6246. static int
  6247. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  6248. {
  6249. struct lpfc_sli *psli;
  6250. struct lpfc_sli_ring *pring;
  6251. psli = &phba->sli;
  6252. /* Adjust cmd/rsp ring iocb entries more evenly */
  6253. /* Take some away from the FCP ring */
  6254. pring = &psli->ring[psli->fcp_ring];
  6255. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6256. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6257. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6258. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6259. /* and give them to the extra ring */
  6260. pring = &psli->ring[psli->extra_ring];
  6261. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6262. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6263. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6264. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6265. /* Setup default profile for this ring */
  6266. pring->iotag_max = 4096;
  6267. pring->num_mask = 1;
  6268. pring->prt[0].profile = 0; /* Mask 0 */
  6269. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  6270. pring->prt[0].type = phba->cfg_multi_ring_type;
  6271. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  6272. return 0;
  6273. }
  6274. /**
  6275. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  6276. * @phba: Pointer to HBA context object.
  6277. * @pring: Pointer to driver SLI ring object.
  6278. * @iocbq: Pointer to iocb object.
  6279. *
  6280. * This function is called by the slow ring event handler
  6281. * function when there is an ASYNC event iocb in the ring.
  6282. * This function is called with no lock held.
  6283. * Currently this function handles only temperature related
  6284. * ASYNC events. The function decodes the temperature sensor
  6285. * event message and posts events for the management applications.
  6286. **/
  6287. static void
  6288. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  6289. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  6290. {
  6291. IOCB_t *icmd;
  6292. uint16_t evt_code;
  6293. uint16_t temp;
  6294. struct temp_event temp_event_data;
  6295. struct Scsi_Host *shost;
  6296. uint32_t *iocb_w;
  6297. icmd = &iocbq->iocb;
  6298. evt_code = icmd->un.asyncstat.evt_code;
  6299. temp = icmd->ulpContext;
  6300. if ((evt_code != ASYNC_TEMP_WARN) &&
  6301. (evt_code != ASYNC_TEMP_SAFE)) {
  6302. iocb_w = (uint32_t *) icmd;
  6303. lpfc_printf_log(phba,
  6304. KERN_ERR,
  6305. LOG_SLI,
  6306. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  6307. " evt_code 0x%x\n"
  6308. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  6309. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  6310. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  6311. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  6312. pring->ringno,
  6313. icmd->un.asyncstat.evt_code,
  6314. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  6315. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  6316. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  6317. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  6318. return;
  6319. }
  6320. temp_event_data.data = (uint32_t)temp;
  6321. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  6322. if (evt_code == ASYNC_TEMP_WARN) {
  6323. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  6324. lpfc_printf_log(phba,
  6325. KERN_ERR,
  6326. LOG_TEMP,
  6327. "0347 Adapter is very hot, please take "
  6328. "corrective action. temperature : %d Celsius\n",
  6329. temp);
  6330. }
  6331. if (evt_code == ASYNC_TEMP_SAFE) {
  6332. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  6333. lpfc_printf_log(phba,
  6334. KERN_ERR,
  6335. LOG_TEMP,
  6336. "0340 Adapter temperature is OK now. "
  6337. "temperature : %d Celsius\n",
  6338. temp);
  6339. }
  6340. /* Send temperature change event to applications */
  6341. shost = lpfc_shost_from_vport(phba->pport);
  6342. fc_host_post_vendor_event(shost, fc_get_event_number(),
  6343. sizeof(temp_event_data), (char *) &temp_event_data,
  6344. LPFC_NL_VENDOR_ID);
  6345. }
  6346. /**
  6347. * lpfc_sli_setup - SLI ring setup function
  6348. * @phba: Pointer to HBA context object.
  6349. *
  6350. * lpfc_sli_setup sets up rings of the SLI interface with
  6351. * number of iocbs per ring and iotags. This function is
  6352. * called while driver attach to the HBA and before the
  6353. * interrupts are enabled. So there is no need for locking.
  6354. *
  6355. * This function always returns 0.
  6356. **/
  6357. int
  6358. lpfc_sli_setup(struct lpfc_hba *phba)
  6359. {
  6360. int i, totiocbsize = 0;
  6361. struct lpfc_sli *psli = &phba->sli;
  6362. struct lpfc_sli_ring *pring;
  6363. psli->num_rings = MAX_CONFIGURED_RINGS;
  6364. psli->sli_flag = 0;
  6365. psli->fcp_ring = LPFC_FCP_RING;
  6366. psli->next_ring = LPFC_FCP_NEXT_RING;
  6367. psli->extra_ring = LPFC_EXTRA_RING;
  6368. psli->iocbq_lookup = NULL;
  6369. psli->iocbq_lookup_len = 0;
  6370. psli->last_iotag = 0;
  6371. for (i = 0; i < psli->num_rings; i++) {
  6372. pring = &psli->ring[i];
  6373. switch (i) {
  6374. case LPFC_FCP_RING: /* ring 0 - FCP */
  6375. /* numCiocb and numRiocb are used in config_port */
  6376. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  6377. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  6378. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6379. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6380. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6381. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6382. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6383. SLI3_IOCB_CMD_SIZE :
  6384. SLI2_IOCB_CMD_SIZE;
  6385. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6386. SLI3_IOCB_RSP_SIZE :
  6387. SLI2_IOCB_RSP_SIZE;
  6388. pring->iotag_ctr = 0;
  6389. pring->iotag_max =
  6390. (phba->cfg_hba_queue_depth * 2);
  6391. pring->fast_iotag = pring->iotag_max;
  6392. pring->num_mask = 0;
  6393. break;
  6394. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  6395. /* numCiocb and numRiocb are used in config_port */
  6396. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  6397. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  6398. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6399. SLI3_IOCB_CMD_SIZE :
  6400. SLI2_IOCB_CMD_SIZE;
  6401. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6402. SLI3_IOCB_RSP_SIZE :
  6403. SLI2_IOCB_RSP_SIZE;
  6404. pring->iotag_max = phba->cfg_hba_queue_depth;
  6405. pring->num_mask = 0;
  6406. break;
  6407. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  6408. /* numCiocb and numRiocb are used in config_port */
  6409. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  6410. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  6411. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6412. SLI3_IOCB_CMD_SIZE :
  6413. SLI2_IOCB_CMD_SIZE;
  6414. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6415. SLI3_IOCB_RSP_SIZE :
  6416. SLI2_IOCB_RSP_SIZE;
  6417. pring->fast_iotag = 0;
  6418. pring->iotag_ctr = 0;
  6419. pring->iotag_max = 4096;
  6420. pring->lpfc_sli_rcv_async_status =
  6421. lpfc_sli_async_event_handler;
  6422. pring->num_mask = LPFC_MAX_RING_MASK;
  6423. pring->prt[0].profile = 0; /* Mask 0 */
  6424. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  6425. pring->prt[0].type = FC_TYPE_ELS;
  6426. pring->prt[0].lpfc_sli_rcv_unsol_event =
  6427. lpfc_els_unsol_event;
  6428. pring->prt[1].profile = 0; /* Mask 1 */
  6429. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  6430. pring->prt[1].type = FC_TYPE_ELS;
  6431. pring->prt[1].lpfc_sli_rcv_unsol_event =
  6432. lpfc_els_unsol_event;
  6433. pring->prt[2].profile = 0; /* Mask 2 */
  6434. /* NameServer Inquiry */
  6435. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  6436. /* NameServer */
  6437. pring->prt[2].type = FC_TYPE_CT;
  6438. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6439. lpfc_ct_unsol_event;
  6440. pring->prt[3].profile = 0; /* Mask 3 */
  6441. /* NameServer response */
  6442. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6443. /* NameServer */
  6444. pring->prt[3].type = FC_TYPE_CT;
  6445. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6446. lpfc_ct_unsol_event;
  6447. /* abort unsolicited sequence */
  6448. pring->prt[4].profile = 0; /* Mask 4 */
  6449. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6450. pring->prt[4].type = FC_TYPE_BLS;
  6451. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6452. lpfc_sli4_ct_abort_unsol_event;
  6453. break;
  6454. }
  6455. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6456. (pring->numRiocb * pring->sizeRiocb);
  6457. }
  6458. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6459. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6460. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6461. "SLI2 SLIM Data: x%x x%lx\n",
  6462. phba->brd_no, totiocbsize,
  6463. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6464. }
  6465. if (phba->cfg_multi_ring_support == 2)
  6466. lpfc_extra_ring_setup(phba);
  6467. return 0;
  6468. }
  6469. /**
  6470. * lpfc_sli_queue_setup - Queue initialization function
  6471. * @phba: Pointer to HBA context object.
  6472. *
  6473. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6474. * ring. This function also initializes ring indices of each ring.
  6475. * This function is called during the initialization of the SLI
  6476. * interface of an HBA.
  6477. * This function is called with no lock held and always returns
  6478. * 1.
  6479. **/
  6480. int
  6481. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6482. {
  6483. struct lpfc_sli *psli;
  6484. struct lpfc_sli_ring *pring;
  6485. int i;
  6486. psli = &phba->sli;
  6487. spin_lock_irq(&phba->hbalock);
  6488. INIT_LIST_HEAD(&psli->mboxq);
  6489. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6490. /* Initialize list headers for txq and txcmplq as double linked lists */
  6491. for (i = 0; i < psli->num_rings; i++) {
  6492. pring = &psli->ring[i];
  6493. pring->ringno = i;
  6494. pring->next_cmdidx = 0;
  6495. pring->local_getidx = 0;
  6496. pring->cmdidx = 0;
  6497. INIT_LIST_HEAD(&pring->txq);
  6498. INIT_LIST_HEAD(&pring->txcmplq);
  6499. INIT_LIST_HEAD(&pring->iocb_continueq);
  6500. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6501. INIT_LIST_HEAD(&pring->postbufq);
  6502. }
  6503. spin_unlock_irq(&phba->hbalock);
  6504. return 1;
  6505. }
  6506. /**
  6507. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6508. * @phba: Pointer to HBA context object.
  6509. *
  6510. * This routine flushes the mailbox command subsystem. It will unconditionally
  6511. * flush all the mailbox commands in the three possible stages in the mailbox
  6512. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6513. * command; and completed mailbox command queue. It is caller's responsibility
  6514. * to make sure that the driver is in the proper state to flush the mailbox
  6515. * command sub-system. Namely, the posting of mailbox commands into the
  6516. * pending mailbox command queue from the various clients must be stopped;
  6517. * either the HBA is in a state that it will never works on the outstanding
  6518. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6519. * mailbox command has been completed.
  6520. **/
  6521. static void
  6522. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6523. {
  6524. LIST_HEAD(completions);
  6525. struct lpfc_sli *psli = &phba->sli;
  6526. LPFC_MBOXQ_t *pmb;
  6527. unsigned long iflag;
  6528. /* Flush all the mailbox commands in the mbox system */
  6529. spin_lock_irqsave(&phba->hbalock, iflag);
  6530. /* The pending mailbox command queue */
  6531. list_splice_init(&phba->sli.mboxq, &completions);
  6532. /* The outstanding active mailbox command */
  6533. if (psli->mbox_active) {
  6534. list_add_tail(&psli->mbox_active->list, &completions);
  6535. psli->mbox_active = NULL;
  6536. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6537. }
  6538. /* The completed mailbox command queue */
  6539. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6540. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6541. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6542. while (!list_empty(&completions)) {
  6543. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6544. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6545. if (pmb->mbox_cmpl)
  6546. pmb->mbox_cmpl(phba, pmb);
  6547. }
  6548. }
  6549. /**
  6550. * lpfc_sli_host_down - Vport cleanup function
  6551. * @vport: Pointer to virtual port object.
  6552. *
  6553. * lpfc_sli_host_down is called to clean up the resources
  6554. * associated with a vport before destroying virtual
  6555. * port data structures.
  6556. * This function does following operations:
  6557. * - Free discovery resources associated with this virtual
  6558. * port.
  6559. * - Free iocbs associated with this virtual port in
  6560. * the txq.
  6561. * - Send abort for all iocb commands associated with this
  6562. * vport in txcmplq.
  6563. *
  6564. * This function is called with no lock held and always returns 1.
  6565. **/
  6566. int
  6567. lpfc_sli_host_down(struct lpfc_vport *vport)
  6568. {
  6569. LIST_HEAD(completions);
  6570. struct lpfc_hba *phba = vport->phba;
  6571. struct lpfc_sli *psli = &phba->sli;
  6572. struct lpfc_sli_ring *pring;
  6573. struct lpfc_iocbq *iocb, *next_iocb;
  6574. int i;
  6575. unsigned long flags = 0;
  6576. uint16_t prev_pring_flag;
  6577. lpfc_cleanup_discovery_resources(vport);
  6578. spin_lock_irqsave(&phba->hbalock, flags);
  6579. for (i = 0; i < psli->num_rings; i++) {
  6580. pring = &psli->ring[i];
  6581. prev_pring_flag = pring->flag;
  6582. /* Only slow rings */
  6583. if (pring->ringno == LPFC_ELS_RING) {
  6584. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6585. /* Set the lpfc data pending flag */
  6586. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6587. }
  6588. /*
  6589. * Error everything on the txq since these iocbs have not been
  6590. * given to the FW yet.
  6591. */
  6592. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6593. if (iocb->vport != vport)
  6594. continue;
  6595. list_move_tail(&iocb->list, &completions);
  6596. pring->txq_cnt--;
  6597. }
  6598. /* Next issue ABTS for everything on the txcmplq */
  6599. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6600. list) {
  6601. if (iocb->vport != vport)
  6602. continue;
  6603. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6604. }
  6605. pring->flag = prev_pring_flag;
  6606. }
  6607. spin_unlock_irqrestore(&phba->hbalock, flags);
  6608. /* Cancel all the IOCBs from the completions list */
  6609. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6610. IOERR_SLI_DOWN);
  6611. return 1;
  6612. }
  6613. /**
  6614. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6615. * @phba: Pointer to HBA context object.
  6616. *
  6617. * This function cleans up all iocb, buffers, mailbox commands
  6618. * while shutting down the HBA. This function is called with no
  6619. * lock held and always returns 1.
  6620. * This function does the following to cleanup driver resources:
  6621. * - Free discovery resources for each virtual port
  6622. * - Cleanup any pending fabric iocbs
  6623. * - Iterate through the iocb txq and free each entry
  6624. * in the list.
  6625. * - Free up any buffer posted to the HBA
  6626. * - Free mailbox commands in the mailbox queue.
  6627. **/
  6628. int
  6629. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6630. {
  6631. LIST_HEAD(completions);
  6632. struct lpfc_sli *psli = &phba->sli;
  6633. struct lpfc_sli_ring *pring;
  6634. struct lpfc_dmabuf *buf_ptr;
  6635. unsigned long flags = 0;
  6636. int i;
  6637. /* Shutdown the mailbox command sub-system */
  6638. lpfc_sli_mbox_sys_shutdown(phba);
  6639. lpfc_hba_down_prep(phba);
  6640. lpfc_fabric_abort_hba(phba);
  6641. spin_lock_irqsave(&phba->hbalock, flags);
  6642. for (i = 0; i < psli->num_rings; i++) {
  6643. pring = &psli->ring[i];
  6644. /* Only slow rings */
  6645. if (pring->ringno == LPFC_ELS_RING) {
  6646. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6647. /* Set the lpfc data pending flag */
  6648. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6649. }
  6650. /*
  6651. * Error everything on the txq since these iocbs have not been
  6652. * given to the FW yet.
  6653. */
  6654. list_splice_init(&pring->txq, &completions);
  6655. pring->txq_cnt = 0;
  6656. }
  6657. spin_unlock_irqrestore(&phba->hbalock, flags);
  6658. /* Cancel all the IOCBs from the completions list */
  6659. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6660. IOERR_SLI_DOWN);
  6661. spin_lock_irqsave(&phba->hbalock, flags);
  6662. list_splice_init(&phba->elsbuf, &completions);
  6663. phba->elsbuf_cnt = 0;
  6664. phba->elsbuf_prev_cnt = 0;
  6665. spin_unlock_irqrestore(&phba->hbalock, flags);
  6666. while (!list_empty(&completions)) {
  6667. list_remove_head(&completions, buf_ptr,
  6668. struct lpfc_dmabuf, list);
  6669. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6670. kfree(buf_ptr);
  6671. }
  6672. /* Return any active mbox cmds */
  6673. del_timer_sync(&psli->mbox_tmo);
  6674. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6675. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6676. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6677. return 1;
  6678. }
  6679. /**
  6680. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6681. * @srcp: Source memory pointer.
  6682. * @destp: Destination memory pointer.
  6683. * @cnt: Number of words required to be copied.
  6684. *
  6685. * This function is used for copying data between driver memory
  6686. * and the SLI memory. This function also changes the endianness
  6687. * of each word if native endianness is different from SLI
  6688. * endianness. This function can be called with or without
  6689. * lock.
  6690. **/
  6691. void
  6692. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6693. {
  6694. uint32_t *src = srcp;
  6695. uint32_t *dest = destp;
  6696. uint32_t ldata;
  6697. int i;
  6698. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6699. ldata = *src;
  6700. ldata = le32_to_cpu(ldata);
  6701. *dest = ldata;
  6702. src++;
  6703. dest++;
  6704. }
  6705. }
  6706. /**
  6707. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6708. * @srcp: Source memory pointer.
  6709. * @destp: Destination memory pointer.
  6710. * @cnt: Number of words required to be copied.
  6711. *
  6712. * This function is used for copying data between a data structure
  6713. * with big endian representation to local endianness.
  6714. * This function can be called with or without lock.
  6715. **/
  6716. void
  6717. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6718. {
  6719. uint32_t *src = srcp;
  6720. uint32_t *dest = destp;
  6721. uint32_t ldata;
  6722. int i;
  6723. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6724. ldata = *src;
  6725. ldata = be32_to_cpu(ldata);
  6726. *dest = ldata;
  6727. src++;
  6728. dest++;
  6729. }
  6730. }
  6731. /**
  6732. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6733. * @phba: Pointer to HBA context object.
  6734. * @pring: Pointer to driver SLI ring object.
  6735. * @mp: Pointer to driver buffer object.
  6736. *
  6737. * This function is called with no lock held.
  6738. * It always return zero after adding the buffer to the postbufq
  6739. * buffer list.
  6740. **/
  6741. int
  6742. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6743. struct lpfc_dmabuf *mp)
  6744. {
  6745. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6746. later */
  6747. spin_lock_irq(&phba->hbalock);
  6748. list_add_tail(&mp->list, &pring->postbufq);
  6749. pring->postbufq_cnt++;
  6750. spin_unlock_irq(&phba->hbalock);
  6751. return 0;
  6752. }
  6753. /**
  6754. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6755. * @phba: Pointer to HBA context object.
  6756. *
  6757. * When HBQ is enabled, buffers are searched based on tags. This function
  6758. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6759. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6760. * does not conflict with tags of buffer posted for unsolicited events.
  6761. * The function returns the allocated tag. The function is called with
  6762. * no locks held.
  6763. **/
  6764. uint32_t
  6765. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6766. {
  6767. spin_lock_irq(&phba->hbalock);
  6768. phba->buffer_tag_count++;
  6769. /*
  6770. * Always set the QUE_BUFTAG_BIT to distiguish between
  6771. * a tag assigned by HBQ.
  6772. */
  6773. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6774. spin_unlock_irq(&phba->hbalock);
  6775. return phba->buffer_tag_count;
  6776. }
  6777. /**
  6778. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6779. * @phba: Pointer to HBA context object.
  6780. * @pring: Pointer to driver SLI ring object.
  6781. * @tag: Buffer tag.
  6782. *
  6783. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6784. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6785. * iocb is posted to the response ring with the tag of the buffer.
  6786. * This function searches the pring->postbufq list using the tag
  6787. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6788. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6789. * buffer is returned to the caller else NULL is returned.
  6790. * This function is called with no lock held.
  6791. **/
  6792. struct lpfc_dmabuf *
  6793. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6794. uint32_t tag)
  6795. {
  6796. struct lpfc_dmabuf *mp, *next_mp;
  6797. struct list_head *slp = &pring->postbufq;
  6798. /* Search postbufq, from the begining, looking for a match on tag */
  6799. spin_lock_irq(&phba->hbalock);
  6800. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6801. if (mp->buffer_tag == tag) {
  6802. list_del_init(&mp->list);
  6803. pring->postbufq_cnt--;
  6804. spin_unlock_irq(&phba->hbalock);
  6805. return mp;
  6806. }
  6807. }
  6808. spin_unlock_irq(&phba->hbalock);
  6809. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6810. "0402 Cannot find virtual addr for buffer tag on "
  6811. "ring %d Data x%lx x%p x%p x%x\n",
  6812. pring->ringno, (unsigned long) tag,
  6813. slp->next, slp->prev, pring->postbufq_cnt);
  6814. return NULL;
  6815. }
  6816. /**
  6817. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6818. * @phba: Pointer to HBA context object.
  6819. * @pring: Pointer to driver SLI ring object.
  6820. * @phys: DMA address of the buffer.
  6821. *
  6822. * This function searches the buffer list using the dma_address
  6823. * of unsolicited event to find the driver's lpfc_dmabuf object
  6824. * corresponding to the dma_address. The function returns the
  6825. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6826. * This function is called by the ct and els unsolicited event
  6827. * handlers to get the buffer associated with the unsolicited
  6828. * event.
  6829. *
  6830. * This function is called with no lock held.
  6831. **/
  6832. struct lpfc_dmabuf *
  6833. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6834. dma_addr_t phys)
  6835. {
  6836. struct lpfc_dmabuf *mp, *next_mp;
  6837. struct list_head *slp = &pring->postbufq;
  6838. /* Search postbufq, from the begining, looking for a match on phys */
  6839. spin_lock_irq(&phba->hbalock);
  6840. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6841. if (mp->phys == phys) {
  6842. list_del_init(&mp->list);
  6843. pring->postbufq_cnt--;
  6844. spin_unlock_irq(&phba->hbalock);
  6845. return mp;
  6846. }
  6847. }
  6848. spin_unlock_irq(&phba->hbalock);
  6849. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6850. "0410 Cannot find virtual addr for mapped buf on "
  6851. "ring %d Data x%llx x%p x%p x%x\n",
  6852. pring->ringno, (unsigned long long)phys,
  6853. slp->next, slp->prev, pring->postbufq_cnt);
  6854. return NULL;
  6855. }
  6856. /**
  6857. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6858. * @phba: Pointer to HBA context object.
  6859. * @cmdiocb: Pointer to driver command iocb object.
  6860. * @rspiocb: Pointer to driver response iocb object.
  6861. *
  6862. * This function is the completion handler for the abort iocbs for
  6863. * ELS commands. This function is called from the ELS ring event
  6864. * handler with no lock held. This function frees memory resources
  6865. * associated with the abort iocb.
  6866. **/
  6867. static void
  6868. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6869. struct lpfc_iocbq *rspiocb)
  6870. {
  6871. IOCB_t *irsp = &rspiocb->iocb;
  6872. uint16_t abort_iotag, abort_context;
  6873. struct lpfc_iocbq *abort_iocb;
  6874. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6875. abort_iocb = NULL;
  6876. if (irsp->ulpStatus) {
  6877. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6878. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6879. spin_lock_irq(&phba->hbalock);
  6880. if (phba->sli_rev < LPFC_SLI_REV4) {
  6881. if (abort_iotag != 0 &&
  6882. abort_iotag <= phba->sli.last_iotag)
  6883. abort_iocb =
  6884. phba->sli.iocbq_lookup[abort_iotag];
  6885. } else
  6886. /* For sli4 the abort_tag is the XRI,
  6887. * so the abort routine puts the iotag of the iocb
  6888. * being aborted in the context field of the abort
  6889. * IOCB.
  6890. */
  6891. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6892. /*
  6893. * If the iocb is not found in Firmware queue the iocb
  6894. * might have completed already. Do not free it again.
  6895. */
  6896. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6897. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6898. spin_unlock_irq(&phba->hbalock);
  6899. lpfc_sli_release_iocbq(phba, cmdiocb);
  6900. return;
  6901. }
  6902. /* For SLI4 the ulpContext field for abort IOCB
  6903. * holds the iotag of the IOCB being aborted so
  6904. * the local abort_context needs to be reset to
  6905. * match the aborted IOCBs ulpContext.
  6906. */
  6907. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6908. abort_context = abort_iocb->iocb.ulpContext;
  6909. }
  6910. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6911. "0327 Cannot abort els iocb %p "
  6912. "with tag %x context %x, abort status %x, "
  6913. "abort code %x\n",
  6914. abort_iocb, abort_iotag, abort_context,
  6915. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6916. /*
  6917. * make sure we have the right iocbq before taking it
  6918. * off the txcmplq and try to call completion routine.
  6919. */
  6920. if (!abort_iocb ||
  6921. abort_iocb->iocb.ulpContext != abort_context ||
  6922. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6923. spin_unlock_irq(&phba->hbalock);
  6924. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6925. /*
  6926. * leave the SLI4 aborted command on the txcmplq
  6927. * list and the command complete WCQE's XB bit
  6928. * will tell whether the SGL (XRI) can be released
  6929. * immediately or to the aborted SGL list for the
  6930. * following abort XRI from the HBA.
  6931. */
  6932. list_del_init(&abort_iocb->list);
  6933. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6934. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6935. pring->txcmplq_cnt--;
  6936. }
  6937. /* Firmware could still be in progress of DMAing
  6938. * payload, so don't free data buffer till after
  6939. * a hbeat.
  6940. */
  6941. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6942. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6943. spin_unlock_irq(&phba->hbalock);
  6944. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6945. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6946. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6947. } else
  6948. spin_unlock_irq(&phba->hbalock);
  6949. }
  6950. lpfc_sli_release_iocbq(phba, cmdiocb);
  6951. return;
  6952. }
  6953. /**
  6954. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6955. * @phba: Pointer to HBA context object.
  6956. * @cmdiocb: Pointer to driver command iocb object.
  6957. * @rspiocb: Pointer to driver response iocb object.
  6958. *
  6959. * The function is called from SLI ring event handler with no
  6960. * lock held. This function is the completion handler for ELS commands
  6961. * which are aborted. The function frees memory resources used for
  6962. * the aborted ELS commands.
  6963. **/
  6964. static void
  6965. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6966. struct lpfc_iocbq *rspiocb)
  6967. {
  6968. IOCB_t *irsp = &rspiocb->iocb;
  6969. /* ELS cmd tag <ulpIoTag> completes */
  6970. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6971. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6972. "x%x x%x x%x\n",
  6973. irsp->ulpIoTag, irsp->ulpStatus,
  6974. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6975. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6976. lpfc_ct_free_iocb(phba, cmdiocb);
  6977. else
  6978. lpfc_els_free_iocb(phba, cmdiocb);
  6979. return;
  6980. }
  6981. /**
  6982. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  6983. * @phba: Pointer to HBA context object.
  6984. * @pring: Pointer to driver SLI ring object.
  6985. * @cmdiocb: Pointer to driver command iocb object.
  6986. *
  6987. * This function issues an abort iocb for the provided command iocb down to
  6988. * the port. Other than the case the outstanding command iocb is an abort
  6989. * request, this function issues abort out unconditionally. This function is
  6990. * called with hbalock held. The function returns 0 when it fails due to
  6991. * memory allocation failure or when the command iocb is an abort request.
  6992. **/
  6993. static int
  6994. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6995. struct lpfc_iocbq *cmdiocb)
  6996. {
  6997. struct lpfc_vport *vport = cmdiocb->vport;
  6998. struct lpfc_iocbq *abtsiocbp;
  6999. IOCB_t *icmd = NULL;
  7000. IOCB_t *iabt = NULL;
  7001. int retval;
  7002. /*
  7003. * There are certain command types we don't want to abort. And we
  7004. * don't want to abort commands that are already in the process of
  7005. * being aborted.
  7006. */
  7007. icmd = &cmdiocb->iocb;
  7008. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7009. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7010. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7011. return 0;
  7012. /* issue ABTS for this IOCB based on iotag */
  7013. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  7014. if (abtsiocbp == NULL)
  7015. return 0;
  7016. /* This signals the response to set the correct status
  7017. * before calling the completion handler
  7018. */
  7019. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  7020. iabt = &abtsiocbp->iocb;
  7021. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  7022. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  7023. if (phba->sli_rev == LPFC_SLI_REV4) {
  7024. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  7025. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  7026. }
  7027. else
  7028. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  7029. iabt->ulpLe = 1;
  7030. iabt->ulpClass = icmd->ulpClass;
  7031. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7032. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  7033. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  7034. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  7035. if (phba->link_state >= LPFC_LINK_UP)
  7036. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  7037. else
  7038. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  7039. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  7040. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  7041. "0339 Abort xri x%x, original iotag x%x, "
  7042. "abort cmd iotag x%x\n",
  7043. iabt->un.acxri.abortIoTag,
  7044. iabt->un.acxri.abortContextTag,
  7045. abtsiocbp->iotag);
  7046. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  7047. if (retval)
  7048. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  7049. /*
  7050. * Caller to this routine should check for IOCB_ERROR
  7051. * and handle it properly. This routine no longer removes
  7052. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7053. */
  7054. return retval;
  7055. }
  7056. /**
  7057. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  7058. * @phba: Pointer to HBA context object.
  7059. * @pring: Pointer to driver SLI ring object.
  7060. * @cmdiocb: Pointer to driver command iocb object.
  7061. *
  7062. * This function issues an abort iocb for the provided command iocb. In case
  7063. * of unloading, the abort iocb will not be issued to commands on the ELS
  7064. * ring. Instead, the callback function shall be changed to those commands
  7065. * so that nothing happens when them finishes. This function is called with
  7066. * hbalock held. The function returns 0 when the command iocb is an abort
  7067. * request.
  7068. **/
  7069. int
  7070. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7071. struct lpfc_iocbq *cmdiocb)
  7072. {
  7073. struct lpfc_vport *vport = cmdiocb->vport;
  7074. int retval = IOCB_ERROR;
  7075. IOCB_t *icmd = NULL;
  7076. /*
  7077. * There are certain command types we don't want to abort. And we
  7078. * don't want to abort commands that are already in the process of
  7079. * being aborted.
  7080. */
  7081. icmd = &cmdiocb->iocb;
  7082. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7083. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7084. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7085. return 0;
  7086. /*
  7087. * If we're unloading, don't abort iocb on the ELS ring, but change
  7088. * the callback so that nothing happens when it finishes.
  7089. */
  7090. if ((vport->load_flag & FC_UNLOADING) &&
  7091. (pring->ringno == LPFC_ELS_RING)) {
  7092. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  7093. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  7094. else
  7095. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  7096. goto abort_iotag_exit;
  7097. }
  7098. /* Now, we try to issue the abort to the cmdiocb out */
  7099. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  7100. abort_iotag_exit:
  7101. /*
  7102. * Caller to this routine should check for IOCB_ERROR
  7103. * and handle it properly. This routine no longer removes
  7104. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7105. */
  7106. return retval;
  7107. }
  7108. /**
  7109. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  7110. * @phba: Pointer to HBA context object.
  7111. * @pring: Pointer to driver SLI ring object.
  7112. *
  7113. * This function aborts all iocbs in the given ring and frees all the iocb
  7114. * objects in txq. This function issues abort iocbs unconditionally for all
  7115. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  7116. * to complete before the return of this function. The caller is not required
  7117. * to hold any locks.
  7118. **/
  7119. static void
  7120. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  7121. {
  7122. LIST_HEAD(completions);
  7123. struct lpfc_iocbq *iocb, *next_iocb;
  7124. if (pring->ringno == LPFC_ELS_RING)
  7125. lpfc_fabric_abort_hba(phba);
  7126. spin_lock_irq(&phba->hbalock);
  7127. /* Take off all the iocbs on txq for cancelling */
  7128. list_splice_init(&pring->txq, &completions);
  7129. pring->txq_cnt = 0;
  7130. /* Next issue ABTS for everything on the txcmplq */
  7131. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  7132. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  7133. spin_unlock_irq(&phba->hbalock);
  7134. /* Cancel all the IOCBs from the completions list */
  7135. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7136. IOERR_SLI_ABORTED);
  7137. }
  7138. /**
  7139. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  7140. * @phba: pointer to lpfc HBA data structure.
  7141. *
  7142. * This routine will abort all pending and outstanding iocbs to an HBA.
  7143. **/
  7144. void
  7145. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  7146. {
  7147. struct lpfc_sli *psli = &phba->sli;
  7148. struct lpfc_sli_ring *pring;
  7149. int i;
  7150. for (i = 0; i < psli->num_rings; i++) {
  7151. pring = &psli->ring[i];
  7152. lpfc_sli_iocb_ring_abort(phba, pring);
  7153. }
  7154. }
  7155. /**
  7156. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  7157. * @iocbq: Pointer to driver iocb object.
  7158. * @vport: Pointer to driver virtual port object.
  7159. * @tgt_id: SCSI ID of the target.
  7160. * @lun_id: LUN ID of the scsi device.
  7161. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  7162. *
  7163. * This function acts as an iocb filter for functions which abort or count
  7164. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  7165. * 0 if the filtering criteria is met for the given iocb and will return
  7166. * 1 if the filtering criteria is not met.
  7167. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  7168. * given iocb is for the SCSI device specified by vport, tgt_id and
  7169. * lun_id parameter.
  7170. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  7171. * given iocb is for the SCSI target specified by vport and tgt_id
  7172. * parameters.
  7173. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  7174. * given iocb is for the SCSI host associated with the given vport.
  7175. * This function is called with no locks held.
  7176. **/
  7177. static int
  7178. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  7179. uint16_t tgt_id, uint64_t lun_id,
  7180. lpfc_ctx_cmd ctx_cmd)
  7181. {
  7182. struct lpfc_scsi_buf *lpfc_cmd;
  7183. int rc = 1;
  7184. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  7185. return rc;
  7186. if (iocbq->vport != vport)
  7187. return rc;
  7188. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  7189. if (lpfc_cmd->pCmd == NULL)
  7190. return rc;
  7191. switch (ctx_cmd) {
  7192. case LPFC_CTX_LUN:
  7193. if ((lpfc_cmd->rdata->pnode) &&
  7194. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  7195. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  7196. rc = 0;
  7197. break;
  7198. case LPFC_CTX_TGT:
  7199. if ((lpfc_cmd->rdata->pnode) &&
  7200. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  7201. rc = 0;
  7202. break;
  7203. case LPFC_CTX_HOST:
  7204. rc = 0;
  7205. break;
  7206. default:
  7207. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  7208. __func__, ctx_cmd);
  7209. break;
  7210. }
  7211. return rc;
  7212. }
  7213. /**
  7214. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  7215. * @vport: Pointer to virtual port.
  7216. * @tgt_id: SCSI ID of the target.
  7217. * @lun_id: LUN ID of the scsi device.
  7218. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7219. *
  7220. * This function returns number of FCP commands pending for the vport.
  7221. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  7222. * commands pending on the vport associated with SCSI device specified
  7223. * by tgt_id and lun_id parameters.
  7224. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  7225. * commands pending on the vport associated with SCSI target specified
  7226. * by tgt_id parameter.
  7227. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  7228. * commands pending on the vport.
  7229. * This function returns the number of iocbs which satisfy the filter.
  7230. * This function is called without any lock held.
  7231. **/
  7232. int
  7233. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  7234. lpfc_ctx_cmd ctx_cmd)
  7235. {
  7236. struct lpfc_hba *phba = vport->phba;
  7237. struct lpfc_iocbq *iocbq;
  7238. int sum, i;
  7239. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  7240. iocbq = phba->sli.iocbq_lookup[i];
  7241. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  7242. ctx_cmd) == 0)
  7243. sum++;
  7244. }
  7245. return sum;
  7246. }
  7247. /**
  7248. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  7249. * @phba: Pointer to HBA context object
  7250. * @cmdiocb: Pointer to command iocb object.
  7251. * @rspiocb: Pointer to response iocb object.
  7252. *
  7253. * This function is called when an aborted FCP iocb completes. This
  7254. * function is called by the ring event handler with no lock held.
  7255. * This function frees the iocb.
  7256. **/
  7257. void
  7258. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7259. struct lpfc_iocbq *rspiocb)
  7260. {
  7261. lpfc_sli_release_iocbq(phba, cmdiocb);
  7262. return;
  7263. }
  7264. /**
  7265. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  7266. * @vport: Pointer to virtual port.
  7267. * @pring: Pointer to driver SLI ring object.
  7268. * @tgt_id: SCSI ID of the target.
  7269. * @lun_id: LUN ID of the scsi device.
  7270. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7271. *
  7272. * This function sends an abort command for every SCSI command
  7273. * associated with the given virtual port pending on the ring
  7274. * filtered by lpfc_sli_validate_fcp_iocb function.
  7275. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  7276. * FCP iocbs associated with lun specified by tgt_id and lun_id
  7277. * parameters
  7278. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  7279. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  7280. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  7281. * FCP iocbs associated with virtual port.
  7282. * This function returns number of iocbs it failed to abort.
  7283. * This function is called with no locks held.
  7284. **/
  7285. int
  7286. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  7287. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  7288. {
  7289. struct lpfc_hba *phba = vport->phba;
  7290. struct lpfc_iocbq *iocbq;
  7291. struct lpfc_iocbq *abtsiocb;
  7292. IOCB_t *cmd = NULL;
  7293. int errcnt = 0, ret_val = 0;
  7294. int i;
  7295. for (i = 1; i <= phba->sli.last_iotag; i++) {
  7296. iocbq = phba->sli.iocbq_lookup[i];
  7297. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  7298. abort_cmd) != 0)
  7299. continue;
  7300. /* issue ABTS for this IOCB based on iotag */
  7301. abtsiocb = lpfc_sli_get_iocbq(phba);
  7302. if (abtsiocb == NULL) {
  7303. errcnt++;
  7304. continue;
  7305. }
  7306. cmd = &iocbq->iocb;
  7307. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  7308. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  7309. if (phba->sli_rev == LPFC_SLI_REV4)
  7310. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  7311. else
  7312. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  7313. abtsiocb->iocb.ulpLe = 1;
  7314. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  7315. abtsiocb->vport = phba->pport;
  7316. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7317. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  7318. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7319. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  7320. if (lpfc_is_link_up(phba))
  7321. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  7322. else
  7323. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  7324. /* Setup callback routine and issue the command. */
  7325. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  7326. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  7327. abtsiocb, 0);
  7328. if (ret_val == IOCB_ERROR) {
  7329. lpfc_sli_release_iocbq(phba, abtsiocb);
  7330. errcnt++;
  7331. continue;
  7332. }
  7333. }
  7334. return errcnt;
  7335. }
  7336. /**
  7337. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  7338. * @phba: Pointer to HBA context object.
  7339. * @cmdiocbq: Pointer to command iocb.
  7340. * @rspiocbq: Pointer to response iocb.
  7341. *
  7342. * This function is the completion handler for iocbs issued using
  7343. * lpfc_sli_issue_iocb_wait function. This function is called by the
  7344. * ring event handler function without any lock held. This function
  7345. * can be called from both worker thread context and interrupt
  7346. * context. This function also can be called from other thread which
  7347. * cleans up the SLI layer objects.
  7348. * This function copy the contents of the response iocb to the
  7349. * response iocb memory object provided by the caller of
  7350. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  7351. * sleeps for the iocb completion.
  7352. **/
  7353. static void
  7354. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  7355. struct lpfc_iocbq *cmdiocbq,
  7356. struct lpfc_iocbq *rspiocbq)
  7357. {
  7358. wait_queue_head_t *pdone_q;
  7359. unsigned long iflags;
  7360. struct lpfc_scsi_buf *lpfc_cmd;
  7361. spin_lock_irqsave(&phba->hbalock, iflags);
  7362. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  7363. if (cmdiocbq->context2 && rspiocbq)
  7364. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  7365. &rspiocbq->iocb, sizeof(IOCB_t));
  7366. /* Set the exchange busy flag for task management commands */
  7367. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  7368. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  7369. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  7370. cur_iocbq);
  7371. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  7372. }
  7373. pdone_q = cmdiocbq->context_un.wait_queue;
  7374. if (pdone_q)
  7375. wake_up(pdone_q);
  7376. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7377. return;
  7378. }
  7379. /**
  7380. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  7381. * @phba: Pointer to HBA context object..
  7382. * @piocbq: Pointer to command iocb.
  7383. * @flag: Flag to test.
  7384. *
  7385. * This routine grabs the hbalock and then test the iocb_flag to
  7386. * see if the passed in flag is set.
  7387. * Returns:
  7388. * 1 if flag is set.
  7389. * 0 if flag is not set.
  7390. **/
  7391. static int
  7392. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  7393. struct lpfc_iocbq *piocbq, uint32_t flag)
  7394. {
  7395. unsigned long iflags;
  7396. int ret;
  7397. spin_lock_irqsave(&phba->hbalock, iflags);
  7398. ret = piocbq->iocb_flag & flag;
  7399. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7400. return ret;
  7401. }
  7402. /**
  7403. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  7404. * @phba: Pointer to HBA context object..
  7405. * @pring: Pointer to sli ring.
  7406. * @piocb: Pointer to command iocb.
  7407. * @prspiocbq: Pointer to response iocb.
  7408. * @timeout: Timeout in number of seconds.
  7409. *
  7410. * This function issues the iocb to firmware and waits for the
  7411. * iocb to complete. If the iocb command is not
  7412. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  7413. * Caller should not free the iocb resources if this function
  7414. * returns IOCB_TIMEDOUT.
  7415. * The function waits for the iocb completion using an
  7416. * non-interruptible wait.
  7417. * This function will sleep while waiting for iocb completion.
  7418. * So, this function should not be called from any context which
  7419. * does not allow sleeping. Due to the same reason, this function
  7420. * cannot be called with interrupt disabled.
  7421. * This function assumes that the iocb completions occur while
  7422. * this function sleep. So, this function cannot be called from
  7423. * the thread which process iocb completion for this ring.
  7424. * This function clears the iocb_flag of the iocb object before
  7425. * issuing the iocb and the iocb completion handler sets this
  7426. * flag and wakes this thread when the iocb completes.
  7427. * The contents of the response iocb will be copied to prspiocbq
  7428. * by the completion handler when the command completes.
  7429. * This function returns IOCB_SUCCESS when success.
  7430. * This function is called with no lock held.
  7431. **/
  7432. int
  7433. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  7434. uint32_t ring_number,
  7435. struct lpfc_iocbq *piocb,
  7436. struct lpfc_iocbq *prspiocbq,
  7437. uint32_t timeout)
  7438. {
  7439. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7440. long timeleft, timeout_req = 0;
  7441. int retval = IOCB_SUCCESS;
  7442. uint32_t creg_val;
  7443. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7444. /*
  7445. * If the caller has provided a response iocbq buffer, then context2
  7446. * is NULL or its an error.
  7447. */
  7448. if (prspiocbq) {
  7449. if (piocb->context2)
  7450. return IOCB_ERROR;
  7451. piocb->context2 = prspiocbq;
  7452. }
  7453. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  7454. piocb->context_un.wait_queue = &done_q;
  7455. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  7456. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7457. creg_val = readl(phba->HCregaddr);
  7458. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  7459. writel(creg_val, phba->HCregaddr);
  7460. readl(phba->HCregaddr); /* flush */
  7461. }
  7462. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7463. SLI_IOCB_RET_IOCB);
  7464. if (retval == IOCB_SUCCESS) {
  7465. timeout_req = timeout * HZ;
  7466. timeleft = wait_event_timeout(done_q,
  7467. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  7468. timeout_req);
  7469. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  7470. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7471. "0331 IOCB wake signaled\n");
  7472. } else if (timeleft == 0) {
  7473. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7474. "0338 IOCB wait timeout error - no "
  7475. "wake response Data x%x\n", timeout);
  7476. retval = IOCB_TIMEDOUT;
  7477. } else {
  7478. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7479. "0330 IOCB wake NOT set, "
  7480. "Data x%x x%lx\n",
  7481. timeout, (timeleft / jiffies));
  7482. retval = IOCB_TIMEDOUT;
  7483. }
  7484. } else if (retval == IOCB_BUSY) {
  7485. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7486. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  7487. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  7488. return retval;
  7489. } else {
  7490. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7491. "0332 IOCB wait issue failed, Data x%x\n",
  7492. retval);
  7493. retval = IOCB_ERROR;
  7494. }
  7495. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7496. creg_val = readl(phba->HCregaddr);
  7497. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  7498. writel(creg_val, phba->HCregaddr);
  7499. readl(phba->HCregaddr); /* flush */
  7500. }
  7501. if (prspiocbq)
  7502. piocb->context2 = NULL;
  7503. piocb->context_un.wait_queue = NULL;
  7504. piocb->iocb_cmpl = NULL;
  7505. return retval;
  7506. }
  7507. /**
  7508. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7509. * @phba: Pointer to HBA context object.
  7510. * @pmboxq: Pointer to driver mailbox object.
  7511. * @timeout: Timeout in number of seconds.
  7512. *
  7513. * This function issues the mailbox to firmware and waits for the
  7514. * mailbox command to complete. If the mailbox command is not
  7515. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7516. * The function waits for the mailbox completion using an
  7517. * interruptible wait. If the thread is woken up due to a
  7518. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7519. * should not free the mailbox resources, if this function returns
  7520. * MBX_TIMEOUT.
  7521. * This function will sleep while waiting for mailbox completion.
  7522. * So, this function should not be called from any context which
  7523. * does not allow sleeping. Due to the same reason, this function
  7524. * cannot be called with interrupt disabled.
  7525. * This function assumes that the mailbox completion occurs while
  7526. * this function sleep. So, this function cannot be called from
  7527. * the worker thread which processes mailbox completion.
  7528. * This function is called in the context of HBA management
  7529. * applications.
  7530. * This function returns MBX_SUCCESS when successful.
  7531. * This function is called with no lock held.
  7532. **/
  7533. int
  7534. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7535. uint32_t timeout)
  7536. {
  7537. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7538. int retval;
  7539. unsigned long flag;
  7540. /* The caller must leave context1 empty. */
  7541. if (pmboxq->context1)
  7542. return MBX_NOT_FINISHED;
  7543. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7544. /* setup wake call as IOCB callback */
  7545. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7546. /* setup context field to pass wait_queue pointer to wake function */
  7547. pmboxq->context1 = &done_q;
  7548. /* now issue the command */
  7549. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7550. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7551. wait_event_interruptible_timeout(done_q,
  7552. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7553. timeout * HZ);
  7554. spin_lock_irqsave(&phba->hbalock, flag);
  7555. pmboxq->context1 = NULL;
  7556. /*
  7557. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7558. * else do not free the resources.
  7559. */
  7560. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7561. retval = MBX_SUCCESS;
  7562. lpfc_sli4_swap_str(phba, pmboxq);
  7563. } else {
  7564. retval = MBX_TIMEOUT;
  7565. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7566. }
  7567. spin_unlock_irqrestore(&phba->hbalock, flag);
  7568. }
  7569. return retval;
  7570. }
  7571. /**
  7572. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7573. * @phba: Pointer to HBA context.
  7574. *
  7575. * This function is called to shutdown the driver's mailbox sub-system.
  7576. * It first marks the mailbox sub-system is in a block state to prevent
  7577. * the asynchronous mailbox command from issued off the pending mailbox
  7578. * command queue. If the mailbox command sub-system shutdown is due to
  7579. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7580. * the mailbox sub-system flush routine to forcefully bring down the
  7581. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7582. * as with offline or HBA function reset), this routine will wait for the
  7583. * outstanding mailbox command to complete before invoking the mailbox
  7584. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7585. **/
  7586. void
  7587. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7588. {
  7589. struct lpfc_sli *psli = &phba->sli;
  7590. uint8_t actcmd = MBX_HEARTBEAT;
  7591. unsigned long timeout;
  7592. spin_lock_irq(&phba->hbalock);
  7593. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7594. spin_unlock_irq(&phba->hbalock);
  7595. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7596. spin_lock_irq(&phba->hbalock);
  7597. if (phba->sli.mbox_active)
  7598. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7599. spin_unlock_irq(&phba->hbalock);
  7600. /* Determine how long we might wait for the active mailbox
  7601. * command to be gracefully completed by firmware.
  7602. */
  7603. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7604. 1000) + jiffies;
  7605. while (phba->sli.mbox_active) {
  7606. /* Check active mailbox complete status every 2ms */
  7607. msleep(2);
  7608. if (time_after(jiffies, timeout))
  7609. /* Timeout, let the mailbox flush routine to
  7610. * forcefully release active mailbox command
  7611. */
  7612. break;
  7613. }
  7614. }
  7615. lpfc_sli_mbox_sys_flush(phba);
  7616. }
  7617. /**
  7618. * lpfc_sli_eratt_read - read sli-3 error attention events
  7619. * @phba: Pointer to HBA context.
  7620. *
  7621. * This function is called to read the SLI3 device error attention registers
  7622. * for possible error attention events. The caller must hold the hostlock
  7623. * with spin_lock_irq().
  7624. *
  7625. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7626. * Register and returns 0 otherwise.
  7627. **/
  7628. static int
  7629. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7630. {
  7631. uint32_t ha_copy;
  7632. /* Read chip Host Attention (HA) register */
  7633. ha_copy = readl(phba->HAregaddr);
  7634. if (ha_copy & HA_ERATT) {
  7635. /* Read host status register to retrieve error event */
  7636. lpfc_sli_read_hs(phba);
  7637. /* Check if there is a deferred error condition is active */
  7638. if ((HS_FFER1 & phba->work_hs) &&
  7639. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7640. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  7641. phba->hba_flag |= DEFER_ERATT;
  7642. /* Clear all interrupt enable conditions */
  7643. writel(0, phba->HCregaddr);
  7644. readl(phba->HCregaddr);
  7645. }
  7646. /* Set the driver HA work bitmap */
  7647. phba->work_ha |= HA_ERATT;
  7648. /* Indicate polling handles this ERATT */
  7649. phba->hba_flag |= HBA_ERATT_HANDLED;
  7650. return 1;
  7651. }
  7652. return 0;
  7653. }
  7654. /**
  7655. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7656. * @phba: Pointer to HBA context.
  7657. *
  7658. * This function is called to read the SLI4 device error attention registers
  7659. * for possible error attention events. The caller must hold the hostlock
  7660. * with spin_lock_irq().
  7661. *
  7662. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7663. * Register and returns 0 otherwise.
  7664. **/
  7665. static int
  7666. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7667. {
  7668. uint32_t uerr_sta_hi, uerr_sta_lo;
  7669. uint32_t if_type, portsmphr;
  7670. struct lpfc_register portstat_reg;
  7671. /*
  7672. * For now, use the SLI4 device internal unrecoverable error
  7673. * registers for error attention. This can be changed later.
  7674. */
  7675. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7676. switch (if_type) {
  7677. case LPFC_SLI_INTF_IF_TYPE_0:
  7678. uerr_sta_lo = readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
  7679. uerr_sta_hi = readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
  7680. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7681. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7682. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7683. "1423 HBA Unrecoverable error: "
  7684. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7685. "ue_mask_lo_reg=0x%x, "
  7686. "ue_mask_hi_reg=0x%x\n",
  7687. uerr_sta_lo, uerr_sta_hi,
  7688. phba->sli4_hba.ue_mask_lo,
  7689. phba->sli4_hba.ue_mask_hi);
  7690. phba->work_status[0] = uerr_sta_lo;
  7691. phba->work_status[1] = uerr_sta_hi;
  7692. phba->work_ha |= HA_ERATT;
  7693. phba->hba_flag |= HBA_ERATT_HANDLED;
  7694. return 1;
  7695. }
  7696. break;
  7697. case LPFC_SLI_INTF_IF_TYPE_2:
  7698. portstat_reg.word0 =
  7699. readl(phba->sli4_hba.u.if_type2.STATUSregaddr);
  7700. portsmphr = readl(phba->sli4_hba.PSMPHRregaddr);
  7701. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  7702. phba->work_status[0] =
  7703. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  7704. phba->work_status[1] =
  7705. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  7706. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7707. "2885 Port Error Detected: "
  7708. "port status reg 0x%x, "
  7709. "port smphr reg 0x%x, "
  7710. "error 1=0x%x, error 2=0x%x\n",
  7711. portstat_reg.word0,
  7712. portsmphr,
  7713. phba->work_status[0],
  7714. phba->work_status[1]);
  7715. phba->work_ha |= HA_ERATT;
  7716. phba->hba_flag |= HBA_ERATT_HANDLED;
  7717. return 1;
  7718. }
  7719. break;
  7720. case LPFC_SLI_INTF_IF_TYPE_1:
  7721. default:
  7722. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7723. "2886 HBA Error Attention on unsupported "
  7724. "if type %d.", if_type);
  7725. return 1;
  7726. }
  7727. return 0;
  7728. }
  7729. /**
  7730. * lpfc_sli_check_eratt - check error attention events
  7731. * @phba: Pointer to HBA context.
  7732. *
  7733. * This function is called from timer soft interrupt context to check HBA's
  7734. * error attention register bit for error attention events.
  7735. *
  7736. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7737. * Register and returns 0 otherwise.
  7738. **/
  7739. int
  7740. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7741. {
  7742. uint32_t ha_copy;
  7743. /* If somebody is waiting to handle an eratt, don't process it
  7744. * here. The brdkill function will do this.
  7745. */
  7746. if (phba->link_flag & LS_IGNORE_ERATT)
  7747. return 0;
  7748. /* Check if interrupt handler handles this ERATT */
  7749. spin_lock_irq(&phba->hbalock);
  7750. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7751. /* Interrupt handler has handled ERATT */
  7752. spin_unlock_irq(&phba->hbalock);
  7753. return 0;
  7754. }
  7755. /*
  7756. * If there is deferred error attention, do not check for error
  7757. * attention
  7758. */
  7759. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7760. spin_unlock_irq(&phba->hbalock);
  7761. return 0;
  7762. }
  7763. /* If PCI channel is offline, don't process it */
  7764. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7765. spin_unlock_irq(&phba->hbalock);
  7766. return 0;
  7767. }
  7768. switch (phba->sli_rev) {
  7769. case LPFC_SLI_REV2:
  7770. case LPFC_SLI_REV3:
  7771. /* Read chip Host Attention (HA) register */
  7772. ha_copy = lpfc_sli_eratt_read(phba);
  7773. break;
  7774. case LPFC_SLI_REV4:
  7775. /* Read device Uncoverable Error (UERR) registers */
  7776. ha_copy = lpfc_sli4_eratt_read(phba);
  7777. break;
  7778. default:
  7779. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7780. "0299 Invalid SLI revision (%d)\n",
  7781. phba->sli_rev);
  7782. ha_copy = 0;
  7783. break;
  7784. }
  7785. spin_unlock_irq(&phba->hbalock);
  7786. return ha_copy;
  7787. }
  7788. /**
  7789. * lpfc_intr_state_check - Check device state for interrupt handling
  7790. * @phba: Pointer to HBA context.
  7791. *
  7792. * This inline routine checks whether a device or its PCI slot is in a state
  7793. * that the interrupt should be handled.
  7794. *
  7795. * This function returns 0 if the device or the PCI slot is in a state that
  7796. * interrupt should be handled, otherwise -EIO.
  7797. */
  7798. static inline int
  7799. lpfc_intr_state_check(struct lpfc_hba *phba)
  7800. {
  7801. /* If the pci channel is offline, ignore all the interrupts */
  7802. if (unlikely(pci_channel_offline(phba->pcidev)))
  7803. return -EIO;
  7804. /* Update device level interrupt statistics */
  7805. phba->sli.slistat.sli_intr++;
  7806. /* Ignore all interrupts during initialization. */
  7807. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7808. return -EIO;
  7809. return 0;
  7810. }
  7811. /**
  7812. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7813. * @irq: Interrupt number.
  7814. * @dev_id: The device context pointer.
  7815. *
  7816. * This function is directly called from the PCI layer as an interrupt
  7817. * service routine when device with SLI-3 interface spec is enabled with
  7818. * MSI-X multi-message interrupt mode and there are slow-path events in
  7819. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7820. * interrupt mode, this function is called as part of the device-level
  7821. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7822. * is undergoing initialization, the interrupt handler will not process
  7823. * the interrupt. The link attention and ELS ring attention events are
  7824. * handled by the worker thread. The interrupt handler signals the worker
  7825. * thread and returns for these events. This function is called without
  7826. * any lock held. It gets the hbalock to access and update SLI data
  7827. * structures.
  7828. *
  7829. * This function returns IRQ_HANDLED when interrupt is handled else it
  7830. * returns IRQ_NONE.
  7831. **/
  7832. irqreturn_t
  7833. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7834. {
  7835. struct lpfc_hba *phba;
  7836. uint32_t ha_copy, hc_copy;
  7837. uint32_t work_ha_copy;
  7838. unsigned long status;
  7839. unsigned long iflag;
  7840. uint32_t control;
  7841. MAILBOX_t *mbox, *pmbox;
  7842. struct lpfc_vport *vport;
  7843. struct lpfc_nodelist *ndlp;
  7844. struct lpfc_dmabuf *mp;
  7845. LPFC_MBOXQ_t *pmb;
  7846. int rc;
  7847. /*
  7848. * Get the driver's phba structure from the dev_id and
  7849. * assume the HBA is not interrupting.
  7850. */
  7851. phba = (struct lpfc_hba *)dev_id;
  7852. if (unlikely(!phba))
  7853. return IRQ_NONE;
  7854. /*
  7855. * Stuff needs to be attented to when this function is invoked as an
  7856. * individual interrupt handler in MSI-X multi-message interrupt mode
  7857. */
  7858. if (phba->intr_type == MSIX) {
  7859. /* Check device state for handling interrupt */
  7860. if (lpfc_intr_state_check(phba))
  7861. return IRQ_NONE;
  7862. /* Need to read HA REG for slow-path events */
  7863. spin_lock_irqsave(&phba->hbalock, iflag);
  7864. ha_copy = readl(phba->HAregaddr);
  7865. /* If somebody is waiting to handle an eratt don't process it
  7866. * here. The brdkill function will do this.
  7867. */
  7868. if (phba->link_flag & LS_IGNORE_ERATT)
  7869. ha_copy &= ~HA_ERATT;
  7870. /* Check the need for handling ERATT in interrupt handler */
  7871. if (ha_copy & HA_ERATT) {
  7872. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7873. /* ERATT polling has handled ERATT */
  7874. ha_copy &= ~HA_ERATT;
  7875. else
  7876. /* Indicate interrupt handler handles ERATT */
  7877. phba->hba_flag |= HBA_ERATT_HANDLED;
  7878. }
  7879. /*
  7880. * If there is deferred error attention, do not check for any
  7881. * interrupt.
  7882. */
  7883. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7884. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7885. return IRQ_NONE;
  7886. }
  7887. /* Clear up only attention source related to slow-path */
  7888. hc_copy = readl(phba->HCregaddr);
  7889. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7890. HC_LAINT_ENA | HC_ERINT_ENA),
  7891. phba->HCregaddr);
  7892. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7893. phba->HAregaddr);
  7894. writel(hc_copy, phba->HCregaddr);
  7895. readl(phba->HAregaddr); /* flush */
  7896. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7897. } else
  7898. ha_copy = phba->ha_copy;
  7899. work_ha_copy = ha_copy & phba->work_ha_mask;
  7900. if (work_ha_copy) {
  7901. if (work_ha_copy & HA_LATT) {
  7902. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7903. /*
  7904. * Turn off Link Attention interrupts
  7905. * until CLEAR_LA done
  7906. */
  7907. spin_lock_irqsave(&phba->hbalock, iflag);
  7908. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7909. control = readl(phba->HCregaddr);
  7910. control &= ~HC_LAINT_ENA;
  7911. writel(control, phba->HCregaddr);
  7912. readl(phba->HCregaddr); /* flush */
  7913. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7914. }
  7915. else
  7916. work_ha_copy &= ~HA_LATT;
  7917. }
  7918. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7919. /*
  7920. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7921. * the only slow ring.
  7922. */
  7923. status = (work_ha_copy &
  7924. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7925. status >>= (4*LPFC_ELS_RING);
  7926. if (status & HA_RXMASK) {
  7927. spin_lock_irqsave(&phba->hbalock, iflag);
  7928. control = readl(phba->HCregaddr);
  7929. lpfc_debugfs_slow_ring_trc(phba,
  7930. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7931. control, status,
  7932. (uint32_t)phba->sli.slistat.sli_intr);
  7933. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7934. lpfc_debugfs_slow_ring_trc(phba,
  7935. "ISR Disable ring:"
  7936. "pwork:x%x hawork:x%x wait:x%x",
  7937. phba->work_ha, work_ha_copy,
  7938. (uint32_t)((unsigned long)
  7939. &phba->work_waitq));
  7940. control &=
  7941. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7942. writel(control, phba->HCregaddr);
  7943. readl(phba->HCregaddr); /* flush */
  7944. }
  7945. else {
  7946. lpfc_debugfs_slow_ring_trc(phba,
  7947. "ISR slow ring: pwork:"
  7948. "x%x hawork:x%x wait:x%x",
  7949. phba->work_ha, work_ha_copy,
  7950. (uint32_t)((unsigned long)
  7951. &phba->work_waitq));
  7952. }
  7953. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7954. }
  7955. }
  7956. spin_lock_irqsave(&phba->hbalock, iflag);
  7957. if (work_ha_copy & HA_ERATT) {
  7958. lpfc_sli_read_hs(phba);
  7959. /*
  7960. * Check if there is a deferred error condition
  7961. * is active
  7962. */
  7963. if ((HS_FFER1 & phba->work_hs) &&
  7964. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7965. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  7966. phba->work_hs)) {
  7967. phba->hba_flag |= DEFER_ERATT;
  7968. /* Clear all interrupt enable conditions */
  7969. writel(0, phba->HCregaddr);
  7970. readl(phba->HCregaddr);
  7971. }
  7972. }
  7973. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7974. pmb = phba->sli.mbox_active;
  7975. pmbox = &pmb->u.mb;
  7976. mbox = phba->mbox;
  7977. vport = pmb->vport;
  7978. /* First check out the status word */
  7979. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7980. if (pmbox->mbxOwner != OWN_HOST) {
  7981. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7982. /*
  7983. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7984. * mbxStatus <status>
  7985. */
  7986. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7987. LOG_SLI,
  7988. "(%d):0304 Stray Mailbox "
  7989. "Interrupt mbxCommand x%x "
  7990. "mbxStatus x%x\n",
  7991. (vport ? vport->vpi : 0),
  7992. pmbox->mbxCommand,
  7993. pmbox->mbxStatus);
  7994. /* clear mailbox attention bit */
  7995. work_ha_copy &= ~HA_MBATT;
  7996. } else {
  7997. phba->sli.mbox_active = NULL;
  7998. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7999. phba->last_completion_time = jiffies;
  8000. del_timer(&phba->sli.mbox_tmo);
  8001. if (pmb->mbox_cmpl) {
  8002. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  8003. MAILBOX_CMD_SIZE);
  8004. if (pmb->out_ext_byte_len &&
  8005. pmb->context2)
  8006. lpfc_sli_pcimem_bcopy(
  8007. phba->mbox_ext,
  8008. pmb->context2,
  8009. pmb->out_ext_byte_len);
  8010. }
  8011. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8012. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8013. lpfc_debugfs_disc_trc(vport,
  8014. LPFC_DISC_TRC_MBOX_VPORT,
  8015. "MBOX dflt rpi: : "
  8016. "status:x%x rpi:x%x",
  8017. (uint32_t)pmbox->mbxStatus,
  8018. pmbox->un.varWords[0], 0);
  8019. if (!pmbox->mbxStatus) {
  8020. mp = (struct lpfc_dmabuf *)
  8021. (pmb->context1);
  8022. ndlp = (struct lpfc_nodelist *)
  8023. pmb->context2;
  8024. /* Reg_LOGIN of dflt RPI was
  8025. * successful. new lets get
  8026. * rid of the RPI using the
  8027. * same mbox buffer.
  8028. */
  8029. lpfc_unreg_login(phba,
  8030. vport->vpi,
  8031. pmbox->un.varWords[0],
  8032. pmb);
  8033. pmb->mbox_cmpl =
  8034. lpfc_mbx_cmpl_dflt_rpi;
  8035. pmb->context1 = mp;
  8036. pmb->context2 = ndlp;
  8037. pmb->vport = vport;
  8038. rc = lpfc_sli_issue_mbox(phba,
  8039. pmb,
  8040. MBX_NOWAIT);
  8041. if (rc != MBX_BUSY)
  8042. lpfc_printf_log(phba,
  8043. KERN_ERR,
  8044. LOG_MBOX | LOG_SLI,
  8045. "0350 rc should have"
  8046. "been MBX_BUSY\n");
  8047. if (rc != MBX_NOT_FINISHED)
  8048. goto send_current_mbox;
  8049. }
  8050. }
  8051. spin_lock_irqsave(
  8052. &phba->pport->work_port_lock,
  8053. iflag);
  8054. phba->pport->work_port_events &=
  8055. ~WORKER_MBOX_TMO;
  8056. spin_unlock_irqrestore(
  8057. &phba->pport->work_port_lock,
  8058. iflag);
  8059. lpfc_mbox_cmpl_put(phba, pmb);
  8060. }
  8061. } else
  8062. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8063. if ((work_ha_copy & HA_MBATT) &&
  8064. (phba->sli.mbox_active == NULL)) {
  8065. send_current_mbox:
  8066. /* Process next mailbox command if there is one */
  8067. do {
  8068. rc = lpfc_sli_issue_mbox(phba, NULL,
  8069. MBX_NOWAIT);
  8070. } while (rc == MBX_NOT_FINISHED);
  8071. if (rc != MBX_SUCCESS)
  8072. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8073. LOG_SLI, "0349 rc should be "
  8074. "MBX_SUCCESS\n");
  8075. }
  8076. spin_lock_irqsave(&phba->hbalock, iflag);
  8077. phba->work_ha |= work_ha_copy;
  8078. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8079. lpfc_worker_wake_up(phba);
  8080. }
  8081. return IRQ_HANDLED;
  8082. } /* lpfc_sli_sp_intr_handler */
  8083. /**
  8084. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  8085. * @irq: Interrupt number.
  8086. * @dev_id: The device context pointer.
  8087. *
  8088. * This function is directly called from the PCI layer as an interrupt
  8089. * service routine when device with SLI-3 interface spec is enabled with
  8090. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8091. * ring event in the HBA. However, when the device is enabled with either
  8092. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8093. * device-level interrupt handler. When the PCI slot is in error recovery
  8094. * or the HBA is undergoing initialization, the interrupt handler will not
  8095. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8096. * the intrrupt context. This function is called without any lock held.
  8097. * It gets the hbalock to access and update SLI data structures.
  8098. *
  8099. * This function returns IRQ_HANDLED when interrupt is handled else it
  8100. * returns IRQ_NONE.
  8101. **/
  8102. irqreturn_t
  8103. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  8104. {
  8105. struct lpfc_hba *phba;
  8106. uint32_t ha_copy;
  8107. unsigned long status;
  8108. unsigned long iflag;
  8109. /* Get the driver's phba structure from the dev_id and
  8110. * assume the HBA is not interrupting.
  8111. */
  8112. phba = (struct lpfc_hba *) dev_id;
  8113. if (unlikely(!phba))
  8114. return IRQ_NONE;
  8115. /*
  8116. * Stuff needs to be attented to when this function is invoked as an
  8117. * individual interrupt handler in MSI-X multi-message interrupt mode
  8118. */
  8119. if (phba->intr_type == MSIX) {
  8120. /* Check device state for handling interrupt */
  8121. if (lpfc_intr_state_check(phba))
  8122. return IRQ_NONE;
  8123. /* Need to read HA REG for FCP ring and other ring events */
  8124. ha_copy = readl(phba->HAregaddr);
  8125. /* Clear up only attention source related to fast-path */
  8126. spin_lock_irqsave(&phba->hbalock, iflag);
  8127. /*
  8128. * If there is deferred error attention, do not check for
  8129. * any interrupt.
  8130. */
  8131. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8132. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8133. return IRQ_NONE;
  8134. }
  8135. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  8136. phba->HAregaddr);
  8137. readl(phba->HAregaddr); /* flush */
  8138. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8139. } else
  8140. ha_copy = phba->ha_copy;
  8141. /*
  8142. * Process all events on FCP ring. Take the optimized path for FCP IO.
  8143. */
  8144. ha_copy &= ~(phba->work_ha_mask);
  8145. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8146. status >>= (4*LPFC_FCP_RING);
  8147. if (status & HA_RXMASK)
  8148. lpfc_sli_handle_fast_ring_event(phba,
  8149. &phba->sli.ring[LPFC_FCP_RING],
  8150. status);
  8151. if (phba->cfg_multi_ring_support == 2) {
  8152. /*
  8153. * Process all events on extra ring. Take the optimized path
  8154. * for extra ring IO.
  8155. */
  8156. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8157. status >>= (4*LPFC_EXTRA_RING);
  8158. if (status & HA_RXMASK) {
  8159. lpfc_sli_handle_fast_ring_event(phba,
  8160. &phba->sli.ring[LPFC_EXTRA_RING],
  8161. status);
  8162. }
  8163. }
  8164. return IRQ_HANDLED;
  8165. } /* lpfc_sli_fp_intr_handler */
  8166. /**
  8167. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  8168. * @irq: Interrupt number.
  8169. * @dev_id: The device context pointer.
  8170. *
  8171. * This function is the HBA device-level interrupt handler to device with
  8172. * SLI-3 interface spec, called from the PCI layer when either MSI or
  8173. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  8174. * requires driver attention. This function invokes the slow-path interrupt
  8175. * attention handling function and fast-path interrupt attention handling
  8176. * function in turn to process the relevant HBA attention events. This
  8177. * function is called without any lock held. It gets the hbalock to access
  8178. * and update SLI data structures.
  8179. *
  8180. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8181. * returns IRQ_NONE.
  8182. **/
  8183. irqreturn_t
  8184. lpfc_sli_intr_handler(int irq, void *dev_id)
  8185. {
  8186. struct lpfc_hba *phba;
  8187. irqreturn_t sp_irq_rc, fp_irq_rc;
  8188. unsigned long status1, status2;
  8189. uint32_t hc_copy;
  8190. /*
  8191. * Get the driver's phba structure from the dev_id and
  8192. * assume the HBA is not interrupting.
  8193. */
  8194. phba = (struct lpfc_hba *) dev_id;
  8195. if (unlikely(!phba))
  8196. return IRQ_NONE;
  8197. /* Check device state for handling interrupt */
  8198. if (lpfc_intr_state_check(phba))
  8199. return IRQ_NONE;
  8200. spin_lock(&phba->hbalock);
  8201. phba->ha_copy = readl(phba->HAregaddr);
  8202. if (unlikely(!phba->ha_copy)) {
  8203. spin_unlock(&phba->hbalock);
  8204. return IRQ_NONE;
  8205. } else if (phba->ha_copy & HA_ERATT) {
  8206. if (phba->hba_flag & HBA_ERATT_HANDLED)
  8207. /* ERATT polling has handled ERATT */
  8208. phba->ha_copy &= ~HA_ERATT;
  8209. else
  8210. /* Indicate interrupt handler handles ERATT */
  8211. phba->hba_flag |= HBA_ERATT_HANDLED;
  8212. }
  8213. /*
  8214. * If there is deferred error attention, do not check for any interrupt.
  8215. */
  8216. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8217. spin_unlock(&phba->hbalock);
  8218. return IRQ_NONE;
  8219. }
  8220. /* Clear attention sources except link and error attentions */
  8221. hc_copy = readl(phba->HCregaddr);
  8222. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  8223. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  8224. phba->HCregaddr);
  8225. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  8226. writel(hc_copy, phba->HCregaddr);
  8227. readl(phba->HAregaddr); /* flush */
  8228. spin_unlock(&phba->hbalock);
  8229. /*
  8230. * Invokes slow-path host attention interrupt handling as appropriate.
  8231. */
  8232. /* status of events with mailbox and link attention */
  8233. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  8234. /* status of events with ELS ring */
  8235. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  8236. status2 >>= (4*LPFC_ELS_RING);
  8237. if (status1 || (status2 & HA_RXMASK))
  8238. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  8239. else
  8240. sp_irq_rc = IRQ_NONE;
  8241. /*
  8242. * Invoke fast-path host attention interrupt handling as appropriate.
  8243. */
  8244. /* status of events with FCP ring */
  8245. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8246. status1 >>= (4*LPFC_FCP_RING);
  8247. /* status of events with extra ring */
  8248. if (phba->cfg_multi_ring_support == 2) {
  8249. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8250. status2 >>= (4*LPFC_EXTRA_RING);
  8251. } else
  8252. status2 = 0;
  8253. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  8254. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  8255. else
  8256. fp_irq_rc = IRQ_NONE;
  8257. /* Return device-level interrupt handling status */
  8258. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  8259. } /* lpfc_sli_intr_handler */
  8260. /**
  8261. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  8262. * @phba: pointer to lpfc hba data structure.
  8263. *
  8264. * This routine is invoked by the worker thread to process all the pending
  8265. * SLI4 FCP abort XRI events.
  8266. **/
  8267. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  8268. {
  8269. struct lpfc_cq_event *cq_event;
  8270. /* First, declare the fcp xri abort event has been handled */
  8271. spin_lock_irq(&phba->hbalock);
  8272. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  8273. spin_unlock_irq(&phba->hbalock);
  8274. /* Now, handle all the fcp xri abort events */
  8275. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  8276. /* Get the first event from the head of the event queue */
  8277. spin_lock_irq(&phba->hbalock);
  8278. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  8279. cq_event, struct lpfc_cq_event, list);
  8280. spin_unlock_irq(&phba->hbalock);
  8281. /* Notify aborted XRI for FCP work queue */
  8282. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8283. /* Free the event processed back to the free pool */
  8284. lpfc_sli4_cq_event_release(phba, cq_event);
  8285. }
  8286. }
  8287. /**
  8288. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  8289. * @phba: pointer to lpfc hba data structure.
  8290. *
  8291. * This routine is invoked by the worker thread to process all the pending
  8292. * SLI4 els abort xri events.
  8293. **/
  8294. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  8295. {
  8296. struct lpfc_cq_event *cq_event;
  8297. /* First, declare the els xri abort event has been handled */
  8298. spin_lock_irq(&phba->hbalock);
  8299. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  8300. spin_unlock_irq(&phba->hbalock);
  8301. /* Now, handle all the els xri abort events */
  8302. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  8303. /* Get the first event from the head of the event queue */
  8304. spin_lock_irq(&phba->hbalock);
  8305. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  8306. cq_event, struct lpfc_cq_event, list);
  8307. spin_unlock_irq(&phba->hbalock);
  8308. /* Notify aborted XRI for ELS work queue */
  8309. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8310. /* Free the event processed back to the free pool */
  8311. lpfc_sli4_cq_event_release(phba, cq_event);
  8312. }
  8313. }
  8314. /**
  8315. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  8316. * @phba: pointer to lpfc hba data structure
  8317. * @pIocbIn: pointer to the rspiocbq
  8318. * @pIocbOut: pointer to the cmdiocbq
  8319. * @wcqe: pointer to the complete wcqe
  8320. *
  8321. * This routine transfers the fields of a command iocbq to a response iocbq
  8322. * by copying all the IOCB fields from command iocbq and transferring the
  8323. * completion status information from the complete wcqe.
  8324. **/
  8325. static void
  8326. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  8327. struct lpfc_iocbq *pIocbIn,
  8328. struct lpfc_iocbq *pIocbOut,
  8329. struct lpfc_wcqe_complete *wcqe)
  8330. {
  8331. unsigned long iflags;
  8332. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  8333. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  8334. sizeof(struct lpfc_iocbq) - offset);
  8335. /* Map WCQE parameters into irspiocb parameters */
  8336. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  8337. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  8338. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  8339. pIocbIn->iocb.un.fcpi.fcpi_parm =
  8340. pIocbOut->iocb.un.fcpi.fcpi_parm -
  8341. wcqe->total_data_placed;
  8342. else
  8343. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8344. else {
  8345. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8346. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  8347. }
  8348. /* Pick up HBA exchange busy condition */
  8349. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  8350. spin_lock_irqsave(&phba->hbalock, iflags);
  8351. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  8352. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8353. }
  8354. }
  8355. /**
  8356. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  8357. * @phba: Pointer to HBA context object.
  8358. * @wcqe: Pointer to work-queue completion queue entry.
  8359. *
  8360. * This routine handles an ELS work-queue completion event and construct
  8361. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  8362. * discovery engine to handle.
  8363. *
  8364. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  8365. **/
  8366. static struct lpfc_iocbq *
  8367. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  8368. struct lpfc_iocbq *irspiocbq)
  8369. {
  8370. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8371. struct lpfc_iocbq *cmdiocbq;
  8372. struct lpfc_wcqe_complete *wcqe;
  8373. unsigned long iflags;
  8374. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  8375. spin_lock_irqsave(&phba->hbalock, iflags);
  8376. pring->stats.iocb_event++;
  8377. /* Look up the ELS command IOCB and create pseudo response IOCB */
  8378. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8379. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8380. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8381. if (unlikely(!cmdiocbq)) {
  8382. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8383. "0386 ELS complete with no corresponding "
  8384. "cmdiocb: iotag (%d)\n",
  8385. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8386. lpfc_sli_release_iocbq(phba, irspiocbq);
  8387. return NULL;
  8388. }
  8389. /* Fake the irspiocbq and copy necessary response information */
  8390. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  8391. return irspiocbq;
  8392. }
  8393. /**
  8394. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  8395. * @phba: Pointer to HBA context object.
  8396. * @cqe: Pointer to mailbox completion queue entry.
  8397. *
  8398. * This routine process a mailbox completion queue entry with asynchrous
  8399. * event.
  8400. *
  8401. * Return: true if work posted to worker thread, otherwise false.
  8402. **/
  8403. static bool
  8404. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8405. {
  8406. struct lpfc_cq_event *cq_event;
  8407. unsigned long iflags;
  8408. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8409. "0392 Async Event: word0:x%x, word1:x%x, "
  8410. "word2:x%x, word3:x%x\n", mcqe->word0,
  8411. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  8412. /* Allocate a new internal CQ_EVENT entry */
  8413. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8414. if (!cq_event) {
  8415. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8416. "0394 Failed to allocate CQ_EVENT entry\n");
  8417. return false;
  8418. }
  8419. /* Move the CQE into an asynchronous event entry */
  8420. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  8421. spin_lock_irqsave(&phba->hbalock, iflags);
  8422. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  8423. /* Set the async event flag */
  8424. phba->hba_flag |= ASYNC_EVENT;
  8425. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8426. return true;
  8427. }
  8428. /**
  8429. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  8430. * @phba: Pointer to HBA context object.
  8431. * @cqe: Pointer to mailbox completion queue entry.
  8432. *
  8433. * This routine process a mailbox completion queue entry with mailbox
  8434. * completion event.
  8435. *
  8436. * Return: true if work posted to worker thread, otherwise false.
  8437. **/
  8438. static bool
  8439. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8440. {
  8441. uint32_t mcqe_status;
  8442. MAILBOX_t *mbox, *pmbox;
  8443. struct lpfc_mqe *mqe;
  8444. struct lpfc_vport *vport;
  8445. struct lpfc_nodelist *ndlp;
  8446. struct lpfc_dmabuf *mp;
  8447. unsigned long iflags;
  8448. LPFC_MBOXQ_t *pmb;
  8449. bool workposted = false;
  8450. int rc;
  8451. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  8452. if (!bf_get(lpfc_trailer_completed, mcqe))
  8453. goto out_no_mqe_complete;
  8454. /* Get the reference to the active mbox command */
  8455. spin_lock_irqsave(&phba->hbalock, iflags);
  8456. pmb = phba->sli.mbox_active;
  8457. if (unlikely(!pmb)) {
  8458. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  8459. "1832 No pending MBOX command to handle\n");
  8460. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8461. goto out_no_mqe_complete;
  8462. }
  8463. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8464. mqe = &pmb->u.mqe;
  8465. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  8466. mbox = phba->mbox;
  8467. vport = pmb->vport;
  8468. /* Reset heartbeat timer */
  8469. phba->last_completion_time = jiffies;
  8470. del_timer(&phba->sli.mbox_tmo);
  8471. /* Move mbox data to caller's mailbox region, do endian swapping */
  8472. if (pmb->mbox_cmpl && mbox)
  8473. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  8474. /* Set the mailbox status with SLI4 range 0x4000 */
  8475. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  8476. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  8477. bf_set(lpfc_mqe_status, mqe,
  8478. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  8479. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8480. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8481. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  8482. "MBOX dflt rpi: status:x%x rpi:x%x",
  8483. mcqe_status,
  8484. pmbox->un.varWords[0], 0);
  8485. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  8486. mp = (struct lpfc_dmabuf *)(pmb->context1);
  8487. ndlp = (struct lpfc_nodelist *)pmb->context2;
  8488. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  8489. * RID of the PPI using the same mbox buffer.
  8490. */
  8491. lpfc_unreg_login(phba, vport->vpi,
  8492. pmbox->un.varWords[0], pmb);
  8493. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  8494. pmb->context1 = mp;
  8495. pmb->context2 = ndlp;
  8496. pmb->vport = vport;
  8497. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  8498. if (rc != MBX_BUSY)
  8499. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8500. LOG_SLI, "0385 rc should "
  8501. "have been MBX_BUSY\n");
  8502. if (rc != MBX_NOT_FINISHED)
  8503. goto send_current_mbox;
  8504. }
  8505. }
  8506. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  8507. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8508. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  8509. /* There is mailbox completion work to do */
  8510. spin_lock_irqsave(&phba->hbalock, iflags);
  8511. __lpfc_mbox_cmpl_put(phba, pmb);
  8512. phba->work_ha |= HA_MBATT;
  8513. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8514. workposted = true;
  8515. send_current_mbox:
  8516. spin_lock_irqsave(&phba->hbalock, iflags);
  8517. /* Release the mailbox command posting token */
  8518. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8519. /* Setting active mailbox pointer need to be in sync to flag clear */
  8520. phba->sli.mbox_active = NULL;
  8521. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8522. /* Wake up worker thread to post the next pending mailbox command */
  8523. lpfc_worker_wake_up(phba);
  8524. out_no_mqe_complete:
  8525. if (bf_get(lpfc_trailer_consumed, mcqe))
  8526. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  8527. return workposted;
  8528. }
  8529. /**
  8530. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  8531. * @phba: Pointer to HBA context object.
  8532. * @cqe: Pointer to mailbox completion queue entry.
  8533. *
  8534. * This routine process a mailbox completion queue entry, it invokes the
  8535. * proper mailbox complete handling or asynchrous event handling routine
  8536. * according to the MCQE's async bit.
  8537. *
  8538. * Return: true if work posted to worker thread, otherwise false.
  8539. **/
  8540. static bool
  8541. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8542. {
  8543. struct lpfc_mcqe mcqe;
  8544. bool workposted;
  8545. /* Copy the mailbox MCQE and convert endian order as needed */
  8546. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8547. /* Invoke the proper event handling routine */
  8548. if (!bf_get(lpfc_trailer_async, &mcqe))
  8549. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8550. else
  8551. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8552. return workposted;
  8553. }
  8554. /**
  8555. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8556. * @phba: Pointer to HBA context object.
  8557. * @wcqe: Pointer to work-queue completion queue entry.
  8558. *
  8559. * This routine handles an ELS work-queue completion event.
  8560. *
  8561. * Return: true if work posted to worker thread, otherwise false.
  8562. **/
  8563. static bool
  8564. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8565. struct lpfc_wcqe_complete *wcqe)
  8566. {
  8567. struct lpfc_iocbq *irspiocbq;
  8568. unsigned long iflags;
  8569. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8570. /* Get an irspiocbq for later ELS response processing use */
  8571. irspiocbq = lpfc_sli_get_iocbq(phba);
  8572. if (!irspiocbq) {
  8573. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8574. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8575. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8576. pring->txq_cnt, phba->iocb_cnt,
  8577. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8578. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8579. return false;
  8580. }
  8581. /* Save off the slow-path queue event for work thread to process */
  8582. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8583. spin_lock_irqsave(&phba->hbalock, iflags);
  8584. list_add_tail(&irspiocbq->cq_event.list,
  8585. &phba->sli4_hba.sp_queue_event);
  8586. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8587. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8588. return true;
  8589. }
  8590. /**
  8591. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8592. * @phba: Pointer to HBA context object.
  8593. * @wcqe: Pointer to work-queue completion queue entry.
  8594. *
  8595. * This routine handles slow-path WQ entry comsumed event by invoking the
  8596. * proper WQ release routine to the slow-path WQ.
  8597. **/
  8598. static void
  8599. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8600. struct lpfc_wcqe_release *wcqe)
  8601. {
  8602. /* Check for the slow-path ELS work queue */
  8603. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8604. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8605. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8606. else
  8607. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8608. "2579 Slow-path wqe consume event carries "
  8609. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8610. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8611. phba->sli4_hba.els_wq->queue_id);
  8612. }
  8613. /**
  8614. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8615. * @phba: Pointer to HBA context object.
  8616. * @cq: Pointer to a WQ completion queue.
  8617. * @wcqe: Pointer to work-queue completion queue entry.
  8618. *
  8619. * This routine handles an XRI abort event.
  8620. *
  8621. * Return: true if work posted to worker thread, otherwise false.
  8622. **/
  8623. static bool
  8624. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8625. struct lpfc_queue *cq,
  8626. struct sli4_wcqe_xri_aborted *wcqe)
  8627. {
  8628. bool workposted = false;
  8629. struct lpfc_cq_event *cq_event;
  8630. unsigned long iflags;
  8631. /* Allocate a new internal CQ_EVENT entry */
  8632. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8633. if (!cq_event) {
  8634. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8635. "0602 Failed to allocate CQ_EVENT entry\n");
  8636. return false;
  8637. }
  8638. /* Move the CQE into the proper xri abort event list */
  8639. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8640. switch (cq->subtype) {
  8641. case LPFC_FCP:
  8642. spin_lock_irqsave(&phba->hbalock, iflags);
  8643. list_add_tail(&cq_event->list,
  8644. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8645. /* Set the fcp xri abort event flag */
  8646. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8647. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8648. workposted = true;
  8649. break;
  8650. case LPFC_ELS:
  8651. spin_lock_irqsave(&phba->hbalock, iflags);
  8652. list_add_tail(&cq_event->list,
  8653. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8654. /* Set the els xri abort event flag */
  8655. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8656. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8657. workposted = true;
  8658. break;
  8659. default:
  8660. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8661. "0603 Invalid work queue CQE subtype (x%x)\n",
  8662. cq->subtype);
  8663. workposted = false;
  8664. break;
  8665. }
  8666. return workposted;
  8667. }
  8668. /**
  8669. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8670. * @phba: Pointer to HBA context object.
  8671. * @rcqe: Pointer to receive-queue completion queue entry.
  8672. *
  8673. * This routine process a receive-queue completion queue entry.
  8674. *
  8675. * Return: true if work posted to worker thread, otherwise false.
  8676. **/
  8677. static bool
  8678. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8679. {
  8680. bool workposted = false;
  8681. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8682. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8683. struct hbq_dmabuf *dma_buf;
  8684. uint32_t status;
  8685. unsigned long iflags;
  8686. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8687. goto out;
  8688. status = bf_get(lpfc_rcqe_status, rcqe);
  8689. switch (status) {
  8690. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8691. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8692. "2537 Receive Frame Truncated!!\n");
  8693. case FC_STATUS_RQ_SUCCESS:
  8694. lpfc_sli4_rq_release(hrq, drq);
  8695. spin_lock_irqsave(&phba->hbalock, iflags);
  8696. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8697. if (!dma_buf) {
  8698. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8699. goto out;
  8700. }
  8701. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8702. /* save off the frame for the word thread to process */
  8703. list_add_tail(&dma_buf->cq_event.list,
  8704. &phba->sli4_hba.sp_queue_event);
  8705. /* Frame received */
  8706. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8707. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8708. workposted = true;
  8709. break;
  8710. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8711. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8712. /* Post more buffers if possible */
  8713. spin_lock_irqsave(&phba->hbalock, iflags);
  8714. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8715. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8716. workposted = true;
  8717. break;
  8718. }
  8719. out:
  8720. return workposted;
  8721. }
  8722. /**
  8723. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8724. * @phba: Pointer to HBA context object.
  8725. * @cq: Pointer to the completion queue.
  8726. * @wcqe: Pointer to a completion queue entry.
  8727. *
  8728. * This routine process a slow-path work-queue or recieve queue completion queue
  8729. * entry.
  8730. *
  8731. * Return: true if work posted to worker thread, otherwise false.
  8732. **/
  8733. static bool
  8734. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8735. struct lpfc_cqe *cqe)
  8736. {
  8737. struct lpfc_cqe cqevt;
  8738. bool workposted = false;
  8739. /* Copy the work queue CQE and convert endian order if needed */
  8740. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8741. /* Check and process for different type of WCQE and dispatch */
  8742. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8743. case CQE_CODE_COMPL_WQE:
  8744. /* Process the WQ/RQ complete event */
  8745. phba->last_completion_time = jiffies;
  8746. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8747. (struct lpfc_wcqe_complete *)&cqevt);
  8748. break;
  8749. case CQE_CODE_RELEASE_WQE:
  8750. /* Process the WQ release event */
  8751. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8752. (struct lpfc_wcqe_release *)&cqevt);
  8753. break;
  8754. case CQE_CODE_XRI_ABORTED:
  8755. /* Process the WQ XRI abort event */
  8756. phba->last_completion_time = jiffies;
  8757. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8758. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8759. break;
  8760. case CQE_CODE_RECEIVE:
  8761. /* Process the RQ event */
  8762. phba->last_completion_time = jiffies;
  8763. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8764. (struct lpfc_rcqe *)&cqevt);
  8765. break;
  8766. default:
  8767. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8768. "0388 Not a valid WCQE code: x%x\n",
  8769. bf_get(lpfc_cqe_code, &cqevt));
  8770. break;
  8771. }
  8772. return workposted;
  8773. }
  8774. /**
  8775. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8776. * @phba: Pointer to HBA context object.
  8777. * @eqe: Pointer to fast-path event queue entry.
  8778. *
  8779. * This routine process a event queue entry from the slow-path event queue.
  8780. * It will check the MajorCode and MinorCode to determine this is for a
  8781. * completion event on a completion queue, if not, an error shall be logged
  8782. * and just return. Otherwise, it will get to the corresponding completion
  8783. * queue and process all the entries on that completion queue, rearm the
  8784. * completion queue, and then return.
  8785. *
  8786. **/
  8787. static void
  8788. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8789. {
  8790. struct lpfc_queue *cq = NULL, *childq, *speq;
  8791. struct lpfc_cqe *cqe;
  8792. bool workposted = false;
  8793. int ecount = 0;
  8794. uint16_t cqid;
  8795. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8796. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8797. "0359 Not a valid slow-path completion "
  8798. "event: majorcode=x%x, minorcode=x%x\n",
  8799. bf_get_le32(lpfc_eqe_major_code, eqe),
  8800. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8801. return;
  8802. }
  8803. /* Get the reference to the corresponding CQ */
  8804. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8805. /* Search for completion queue pointer matching this cqid */
  8806. speq = phba->sli4_hba.sp_eq;
  8807. list_for_each_entry(childq, &speq->child_list, list) {
  8808. if (childq->queue_id == cqid) {
  8809. cq = childq;
  8810. break;
  8811. }
  8812. }
  8813. if (unlikely(!cq)) {
  8814. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8815. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8816. "0365 Slow-path CQ identifier "
  8817. "(%d) does not exist\n", cqid);
  8818. return;
  8819. }
  8820. /* Process all the entries to the CQ */
  8821. switch (cq->type) {
  8822. case LPFC_MCQ:
  8823. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8824. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8825. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8826. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8827. }
  8828. break;
  8829. case LPFC_WCQ:
  8830. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8831. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8832. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8833. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8834. }
  8835. break;
  8836. default:
  8837. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8838. "0370 Invalid completion queue type (%d)\n",
  8839. cq->type);
  8840. return;
  8841. }
  8842. /* Catch the no cq entry condition, log an error */
  8843. if (unlikely(ecount == 0))
  8844. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8845. "0371 No entry from the CQ: identifier "
  8846. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8847. /* In any case, flash and re-arm the RCQ */
  8848. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8849. /* wake up worker thread if there are works to be done */
  8850. if (workposted)
  8851. lpfc_worker_wake_up(phba);
  8852. }
  8853. /**
  8854. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8855. * @eqe: Pointer to fast-path completion queue entry.
  8856. *
  8857. * This routine process a fast-path work queue completion entry from fast-path
  8858. * event queue for FCP command response completion.
  8859. **/
  8860. static void
  8861. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8862. struct lpfc_wcqe_complete *wcqe)
  8863. {
  8864. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8865. struct lpfc_iocbq *cmdiocbq;
  8866. struct lpfc_iocbq irspiocbq;
  8867. unsigned long iflags;
  8868. spin_lock_irqsave(&phba->hbalock, iflags);
  8869. pring->stats.iocb_event++;
  8870. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8871. /* Check for response status */
  8872. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8873. /* If resource errors reported from HBA, reduce queue
  8874. * depth of the SCSI device.
  8875. */
  8876. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8877. IOSTAT_LOCAL_REJECT) &&
  8878. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8879. phba->lpfc_rampdown_queue_depth(phba);
  8880. }
  8881. /* Log the error status */
  8882. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8883. "0373 FCP complete error: status=x%x, "
  8884. "hw_status=x%x, total_data_specified=%d, "
  8885. "parameter=x%x, word3=x%x\n",
  8886. bf_get(lpfc_wcqe_c_status, wcqe),
  8887. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8888. wcqe->total_data_placed, wcqe->parameter,
  8889. wcqe->word3);
  8890. }
  8891. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8892. spin_lock_irqsave(&phba->hbalock, iflags);
  8893. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8894. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8895. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8896. if (unlikely(!cmdiocbq)) {
  8897. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8898. "0374 FCP complete with no corresponding "
  8899. "cmdiocb: iotag (%d)\n",
  8900. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8901. return;
  8902. }
  8903. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8904. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8905. "0375 FCP cmdiocb not callback function "
  8906. "iotag: (%d)\n",
  8907. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8908. return;
  8909. }
  8910. /* Fake the irspiocb and copy necessary response information */
  8911. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8912. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8913. spin_lock_irqsave(&phba->hbalock, iflags);
  8914. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8915. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8916. }
  8917. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8918. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8919. }
  8920. /**
  8921. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8922. * @phba: Pointer to HBA context object.
  8923. * @cq: Pointer to completion queue.
  8924. * @wcqe: Pointer to work-queue completion queue entry.
  8925. *
  8926. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8927. * proper WQ release routine to the slow-path WQ.
  8928. **/
  8929. static void
  8930. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8931. struct lpfc_wcqe_release *wcqe)
  8932. {
  8933. struct lpfc_queue *childwq;
  8934. bool wqid_matched = false;
  8935. uint16_t fcp_wqid;
  8936. /* Check for fast-path FCP work queue release */
  8937. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8938. list_for_each_entry(childwq, &cq->child_list, list) {
  8939. if (childwq->queue_id == fcp_wqid) {
  8940. lpfc_sli4_wq_release(childwq,
  8941. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8942. wqid_matched = true;
  8943. break;
  8944. }
  8945. }
  8946. /* Report warning log message if no match found */
  8947. if (wqid_matched != true)
  8948. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8949. "2580 Fast-path wqe consume event carries "
  8950. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8951. }
  8952. /**
  8953. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8954. * @cq: Pointer to the completion queue.
  8955. * @eqe: Pointer to fast-path completion queue entry.
  8956. *
  8957. * This routine process a fast-path work queue completion entry from fast-path
  8958. * event queue for FCP command response completion.
  8959. **/
  8960. static int
  8961. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8962. struct lpfc_cqe *cqe)
  8963. {
  8964. struct lpfc_wcqe_release wcqe;
  8965. bool workposted = false;
  8966. /* Copy the work queue CQE and convert endian order if needed */
  8967. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8968. /* Check and process for different type of WCQE and dispatch */
  8969. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8970. case CQE_CODE_COMPL_WQE:
  8971. /* Process the WQ complete event */
  8972. phba->last_completion_time = jiffies;
  8973. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8974. (struct lpfc_wcqe_complete *)&wcqe);
  8975. break;
  8976. case CQE_CODE_RELEASE_WQE:
  8977. /* Process the WQ release event */
  8978. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8979. (struct lpfc_wcqe_release *)&wcqe);
  8980. break;
  8981. case CQE_CODE_XRI_ABORTED:
  8982. /* Process the WQ XRI abort event */
  8983. phba->last_completion_time = jiffies;
  8984. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8985. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8986. break;
  8987. default:
  8988. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8989. "0144 Not a valid WCQE code: x%x\n",
  8990. bf_get(lpfc_wcqe_c_code, &wcqe));
  8991. break;
  8992. }
  8993. return workposted;
  8994. }
  8995. /**
  8996. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8997. * @phba: Pointer to HBA context object.
  8998. * @eqe: Pointer to fast-path event queue entry.
  8999. *
  9000. * This routine process a event queue entry from the fast-path event queue.
  9001. * It will check the MajorCode and MinorCode to determine this is for a
  9002. * completion event on a completion queue, if not, an error shall be logged
  9003. * and just return. Otherwise, it will get to the corresponding completion
  9004. * queue and process all the entries on the completion queue, rearm the
  9005. * completion queue, and then return.
  9006. **/
  9007. static void
  9008. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  9009. uint32_t fcp_cqidx)
  9010. {
  9011. struct lpfc_queue *cq;
  9012. struct lpfc_cqe *cqe;
  9013. bool workposted = false;
  9014. uint16_t cqid;
  9015. int ecount = 0;
  9016. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  9017. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9018. "0366 Not a valid fast-path completion "
  9019. "event: majorcode=x%x, minorcode=x%x\n",
  9020. bf_get_le32(lpfc_eqe_major_code, eqe),
  9021. bf_get_le32(lpfc_eqe_minor_code, eqe));
  9022. return;
  9023. }
  9024. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  9025. if (unlikely(!cq)) {
  9026. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  9027. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9028. "0367 Fast-path completion queue "
  9029. "does not exist\n");
  9030. return;
  9031. }
  9032. /* Get the reference to the corresponding CQ */
  9033. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  9034. if (unlikely(cqid != cq->queue_id)) {
  9035. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9036. "0368 Miss-matched fast-path completion "
  9037. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  9038. cqid, cq->queue_id);
  9039. return;
  9040. }
  9041. /* Process all the entries to the CQ */
  9042. while ((cqe = lpfc_sli4_cq_get(cq))) {
  9043. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  9044. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9045. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  9046. }
  9047. /* Catch the no cq entry condition */
  9048. if (unlikely(ecount == 0))
  9049. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9050. "0369 No entry from fast-path completion "
  9051. "queue fcpcqid=%d\n", cq->queue_id);
  9052. /* In any case, flash and re-arm the CQ */
  9053. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  9054. /* wake up worker thread if there are works to be done */
  9055. if (workposted)
  9056. lpfc_worker_wake_up(phba);
  9057. }
  9058. static void
  9059. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9060. {
  9061. struct lpfc_eqe *eqe;
  9062. /* walk all the EQ entries and drop on the floor */
  9063. while ((eqe = lpfc_sli4_eq_get(eq)))
  9064. ;
  9065. /* Clear and re-arm the EQ */
  9066. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  9067. }
  9068. /**
  9069. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  9070. * @irq: Interrupt number.
  9071. * @dev_id: The device context pointer.
  9072. *
  9073. * This function is directly called from the PCI layer as an interrupt
  9074. * service routine when device with SLI-4 interface spec is enabled with
  9075. * MSI-X multi-message interrupt mode and there are slow-path events in
  9076. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9077. * interrupt mode, this function is called as part of the device-level
  9078. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  9079. * undergoing initialization, the interrupt handler will not process the
  9080. * interrupt. The link attention and ELS ring attention events are handled
  9081. * by the worker thread. The interrupt handler signals the worker thread
  9082. * and returns for these events. This function is called without any lock
  9083. * held. It gets the hbalock to access and update SLI data structures.
  9084. *
  9085. * This function returns IRQ_HANDLED when interrupt is handled else it
  9086. * returns IRQ_NONE.
  9087. **/
  9088. irqreturn_t
  9089. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  9090. {
  9091. struct lpfc_hba *phba;
  9092. struct lpfc_queue *speq;
  9093. struct lpfc_eqe *eqe;
  9094. unsigned long iflag;
  9095. int ecount = 0;
  9096. /*
  9097. * Get the driver's phba structure from the dev_id
  9098. */
  9099. phba = (struct lpfc_hba *)dev_id;
  9100. if (unlikely(!phba))
  9101. return IRQ_NONE;
  9102. /* Get to the EQ struct associated with this vector */
  9103. speq = phba->sli4_hba.sp_eq;
  9104. /* Check device state for handling interrupt */
  9105. if (unlikely(lpfc_intr_state_check(phba))) {
  9106. /* Check again for link_state with lock held */
  9107. spin_lock_irqsave(&phba->hbalock, iflag);
  9108. if (phba->link_state < LPFC_LINK_DOWN)
  9109. /* Flush, clear interrupt, and rearm the EQ */
  9110. lpfc_sli4_eq_flush(phba, speq);
  9111. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9112. return IRQ_NONE;
  9113. }
  9114. /*
  9115. * Process all the event on FCP slow-path EQ
  9116. */
  9117. while ((eqe = lpfc_sli4_eq_get(speq))) {
  9118. lpfc_sli4_sp_handle_eqe(phba, eqe);
  9119. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9120. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  9121. }
  9122. /* Always clear and re-arm the slow-path EQ */
  9123. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  9124. /* Catch the no cq entry condition */
  9125. if (unlikely(ecount == 0)) {
  9126. if (phba->intr_type == MSIX)
  9127. /* MSI-X treated interrupt served as no EQ share INT */
  9128. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9129. "0357 MSI-X interrupt with no EQE\n");
  9130. else
  9131. /* Non MSI-X treated on interrupt as EQ share INT */
  9132. return IRQ_NONE;
  9133. }
  9134. return IRQ_HANDLED;
  9135. } /* lpfc_sli4_sp_intr_handler */
  9136. /**
  9137. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  9138. * @irq: Interrupt number.
  9139. * @dev_id: The device context pointer.
  9140. *
  9141. * This function is directly called from the PCI layer as an interrupt
  9142. * service routine when device with SLI-4 interface spec is enabled with
  9143. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9144. * ring event in the HBA. However, when the device is enabled with either
  9145. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9146. * device-level interrupt handler. When the PCI slot is in error recovery
  9147. * or the HBA is undergoing initialization, the interrupt handler will not
  9148. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9149. * the intrrupt context. This function is called without any lock held.
  9150. * It gets the hbalock to access and update SLI data structures. Note that,
  9151. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  9152. * equal to that of FCP CQ index.
  9153. *
  9154. * This function returns IRQ_HANDLED when interrupt is handled else it
  9155. * returns IRQ_NONE.
  9156. **/
  9157. irqreturn_t
  9158. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  9159. {
  9160. struct lpfc_hba *phba;
  9161. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  9162. struct lpfc_queue *fpeq;
  9163. struct lpfc_eqe *eqe;
  9164. unsigned long iflag;
  9165. int ecount = 0;
  9166. uint32_t fcp_eqidx;
  9167. /* Get the driver's phba structure from the dev_id */
  9168. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  9169. phba = fcp_eq_hdl->phba;
  9170. fcp_eqidx = fcp_eq_hdl->idx;
  9171. if (unlikely(!phba))
  9172. return IRQ_NONE;
  9173. /* Get to the EQ struct associated with this vector */
  9174. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  9175. /* Check device state for handling interrupt */
  9176. if (unlikely(lpfc_intr_state_check(phba))) {
  9177. /* Check again for link_state with lock held */
  9178. spin_lock_irqsave(&phba->hbalock, iflag);
  9179. if (phba->link_state < LPFC_LINK_DOWN)
  9180. /* Flush, clear interrupt, and rearm the EQ */
  9181. lpfc_sli4_eq_flush(phba, fpeq);
  9182. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9183. return IRQ_NONE;
  9184. }
  9185. /*
  9186. * Process all the event on FCP fast-path EQ
  9187. */
  9188. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  9189. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  9190. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9191. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  9192. }
  9193. /* Always clear and re-arm the fast-path EQ */
  9194. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  9195. if (unlikely(ecount == 0)) {
  9196. if (phba->intr_type == MSIX)
  9197. /* MSI-X treated interrupt served as no EQ share INT */
  9198. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9199. "0358 MSI-X interrupt with no EQE\n");
  9200. else
  9201. /* Non MSI-X treated on interrupt as EQ share INT */
  9202. return IRQ_NONE;
  9203. }
  9204. return IRQ_HANDLED;
  9205. } /* lpfc_sli4_fp_intr_handler */
  9206. /**
  9207. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  9208. * @irq: Interrupt number.
  9209. * @dev_id: The device context pointer.
  9210. *
  9211. * This function is the device-level interrupt handler to device with SLI-4
  9212. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  9213. * interrupt mode is enabled and there is an event in the HBA which requires
  9214. * driver attention. This function invokes the slow-path interrupt attention
  9215. * handling function and fast-path interrupt attention handling function in
  9216. * turn to process the relevant HBA attention events. This function is called
  9217. * without any lock held. It gets the hbalock to access and update SLI data
  9218. * structures.
  9219. *
  9220. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9221. * returns IRQ_NONE.
  9222. **/
  9223. irqreturn_t
  9224. lpfc_sli4_intr_handler(int irq, void *dev_id)
  9225. {
  9226. struct lpfc_hba *phba;
  9227. irqreturn_t sp_irq_rc, fp_irq_rc;
  9228. bool fp_handled = false;
  9229. uint32_t fcp_eqidx;
  9230. /* Get the driver's phba structure from the dev_id */
  9231. phba = (struct lpfc_hba *)dev_id;
  9232. if (unlikely(!phba))
  9233. return IRQ_NONE;
  9234. /*
  9235. * Invokes slow-path host attention interrupt handling as appropriate.
  9236. */
  9237. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  9238. /*
  9239. * Invoke fast-path host attention interrupt handling as appropriate.
  9240. */
  9241. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  9242. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  9243. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  9244. if (fp_irq_rc == IRQ_HANDLED)
  9245. fp_handled |= true;
  9246. }
  9247. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  9248. } /* lpfc_sli4_intr_handler */
  9249. /**
  9250. * lpfc_sli4_queue_free - free a queue structure and associated memory
  9251. * @queue: The queue structure to free.
  9252. *
  9253. * This function frees a queue structure and the DMAable memeory used for
  9254. * the host resident queue. This function must be called after destroying the
  9255. * queue on the HBA.
  9256. **/
  9257. void
  9258. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  9259. {
  9260. struct lpfc_dmabuf *dmabuf;
  9261. if (!queue)
  9262. return;
  9263. while (!list_empty(&queue->page_list)) {
  9264. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  9265. list);
  9266. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  9267. dmabuf->virt, dmabuf->phys);
  9268. kfree(dmabuf);
  9269. }
  9270. kfree(queue);
  9271. return;
  9272. }
  9273. /**
  9274. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  9275. * @phba: The HBA that this queue is being created on.
  9276. * @entry_size: The size of each queue entry for this queue.
  9277. * @entry count: The number of entries that this queue will handle.
  9278. *
  9279. * This function allocates a queue structure and the DMAable memory used for
  9280. * the host resident queue. This function must be called before creating the
  9281. * queue on the HBA.
  9282. **/
  9283. struct lpfc_queue *
  9284. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  9285. uint32_t entry_count)
  9286. {
  9287. struct lpfc_queue *queue;
  9288. struct lpfc_dmabuf *dmabuf;
  9289. int x, total_qe_count;
  9290. void *dma_pointer;
  9291. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9292. if (!phba->sli4_hba.pc_sli4_params.supported)
  9293. hw_page_size = SLI4_PAGE_SIZE;
  9294. queue = kzalloc(sizeof(struct lpfc_queue) +
  9295. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  9296. if (!queue)
  9297. return NULL;
  9298. queue->page_count = (ALIGN(entry_size * entry_count,
  9299. hw_page_size))/hw_page_size;
  9300. INIT_LIST_HEAD(&queue->list);
  9301. INIT_LIST_HEAD(&queue->page_list);
  9302. INIT_LIST_HEAD(&queue->child_list);
  9303. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  9304. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  9305. if (!dmabuf)
  9306. goto out_fail;
  9307. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  9308. hw_page_size, &dmabuf->phys,
  9309. GFP_KERNEL);
  9310. if (!dmabuf->virt) {
  9311. kfree(dmabuf);
  9312. goto out_fail;
  9313. }
  9314. memset(dmabuf->virt, 0, hw_page_size);
  9315. dmabuf->buffer_tag = x;
  9316. list_add_tail(&dmabuf->list, &queue->page_list);
  9317. /* initialize queue's entry array */
  9318. dma_pointer = dmabuf->virt;
  9319. for (; total_qe_count < entry_count &&
  9320. dma_pointer < (hw_page_size + dmabuf->virt);
  9321. total_qe_count++, dma_pointer += entry_size) {
  9322. queue->qe[total_qe_count].address = dma_pointer;
  9323. }
  9324. }
  9325. queue->entry_size = entry_size;
  9326. queue->entry_count = entry_count;
  9327. queue->phba = phba;
  9328. return queue;
  9329. out_fail:
  9330. lpfc_sli4_queue_free(queue);
  9331. return NULL;
  9332. }
  9333. /**
  9334. * lpfc_eq_create - Create an Event Queue on the HBA
  9335. * @phba: HBA structure that indicates port to create a queue on.
  9336. * @eq: The queue structure to use to create the event queue.
  9337. * @imax: The maximum interrupt per second limit.
  9338. *
  9339. * This function creates an event queue, as detailed in @eq, on a port,
  9340. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  9341. *
  9342. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  9343. * is used to get the entry count and entry size that are necessary to
  9344. * determine the number of pages to allocate and use for this queue. This
  9345. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  9346. * event queue. This function is asynchronous and will wait for the mailbox
  9347. * command to finish before continuing.
  9348. *
  9349. * On success this function will return a zero. If unable to allocate enough
  9350. * memory this function will return -ENOMEM. If the queue create mailbox command
  9351. * fails this function will return -ENXIO.
  9352. **/
  9353. uint32_t
  9354. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  9355. {
  9356. struct lpfc_mbx_eq_create *eq_create;
  9357. LPFC_MBOXQ_t *mbox;
  9358. int rc, length, status = 0;
  9359. struct lpfc_dmabuf *dmabuf;
  9360. uint32_t shdr_status, shdr_add_status;
  9361. union lpfc_sli4_cfg_shdr *shdr;
  9362. uint16_t dmult;
  9363. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9364. if (!phba->sli4_hba.pc_sli4_params.supported)
  9365. hw_page_size = SLI4_PAGE_SIZE;
  9366. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9367. if (!mbox)
  9368. return -ENOMEM;
  9369. length = (sizeof(struct lpfc_mbx_eq_create) -
  9370. sizeof(struct lpfc_sli4_cfg_mhdr));
  9371. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9372. LPFC_MBOX_OPCODE_EQ_CREATE,
  9373. length, LPFC_SLI4_MBX_EMBED);
  9374. eq_create = &mbox->u.mqe.un.eq_create;
  9375. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  9376. eq->page_count);
  9377. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  9378. LPFC_EQE_SIZE);
  9379. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  9380. /* Calculate delay multiper from maximum interrupt per second */
  9381. dmult = LPFC_DMULT_CONST/imax - 1;
  9382. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  9383. dmult);
  9384. switch (eq->entry_count) {
  9385. default:
  9386. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9387. "0360 Unsupported EQ count. (%d)\n",
  9388. eq->entry_count);
  9389. if (eq->entry_count < 256)
  9390. return -EINVAL;
  9391. /* otherwise default to smallest count (drop through) */
  9392. case 256:
  9393. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9394. LPFC_EQ_CNT_256);
  9395. break;
  9396. case 512:
  9397. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9398. LPFC_EQ_CNT_512);
  9399. break;
  9400. case 1024:
  9401. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9402. LPFC_EQ_CNT_1024);
  9403. break;
  9404. case 2048:
  9405. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9406. LPFC_EQ_CNT_2048);
  9407. break;
  9408. case 4096:
  9409. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9410. LPFC_EQ_CNT_4096);
  9411. break;
  9412. }
  9413. list_for_each_entry(dmabuf, &eq->page_list, list) {
  9414. memset(dmabuf->virt, 0, hw_page_size);
  9415. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9416. putPaddrLow(dmabuf->phys);
  9417. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9418. putPaddrHigh(dmabuf->phys);
  9419. }
  9420. mbox->vport = phba->pport;
  9421. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9422. mbox->context1 = NULL;
  9423. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9424. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  9425. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9426. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9427. if (shdr_status || shdr_add_status || rc) {
  9428. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9429. "2500 EQ_CREATE mailbox failed with "
  9430. "status x%x add_status x%x, mbx status x%x\n",
  9431. shdr_status, shdr_add_status, rc);
  9432. status = -ENXIO;
  9433. }
  9434. eq->type = LPFC_EQ;
  9435. eq->subtype = LPFC_NONE;
  9436. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  9437. if (eq->queue_id == 0xFFFF)
  9438. status = -ENXIO;
  9439. eq->host_index = 0;
  9440. eq->hba_index = 0;
  9441. mempool_free(mbox, phba->mbox_mem_pool);
  9442. return status;
  9443. }
  9444. /**
  9445. * lpfc_cq_create - Create a Completion Queue on the HBA
  9446. * @phba: HBA structure that indicates port to create a queue on.
  9447. * @cq: The queue structure to use to create the completion queue.
  9448. * @eq: The event queue to bind this completion queue to.
  9449. *
  9450. * This function creates a completion queue, as detailed in @wq, on a port,
  9451. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  9452. *
  9453. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9454. * is used to get the entry count and entry size that are necessary to
  9455. * determine the number of pages to allocate and use for this queue. The @eq
  9456. * is used to indicate which event queue to bind this completion queue to. This
  9457. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  9458. * completion queue. This function is asynchronous and will wait for the mailbox
  9459. * command to finish before continuing.
  9460. *
  9461. * On success this function will return a zero. If unable to allocate enough
  9462. * memory this function will return -ENOMEM. If the queue create mailbox command
  9463. * fails this function will return -ENXIO.
  9464. **/
  9465. uint32_t
  9466. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9467. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  9468. {
  9469. struct lpfc_mbx_cq_create *cq_create;
  9470. struct lpfc_dmabuf *dmabuf;
  9471. LPFC_MBOXQ_t *mbox;
  9472. int rc, length, status = 0;
  9473. uint32_t shdr_status, shdr_add_status;
  9474. union lpfc_sli4_cfg_shdr *shdr;
  9475. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9476. if (!phba->sli4_hba.pc_sli4_params.supported)
  9477. hw_page_size = SLI4_PAGE_SIZE;
  9478. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9479. if (!mbox)
  9480. return -ENOMEM;
  9481. length = (sizeof(struct lpfc_mbx_cq_create) -
  9482. sizeof(struct lpfc_sli4_cfg_mhdr));
  9483. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9484. LPFC_MBOX_OPCODE_CQ_CREATE,
  9485. length, LPFC_SLI4_MBX_EMBED);
  9486. cq_create = &mbox->u.mqe.un.cq_create;
  9487. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  9488. cq->page_count);
  9489. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  9490. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  9491. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  9492. switch (cq->entry_count) {
  9493. default:
  9494. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9495. "0361 Unsupported CQ count. (%d)\n",
  9496. cq->entry_count);
  9497. if (cq->entry_count < 256)
  9498. return -EINVAL;
  9499. /* otherwise default to smallest count (drop through) */
  9500. case 256:
  9501. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9502. LPFC_CQ_CNT_256);
  9503. break;
  9504. case 512:
  9505. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9506. LPFC_CQ_CNT_512);
  9507. break;
  9508. case 1024:
  9509. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9510. LPFC_CQ_CNT_1024);
  9511. break;
  9512. }
  9513. list_for_each_entry(dmabuf, &cq->page_list, list) {
  9514. memset(dmabuf->virt, 0, hw_page_size);
  9515. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9516. putPaddrLow(dmabuf->phys);
  9517. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9518. putPaddrHigh(dmabuf->phys);
  9519. }
  9520. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9521. /* The IOCTL status is embedded in the mailbox subheader. */
  9522. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  9523. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9524. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9525. if (shdr_status || shdr_add_status || rc) {
  9526. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9527. "2501 CQ_CREATE mailbox failed with "
  9528. "status x%x add_status x%x, mbx status x%x\n",
  9529. shdr_status, shdr_add_status, rc);
  9530. status = -ENXIO;
  9531. goto out;
  9532. }
  9533. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9534. if (cq->queue_id == 0xFFFF) {
  9535. status = -ENXIO;
  9536. goto out;
  9537. }
  9538. /* link the cq onto the parent eq child list */
  9539. list_add_tail(&cq->list, &eq->child_list);
  9540. /* Set up completion queue's type and subtype */
  9541. cq->type = type;
  9542. cq->subtype = subtype;
  9543. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9544. cq->host_index = 0;
  9545. cq->hba_index = 0;
  9546. out:
  9547. mempool_free(mbox, phba->mbox_mem_pool);
  9548. return status;
  9549. }
  9550. /**
  9551. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9552. * @phba: HBA structure that indicates port to create a queue on.
  9553. * @mq: The queue structure to use to create the mailbox queue.
  9554. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9555. * @cq: The completion queue to associate with this cq.
  9556. *
  9557. * This function provides failback (fb) functionality when the
  9558. * mq_create_ext fails on older FW generations. It's purpose is identical
  9559. * to mq_create_ext otherwise.
  9560. *
  9561. * This routine cannot fail as all attributes were previously accessed and
  9562. * initialized in mq_create_ext.
  9563. **/
  9564. static void
  9565. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9566. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9567. {
  9568. struct lpfc_mbx_mq_create *mq_create;
  9569. struct lpfc_dmabuf *dmabuf;
  9570. int length;
  9571. length = (sizeof(struct lpfc_mbx_mq_create) -
  9572. sizeof(struct lpfc_sli4_cfg_mhdr));
  9573. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9574. LPFC_MBOX_OPCODE_MQ_CREATE,
  9575. length, LPFC_SLI4_MBX_EMBED);
  9576. mq_create = &mbox->u.mqe.un.mq_create;
  9577. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9578. mq->page_count);
  9579. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9580. cq->queue_id);
  9581. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9582. switch (mq->entry_count) {
  9583. case 16:
  9584. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9585. LPFC_MQ_CNT_16);
  9586. break;
  9587. case 32:
  9588. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9589. LPFC_MQ_CNT_32);
  9590. break;
  9591. case 64:
  9592. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9593. LPFC_MQ_CNT_64);
  9594. break;
  9595. case 128:
  9596. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9597. LPFC_MQ_CNT_128);
  9598. break;
  9599. }
  9600. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9601. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9602. putPaddrLow(dmabuf->phys);
  9603. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9604. putPaddrHigh(dmabuf->phys);
  9605. }
  9606. }
  9607. /**
  9608. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9609. * @phba: HBA structure that indicates port to create a queue on.
  9610. * @mq: The queue structure to use to create the mailbox queue.
  9611. * @cq: The completion queue to associate with this cq.
  9612. * @subtype: The queue's subtype.
  9613. *
  9614. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9615. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9616. *
  9617. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9618. * is used to get the entry count and entry size that are necessary to
  9619. * determine the number of pages to allocate and use for this queue. This
  9620. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9621. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9622. * command to finish before continuing.
  9623. *
  9624. * On success this function will return a zero. If unable to allocate enough
  9625. * memory this function will return -ENOMEM. If the queue create mailbox command
  9626. * fails this function will return -ENXIO.
  9627. **/
  9628. int32_t
  9629. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9630. struct lpfc_queue *cq, uint32_t subtype)
  9631. {
  9632. struct lpfc_mbx_mq_create *mq_create;
  9633. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9634. struct lpfc_dmabuf *dmabuf;
  9635. LPFC_MBOXQ_t *mbox;
  9636. int rc, length, status = 0;
  9637. uint32_t shdr_status, shdr_add_status;
  9638. union lpfc_sli4_cfg_shdr *shdr;
  9639. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9640. if (!phba->sli4_hba.pc_sli4_params.supported)
  9641. hw_page_size = SLI4_PAGE_SIZE;
  9642. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9643. if (!mbox)
  9644. return -ENOMEM;
  9645. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9646. sizeof(struct lpfc_sli4_cfg_mhdr));
  9647. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9648. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9649. length, LPFC_SLI4_MBX_EMBED);
  9650. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9651. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  9652. &mq_create_ext->u.request, mq->page_count);
  9653. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  9654. &mq_create_ext->u.request, 1);
  9655. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  9656. &mq_create_ext->u.request, 1);
  9657. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9658. &mq_create_ext->u.request, 1);
  9659. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  9660. &mq_create_ext->u.request, 1);
  9661. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  9662. &mq_create_ext->u.request, 1);
  9663. bf_set(lpfc_mq_context_cq_id,
  9664. &mq_create_ext->u.request.context, cq->queue_id);
  9665. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9666. switch (mq->entry_count) {
  9667. default:
  9668. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9669. "0362 Unsupported MQ count. (%d)\n",
  9670. mq->entry_count);
  9671. if (mq->entry_count < 16)
  9672. return -EINVAL;
  9673. /* otherwise default to smallest count (drop through) */
  9674. case 16:
  9675. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9676. LPFC_MQ_CNT_16);
  9677. break;
  9678. case 32:
  9679. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9680. LPFC_MQ_CNT_32);
  9681. break;
  9682. case 64:
  9683. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9684. LPFC_MQ_CNT_64);
  9685. break;
  9686. case 128:
  9687. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9688. LPFC_MQ_CNT_128);
  9689. break;
  9690. }
  9691. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9692. memset(dmabuf->virt, 0, hw_page_size);
  9693. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9694. putPaddrLow(dmabuf->phys);
  9695. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9696. putPaddrHigh(dmabuf->phys);
  9697. }
  9698. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9699. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9700. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9701. &mq_create_ext->u.response);
  9702. if (rc != MBX_SUCCESS) {
  9703. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9704. "2795 MQ_CREATE_EXT failed with "
  9705. "status x%x. Failback to MQ_CREATE.\n",
  9706. rc);
  9707. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9708. mq_create = &mbox->u.mqe.un.mq_create;
  9709. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9710. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9711. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9712. &mq_create->u.response);
  9713. }
  9714. /* The IOCTL status is embedded in the mailbox subheader. */
  9715. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9716. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9717. if (shdr_status || shdr_add_status || rc) {
  9718. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9719. "2502 MQ_CREATE mailbox failed with "
  9720. "status x%x add_status x%x, mbx status x%x\n",
  9721. shdr_status, shdr_add_status, rc);
  9722. status = -ENXIO;
  9723. goto out;
  9724. }
  9725. if (mq->queue_id == 0xFFFF) {
  9726. status = -ENXIO;
  9727. goto out;
  9728. }
  9729. mq->type = LPFC_MQ;
  9730. mq->subtype = subtype;
  9731. mq->host_index = 0;
  9732. mq->hba_index = 0;
  9733. /* link the mq onto the parent cq child list */
  9734. list_add_tail(&mq->list, &cq->child_list);
  9735. out:
  9736. mempool_free(mbox, phba->mbox_mem_pool);
  9737. return status;
  9738. }
  9739. /**
  9740. * lpfc_wq_create - Create a Work Queue on the HBA
  9741. * @phba: HBA structure that indicates port to create a queue on.
  9742. * @wq: The queue structure to use to create the work queue.
  9743. * @cq: The completion queue to bind this work queue to.
  9744. * @subtype: The subtype of the work queue indicating its functionality.
  9745. *
  9746. * This function creates a work queue, as detailed in @wq, on a port, described
  9747. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9748. *
  9749. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9750. * is used to get the entry count and entry size that are necessary to
  9751. * determine the number of pages to allocate and use for this queue. The @cq
  9752. * is used to indicate which completion queue to bind this work queue to. This
  9753. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9754. * work queue. This function is asynchronous and will wait for the mailbox
  9755. * command to finish before continuing.
  9756. *
  9757. * On success this function will return a zero. If unable to allocate enough
  9758. * memory this function will return -ENOMEM. If the queue create mailbox command
  9759. * fails this function will return -ENXIO.
  9760. **/
  9761. uint32_t
  9762. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9763. struct lpfc_queue *cq, uint32_t subtype)
  9764. {
  9765. struct lpfc_mbx_wq_create *wq_create;
  9766. struct lpfc_dmabuf *dmabuf;
  9767. LPFC_MBOXQ_t *mbox;
  9768. int rc, length, status = 0;
  9769. uint32_t shdr_status, shdr_add_status;
  9770. union lpfc_sli4_cfg_shdr *shdr;
  9771. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9772. if (!phba->sli4_hba.pc_sli4_params.supported)
  9773. hw_page_size = SLI4_PAGE_SIZE;
  9774. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9775. if (!mbox)
  9776. return -ENOMEM;
  9777. length = (sizeof(struct lpfc_mbx_wq_create) -
  9778. sizeof(struct lpfc_sli4_cfg_mhdr));
  9779. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9780. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9781. length, LPFC_SLI4_MBX_EMBED);
  9782. wq_create = &mbox->u.mqe.un.wq_create;
  9783. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9784. wq->page_count);
  9785. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9786. cq->queue_id);
  9787. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9788. memset(dmabuf->virt, 0, hw_page_size);
  9789. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9790. putPaddrLow(dmabuf->phys);
  9791. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9792. putPaddrHigh(dmabuf->phys);
  9793. }
  9794. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9795. /* The IOCTL status is embedded in the mailbox subheader. */
  9796. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9797. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9798. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9799. if (shdr_status || shdr_add_status || rc) {
  9800. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9801. "2503 WQ_CREATE mailbox failed with "
  9802. "status x%x add_status x%x, mbx status x%x\n",
  9803. shdr_status, shdr_add_status, rc);
  9804. status = -ENXIO;
  9805. goto out;
  9806. }
  9807. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9808. if (wq->queue_id == 0xFFFF) {
  9809. status = -ENXIO;
  9810. goto out;
  9811. }
  9812. wq->type = LPFC_WQ;
  9813. wq->subtype = subtype;
  9814. wq->host_index = 0;
  9815. wq->hba_index = 0;
  9816. /* link the wq onto the parent cq child list */
  9817. list_add_tail(&wq->list, &cq->child_list);
  9818. out:
  9819. mempool_free(mbox, phba->mbox_mem_pool);
  9820. return status;
  9821. }
  9822. /**
  9823. * lpfc_rq_create - Create a Receive Queue on the HBA
  9824. * @phba: HBA structure that indicates port to create a queue on.
  9825. * @hrq: The queue structure to use to create the header receive queue.
  9826. * @drq: The queue structure to use to create the data receive queue.
  9827. * @cq: The completion queue to bind this work queue to.
  9828. *
  9829. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9830. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9831. * to the HBA.
  9832. *
  9833. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9834. * struct is used to get the entry count that is necessary to determine the
  9835. * number of pages to use for this queue. The @cq is used to indicate which
  9836. * completion queue to bind received buffers that are posted to these queues to.
  9837. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9838. * receive queue pair. This function is asynchronous and will wait for the
  9839. * mailbox command to finish before continuing.
  9840. *
  9841. * On success this function will return a zero. If unable to allocate enough
  9842. * memory this function will return -ENOMEM. If the queue create mailbox command
  9843. * fails this function will return -ENXIO.
  9844. **/
  9845. uint32_t
  9846. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9847. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9848. {
  9849. struct lpfc_mbx_rq_create *rq_create;
  9850. struct lpfc_dmabuf *dmabuf;
  9851. LPFC_MBOXQ_t *mbox;
  9852. int rc, length, status = 0;
  9853. uint32_t shdr_status, shdr_add_status;
  9854. union lpfc_sli4_cfg_shdr *shdr;
  9855. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9856. if (!phba->sli4_hba.pc_sli4_params.supported)
  9857. hw_page_size = SLI4_PAGE_SIZE;
  9858. if (hrq->entry_count != drq->entry_count)
  9859. return -EINVAL;
  9860. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9861. if (!mbox)
  9862. return -ENOMEM;
  9863. length = (sizeof(struct lpfc_mbx_rq_create) -
  9864. sizeof(struct lpfc_sli4_cfg_mhdr));
  9865. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9866. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9867. length, LPFC_SLI4_MBX_EMBED);
  9868. rq_create = &mbox->u.mqe.un.rq_create;
  9869. switch (hrq->entry_count) {
  9870. default:
  9871. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9872. "2535 Unsupported RQ count. (%d)\n",
  9873. hrq->entry_count);
  9874. if (hrq->entry_count < 512)
  9875. return -EINVAL;
  9876. /* otherwise default to smallest count (drop through) */
  9877. case 512:
  9878. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9879. LPFC_RQ_RING_SIZE_512);
  9880. break;
  9881. case 1024:
  9882. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9883. LPFC_RQ_RING_SIZE_1024);
  9884. break;
  9885. case 2048:
  9886. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9887. LPFC_RQ_RING_SIZE_2048);
  9888. break;
  9889. case 4096:
  9890. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9891. LPFC_RQ_RING_SIZE_4096);
  9892. break;
  9893. }
  9894. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9895. cq->queue_id);
  9896. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9897. hrq->page_count);
  9898. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9899. LPFC_HDR_BUF_SIZE);
  9900. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9901. memset(dmabuf->virt, 0, hw_page_size);
  9902. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9903. putPaddrLow(dmabuf->phys);
  9904. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9905. putPaddrHigh(dmabuf->phys);
  9906. }
  9907. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9908. /* The IOCTL status is embedded in the mailbox subheader. */
  9909. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9910. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9911. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9912. if (shdr_status || shdr_add_status || rc) {
  9913. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9914. "2504 RQ_CREATE mailbox failed with "
  9915. "status x%x add_status x%x, mbx status x%x\n",
  9916. shdr_status, shdr_add_status, rc);
  9917. status = -ENXIO;
  9918. goto out;
  9919. }
  9920. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9921. if (hrq->queue_id == 0xFFFF) {
  9922. status = -ENXIO;
  9923. goto out;
  9924. }
  9925. hrq->type = LPFC_HRQ;
  9926. hrq->subtype = subtype;
  9927. hrq->host_index = 0;
  9928. hrq->hba_index = 0;
  9929. /* now create the data queue */
  9930. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9931. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9932. length, LPFC_SLI4_MBX_EMBED);
  9933. switch (drq->entry_count) {
  9934. default:
  9935. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9936. "2536 Unsupported RQ count. (%d)\n",
  9937. drq->entry_count);
  9938. if (drq->entry_count < 512)
  9939. return -EINVAL;
  9940. /* otherwise default to smallest count (drop through) */
  9941. case 512:
  9942. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9943. LPFC_RQ_RING_SIZE_512);
  9944. break;
  9945. case 1024:
  9946. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9947. LPFC_RQ_RING_SIZE_1024);
  9948. break;
  9949. case 2048:
  9950. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9951. LPFC_RQ_RING_SIZE_2048);
  9952. break;
  9953. case 4096:
  9954. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9955. LPFC_RQ_RING_SIZE_4096);
  9956. break;
  9957. }
  9958. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9959. cq->queue_id);
  9960. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9961. drq->page_count);
  9962. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9963. LPFC_DATA_BUF_SIZE);
  9964. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9965. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9966. putPaddrLow(dmabuf->phys);
  9967. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9968. putPaddrHigh(dmabuf->phys);
  9969. }
  9970. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9971. /* The IOCTL status is embedded in the mailbox subheader. */
  9972. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9973. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9974. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9975. if (shdr_status || shdr_add_status || rc) {
  9976. status = -ENXIO;
  9977. goto out;
  9978. }
  9979. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9980. if (drq->queue_id == 0xFFFF) {
  9981. status = -ENXIO;
  9982. goto out;
  9983. }
  9984. drq->type = LPFC_DRQ;
  9985. drq->subtype = subtype;
  9986. drq->host_index = 0;
  9987. drq->hba_index = 0;
  9988. /* link the header and data RQs onto the parent cq child list */
  9989. list_add_tail(&hrq->list, &cq->child_list);
  9990. list_add_tail(&drq->list, &cq->child_list);
  9991. out:
  9992. mempool_free(mbox, phba->mbox_mem_pool);
  9993. return status;
  9994. }
  9995. /**
  9996. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9997. * @eq: The queue structure associated with the queue to destroy.
  9998. *
  9999. * This function destroys a queue, as detailed in @eq by sending an mailbox
  10000. * command, specific to the type of queue, to the HBA.
  10001. *
  10002. * The @eq struct is used to get the queue ID of the queue to destroy.
  10003. *
  10004. * On success this function will return a zero. If the queue destroy mailbox
  10005. * command fails this function will return -ENXIO.
  10006. **/
  10007. uint32_t
  10008. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10009. {
  10010. LPFC_MBOXQ_t *mbox;
  10011. int rc, length, status = 0;
  10012. uint32_t shdr_status, shdr_add_status;
  10013. union lpfc_sli4_cfg_shdr *shdr;
  10014. if (!eq)
  10015. return -ENODEV;
  10016. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  10017. if (!mbox)
  10018. return -ENOMEM;
  10019. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  10020. sizeof(struct lpfc_sli4_cfg_mhdr));
  10021. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10022. LPFC_MBOX_OPCODE_EQ_DESTROY,
  10023. length, LPFC_SLI4_MBX_EMBED);
  10024. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  10025. eq->queue_id);
  10026. mbox->vport = eq->phba->pport;
  10027. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10028. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  10029. /* The IOCTL status is embedded in the mailbox subheader. */
  10030. shdr = (union lpfc_sli4_cfg_shdr *)
  10031. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  10032. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10033. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10034. if (shdr_status || shdr_add_status || rc) {
  10035. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10036. "2505 EQ_DESTROY mailbox failed with "
  10037. "status x%x add_status x%x, mbx status x%x\n",
  10038. shdr_status, shdr_add_status, rc);
  10039. status = -ENXIO;
  10040. }
  10041. /* Remove eq from any list */
  10042. list_del_init(&eq->list);
  10043. mempool_free(mbox, eq->phba->mbox_mem_pool);
  10044. return status;
  10045. }
  10046. /**
  10047. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  10048. * @cq: The queue structure associated with the queue to destroy.
  10049. *
  10050. * This function destroys a queue, as detailed in @cq by sending an mailbox
  10051. * command, specific to the type of queue, to the HBA.
  10052. *
  10053. * The @cq struct is used to get the queue ID of the queue to destroy.
  10054. *
  10055. * On success this function will return a zero. If the queue destroy mailbox
  10056. * command fails this function will return -ENXIO.
  10057. **/
  10058. uint32_t
  10059. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  10060. {
  10061. LPFC_MBOXQ_t *mbox;
  10062. int rc, length, status = 0;
  10063. uint32_t shdr_status, shdr_add_status;
  10064. union lpfc_sli4_cfg_shdr *shdr;
  10065. if (!cq)
  10066. return -ENODEV;
  10067. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  10068. if (!mbox)
  10069. return -ENOMEM;
  10070. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  10071. sizeof(struct lpfc_sli4_cfg_mhdr));
  10072. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10073. LPFC_MBOX_OPCODE_CQ_DESTROY,
  10074. length, LPFC_SLI4_MBX_EMBED);
  10075. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  10076. cq->queue_id);
  10077. mbox->vport = cq->phba->pport;
  10078. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10079. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  10080. /* The IOCTL status is embedded in the mailbox subheader. */
  10081. shdr = (union lpfc_sli4_cfg_shdr *)
  10082. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  10083. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10084. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10085. if (shdr_status || shdr_add_status || rc) {
  10086. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10087. "2506 CQ_DESTROY mailbox failed with "
  10088. "status x%x add_status x%x, mbx status x%x\n",
  10089. shdr_status, shdr_add_status, rc);
  10090. status = -ENXIO;
  10091. }
  10092. /* Remove cq from any list */
  10093. list_del_init(&cq->list);
  10094. mempool_free(mbox, cq->phba->mbox_mem_pool);
  10095. return status;
  10096. }
  10097. /**
  10098. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  10099. * @qm: The queue structure associated with the queue to destroy.
  10100. *
  10101. * This function destroys a queue, as detailed in @mq by sending an mailbox
  10102. * command, specific to the type of queue, to the HBA.
  10103. *
  10104. * The @mq struct is used to get the queue ID of the queue to destroy.
  10105. *
  10106. * On success this function will return a zero. If the queue destroy mailbox
  10107. * command fails this function will return -ENXIO.
  10108. **/
  10109. uint32_t
  10110. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  10111. {
  10112. LPFC_MBOXQ_t *mbox;
  10113. int rc, length, status = 0;
  10114. uint32_t shdr_status, shdr_add_status;
  10115. union lpfc_sli4_cfg_shdr *shdr;
  10116. if (!mq)
  10117. return -ENODEV;
  10118. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  10119. if (!mbox)
  10120. return -ENOMEM;
  10121. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  10122. sizeof(struct lpfc_sli4_cfg_mhdr));
  10123. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10124. LPFC_MBOX_OPCODE_MQ_DESTROY,
  10125. length, LPFC_SLI4_MBX_EMBED);
  10126. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  10127. mq->queue_id);
  10128. mbox->vport = mq->phba->pport;
  10129. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10130. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  10131. /* The IOCTL status is embedded in the mailbox subheader. */
  10132. shdr = (union lpfc_sli4_cfg_shdr *)
  10133. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  10134. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10135. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10136. if (shdr_status || shdr_add_status || rc) {
  10137. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10138. "2507 MQ_DESTROY mailbox failed with "
  10139. "status x%x add_status x%x, mbx status x%x\n",
  10140. shdr_status, shdr_add_status, rc);
  10141. status = -ENXIO;
  10142. }
  10143. /* Remove mq from any list */
  10144. list_del_init(&mq->list);
  10145. mempool_free(mbox, mq->phba->mbox_mem_pool);
  10146. return status;
  10147. }
  10148. /**
  10149. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  10150. * @wq: The queue structure associated with the queue to destroy.
  10151. *
  10152. * This function destroys a queue, as detailed in @wq by sending an mailbox
  10153. * command, specific to the type of queue, to the HBA.
  10154. *
  10155. * The @wq struct is used to get the queue ID of the queue to destroy.
  10156. *
  10157. * On success this function will return a zero. If the queue destroy mailbox
  10158. * command fails this function will return -ENXIO.
  10159. **/
  10160. uint32_t
  10161. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  10162. {
  10163. LPFC_MBOXQ_t *mbox;
  10164. int rc, length, status = 0;
  10165. uint32_t shdr_status, shdr_add_status;
  10166. union lpfc_sli4_cfg_shdr *shdr;
  10167. if (!wq)
  10168. return -ENODEV;
  10169. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  10170. if (!mbox)
  10171. return -ENOMEM;
  10172. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  10173. sizeof(struct lpfc_sli4_cfg_mhdr));
  10174. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10175. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  10176. length, LPFC_SLI4_MBX_EMBED);
  10177. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  10178. wq->queue_id);
  10179. mbox->vport = wq->phba->pport;
  10180. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10181. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  10182. shdr = (union lpfc_sli4_cfg_shdr *)
  10183. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  10184. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10185. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10186. if (shdr_status || shdr_add_status || rc) {
  10187. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10188. "2508 WQ_DESTROY mailbox failed with "
  10189. "status x%x add_status x%x, mbx status x%x\n",
  10190. shdr_status, shdr_add_status, rc);
  10191. status = -ENXIO;
  10192. }
  10193. /* Remove wq from any list */
  10194. list_del_init(&wq->list);
  10195. mempool_free(mbox, wq->phba->mbox_mem_pool);
  10196. return status;
  10197. }
  10198. /**
  10199. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  10200. * @rq: The queue structure associated with the queue to destroy.
  10201. *
  10202. * This function destroys a queue, as detailed in @rq by sending an mailbox
  10203. * command, specific to the type of queue, to the HBA.
  10204. *
  10205. * The @rq struct is used to get the queue ID of the queue to destroy.
  10206. *
  10207. * On success this function will return a zero. If the queue destroy mailbox
  10208. * command fails this function will return -ENXIO.
  10209. **/
  10210. uint32_t
  10211. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  10212. struct lpfc_queue *drq)
  10213. {
  10214. LPFC_MBOXQ_t *mbox;
  10215. int rc, length, status = 0;
  10216. uint32_t shdr_status, shdr_add_status;
  10217. union lpfc_sli4_cfg_shdr *shdr;
  10218. if (!hrq || !drq)
  10219. return -ENODEV;
  10220. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  10221. if (!mbox)
  10222. return -ENOMEM;
  10223. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  10224. sizeof(struct mbox_header));
  10225. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10226. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  10227. length, LPFC_SLI4_MBX_EMBED);
  10228. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10229. hrq->queue_id);
  10230. mbox->vport = hrq->phba->pport;
  10231. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10232. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  10233. /* The IOCTL status is embedded in the mailbox subheader. */
  10234. shdr = (union lpfc_sli4_cfg_shdr *)
  10235. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10236. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10237. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10238. if (shdr_status || shdr_add_status || rc) {
  10239. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10240. "2509 RQ_DESTROY mailbox failed with "
  10241. "status x%x add_status x%x, mbx status x%x\n",
  10242. shdr_status, shdr_add_status, rc);
  10243. if (rc != MBX_TIMEOUT)
  10244. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10245. return -ENXIO;
  10246. }
  10247. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10248. drq->queue_id);
  10249. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  10250. shdr = (union lpfc_sli4_cfg_shdr *)
  10251. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10252. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10253. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10254. if (shdr_status || shdr_add_status || rc) {
  10255. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10256. "2510 RQ_DESTROY mailbox failed with "
  10257. "status x%x add_status x%x, mbx status x%x\n",
  10258. shdr_status, shdr_add_status, rc);
  10259. status = -ENXIO;
  10260. }
  10261. list_del_init(&hrq->list);
  10262. list_del_init(&drq->list);
  10263. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10264. return status;
  10265. }
  10266. /**
  10267. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  10268. * @phba: The virtual port for which this call being executed.
  10269. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  10270. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  10271. * @xritag: the xritag that ties this io to the SGL pages.
  10272. *
  10273. * This routine will post the sgl pages for the IO that has the xritag
  10274. * that is in the iocbq structure. The xritag is assigned during iocbq
  10275. * creation and persists for as long as the driver is loaded.
  10276. * if the caller has fewer than 256 scatter gather segments to map then
  10277. * pdma_phys_addr1 should be 0.
  10278. * If the caller needs to map more than 256 scatter gather segment then
  10279. * pdma_phys_addr1 should be a valid physical address.
  10280. * physical address for SGLs must be 64 byte aligned.
  10281. * If you are going to map 2 SGL's then the first one must have 256 entries
  10282. * the second sgl can have between 1 and 256 entries.
  10283. *
  10284. * Return codes:
  10285. * 0 - Success
  10286. * -ENXIO, -ENOMEM - Failure
  10287. **/
  10288. int
  10289. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  10290. dma_addr_t pdma_phys_addr0,
  10291. dma_addr_t pdma_phys_addr1,
  10292. uint16_t xritag)
  10293. {
  10294. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  10295. LPFC_MBOXQ_t *mbox;
  10296. int rc;
  10297. uint32_t shdr_status, shdr_add_status;
  10298. union lpfc_sli4_cfg_shdr *shdr;
  10299. if (xritag == NO_XRI) {
  10300. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10301. "0364 Invalid param:\n");
  10302. return -EINVAL;
  10303. }
  10304. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10305. if (!mbox)
  10306. return -ENOMEM;
  10307. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10308. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  10309. sizeof(struct lpfc_mbx_post_sgl_pages) -
  10310. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10311. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  10312. &mbox->u.mqe.un.post_sgl_pages;
  10313. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  10314. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  10315. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  10316. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  10317. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  10318. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  10319. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  10320. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  10321. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  10322. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  10323. if (!phba->sli4_hba.intr_enable)
  10324. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10325. else
  10326. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  10327. /* The IOCTL status is embedded in the mailbox subheader. */
  10328. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  10329. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10330. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10331. if (rc != MBX_TIMEOUT)
  10332. mempool_free(mbox, phba->mbox_mem_pool);
  10333. if (shdr_status || shdr_add_status || rc) {
  10334. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10335. "2511 POST_SGL mailbox failed with "
  10336. "status x%x add_status x%x, mbx status x%x\n",
  10337. shdr_status, shdr_add_status, rc);
  10338. rc = -ENXIO;
  10339. }
  10340. return 0;
  10341. }
  10342. /**
  10343. * lpfc_sli4_next_xritag - Get an xritag for the io
  10344. * @phba: Pointer to HBA context object.
  10345. *
  10346. * This function gets an xritag for the iocb. If there is no unused xritag
  10347. * it will return 0xffff.
  10348. * The function returns the allocated xritag if successful, else returns zero.
  10349. * Zero is not a valid xritag.
  10350. * The caller is not required to hold any lock.
  10351. **/
  10352. uint16_t
  10353. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  10354. {
  10355. uint16_t xritag;
  10356. spin_lock_irq(&phba->hbalock);
  10357. xritag = phba->sli4_hba.next_xri;
  10358. if ((xritag != (uint16_t) -1) && xritag <
  10359. (phba->sli4_hba.max_cfg_param.max_xri
  10360. + phba->sli4_hba.max_cfg_param.xri_base)) {
  10361. phba->sli4_hba.next_xri++;
  10362. phba->sli4_hba.max_cfg_param.xri_used++;
  10363. spin_unlock_irq(&phba->hbalock);
  10364. return xritag;
  10365. }
  10366. spin_unlock_irq(&phba->hbalock);
  10367. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10368. "2004 Failed to allocate XRI.last XRITAG is %d"
  10369. " Max XRI is %d, Used XRI is %d\n",
  10370. phba->sli4_hba.next_xri,
  10371. phba->sli4_hba.max_cfg_param.max_xri,
  10372. phba->sli4_hba.max_cfg_param.xri_used);
  10373. return -1;
  10374. }
  10375. /**
  10376. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  10377. * @phba: pointer to lpfc hba data structure.
  10378. *
  10379. * This routine is invoked to post a block of driver's sgl pages to the
  10380. * HBA using non-embedded mailbox command. No Lock is held. This routine
  10381. * is only called when the driver is loading and after all IO has been
  10382. * stopped.
  10383. **/
  10384. int
  10385. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  10386. {
  10387. struct lpfc_sglq *sglq_entry;
  10388. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10389. struct sgl_page_pairs *sgl_pg_pairs;
  10390. void *viraddr;
  10391. LPFC_MBOXQ_t *mbox;
  10392. uint32_t reqlen, alloclen, pg_pairs;
  10393. uint32_t mbox_tmo;
  10394. uint16_t xritag_start = 0;
  10395. int els_xri_cnt, rc = 0;
  10396. uint32_t shdr_status, shdr_add_status;
  10397. union lpfc_sli4_cfg_shdr *shdr;
  10398. /* The number of sgls to be posted */
  10399. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  10400. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  10401. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10402. if (reqlen > SLI4_PAGE_SIZE) {
  10403. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10404. "2559 Block sgl registration required DMA "
  10405. "size (%d) great than a page\n", reqlen);
  10406. return -ENOMEM;
  10407. }
  10408. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10409. if (!mbox) {
  10410. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10411. "2560 Failed to allocate mbox cmd memory\n");
  10412. return -ENOMEM;
  10413. }
  10414. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10415. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10416. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10417. LPFC_SLI4_MBX_NEMBED);
  10418. if (alloclen < reqlen) {
  10419. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10420. "0285 Allocated DMA memory size (%d) is "
  10421. "less than the requested DMA memory "
  10422. "size (%d)\n", alloclen, reqlen);
  10423. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10424. return -ENOMEM;
  10425. }
  10426. /* Get the first SGE entry from the non-embedded DMA memory */
  10427. viraddr = mbox->sge_array->addr[0];
  10428. /* Set up the SGL pages in the non-embedded DMA pages */
  10429. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10430. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10431. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  10432. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  10433. /* Set up the sge entry */
  10434. sgl_pg_pairs->sgl_pg0_addr_lo =
  10435. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  10436. sgl_pg_pairs->sgl_pg0_addr_hi =
  10437. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  10438. sgl_pg_pairs->sgl_pg1_addr_lo =
  10439. cpu_to_le32(putPaddrLow(0));
  10440. sgl_pg_pairs->sgl_pg1_addr_hi =
  10441. cpu_to_le32(putPaddrHigh(0));
  10442. /* Keep the first xritag on the list */
  10443. if (pg_pairs == 0)
  10444. xritag_start = sglq_entry->sli4_xritag;
  10445. sgl_pg_pairs++;
  10446. }
  10447. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10448. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  10449. /* Perform endian conversion if necessary */
  10450. sgl->word0 = cpu_to_le32(sgl->word0);
  10451. if (!phba->sli4_hba.intr_enable)
  10452. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10453. else {
  10454. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10455. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10456. }
  10457. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10458. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10459. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10460. if (rc != MBX_TIMEOUT)
  10461. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10462. if (shdr_status || shdr_add_status || rc) {
  10463. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10464. "2513 POST_SGL_BLOCK mailbox command failed "
  10465. "status x%x add_status x%x mbx status x%x\n",
  10466. shdr_status, shdr_add_status, rc);
  10467. rc = -ENXIO;
  10468. }
  10469. return rc;
  10470. }
  10471. /**
  10472. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  10473. * @phba: pointer to lpfc hba data structure.
  10474. * @sblist: pointer to scsi buffer list.
  10475. * @count: number of scsi buffers on the list.
  10476. *
  10477. * This routine is invoked to post a block of @count scsi sgl pages from a
  10478. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  10479. * No Lock is held.
  10480. *
  10481. **/
  10482. int
  10483. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  10484. int cnt)
  10485. {
  10486. struct lpfc_scsi_buf *psb;
  10487. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10488. struct sgl_page_pairs *sgl_pg_pairs;
  10489. void *viraddr;
  10490. LPFC_MBOXQ_t *mbox;
  10491. uint32_t reqlen, alloclen, pg_pairs;
  10492. uint32_t mbox_tmo;
  10493. uint16_t xritag_start = 0;
  10494. int rc = 0;
  10495. uint32_t shdr_status, shdr_add_status;
  10496. dma_addr_t pdma_phys_bpl1;
  10497. union lpfc_sli4_cfg_shdr *shdr;
  10498. /* Calculate the requested length of the dma memory */
  10499. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10500. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10501. if (reqlen > SLI4_PAGE_SIZE) {
  10502. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10503. "0217 Block sgl registration required DMA "
  10504. "size (%d) great than a page\n", reqlen);
  10505. return -ENOMEM;
  10506. }
  10507. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10508. if (!mbox) {
  10509. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10510. "0283 Failed to allocate mbox cmd memory\n");
  10511. return -ENOMEM;
  10512. }
  10513. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10514. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10515. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10516. LPFC_SLI4_MBX_NEMBED);
  10517. if (alloclen < reqlen) {
  10518. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10519. "2561 Allocated DMA memory size (%d) is "
  10520. "less than the requested DMA memory "
  10521. "size (%d)\n", alloclen, reqlen);
  10522. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10523. return -ENOMEM;
  10524. }
  10525. /* Get the first SGE entry from the non-embedded DMA memory */
  10526. viraddr = mbox->sge_array->addr[0];
  10527. /* Set up the SGL pages in the non-embedded DMA pages */
  10528. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10529. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10530. pg_pairs = 0;
  10531. list_for_each_entry(psb, sblist, list) {
  10532. /* Set up the sge entry */
  10533. sgl_pg_pairs->sgl_pg0_addr_lo =
  10534. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10535. sgl_pg_pairs->sgl_pg0_addr_hi =
  10536. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10537. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10538. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10539. else
  10540. pdma_phys_bpl1 = 0;
  10541. sgl_pg_pairs->sgl_pg1_addr_lo =
  10542. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10543. sgl_pg_pairs->sgl_pg1_addr_hi =
  10544. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10545. /* Keep the first xritag on the list */
  10546. if (pg_pairs == 0)
  10547. xritag_start = psb->cur_iocbq.sli4_xritag;
  10548. sgl_pg_pairs++;
  10549. pg_pairs++;
  10550. }
  10551. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10552. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10553. /* Perform endian conversion if necessary */
  10554. sgl->word0 = cpu_to_le32(sgl->word0);
  10555. if (!phba->sli4_hba.intr_enable)
  10556. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10557. else {
  10558. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10559. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10560. }
  10561. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10562. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10563. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10564. if (rc != MBX_TIMEOUT)
  10565. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10566. if (shdr_status || shdr_add_status || rc) {
  10567. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10568. "2564 POST_SGL_BLOCK mailbox command failed "
  10569. "status x%x add_status x%x mbx status x%x\n",
  10570. shdr_status, shdr_add_status, rc);
  10571. rc = -ENXIO;
  10572. }
  10573. return rc;
  10574. }
  10575. /**
  10576. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10577. * @phba: pointer to lpfc_hba struct that the frame was received on
  10578. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10579. *
  10580. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10581. * valid type of frame that the LPFC driver will handle. This function will
  10582. * return a zero if the frame is a valid frame or a non zero value when the
  10583. * frame does not pass the check.
  10584. **/
  10585. static int
  10586. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10587. {
  10588. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10589. char *type_names[] = FC_TYPE_NAMES_INIT;
  10590. struct fc_vft_header *fc_vft_hdr;
  10591. switch (fc_hdr->fh_r_ctl) {
  10592. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10593. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10594. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10595. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10596. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10597. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10598. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10599. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10600. case FC_RCTL_ELS_REQ: /* extended link services request */
  10601. case FC_RCTL_ELS_REP: /* extended link services reply */
  10602. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10603. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10604. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10605. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10606. case FC_RCTL_BA_RMC: /* remove connection */
  10607. case FC_RCTL_BA_ACC: /* basic accept */
  10608. case FC_RCTL_BA_RJT: /* basic reject */
  10609. case FC_RCTL_BA_PRMT:
  10610. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10611. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10612. case FC_RCTL_P_RJT: /* port reject */
  10613. case FC_RCTL_F_RJT: /* fabric reject */
  10614. case FC_RCTL_P_BSY: /* port busy */
  10615. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10616. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10617. case FC_RCTL_LCR: /* link credit reset */
  10618. case FC_RCTL_END: /* end */
  10619. break;
  10620. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10621. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10622. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10623. return lpfc_fc_frame_check(phba, fc_hdr);
  10624. default:
  10625. goto drop;
  10626. }
  10627. switch (fc_hdr->fh_type) {
  10628. case FC_TYPE_BLS:
  10629. case FC_TYPE_ELS:
  10630. case FC_TYPE_FCP:
  10631. case FC_TYPE_CT:
  10632. break;
  10633. case FC_TYPE_IP:
  10634. case FC_TYPE_ILS:
  10635. default:
  10636. goto drop;
  10637. }
  10638. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10639. "2538 Received frame rctl:%s type:%s\n",
  10640. rctl_names[fc_hdr->fh_r_ctl],
  10641. type_names[fc_hdr->fh_type]);
  10642. return 0;
  10643. drop:
  10644. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10645. "2539 Dropped frame rctl:%s type:%s\n",
  10646. rctl_names[fc_hdr->fh_r_ctl],
  10647. type_names[fc_hdr->fh_type]);
  10648. return 1;
  10649. }
  10650. /**
  10651. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10652. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10653. *
  10654. * This function processes the FC header to retrieve the VFI from the VF
  10655. * header, if one exists. This function will return the VFI if one exists
  10656. * or 0 if no VSAN Header exists.
  10657. **/
  10658. static uint32_t
  10659. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10660. {
  10661. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10662. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10663. return 0;
  10664. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10665. }
  10666. /**
  10667. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10668. * @phba: Pointer to the HBA structure to search for the vport on
  10669. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10670. * @fcfi: The FC Fabric ID that the frame came from
  10671. *
  10672. * This function searches the @phba for a vport that matches the content of the
  10673. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10674. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10675. * returns the matching vport pointer or NULL if unable to match frame to a
  10676. * vport.
  10677. **/
  10678. static struct lpfc_vport *
  10679. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10680. uint16_t fcfi)
  10681. {
  10682. struct lpfc_vport **vports;
  10683. struct lpfc_vport *vport = NULL;
  10684. int i;
  10685. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10686. fc_hdr->fh_d_id[1] << 8 |
  10687. fc_hdr->fh_d_id[2]);
  10688. vports = lpfc_create_vport_work_array(phba);
  10689. if (vports != NULL)
  10690. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10691. if (phba->fcf.fcfi == fcfi &&
  10692. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10693. vports[i]->fc_myDID == did) {
  10694. vport = vports[i];
  10695. break;
  10696. }
  10697. }
  10698. lpfc_destroy_vport_work_array(phba, vports);
  10699. return vport;
  10700. }
  10701. /**
  10702. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10703. * @vport: The vport to work on.
  10704. *
  10705. * This function updates the receive sequence time stamp for this vport. The
  10706. * receive sequence time stamp indicates the time that the last frame of the
  10707. * the sequence that has been idle for the longest amount of time was received.
  10708. * the driver uses this time stamp to indicate if any received sequences have
  10709. * timed out.
  10710. **/
  10711. void
  10712. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10713. {
  10714. struct lpfc_dmabuf *h_buf;
  10715. struct hbq_dmabuf *dmabuf = NULL;
  10716. /* get the oldest sequence on the rcv list */
  10717. h_buf = list_get_first(&vport->rcv_buffer_list,
  10718. struct lpfc_dmabuf, list);
  10719. if (!h_buf)
  10720. return;
  10721. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10722. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10723. }
  10724. /**
  10725. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10726. * @vport: The vport that the received sequences were sent to.
  10727. *
  10728. * This function cleans up all outstanding received sequences. This is called
  10729. * by the driver when a link event or user action invalidates all the received
  10730. * sequences.
  10731. **/
  10732. void
  10733. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10734. {
  10735. struct lpfc_dmabuf *h_buf, *hnext;
  10736. struct lpfc_dmabuf *d_buf, *dnext;
  10737. struct hbq_dmabuf *dmabuf = NULL;
  10738. /* start with the oldest sequence on the rcv list */
  10739. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10740. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10741. list_del_init(&dmabuf->hbuf.list);
  10742. list_for_each_entry_safe(d_buf, dnext,
  10743. &dmabuf->dbuf.list, list) {
  10744. list_del_init(&d_buf->list);
  10745. lpfc_in_buf_free(vport->phba, d_buf);
  10746. }
  10747. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10748. }
  10749. }
  10750. /**
  10751. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10752. * @vport: The vport that the received sequences were sent to.
  10753. *
  10754. * This function determines whether any received sequences have timed out by
  10755. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10756. * indicates that there is at least one timed out sequence this routine will
  10757. * go through the received sequences one at a time from most inactive to most
  10758. * active to determine which ones need to be cleaned up. Once it has determined
  10759. * that a sequence needs to be cleaned up it will simply free up the resources
  10760. * without sending an abort.
  10761. **/
  10762. void
  10763. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10764. {
  10765. struct lpfc_dmabuf *h_buf, *hnext;
  10766. struct lpfc_dmabuf *d_buf, *dnext;
  10767. struct hbq_dmabuf *dmabuf = NULL;
  10768. unsigned long timeout;
  10769. int abort_count = 0;
  10770. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10771. vport->rcv_buffer_time_stamp);
  10772. if (list_empty(&vport->rcv_buffer_list) ||
  10773. time_before(jiffies, timeout))
  10774. return;
  10775. /* start with the oldest sequence on the rcv list */
  10776. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10777. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10778. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10779. dmabuf->time_stamp);
  10780. if (time_before(jiffies, timeout))
  10781. break;
  10782. abort_count++;
  10783. list_del_init(&dmabuf->hbuf.list);
  10784. list_for_each_entry_safe(d_buf, dnext,
  10785. &dmabuf->dbuf.list, list) {
  10786. list_del_init(&d_buf->list);
  10787. lpfc_in_buf_free(vport->phba, d_buf);
  10788. }
  10789. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10790. }
  10791. if (abort_count)
  10792. lpfc_update_rcv_time_stamp(vport);
  10793. }
  10794. /**
  10795. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10796. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10797. *
  10798. * This function searches through the existing incomplete sequences that have
  10799. * been sent to this @vport. If the frame matches one of the incomplete
  10800. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10801. * make up that sequence. If no sequence is found that matches this frame then
  10802. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10803. * This function returns a pointer to the first dmabuf in the sequence list that
  10804. * the frame was linked to.
  10805. **/
  10806. static struct hbq_dmabuf *
  10807. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10808. {
  10809. struct fc_frame_header *new_hdr;
  10810. struct fc_frame_header *temp_hdr;
  10811. struct lpfc_dmabuf *d_buf;
  10812. struct lpfc_dmabuf *h_buf;
  10813. struct hbq_dmabuf *seq_dmabuf = NULL;
  10814. struct hbq_dmabuf *temp_dmabuf = NULL;
  10815. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10816. dmabuf->time_stamp = jiffies;
  10817. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10818. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10819. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10820. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10821. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10822. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10823. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10824. continue;
  10825. /* found a pending sequence that matches this frame */
  10826. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10827. break;
  10828. }
  10829. if (!seq_dmabuf) {
  10830. /*
  10831. * This indicates first frame received for this sequence.
  10832. * Queue the buffer on the vport's rcv_buffer_list.
  10833. */
  10834. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10835. lpfc_update_rcv_time_stamp(vport);
  10836. return dmabuf;
  10837. }
  10838. temp_hdr = seq_dmabuf->hbuf.virt;
  10839. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10840. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10841. list_del_init(&seq_dmabuf->hbuf.list);
  10842. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10843. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10844. lpfc_update_rcv_time_stamp(vport);
  10845. return dmabuf;
  10846. }
  10847. /* move this sequence to the tail to indicate a young sequence */
  10848. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10849. seq_dmabuf->time_stamp = jiffies;
  10850. lpfc_update_rcv_time_stamp(vport);
  10851. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10852. temp_hdr = dmabuf->hbuf.virt;
  10853. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10854. return seq_dmabuf;
  10855. }
  10856. /* find the correct place in the sequence to insert this frame */
  10857. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10858. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10859. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10860. /*
  10861. * If the frame's sequence count is greater than the frame on
  10862. * the list then insert the frame right after this frame
  10863. */
  10864. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10865. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10866. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10867. return seq_dmabuf;
  10868. }
  10869. }
  10870. return NULL;
  10871. }
  10872. /**
  10873. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10874. * @vport: pointer to a vitural port
  10875. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10876. *
  10877. * This function tries to abort from the partially assembed sequence, described
  10878. * by the information from basic abbort @dmabuf. It checks to see whether such
  10879. * partially assembled sequence held by the driver. If so, it shall free up all
  10880. * the frames from the partially assembled sequence.
  10881. *
  10882. * Return
  10883. * true -- if there is matching partially assembled sequence present and all
  10884. * the frames freed with the sequence;
  10885. * false -- if there is no matching partially assembled sequence present so
  10886. * nothing got aborted in the lower layer driver
  10887. **/
  10888. static bool
  10889. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10890. struct hbq_dmabuf *dmabuf)
  10891. {
  10892. struct fc_frame_header *new_hdr;
  10893. struct fc_frame_header *temp_hdr;
  10894. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10895. struct hbq_dmabuf *seq_dmabuf = NULL;
  10896. /* Use the hdr_buf to find the sequence that matches this frame */
  10897. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10898. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10899. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10900. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10901. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10902. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10903. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10904. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10905. continue;
  10906. /* found a pending sequence that matches this frame */
  10907. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10908. break;
  10909. }
  10910. /* Free up all the frames from the partially assembled sequence */
  10911. if (seq_dmabuf) {
  10912. list_for_each_entry_safe(d_buf, n_buf,
  10913. &seq_dmabuf->dbuf.list, list) {
  10914. list_del_init(&d_buf->list);
  10915. lpfc_in_buf_free(vport->phba, d_buf);
  10916. }
  10917. return true;
  10918. }
  10919. return false;
  10920. }
  10921. /**
  10922. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10923. * @phba: Pointer to HBA context object.
  10924. * @cmd_iocbq: pointer to the command iocbq structure.
  10925. * @rsp_iocbq: pointer to the response iocbq structure.
  10926. *
  10927. * This function handles the sequence abort accept iocb command complete
  10928. * event. It properly releases the memory allocated to the sequence abort
  10929. * accept iocb.
  10930. **/
  10931. static void
  10932. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10933. struct lpfc_iocbq *cmd_iocbq,
  10934. struct lpfc_iocbq *rsp_iocbq)
  10935. {
  10936. if (cmd_iocbq)
  10937. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10938. }
  10939. /**
  10940. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10941. * @phba: Pointer to HBA context object.
  10942. * @fc_hdr: pointer to a FC frame header.
  10943. *
  10944. * This function sends a basic accept to a previous unsol sequence abort
  10945. * event after aborting the sequence handling.
  10946. **/
  10947. static void
  10948. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10949. struct fc_frame_header *fc_hdr)
  10950. {
  10951. struct lpfc_iocbq *ctiocb = NULL;
  10952. struct lpfc_nodelist *ndlp;
  10953. uint16_t oxid, rxid;
  10954. uint32_t sid, fctl;
  10955. IOCB_t *icmd;
  10956. if (!lpfc_is_link_up(phba))
  10957. return;
  10958. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10959. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10960. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10961. ndlp = lpfc_findnode_did(phba->pport, sid);
  10962. if (!ndlp) {
  10963. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10964. "1268 Find ndlp returned NULL for oxid:x%x "
  10965. "SID:x%x\n", oxid, sid);
  10966. return;
  10967. }
  10968. if (rxid >= phba->sli4_hba.max_cfg_param.xri_base
  10969. && rxid <= (phba->sli4_hba.max_cfg_param.max_xri
  10970. + phba->sli4_hba.max_cfg_param.xri_base))
  10971. lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
  10972. /* Allocate buffer for acc iocb */
  10973. ctiocb = lpfc_sli_get_iocbq(phba);
  10974. if (!ctiocb)
  10975. return;
  10976. /* Extract the F_CTL field from FC_HDR */
  10977. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10978. icmd = &ctiocb->iocb;
  10979. icmd->un.xseq64.bdl.bdeSize = 0;
  10980. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10981. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10982. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10983. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10984. /* Fill in the rest of iocb fields */
  10985. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10986. icmd->ulpBdeCount = 0;
  10987. icmd->ulpLe = 1;
  10988. icmd->ulpClass = CLASS3;
  10989. icmd->ulpContext = ndlp->nlp_rpi;
  10990. ctiocb->context1 = ndlp;
  10991. ctiocb->iocb_cmpl = NULL;
  10992. ctiocb->vport = phba->pport;
  10993. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10994. if (fctl & FC_FC_EX_CTX) {
  10995. /* ABTS sent by responder to CT exchange, construction
  10996. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10997. * field and RX_ID from ABTS for RX_ID field.
  10998. */
  10999. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  11000. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  11001. ctiocb->sli4_xritag = oxid;
  11002. } else {
  11003. /* ABTS sent by initiator to CT exchange, construction
  11004. * of BA_ACC will need to allocate a new XRI as for the
  11005. * XRI_TAG and RX_ID fields.
  11006. */
  11007. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  11008. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  11009. ctiocb->sli4_xritag = NO_XRI;
  11010. }
  11011. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  11012. /* Xmit CT abts accept on exchange <xid> */
  11013. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  11014. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  11015. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  11016. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  11017. }
  11018. /**
  11019. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  11020. * @vport: Pointer to the vport on which this sequence was received
  11021. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11022. *
  11023. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  11024. * receive sequence is only partially assembed by the driver, it shall abort
  11025. * the partially assembled frames for the sequence. Otherwise, if the
  11026. * unsolicited receive sequence has been completely assembled and passed to
  11027. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  11028. * unsolicited sequence has been aborted. After that, it will issue a basic
  11029. * accept to accept the abort.
  11030. **/
  11031. void
  11032. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  11033. struct hbq_dmabuf *dmabuf)
  11034. {
  11035. struct lpfc_hba *phba = vport->phba;
  11036. struct fc_frame_header fc_hdr;
  11037. uint32_t fctl;
  11038. bool abts_par;
  11039. /* Make a copy of fc_hdr before the dmabuf being released */
  11040. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  11041. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  11042. if (fctl & FC_FC_EX_CTX) {
  11043. /*
  11044. * ABTS sent by responder to exchange, just free the buffer
  11045. */
  11046. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11047. } else {
  11048. /*
  11049. * ABTS sent by initiator to exchange, need to do cleanup
  11050. */
  11051. /* Try to abort partially assembled seq */
  11052. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  11053. /* Send abort to ULP if partially seq abort failed */
  11054. if (abts_par == false)
  11055. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  11056. else
  11057. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11058. }
  11059. /* Send basic accept (BA_ACC) to the abort requester */
  11060. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  11061. }
  11062. /**
  11063. * lpfc_seq_complete - Indicates if a sequence is complete
  11064. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11065. *
  11066. * This function checks the sequence, starting with the frame described by
  11067. * @dmabuf, to see if all the frames associated with this sequence are present.
  11068. * the frames associated with this sequence are linked to the @dmabuf using the
  11069. * dbuf list. This function looks for two major things. 1) That the first frame
  11070. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  11071. * set. 3) That there are no holes in the sequence count. The function will
  11072. * return 1 when the sequence is complete, otherwise it will return 0.
  11073. **/
  11074. static int
  11075. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  11076. {
  11077. struct fc_frame_header *hdr;
  11078. struct lpfc_dmabuf *d_buf;
  11079. struct hbq_dmabuf *seq_dmabuf;
  11080. uint32_t fctl;
  11081. int seq_count = 0;
  11082. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11083. /* make sure first fame of sequence has a sequence count of zero */
  11084. if (hdr->fh_seq_cnt != seq_count)
  11085. return 0;
  11086. fctl = (hdr->fh_f_ctl[0] << 16 |
  11087. hdr->fh_f_ctl[1] << 8 |
  11088. hdr->fh_f_ctl[2]);
  11089. /* If last frame of sequence we can return success. */
  11090. if (fctl & FC_FC_END_SEQ)
  11091. return 1;
  11092. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  11093. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  11094. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11095. /* If there is a hole in the sequence count then fail. */
  11096. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  11097. return 0;
  11098. fctl = (hdr->fh_f_ctl[0] << 16 |
  11099. hdr->fh_f_ctl[1] << 8 |
  11100. hdr->fh_f_ctl[2]);
  11101. /* If last frame of sequence we can return success. */
  11102. if (fctl & FC_FC_END_SEQ)
  11103. return 1;
  11104. }
  11105. return 0;
  11106. }
  11107. /**
  11108. * lpfc_prep_seq - Prep sequence for ULP processing
  11109. * @vport: Pointer to the vport on which this sequence was received
  11110. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11111. *
  11112. * This function takes a sequence, described by a list of frames, and creates
  11113. * a list of iocbq structures to describe the sequence. This iocbq list will be
  11114. * used to issue to the generic unsolicited sequence handler. This routine
  11115. * returns a pointer to the first iocbq in the list. If the function is unable
  11116. * to allocate an iocbq then it throw out the received frames that were not
  11117. * able to be described and return a pointer to the first iocbq. If unable to
  11118. * allocate any iocbqs (including the first) this function will return NULL.
  11119. **/
  11120. static struct lpfc_iocbq *
  11121. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  11122. {
  11123. struct lpfc_dmabuf *d_buf, *n_buf;
  11124. struct lpfc_iocbq *first_iocbq, *iocbq;
  11125. struct fc_frame_header *fc_hdr;
  11126. uint32_t sid;
  11127. struct ulp_bde64 *pbde;
  11128. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11129. /* remove from receive buffer list */
  11130. list_del_init(&seq_dmabuf->hbuf.list);
  11131. lpfc_update_rcv_time_stamp(vport);
  11132. /* get the Remote Port's SID */
  11133. sid = sli4_sid_from_fc_hdr(fc_hdr);
  11134. /* Get an iocbq struct to fill in. */
  11135. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  11136. if (first_iocbq) {
  11137. /* Initialize the first IOCB. */
  11138. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  11139. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  11140. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  11141. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  11142. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  11143. vport->vpi + vport->phba->vpi_base;
  11144. /* put the first buffer into the first IOCBq */
  11145. first_iocbq->context2 = &seq_dmabuf->dbuf;
  11146. first_iocbq->context3 = NULL;
  11147. first_iocbq->iocb.ulpBdeCount = 1;
  11148. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11149. LPFC_DATA_BUF_SIZE;
  11150. first_iocbq->iocb.un.rcvels.remoteID = sid;
  11151. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11152. bf_get(lpfc_rcqe_length,
  11153. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11154. }
  11155. iocbq = first_iocbq;
  11156. /*
  11157. * Each IOCBq can have two Buffers assigned, so go through the list
  11158. * of buffers for this sequence and save two buffers in each IOCBq
  11159. */
  11160. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  11161. if (!iocbq) {
  11162. lpfc_in_buf_free(vport->phba, d_buf);
  11163. continue;
  11164. }
  11165. if (!iocbq->context3) {
  11166. iocbq->context3 = d_buf;
  11167. iocbq->iocb.ulpBdeCount++;
  11168. pbde = (struct ulp_bde64 *)
  11169. &iocbq->iocb.unsli3.sli3Words[4];
  11170. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  11171. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11172. bf_get(lpfc_rcqe_length,
  11173. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11174. } else {
  11175. iocbq = lpfc_sli_get_iocbq(vport->phba);
  11176. if (!iocbq) {
  11177. if (first_iocbq) {
  11178. first_iocbq->iocb.ulpStatus =
  11179. IOSTAT_FCP_RSP_ERROR;
  11180. first_iocbq->iocb.un.ulpWord[4] =
  11181. IOERR_NO_RESOURCES;
  11182. }
  11183. lpfc_in_buf_free(vport->phba, d_buf);
  11184. continue;
  11185. }
  11186. iocbq->context2 = d_buf;
  11187. iocbq->context3 = NULL;
  11188. iocbq->iocb.ulpBdeCount = 1;
  11189. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11190. LPFC_DATA_BUF_SIZE;
  11191. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11192. bf_get(lpfc_rcqe_length,
  11193. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11194. iocbq->iocb.un.rcvels.remoteID = sid;
  11195. list_add_tail(&iocbq->list, &first_iocbq->list);
  11196. }
  11197. }
  11198. return first_iocbq;
  11199. }
  11200. static void
  11201. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  11202. struct hbq_dmabuf *seq_dmabuf)
  11203. {
  11204. struct fc_frame_header *fc_hdr;
  11205. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  11206. struct lpfc_hba *phba = vport->phba;
  11207. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11208. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  11209. if (!iocbq) {
  11210. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11211. "2707 Ring %d handler: Failed to allocate "
  11212. "iocb Rctl x%x Type x%x received\n",
  11213. LPFC_ELS_RING,
  11214. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11215. return;
  11216. }
  11217. if (!lpfc_complete_unsol_iocb(phba,
  11218. &phba->sli.ring[LPFC_ELS_RING],
  11219. iocbq, fc_hdr->fh_r_ctl,
  11220. fc_hdr->fh_type))
  11221. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11222. "2540 Ring %d handler: unexpected Rctl "
  11223. "x%x Type x%x received\n",
  11224. LPFC_ELS_RING,
  11225. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11226. /* Free iocb created in lpfc_prep_seq */
  11227. list_for_each_entry_safe(curr_iocb, next_iocb,
  11228. &iocbq->list, list) {
  11229. list_del_init(&curr_iocb->list);
  11230. lpfc_sli_release_iocbq(phba, curr_iocb);
  11231. }
  11232. lpfc_sli_release_iocbq(phba, iocbq);
  11233. }
  11234. /**
  11235. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  11236. * @phba: Pointer to HBA context object.
  11237. *
  11238. * This function is called with no lock held. This function processes all
  11239. * the received buffers and gives it to upper layers when a received buffer
  11240. * indicates that it is the final frame in the sequence. The interrupt
  11241. * service routine processes received buffers at interrupt contexts and adds
  11242. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  11243. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  11244. * appropriate receive function when the final frame in a sequence is received.
  11245. **/
  11246. void
  11247. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  11248. struct hbq_dmabuf *dmabuf)
  11249. {
  11250. struct hbq_dmabuf *seq_dmabuf;
  11251. struct fc_frame_header *fc_hdr;
  11252. struct lpfc_vport *vport;
  11253. uint32_t fcfi;
  11254. /* Process each received buffer */
  11255. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11256. /* check to see if this a valid type of frame */
  11257. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  11258. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11259. return;
  11260. }
  11261. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  11262. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  11263. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  11264. /* throw out the frame */
  11265. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11266. return;
  11267. }
  11268. /* Handle the basic abort sequence (BA_ABTS) event */
  11269. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  11270. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  11271. return;
  11272. }
  11273. /* Link this frame */
  11274. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  11275. if (!seq_dmabuf) {
  11276. /* unable to add frame to vport - throw it out */
  11277. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11278. return;
  11279. }
  11280. /* If not last frame in sequence continue processing frames. */
  11281. if (!lpfc_seq_complete(seq_dmabuf))
  11282. return;
  11283. /* Send the complete sequence to the upper layer protocol */
  11284. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  11285. }
  11286. /**
  11287. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  11288. * @phba: pointer to lpfc hba data structure.
  11289. *
  11290. * This routine is invoked to post rpi header templates to the
  11291. * HBA consistent with the SLI-4 interface spec. This routine
  11292. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11293. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11294. *
  11295. * This routine does not require any locks. It's usage is expected
  11296. * to be driver load or reset recovery when the driver is
  11297. * sequential.
  11298. *
  11299. * Return codes
  11300. * 0 - successful
  11301. * -EIO - The mailbox failed to complete successfully.
  11302. * When this error occurs, the driver is not guaranteed
  11303. * to have any rpi regions posted to the device and
  11304. * must either attempt to repost the regions or take a
  11305. * fatal error.
  11306. **/
  11307. int
  11308. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  11309. {
  11310. struct lpfc_rpi_hdr *rpi_page;
  11311. uint32_t rc = 0;
  11312. /* Post all rpi memory regions to the port. */
  11313. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  11314. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  11315. if (rc != MBX_SUCCESS) {
  11316. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11317. "2008 Error %d posting all rpi "
  11318. "headers\n", rc);
  11319. rc = -EIO;
  11320. break;
  11321. }
  11322. }
  11323. return rc;
  11324. }
  11325. /**
  11326. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  11327. * @phba: pointer to lpfc hba data structure.
  11328. * @rpi_page: pointer to the rpi memory region.
  11329. *
  11330. * This routine is invoked to post a single rpi header to the
  11331. * HBA consistent with the SLI-4 interface spec. This memory region
  11332. * maps up to 64 rpi context regions.
  11333. *
  11334. * Return codes
  11335. * 0 - successful
  11336. * -ENOMEM - No available memory
  11337. * -EIO - The mailbox failed to complete successfully.
  11338. **/
  11339. int
  11340. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  11341. {
  11342. LPFC_MBOXQ_t *mboxq;
  11343. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  11344. uint32_t rc = 0;
  11345. uint32_t mbox_tmo;
  11346. uint32_t shdr_status, shdr_add_status;
  11347. union lpfc_sli4_cfg_shdr *shdr;
  11348. /* The port is notified of the header region via a mailbox command. */
  11349. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11350. if (!mboxq) {
  11351. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11352. "2001 Unable to allocate memory for issuing "
  11353. "SLI_CONFIG_SPECIAL mailbox command\n");
  11354. return -ENOMEM;
  11355. }
  11356. /* Post all rpi memory regions to the port. */
  11357. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  11358. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  11359. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11360. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  11361. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  11362. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  11363. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  11364. hdr_tmpl, rpi_page->page_count);
  11365. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  11366. rpi_page->start_rpi);
  11367. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  11368. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  11369. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  11370. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  11371. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11372. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11373. if (rc != MBX_TIMEOUT)
  11374. mempool_free(mboxq, phba->mbox_mem_pool);
  11375. if (shdr_status || shdr_add_status || rc) {
  11376. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11377. "2514 POST_RPI_HDR mailbox failed with "
  11378. "status x%x add_status x%x, mbx status x%x\n",
  11379. shdr_status, shdr_add_status, rc);
  11380. rc = -ENXIO;
  11381. }
  11382. return rc;
  11383. }
  11384. /**
  11385. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  11386. * @phba: pointer to lpfc hba data structure.
  11387. *
  11388. * This routine is invoked to post rpi header templates to the
  11389. * HBA consistent with the SLI-4 interface spec. This routine
  11390. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11391. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11392. *
  11393. * Returns
  11394. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  11395. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  11396. **/
  11397. int
  11398. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  11399. {
  11400. int rpi;
  11401. uint16_t max_rpi, rpi_base, rpi_limit;
  11402. uint16_t rpi_remaining;
  11403. struct lpfc_rpi_hdr *rpi_hdr;
  11404. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  11405. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  11406. rpi_limit = phba->sli4_hba.next_rpi;
  11407. /*
  11408. * The valid rpi range is not guaranteed to be zero-based. Start
  11409. * the search at the rpi_base as reported by the port.
  11410. */
  11411. spin_lock_irq(&phba->hbalock);
  11412. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  11413. if (rpi >= rpi_limit || rpi < rpi_base)
  11414. rpi = LPFC_RPI_ALLOC_ERROR;
  11415. else {
  11416. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  11417. phba->sli4_hba.max_cfg_param.rpi_used++;
  11418. phba->sli4_hba.rpi_count++;
  11419. }
  11420. /*
  11421. * Don't try to allocate more rpi header regions if the device limit
  11422. * on available rpis max has been exhausted.
  11423. */
  11424. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  11425. (phba->sli4_hba.rpi_count >= max_rpi)) {
  11426. spin_unlock_irq(&phba->hbalock);
  11427. return rpi;
  11428. }
  11429. /*
  11430. * If the driver is running low on rpi resources, allocate another
  11431. * page now. Note that the next_rpi value is used because
  11432. * it represents how many are actually in use whereas max_rpi notes
  11433. * how many are supported max by the device.
  11434. */
  11435. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  11436. phba->sli4_hba.rpi_count;
  11437. spin_unlock_irq(&phba->hbalock);
  11438. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  11439. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  11440. if (!rpi_hdr) {
  11441. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11442. "2002 Error Could not grow rpi "
  11443. "count\n");
  11444. } else {
  11445. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  11446. }
  11447. }
  11448. return rpi;
  11449. }
  11450. /**
  11451. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11452. * @phba: pointer to lpfc hba data structure.
  11453. *
  11454. * This routine is invoked to release an rpi to the pool of
  11455. * available rpis maintained by the driver.
  11456. **/
  11457. void
  11458. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11459. {
  11460. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  11461. phba->sli4_hba.rpi_count--;
  11462. phba->sli4_hba.max_cfg_param.rpi_used--;
  11463. }
  11464. }
  11465. /**
  11466. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11467. * @phba: pointer to lpfc hba data structure.
  11468. *
  11469. * This routine is invoked to release an rpi to the pool of
  11470. * available rpis maintained by the driver.
  11471. **/
  11472. void
  11473. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11474. {
  11475. spin_lock_irq(&phba->hbalock);
  11476. __lpfc_sli4_free_rpi(phba, rpi);
  11477. spin_unlock_irq(&phba->hbalock);
  11478. }
  11479. /**
  11480. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  11481. * @phba: pointer to lpfc hba data structure.
  11482. *
  11483. * This routine is invoked to remove the memory region that
  11484. * provided rpi via a bitmask.
  11485. **/
  11486. void
  11487. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  11488. {
  11489. kfree(phba->sli4_hba.rpi_bmask);
  11490. }
  11491. /**
  11492. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  11493. * @phba: pointer to lpfc hba data structure.
  11494. *
  11495. * This routine is invoked to remove the memory region that
  11496. * provided rpi via a bitmask.
  11497. **/
  11498. int
  11499. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  11500. {
  11501. LPFC_MBOXQ_t *mboxq;
  11502. struct lpfc_hba *phba = ndlp->phba;
  11503. int rc;
  11504. /* The port is notified of the header region via a mailbox command. */
  11505. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11506. if (!mboxq)
  11507. return -ENOMEM;
  11508. /* Post all rpi memory regions to the port. */
  11509. lpfc_resume_rpi(mboxq, ndlp);
  11510. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11511. if (rc == MBX_NOT_FINISHED) {
  11512. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11513. "2010 Resume RPI Mailbox failed "
  11514. "status %d, mbxStatus x%x\n", rc,
  11515. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11516. mempool_free(mboxq, phba->mbox_mem_pool);
  11517. return -EIO;
  11518. }
  11519. return 0;
  11520. }
  11521. /**
  11522. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11523. * @vport: Pointer to the vport for which the vpi is being initialized
  11524. *
  11525. * This routine is invoked to activate a vpi with the port.
  11526. *
  11527. * Returns:
  11528. * 0 success
  11529. * -Evalue otherwise
  11530. **/
  11531. int
  11532. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  11533. {
  11534. LPFC_MBOXQ_t *mboxq;
  11535. int rc = 0;
  11536. int retval = MBX_SUCCESS;
  11537. uint32_t mbox_tmo;
  11538. struct lpfc_hba *phba = vport->phba;
  11539. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11540. if (!mboxq)
  11541. return -ENOMEM;
  11542. lpfc_init_vpi(phba, mboxq, vport->vpi);
  11543. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11544. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11545. if (rc != MBX_SUCCESS) {
  11546. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  11547. "2022 INIT VPI Mailbox failed "
  11548. "status %d, mbxStatus x%x\n", rc,
  11549. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11550. retval = -EIO;
  11551. }
  11552. if (rc != MBX_TIMEOUT)
  11553. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  11554. return retval;
  11555. }
  11556. /**
  11557. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11558. * @phba: pointer to lpfc hba data structure.
  11559. * @mboxq: Pointer to mailbox object.
  11560. *
  11561. * This routine is invoked to manually add a single FCF record. The caller
  11562. * must pass a completely initialized FCF_Record. This routine takes
  11563. * care of the nonembedded mailbox operations.
  11564. **/
  11565. static void
  11566. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11567. {
  11568. void *virt_addr;
  11569. union lpfc_sli4_cfg_shdr *shdr;
  11570. uint32_t shdr_status, shdr_add_status;
  11571. virt_addr = mboxq->sge_array->addr[0];
  11572. /* The IOCTL status is embedded in the mailbox subheader. */
  11573. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11574. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11575. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11576. if ((shdr_status || shdr_add_status) &&
  11577. (shdr_status != STATUS_FCF_IN_USE))
  11578. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11579. "2558 ADD_FCF_RECORD mailbox failed with "
  11580. "status x%x add_status x%x\n",
  11581. shdr_status, shdr_add_status);
  11582. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11583. }
  11584. /**
  11585. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11586. * @phba: pointer to lpfc hba data structure.
  11587. * @fcf_record: pointer to the initialized fcf record to add.
  11588. *
  11589. * This routine is invoked to manually add a single FCF record. The caller
  11590. * must pass a completely initialized FCF_Record. This routine takes
  11591. * care of the nonembedded mailbox operations.
  11592. **/
  11593. int
  11594. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11595. {
  11596. int rc = 0;
  11597. LPFC_MBOXQ_t *mboxq;
  11598. uint8_t *bytep;
  11599. void *virt_addr;
  11600. dma_addr_t phys_addr;
  11601. struct lpfc_mbx_sge sge;
  11602. uint32_t alloc_len, req_len;
  11603. uint32_t fcfindex;
  11604. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11605. if (!mboxq) {
  11606. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11607. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11608. return -ENOMEM;
  11609. }
  11610. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11611. sizeof(uint32_t);
  11612. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11613. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11614. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11615. req_len, LPFC_SLI4_MBX_NEMBED);
  11616. if (alloc_len < req_len) {
  11617. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11618. "2523 Allocated DMA memory size (x%x) is "
  11619. "less than the requested DMA memory "
  11620. "size (x%x)\n", alloc_len, req_len);
  11621. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11622. return -ENOMEM;
  11623. }
  11624. /*
  11625. * Get the first SGE entry from the non-embedded DMA memory. This
  11626. * routine only uses a single SGE.
  11627. */
  11628. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11629. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11630. virt_addr = mboxq->sge_array->addr[0];
  11631. /*
  11632. * Configure the FCF record for FCFI 0. This is the driver's
  11633. * hardcoded default and gets used in nonFIP mode.
  11634. */
  11635. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11636. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11637. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11638. /*
  11639. * Copy the fcf_index and the FCF Record Data. The data starts after
  11640. * the FCoE header plus word10. The data copy needs to be endian
  11641. * correct.
  11642. */
  11643. bytep += sizeof(uint32_t);
  11644. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11645. mboxq->vport = phba->pport;
  11646. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11647. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11648. if (rc == MBX_NOT_FINISHED) {
  11649. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11650. "2515 ADD_FCF_RECORD mailbox failed with "
  11651. "status 0x%x\n", rc);
  11652. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11653. rc = -EIO;
  11654. } else
  11655. rc = 0;
  11656. return rc;
  11657. }
  11658. /**
  11659. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11660. * @phba: pointer to lpfc hba data structure.
  11661. * @fcf_record: pointer to the fcf record to write the default data.
  11662. * @fcf_index: FCF table entry index.
  11663. *
  11664. * This routine is invoked to build the driver's default FCF record. The
  11665. * values used are hardcoded. This routine handles memory initialization.
  11666. *
  11667. **/
  11668. void
  11669. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11670. struct fcf_record *fcf_record,
  11671. uint16_t fcf_index)
  11672. {
  11673. memset(fcf_record, 0, sizeof(struct fcf_record));
  11674. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11675. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11676. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11677. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11678. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11679. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11680. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11681. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11682. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11683. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11684. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11685. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11686. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11687. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11688. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11689. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11690. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11691. /* Set the VLAN bit map */
  11692. if (phba->valid_vlan) {
  11693. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11694. = 1 << (phba->vlan_id % 8);
  11695. }
  11696. }
  11697. /**
  11698. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11699. * @phba: pointer to lpfc hba data structure.
  11700. * @fcf_index: FCF table entry offset.
  11701. *
  11702. * This routine is invoked to scan the entire FCF table by reading FCF
  11703. * record and processing it one at a time starting from the @fcf_index
  11704. * for initial FCF discovery or fast FCF failover rediscovery.
  11705. *
  11706. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11707. * otherwise.
  11708. **/
  11709. int
  11710. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11711. {
  11712. int rc = 0, error;
  11713. LPFC_MBOXQ_t *mboxq;
  11714. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11715. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11716. if (!mboxq) {
  11717. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11718. "2000 Failed to allocate mbox for "
  11719. "READ_FCF cmd\n");
  11720. error = -ENOMEM;
  11721. goto fail_fcf_scan;
  11722. }
  11723. /* Construct the read FCF record mailbox command */
  11724. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11725. if (rc) {
  11726. error = -EINVAL;
  11727. goto fail_fcf_scan;
  11728. }
  11729. /* Issue the mailbox command asynchronously */
  11730. mboxq->vport = phba->pport;
  11731. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11732. spin_lock_irq(&phba->hbalock);
  11733. phba->hba_flag |= FCF_TS_INPROG;
  11734. spin_unlock_irq(&phba->hbalock);
  11735. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11736. if (rc == MBX_NOT_FINISHED)
  11737. error = -EIO;
  11738. else {
  11739. /* Reset eligible FCF count for new scan */
  11740. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11741. phba->fcf.eligible_fcf_cnt = 0;
  11742. error = 0;
  11743. }
  11744. fail_fcf_scan:
  11745. if (error) {
  11746. if (mboxq)
  11747. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11748. /* FCF scan failed, clear FCF_TS_INPROG flag */
  11749. spin_lock_irq(&phba->hbalock);
  11750. phba->hba_flag &= ~FCF_TS_INPROG;
  11751. spin_unlock_irq(&phba->hbalock);
  11752. }
  11753. return error;
  11754. }
  11755. /**
  11756. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  11757. * @phba: pointer to lpfc hba data structure.
  11758. * @fcf_index: FCF table entry offset.
  11759. *
  11760. * This routine is invoked to read an FCF record indicated by @fcf_index
  11761. * and to use it for FLOGI roundrobin FCF failover.
  11762. *
  11763. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11764. * otherwise.
  11765. **/
  11766. int
  11767. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11768. {
  11769. int rc = 0, error;
  11770. LPFC_MBOXQ_t *mboxq;
  11771. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11772. if (!mboxq) {
  11773. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11774. "2763 Failed to allocate mbox for "
  11775. "READ_FCF cmd\n");
  11776. error = -ENOMEM;
  11777. goto fail_fcf_read;
  11778. }
  11779. /* Construct the read FCF record mailbox command */
  11780. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11781. if (rc) {
  11782. error = -EINVAL;
  11783. goto fail_fcf_read;
  11784. }
  11785. /* Issue the mailbox command asynchronously */
  11786. mboxq->vport = phba->pport;
  11787. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11788. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11789. if (rc == MBX_NOT_FINISHED)
  11790. error = -EIO;
  11791. else
  11792. error = 0;
  11793. fail_fcf_read:
  11794. if (error && mboxq)
  11795. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11796. return error;
  11797. }
  11798. /**
  11799. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11800. * @phba: pointer to lpfc hba data structure.
  11801. * @fcf_index: FCF table entry offset.
  11802. *
  11803. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11804. * determine whether it's eligible for FLOGI roundrobin failover list.
  11805. *
  11806. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11807. * otherwise.
  11808. **/
  11809. int
  11810. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11811. {
  11812. int rc = 0, error;
  11813. LPFC_MBOXQ_t *mboxq;
  11814. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11815. if (!mboxq) {
  11816. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11817. "2758 Failed to allocate mbox for "
  11818. "READ_FCF cmd\n");
  11819. error = -ENOMEM;
  11820. goto fail_fcf_read;
  11821. }
  11822. /* Construct the read FCF record mailbox command */
  11823. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11824. if (rc) {
  11825. error = -EINVAL;
  11826. goto fail_fcf_read;
  11827. }
  11828. /* Issue the mailbox command asynchronously */
  11829. mboxq->vport = phba->pport;
  11830. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11831. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11832. if (rc == MBX_NOT_FINISHED)
  11833. error = -EIO;
  11834. else
  11835. error = 0;
  11836. fail_fcf_read:
  11837. if (error && mboxq)
  11838. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11839. return error;
  11840. }
  11841. /**
  11842. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11843. * @phba: pointer to lpfc hba data structure.
  11844. *
  11845. * This routine is to get the next eligible FCF record index in a round
  11846. * robin fashion. If the next eligible FCF record index equals to the
  11847. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11848. * shall be returned, otherwise, the next eligible FCF record's index
  11849. * shall be returned.
  11850. **/
  11851. uint16_t
  11852. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11853. {
  11854. uint16_t next_fcf_index;
  11855. /* Search start from next bit of currently registered FCF index */
  11856. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  11857. LPFC_SLI4_FCF_TBL_INDX_MAX;
  11858. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11859. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11860. next_fcf_index);
  11861. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11862. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11863. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11864. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11865. /* Check roundrobin failover list empty condition */
  11866. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11867. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  11868. "2844 No roundrobin failover FCF available\n");
  11869. return LPFC_FCOE_FCF_NEXT_NONE;
  11870. }
  11871. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11872. "2845 Get next roundrobin failover FCF (x%x)\n",
  11873. next_fcf_index);
  11874. return next_fcf_index;
  11875. }
  11876. /**
  11877. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11878. * @phba: pointer to lpfc hba data structure.
  11879. *
  11880. * This routine sets the FCF record index in to the eligible bmask for
  11881. * roundrobin failover search. It checks to make sure that the index
  11882. * does not go beyond the range of the driver allocated bmask dimension
  11883. * before setting the bit.
  11884. *
  11885. * Returns 0 if the index bit successfully set, otherwise, it returns
  11886. * -EINVAL.
  11887. **/
  11888. int
  11889. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11890. {
  11891. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11892. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11893. "2610 FCF (x%x) reached driver's book "
  11894. "keeping dimension:x%x\n",
  11895. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11896. return -EINVAL;
  11897. }
  11898. /* Set the eligible FCF record index bmask */
  11899. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11900. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11901. "2790 Set FCF (x%x) to roundrobin FCF failover "
  11902. "bmask\n", fcf_index);
  11903. return 0;
  11904. }
  11905. /**
  11906. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  11907. * @phba: pointer to lpfc hba data structure.
  11908. *
  11909. * This routine clears the FCF record index from the eligible bmask for
  11910. * roundrobin failover search. It checks to make sure that the index
  11911. * does not go beyond the range of the driver allocated bmask dimension
  11912. * before clearing the bit.
  11913. **/
  11914. void
  11915. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11916. {
  11917. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11918. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11919. "2762 FCF (x%x) reached driver's book "
  11920. "keeping dimension:x%x\n",
  11921. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11922. return;
  11923. }
  11924. /* Clear the eligible FCF record index bmask */
  11925. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11926. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11927. "2791 Clear FCF (x%x) from roundrobin failover "
  11928. "bmask\n", fcf_index);
  11929. }
  11930. /**
  11931. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11932. * @phba: pointer to lpfc hba data structure.
  11933. *
  11934. * This routine is the completion routine for the rediscover FCF table mailbox
  11935. * command. If the mailbox command returned failure, it will try to stop the
  11936. * FCF rediscover wait timer.
  11937. **/
  11938. void
  11939. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11940. {
  11941. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11942. uint32_t shdr_status, shdr_add_status;
  11943. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11944. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11945. &redisc_fcf->header.cfg_shdr.response);
  11946. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11947. &redisc_fcf->header.cfg_shdr.response);
  11948. if (shdr_status || shdr_add_status) {
  11949. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11950. "2746 Requesting for FCF rediscovery failed "
  11951. "status x%x add_status x%x\n",
  11952. shdr_status, shdr_add_status);
  11953. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11954. spin_lock_irq(&phba->hbalock);
  11955. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11956. spin_unlock_irq(&phba->hbalock);
  11957. /*
  11958. * CVL event triggered FCF rediscover request failed,
  11959. * last resort to re-try current registered FCF entry.
  11960. */
  11961. lpfc_retry_pport_discovery(phba);
  11962. } else {
  11963. spin_lock_irq(&phba->hbalock);
  11964. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11965. spin_unlock_irq(&phba->hbalock);
  11966. /*
  11967. * DEAD FCF event triggered FCF rediscover request
  11968. * failed, last resort to fail over as a link down
  11969. * to FCF registration.
  11970. */
  11971. lpfc_sli4_fcf_dead_failthrough(phba);
  11972. }
  11973. } else {
  11974. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11975. "2775 Start FCF rediscover quiescent timer\n");
  11976. /*
  11977. * Start FCF rediscovery wait timer for pending FCF
  11978. * before rescan FCF record table.
  11979. */
  11980. lpfc_fcf_redisc_wait_start_timer(phba);
  11981. }
  11982. mempool_free(mbox, phba->mbox_mem_pool);
  11983. }
  11984. /**
  11985. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  11986. * @phba: pointer to lpfc hba data structure.
  11987. *
  11988. * This routine is invoked to request for rediscovery of the entire FCF table
  11989. * by the port.
  11990. **/
  11991. int
  11992. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11993. {
  11994. LPFC_MBOXQ_t *mbox;
  11995. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11996. int rc, length;
  11997. /* Cancel retry delay timers to all vports before FCF rediscover */
  11998. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11999. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12000. if (!mbox) {
  12001. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12002. "2745 Failed to allocate mbox for "
  12003. "requesting FCF rediscover.\n");
  12004. return -ENOMEM;
  12005. }
  12006. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  12007. sizeof(struct lpfc_sli4_cfg_mhdr));
  12008. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12009. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  12010. length, LPFC_SLI4_MBX_EMBED);
  12011. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  12012. /* Set count to 0 for invalidating the entire FCF database */
  12013. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  12014. /* Issue the mailbox command asynchronously */
  12015. mbox->vport = phba->pport;
  12016. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  12017. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  12018. if (rc == MBX_NOT_FINISHED) {
  12019. mempool_free(mbox, phba->mbox_mem_pool);
  12020. return -EIO;
  12021. }
  12022. return 0;
  12023. }
  12024. /**
  12025. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  12026. * @phba: pointer to lpfc hba data structure.
  12027. *
  12028. * This function is the failover routine as a last resort to the FCF DEAD
  12029. * event when driver failed to perform fast FCF failover.
  12030. **/
  12031. void
  12032. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  12033. {
  12034. uint32_t link_state;
  12035. /*
  12036. * Last resort as FCF DEAD event failover will treat this as
  12037. * a link down, but save the link state because we don't want
  12038. * it to be changed to Link Down unless it is already down.
  12039. */
  12040. link_state = phba->link_state;
  12041. lpfc_linkdown(phba);
  12042. phba->link_state = link_state;
  12043. /* Unregister FCF if no devices connected to it */
  12044. lpfc_unregister_unused_fcf(phba);
  12045. }
  12046. /**
  12047. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  12048. * @phba: pointer to lpfc hba data structure.
  12049. *
  12050. * This function read region 23 and parse TLV for port status to
  12051. * decide if the user disaled the port. If the TLV indicates the
  12052. * port is disabled, the hba_flag is set accordingly.
  12053. **/
  12054. void
  12055. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  12056. {
  12057. LPFC_MBOXQ_t *pmb = NULL;
  12058. MAILBOX_t *mb;
  12059. uint8_t *rgn23_data = NULL;
  12060. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  12061. int rc;
  12062. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12063. if (!pmb) {
  12064. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12065. "2600 lpfc_sli_read_serdes_param failed to"
  12066. " allocate mailbox memory\n");
  12067. goto out;
  12068. }
  12069. mb = &pmb->u.mb;
  12070. /* Get adapter Region 23 data */
  12071. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  12072. if (!rgn23_data)
  12073. goto out;
  12074. do {
  12075. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  12076. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  12077. if (rc != MBX_SUCCESS) {
  12078. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12079. "2601 lpfc_sli_read_link_ste failed to"
  12080. " read config region 23 rc 0x%x Status 0x%x\n",
  12081. rc, mb->mbxStatus);
  12082. mb->un.varDmp.word_cnt = 0;
  12083. }
  12084. /*
  12085. * dump mem may return a zero when finished or we got a
  12086. * mailbox error, either way we are done.
  12087. */
  12088. if (mb->un.varDmp.word_cnt == 0)
  12089. break;
  12090. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  12091. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  12092. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  12093. rgn23_data + offset,
  12094. mb->un.varDmp.word_cnt);
  12095. offset += mb->un.varDmp.word_cnt;
  12096. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  12097. data_size = offset;
  12098. offset = 0;
  12099. if (!data_size)
  12100. goto out;
  12101. /* Check the region signature first */
  12102. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  12103. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12104. "2619 Config region 23 has bad signature\n");
  12105. goto out;
  12106. }
  12107. offset += 4;
  12108. /* Check the data structure version */
  12109. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  12110. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12111. "2620 Config region 23 has bad version\n");
  12112. goto out;
  12113. }
  12114. offset += 4;
  12115. /* Parse TLV entries in the region */
  12116. while (offset < data_size) {
  12117. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  12118. break;
  12119. /*
  12120. * If the TLV is not driver specific TLV or driver id is
  12121. * not linux driver id, skip the record.
  12122. */
  12123. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  12124. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  12125. (rgn23_data[offset + 3] != 0)) {
  12126. offset += rgn23_data[offset + 1] * 4 + 4;
  12127. continue;
  12128. }
  12129. /* Driver found a driver specific TLV in the config region */
  12130. sub_tlv_len = rgn23_data[offset + 1] * 4;
  12131. offset += 4;
  12132. tlv_offset = 0;
  12133. /*
  12134. * Search for configured port state sub-TLV.
  12135. */
  12136. while ((offset < data_size) &&
  12137. (tlv_offset < sub_tlv_len)) {
  12138. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  12139. offset += 4;
  12140. tlv_offset += 4;
  12141. break;
  12142. }
  12143. if (rgn23_data[offset] != PORT_STE_TYPE) {
  12144. offset += rgn23_data[offset + 1] * 4 + 4;
  12145. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  12146. continue;
  12147. }
  12148. /* This HBA contains PORT_STE configured */
  12149. if (!rgn23_data[offset + 2])
  12150. phba->hba_flag |= LINK_DISABLED;
  12151. goto out;
  12152. }
  12153. }
  12154. out:
  12155. if (pmb)
  12156. mempool_free(pmb, phba->mbox_mem_pool);
  12157. kfree(rgn23_data);
  12158. return;
  12159. }
  12160. /**
  12161. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  12162. * @vport: pointer to vport data structure.
  12163. *
  12164. * This function iterate through the mailboxq and clean up all REG_LOGIN
  12165. * and REG_VPI mailbox commands associated with the vport. This function
  12166. * is called when driver want to restart discovery of the vport due to
  12167. * a Clear Virtual Link event.
  12168. **/
  12169. void
  12170. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  12171. {
  12172. struct lpfc_hba *phba = vport->phba;
  12173. LPFC_MBOXQ_t *mb, *nextmb;
  12174. struct lpfc_dmabuf *mp;
  12175. struct lpfc_nodelist *ndlp;
  12176. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  12177. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  12178. LIST_HEAD(mbox_cmd_list);
  12179. uint8_t restart_loop;
  12180. /* Clean up internally queued mailbox commands with the vport */
  12181. spin_lock_irq(&phba->hbalock);
  12182. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  12183. if (mb->vport != vport)
  12184. continue;
  12185. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12186. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12187. continue;
  12188. list_del(&mb->list);
  12189. list_add_tail(&mb->list, &mbox_cmd_list);
  12190. }
  12191. /* Clean up active mailbox command with the vport */
  12192. mb = phba->sli.mbox_active;
  12193. if (mb && (mb->vport == vport)) {
  12194. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  12195. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  12196. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12197. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12198. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  12199. /* Put reference count for delayed processing */
  12200. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  12201. /* Unregister the RPI when mailbox complete */
  12202. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12203. }
  12204. }
  12205. /* Cleanup any mailbox completions which are not yet processed */
  12206. do {
  12207. restart_loop = 0;
  12208. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  12209. /*
  12210. * If this mailox is already processed or it is
  12211. * for another vport ignore it.
  12212. */
  12213. if ((mb->vport != vport) ||
  12214. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  12215. continue;
  12216. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12217. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12218. continue;
  12219. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12220. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12221. ndlp = (struct lpfc_nodelist *)mb->context2;
  12222. /* Unregister the RPI when mailbox complete */
  12223. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12224. restart_loop = 1;
  12225. spin_unlock_irq(&phba->hbalock);
  12226. spin_lock(shost->host_lock);
  12227. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12228. spin_unlock(shost->host_lock);
  12229. spin_lock_irq(&phba->hbalock);
  12230. break;
  12231. }
  12232. }
  12233. } while (restart_loop);
  12234. spin_unlock_irq(&phba->hbalock);
  12235. /* Release the cleaned-up mailbox commands */
  12236. while (!list_empty(&mbox_cmd_list)) {
  12237. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  12238. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12239. mp = (struct lpfc_dmabuf *) (mb->context1);
  12240. if (mp) {
  12241. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  12242. kfree(mp);
  12243. }
  12244. ndlp = (struct lpfc_nodelist *) mb->context2;
  12245. mb->context2 = NULL;
  12246. if (ndlp) {
  12247. spin_lock(shost->host_lock);
  12248. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12249. spin_unlock(shost->host_lock);
  12250. lpfc_nlp_put(ndlp);
  12251. }
  12252. }
  12253. mempool_free(mb, phba->mbox_mem_pool);
  12254. }
  12255. /* Release the ndlp with the cleaned-up active mailbox command */
  12256. if (act_mbx_ndlp) {
  12257. spin_lock(shost->host_lock);
  12258. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12259. spin_unlock(shost->host_lock);
  12260. lpfc_nlp_put(act_mbx_ndlp);
  12261. }
  12262. }
  12263. /**
  12264. * lpfc_drain_txq - Drain the txq
  12265. * @phba: Pointer to HBA context object.
  12266. *
  12267. * This function attempt to submit IOCBs on the txq
  12268. * to the adapter. For SLI4 adapters, the txq contains
  12269. * ELS IOCBs that have been deferred because the there
  12270. * are no SGLs. This congestion can occur with large
  12271. * vport counts during node discovery.
  12272. **/
  12273. uint32_t
  12274. lpfc_drain_txq(struct lpfc_hba *phba)
  12275. {
  12276. LIST_HEAD(completions);
  12277. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  12278. struct lpfc_iocbq *piocbq = 0;
  12279. unsigned long iflags = 0;
  12280. char *fail_msg = NULL;
  12281. struct lpfc_sglq *sglq;
  12282. union lpfc_wqe wqe;
  12283. spin_lock_irqsave(&phba->hbalock, iflags);
  12284. if (pring->txq_cnt > pring->txq_max)
  12285. pring->txq_max = pring->txq_cnt;
  12286. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12287. while (pring->txq_cnt) {
  12288. spin_lock_irqsave(&phba->hbalock, iflags);
  12289. piocbq = lpfc_sli_ringtx_get(phba, pring);
  12290. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  12291. if (!sglq) {
  12292. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  12293. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12294. break;
  12295. } else {
  12296. if (!piocbq) {
  12297. /* The txq_cnt out of sync. This should
  12298. * never happen
  12299. */
  12300. sglq = __lpfc_clear_active_sglq(phba,
  12301. sglq->sli4_xritag);
  12302. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12303. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12304. "2823 txq empty and txq_cnt is %d\n ",
  12305. pring->txq_cnt);
  12306. break;
  12307. }
  12308. }
  12309. /* The xri and iocb resources secured,
  12310. * attempt to issue request
  12311. */
  12312. piocbq->sli4_xritag = sglq->sli4_xritag;
  12313. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  12314. fail_msg = "to convert bpl to sgl";
  12315. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  12316. fail_msg = "to convert iocb to wqe";
  12317. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  12318. fail_msg = " - Wq is full";
  12319. else
  12320. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  12321. if (fail_msg) {
  12322. /* Failed means we can't issue and need to cancel */
  12323. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12324. "2822 IOCB failed %s iotag 0x%x "
  12325. "xri 0x%x\n",
  12326. fail_msg,
  12327. piocbq->iotag, piocbq->sli4_xritag);
  12328. list_add_tail(&piocbq->list, &completions);
  12329. }
  12330. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12331. }
  12332. /* Cancel all the IOCBs that cannot be issued */
  12333. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  12334. IOERR_SLI_ABORTED);
  12335. return pring->txq_cnt;
  12336. }