lpfc_sli.c 378 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267
  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 <scsi/scsi.h>
  26. #include <scsi/scsi_cmnd.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include <scsi/fc/fc_fs.h>
  31. #include <linux/aer.h>
  32. #include "lpfc_hw4.h"
  33. #include "lpfc_hw.h"
  34. #include "lpfc_sli.h"
  35. #include "lpfc_sli4.h"
  36. #include "lpfc_nl.h"
  37. #include "lpfc_disc.h"
  38. #include "lpfc_scsi.h"
  39. #include "lpfc.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_logmsg.h"
  42. #include "lpfc_compat.h"
  43. #include "lpfc_debugfs.h"
  44. #include "lpfc_vport.h"
  45. /* There are only four IOCB completion types. */
  46. typedef enum _lpfc_iocb_type {
  47. LPFC_UNKNOWN_IOCB,
  48. LPFC_UNSOL_IOCB,
  49. LPFC_SOL_IOCB,
  50. LPFC_ABORT_IOCB
  51. } lpfc_iocb_type;
  52. /* Provide function prototypes local to this module. */
  53. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  54. uint32_t);
  55. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  56. uint8_t *, uint32_t *);
  57. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  58. struct lpfc_iocbq *);
  59. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  60. struct hbq_dmabuf *);
  61. static IOCB_t *
  62. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  63. {
  64. return &iocbq->iocb;
  65. }
  66. /**
  67. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  68. * @q: The Work Queue to operate on.
  69. * @wqe: The work Queue Entry to put on the Work queue.
  70. *
  71. * This routine will copy the contents of @wqe to the next available entry on
  72. * the @q. This function will then ring the Work Queue Doorbell to signal the
  73. * HBA to start processing the Work Queue Entry. This function returns 0 if
  74. * successful. If no entries are available on @q then this function will return
  75. * -ENOMEM.
  76. * The caller is expected to hold the hbalock when calling this routine.
  77. **/
  78. static uint32_t
  79. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  80. {
  81. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  82. struct lpfc_register doorbell;
  83. uint32_t host_index;
  84. /* If the host has not yet processed the next entry then we are done */
  85. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  86. return -ENOMEM;
  87. /* set consumption flag every once in a while */
  88. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  89. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  90. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  91. /* Update the host index before invoking device */
  92. host_index = q->host_index;
  93. q->host_index = ((q->host_index + 1) % q->entry_count);
  94. /* Ring Doorbell */
  95. doorbell.word0 = 0;
  96. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  97. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  98. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  99. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  100. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  101. return 0;
  102. }
  103. /**
  104. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  105. * @q: The Work Queue to operate on.
  106. * @index: The index to advance the hba index to.
  107. *
  108. * This routine will update the HBA index of a queue to reflect consumption of
  109. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  110. * an entry the host calls this function to update the queue's internal
  111. * pointers. This routine returns the number of entries that were consumed by
  112. * the HBA.
  113. **/
  114. static uint32_t
  115. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  116. {
  117. uint32_t released = 0;
  118. if (q->hba_index == index)
  119. return 0;
  120. do {
  121. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  122. released++;
  123. } while (q->hba_index != index);
  124. return released;
  125. }
  126. /**
  127. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  128. * @q: The Mailbox Queue to operate on.
  129. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  130. *
  131. * This routine will copy the contents of @mqe to the next available entry on
  132. * the @q. This function will then ring the Work Queue Doorbell to signal the
  133. * HBA to start processing the Work Queue Entry. This function returns 0 if
  134. * successful. If no entries are available on @q then this function will return
  135. * -ENOMEM.
  136. * The caller is expected to hold the hbalock when calling this routine.
  137. **/
  138. static uint32_t
  139. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  140. {
  141. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  142. struct lpfc_register doorbell;
  143. uint32_t host_index;
  144. /* If the host has not yet processed the next entry then we are done */
  145. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  146. return -ENOMEM;
  147. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  148. /* Save off the mailbox pointer for completion */
  149. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  150. /* Update the host index before invoking device */
  151. host_index = q->host_index;
  152. q->host_index = ((q->host_index + 1) % q->entry_count);
  153. /* Ring Doorbell */
  154. doorbell.word0 = 0;
  155. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  156. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  157. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  158. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  159. return 0;
  160. }
  161. /**
  162. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  163. * @q: The Mailbox Queue to operate on.
  164. *
  165. * This routine will update the HBA index of a queue to reflect consumption of
  166. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  167. * an entry the host calls this function to update the queue's internal
  168. * pointers. This routine returns the number of entries that were consumed by
  169. * the HBA.
  170. **/
  171. static uint32_t
  172. lpfc_sli4_mq_release(struct lpfc_queue *q)
  173. {
  174. /* Clear the mailbox pointer for completion */
  175. q->phba->mbox = NULL;
  176. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  177. return 1;
  178. }
  179. /**
  180. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  181. * @q: The Event Queue to get the first valid EQE from
  182. *
  183. * This routine will get the first valid Event Queue Entry from @q, update
  184. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  185. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  186. * processed, but not popped back to the HBA then this routine will return NULL.
  187. **/
  188. static struct lpfc_eqe *
  189. lpfc_sli4_eq_get(struct lpfc_queue *q)
  190. {
  191. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  192. /* If the next EQE is not valid then we are done */
  193. if (!bf_get(lpfc_eqe_valid, eqe))
  194. return NULL;
  195. /* If the host has not yet processed the next entry then we are done */
  196. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  197. return NULL;
  198. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  199. return eqe;
  200. }
  201. /**
  202. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  203. * @q: The Event Queue that the host has completed processing for.
  204. * @arm: Indicates whether the host wants to arms this CQ.
  205. *
  206. * This routine will mark all Event Queue Entries on @q, from the last
  207. * known completed entry to the last entry that was processed, as completed
  208. * by clearing the valid bit for each completion queue entry. Then it will
  209. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  210. * The internal host index in the @q will be updated by this routine to indicate
  211. * that the host has finished processing the entries. The @arm parameter
  212. * indicates that the queue should be rearmed when ringing the doorbell.
  213. *
  214. * This function will return the number of EQEs that were popped.
  215. **/
  216. uint32_t
  217. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  218. {
  219. uint32_t released = 0;
  220. struct lpfc_eqe *temp_eqe;
  221. struct lpfc_register doorbell;
  222. /* while there are valid entries */
  223. while (q->hba_index != q->host_index) {
  224. temp_eqe = q->qe[q->host_index].eqe;
  225. bf_set(lpfc_eqe_valid, temp_eqe, 0);
  226. released++;
  227. q->host_index = ((q->host_index + 1) % q->entry_count);
  228. }
  229. if (unlikely(released == 0 && !arm))
  230. return 0;
  231. /* ring doorbell for number popped */
  232. doorbell.word0 = 0;
  233. if (arm) {
  234. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  235. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  236. }
  237. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  238. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  239. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  240. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  241. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  242. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  243. readl(q->phba->sli4_hba.EQCQDBregaddr);
  244. return released;
  245. }
  246. /**
  247. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  248. * @q: The Completion Queue to get the first valid CQE from
  249. *
  250. * This routine will get the first valid Completion Queue Entry from @q, update
  251. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  252. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  253. * processed, but not popped back to the HBA then this routine will return NULL.
  254. **/
  255. static struct lpfc_cqe *
  256. lpfc_sli4_cq_get(struct lpfc_queue *q)
  257. {
  258. struct lpfc_cqe *cqe;
  259. /* If the next CQE is not valid then we are done */
  260. if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  261. return NULL;
  262. /* If the host has not yet processed the next entry then we are done */
  263. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  264. return NULL;
  265. cqe = q->qe[q->hba_index].cqe;
  266. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  267. return cqe;
  268. }
  269. /**
  270. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  271. * @q: The Completion Queue that the host has completed processing for.
  272. * @arm: Indicates whether the host wants to arms this CQ.
  273. *
  274. * This routine will mark all Completion queue entries on @q, from the last
  275. * known completed entry to the last entry that was processed, as completed
  276. * by clearing the valid bit for each completion queue entry. Then it will
  277. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  278. * The internal host index in the @q will be updated by this routine to indicate
  279. * that the host has finished processing the entries. The @arm parameter
  280. * indicates that the queue should be rearmed when ringing the doorbell.
  281. *
  282. * This function will return the number of CQEs that were released.
  283. **/
  284. uint32_t
  285. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  286. {
  287. uint32_t released = 0;
  288. struct lpfc_cqe *temp_qe;
  289. struct lpfc_register doorbell;
  290. /* while there are valid entries */
  291. while (q->hba_index != q->host_index) {
  292. temp_qe = q->qe[q->host_index].cqe;
  293. bf_set(lpfc_cqe_valid, temp_qe, 0);
  294. released++;
  295. q->host_index = ((q->host_index + 1) % q->entry_count);
  296. }
  297. if (unlikely(released == 0 && !arm))
  298. return 0;
  299. /* ring doorbell for number popped */
  300. doorbell.word0 = 0;
  301. if (arm)
  302. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  303. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  304. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  305. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  306. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  307. return released;
  308. }
  309. /**
  310. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  311. * @q: The Header Receive Queue to operate on.
  312. * @wqe: The Receive Queue Entry to put on the Receive queue.
  313. *
  314. * This routine will copy the contents of @wqe to the next available entry on
  315. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  316. * HBA to start processing the Receive Queue Entry. This function returns the
  317. * index that the rqe was copied to if successful. If no entries are available
  318. * on @q then this function will return -ENOMEM.
  319. * The caller is expected to hold the hbalock when calling this routine.
  320. **/
  321. static int
  322. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  323. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  324. {
  325. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  326. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  327. struct lpfc_register doorbell;
  328. int put_index = hq->host_index;
  329. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  330. return -EINVAL;
  331. if (hq->host_index != dq->host_index)
  332. return -EINVAL;
  333. /* If the host has not yet processed the next entry then we are done */
  334. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  335. return -EBUSY;
  336. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  337. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  338. /* Update the host index to point to the next slot */
  339. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  340. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  341. /* Ring The Header Receive Queue Doorbell */
  342. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  343. doorbell.word0 = 0;
  344. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  345. LPFC_RQ_POST_BATCH);
  346. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  347. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  348. }
  349. return put_index;
  350. }
  351. /**
  352. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  353. * @q: The Header Receive Queue to operate on.
  354. *
  355. * This routine will update the HBA index of a queue to reflect consumption of
  356. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  357. * consumed an entry the host calls this function to update the queue's
  358. * internal pointers. This routine returns the number of entries that were
  359. * consumed by the HBA.
  360. **/
  361. static uint32_t
  362. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  363. {
  364. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  365. return 0;
  366. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  367. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  368. return 1;
  369. }
  370. /**
  371. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  372. * @phba: Pointer to HBA context object.
  373. * @pring: Pointer to driver SLI ring object.
  374. *
  375. * This function returns pointer to next command iocb entry
  376. * in the command ring. The caller must hold hbalock to prevent
  377. * other threads consume the next command iocb.
  378. * SLI-2/SLI-3 provide different sized iocbs.
  379. **/
  380. static inline IOCB_t *
  381. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  382. {
  383. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  384. pring->cmdidx * phba->iocb_cmd_size);
  385. }
  386. /**
  387. * lpfc_resp_iocb - Get next response iocb entry in the ring
  388. * @phba: Pointer to HBA context object.
  389. * @pring: Pointer to driver SLI ring object.
  390. *
  391. * This function returns pointer to next response iocb entry
  392. * in the response ring. The caller must hold hbalock to make sure
  393. * that no other thread consume the next response iocb.
  394. * SLI-2/SLI-3 provide different sized iocbs.
  395. **/
  396. static inline IOCB_t *
  397. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  398. {
  399. return (IOCB_t *) (((char *) pring->rspringaddr) +
  400. pring->rspidx * phba->iocb_rsp_size);
  401. }
  402. /**
  403. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  404. * @phba: Pointer to HBA context object.
  405. *
  406. * This function is called with hbalock held. This function
  407. * allocates a new driver iocb object from the iocb pool. If the
  408. * allocation is successful, it returns pointer to the newly
  409. * allocated iocb object else it returns NULL.
  410. **/
  411. static struct lpfc_iocbq *
  412. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  413. {
  414. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  415. struct lpfc_iocbq * iocbq = NULL;
  416. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  417. return iocbq;
  418. }
  419. /**
  420. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  421. * @phba: Pointer to HBA context object.
  422. * @xritag: XRI value.
  423. *
  424. * This function clears the sglq pointer from the array of acive
  425. * sglq's. The xritag that is passed in is used to index into the
  426. * array. Before the xritag can be used it needs to be adjusted
  427. * by subtracting the xribase.
  428. *
  429. * Returns sglq ponter = success, NULL = Failure.
  430. **/
  431. static struct lpfc_sglq *
  432. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  433. {
  434. uint16_t adj_xri;
  435. struct lpfc_sglq *sglq;
  436. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  437. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  438. return NULL;
  439. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  440. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  441. return sglq;
  442. }
  443. /**
  444. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  445. * @phba: Pointer to HBA context object.
  446. * @xritag: XRI value.
  447. *
  448. * This function returns the sglq pointer from the array of acive
  449. * sglq's. The xritag that is passed in is used to index into the
  450. * array. Before the xritag can be used it needs to be adjusted
  451. * by subtracting the xribase.
  452. *
  453. * Returns sglq ponter = success, NULL = Failure.
  454. **/
  455. static struct lpfc_sglq *
  456. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  457. {
  458. uint16_t adj_xri;
  459. struct lpfc_sglq *sglq;
  460. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  461. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  462. return NULL;
  463. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  464. return sglq;
  465. }
  466. /**
  467. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  468. * @phba: Pointer to HBA context object.
  469. *
  470. * This function is called with hbalock held. This function
  471. * Gets a new driver sglq object from the sglq list. If the
  472. * list is not empty then it is successful, it returns pointer to the newly
  473. * allocated sglq object else it returns NULL.
  474. **/
  475. static struct lpfc_sglq *
  476. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  477. {
  478. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  479. struct lpfc_sglq *sglq = NULL;
  480. uint16_t adj_xri;
  481. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  482. if (!sglq)
  483. return NULL;
  484. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  485. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  486. return sglq;
  487. }
  488. /**
  489. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  490. * @phba: Pointer to HBA context object.
  491. *
  492. * This function is called with no lock held. This function
  493. * allocates a new driver iocb object from the iocb pool. If the
  494. * allocation is successful, it returns pointer to the newly
  495. * allocated iocb object else it returns NULL.
  496. **/
  497. struct lpfc_iocbq *
  498. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  499. {
  500. struct lpfc_iocbq * iocbq = NULL;
  501. unsigned long iflags;
  502. spin_lock_irqsave(&phba->hbalock, iflags);
  503. iocbq = __lpfc_sli_get_iocbq(phba);
  504. spin_unlock_irqrestore(&phba->hbalock, iflags);
  505. return iocbq;
  506. }
  507. /**
  508. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  509. * @phba: Pointer to HBA context object.
  510. * @iocbq: Pointer to driver iocb object.
  511. *
  512. * This function is called with hbalock held to release driver
  513. * iocb object to the iocb pool. The iotag in the iocb object
  514. * does not change for each use of the iocb object. This function
  515. * clears all other fields of the iocb object when it is freed.
  516. * The sqlq structure that holds the xritag and phys and virtual
  517. * mappings for the scatter gather list is retrieved from the
  518. * active array of sglq. The get of the sglq pointer also clears
  519. * the entry in the array. If the status of the IO indiactes that
  520. * this IO was aborted then the sglq entry it put on the
  521. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  522. * IO has good status or fails for any other reason then the sglq
  523. * entry is added to the free list (lpfc_sgl_list).
  524. **/
  525. static void
  526. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  527. {
  528. struct lpfc_sglq *sglq;
  529. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  530. unsigned long iflag;
  531. if (iocbq->sli4_xritag == NO_XRI)
  532. sglq = NULL;
  533. else
  534. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  535. if (sglq) {
  536. if (iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) {
  537. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  538. iflag);
  539. list_add(&sglq->list,
  540. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  541. spin_unlock_irqrestore(
  542. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  543. } else
  544. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  545. }
  546. /*
  547. * Clean all volatile data fields, preserve iotag and node struct.
  548. */
  549. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  550. iocbq->sli4_xritag = NO_XRI;
  551. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  552. }
  553. /**
  554. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  555. * @phba: Pointer to HBA context object.
  556. * @iocbq: Pointer to driver iocb object.
  557. *
  558. * This function is called with hbalock held to release driver
  559. * iocb object to the iocb pool. The iotag in the iocb object
  560. * does not change for each use of the iocb object. This function
  561. * clears all other fields of the iocb object when it is freed.
  562. **/
  563. static void
  564. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  565. {
  566. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  567. /*
  568. * Clean all volatile data fields, preserve iotag and node struct.
  569. */
  570. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  571. iocbq->sli4_xritag = NO_XRI;
  572. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  573. }
  574. /**
  575. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  576. * @phba: Pointer to HBA context object.
  577. * @iocbq: Pointer to driver iocb object.
  578. *
  579. * This function is called with hbalock held to release driver
  580. * iocb object to the iocb pool. The iotag in the iocb object
  581. * does not change for each use of the iocb object. This function
  582. * clears all other fields of the iocb object when it is freed.
  583. **/
  584. static void
  585. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  586. {
  587. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  588. }
  589. /**
  590. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  591. * @phba: Pointer to HBA context object.
  592. * @iocbq: Pointer to driver iocb object.
  593. *
  594. * This function is called with no lock held to release the iocb to
  595. * iocb pool.
  596. **/
  597. void
  598. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  599. {
  600. unsigned long iflags;
  601. /*
  602. * Clean all volatile data fields, preserve iotag and node struct.
  603. */
  604. spin_lock_irqsave(&phba->hbalock, iflags);
  605. __lpfc_sli_release_iocbq(phba, iocbq);
  606. spin_unlock_irqrestore(&phba->hbalock, iflags);
  607. }
  608. /**
  609. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  610. * @phba: Pointer to HBA context object.
  611. * @iocblist: List of IOCBs.
  612. * @ulpstatus: ULP status in IOCB command field.
  613. * @ulpWord4: ULP word-4 in IOCB command field.
  614. *
  615. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  616. * on the list by invoking the complete callback function associated with the
  617. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  618. * fields.
  619. **/
  620. void
  621. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  622. uint32_t ulpstatus, uint32_t ulpWord4)
  623. {
  624. struct lpfc_iocbq *piocb;
  625. while (!list_empty(iocblist)) {
  626. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  627. if (!piocb->iocb_cmpl)
  628. lpfc_sli_release_iocbq(phba, piocb);
  629. else {
  630. piocb->iocb.ulpStatus = ulpstatus;
  631. piocb->iocb.un.ulpWord[4] = ulpWord4;
  632. (piocb->iocb_cmpl) (phba, piocb, piocb);
  633. }
  634. }
  635. return;
  636. }
  637. /**
  638. * lpfc_sli_iocb_cmd_type - Get the iocb type
  639. * @iocb_cmnd: iocb command code.
  640. *
  641. * This function is called by ring event handler function to get the iocb type.
  642. * This function translates the iocb command to an iocb command type used to
  643. * decide the final disposition of each completed IOCB.
  644. * The function returns
  645. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  646. * LPFC_SOL_IOCB if it is a solicited iocb completion
  647. * LPFC_ABORT_IOCB if it is an abort iocb
  648. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  649. *
  650. * The caller is not required to hold any lock.
  651. **/
  652. static lpfc_iocb_type
  653. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  654. {
  655. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  656. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  657. return 0;
  658. switch (iocb_cmnd) {
  659. case CMD_XMIT_SEQUENCE_CR:
  660. case CMD_XMIT_SEQUENCE_CX:
  661. case CMD_XMIT_BCAST_CN:
  662. case CMD_XMIT_BCAST_CX:
  663. case CMD_ELS_REQUEST_CR:
  664. case CMD_ELS_REQUEST_CX:
  665. case CMD_CREATE_XRI_CR:
  666. case CMD_CREATE_XRI_CX:
  667. case CMD_GET_RPI_CN:
  668. case CMD_XMIT_ELS_RSP_CX:
  669. case CMD_GET_RPI_CR:
  670. case CMD_FCP_IWRITE_CR:
  671. case CMD_FCP_IWRITE_CX:
  672. case CMD_FCP_IREAD_CR:
  673. case CMD_FCP_IREAD_CX:
  674. case CMD_FCP_ICMND_CR:
  675. case CMD_FCP_ICMND_CX:
  676. case CMD_FCP_TSEND_CX:
  677. case CMD_FCP_TRSP_CX:
  678. case CMD_FCP_TRECEIVE_CX:
  679. case CMD_FCP_AUTO_TRSP_CX:
  680. case CMD_ADAPTER_MSG:
  681. case CMD_ADAPTER_DUMP:
  682. case CMD_XMIT_SEQUENCE64_CR:
  683. case CMD_XMIT_SEQUENCE64_CX:
  684. case CMD_XMIT_BCAST64_CN:
  685. case CMD_XMIT_BCAST64_CX:
  686. case CMD_ELS_REQUEST64_CR:
  687. case CMD_ELS_REQUEST64_CX:
  688. case CMD_FCP_IWRITE64_CR:
  689. case CMD_FCP_IWRITE64_CX:
  690. case CMD_FCP_IREAD64_CR:
  691. case CMD_FCP_IREAD64_CX:
  692. case CMD_FCP_ICMND64_CR:
  693. case CMD_FCP_ICMND64_CX:
  694. case CMD_FCP_TSEND64_CX:
  695. case CMD_FCP_TRSP64_CX:
  696. case CMD_FCP_TRECEIVE64_CX:
  697. case CMD_GEN_REQUEST64_CR:
  698. case CMD_GEN_REQUEST64_CX:
  699. case CMD_XMIT_ELS_RSP64_CX:
  700. case DSSCMD_IWRITE64_CR:
  701. case DSSCMD_IWRITE64_CX:
  702. case DSSCMD_IREAD64_CR:
  703. case DSSCMD_IREAD64_CX:
  704. type = LPFC_SOL_IOCB;
  705. break;
  706. case CMD_ABORT_XRI_CN:
  707. case CMD_ABORT_XRI_CX:
  708. case CMD_CLOSE_XRI_CN:
  709. case CMD_CLOSE_XRI_CX:
  710. case CMD_XRI_ABORTED_CX:
  711. case CMD_ABORT_MXRI64_CN:
  712. case CMD_XMIT_BLS_RSP64_CX:
  713. type = LPFC_ABORT_IOCB;
  714. break;
  715. case CMD_RCV_SEQUENCE_CX:
  716. case CMD_RCV_ELS_REQ_CX:
  717. case CMD_RCV_SEQUENCE64_CX:
  718. case CMD_RCV_ELS_REQ64_CX:
  719. case CMD_ASYNC_STATUS:
  720. case CMD_IOCB_RCV_SEQ64_CX:
  721. case CMD_IOCB_RCV_ELS64_CX:
  722. case CMD_IOCB_RCV_CONT64_CX:
  723. case CMD_IOCB_RET_XRI64_CX:
  724. type = LPFC_UNSOL_IOCB;
  725. break;
  726. case CMD_IOCB_XMIT_MSEQ64_CR:
  727. case CMD_IOCB_XMIT_MSEQ64_CX:
  728. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  729. case CMD_IOCB_RCV_ELS_LIST64_CX:
  730. case CMD_IOCB_CLOSE_EXTENDED_CN:
  731. case CMD_IOCB_ABORT_EXTENDED_CN:
  732. case CMD_IOCB_RET_HBQE64_CN:
  733. case CMD_IOCB_FCP_IBIDIR64_CR:
  734. case CMD_IOCB_FCP_IBIDIR64_CX:
  735. case CMD_IOCB_FCP_ITASKMGT64_CX:
  736. case CMD_IOCB_LOGENTRY_CN:
  737. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  738. printk("%s - Unhandled SLI-3 Command x%x\n",
  739. __func__, iocb_cmnd);
  740. type = LPFC_UNKNOWN_IOCB;
  741. break;
  742. default:
  743. type = LPFC_UNKNOWN_IOCB;
  744. break;
  745. }
  746. return type;
  747. }
  748. /**
  749. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  750. * @phba: Pointer to HBA context object.
  751. *
  752. * This function is called from SLI initialization code
  753. * to configure every ring of the HBA's SLI interface. The
  754. * caller is not required to hold any lock. This function issues
  755. * a config_ring mailbox command for each ring.
  756. * This function returns zero if successful else returns a negative
  757. * error code.
  758. **/
  759. static int
  760. lpfc_sli_ring_map(struct lpfc_hba *phba)
  761. {
  762. struct lpfc_sli *psli = &phba->sli;
  763. LPFC_MBOXQ_t *pmb;
  764. MAILBOX_t *pmbox;
  765. int i, rc, ret = 0;
  766. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  767. if (!pmb)
  768. return -ENOMEM;
  769. pmbox = &pmb->u.mb;
  770. phba->link_state = LPFC_INIT_MBX_CMDS;
  771. for (i = 0; i < psli->num_rings; i++) {
  772. lpfc_config_ring(phba, i, pmb);
  773. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  774. if (rc != MBX_SUCCESS) {
  775. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  776. "0446 Adapter failed to init (%d), "
  777. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  778. "ring %d\n",
  779. rc, pmbox->mbxCommand,
  780. pmbox->mbxStatus, i);
  781. phba->link_state = LPFC_HBA_ERROR;
  782. ret = -ENXIO;
  783. break;
  784. }
  785. }
  786. mempool_free(pmb, phba->mbox_mem_pool);
  787. return ret;
  788. }
  789. /**
  790. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  791. * @phba: Pointer to HBA context object.
  792. * @pring: Pointer to driver SLI ring object.
  793. * @piocb: Pointer to the driver iocb object.
  794. *
  795. * This function is called with hbalock held. The function adds the
  796. * new iocb to txcmplq of the given ring. This function always returns
  797. * 0. If this function is called for ELS ring, this function checks if
  798. * there is a vport associated with the ELS command. This function also
  799. * starts els_tmofunc timer if this is an ELS command.
  800. **/
  801. static int
  802. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  803. struct lpfc_iocbq *piocb)
  804. {
  805. list_add_tail(&piocb->list, &pring->txcmplq);
  806. pring->txcmplq_cnt++;
  807. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  808. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  809. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  810. if (!piocb->vport)
  811. BUG();
  812. else
  813. mod_timer(&piocb->vport->els_tmofunc,
  814. jiffies + HZ * (phba->fc_ratov << 1));
  815. }
  816. return 0;
  817. }
  818. /**
  819. * lpfc_sli_ringtx_get - Get first element of the txq
  820. * @phba: Pointer to HBA context object.
  821. * @pring: Pointer to driver SLI ring object.
  822. *
  823. * This function is called with hbalock held to get next
  824. * iocb in txq of the given ring. If there is any iocb in
  825. * the txq, the function returns first iocb in the list after
  826. * removing the iocb from the list, else it returns NULL.
  827. **/
  828. static struct lpfc_iocbq *
  829. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  830. {
  831. struct lpfc_iocbq *cmd_iocb;
  832. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  833. if (cmd_iocb != NULL)
  834. pring->txq_cnt--;
  835. return cmd_iocb;
  836. }
  837. /**
  838. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  839. * @phba: Pointer to HBA context object.
  840. * @pring: Pointer to driver SLI ring object.
  841. *
  842. * This function is called with hbalock held and the caller must post the
  843. * iocb without releasing the lock. If the caller releases the lock,
  844. * iocb slot returned by the function is not guaranteed to be available.
  845. * The function returns pointer to the next available iocb slot if there
  846. * is available slot in the ring, else it returns NULL.
  847. * If the get index of the ring is ahead of the put index, the function
  848. * will post an error attention event to the worker thread to take the
  849. * HBA to offline state.
  850. **/
  851. static IOCB_t *
  852. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  853. {
  854. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  855. uint32_t max_cmd_idx = pring->numCiocb;
  856. if ((pring->next_cmdidx == pring->cmdidx) &&
  857. (++pring->next_cmdidx >= max_cmd_idx))
  858. pring->next_cmdidx = 0;
  859. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  860. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  861. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  862. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  863. "0315 Ring %d issue: portCmdGet %d "
  864. "is bigger than cmd ring %d\n",
  865. pring->ringno,
  866. pring->local_getidx, max_cmd_idx);
  867. phba->link_state = LPFC_HBA_ERROR;
  868. /*
  869. * All error attention handlers are posted to
  870. * worker thread
  871. */
  872. phba->work_ha |= HA_ERATT;
  873. phba->work_hs = HS_FFER3;
  874. lpfc_worker_wake_up(phba);
  875. return NULL;
  876. }
  877. if (pring->local_getidx == pring->next_cmdidx)
  878. return NULL;
  879. }
  880. return lpfc_cmd_iocb(phba, pring);
  881. }
  882. /**
  883. * lpfc_sli_next_iotag - Get an iotag for the iocb
  884. * @phba: Pointer to HBA context object.
  885. * @iocbq: Pointer to driver iocb object.
  886. *
  887. * This function gets an iotag for the iocb. If there is no unused iotag and
  888. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  889. * array and assigns a new iotag.
  890. * The function returns the allocated iotag if successful, else returns zero.
  891. * Zero is not a valid iotag.
  892. * The caller is not required to hold any lock.
  893. **/
  894. uint16_t
  895. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  896. {
  897. struct lpfc_iocbq **new_arr;
  898. struct lpfc_iocbq **old_arr;
  899. size_t new_len;
  900. struct lpfc_sli *psli = &phba->sli;
  901. uint16_t iotag;
  902. spin_lock_irq(&phba->hbalock);
  903. iotag = psli->last_iotag;
  904. if(++iotag < psli->iocbq_lookup_len) {
  905. psli->last_iotag = iotag;
  906. psli->iocbq_lookup[iotag] = iocbq;
  907. spin_unlock_irq(&phba->hbalock);
  908. iocbq->iotag = iotag;
  909. return iotag;
  910. } else if (psli->iocbq_lookup_len < (0xffff
  911. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  912. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  913. spin_unlock_irq(&phba->hbalock);
  914. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  915. GFP_KERNEL);
  916. if (new_arr) {
  917. spin_lock_irq(&phba->hbalock);
  918. old_arr = psli->iocbq_lookup;
  919. if (new_len <= psli->iocbq_lookup_len) {
  920. /* highly unprobable case */
  921. kfree(new_arr);
  922. iotag = psli->last_iotag;
  923. if(++iotag < psli->iocbq_lookup_len) {
  924. psli->last_iotag = iotag;
  925. psli->iocbq_lookup[iotag] = iocbq;
  926. spin_unlock_irq(&phba->hbalock);
  927. iocbq->iotag = iotag;
  928. return iotag;
  929. }
  930. spin_unlock_irq(&phba->hbalock);
  931. return 0;
  932. }
  933. if (psli->iocbq_lookup)
  934. memcpy(new_arr, old_arr,
  935. ((psli->last_iotag + 1) *
  936. sizeof (struct lpfc_iocbq *)));
  937. psli->iocbq_lookup = new_arr;
  938. psli->iocbq_lookup_len = new_len;
  939. psli->last_iotag = iotag;
  940. psli->iocbq_lookup[iotag] = iocbq;
  941. spin_unlock_irq(&phba->hbalock);
  942. iocbq->iotag = iotag;
  943. kfree(old_arr);
  944. return iotag;
  945. }
  946. } else
  947. spin_unlock_irq(&phba->hbalock);
  948. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  949. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  950. psli->last_iotag);
  951. return 0;
  952. }
  953. /**
  954. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  955. * @phba: Pointer to HBA context object.
  956. * @pring: Pointer to driver SLI ring object.
  957. * @iocb: Pointer to iocb slot in the ring.
  958. * @nextiocb: Pointer to driver iocb object which need to be
  959. * posted to firmware.
  960. *
  961. * This function is called with hbalock held to post a new iocb to
  962. * the firmware. This function copies the new iocb to ring iocb slot and
  963. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  964. * a completion call back for this iocb else the function will free the
  965. * iocb object.
  966. **/
  967. static void
  968. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  969. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  970. {
  971. /*
  972. * Set up an iotag
  973. */
  974. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  975. if (pring->ringno == LPFC_ELS_RING) {
  976. lpfc_debugfs_slow_ring_trc(phba,
  977. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  978. *(((uint32_t *) &nextiocb->iocb) + 4),
  979. *(((uint32_t *) &nextiocb->iocb) + 6),
  980. *(((uint32_t *) &nextiocb->iocb) + 7));
  981. }
  982. /*
  983. * Issue iocb command to adapter
  984. */
  985. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  986. wmb();
  987. pring->stats.iocb_cmd++;
  988. /*
  989. * If there is no completion routine to call, we can release the
  990. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  991. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  992. */
  993. if (nextiocb->iocb_cmpl)
  994. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  995. else
  996. __lpfc_sli_release_iocbq(phba, nextiocb);
  997. /*
  998. * Let the HBA know what IOCB slot will be the next one the
  999. * driver will put a command into.
  1000. */
  1001. pring->cmdidx = pring->next_cmdidx;
  1002. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1003. }
  1004. /**
  1005. * lpfc_sli_update_full_ring - Update the chip attention register
  1006. * @phba: Pointer to HBA context object.
  1007. * @pring: Pointer to driver SLI ring object.
  1008. *
  1009. * The caller is not required to hold any lock for calling this function.
  1010. * This function updates the chip attention bits for the ring to inform firmware
  1011. * that there are pending work to be done for this ring and requests an
  1012. * interrupt when there is space available in the ring. This function is
  1013. * called when the driver is unable to post more iocbs to the ring due
  1014. * to unavailability of space in the ring.
  1015. **/
  1016. static void
  1017. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1018. {
  1019. int ringno = pring->ringno;
  1020. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1021. wmb();
  1022. /*
  1023. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1024. * The HBA will tell us when an IOCB entry is available.
  1025. */
  1026. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1027. readl(phba->CAregaddr); /* flush */
  1028. pring->stats.iocb_cmd_full++;
  1029. }
  1030. /**
  1031. * lpfc_sli_update_ring - Update chip attention register
  1032. * @phba: Pointer to HBA context object.
  1033. * @pring: Pointer to driver SLI ring object.
  1034. *
  1035. * This function updates the chip attention register bit for the
  1036. * given ring to inform HBA that there is more work to be done
  1037. * in this ring. The caller is not required to hold any lock.
  1038. **/
  1039. static void
  1040. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1041. {
  1042. int ringno = pring->ringno;
  1043. /*
  1044. * Tell the HBA that there is work to do in this ring.
  1045. */
  1046. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1047. wmb();
  1048. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1049. readl(phba->CAregaddr); /* flush */
  1050. }
  1051. }
  1052. /**
  1053. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1054. * @phba: Pointer to HBA context object.
  1055. * @pring: Pointer to driver SLI ring object.
  1056. *
  1057. * This function is called with hbalock held to post pending iocbs
  1058. * in the txq to the firmware. This function is called when driver
  1059. * detects space available in the ring.
  1060. **/
  1061. static void
  1062. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1063. {
  1064. IOCB_t *iocb;
  1065. struct lpfc_iocbq *nextiocb;
  1066. /*
  1067. * Check to see if:
  1068. * (a) there is anything on the txq to send
  1069. * (b) link is up
  1070. * (c) link attention events can be processed (fcp ring only)
  1071. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1072. */
  1073. if (pring->txq_cnt &&
  1074. lpfc_is_link_up(phba) &&
  1075. (pring->ringno != phba->sli.fcp_ring ||
  1076. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1077. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1078. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1079. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1080. if (iocb)
  1081. lpfc_sli_update_ring(phba, pring);
  1082. else
  1083. lpfc_sli_update_full_ring(phba, pring);
  1084. }
  1085. return;
  1086. }
  1087. /**
  1088. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1089. * @phba: Pointer to HBA context object.
  1090. * @hbqno: HBQ number.
  1091. *
  1092. * This function is called with hbalock held to get the next
  1093. * available slot for the given HBQ. If there is free slot
  1094. * available for the HBQ it will return pointer to the next available
  1095. * HBQ entry else it will return NULL.
  1096. **/
  1097. static struct lpfc_hbq_entry *
  1098. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1099. {
  1100. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1101. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1102. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1103. hbqp->next_hbqPutIdx = 0;
  1104. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1105. uint32_t raw_index = phba->hbq_get[hbqno];
  1106. uint32_t getidx = le32_to_cpu(raw_index);
  1107. hbqp->local_hbqGetIdx = getidx;
  1108. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1109. lpfc_printf_log(phba, KERN_ERR,
  1110. LOG_SLI | LOG_VPORT,
  1111. "1802 HBQ %d: local_hbqGetIdx "
  1112. "%u is > than hbqp->entry_count %u\n",
  1113. hbqno, hbqp->local_hbqGetIdx,
  1114. hbqp->entry_count);
  1115. phba->link_state = LPFC_HBA_ERROR;
  1116. return NULL;
  1117. }
  1118. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1119. return NULL;
  1120. }
  1121. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1122. hbqp->hbqPutIdx;
  1123. }
  1124. /**
  1125. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1126. * @phba: Pointer to HBA context object.
  1127. *
  1128. * This function is called with no lock held to free all the
  1129. * hbq buffers while uninitializing the SLI interface. It also
  1130. * frees the HBQ buffers returned by the firmware but not yet
  1131. * processed by the upper layers.
  1132. **/
  1133. void
  1134. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1135. {
  1136. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1137. struct hbq_dmabuf *hbq_buf;
  1138. unsigned long flags;
  1139. int i, hbq_count;
  1140. uint32_t hbqno;
  1141. hbq_count = lpfc_sli_hbq_count();
  1142. /* Return all memory used by all HBQs */
  1143. spin_lock_irqsave(&phba->hbalock, flags);
  1144. for (i = 0; i < hbq_count; ++i) {
  1145. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1146. &phba->hbqs[i].hbq_buffer_list, list) {
  1147. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1148. list_del(&hbq_buf->dbuf.list);
  1149. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1150. }
  1151. phba->hbqs[i].buffer_count = 0;
  1152. }
  1153. /* Return all HBQ buffer that are in-fly */
  1154. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1155. list) {
  1156. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1157. list_del(&hbq_buf->dbuf.list);
  1158. if (hbq_buf->tag == -1) {
  1159. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1160. (phba, hbq_buf);
  1161. } else {
  1162. hbqno = hbq_buf->tag >> 16;
  1163. if (hbqno >= LPFC_MAX_HBQS)
  1164. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1165. (phba, hbq_buf);
  1166. else
  1167. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1168. hbq_buf);
  1169. }
  1170. }
  1171. /* Mark the HBQs not in use */
  1172. phba->hbq_in_use = 0;
  1173. spin_unlock_irqrestore(&phba->hbalock, flags);
  1174. }
  1175. /**
  1176. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1177. * @phba: Pointer to HBA context object.
  1178. * @hbqno: HBQ number.
  1179. * @hbq_buf: Pointer to HBQ buffer.
  1180. *
  1181. * This function is called with the hbalock held to post a
  1182. * hbq buffer to the firmware. If the function finds an empty
  1183. * slot in the HBQ, it will post the buffer. The function will return
  1184. * pointer to the hbq entry if it successfully post the buffer
  1185. * else it will return NULL.
  1186. **/
  1187. static int
  1188. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1189. struct hbq_dmabuf *hbq_buf)
  1190. {
  1191. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1192. }
  1193. /**
  1194. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1195. * @phba: Pointer to HBA context object.
  1196. * @hbqno: HBQ number.
  1197. * @hbq_buf: Pointer to HBQ buffer.
  1198. *
  1199. * This function is called with the hbalock held to post a hbq buffer to the
  1200. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1201. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1202. * it successfully post the buffer else it will return an error.
  1203. **/
  1204. static int
  1205. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1206. struct hbq_dmabuf *hbq_buf)
  1207. {
  1208. struct lpfc_hbq_entry *hbqe;
  1209. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1210. /* Get next HBQ entry slot to use */
  1211. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1212. if (hbqe) {
  1213. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1214. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1215. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1216. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1217. hbqe->bde.tus.f.bdeFlags = 0;
  1218. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1219. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1220. /* Sync SLIM */
  1221. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1222. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1223. /* flush */
  1224. readl(phba->hbq_put + hbqno);
  1225. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1226. return 0;
  1227. } else
  1228. return -ENOMEM;
  1229. }
  1230. /**
  1231. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1232. * @phba: Pointer to HBA context object.
  1233. * @hbqno: HBQ number.
  1234. * @hbq_buf: Pointer to HBQ buffer.
  1235. *
  1236. * This function is called with the hbalock held to post an RQE to the SLI4
  1237. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1238. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1239. **/
  1240. static int
  1241. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1242. struct hbq_dmabuf *hbq_buf)
  1243. {
  1244. int rc;
  1245. struct lpfc_rqe hrqe;
  1246. struct lpfc_rqe drqe;
  1247. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1248. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1249. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1250. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1251. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1252. &hrqe, &drqe);
  1253. if (rc < 0)
  1254. return rc;
  1255. hbq_buf->tag = rc;
  1256. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1257. return 0;
  1258. }
  1259. /* HBQ for ELS and CT traffic. */
  1260. static struct lpfc_hbq_init lpfc_els_hbq = {
  1261. .rn = 1,
  1262. .entry_count = 256,
  1263. .mask_count = 0,
  1264. .profile = 0,
  1265. .ring_mask = (1 << LPFC_ELS_RING),
  1266. .buffer_count = 0,
  1267. .init_count = 40,
  1268. .add_count = 40,
  1269. };
  1270. /* HBQ for the extra ring if needed */
  1271. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1272. .rn = 1,
  1273. .entry_count = 200,
  1274. .mask_count = 0,
  1275. .profile = 0,
  1276. .ring_mask = (1 << LPFC_EXTRA_RING),
  1277. .buffer_count = 0,
  1278. .init_count = 0,
  1279. .add_count = 5,
  1280. };
  1281. /* Array of HBQs */
  1282. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1283. &lpfc_els_hbq,
  1284. &lpfc_extra_hbq,
  1285. };
  1286. /**
  1287. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1288. * @phba: Pointer to HBA context object.
  1289. * @hbqno: HBQ number.
  1290. * @count: Number of HBQ buffers to be posted.
  1291. *
  1292. * This function is called with no lock held to post more hbq buffers to the
  1293. * given HBQ. The function returns the number of HBQ buffers successfully
  1294. * posted.
  1295. **/
  1296. static int
  1297. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1298. {
  1299. uint32_t i, posted = 0;
  1300. unsigned long flags;
  1301. struct hbq_dmabuf *hbq_buffer;
  1302. LIST_HEAD(hbq_buf_list);
  1303. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1304. return 0;
  1305. if ((phba->hbqs[hbqno].buffer_count + count) >
  1306. lpfc_hbq_defs[hbqno]->entry_count)
  1307. count = lpfc_hbq_defs[hbqno]->entry_count -
  1308. phba->hbqs[hbqno].buffer_count;
  1309. if (!count)
  1310. return 0;
  1311. /* Allocate HBQ entries */
  1312. for (i = 0; i < count; i++) {
  1313. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1314. if (!hbq_buffer)
  1315. break;
  1316. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1317. }
  1318. /* Check whether HBQ is still in use */
  1319. spin_lock_irqsave(&phba->hbalock, flags);
  1320. if (!phba->hbq_in_use)
  1321. goto err;
  1322. while (!list_empty(&hbq_buf_list)) {
  1323. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1324. dbuf.list);
  1325. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1326. (hbqno << 16));
  1327. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1328. phba->hbqs[hbqno].buffer_count++;
  1329. posted++;
  1330. } else
  1331. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1332. }
  1333. spin_unlock_irqrestore(&phba->hbalock, flags);
  1334. return posted;
  1335. err:
  1336. spin_unlock_irqrestore(&phba->hbalock, flags);
  1337. while (!list_empty(&hbq_buf_list)) {
  1338. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1339. dbuf.list);
  1340. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1341. }
  1342. return 0;
  1343. }
  1344. /**
  1345. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1346. * @phba: Pointer to HBA context object.
  1347. * @qno: HBQ number.
  1348. *
  1349. * This function posts more buffers to the HBQ. This function
  1350. * is called with no lock held. The function returns the number of HBQ entries
  1351. * successfully allocated.
  1352. **/
  1353. int
  1354. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1355. {
  1356. if (phba->sli_rev == LPFC_SLI_REV4)
  1357. return 0;
  1358. else
  1359. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1360. lpfc_hbq_defs[qno]->add_count);
  1361. }
  1362. /**
  1363. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1364. * @phba: Pointer to HBA context object.
  1365. * @qno: HBQ queue number.
  1366. *
  1367. * This function is called from SLI initialization code path with
  1368. * no lock held to post initial HBQ buffers to firmware. The
  1369. * function returns the number of HBQ entries successfully allocated.
  1370. **/
  1371. static int
  1372. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1373. {
  1374. if (phba->sli_rev == LPFC_SLI_REV4)
  1375. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1376. lpfc_hbq_defs[qno]->entry_count);
  1377. else
  1378. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1379. lpfc_hbq_defs[qno]->init_count);
  1380. }
  1381. /**
  1382. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1383. * @phba: Pointer to HBA context object.
  1384. * @hbqno: HBQ number.
  1385. *
  1386. * This function removes the first hbq buffer on an hbq list and returns a
  1387. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1388. **/
  1389. static struct hbq_dmabuf *
  1390. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1391. {
  1392. struct lpfc_dmabuf *d_buf;
  1393. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1394. if (!d_buf)
  1395. return NULL;
  1396. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1397. }
  1398. /**
  1399. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1400. * @phba: Pointer to HBA context object.
  1401. * @tag: Tag of the hbq buffer.
  1402. *
  1403. * This function is called with hbalock held. This function searches
  1404. * for the hbq buffer associated with the given tag in the hbq buffer
  1405. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1406. * it returns NULL.
  1407. **/
  1408. static struct hbq_dmabuf *
  1409. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1410. {
  1411. struct lpfc_dmabuf *d_buf;
  1412. struct hbq_dmabuf *hbq_buf;
  1413. uint32_t hbqno;
  1414. hbqno = tag >> 16;
  1415. if (hbqno >= LPFC_MAX_HBQS)
  1416. return NULL;
  1417. spin_lock_irq(&phba->hbalock);
  1418. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1419. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1420. if (hbq_buf->tag == tag) {
  1421. spin_unlock_irq(&phba->hbalock);
  1422. return hbq_buf;
  1423. }
  1424. }
  1425. spin_unlock_irq(&phba->hbalock);
  1426. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1427. "1803 Bad hbq tag. Data: x%x x%x\n",
  1428. tag, phba->hbqs[tag >> 16].buffer_count);
  1429. return NULL;
  1430. }
  1431. /**
  1432. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1433. * @phba: Pointer to HBA context object.
  1434. * @hbq_buffer: Pointer to HBQ buffer.
  1435. *
  1436. * This function is called with hbalock. This function gives back
  1437. * the hbq buffer to firmware. If the HBQ does not have space to
  1438. * post the buffer, it will free the buffer.
  1439. **/
  1440. void
  1441. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1442. {
  1443. uint32_t hbqno;
  1444. if (hbq_buffer) {
  1445. hbqno = hbq_buffer->tag >> 16;
  1446. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1447. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1448. }
  1449. }
  1450. /**
  1451. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1452. * @mbxCommand: mailbox command code.
  1453. *
  1454. * This function is called by the mailbox event handler function to verify
  1455. * that the completed mailbox command is a legitimate mailbox command. If the
  1456. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1457. * and the mailbox event handler will take the HBA offline.
  1458. **/
  1459. static int
  1460. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1461. {
  1462. uint8_t ret;
  1463. switch (mbxCommand) {
  1464. case MBX_LOAD_SM:
  1465. case MBX_READ_NV:
  1466. case MBX_WRITE_NV:
  1467. case MBX_WRITE_VPARMS:
  1468. case MBX_RUN_BIU_DIAG:
  1469. case MBX_INIT_LINK:
  1470. case MBX_DOWN_LINK:
  1471. case MBX_CONFIG_LINK:
  1472. case MBX_CONFIG_RING:
  1473. case MBX_RESET_RING:
  1474. case MBX_READ_CONFIG:
  1475. case MBX_READ_RCONFIG:
  1476. case MBX_READ_SPARM:
  1477. case MBX_READ_STATUS:
  1478. case MBX_READ_RPI:
  1479. case MBX_READ_XRI:
  1480. case MBX_READ_REV:
  1481. case MBX_READ_LNK_STAT:
  1482. case MBX_REG_LOGIN:
  1483. case MBX_UNREG_LOGIN:
  1484. case MBX_READ_LA:
  1485. case MBX_CLEAR_LA:
  1486. case MBX_DUMP_MEMORY:
  1487. case MBX_DUMP_CONTEXT:
  1488. case MBX_RUN_DIAGS:
  1489. case MBX_RESTART:
  1490. case MBX_UPDATE_CFG:
  1491. case MBX_DOWN_LOAD:
  1492. case MBX_DEL_LD_ENTRY:
  1493. case MBX_RUN_PROGRAM:
  1494. case MBX_SET_MASK:
  1495. case MBX_SET_VARIABLE:
  1496. case MBX_UNREG_D_ID:
  1497. case MBX_KILL_BOARD:
  1498. case MBX_CONFIG_FARP:
  1499. case MBX_BEACON:
  1500. case MBX_LOAD_AREA:
  1501. case MBX_RUN_BIU_DIAG64:
  1502. case MBX_CONFIG_PORT:
  1503. case MBX_READ_SPARM64:
  1504. case MBX_READ_RPI64:
  1505. case MBX_REG_LOGIN64:
  1506. case MBX_READ_LA64:
  1507. case MBX_WRITE_WWN:
  1508. case MBX_SET_DEBUG:
  1509. case MBX_LOAD_EXP_ROM:
  1510. case MBX_ASYNCEVT_ENABLE:
  1511. case MBX_REG_VPI:
  1512. case MBX_UNREG_VPI:
  1513. case MBX_HEARTBEAT:
  1514. case MBX_PORT_CAPABILITIES:
  1515. case MBX_PORT_IOV_CONTROL:
  1516. case MBX_SLI4_CONFIG:
  1517. case MBX_SLI4_REQ_FTRS:
  1518. case MBX_REG_FCFI:
  1519. case MBX_UNREG_FCFI:
  1520. case MBX_REG_VFI:
  1521. case MBX_UNREG_VFI:
  1522. case MBX_INIT_VPI:
  1523. case MBX_INIT_VFI:
  1524. case MBX_RESUME_RPI:
  1525. ret = mbxCommand;
  1526. break;
  1527. default:
  1528. ret = MBX_SHUTDOWN;
  1529. break;
  1530. }
  1531. return ret;
  1532. }
  1533. /**
  1534. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1535. * @phba: Pointer to HBA context object.
  1536. * @pmboxq: Pointer to mailbox command.
  1537. *
  1538. * This is completion handler function for mailbox commands issued from
  1539. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1540. * mailbox event handler function with no lock held. This function
  1541. * will wake up thread waiting on the wait queue pointed by context1
  1542. * of the mailbox.
  1543. **/
  1544. void
  1545. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1546. {
  1547. wait_queue_head_t *pdone_q;
  1548. unsigned long drvr_flag;
  1549. /*
  1550. * If pdone_q is empty, the driver thread gave up waiting and
  1551. * continued running.
  1552. */
  1553. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1554. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1555. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1556. if (pdone_q)
  1557. wake_up_interruptible(pdone_q);
  1558. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1559. return;
  1560. }
  1561. /**
  1562. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1563. * @phba: Pointer to HBA context object.
  1564. * @pmb: Pointer to mailbox object.
  1565. *
  1566. * This function is the default mailbox completion handler. It
  1567. * frees the memory resources associated with the completed mailbox
  1568. * command. If the completed command is a REG_LOGIN mailbox command,
  1569. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1570. **/
  1571. void
  1572. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1573. {
  1574. struct lpfc_dmabuf *mp;
  1575. uint16_t rpi, vpi;
  1576. int rc;
  1577. struct lpfc_vport *vport = pmb->vport;
  1578. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1579. if (mp) {
  1580. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1581. kfree(mp);
  1582. }
  1583. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1584. (phba->sli_rev == LPFC_SLI_REV4))
  1585. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1586. /*
  1587. * If a REG_LOGIN succeeded after node is destroyed or node
  1588. * is in re-discovery driver need to cleanup the RPI.
  1589. */
  1590. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1591. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1592. !pmb->u.mb.mbxStatus) {
  1593. rpi = pmb->u.mb.un.varWords[0];
  1594. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1595. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1596. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1597. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1598. if (rc != MBX_NOT_FINISHED)
  1599. return;
  1600. }
  1601. /* Unreg VPI, if the REG_VPI succeed after VLink failure */
  1602. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1603. !(phba->pport->load_flag & FC_UNLOADING) &&
  1604. !pmb->u.mb.mbxStatus) {
  1605. lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb);
  1606. pmb->vport = vport;
  1607. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1608. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1609. if (rc != MBX_NOT_FINISHED)
  1610. return;
  1611. }
  1612. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1613. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1614. else
  1615. mempool_free(pmb, phba->mbox_mem_pool);
  1616. }
  1617. /**
  1618. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1619. * @phba: Pointer to HBA context object.
  1620. *
  1621. * This function is called with no lock held. This function processes all
  1622. * the completed mailbox commands and gives it to upper layers. The interrupt
  1623. * service routine processes mailbox completion interrupt and adds completed
  1624. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1625. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1626. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1627. * function returns the mailbox commands to the upper layer by calling the
  1628. * completion handler function of each mailbox.
  1629. **/
  1630. int
  1631. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1632. {
  1633. MAILBOX_t *pmbox;
  1634. LPFC_MBOXQ_t *pmb;
  1635. int rc;
  1636. LIST_HEAD(cmplq);
  1637. phba->sli.slistat.mbox_event++;
  1638. /* Get all completed mailboxe buffers into the cmplq */
  1639. spin_lock_irq(&phba->hbalock);
  1640. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1641. spin_unlock_irq(&phba->hbalock);
  1642. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1643. do {
  1644. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1645. if (pmb == NULL)
  1646. break;
  1647. pmbox = &pmb->u.mb;
  1648. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1649. if (pmb->vport) {
  1650. lpfc_debugfs_disc_trc(pmb->vport,
  1651. LPFC_DISC_TRC_MBOX_VPORT,
  1652. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1653. (uint32_t)pmbox->mbxCommand,
  1654. pmbox->un.varWords[0],
  1655. pmbox->un.varWords[1]);
  1656. }
  1657. else {
  1658. lpfc_debugfs_disc_trc(phba->pport,
  1659. LPFC_DISC_TRC_MBOX,
  1660. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1661. (uint32_t)pmbox->mbxCommand,
  1662. pmbox->un.varWords[0],
  1663. pmbox->un.varWords[1]);
  1664. }
  1665. }
  1666. /*
  1667. * It is a fatal error if unknown mbox command completion.
  1668. */
  1669. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1670. MBX_SHUTDOWN) {
  1671. /* Unknown mailbox command compl */
  1672. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1673. "(%d):0323 Unknown Mailbox command "
  1674. "x%x (x%x) Cmpl\n",
  1675. pmb->vport ? pmb->vport->vpi : 0,
  1676. pmbox->mbxCommand,
  1677. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1678. phba->link_state = LPFC_HBA_ERROR;
  1679. phba->work_hs = HS_FFER3;
  1680. lpfc_handle_eratt(phba);
  1681. continue;
  1682. }
  1683. if (pmbox->mbxStatus) {
  1684. phba->sli.slistat.mbox_stat_err++;
  1685. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1686. /* Mbox cmd cmpl error - RETRYing */
  1687. lpfc_printf_log(phba, KERN_INFO,
  1688. LOG_MBOX | LOG_SLI,
  1689. "(%d):0305 Mbox cmd cmpl "
  1690. "error - RETRYing Data: x%x "
  1691. "(x%x) x%x x%x x%x\n",
  1692. pmb->vport ? pmb->vport->vpi :0,
  1693. pmbox->mbxCommand,
  1694. lpfc_sli4_mbox_opcode_get(phba,
  1695. pmb),
  1696. pmbox->mbxStatus,
  1697. pmbox->un.varWords[0],
  1698. pmb->vport->port_state);
  1699. pmbox->mbxStatus = 0;
  1700. pmbox->mbxOwner = OWN_HOST;
  1701. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1702. if (rc != MBX_NOT_FINISHED)
  1703. continue;
  1704. }
  1705. }
  1706. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1707. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1708. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1709. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1710. pmb->vport ? pmb->vport->vpi : 0,
  1711. pmbox->mbxCommand,
  1712. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1713. pmb->mbox_cmpl,
  1714. *((uint32_t *) pmbox),
  1715. pmbox->un.varWords[0],
  1716. pmbox->un.varWords[1],
  1717. pmbox->un.varWords[2],
  1718. pmbox->un.varWords[3],
  1719. pmbox->un.varWords[4],
  1720. pmbox->un.varWords[5],
  1721. pmbox->un.varWords[6],
  1722. pmbox->un.varWords[7]);
  1723. if (pmb->mbox_cmpl)
  1724. pmb->mbox_cmpl(phba,pmb);
  1725. } while (1);
  1726. return 0;
  1727. }
  1728. /**
  1729. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1730. * @phba: Pointer to HBA context object.
  1731. * @pring: Pointer to driver SLI ring object.
  1732. * @tag: buffer tag.
  1733. *
  1734. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1735. * is set in the tag the buffer is posted for a particular exchange,
  1736. * the function will return the buffer without replacing the buffer.
  1737. * If the buffer is for unsolicited ELS or CT traffic, this function
  1738. * returns the buffer and also posts another buffer to the firmware.
  1739. **/
  1740. static struct lpfc_dmabuf *
  1741. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1742. struct lpfc_sli_ring *pring,
  1743. uint32_t tag)
  1744. {
  1745. struct hbq_dmabuf *hbq_entry;
  1746. if (tag & QUE_BUFTAG_BIT)
  1747. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1748. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1749. if (!hbq_entry)
  1750. return NULL;
  1751. return &hbq_entry->dbuf;
  1752. }
  1753. /**
  1754. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1755. * @phba: Pointer to HBA context object.
  1756. * @pring: Pointer to driver SLI ring object.
  1757. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1758. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1759. * @fch_type: the type for the first frame of the sequence.
  1760. *
  1761. * This function is called with no lock held. This function uses the r_ctl and
  1762. * type of the received sequence to find the correct callback function to call
  1763. * to process the sequence.
  1764. **/
  1765. static int
  1766. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1767. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1768. uint32_t fch_type)
  1769. {
  1770. int i;
  1771. /* unSolicited Responses */
  1772. if (pring->prt[0].profile) {
  1773. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1774. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1775. saveq);
  1776. return 1;
  1777. }
  1778. /* We must search, based on rctl / type
  1779. for the right routine */
  1780. for (i = 0; i < pring->num_mask; i++) {
  1781. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1782. (pring->prt[i].type == fch_type)) {
  1783. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1784. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1785. (phba, pring, saveq);
  1786. return 1;
  1787. }
  1788. }
  1789. return 0;
  1790. }
  1791. /**
  1792. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1793. * @phba: Pointer to HBA context object.
  1794. * @pring: Pointer to driver SLI ring object.
  1795. * @saveq: Pointer to the unsolicited iocb.
  1796. *
  1797. * This function is called with no lock held by the ring event handler
  1798. * when there is an unsolicited iocb posted to the response ring by the
  1799. * firmware. This function gets the buffer associated with the iocbs
  1800. * and calls the event handler for the ring. This function handles both
  1801. * qring buffers and hbq buffers.
  1802. * When the function returns 1 the caller can free the iocb object otherwise
  1803. * upper layer functions will free the iocb objects.
  1804. **/
  1805. static int
  1806. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1807. struct lpfc_iocbq *saveq)
  1808. {
  1809. IOCB_t * irsp;
  1810. WORD5 * w5p;
  1811. uint32_t Rctl, Type;
  1812. uint32_t match;
  1813. struct lpfc_iocbq *iocbq;
  1814. struct lpfc_dmabuf *dmzbuf;
  1815. match = 0;
  1816. irsp = &(saveq->iocb);
  1817. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1818. if (pring->lpfc_sli_rcv_async_status)
  1819. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1820. else
  1821. lpfc_printf_log(phba,
  1822. KERN_WARNING,
  1823. LOG_SLI,
  1824. "0316 Ring %d handler: unexpected "
  1825. "ASYNC_STATUS iocb received evt_code "
  1826. "0x%x\n",
  1827. pring->ringno,
  1828. irsp->un.asyncstat.evt_code);
  1829. return 1;
  1830. }
  1831. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1832. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1833. if (irsp->ulpBdeCount > 0) {
  1834. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1835. irsp->un.ulpWord[3]);
  1836. lpfc_in_buf_free(phba, dmzbuf);
  1837. }
  1838. if (irsp->ulpBdeCount > 1) {
  1839. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1840. irsp->unsli3.sli3Words[3]);
  1841. lpfc_in_buf_free(phba, dmzbuf);
  1842. }
  1843. if (irsp->ulpBdeCount > 2) {
  1844. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1845. irsp->unsli3.sli3Words[7]);
  1846. lpfc_in_buf_free(phba, dmzbuf);
  1847. }
  1848. return 1;
  1849. }
  1850. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1851. if (irsp->ulpBdeCount != 0) {
  1852. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1853. irsp->un.ulpWord[3]);
  1854. if (!saveq->context2)
  1855. lpfc_printf_log(phba,
  1856. KERN_ERR,
  1857. LOG_SLI,
  1858. "0341 Ring %d Cannot find buffer for "
  1859. "an unsolicited iocb. tag 0x%x\n",
  1860. pring->ringno,
  1861. irsp->un.ulpWord[3]);
  1862. }
  1863. if (irsp->ulpBdeCount == 2) {
  1864. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1865. irsp->unsli3.sli3Words[7]);
  1866. if (!saveq->context3)
  1867. lpfc_printf_log(phba,
  1868. KERN_ERR,
  1869. LOG_SLI,
  1870. "0342 Ring %d Cannot find buffer for an"
  1871. " unsolicited iocb. tag 0x%x\n",
  1872. pring->ringno,
  1873. irsp->unsli3.sli3Words[7]);
  1874. }
  1875. list_for_each_entry(iocbq, &saveq->list, list) {
  1876. irsp = &(iocbq->iocb);
  1877. if (irsp->ulpBdeCount != 0) {
  1878. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1879. irsp->un.ulpWord[3]);
  1880. if (!iocbq->context2)
  1881. lpfc_printf_log(phba,
  1882. KERN_ERR,
  1883. LOG_SLI,
  1884. "0343 Ring %d Cannot find "
  1885. "buffer for an unsolicited iocb"
  1886. ". tag 0x%x\n", pring->ringno,
  1887. irsp->un.ulpWord[3]);
  1888. }
  1889. if (irsp->ulpBdeCount == 2) {
  1890. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1891. irsp->unsli3.sli3Words[7]);
  1892. if (!iocbq->context3)
  1893. lpfc_printf_log(phba,
  1894. KERN_ERR,
  1895. LOG_SLI,
  1896. "0344 Ring %d Cannot find "
  1897. "buffer for an unsolicited "
  1898. "iocb. tag 0x%x\n",
  1899. pring->ringno,
  1900. irsp->unsli3.sli3Words[7]);
  1901. }
  1902. }
  1903. }
  1904. if (irsp->ulpBdeCount != 0 &&
  1905. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1906. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1907. int found = 0;
  1908. /* search continue save q for same XRI */
  1909. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1910. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1911. list_add_tail(&saveq->list, &iocbq->list);
  1912. found = 1;
  1913. break;
  1914. }
  1915. }
  1916. if (!found)
  1917. list_add_tail(&saveq->clist,
  1918. &pring->iocb_continue_saveq);
  1919. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1920. list_del_init(&iocbq->clist);
  1921. saveq = iocbq;
  1922. irsp = &(saveq->iocb);
  1923. } else
  1924. return 0;
  1925. }
  1926. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1927. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1928. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1929. Rctl = FC_RCTL_ELS_REQ;
  1930. Type = FC_TYPE_ELS;
  1931. } else {
  1932. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1933. Rctl = w5p->hcsw.Rctl;
  1934. Type = w5p->hcsw.Type;
  1935. /* Firmware Workaround */
  1936. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1937. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1938. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1939. Rctl = FC_RCTL_ELS_REQ;
  1940. Type = FC_TYPE_ELS;
  1941. w5p->hcsw.Rctl = Rctl;
  1942. w5p->hcsw.Type = Type;
  1943. }
  1944. }
  1945. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1946. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1947. "0313 Ring %d handler: unexpected Rctl x%x "
  1948. "Type x%x received\n",
  1949. pring->ringno, Rctl, Type);
  1950. return 1;
  1951. }
  1952. /**
  1953. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1954. * @phba: Pointer to HBA context object.
  1955. * @pring: Pointer to driver SLI ring object.
  1956. * @prspiocb: Pointer to response iocb object.
  1957. *
  1958. * This function looks up the iocb_lookup table to get the command iocb
  1959. * corresponding to the given response iocb using the iotag of the
  1960. * response iocb. This function is called with the hbalock held.
  1961. * This function returns the command iocb object if it finds the command
  1962. * iocb else returns NULL.
  1963. **/
  1964. static struct lpfc_iocbq *
  1965. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1966. struct lpfc_sli_ring *pring,
  1967. struct lpfc_iocbq *prspiocb)
  1968. {
  1969. struct lpfc_iocbq *cmd_iocb = NULL;
  1970. uint16_t iotag;
  1971. iotag = prspiocb->iocb.ulpIoTag;
  1972. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1973. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1974. list_del_init(&cmd_iocb->list);
  1975. pring->txcmplq_cnt--;
  1976. return cmd_iocb;
  1977. }
  1978. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1979. "0317 iotag x%x is out off "
  1980. "range: max iotag x%x wd0 x%x\n",
  1981. iotag, phba->sli.last_iotag,
  1982. *(((uint32_t *) &prspiocb->iocb) + 7));
  1983. return NULL;
  1984. }
  1985. /**
  1986. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1987. * @phba: Pointer to HBA context object.
  1988. * @pring: Pointer to driver SLI ring object.
  1989. * @iotag: IOCB tag.
  1990. *
  1991. * This function looks up the iocb_lookup table to get the command iocb
  1992. * corresponding to the given iotag. This function is called with the
  1993. * hbalock held.
  1994. * This function returns the command iocb object if it finds the command
  1995. * iocb else returns NULL.
  1996. **/
  1997. static struct lpfc_iocbq *
  1998. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  1999. struct lpfc_sli_ring *pring, uint16_t iotag)
  2000. {
  2001. struct lpfc_iocbq *cmd_iocb;
  2002. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2003. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2004. list_del_init(&cmd_iocb->list);
  2005. pring->txcmplq_cnt--;
  2006. return cmd_iocb;
  2007. }
  2008. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2009. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2010. iotag, phba->sli.last_iotag);
  2011. return NULL;
  2012. }
  2013. /**
  2014. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2015. * @phba: Pointer to HBA context object.
  2016. * @pring: Pointer to driver SLI ring object.
  2017. * @saveq: Pointer to the response iocb to be processed.
  2018. *
  2019. * This function is called by the ring event handler for non-fcp
  2020. * rings when there is a new response iocb in the response ring.
  2021. * The caller is not required to hold any locks. This function
  2022. * gets the command iocb associated with the response iocb and
  2023. * calls the completion handler for the command iocb. If there
  2024. * is no completion handler, the function will free the resources
  2025. * associated with command iocb. If the response iocb is for
  2026. * an already aborted command iocb, the status of the completion
  2027. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2028. * This function always returns 1.
  2029. **/
  2030. static int
  2031. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2032. struct lpfc_iocbq *saveq)
  2033. {
  2034. struct lpfc_iocbq *cmdiocbp;
  2035. int rc = 1;
  2036. unsigned long iflag;
  2037. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2038. spin_lock_irqsave(&phba->hbalock, iflag);
  2039. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2040. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2041. if (cmdiocbp) {
  2042. if (cmdiocbp->iocb_cmpl) {
  2043. /*
  2044. * If an ELS command failed send an event to mgmt
  2045. * application.
  2046. */
  2047. if (saveq->iocb.ulpStatus &&
  2048. (pring->ringno == LPFC_ELS_RING) &&
  2049. (cmdiocbp->iocb.ulpCommand ==
  2050. CMD_ELS_REQUEST64_CR))
  2051. lpfc_send_els_failure_event(phba,
  2052. cmdiocbp, saveq);
  2053. /*
  2054. * Post all ELS completions to the worker thread.
  2055. * All other are passed to the completion callback.
  2056. */
  2057. if (pring->ringno == LPFC_ELS_RING) {
  2058. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2059. (cmdiocbp->iocb_flag &
  2060. LPFC_DRIVER_ABORTED)) {
  2061. spin_lock_irqsave(&phba->hbalock,
  2062. iflag);
  2063. cmdiocbp->iocb_flag &=
  2064. ~LPFC_DRIVER_ABORTED;
  2065. spin_unlock_irqrestore(&phba->hbalock,
  2066. iflag);
  2067. saveq->iocb.ulpStatus =
  2068. IOSTAT_LOCAL_REJECT;
  2069. saveq->iocb.un.ulpWord[4] =
  2070. IOERR_SLI_ABORTED;
  2071. /* Firmware could still be in progress
  2072. * of DMAing payload, so don't free data
  2073. * buffer till after a hbeat.
  2074. */
  2075. spin_lock_irqsave(&phba->hbalock,
  2076. iflag);
  2077. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2078. spin_unlock_irqrestore(&phba->hbalock,
  2079. iflag);
  2080. }
  2081. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  2082. (saveq->iocb_flag & LPFC_EXCHANGE_BUSY)) {
  2083. /* Set cmdiocb flag for the exchange
  2084. * busy so sgl (xri) will not be
  2085. * released until the abort xri is
  2086. * received from hba, clear the
  2087. * LPFC_DRIVER_ABORTED bit in case
  2088. * it was driver initiated abort.
  2089. */
  2090. spin_lock_irqsave(&phba->hbalock,
  2091. iflag);
  2092. cmdiocbp->iocb_flag &=
  2093. ~LPFC_DRIVER_ABORTED;
  2094. cmdiocbp->iocb_flag |=
  2095. LPFC_EXCHANGE_BUSY;
  2096. spin_unlock_irqrestore(&phba->hbalock,
  2097. iflag);
  2098. cmdiocbp->iocb.ulpStatus =
  2099. IOSTAT_LOCAL_REJECT;
  2100. cmdiocbp->iocb.un.ulpWord[4] =
  2101. IOERR_ABORT_REQUESTED;
  2102. /*
  2103. * For SLI4, irsiocb contains NO_XRI
  2104. * in sli_xritag, it shall not affect
  2105. * releasing sgl (xri) process.
  2106. */
  2107. saveq->iocb.ulpStatus =
  2108. IOSTAT_LOCAL_REJECT;
  2109. saveq->iocb.un.ulpWord[4] =
  2110. IOERR_SLI_ABORTED;
  2111. spin_lock_irqsave(&phba->hbalock,
  2112. iflag);
  2113. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2114. spin_unlock_irqrestore(&phba->hbalock,
  2115. iflag);
  2116. }
  2117. }
  2118. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2119. } else
  2120. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2121. } else {
  2122. /*
  2123. * Unknown initiating command based on the response iotag.
  2124. * This could be the case on the ELS ring because of
  2125. * lpfc_els_abort().
  2126. */
  2127. if (pring->ringno != LPFC_ELS_RING) {
  2128. /*
  2129. * Ring <ringno> handler: unexpected completion IoTag
  2130. * <IoTag>
  2131. */
  2132. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2133. "0322 Ring %d handler: "
  2134. "unexpected completion IoTag x%x "
  2135. "Data: x%x x%x x%x x%x\n",
  2136. pring->ringno,
  2137. saveq->iocb.ulpIoTag,
  2138. saveq->iocb.ulpStatus,
  2139. saveq->iocb.un.ulpWord[4],
  2140. saveq->iocb.ulpCommand,
  2141. saveq->iocb.ulpContext);
  2142. }
  2143. }
  2144. return rc;
  2145. }
  2146. /**
  2147. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2148. * @phba: Pointer to HBA context object.
  2149. * @pring: Pointer to driver SLI ring object.
  2150. *
  2151. * This function is called from the iocb ring event handlers when
  2152. * put pointer is ahead of the get pointer for a ring. This function signal
  2153. * an error attention condition to the worker thread and the worker
  2154. * thread will transition the HBA to offline state.
  2155. **/
  2156. static void
  2157. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2158. {
  2159. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2160. /*
  2161. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2162. * rsp ring <portRspMax>
  2163. */
  2164. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2165. "0312 Ring %d handler: portRspPut %d "
  2166. "is bigger than rsp ring %d\n",
  2167. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2168. pring->numRiocb);
  2169. phba->link_state = LPFC_HBA_ERROR;
  2170. /*
  2171. * All error attention handlers are posted to
  2172. * worker thread
  2173. */
  2174. phba->work_ha |= HA_ERATT;
  2175. phba->work_hs = HS_FFER3;
  2176. lpfc_worker_wake_up(phba);
  2177. return;
  2178. }
  2179. /**
  2180. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2181. * @ptr: Pointer to address of HBA context object.
  2182. *
  2183. * This function is invoked by the Error Attention polling timer when the
  2184. * timer times out. It will check the SLI Error Attention register for
  2185. * possible attention events. If so, it will post an Error Attention event
  2186. * and wake up worker thread to process it. Otherwise, it will set up the
  2187. * Error Attention polling timer for the next poll.
  2188. **/
  2189. void lpfc_poll_eratt(unsigned long ptr)
  2190. {
  2191. struct lpfc_hba *phba;
  2192. uint32_t eratt = 0;
  2193. phba = (struct lpfc_hba *)ptr;
  2194. /* Check chip HA register for error event */
  2195. eratt = lpfc_sli_check_eratt(phba);
  2196. if (eratt)
  2197. /* Tell the worker thread there is work to do */
  2198. lpfc_worker_wake_up(phba);
  2199. else
  2200. /* Restart the timer for next eratt poll */
  2201. mod_timer(&phba->eratt_poll, jiffies +
  2202. HZ * LPFC_ERATT_POLL_INTERVAL);
  2203. return;
  2204. }
  2205. /**
  2206. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2207. * @phba: Pointer to HBA context object.
  2208. * @pring: Pointer to driver SLI ring object.
  2209. * @mask: Host attention register mask for this ring.
  2210. *
  2211. * This function is called from the interrupt context when there is a ring
  2212. * event for the fcp ring. The caller does not hold any lock.
  2213. * The function processes each response iocb in the response ring until it
  2214. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2215. * LE bit set. The function will call the completion handler of the command iocb
  2216. * if the response iocb indicates a completion for a command iocb or it is
  2217. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2218. * function if this is an unsolicited iocb.
  2219. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2220. * to check it explicitly.
  2221. */
  2222. int
  2223. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2224. struct lpfc_sli_ring *pring, uint32_t mask)
  2225. {
  2226. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2227. IOCB_t *irsp = NULL;
  2228. IOCB_t *entry = NULL;
  2229. struct lpfc_iocbq *cmdiocbq = NULL;
  2230. struct lpfc_iocbq rspiocbq;
  2231. uint32_t status;
  2232. uint32_t portRspPut, portRspMax;
  2233. int rc = 1;
  2234. lpfc_iocb_type type;
  2235. unsigned long iflag;
  2236. uint32_t rsp_cmpl = 0;
  2237. spin_lock_irqsave(&phba->hbalock, iflag);
  2238. pring->stats.iocb_event++;
  2239. /*
  2240. * The next available response entry should never exceed the maximum
  2241. * entries. If it does, treat it as an adapter hardware error.
  2242. */
  2243. portRspMax = pring->numRiocb;
  2244. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2245. if (unlikely(portRspPut >= portRspMax)) {
  2246. lpfc_sli_rsp_pointers_error(phba, pring);
  2247. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2248. return 1;
  2249. }
  2250. if (phba->fcp_ring_in_use) {
  2251. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2252. return 1;
  2253. } else
  2254. phba->fcp_ring_in_use = 1;
  2255. rmb();
  2256. while (pring->rspidx != portRspPut) {
  2257. /*
  2258. * Fetch an entry off the ring and copy it into a local data
  2259. * structure. The copy involves a byte-swap since the
  2260. * network byte order and pci byte orders are different.
  2261. */
  2262. entry = lpfc_resp_iocb(phba, pring);
  2263. phba->last_completion_time = jiffies;
  2264. if (++pring->rspidx >= portRspMax)
  2265. pring->rspidx = 0;
  2266. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2267. (uint32_t *) &rspiocbq.iocb,
  2268. phba->iocb_rsp_size);
  2269. INIT_LIST_HEAD(&(rspiocbq.list));
  2270. irsp = &rspiocbq.iocb;
  2271. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2272. pring->stats.iocb_rsp++;
  2273. rsp_cmpl++;
  2274. if (unlikely(irsp->ulpStatus)) {
  2275. /*
  2276. * If resource errors reported from HBA, reduce
  2277. * queuedepths of the SCSI device.
  2278. */
  2279. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2280. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2281. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2282. phba->lpfc_rampdown_queue_depth(phba);
  2283. spin_lock_irqsave(&phba->hbalock, iflag);
  2284. }
  2285. /* Rsp ring <ringno> error: IOCB */
  2286. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2287. "0336 Rsp Ring %d error: IOCB Data: "
  2288. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2289. pring->ringno,
  2290. irsp->un.ulpWord[0],
  2291. irsp->un.ulpWord[1],
  2292. irsp->un.ulpWord[2],
  2293. irsp->un.ulpWord[3],
  2294. irsp->un.ulpWord[4],
  2295. irsp->un.ulpWord[5],
  2296. *(uint32_t *)&irsp->un1,
  2297. *((uint32_t *)&irsp->un1 + 1));
  2298. }
  2299. switch (type) {
  2300. case LPFC_ABORT_IOCB:
  2301. case LPFC_SOL_IOCB:
  2302. /*
  2303. * Idle exchange closed via ABTS from port. No iocb
  2304. * resources need to be recovered.
  2305. */
  2306. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2307. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2308. "0333 IOCB cmd 0x%x"
  2309. " processed. Skipping"
  2310. " completion\n",
  2311. irsp->ulpCommand);
  2312. break;
  2313. }
  2314. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2315. &rspiocbq);
  2316. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2317. spin_unlock_irqrestore(&phba->hbalock,
  2318. iflag);
  2319. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2320. &rspiocbq);
  2321. spin_lock_irqsave(&phba->hbalock,
  2322. iflag);
  2323. }
  2324. break;
  2325. case LPFC_UNSOL_IOCB:
  2326. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2327. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2328. spin_lock_irqsave(&phba->hbalock, iflag);
  2329. break;
  2330. default:
  2331. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2332. char adaptermsg[LPFC_MAX_ADPTMSG];
  2333. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2334. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2335. MAX_MSG_DATA);
  2336. dev_warn(&((phba->pcidev)->dev),
  2337. "lpfc%d: %s\n",
  2338. phba->brd_no, adaptermsg);
  2339. } else {
  2340. /* Unknown IOCB command */
  2341. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2342. "0334 Unknown IOCB command "
  2343. "Data: x%x, x%x x%x x%x x%x\n",
  2344. type, irsp->ulpCommand,
  2345. irsp->ulpStatus,
  2346. irsp->ulpIoTag,
  2347. irsp->ulpContext);
  2348. }
  2349. break;
  2350. }
  2351. /*
  2352. * The response IOCB has been processed. Update the ring
  2353. * pointer in SLIM. If the port response put pointer has not
  2354. * been updated, sync the pgp->rspPutInx and fetch the new port
  2355. * response put pointer.
  2356. */
  2357. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2358. if (pring->rspidx == portRspPut)
  2359. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2360. }
  2361. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2362. pring->stats.iocb_rsp_full++;
  2363. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2364. writel(status, phba->CAregaddr);
  2365. readl(phba->CAregaddr);
  2366. }
  2367. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2368. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2369. pring->stats.iocb_cmd_empty++;
  2370. /* Force update of the local copy of cmdGetInx */
  2371. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2372. lpfc_sli_resume_iocb(phba, pring);
  2373. if ((pring->lpfc_sli_cmd_available))
  2374. (pring->lpfc_sli_cmd_available) (phba, pring);
  2375. }
  2376. phba->fcp_ring_in_use = 0;
  2377. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2378. return rc;
  2379. }
  2380. /**
  2381. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2382. * @phba: Pointer to HBA context object.
  2383. * @pring: Pointer to driver SLI ring object.
  2384. * @rspiocbp: Pointer to driver response IOCB object.
  2385. *
  2386. * This function is called from the worker thread when there is a slow-path
  2387. * response IOCB to process. This function chains all the response iocbs until
  2388. * seeing the iocb with the LE bit set. The function will call
  2389. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2390. * completion of a command iocb. The function will call the
  2391. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2392. * The function frees the resources or calls the completion handler if this
  2393. * iocb is an abort completion. The function returns NULL when the response
  2394. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2395. * this function shall chain the iocb on to the iocb_continueq and return the
  2396. * response iocb passed in.
  2397. **/
  2398. static struct lpfc_iocbq *
  2399. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2400. struct lpfc_iocbq *rspiocbp)
  2401. {
  2402. struct lpfc_iocbq *saveq;
  2403. struct lpfc_iocbq *cmdiocbp;
  2404. struct lpfc_iocbq *next_iocb;
  2405. IOCB_t *irsp = NULL;
  2406. uint32_t free_saveq;
  2407. uint8_t iocb_cmd_type;
  2408. lpfc_iocb_type type;
  2409. unsigned long iflag;
  2410. int rc;
  2411. spin_lock_irqsave(&phba->hbalock, iflag);
  2412. /* First add the response iocb to the countinueq list */
  2413. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2414. pring->iocb_continueq_cnt++;
  2415. /* Now, determine whetehr the list is completed for processing */
  2416. irsp = &rspiocbp->iocb;
  2417. if (irsp->ulpLe) {
  2418. /*
  2419. * By default, the driver expects to free all resources
  2420. * associated with this iocb completion.
  2421. */
  2422. free_saveq = 1;
  2423. saveq = list_get_first(&pring->iocb_continueq,
  2424. struct lpfc_iocbq, list);
  2425. irsp = &(saveq->iocb);
  2426. list_del_init(&pring->iocb_continueq);
  2427. pring->iocb_continueq_cnt = 0;
  2428. pring->stats.iocb_rsp++;
  2429. /*
  2430. * If resource errors reported from HBA, reduce
  2431. * queuedepths of the SCSI device.
  2432. */
  2433. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2434. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2435. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2436. phba->lpfc_rampdown_queue_depth(phba);
  2437. spin_lock_irqsave(&phba->hbalock, iflag);
  2438. }
  2439. if (irsp->ulpStatus) {
  2440. /* Rsp ring <ringno> error: IOCB */
  2441. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2442. "0328 Rsp Ring %d error: "
  2443. "IOCB Data: "
  2444. "x%x x%x x%x x%x "
  2445. "x%x x%x x%x x%x "
  2446. "x%x x%x x%x x%x "
  2447. "x%x x%x x%x x%x\n",
  2448. pring->ringno,
  2449. irsp->un.ulpWord[0],
  2450. irsp->un.ulpWord[1],
  2451. irsp->un.ulpWord[2],
  2452. irsp->un.ulpWord[3],
  2453. irsp->un.ulpWord[4],
  2454. irsp->un.ulpWord[5],
  2455. *(((uint32_t *) irsp) + 6),
  2456. *(((uint32_t *) irsp) + 7),
  2457. *(((uint32_t *) irsp) + 8),
  2458. *(((uint32_t *) irsp) + 9),
  2459. *(((uint32_t *) irsp) + 10),
  2460. *(((uint32_t *) irsp) + 11),
  2461. *(((uint32_t *) irsp) + 12),
  2462. *(((uint32_t *) irsp) + 13),
  2463. *(((uint32_t *) irsp) + 14),
  2464. *(((uint32_t *) irsp) + 15));
  2465. }
  2466. /*
  2467. * Fetch the IOCB command type and call the correct completion
  2468. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2469. * get freed back to the lpfc_iocb_list by the discovery
  2470. * kernel thread.
  2471. */
  2472. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2473. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2474. switch (type) {
  2475. case LPFC_SOL_IOCB:
  2476. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2477. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2478. spin_lock_irqsave(&phba->hbalock, iflag);
  2479. break;
  2480. case LPFC_UNSOL_IOCB:
  2481. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2482. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2483. spin_lock_irqsave(&phba->hbalock, iflag);
  2484. if (!rc)
  2485. free_saveq = 0;
  2486. break;
  2487. case LPFC_ABORT_IOCB:
  2488. cmdiocbp = NULL;
  2489. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2490. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2491. saveq);
  2492. if (cmdiocbp) {
  2493. /* Call the specified completion routine */
  2494. if (cmdiocbp->iocb_cmpl) {
  2495. spin_unlock_irqrestore(&phba->hbalock,
  2496. iflag);
  2497. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2498. saveq);
  2499. spin_lock_irqsave(&phba->hbalock,
  2500. iflag);
  2501. } else
  2502. __lpfc_sli_release_iocbq(phba,
  2503. cmdiocbp);
  2504. }
  2505. break;
  2506. case LPFC_UNKNOWN_IOCB:
  2507. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2508. char adaptermsg[LPFC_MAX_ADPTMSG];
  2509. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2510. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2511. MAX_MSG_DATA);
  2512. dev_warn(&((phba->pcidev)->dev),
  2513. "lpfc%d: %s\n",
  2514. phba->brd_no, adaptermsg);
  2515. } else {
  2516. /* Unknown IOCB command */
  2517. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2518. "0335 Unknown IOCB "
  2519. "command Data: x%x "
  2520. "x%x x%x x%x\n",
  2521. irsp->ulpCommand,
  2522. irsp->ulpStatus,
  2523. irsp->ulpIoTag,
  2524. irsp->ulpContext);
  2525. }
  2526. break;
  2527. }
  2528. if (free_saveq) {
  2529. list_for_each_entry_safe(rspiocbp, next_iocb,
  2530. &saveq->list, list) {
  2531. list_del(&rspiocbp->list);
  2532. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2533. }
  2534. __lpfc_sli_release_iocbq(phba, saveq);
  2535. }
  2536. rspiocbp = NULL;
  2537. }
  2538. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2539. return rspiocbp;
  2540. }
  2541. /**
  2542. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2543. * @phba: Pointer to HBA context object.
  2544. * @pring: Pointer to driver SLI ring object.
  2545. * @mask: Host attention register mask for this ring.
  2546. *
  2547. * This routine wraps the actual slow_ring event process routine from the
  2548. * API jump table function pointer from the lpfc_hba struct.
  2549. **/
  2550. void
  2551. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2552. struct lpfc_sli_ring *pring, uint32_t mask)
  2553. {
  2554. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2555. }
  2556. /**
  2557. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2558. * @phba: Pointer to HBA context object.
  2559. * @pring: Pointer to driver SLI ring object.
  2560. * @mask: Host attention register mask for this ring.
  2561. *
  2562. * This function is called from the worker thread when there is a ring event
  2563. * for non-fcp rings. The caller does not hold any lock. The function will
  2564. * remove each response iocb in the response ring and calls the handle
  2565. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2566. **/
  2567. static void
  2568. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2569. struct lpfc_sli_ring *pring, uint32_t mask)
  2570. {
  2571. struct lpfc_pgp *pgp;
  2572. IOCB_t *entry;
  2573. IOCB_t *irsp = NULL;
  2574. struct lpfc_iocbq *rspiocbp = NULL;
  2575. uint32_t portRspPut, portRspMax;
  2576. unsigned long iflag;
  2577. uint32_t status;
  2578. pgp = &phba->port_gp[pring->ringno];
  2579. spin_lock_irqsave(&phba->hbalock, iflag);
  2580. pring->stats.iocb_event++;
  2581. /*
  2582. * The next available response entry should never exceed the maximum
  2583. * entries. If it does, treat it as an adapter hardware error.
  2584. */
  2585. portRspMax = pring->numRiocb;
  2586. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2587. if (portRspPut >= portRspMax) {
  2588. /*
  2589. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2590. * rsp ring <portRspMax>
  2591. */
  2592. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2593. "0303 Ring %d handler: portRspPut %d "
  2594. "is bigger than rsp ring %d\n",
  2595. pring->ringno, portRspPut, portRspMax);
  2596. phba->link_state = LPFC_HBA_ERROR;
  2597. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2598. phba->work_hs = HS_FFER3;
  2599. lpfc_handle_eratt(phba);
  2600. return;
  2601. }
  2602. rmb();
  2603. while (pring->rspidx != portRspPut) {
  2604. /*
  2605. * Build a completion list and call the appropriate handler.
  2606. * The process is to get the next available response iocb, get
  2607. * a free iocb from the list, copy the response data into the
  2608. * free iocb, insert to the continuation list, and update the
  2609. * next response index to slim. This process makes response
  2610. * iocb's in the ring available to DMA as fast as possible but
  2611. * pays a penalty for a copy operation. Since the iocb is
  2612. * only 32 bytes, this penalty is considered small relative to
  2613. * the PCI reads for register values and a slim write. When
  2614. * the ulpLe field is set, the entire Command has been
  2615. * received.
  2616. */
  2617. entry = lpfc_resp_iocb(phba, pring);
  2618. phba->last_completion_time = jiffies;
  2619. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2620. if (rspiocbp == NULL) {
  2621. printk(KERN_ERR "%s: out of buffers! Failing "
  2622. "completion.\n", __func__);
  2623. break;
  2624. }
  2625. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2626. phba->iocb_rsp_size);
  2627. irsp = &rspiocbp->iocb;
  2628. if (++pring->rspidx >= portRspMax)
  2629. pring->rspidx = 0;
  2630. if (pring->ringno == LPFC_ELS_RING) {
  2631. lpfc_debugfs_slow_ring_trc(phba,
  2632. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2633. *(((uint32_t *) irsp) + 4),
  2634. *(((uint32_t *) irsp) + 6),
  2635. *(((uint32_t *) irsp) + 7));
  2636. }
  2637. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2638. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2639. /* Handle the response IOCB */
  2640. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2641. spin_lock_irqsave(&phba->hbalock, iflag);
  2642. /*
  2643. * If the port response put pointer has not been updated, sync
  2644. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2645. * response put pointer.
  2646. */
  2647. if (pring->rspidx == portRspPut) {
  2648. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2649. }
  2650. } /* while (pring->rspidx != portRspPut) */
  2651. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2652. /* At least one response entry has been freed */
  2653. pring->stats.iocb_rsp_full++;
  2654. /* SET RxRE_RSP in Chip Att register */
  2655. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2656. writel(status, phba->CAregaddr);
  2657. readl(phba->CAregaddr); /* flush */
  2658. }
  2659. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2660. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2661. pring->stats.iocb_cmd_empty++;
  2662. /* Force update of the local copy of cmdGetInx */
  2663. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2664. lpfc_sli_resume_iocb(phba, pring);
  2665. if ((pring->lpfc_sli_cmd_available))
  2666. (pring->lpfc_sli_cmd_available) (phba, pring);
  2667. }
  2668. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2669. return;
  2670. }
  2671. /**
  2672. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2673. * @phba: Pointer to HBA context object.
  2674. * @pring: Pointer to driver SLI ring object.
  2675. * @mask: Host attention register mask for this ring.
  2676. *
  2677. * This function is called from the worker thread when there is a pending
  2678. * ELS response iocb on the driver internal slow-path response iocb worker
  2679. * queue. The caller does not hold any lock. The function will remove each
  2680. * response iocb from the response worker queue and calls the handle
  2681. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2682. **/
  2683. static void
  2684. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2685. struct lpfc_sli_ring *pring, uint32_t mask)
  2686. {
  2687. struct lpfc_iocbq *irspiocbq;
  2688. struct hbq_dmabuf *dmabuf;
  2689. struct lpfc_cq_event *cq_event;
  2690. unsigned long iflag;
  2691. spin_lock_irqsave(&phba->hbalock, iflag);
  2692. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2693. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2694. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2695. /* Get the response iocb from the head of work queue */
  2696. spin_lock_irqsave(&phba->hbalock, iflag);
  2697. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2698. cq_event, struct lpfc_cq_event, list);
  2699. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2700. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2701. case CQE_CODE_COMPL_WQE:
  2702. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2703. cq_event);
  2704. /* Translate ELS WCQE to response IOCBQ */
  2705. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2706. irspiocbq);
  2707. if (irspiocbq)
  2708. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2709. irspiocbq);
  2710. break;
  2711. case CQE_CODE_RECEIVE:
  2712. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2713. cq_event);
  2714. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2715. break;
  2716. default:
  2717. break;
  2718. }
  2719. }
  2720. }
  2721. /**
  2722. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2723. * @phba: Pointer to HBA context object.
  2724. * @pring: Pointer to driver SLI ring object.
  2725. *
  2726. * This function aborts all iocbs in the given ring and frees all the iocb
  2727. * objects in txq. This function issues an abort iocb for all the iocb commands
  2728. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2729. * the return of this function. The caller is not required to hold any locks.
  2730. **/
  2731. void
  2732. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2733. {
  2734. LIST_HEAD(completions);
  2735. struct lpfc_iocbq *iocb, *next_iocb;
  2736. if (pring->ringno == LPFC_ELS_RING) {
  2737. lpfc_fabric_abort_hba(phba);
  2738. }
  2739. /* Error everything on txq and txcmplq
  2740. * First do the txq.
  2741. */
  2742. spin_lock_irq(&phba->hbalock);
  2743. list_splice_init(&pring->txq, &completions);
  2744. pring->txq_cnt = 0;
  2745. /* Next issue ABTS for everything on the txcmplq */
  2746. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2747. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2748. spin_unlock_irq(&phba->hbalock);
  2749. /* Cancel all the IOCBs from the completions list */
  2750. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2751. IOERR_SLI_ABORTED);
  2752. }
  2753. /**
  2754. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2755. * @phba: Pointer to HBA context object.
  2756. *
  2757. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2758. * objects in txq and txcmplq. This function will not issue abort iocbs
  2759. * for all the iocb commands in txcmplq, they will just be returned with
  2760. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2761. * slot has been permanently disabled.
  2762. **/
  2763. void
  2764. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2765. {
  2766. LIST_HEAD(txq);
  2767. LIST_HEAD(txcmplq);
  2768. struct lpfc_sli *psli = &phba->sli;
  2769. struct lpfc_sli_ring *pring;
  2770. /* Currently, only one fcp ring */
  2771. pring = &psli->ring[psli->fcp_ring];
  2772. spin_lock_irq(&phba->hbalock);
  2773. /* Retrieve everything on txq */
  2774. list_splice_init(&pring->txq, &txq);
  2775. pring->txq_cnt = 0;
  2776. /* Retrieve everything on the txcmplq */
  2777. list_splice_init(&pring->txcmplq, &txcmplq);
  2778. pring->txcmplq_cnt = 0;
  2779. spin_unlock_irq(&phba->hbalock);
  2780. /* Flush the txq */
  2781. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2782. IOERR_SLI_DOWN);
  2783. /* Flush the txcmpq */
  2784. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2785. IOERR_SLI_DOWN);
  2786. }
  2787. /**
  2788. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2789. * @phba: Pointer to HBA context object.
  2790. * @mask: Bit mask to be checked.
  2791. *
  2792. * This function reads the host status register and compares
  2793. * with the provided bit mask to check if HBA completed
  2794. * the restart. This function will wait in a loop for the
  2795. * HBA to complete restart. If the HBA does not restart within
  2796. * 15 iterations, the function will reset the HBA again. The
  2797. * function returns 1 when HBA fail to restart otherwise returns
  2798. * zero.
  2799. **/
  2800. static int
  2801. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2802. {
  2803. uint32_t status;
  2804. int i = 0;
  2805. int retval = 0;
  2806. /* Read the HBA Host Status Register */
  2807. status = readl(phba->HSregaddr);
  2808. /*
  2809. * Check status register every 100ms for 5 retries, then every
  2810. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2811. * every 2.5 sec for 4.
  2812. * Break our of the loop if errors occurred during init.
  2813. */
  2814. while (((status & mask) != mask) &&
  2815. !(status & HS_FFERM) &&
  2816. i++ < 20) {
  2817. if (i <= 5)
  2818. msleep(10);
  2819. else if (i <= 10)
  2820. msleep(500);
  2821. else
  2822. msleep(2500);
  2823. if (i == 15) {
  2824. /* Do post */
  2825. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2826. lpfc_sli_brdrestart(phba);
  2827. }
  2828. /* Read the HBA Host Status Register */
  2829. status = readl(phba->HSregaddr);
  2830. }
  2831. /* Check to see if any errors occurred during init */
  2832. if ((status & HS_FFERM) || (i >= 20)) {
  2833. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2834. "2751 Adapter failed to restart, "
  2835. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  2836. status,
  2837. readl(phba->MBslimaddr + 0xa8),
  2838. readl(phba->MBslimaddr + 0xac));
  2839. phba->link_state = LPFC_HBA_ERROR;
  2840. retval = 1;
  2841. }
  2842. return retval;
  2843. }
  2844. /**
  2845. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2846. * @phba: Pointer to HBA context object.
  2847. * @mask: Bit mask to be checked.
  2848. *
  2849. * This function checks the host status register to check if HBA is
  2850. * ready. This function will wait in a loop for the HBA to be ready
  2851. * If the HBA is not ready , the function will will reset the HBA PCI
  2852. * function again. The function returns 1 when HBA fail to be ready
  2853. * otherwise returns zero.
  2854. **/
  2855. static int
  2856. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2857. {
  2858. uint32_t status;
  2859. int retval = 0;
  2860. /* Read the HBA Host Status Register */
  2861. status = lpfc_sli4_post_status_check(phba);
  2862. if (status) {
  2863. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2864. lpfc_sli_brdrestart(phba);
  2865. status = lpfc_sli4_post_status_check(phba);
  2866. }
  2867. /* Check to see if any errors occurred during init */
  2868. if (status) {
  2869. phba->link_state = LPFC_HBA_ERROR;
  2870. retval = 1;
  2871. } else
  2872. phba->sli4_hba.intr_enable = 0;
  2873. return retval;
  2874. }
  2875. /**
  2876. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2877. * @phba: Pointer to HBA context object.
  2878. * @mask: Bit mask to be checked.
  2879. *
  2880. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2881. * from the API jump table function pointer from the lpfc_hba struct.
  2882. **/
  2883. int
  2884. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2885. {
  2886. return phba->lpfc_sli_brdready(phba, mask);
  2887. }
  2888. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2889. /**
  2890. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2891. * @phba: Pointer to HBA context object.
  2892. *
  2893. * This function is called before resetting an HBA. This
  2894. * function requests HBA to quiesce DMAs before a reset.
  2895. **/
  2896. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2897. {
  2898. uint32_t __iomem *resp_buf;
  2899. uint32_t __iomem *mbox_buf;
  2900. volatile uint32_t mbox;
  2901. uint32_t hc_copy;
  2902. int i;
  2903. uint8_t hdrtype;
  2904. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2905. if (hdrtype != 0x80 ||
  2906. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2907. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2908. return;
  2909. /*
  2910. * Tell the other part of the chip to suspend temporarily all
  2911. * its DMA activity.
  2912. */
  2913. resp_buf = phba->MBslimaddr;
  2914. /* Disable the error attention */
  2915. hc_copy = readl(phba->HCregaddr);
  2916. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2917. readl(phba->HCregaddr); /* flush */
  2918. phba->link_flag |= LS_IGNORE_ERATT;
  2919. if (readl(phba->HAregaddr) & HA_ERATT) {
  2920. /* Clear Chip error bit */
  2921. writel(HA_ERATT, phba->HAregaddr);
  2922. phba->pport->stopped = 1;
  2923. }
  2924. mbox = 0;
  2925. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2926. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2927. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2928. mbox_buf = phba->MBslimaddr;
  2929. writel(mbox, mbox_buf);
  2930. for (i = 0;
  2931. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2932. mdelay(1);
  2933. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2934. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2935. phba->pport->stopped)
  2936. goto restore_hc;
  2937. else
  2938. goto clear_errat;
  2939. }
  2940. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2941. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2942. mdelay(1);
  2943. clear_errat:
  2944. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2945. mdelay(1);
  2946. if (readl(phba->HAregaddr) & HA_ERATT) {
  2947. writel(HA_ERATT, phba->HAregaddr);
  2948. phba->pport->stopped = 1;
  2949. }
  2950. restore_hc:
  2951. phba->link_flag &= ~LS_IGNORE_ERATT;
  2952. writel(hc_copy, phba->HCregaddr);
  2953. readl(phba->HCregaddr); /* flush */
  2954. }
  2955. /**
  2956. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  2957. * @phba: Pointer to HBA context object.
  2958. *
  2959. * This function issues a kill_board mailbox command and waits for
  2960. * the error attention interrupt. This function is called for stopping
  2961. * the firmware processing. The caller is not required to hold any
  2962. * locks. This function calls lpfc_hba_down_post function to free
  2963. * any pending commands after the kill. The function will return 1 when it
  2964. * fails to kill the board else will return 0.
  2965. **/
  2966. int
  2967. lpfc_sli_brdkill(struct lpfc_hba *phba)
  2968. {
  2969. struct lpfc_sli *psli;
  2970. LPFC_MBOXQ_t *pmb;
  2971. uint32_t status;
  2972. uint32_t ha_copy;
  2973. int retval;
  2974. int i = 0;
  2975. psli = &phba->sli;
  2976. /* Kill HBA */
  2977. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2978. "0329 Kill HBA Data: x%x x%x\n",
  2979. phba->pport->port_state, psli->sli_flag);
  2980. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2981. if (!pmb)
  2982. return 1;
  2983. /* Disable the error attention */
  2984. spin_lock_irq(&phba->hbalock);
  2985. status = readl(phba->HCregaddr);
  2986. status &= ~HC_ERINT_ENA;
  2987. writel(status, phba->HCregaddr);
  2988. readl(phba->HCregaddr); /* flush */
  2989. phba->link_flag |= LS_IGNORE_ERATT;
  2990. spin_unlock_irq(&phba->hbalock);
  2991. lpfc_kill_board(phba, pmb);
  2992. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2993. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2994. if (retval != MBX_SUCCESS) {
  2995. if (retval != MBX_BUSY)
  2996. mempool_free(pmb, phba->mbox_mem_pool);
  2997. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2998. "2752 KILL_BOARD command failed retval %d\n",
  2999. retval);
  3000. spin_lock_irq(&phba->hbalock);
  3001. phba->link_flag &= ~LS_IGNORE_ERATT;
  3002. spin_unlock_irq(&phba->hbalock);
  3003. return 1;
  3004. }
  3005. spin_lock_irq(&phba->hbalock);
  3006. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3007. spin_unlock_irq(&phba->hbalock);
  3008. mempool_free(pmb, phba->mbox_mem_pool);
  3009. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3010. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3011. * 3 seconds we still set HBA_ERROR state because the status of the
  3012. * board is now undefined.
  3013. */
  3014. ha_copy = readl(phba->HAregaddr);
  3015. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3016. mdelay(100);
  3017. ha_copy = readl(phba->HAregaddr);
  3018. }
  3019. del_timer_sync(&psli->mbox_tmo);
  3020. if (ha_copy & HA_ERATT) {
  3021. writel(HA_ERATT, phba->HAregaddr);
  3022. phba->pport->stopped = 1;
  3023. }
  3024. spin_lock_irq(&phba->hbalock);
  3025. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3026. psli->mbox_active = NULL;
  3027. phba->link_flag &= ~LS_IGNORE_ERATT;
  3028. spin_unlock_irq(&phba->hbalock);
  3029. lpfc_hba_down_post(phba);
  3030. phba->link_state = LPFC_HBA_ERROR;
  3031. return ha_copy & HA_ERATT ? 0 : 1;
  3032. }
  3033. /**
  3034. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3035. * @phba: Pointer to HBA context object.
  3036. *
  3037. * This function resets the HBA by writing HC_INITFF to the control
  3038. * register. After the HBA resets, this function resets all the iocb ring
  3039. * indices. This function disables PCI layer parity checking during
  3040. * the reset.
  3041. * This function returns 0 always.
  3042. * The caller is not required to hold any locks.
  3043. **/
  3044. int
  3045. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3046. {
  3047. struct lpfc_sli *psli;
  3048. struct lpfc_sli_ring *pring;
  3049. uint16_t cfg_value;
  3050. int i;
  3051. psli = &phba->sli;
  3052. /* Reset HBA */
  3053. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3054. "0325 Reset HBA Data: x%x x%x\n",
  3055. phba->pport->port_state, psli->sli_flag);
  3056. /* perform board reset */
  3057. phba->fc_eventTag = 0;
  3058. phba->link_events = 0;
  3059. phba->pport->fc_myDID = 0;
  3060. phba->pport->fc_prevDID = 0;
  3061. /* Turn off parity checking and serr during the physical reset */
  3062. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3063. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3064. (cfg_value &
  3065. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3066. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3067. /* Now toggle INITFF bit in the Host Control Register */
  3068. writel(HC_INITFF, phba->HCregaddr);
  3069. mdelay(1);
  3070. readl(phba->HCregaddr); /* flush */
  3071. writel(0, phba->HCregaddr);
  3072. readl(phba->HCregaddr); /* flush */
  3073. /* Restore PCI cmd register */
  3074. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3075. /* Initialize relevant SLI info */
  3076. for (i = 0; i < psli->num_rings; i++) {
  3077. pring = &psli->ring[i];
  3078. pring->flag = 0;
  3079. pring->rspidx = 0;
  3080. pring->next_cmdidx = 0;
  3081. pring->local_getidx = 0;
  3082. pring->cmdidx = 0;
  3083. pring->missbufcnt = 0;
  3084. }
  3085. phba->link_state = LPFC_WARM_START;
  3086. return 0;
  3087. }
  3088. /**
  3089. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3090. * @phba: Pointer to HBA context object.
  3091. *
  3092. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3093. * checking during resets the device. The caller is not required to hold
  3094. * any locks.
  3095. *
  3096. * This function returns 0 always.
  3097. **/
  3098. int
  3099. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3100. {
  3101. struct lpfc_sli *psli = &phba->sli;
  3102. uint16_t cfg_value;
  3103. uint8_t qindx;
  3104. /* Reset HBA */
  3105. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3106. "0295 Reset HBA Data: x%x x%x\n",
  3107. phba->pport->port_state, psli->sli_flag);
  3108. /* perform board reset */
  3109. phba->fc_eventTag = 0;
  3110. phba->link_events = 0;
  3111. phba->pport->fc_myDID = 0;
  3112. phba->pport->fc_prevDID = 0;
  3113. /* Turn off parity checking and serr during the physical reset */
  3114. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3115. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3116. (cfg_value &
  3117. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3118. spin_lock_irq(&phba->hbalock);
  3119. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3120. phba->fcf.fcf_flag = 0;
  3121. /* Clean up the child queue list for the CQs */
  3122. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3123. list_del_init(&phba->sli4_hba.els_wq->list);
  3124. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3125. list_del_init(&phba->sli4_hba.dat_rq->list);
  3126. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3127. list_del_init(&phba->sli4_hba.els_cq->list);
  3128. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3129. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3130. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3131. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3132. spin_unlock_irq(&phba->hbalock);
  3133. /* Now physically reset the device */
  3134. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3135. "0389 Performing PCI function reset!\n");
  3136. /* Perform FCoE PCI function reset */
  3137. lpfc_pci_function_reset(phba);
  3138. return 0;
  3139. }
  3140. /**
  3141. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3142. * @phba: Pointer to HBA context object.
  3143. *
  3144. * This function is called in the SLI initialization code path to
  3145. * restart the HBA. The caller is not required to hold any lock.
  3146. * This function writes MBX_RESTART mailbox command to the SLIM and
  3147. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3148. * function to free any pending commands. The function enables
  3149. * POST only during the first initialization. The function returns zero.
  3150. * The function does not guarantee completion of MBX_RESTART mailbox
  3151. * command before the return of this function.
  3152. **/
  3153. static int
  3154. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3155. {
  3156. MAILBOX_t *mb;
  3157. struct lpfc_sli *psli;
  3158. volatile uint32_t word0;
  3159. void __iomem *to_slim;
  3160. uint32_t hba_aer_enabled;
  3161. spin_lock_irq(&phba->hbalock);
  3162. /* Take PCIe device Advanced Error Reporting (AER) state */
  3163. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3164. psli = &phba->sli;
  3165. /* Restart HBA */
  3166. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3167. "0337 Restart HBA Data: x%x x%x\n",
  3168. phba->pport->port_state, psli->sli_flag);
  3169. word0 = 0;
  3170. mb = (MAILBOX_t *) &word0;
  3171. mb->mbxCommand = MBX_RESTART;
  3172. mb->mbxHc = 1;
  3173. lpfc_reset_barrier(phba);
  3174. to_slim = phba->MBslimaddr;
  3175. writel(*(uint32_t *) mb, to_slim);
  3176. readl(to_slim); /* flush */
  3177. /* Only skip post after fc_ffinit is completed */
  3178. if (phba->pport->port_state)
  3179. word0 = 1; /* This is really setting up word1 */
  3180. else
  3181. word0 = 0; /* This is really setting up word1 */
  3182. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3183. writel(*(uint32_t *) mb, to_slim);
  3184. readl(to_slim); /* flush */
  3185. lpfc_sli_brdreset(phba);
  3186. phba->pport->stopped = 0;
  3187. phba->link_state = LPFC_INIT_START;
  3188. phba->hba_flag = 0;
  3189. spin_unlock_irq(&phba->hbalock);
  3190. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3191. psli->stats_start = get_seconds();
  3192. /* Give the INITFF and Post time to settle. */
  3193. mdelay(100);
  3194. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3195. if (hba_aer_enabled)
  3196. pci_disable_pcie_error_reporting(phba->pcidev);
  3197. lpfc_hba_down_post(phba);
  3198. return 0;
  3199. }
  3200. /**
  3201. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3202. * @phba: Pointer to HBA context object.
  3203. *
  3204. * This function is called in the SLI initialization code path to restart
  3205. * a SLI4 HBA. The caller is not required to hold any lock.
  3206. * At the end of the function, it calls lpfc_hba_down_post function to
  3207. * free any pending commands.
  3208. **/
  3209. static int
  3210. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3211. {
  3212. struct lpfc_sli *psli = &phba->sli;
  3213. /* Restart HBA */
  3214. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3215. "0296 Restart HBA Data: x%x x%x\n",
  3216. phba->pport->port_state, psli->sli_flag);
  3217. lpfc_sli4_brdreset(phba);
  3218. spin_lock_irq(&phba->hbalock);
  3219. phba->pport->stopped = 0;
  3220. phba->link_state = LPFC_INIT_START;
  3221. phba->hba_flag = 0;
  3222. spin_unlock_irq(&phba->hbalock);
  3223. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3224. psli->stats_start = get_seconds();
  3225. lpfc_hba_down_post(phba);
  3226. return 0;
  3227. }
  3228. /**
  3229. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3230. * @phba: Pointer to HBA context object.
  3231. *
  3232. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3233. * API jump table function pointer from the lpfc_hba struct.
  3234. **/
  3235. int
  3236. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3237. {
  3238. return phba->lpfc_sli_brdrestart(phba);
  3239. }
  3240. /**
  3241. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3242. * @phba: Pointer to HBA context object.
  3243. *
  3244. * This function is called after a HBA restart to wait for successful
  3245. * restart of the HBA. Successful restart of the HBA is indicated by
  3246. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3247. * iteration, the function will restart the HBA again. The function returns
  3248. * zero if HBA successfully restarted else returns negative error code.
  3249. **/
  3250. static int
  3251. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3252. {
  3253. uint32_t status, i = 0;
  3254. /* Read the HBA Host Status Register */
  3255. status = readl(phba->HSregaddr);
  3256. /* Check status register to see what current state is */
  3257. i = 0;
  3258. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3259. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3260. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3261. * 4.
  3262. */
  3263. if (i++ >= 20) {
  3264. /* Adapter failed to init, timeout, status reg
  3265. <status> */
  3266. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3267. "0436 Adapter failed to init, "
  3268. "timeout, status reg x%x, "
  3269. "FW Data: A8 x%x AC x%x\n", status,
  3270. readl(phba->MBslimaddr + 0xa8),
  3271. readl(phba->MBslimaddr + 0xac));
  3272. phba->link_state = LPFC_HBA_ERROR;
  3273. return -ETIMEDOUT;
  3274. }
  3275. /* Check to see if any errors occurred during init */
  3276. if (status & HS_FFERM) {
  3277. /* ERROR: During chipset initialization */
  3278. /* Adapter failed to init, chipset, status reg
  3279. <status> */
  3280. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3281. "0437 Adapter failed to init, "
  3282. "chipset, status reg x%x, "
  3283. "FW Data: A8 x%x AC x%x\n", status,
  3284. readl(phba->MBslimaddr + 0xa8),
  3285. readl(phba->MBslimaddr + 0xac));
  3286. phba->link_state = LPFC_HBA_ERROR;
  3287. return -EIO;
  3288. }
  3289. if (i <= 5) {
  3290. msleep(10);
  3291. } else if (i <= 10) {
  3292. msleep(500);
  3293. } else {
  3294. msleep(2500);
  3295. }
  3296. if (i == 15) {
  3297. /* Do post */
  3298. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3299. lpfc_sli_brdrestart(phba);
  3300. }
  3301. /* Read the HBA Host Status Register */
  3302. status = readl(phba->HSregaddr);
  3303. }
  3304. /* Check to see if any errors occurred during init */
  3305. if (status & HS_FFERM) {
  3306. /* ERROR: During chipset initialization */
  3307. /* Adapter failed to init, chipset, status reg <status> */
  3308. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3309. "0438 Adapter failed to init, chipset, "
  3310. "status reg x%x, "
  3311. "FW Data: A8 x%x AC x%x\n", status,
  3312. readl(phba->MBslimaddr + 0xa8),
  3313. readl(phba->MBslimaddr + 0xac));
  3314. phba->link_state = LPFC_HBA_ERROR;
  3315. return -EIO;
  3316. }
  3317. /* Clear all interrupt enable conditions */
  3318. writel(0, phba->HCregaddr);
  3319. readl(phba->HCregaddr); /* flush */
  3320. /* setup host attn register */
  3321. writel(0xffffffff, phba->HAregaddr);
  3322. readl(phba->HAregaddr); /* flush */
  3323. return 0;
  3324. }
  3325. /**
  3326. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3327. *
  3328. * This function calculates and returns the number of HBQs required to be
  3329. * configured.
  3330. **/
  3331. int
  3332. lpfc_sli_hbq_count(void)
  3333. {
  3334. return ARRAY_SIZE(lpfc_hbq_defs);
  3335. }
  3336. /**
  3337. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3338. *
  3339. * This function adds the number of hbq entries in every HBQ to get
  3340. * the total number of hbq entries required for the HBA and returns
  3341. * the total count.
  3342. **/
  3343. static int
  3344. lpfc_sli_hbq_entry_count(void)
  3345. {
  3346. int hbq_count = lpfc_sli_hbq_count();
  3347. int count = 0;
  3348. int i;
  3349. for (i = 0; i < hbq_count; ++i)
  3350. count += lpfc_hbq_defs[i]->entry_count;
  3351. return count;
  3352. }
  3353. /**
  3354. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3355. *
  3356. * This function calculates amount of memory required for all hbq entries
  3357. * to be configured and returns the total memory required.
  3358. **/
  3359. int
  3360. lpfc_sli_hbq_size(void)
  3361. {
  3362. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3363. }
  3364. /**
  3365. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3366. * @phba: Pointer to HBA context object.
  3367. *
  3368. * This function is called during the SLI initialization to configure
  3369. * all the HBQs and post buffers to the HBQ. The caller is not
  3370. * required to hold any locks. This function will return zero if successful
  3371. * else it will return negative error code.
  3372. **/
  3373. static int
  3374. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3375. {
  3376. int hbq_count = lpfc_sli_hbq_count();
  3377. LPFC_MBOXQ_t *pmb;
  3378. MAILBOX_t *pmbox;
  3379. uint32_t hbqno;
  3380. uint32_t hbq_entry_index;
  3381. /* Get a Mailbox buffer to setup mailbox
  3382. * commands for HBA initialization
  3383. */
  3384. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3385. if (!pmb)
  3386. return -ENOMEM;
  3387. pmbox = &pmb->u.mb;
  3388. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3389. phba->link_state = LPFC_INIT_MBX_CMDS;
  3390. phba->hbq_in_use = 1;
  3391. hbq_entry_index = 0;
  3392. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3393. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3394. phba->hbqs[hbqno].hbqPutIdx = 0;
  3395. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3396. phba->hbqs[hbqno].entry_count =
  3397. lpfc_hbq_defs[hbqno]->entry_count;
  3398. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3399. hbq_entry_index, pmb);
  3400. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3401. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3402. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3403. mbxStatus <status>, ring <num> */
  3404. lpfc_printf_log(phba, KERN_ERR,
  3405. LOG_SLI | LOG_VPORT,
  3406. "1805 Adapter failed to init. "
  3407. "Data: x%x x%x x%x\n",
  3408. pmbox->mbxCommand,
  3409. pmbox->mbxStatus, hbqno);
  3410. phba->link_state = LPFC_HBA_ERROR;
  3411. mempool_free(pmb, phba->mbox_mem_pool);
  3412. return ENXIO;
  3413. }
  3414. }
  3415. phba->hbq_count = hbq_count;
  3416. mempool_free(pmb, phba->mbox_mem_pool);
  3417. /* Initially populate or replenish the HBQs */
  3418. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3419. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3420. return 0;
  3421. }
  3422. /**
  3423. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3424. * @phba: Pointer to HBA context object.
  3425. *
  3426. * This function is called during the SLI initialization to configure
  3427. * all the HBQs and post buffers to the HBQ. The caller is not
  3428. * required to hold any locks. This function will return zero if successful
  3429. * else it will return negative error code.
  3430. **/
  3431. static int
  3432. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3433. {
  3434. phba->hbq_in_use = 1;
  3435. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3436. phba->hbq_count = 1;
  3437. /* Initially populate or replenish the HBQs */
  3438. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3439. return 0;
  3440. }
  3441. /**
  3442. * lpfc_sli_config_port - Issue config port mailbox command
  3443. * @phba: Pointer to HBA context object.
  3444. * @sli_mode: sli mode - 2/3
  3445. *
  3446. * This function is called by the sli intialization code path
  3447. * to issue config_port mailbox command. This function restarts the
  3448. * HBA firmware and issues a config_port mailbox command to configure
  3449. * the SLI interface in the sli mode specified by sli_mode
  3450. * variable. The caller is not required to hold any locks.
  3451. * The function returns 0 if successful, else returns negative error
  3452. * code.
  3453. **/
  3454. int
  3455. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3456. {
  3457. LPFC_MBOXQ_t *pmb;
  3458. uint32_t resetcount = 0, rc = 0, done = 0;
  3459. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3460. if (!pmb) {
  3461. phba->link_state = LPFC_HBA_ERROR;
  3462. return -ENOMEM;
  3463. }
  3464. phba->sli_rev = sli_mode;
  3465. while (resetcount < 2 && !done) {
  3466. spin_lock_irq(&phba->hbalock);
  3467. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3468. spin_unlock_irq(&phba->hbalock);
  3469. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3470. lpfc_sli_brdrestart(phba);
  3471. rc = lpfc_sli_chipset_init(phba);
  3472. if (rc)
  3473. break;
  3474. spin_lock_irq(&phba->hbalock);
  3475. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3476. spin_unlock_irq(&phba->hbalock);
  3477. resetcount++;
  3478. /* Call pre CONFIG_PORT mailbox command initialization. A
  3479. * value of 0 means the call was successful. Any other
  3480. * nonzero value is a failure, but if ERESTART is returned,
  3481. * the driver may reset the HBA and try again.
  3482. */
  3483. rc = lpfc_config_port_prep(phba);
  3484. if (rc == -ERESTART) {
  3485. phba->link_state = LPFC_LINK_UNKNOWN;
  3486. continue;
  3487. } else if (rc)
  3488. break;
  3489. phba->link_state = LPFC_INIT_MBX_CMDS;
  3490. lpfc_config_port(phba, pmb);
  3491. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3492. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3493. LPFC_SLI3_HBQ_ENABLED |
  3494. LPFC_SLI3_CRP_ENABLED |
  3495. LPFC_SLI3_INB_ENABLED |
  3496. LPFC_SLI3_BG_ENABLED);
  3497. if (rc != MBX_SUCCESS) {
  3498. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3499. "0442 Adapter failed to init, mbxCmd x%x "
  3500. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3501. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3502. spin_lock_irq(&phba->hbalock);
  3503. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3504. spin_unlock_irq(&phba->hbalock);
  3505. rc = -ENXIO;
  3506. } else {
  3507. /* Allow asynchronous mailbox command to go through */
  3508. spin_lock_irq(&phba->hbalock);
  3509. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3510. spin_unlock_irq(&phba->hbalock);
  3511. done = 1;
  3512. }
  3513. }
  3514. if (!done) {
  3515. rc = -EINVAL;
  3516. goto do_prep_failed;
  3517. }
  3518. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3519. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3520. rc = -ENXIO;
  3521. goto do_prep_failed;
  3522. }
  3523. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3524. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3525. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3526. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3527. phba->max_vpi : phba->max_vports;
  3528. } else
  3529. phba->max_vpi = 0;
  3530. if (pmb->u.mb.un.varCfgPort.gdss)
  3531. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3532. if (pmb->u.mb.un.varCfgPort.gerbm)
  3533. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3534. if (pmb->u.mb.un.varCfgPort.gcrp)
  3535. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3536. if (pmb->u.mb.un.varCfgPort.ginb) {
  3537. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3538. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3539. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3540. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3541. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3542. phba->inb_last_counter =
  3543. phba->mbox->us.s3_inb_pgp.counter;
  3544. } else {
  3545. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3546. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3547. phba->inb_ha_copy = NULL;
  3548. phba->inb_counter = NULL;
  3549. }
  3550. if (phba->cfg_enable_bg) {
  3551. if (pmb->u.mb.un.varCfgPort.gbg)
  3552. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3553. else
  3554. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3555. "0443 Adapter did not grant "
  3556. "BlockGuard\n");
  3557. }
  3558. } else {
  3559. phba->hbq_get = NULL;
  3560. phba->port_gp = phba->mbox->us.s2.port;
  3561. phba->inb_ha_copy = NULL;
  3562. phba->inb_counter = NULL;
  3563. phba->max_vpi = 0;
  3564. }
  3565. do_prep_failed:
  3566. mempool_free(pmb, phba->mbox_mem_pool);
  3567. return rc;
  3568. }
  3569. /**
  3570. * lpfc_sli_hba_setup - SLI intialization function
  3571. * @phba: Pointer to HBA context object.
  3572. *
  3573. * This function is the main SLI intialization function. This function
  3574. * is called by the HBA intialization code, HBA reset code and HBA
  3575. * error attention handler code. Caller is not required to hold any
  3576. * locks. This function issues config_port mailbox command to configure
  3577. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3578. * calls the config_port_post function to issue init_link mailbox
  3579. * command and to start the discovery. The function will return zero
  3580. * if successful, else it will return negative error code.
  3581. **/
  3582. int
  3583. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3584. {
  3585. uint32_t rc;
  3586. int mode = 3;
  3587. switch (lpfc_sli_mode) {
  3588. case 2:
  3589. if (phba->cfg_enable_npiv) {
  3590. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3591. "1824 NPIV enabled: Override lpfc_sli_mode "
  3592. "parameter (%d) to auto (0).\n",
  3593. lpfc_sli_mode);
  3594. break;
  3595. }
  3596. mode = 2;
  3597. break;
  3598. case 0:
  3599. case 3:
  3600. break;
  3601. default:
  3602. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3603. "1819 Unrecognized lpfc_sli_mode "
  3604. "parameter: %d.\n", lpfc_sli_mode);
  3605. break;
  3606. }
  3607. rc = lpfc_sli_config_port(phba, mode);
  3608. if (rc && lpfc_sli_mode == 3)
  3609. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3610. "1820 Unable to select SLI-3. "
  3611. "Not supported by adapter.\n");
  3612. if (rc && mode != 2)
  3613. rc = lpfc_sli_config_port(phba, 2);
  3614. if (rc)
  3615. goto lpfc_sli_hba_setup_error;
  3616. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3617. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3618. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3619. if (!rc) {
  3620. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3621. "2709 This device supports "
  3622. "Advanced Error Reporting (AER)\n");
  3623. spin_lock_irq(&phba->hbalock);
  3624. phba->hba_flag |= HBA_AER_ENABLED;
  3625. spin_unlock_irq(&phba->hbalock);
  3626. } else {
  3627. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3628. "2708 This device does not support "
  3629. "Advanced Error Reporting (AER)\n");
  3630. phba->cfg_aer_support = 0;
  3631. }
  3632. }
  3633. if (phba->sli_rev == 3) {
  3634. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3635. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3636. } else {
  3637. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3638. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3639. phba->sli3_options = 0;
  3640. }
  3641. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3642. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3643. phba->sli_rev, phba->max_vpi);
  3644. rc = lpfc_sli_ring_map(phba);
  3645. if (rc)
  3646. goto lpfc_sli_hba_setup_error;
  3647. /* Init HBQs */
  3648. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3649. rc = lpfc_sli_hbq_setup(phba);
  3650. if (rc)
  3651. goto lpfc_sli_hba_setup_error;
  3652. }
  3653. spin_lock_irq(&phba->hbalock);
  3654. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3655. spin_unlock_irq(&phba->hbalock);
  3656. rc = lpfc_config_port_post(phba);
  3657. if (rc)
  3658. goto lpfc_sli_hba_setup_error;
  3659. return rc;
  3660. lpfc_sli_hba_setup_error:
  3661. phba->link_state = LPFC_HBA_ERROR;
  3662. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3663. "0445 Firmware initialization failed\n");
  3664. return rc;
  3665. }
  3666. /**
  3667. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3668. * @phba: Pointer to HBA context object.
  3669. * @mboxq: mailbox pointer.
  3670. * This function issue a dump mailbox command to read config region
  3671. * 23 and parse the records in the region and populate driver
  3672. * data structure.
  3673. **/
  3674. static int
  3675. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3676. LPFC_MBOXQ_t *mboxq)
  3677. {
  3678. struct lpfc_dmabuf *mp;
  3679. struct lpfc_mqe *mqe;
  3680. uint32_t data_length;
  3681. int rc;
  3682. /* Program the default value of vlan_id and fc_map */
  3683. phba->valid_vlan = 0;
  3684. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3685. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3686. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3687. mqe = &mboxq->u.mqe;
  3688. if (lpfc_dump_fcoe_param(phba, mboxq))
  3689. return -ENOMEM;
  3690. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3691. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3692. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3693. "(%d):2571 Mailbox cmd x%x Status x%x "
  3694. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3695. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3696. "CQ: x%x x%x x%x x%x\n",
  3697. mboxq->vport ? mboxq->vport->vpi : 0,
  3698. bf_get(lpfc_mqe_command, mqe),
  3699. bf_get(lpfc_mqe_status, mqe),
  3700. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3701. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3702. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3703. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3704. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3705. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3706. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3707. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3708. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3709. mboxq->mcqe.word0,
  3710. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3711. mboxq->mcqe.trailer);
  3712. if (rc) {
  3713. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3714. kfree(mp);
  3715. return -EIO;
  3716. }
  3717. data_length = mqe->un.mb_words[5];
  3718. if (data_length > DMP_RGN23_SIZE) {
  3719. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3720. kfree(mp);
  3721. return -EIO;
  3722. }
  3723. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3724. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3725. kfree(mp);
  3726. return 0;
  3727. }
  3728. /**
  3729. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3730. * @phba: pointer to lpfc hba data structure.
  3731. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3732. * @vpd: pointer to the memory to hold resulting port vpd data.
  3733. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3734. * On output, the number of data bytes in @vpd.
  3735. *
  3736. * This routine executes a READ_REV SLI4 mailbox command. In
  3737. * addition, this routine gets the port vpd data.
  3738. *
  3739. * Return codes
  3740. * 0 - successful
  3741. * ENOMEM - could not allocated memory.
  3742. **/
  3743. static int
  3744. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3745. uint8_t *vpd, uint32_t *vpd_size)
  3746. {
  3747. int rc = 0;
  3748. uint32_t dma_size;
  3749. struct lpfc_dmabuf *dmabuf;
  3750. struct lpfc_mqe *mqe;
  3751. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3752. if (!dmabuf)
  3753. return -ENOMEM;
  3754. /*
  3755. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3756. * mailbox command.
  3757. */
  3758. dma_size = *vpd_size;
  3759. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3760. dma_size,
  3761. &dmabuf->phys,
  3762. GFP_KERNEL);
  3763. if (!dmabuf->virt) {
  3764. kfree(dmabuf);
  3765. return -ENOMEM;
  3766. }
  3767. memset(dmabuf->virt, 0, dma_size);
  3768. /*
  3769. * The SLI4 implementation of READ_REV conflicts at word1,
  3770. * bits 31:16 and SLI4 adds vpd functionality not present
  3771. * in SLI3. This code corrects the conflicts.
  3772. */
  3773. lpfc_read_rev(phba, mboxq);
  3774. mqe = &mboxq->u.mqe;
  3775. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3776. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3777. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3778. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3779. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3780. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3781. if (rc) {
  3782. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3783. dmabuf->virt, dmabuf->phys);
  3784. kfree(dmabuf);
  3785. return -EIO;
  3786. }
  3787. /*
  3788. * The available vpd length cannot be bigger than the
  3789. * DMA buffer passed to the port. Catch the less than
  3790. * case and update the caller's size.
  3791. */
  3792. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3793. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3794. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3795. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3796. dmabuf->virt, dmabuf->phys);
  3797. kfree(dmabuf);
  3798. return 0;
  3799. }
  3800. /**
  3801. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3802. * @phba: pointer to lpfc hba data structure.
  3803. *
  3804. * This routine is called to explicitly arm the SLI4 device's completion and
  3805. * event queues
  3806. **/
  3807. static void
  3808. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3809. {
  3810. uint8_t fcp_eqidx;
  3811. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3812. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3813. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3814. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3815. LPFC_QUEUE_REARM);
  3816. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3817. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3818. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3819. LPFC_QUEUE_REARM);
  3820. }
  3821. /**
  3822. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3823. * @phba: Pointer to HBA context object.
  3824. *
  3825. * This function is the main SLI4 device intialization PCI function. This
  3826. * function is called by the HBA intialization code, HBA reset code and
  3827. * HBA error attention handler code. Caller is not required to hold any
  3828. * locks.
  3829. **/
  3830. int
  3831. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3832. {
  3833. int rc;
  3834. LPFC_MBOXQ_t *mboxq;
  3835. struct lpfc_mqe *mqe;
  3836. uint8_t *vpd;
  3837. uint32_t vpd_size;
  3838. uint32_t ftr_rsp = 0;
  3839. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3840. struct lpfc_vport *vport = phba->pport;
  3841. struct lpfc_dmabuf *mp;
  3842. /* Perform a PCI function reset to start from clean */
  3843. rc = lpfc_pci_function_reset(phba);
  3844. if (unlikely(rc))
  3845. return -ENODEV;
  3846. /* Check the HBA Host Status Register for readyness */
  3847. rc = lpfc_sli4_post_status_check(phba);
  3848. if (unlikely(rc))
  3849. return -ENODEV;
  3850. else {
  3851. spin_lock_irq(&phba->hbalock);
  3852. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3853. spin_unlock_irq(&phba->hbalock);
  3854. }
  3855. /*
  3856. * Allocate a single mailbox container for initializing the
  3857. * port.
  3858. */
  3859. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3860. if (!mboxq)
  3861. return -ENOMEM;
  3862. /*
  3863. * Continue initialization with default values even if driver failed
  3864. * to read FCoE param config regions
  3865. */
  3866. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3867. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3868. "2570 Failed to read FCoE parameters\n");
  3869. /* Issue READ_REV to collect vpd and FW information. */
  3870. vpd_size = PAGE_SIZE;
  3871. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3872. if (!vpd) {
  3873. rc = -ENOMEM;
  3874. goto out_free_mbox;
  3875. }
  3876. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3877. if (unlikely(rc))
  3878. goto out_free_vpd;
  3879. mqe = &mboxq->u.mqe;
  3880. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3881. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3882. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3883. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3884. LPFC_DCBX_CEE_MODE)
  3885. phba->hba_flag |= HBA_FIP_SUPPORT;
  3886. else
  3887. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3888. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3889. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3890. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3891. "0376 READ_REV Error. SLI Level %d "
  3892. "FCoE enabled %d\n",
  3893. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3894. rc = -EIO;
  3895. goto out_free_vpd;
  3896. }
  3897. /*
  3898. * Evaluate the read rev and vpd data. Populate the driver
  3899. * state with the results. If this routine fails, the failure
  3900. * is not fatal as the driver will use generic values.
  3901. */
  3902. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3903. if (unlikely(!rc)) {
  3904. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3905. "0377 Error %d parsing vpd. "
  3906. "Using defaults.\n", rc);
  3907. rc = 0;
  3908. }
  3909. /* Save information as VPD data */
  3910. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3911. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3912. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3913. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3914. &mqe->un.read_rev);
  3915. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3916. &mqe->un.read_rev);
  3917. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3918. &mqe->un.read_rev);
  3919. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3920. &mqe->un.read_rev);
  3921. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3922. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3923. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3924. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3925. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3926. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3927. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3928. "(%d):0380 READ_REV Status x%x "
  3929. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3930. mboxq->vport ? mboxq->vport->vpi : 0,
  3931. bf_get(lpfc_mqe_status, mqe),
  3932. phba->vpd.rev.opFwName,
  3933. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3934. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3935. /*
  3936. * Discover the port's supported feature set and match it against the
  3937. * hosts requests.
  3938. */
  3939. lpfc_request_features(phba, mboxq);
  3940. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3941. if (unlikely(rc)) {
  3942. rc = -EIO;
  3943. goto out_free_vpd;
  3944. }
  3945. /*
  3946. * The port must support FCP initiator mode as this is the
  3947. * only mode running in the host.
  3948. */
  3949. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3950. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3951. "0378 No support for fcpi mode.\n");
  3952. ftr_rsp++;
  3953. }
  3954. /*
  3955. * If the port cannot support the host's requested features
  3956. * then turn off the global config parameters to disable the
  3957. * feature in the driver. This is not a fatal error.
  3958. */
  3959. if ((phba->cfg_enable_bg) &&
  3960. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3961. ftr_rsp++;
  3962. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3963. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3964. ftr_rsp++;
  3965. if (ftr_rsp) {
  3966. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3967. "0379 Feature Mismatch Data: x%08x %08x "
  3968. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3969. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3970. phba->cfg_enable_npiv, phba->max_vpi);
  3971. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3972. phba->cfg_enable_bg = 0;
  3973. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3974. phba->cfg_enable_npiv = 0;
  3975. }
  3976. /* These SLI3 features are assumed in SLI4 */
  3977. spin_lock_irq(&phba->hbalock);
  3978. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  3979. spin_unlock_irq(&phba->hbalock);
  3980. /* Read the port's service parameters. */
  3981. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  3982. if (rc) {
  3983. phba->link_state = LPFC_HBA_ERROR;
  3984. rc = -ENOMEM;
  3985. goto out_free_vpd;
  3986. }
  3987. mboxq->vport = vport;
  3988. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3989. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3990. if (rc == MBX_SUCCESS) {
  3991. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  3992. rc = 0;
  3993. }
  3994. /*
  3995. * This memory was allocated by the lpfc_read_sparam routine. Release
  3996. * it to the mbuf pool.
  3997. */
  3998. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3999. kfree(mp);
  4000. mboxq->context1 = NULL;
  4001. if (unlikely(rc)) {
  4002. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4003. "0382 READ_SPARAM command failed "
  4004. "status %d, mbxStatus x%x\n",
  4005. rc, bf_get(lpfc_mqe_status, mqe));
  4006. phba->link_state = LPFC_HBA_ERROR;
  4007. rc = -EIO;
  4008. goto out_free_vpd;
  4009. }
  4010. if (phba->cfg_soft_wwnn)
  4011. u64_to_wwn(phba->cfg_soft_wwnn,
  4012. vport->fc_sparam.nodeName.u.wwn);
  4013. if (phba->cfg_soft_wwpn)
  4014. u64_to_wwn(phba->cfg_soft_wwpn,
  4015. vport->fc_sparam.portName.u.wwn);
  4016. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4017. sizeof(struct lpfc_name));
  4018. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4019. sizeof(struct lpfc_name));
  4020. /* Update the fc_host data structures with new wwn. */
  4021. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4022. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4023. /* Register SGL pool to the device using non-embedded mailbox command */
  4024. rc = lpfc_sli4_post_sgl_list(phba);
  4025. if (unlikely(rc)) {
  4026. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4027. "0582 Error %d during sgl post operation\n",
  4028. rc);
  4029. rc = -ENODEV;
  4030. goto out_free_vpd;
  4031. }
  4032. /* Register SCSI SGL pool to the device */
  4033. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4034. if (unlikely(rc)) {
  4035. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4036. "0383 Error %d during scsi sgl post "
  4037. "operation\n", rc);
  4038. /* Some Scsi buffers were moved to the abort scsi list */
  4039. /* A pci function reset will repost them */
  4040. rc = -ENODEV;
  4041. goto out_free_vpd;
  4042. }
  4043. /* Post the rpi header region to the device. */
  4044. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4045. if (unlikely(rc)) {
  4046. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4047. "0393 Error %d during rpi post operation\n",
  4048. rc);
  4049. rc = -ENODEV;
  4050. goto out_free_vpd;
  4051. }
  4052. /* Set up all the queues to the device */
  4053. rc = lpfc_sli4_queue_setup(phba);
  4054. if (unlikely(rc)) {
  4055. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4056. "0381 Error %d during queue setup.\n ", rc);
  4057. goto out_stop_timers;
  4058. }
  4059. /* Arm the CQs and then EQs on device */
  4060. lpfc_sli4_arm_cqeq_intr(phba);
  4061. /* Indicate device interrupt mode */
  4062. phba->sli4_hba.intr_enable = 1;
  4063. /* Allow asynchronous mailbox command to go through */
  4064. spin_lock_irq(&phba->hbalock);
  4065. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4066. spin_unlock_irq(&phba->hbalock);
  4067. /* Post receive buffers to the device */
  4068. lpfc_sli4_rb_setup(phba);
  4069. /* Start the ELS watchdog timer */
  4070. mod_timer(&vport->els_tmofunc,
  4071. jiffies + HZ * (phba->fc_ratov * 2));
  4072. /* Start heart beat timer */
  4073. mod_timer(&phba->hb_tmofunc,
  4074. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4075. phba->hb_outstanding = 0;
  4076. phba->last_completion_time = jiffies;
  4077. /* Start error attention (ERATT) polling timer */
  4078. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4079. /*
  4080. * The port is ready, set the host's link state to LINK_DOWN
  4081. * in preparation for link interrupts.
  4082. */
  4083. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4084. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4085. lpfc_set_loopback_flag(phba);
  4086. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4087. spin_lock_irq(&phba->hbalock);
  4088. phba->link_state = LPFC_LINK_DOWN;
  4089. spin_unlock_irq(&phba->hbalock);
  4090. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4091. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4092. kfree(vpd);
  4093. return 0;
  4094. } else
  4095. rc = -EIO;
  4096. /* Unset all the queues set up in this routine when error out */
  4097. if (rc)
  4098. lpfc_sli4_queue_unset(phba);
  4099. out_stop_timers:
  4100. if (rc)
  4101. lpfc_stop_hba_timers(phba);
  4102. out_free_vpd:
  4103. kfree(vpd);
  4104. out_free_mbox:
  4105. mempool_free(mboxq, phba->mbox_mem_pool);
  4106. return rc;
  4107. }
  4108. /**
  4109. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4110. * @ptr: context object - pointer to hba structure.
  4111. *
  4112. * This is the callback function for mailbox timer. The mailbox
  4113. * timer is armed when a new mailbox command is issued and the timer
  4114. * is deleted when the mailbox complete. The function is called by
  4115. * the kernel timer code when a mailbox does not complete within
  4116. * expected time. This function wakes up the worker thread to
  4117. * process the mailbox timeout and returns. All the processing is
  4118. * done by the worker thread function lpfc_mbox_timeout_handler.
  4119. **/
  4120. void
  4121. lpfc_mbox_timeout(unsigned long ptr)
  4122. {
  4123. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4124. unsigned long iflag;
  4125. uint32_t tmo_posted;
  4126. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4127. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4128. if (!tmo_posted)
  4129. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4130. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4131. if (!tmo_posted)
  4132. lpfc_worker_wake_up(phba);
  4133. return;
  4134. }
  4135. /**
  4136. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4137. * @phba: Pointer to HBA context object.
  4138. *
  4139. * This function is called from worker thread when a mailbox command times out.
  4140. * The caller is not required to hold any locks. This function will reset the
  4141. * HBA and recover all the pending commands.
  4142. **/
  4143. void
  4144. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4145. {
  4146. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4147. MAILBOX_t *mb = &pmbox->u.mb;
  4148. struct lpfc_sli *psli = &phba->sli;
  4149. struct lpfc_sli_ring *pring;
  4150. /* Check the pmbox pointer first. There is a race condition
  4151. * between the mbox timeout handler getting executed in the
  4152. * worklist and the mailbox actually completing. When this
  4153. * race condition occurs, the mbox_active will be NULL.
  4154. */
  4155. spin_lock_irq(&phba->hbalock);
  4156. if (pmbox == NULL) {
  4157. lpfc_printf_log(phba, KERN_WARNING,
  4158. LOG_MBOX | LOG_SLI,
  4159. "0353 Active Mailbox cleared - mailbox timeout "
  4160. "exiting\n");
  4161. spin_unlock_irq(&phba->hbalock);
  4162. return;
  4163. }
  4164. /* Mbox cmd <mbxCommand> timeout */
  4165. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4166. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4167. mb->mbxCommand,
  4168. phba->pport->port_state,
  4169. phba->sli.sli_flag,
  4170. phba->sli.mbox_active);
  4171. spin_unlock_irq(&phba->hbalock);
  4172. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4173. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4174. * it to fail all oustanding SCSI IO.
  4175. */
  4176. spin_lock_irq(&phba->pport->work_port_lock);
  4177. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4178. spin_unlock_irq(&phba->pport->work_port_lock);
  4179. spin_lock_irq(&phba->hbalock);
  4180. phba->link_state = LPFC_LINK_UNKNOWN;
  4181. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4182. spin_unlock_irq(&phba->hbalock);
  4183. pring = &psli->ring[psli->fcp_ring];
  4184. lpfc_sli_abort_iocb_ring(phba, pring);
  4185. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4186. "0345 Resetting board due to mailbox timeout\n");
  4187. /* Reset the HBA device */
  4188. lpfc_reset_hba(phba);
  4189. }
  4190. /**
  4191. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4192. * @phba: Pointer to HBA context object.
  4193. * @pmbox: Pointer to mailbox object.
  4194. * @flag: Flag indicating how the mailbox need to be processed.
  4195. *
  4196. * This function is called by discovery code and HBA management code
  4197. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4198. * function gets the hbalock to protect the data structures.
  4199. * The mailbox command can be submitted in polling mode, in which case
  4200. * this function will wait in a polling loop for the completion of the
  4201. * mailbox.
  4202. * If the mailbox is submitted in no_wait mode (not polling) the
  4203. * function will submit the command and returns immediately without waiting
  4204. * for the mailbox completion. The no_wait is supported only when HBA
  4205. * is in SLI2/SLI3 mode - interrupts are enabled.
  4206. * The SLI interface allows only one mailbox pending at a time. If the
  4207. * mailbox is issued in polling mode and there is already a mailbox
  4208. * pending, then the function will return an error. If the mailbox is issued
  4209. * in NO_WAIT mode and there is a mailbox pending already, the function
  4210. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4211. * The sli layer owns the mailbox object until the completion of mailbox
  4212. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4213. * return codes the caller owns the mailbox command after the return of
  4214. * the function.
  4215. **/
  4216. static int
  4217. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4218. uint32_t flag)
  4219. {
  4220. MAILBOX_t *mb;
  4221. struct lpfc_sli *psli = &phba->sli;
  4222. uint32_t status, evtctr;
  4223. uint32_t ha_copy;
  4224. int i;
  4225. unsigned long timeout;
  4226. unsigned long drvr_flag = 0;
  4227. uint32_t word0, ldata;
  4228. void __iomem *to_slim;
  4229. int processing_queue = 0;
  4230. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4231. if (!pmbox) {
  4232. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4233. /* processing mbox queue from intr_handler */
  4234. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4235. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4236. return MBX_SUCCESS;
  4237. }
  4238. processing_queue = 1;
  4239. pmbox = lpfc_mbox_get(phba);
  4240. if (!pmbox) {
  4241. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4242. return MBX_SUCCESS;
  4243. }
  4244. }
  4245. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4246. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4247. if(!pmbox->vport) {
  4248. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4249. lpfc_printf_log(phba, KERN_ERR,
  4250. LOG_MBOX | LOG_VPORT,
  4251. "1806 Mbox x%x failed. No vport\n",
  4252. pmbox->u.mb.mbxCommand);
  4253. dump_stack();
  4254. goto out_not_finished;
  4255. }
  4256. }
  4257. /* If the PCI channel is in offline state, do not post mbox. */
  4258. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4259. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4260. goto out_not_finished;
  4261. }
  4262. /* If HBA has a deferred error attention, fail the iocb. */
  4263. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4264. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4265. goto out_not_finished;
  4266. }
  4267. psli = &phba->sli;
  4268. mb = &pmbox->u.mb;
  4269. status = MBX_SUCCESS;
  4270. if (phba->link_state == LPFC_HBA_ERROR) {
  4271. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4272. /* Mbox command <mbxCommand> cannot issue */
  4273. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4274. "(%d):0311 Mailbox command x%x cannot "
  4275. "issue Data: x%x x%x\n",
  4276. pmbox->vport ? pmbox->vport->vpi : 0,
  4277. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4278. goto out_not_finished;
  4279. }
  4280. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4281. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4282. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4283. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4284. "(%d):2528 Mailbox command x%x cannot "
  4285. "issue Data: x%x x%x\n",
  4286. pmbox->vport ? pmbox->vport->vpi : 0,
  4287. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4288. goto out_not_finished;
  4289. }
  4290. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4291. /* Polling for a mbox command when another one is already active
  4292. * is not allowed in SLI. Also, the driver must have established
  4293. * SLI2 mode to queue and process multiple mbox commands.
  4294. */
  4295. if (flag & MBX_POLL) {
  4296. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4297. /* Mbox command <mbxCommand> cannot issue */
  4298. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4299. "(%d):2529 Mailbox command x%x "
  4300. "cannot issue Data: x%x x%x\n",
  4301. pmbox->vport ? pmbox->vport->vpi : 0,
  4302. pmbox->u.mb.mbxCommand,
  4303. psli->sli_flag, flag);
  4304. goto out_not_finished;
  4305. }
  4306. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4307. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4308. /* Mbox command <mbxCommand> cannot issue */
  4309. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4310. "(%d):2530 Mailbox command x%x "
  4311. "cannot issue Data: x%x x%x\n",
  4312. pmbox->vport ? pmbox->vport->vpi : 0,
  4313. pmbox->u.mb.mbxCommand,
  4314. psli->sli_flag, flag);
  4315. goto out_not_finished;
  4316. }
  4317. /* Another mailbox command is still being processed, queue this
  4318. * command to be processed later.
  4319. */
  4320. lpfc_mbox_put(phba, pmbox);
  4321. /* Mbox cmd issue - BUSY */
  4322. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4323. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4324. "x%x x%x x%x x%x\n",
  4325. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4326. mb->mbxCommand, phba->pport->port_state,
  4327. psli->sli_flag, flag);
  4328. psli->slistat.mbox_busy++;
  4329. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4330. if (pmbox->vport) {
  4331. lpfc_debugfs_disc_trc(pmbox->vport,
  4332. LPFC_DISC_TRC_MBOX_VPORT,
  4333. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4334. (uint32_t)mb->mbxCommand,
  4335. mb->un.varWords[0], mb->un.varWords[1]);
  4336. }
  4337. else {
  4338. lpfc_debugfs_disc_trc(phba->pport,
  4339. LPFC_DISC_TRC_MBOX,
  4340. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4341. (uint32_t)mb->mbxCommand,
  4342. mb->un.varWords[0], mb->un.varWords[1]);
  4343. }
  4344. return MBX_BUSY;
  4345. }
  4346. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4347. /* If we are not polling, we MUST be in SLI2 mode */
  4348. if (flag != MBX_POLL) {
  4349. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4350. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4351. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4352. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4353. /* Mbox command <mbxCommand> cannot issue */
  4354. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4355. "(%d):2531 Mailbox command x%x "
  4356. "cannot issue Data: x%x x%x\n",
  4357. pmbox->vport ? pmbox->vport->vpi : 0,
  4358. pmbox->u.mb.mbxCommand,
  4359. psli->sli_flag, flag);
  4360. goto out_not_finished;
  4361. }
  4362. /* timeout active mbox command */
  4363. mod_timer(&psli->mbox_tmo, (jiffies +
  4364. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4365. }
  4366. /* Mailbox cmd <cmd> issue */
  4367. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4368. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4369. "x%x\n",
  4370. pmbox->vport ? pmbox->vport->vpi : 0,
  4371. mb->mbxCommand, phba->pport->port_state,
  4372. psli->sli_flag, flag);
  4373. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4374. if (pmbox->vport) {
  4375. lpfc_debugfs_disc_trc(pmbox->vport,
  4376. LPFC_DISC_TRC_MBOX_VPORT,
  4377. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4378. (uint32_t)mb->mbxCommand,
  4379. mb->un.varWords[0], mb->un.varWords[1]);
  4380. }
  4381. else {
  4382. lpfc_debugfs_disc_trc(phba->pport,
  4383. LPFC_DISC_TRC_MBOX,
  4384. "MBOX Send: cmd:x%x mb:x%x x%x",
  4385. (uint32_t)mb->mbxCommand,
  4386. mb->un.varWords[0], mb->un.varWords[1]);
  4387. }
  4388. }
  4389. psli->slistat.mbox_cmd++;
  4390. evtctr = psli->slistat.mbox_event;
  4391. /* next set own bit for the adapter and copy over command word */
  4392. mb->mbxOwner = OWN_CHIP;
  4393. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4394. /* First copy command data to host SLIM area */
  4395. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4396. } else {
  4397. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4398. /* copy command data into host mbox for cmpl */
  4399. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4400. }
  4401. /* First copy mbox command data to HBA SLIM, skip past first
  4402. word */
  4403. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4404. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4405. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4406. /* Next copy over first word, with mbxOwner set */
  4407. ldata = *((uint32_t *)mb);
  4408. to_slim = phba->MBslimaddr;
  4409. writel(ldata, to_slim);
  4410. readl(to_slim); /* flush */
  4411. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4412. /* switch over to host mailbox */
  4413. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4414. }
  4415. }
  4416. wmb();
  4417. switch (flag) {
  4418. case MBX_NOWAIT:
  4419. /* Set up reference to mailbox command */
  4420. psli->mbox_active = pmbox;
  4421. /* Interrupt board to do it */
  4422. writel(CA_MBATT, phba->CAregaddr);
  4423. readl(phba->CAregaddr); /* flush */
  4424. /* Don't wait for it to finish, just return */
  4425. break;
  4426. case MBX_POLL:
  4427. /* Set up null reference to mailbox command */
  4428. psli->mbox_active = NULL;
  4429. /* Interrupt board to do it */
  4430. writel(CA_MBATT, phba->CAregaddr);
  4431. readl(phba->CAregaddr); /* flush */
  4432. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4433. /* First read mbox status word */
  4434. word0 = *((uint32_t *)phba->mbox);
  4435. word0 = le32_to_cpu(word0);
  4436. } else {
  4437. /* First read mbox status word */
  4438. word0 = readl(phba->MBslimaddr);
  4439. }
  4440. /* Read the HBA Host Attention Register */
  4441. ha_copy = readl(phba->HAregaddr);
  4442. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4443. mb->mbxCommand) *
  4444. 1000) + jiffies;
  4445. i = 0;
  4446. /* Wait for command to complete */
  4447. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4448. (!(ha_copy & HA_MBATT) &&
  4449. (phba->link_state > LPFC_WARM_START))) {
  4450. if (time_after(jiffies, timeout)) {
  4451. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4452. spin_unlock_irqrestore(&phba->hbalock,
  4453. drvr_flag);
  4454. goto out_not_finished;
  4455. }
  4456. /* Check if we took a mbox interrupt while we were
  4457. polling */
  4458. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4459. && (evtctr != psli->slistat.mbox_event))
  4460. break;
  4461. if (i++ > 10) {
  4462. spin_unlock_irqrestore(&phba->hbalock,
  4463. drvr_flag);
  4464. msleep(1);
  4465. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4466. }
  4467. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4468. /* First copy command data */
  4469. word0 = *((uint32_t *)phba->mbox);
  4470. word0 = le32_to_cpu(word0);
  4471. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4472. MAILBOX_t *slimmb;
  4473. uint32_t slimword0;
  4474. /* Check real SLIM for any errors */
  4475. slimword0 = readl(phba->MBslimaddr);
  4476. slimmb = (MAILBOX_t *) & slimword0;
  4477. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4478. && slimmb->mbxStatus) {
  4479. psli->sli_flag &=
  4480. ~LPFC_SLI_ACTIVE;
  4481. word0 = slimword0;
  4482. }
  4483. }
  4484. } else {
  4485. /* First copy command data */
  4486. word0 = readl(phba->MBslimaddr);
  4487. }
  4488. /* Read the HBA Host Attention Register */
  4489. ha_copy = readl(phba->HAregaddr);
  4490. }
  4491. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4492. /* copy results back to user */
  4493. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4494. } else {
  4495. /* First copy command data */
  4496. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4497. MAILBOX_CMD_SIZE);
  4498. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4499. pmbox->context2) {
  4500. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4501. phba->MBslimaddr + DMP_RSP_OFFSET,
  4502. mb->un.varDmp.word_cnt);
  4503. }
  4504. }
  4505. writel(HA_MBATT, phba->HAregaddr);
  4506. readl(phba->HAregaddr); /* flush */
  4507. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4508. status = mb->mbxStatus;
  4509. }
  4510. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4511. return status;
  4512. out_not_finished:
  4513. if (processing_queue) {
  4514. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4515. lpfc_mbox_cmpl_put(phba, pmbox);
  4516. }
  4517. return MBX_NOT_FINISHED;
  4518. }
  4519. /**
  4520. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4521. * @phba: Pointer to HBA context object.
  4522. *
  4523. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4524. * the driver internal pending mailbox queue. It will then try to wait out the
  4525. * possible outstanding mailbox command before return.
  4526. *
  4527. * Returns:
  4528. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4529. * the outstanding mailbox command timed out.
  4530. **/
  4531. static int
  4532. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4533. {
  4534. struct lpfc_sli *psli = &phba->sli;
  4535. uint8_t actcmd = MBX_HEARTBEAT;
  4536. int rc = 0;
  4537. unsigned long timeout;
  4538. /* Mark the asynchronous mailbox command posting as blocked */
  4539. spin_lock_irq(&phba->hbalock);
  4540. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4541. if (phba->sli.mbox_active)
  4542. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4543. spin_unlock_irq(&phba->hbalock);
  4544. /* Determine how long we might wait for the active mailbox
  4545. * command to be gracefully completed by firmware.
  4546. */
  4547. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4548. jiffies;
  4549. /* Wait for the outstnading mailbox command to complete */
  4550. while (phba->sli.mbox_active) {
  4551. /* Check active mailbox complete status every 2ms */
  4552. msleep(2);
  4553. if (time_after(jiffies, timeout)) {
  4554. /* Timeout, marked the outstanding cmd not complete */
  4555. rc = 1;
  4556. break;
  4557. }
  4558. }
  4559. /* Can not cleanly block async mailbox command, fails it */
  4560. if (rc) {
  4561. spin_lock_irq(&phba->hbalock);
  4562. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4563. spin_unlock_irq(&phba->hbalock);
  4564. }
  4565. return rc;
  4566. }
  4567. /**
  4568. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4569. * @phba: Pointer to HBA context object.
  4570. *
  4571. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4572. * commands from the driver internal pending mailbox queue. It makes sure
  4573. * that there is no outstanding mailbox command before resuming posting
  4574. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4575. * mailbox command, it will try to wait it out before resuming asynchronous
  4576. * mailbox command posting.
  4577. **/
  4578. static void
  4579. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4580. {
  4581. struct lpfc_sli *psli = &phba->sli;
  4582. spin_lock_irq(&phba->hbalock);
  4583. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4584. /* Asynchronous mailbox posting is not blocked, do nothing */
  4585. spin_unlock_irq(&phba->hbalock);
  4586. return;
  4587. }
  4588. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4589. * successful or timeout, after timing-out the outstanding mailbox
  4590. * command shall always be removed, so just unblock posting async
  4591. * mailbox command and resume
  4592. */
  4593. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4594. spin_unlock_irq(&phba->hbalock);
  4595. /* wake up worker thread to post asynchronlous mailbox command */
  4596. lpfc_worker_wake_up(phba);
  4597. }
  4598. /**
  4599. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4600. * @phba: Pointer to HBA context object.
  4601. * @mboxq: Pointer to mailbox object.
  4602. *
  4603. * The function posts a mailbox to the port. The mailbox is expected
  4604. * to be comletely filled in and ready for the port to operate on it.
  4605. * This routine executes a synchronous completion operation on the
  4606. * mailbox by polling for its completion.
  4607. *
  4608. * The caller must not be holding any locks when calling this routine.
  4609. *
  4610. * Returns:
  4611. * MBX_SUCCESS - mailbox posted successfully
  4612. * Any of the MBX error values.
  4613. **/
  4614. static int
  4615. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4616. {
  4617. int rc = MBX_SUCCESS;
  4618. unsigned long iflag;
  4619. uint32_t db_ready;
  4620. uint32_t mcqe_status;
  4621. uint32_t mbx_cmnd;
  4622. unsigned long timeout;
  4623. struct lpfc_sli *psli = &phba->sli;
  4624. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4625. struct lpfc_bmbx_create *mbox_rgn;
  4626. struct dma_address *dma_address;
  4627. struct lpfc_register bmbx_reg;
  4628. /*
  4629. * Only one mailbox can be active to the bootstrap mailbox region
  4630. * at a time and there is no queueing provided.
  4631. */
  4632. spin_lock_irqsave(&phba->hbalock, iflag);
  4633. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4634. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4635. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4636. "(%d):2532 Mailbox command x%x (x%x) "
  4637. "cannot issue Data: x%x x%x\n",
  4638. mboxq->vport ? mboxq->vport->vpi : 0,
  4639. mboxq->u.mb.mbxCommand,
  4640. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4641. psli->sli_flag, MBX_POLL);
  4642. return MBXERR_ERROR;
  4643. }
  4644. /* The server grabs the token and owns it until release */
  4645. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4646. phba->sli.mbox_active = mboxq;
  4647. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4648. /*
  4649. * Initialize the bootstrap memory region to avoid stale data areas
  4650. * in the mailbox post. Then copy the caller's mailbox contents to
  4651. * the bmbx mailbox region.
  4652. */
  4653. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4654. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4655. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4656. sizeof(struct lpfc_mqe));
  4657. /* Post the high mailbox dma address to the port and wait for ready. */
  4658. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4659. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4660. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4661. * 1000) + jiffies;
  4662. do {
  4663. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4664. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4665. if (!db_ready)
  4666. msleep(2);
  4667. if (time_after(jiffies, timeout)) {
  4668. rc = MBXERR_ERROR;
  4669. goto exit;
  4670. }
  4671. } while (!db_ready);
  4672. /* Post the low mailbox dma address to the port. */
  4673. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4674. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4675. * 1000) + jiffies;
  4676. do {
  4677. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4678. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4679. if (!db_ready)
  4680. msleep(2);
  4681. if (time_after(jiffies, timeout)) {
  4682. rc = MBXERR_ERROR;
  4683. goto exit;
  4684. }
  4685. } while (!db_ready);
  4686. /*
  4687. * Read the CQ to ensure the mailbox has completed.
  4688. * If so, update the mailbox status so that the upper layers
  4689. * can complete the request normally.
  4690. */
  4691. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4692. sizeof(struct lpfc_mqe));
  4693. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4694. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4695. sizeof(struct lpfc_mcqe));
  4696. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4697. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4698. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4699. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4700. rc = MBXERR_ERROR;
  4701. }
  4702. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4703. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4704. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4705. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4706. mboxq->vport ? mboxq->vport->vpi : 0,
  4707. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4708. bf_get(lpfc_mqe_status, mb),
  4709. mb->un.mb_words[0], mb->un.mb_words[1],
  4710. mb->un.mb_words[2], mb->un.mb_words[3],
  4711. mb->un.mb_words[4], mb->un.mb_words[5],
  4712. mb->un.mb_words[6], mb->un.mb_words[7],
  4713. mb->un.mb_words[8], mb->un.mb_words[9],
  4714. mb->un.mb_words[10], mb->un.mb_words[11],
  4715. mb->un.mb_words[12], mboxq->mcqe.word0,
  4716. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4717. mboxq->mcqe.trailer);
  4718. exit:
  4719. /* We are holding the token, no needed for lock when release */
  4720. spin_lock_irqsave(&phba->hbalock, iflag);
  4721. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4722. phba->sli.mbox_active = NULL;
  4723. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4724. return rc;
  4725. }
  4726. /**
  4727. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4728. * @phba: Pointer to HBA context object.
  4729. * @pmbox: Pointer to mailbox object.
  4730. * @flag: Flag indicating how the mailbox need to be processed.
  4731. *
  4732. * This function is called by discovery code and HBA management code to submit
  4733. * a mailbox command to firmware with SLI-4 interface spec.
  4734. *
  4735. * Return codes the caller owns the mailbox command after the return of the
  4736. * function.
  4737. **/
  4738. static int
  4739. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4740. uint32_t flag)
  4741. {
  4742. struct lpfc_sli *psli = &phba->sli;
  4743. unsigned long iflags;
  4744. int rc;
  4745. rc = lpfc_mbox_dev_check(phba);
  4746. if (unlikely(rc)) {
  4747. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4748. "(%d):2544 Mailbox command x%x (x%x) "
  4749. "cannot issue Data: x%x x%x\n",
  4750. mboxq->vport ? mboxq->vport->vpi : 0,
  4751. mboxq->u.mb.mbxCommand,
  4752. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4753. psli->sli_flag, flag);
  4754. goto out_not_finished;
  4755. }
  4756. /* Detect polling mode and jump to a handler */
  4757. if (!phba->sli4_hba.intr_enable) {
  4758. if (flag == MBX_POLL)
  4759. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4760. else
  4761. rc = -EIO;
  4762. if (rc != MBX_SUCCESS)
  4763. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4764. "(%d):2541 Mailbox command x%x "
  4765. "(x%x) cannot issue Data: x%x x%x\n",
  4766. mboxq->vport ? mboxq->vport->vpi : 0,
  4767. mboxq->u.mb.mbxCommand,
  4768. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4769. psli->sli_flag, flag);
  4770. return rc;
  4771. } else if (flag == MBX_POLL) {
  4772. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4773. "(%d):2542 Try to issue mailbox command "
  4774. "x%x (x%x) synchronously ahead of async"
  4775. "mailbox command queue: x%x x%x\n",
  4776. mboxq->vport ? mboxq->vport->vpi : 0,
  4777. mboxq->u.mb.mbxCommand,
  4778. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4779. psli->sli_flag, flag);
  4780. /* Try to block the asynchronous mailbox posting */
  4781. rc = lpfc_sli4_async_mbox_block(phba);
  4782. if (!rc) {
  4783. /* Successfully blocked, now issue sync mbox cmd */
  4784. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4785. if (rc != MBX_SUCCESS)
  4786. lpfc_printf_log(phba, KERN_ERR,
  4787. LOG_MBOX | LOG_SLI,
  4788. "(%d):2597 Mailbox command "
  4789. "x%x (x%x) cannot issue "
  4790. "Data: x%x x%x\n",
  4791. mboxq->vport ?
  4792. mboxq->vport->vpi : 0,
  4793. mboxq->u.mb.mbxCommand,
  4794. lpfc_sli4_mbox_opcode_get(phba,
  4795. mboxq),
  4796. psli->sli_flag, flag);
  4797. /* Unblock the async mailbox posting afterward */
  4798. lpfc_sli4_async_mbox_unblock(phba);
  4799. }
  4800. return rc;
  4801. }
  4802. /* Now, interrupt mode asynchrous mailbox command */
  4803. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4804. if (rc) {
  4805. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4806. "(%d):2543 Mailbox command x%x (x%x) "
  4807. "cannot issue Data: x%x x%x\n",
  4808. mboxq->vport ? mboxq->vport->vpi : 0,
  4809. mboxq->u.mb.mbxCommand,
  4810. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4811. psli->sli_flag, flag);
  4812. goto out_not_finished;
  4813. }
  4814. /* Put the mailbox command to the driver internal FIFO */
  4815. psli->slistat.mbox_busy++;
  4816. spin_lock_irqsave(&phba->hbalock, iflags);
  4817. lpfc_mbox_put(phba, mboxq);
  4818. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4819. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4820. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4821. "x%x (x%x) x%x x%x x%x\n",
  4822. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4823. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4824. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4825. phba->pport->port_state,
  4826. psli->sli_flag, MBX_NOWAIT);
  4827. /* Wake up worker thread to transport mailbox command from head */
  4828. lpfc_worker_wake_up(phba);
  4829. return MBX_BUSY;
  4830. out_not_finished:
  4831. return MBX_NOT_FINISHED;
  4832. }
  4833. /**
  4834. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4835. * @phba: Pointer to HBA context object.
  4836. *
  4837. * This function is called by worker thread to send a mailbox command to
  4838. * SLI4 HBA firmware.
  4839. *
  4840. **/
  4841. int
  4842. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4843. {
  4844. struct lpfc_sli *psli = &phba->sli;
  4845. LPFC_MBOXQ_t *mboxq;
  4846. int rc = MBX_SUCCESS;
  4847. unsigned long iflags;
  4848. struct lpfc_mqe *mqe;
  4849. uint32_t mbx_cmnd;
  4850. /* Check interrupt mode before post async mailbox command */
  4851. if (unlikely(!phba->sli4_hba.intr_enable))
  4852. return MBX_NOT_FINISHED;
  4853. /* Check for mailbox command service token */
  4854. spin_lock_irqsave(&phba->hbalock, iflags);
  4855. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4856. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4857. return MBX_NOT_FINISHED;
  4858. }
  4859. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4860. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4861. return MBX_NOT_FINISHED;
  4862. }
  4863. if (unlikely(phba->sli.mbox_active)) {
  4864. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4865. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4866. "0384 There is pending active mailbox cmd\n");
  4867. return MBX_NOT_FINISHED;
  4868. }
  4869. /* Take the mailbox command service token */
  4870. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4871. /* Get the next mailbox command from head of queue */
  4872. mboxq = lpfc_mbox_get(phba);
  4873. /* If no more mailbox command waiting for post, we're done */
  4874. if (!mboxq) {
  4875. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4876. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4877. return MBX_SUCCESS;
  4878. }
  4879. phba->sli.mbox_active = mboxq;
  4880. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4881. /* Check device readiness for posting mailbox command */
  4882. rc = lpfc_mbox_dev_check(phba);
  4883. if (unlikely(rc))
  4884. /* Driver clean routine will clean up pending mailbox */
  4885. goto out_not_finished;
  4886. /* Prepare the mbox command to be posted */
  4887. mqe = &mboxq->u.mqe;
  4888. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4889. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4890. mod_timer(&psli->mbox_tmo, (jiffies +
  4891. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4892. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4893. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4894. "x%x x%x\n",
  4895. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4896. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4897. phba->pport->port_state, psli->sli_flag);
  4898. if (mbx_cmnd != MBX_HEARTBEAT) {
  4899. if (mboxq->vport) {
  4900. lpfc_debugfs_disc_trc(mboxq->vport,
  4901. LPFC_DISC_TRC_MBOX_VPORT,
  4902. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4903. mbx_cmnd, mqe->un.mb_words[0],
  4904. mqe->un.mb_words[1]);
  4905. } else {
  4906. lpfc_debugfs_disc_trc(phba->pport,
  4907. LPFC_DISC_TRC_MBOX,
  4908. "MBOX Send: cmd:x%x mb:x%x x%x",
  4909. mbx_cmnd, mqe->un.mb_words[0],
  4910. mqe->un.mb_words[1]);
  4911. }
  4912. }
  4913. psli->slistat.mbox_cmd++;
  4914. /* Post the mailbox command to the port */
  4915. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4916. if (rc != MBX_SUCCESS) {
  4917. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4918. "(%d):2533 Mailbox command x%x (x%x) "
  4919. "cannot issue Data: x%x x%x\n",
  4920. mboxq->vport ? mboxq->vport->vpi : 0,
  4921. mboxq->u.mb.mbxCommand,
  4922. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4923. psli->sli_flag, MBX_NOWAIT);
  4924. goto out_not_finished;
  4925. }
  4926. return rc;
  4927. out_not_finished:
  4928. spin_lock_irqsave(&phba->hbalock, iflags);
  4929. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4930. __lpfc_mbox_cmpl_put(phba, mboxq);
  4931. /* Release the token */
  4932. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4933. phba->sli.mbox_active = NULL;
  4934. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4935. return MBX_NOT_FINISHED;
  4936. }
  4937. /**
  4938. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4939. * @phba: Pointer to HBA context object.
  4940. * @pmbox: Pointer to mailbox object.
  4941. * @flag: Flag indicating how the mailbox need to be processed.
  4942. *
  4943. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4944. * the API jump table function pointer from the lpfc_hba struct.
  4945. *
  4946. * Return codes the caller owns the mailbox command after the return of the
  4947. * function.
  4948. **/
  4949. int
  4950. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4951. {
  4952. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4953. }
  4954. /**
  4955. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4956. * @phba: The hba struct for which this call is being executed.
  4957. * @dev_grp: The HBA PCI-Device group number.
  4958. *
  4959. * This routine sets up the mbox interface API function jump table in @phba
  4960. * struct.
  4961. * Returns: 0 - success, -ENODEV - failure.
  4962. **/
  4963. int
  4964. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4965. {
  4966. switch (dev_grp) {
  4967. case LPFC_PCI_DEV_LP:
  4968. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  4969. phba->lpfc_sli_handle_slow_ring_event =
  4970. lpfc_sli_handle_slow_ring_event_s3;
  4971. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  4972. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  4973. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  4974. break;
  4975. case LPFC_PCI_DEV_OC:
  4976. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  4977. phba->lpfc_sli_handle_slow_ring_event =
  4978. lpfc_sli_handle_slow_ring_event_s4;
  4979. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  4980. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  4981. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  4982. break;
  4983. default:
  4984. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4985. "1420 Invalid HBA PCI-device group: 0x%x\n",
  4986. dev_grp);
  4987. return -ENODEV;
  4988. break;
  4989. }
  4990. return 0;
  4991. }
  4992. /**
  4993. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  4994. * @phba: Pointer to HBA context object.
  4995. * @pring: Pointer to driver SLI ring object.
  4996. * @piocb: Pointer to address of newly added command iocb.
  4997. *
  4998. * This function is called with hbalock held to add a command
  4999. * iocb to the txq when SLI layer cannot submit the command iocb
  5000. * to the ring.
  5001. **/
  5002. static void
  5003. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5004. struct lpfc_iocbq *piocb)
  5005. {
  5006. /* Insert the caller's iocb in the txq tail for later processing. */
  5007. list_add_tail(&piocb->list, &pring->txq);
  5008. pring->txq_cnt++;
  5009. }
  5010. /**
  5011. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5012. * @phba: Pointer to HBA context object.
  5013. * @pring: Pointer to driver SLI ring object.
  5014. * @piocb: Pointer to address of newly added command iocb.
  5015. *
  5016. * This function is called with hbalock held before a new
  5017. * iocb is submitted to the firmware. This function checks
  5018. * txq to flush the iocbs in txq to Firmware before
  5019. * submitting new iocbs to the Firmware.
  5020. * If there are iocbs in the txq which need to be submitted
  5021. * to firmware, lpfc_sli_next_iocb returns the first element
  5022. * of the txq after dequeuing it from txq.
  5023. * If there is no iocb in the txq then the function will return
  5024. * *piocb and *piocb is set to NULL. Caller needs to check
  5025. * *piocb to find if there are more commands in the txq.
  5026. **/
  5027. static struct lpfc_iocbq *
  5028. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5029. struct lpfc_iocbq **piocb)
  5030. {
  5031. struct lpfc_iocbq * nextiocb;
  5032. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5033. if (!nextiocb) {
  5034. nextiocb = *piocb;
  5035. *piocb = NULL;
  5036. }
  5037. return nextiocb;
  5038. }
  5039. /**
  5040. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5041. * @phba: Pointer to HBA context object.
  5042. * @ring_number: SLI ring number to issue iocb on.
  5043. * @piocb: Pointer to command iocb.
  5044. * @flag: Flag indicating if this command can be put into txq.
  5045. *
  5046. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5047. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5048. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5049. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5050. * this function allows only iocbs for posting buffers. This function finds
  5051. * next available slot in the command ring and posts the command to the
  5052. * available slot and writes the port attention register to request HBA start
  5053. * processing new iocb. If there is no slot available in the ring and
  5054. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5055. * the function returns IOCB_BUSY.
  5056. *
  5057. * This function is called with hbalock held. The function will return success
  5058. * after it successfully submit the iocb to firmware or after adding to the
  5059. * txq.
  5060. **/
  5061. static int
  5062. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5063. struct lpfc_iocbq *piocb, uint32_t flag)
  5064. {
  5065. struct lpfc_iocbq *nextiocb;
  5066. IOCB_t *iocb;
  5067. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5068. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5069. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5070. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5071. lpfc_printf_log(phba, KERN_ERR,
  5072. LOG_SLI | LOG_VPORT,
  5073. "1807 IOCB x%x failed. No vport\n",
  5074. piocb->iocb.ulpCommand);
  5075. dump_stack();
  5076. return IOCB_ERROR;
  5077. }
  5078. /* If the PCI channel is in offline state, do not post iocbs. */
  5079. if (unlikely(pci_channel_offline(phba->pcidev)))
  5080. return IOCB_ERROR;
  5081. /* If HBA has a deferred error attention, fail the iocb. */
  5082. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5083. return IOCB_ERROR;
  5084. /*
  5085. * We should never get an IOCB if we are in a < LINK_DOWN state
  5086. */
  5087. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5088. return IOCB_ERROR;
  5089. /*
  5090. * Check to see if we are blocking IOCB processing because of a
  5091. * outstanding event.
  5092. */
  5093. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5094. goto iocb_busy;
  5095. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5096. /*
  5097. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5098. * can be issued if the link is not up.
  5099. */
  5100. switch (piocb->iocb.ulpCommand) {
  5101. case CMD_GEN_REQUEST64_CR:
  5102. case CMD_GEN_REQUEST64_CX:
  5103. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5104. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5105. FC_RCTL_DD_UNSOL_CMD) ||
  5106. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5107. MENLO_TRANSPORT_TYPE))
  5108. goto iocb_busy;
  5109. break;
  5110. case CMD_QUE_RING_BUF_CN:
  5111. case CMD_QUE_RING_BUF64_CN:
  5112. /*
  5113. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5114. * completion, iocb_cmpl MUST be 0.
  5115. */
  5116. if (piocb->iocb_cmpl)
  5117. piocb->iocb_cmpl = NULL;
  5118. /*FALLTHROUGH*/
  5119. case CMD_CREATE_XRI_CR:
  5120. case CMD_CLOSE_XRI_CN:
  5121. case CMD_CLOSE_XRI_CX:
  5122. break;
  5123. default:
  5124. goto iocb_busy;
  5125. }
  5126. /*
  5127. * For FCP commands, we must be in a state where we can process link
  5128. * attention events.
  5129. */
  5130. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5131. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5132. goto iocb_busy;
  5133. }
  5134. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5135. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5136. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5137. if (iocb)
  5138. lpfc_sli_update_ring(phba, pring);
  5139. else
  5140. lpfc_sli_update_full_ring(phba, pring);
  5141. if (!piocb)
  5142. return IOCB_SUCCESS;
  5143. goto out_busy;
  5144. iocb_busy:
  5145. pring->stats.iocb_cmd_delay++;
  5146. out_busy:
  5147. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5148. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5149. return IOCB_SUCCESS;
  5150. }
  5151. return IOCB_BUSY;
  5152. }
  5153. /**
  5154. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5155. * @phba: Pointer to HBA context object.
  5156. * @piocb: Pointer to command iocb.
  5157. * @sglq: Pointer to the scatter gather queue object.
  5158. *
  5159. * This routine converts the bpl or bde that is in the IOCB
  5160. * to a sgl list for the sli4 hardware. The physical address
  5161. * of the bpl/bde is converted back to a virtual address.
  5162. * If the IOCB contains a BPL then the list of BDE's is
  5163. * converted to sli4_sge's. If the IOCB contains a single
  5164. * BDE then it is converted to a single sli_sge.
  5165. * The IOCB is still in cpu endianess so the contents of
  5166. * the bpl can be used without byte swapping.
  5167. *
  5168. * Returns valid XRI = Success, NO_XRI = Failure.
  5169. **/
  5170. static uint16_t
  5171. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5172. struct lpfc_sglq *sglq)
  5173. {
  5174. uint16_t xritag = NO_XRI;
  5175. struct ulp_bde64 *bpl = NULL;
  5176. struct ulp_bde64 bde;
  5177. struct sli4_sge *sgl = NULL;
  5178. IOCB_t *icmd;
  5179. int numBdes = 0;
  5180. int i = 0;
  5181. if (!piocbq || !sglq)
  5182. return xritag;
  5183. sgl = (struct sli4_sge *)sglq->sgl;
  5184. icmd = &piocbq->iocb;
  5185. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5186. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5187. sizeof(struct ulp_bde64);
  5188. /* The addrHigh and addrLow fields within the IOCB
  5189. * have not been byteswapped yet so there is no
  5190. * need to swap them back.
  5191. */
  5192. bpl = (struct ulp_bde64 *)
  5193. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5194. if (!bpl)
  5195. return xritag;
  5196. for (i = 0; i < numBdes; i++) {
  5197. /* Should already be byte swapped. */
  5198. sgl->addr_hi = bpl->addrHigh;
  5199. sgl->addr_lo = bpl->addrLow;
  5200. if ((i+1) == numBdes)
  5201. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5202. else
  5203. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5204. sgl->word2 = cpu_to_le32(sgl->word2);
  5205. /* swap the size field back to the cpu so we
  5206. * can assign it to the sgl.
  5207. */
  5208. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5209. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5210. bpl++;
  5211. sgl++;
  5212. }
  5213. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5214. /* The addrHigh and addrLow fields of the BDE have not
  5215. * been byteswapped yet so they need to be swapped
  5216. * before putting them in the sgl.
  5217. */
  5218. sgl->addr_hi =
  5219. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5220. sgl->addr_lo =
  5221. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5222. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5223. sgl->word2 = cpu_to_le32(sgl->word2);
  5224. sgl->sge_len =
  5225. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5226. }
  5227. return sglq->sli4_xritag;
  5228. }
  5229. /**
  5230. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5231. * @phba: Pointer to HBA context object.
  5232. *
  5233. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5234. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5235. * held.
  5236. *
  5237. * Return: index into SLI4 fast-path FCP queue index.
  5238. **/
  5239. static uint32_t
  5240. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5241. {
  5242. ++phba->fcp_qidx;
  5243. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5244. phba->fcp_qidx = 0;
  5245. return phba->fcp_qidx;
  5246. }
  5247. /**
  5248. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5249. * @phba: Pointer to HBA context object.
  5250. * @piocb: Pointer to command iocb.
  5251. * @wqe: Pointer to the work queue entry.
  5252. *
  5253. * This routine converts the iocb command to its Work Queue Entry
  5254. * equivalent. The wqe pointer should not have any fields set when
  5255. * this routine is called because it will memcpy over them.
  5256. * This routine does not set the CQ_ID or the WQEC bits in the
  5257. * wqe.
  5258. *
  5259. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5260. **/
  5261. static int
  5262. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5263. union lpfc_wqe *wqe)
  5264. {
  5265. uint32_t xmit_len = 0, total_len = 0;
  5266. uint8_t ct = 0;
  5267. uint32_t fip;
  5268. uint32_t abort_tag;
  5269. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5270. uint8_t cmnd;
  5271. uint16_t xritag;
  5272. struct ulp_bde64 *bpl = NULL;
  5273. uint32_t els_id = ELS_ID_DEFAULT;
  5274. int numBdes, i;
  5275. struct ulp_bde64 bde;
  5276. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5277. /* The fcp commands will set command type */
  5278. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5279. command_type = FCP_COMMAND;
  5280. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5281. command_type = ELS_COMMAND_FIP;
  5282. else
  5283. command_type = ELS_COMMAND_NON_FIP;
  5284. /* Some of the fields are in the right position already */
  5285. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5286. abort_tag = (uint32_t) iocbq->iotag;
  5287. xritag = iocbq->sli4_xritag;
  5288. wqe->words[7] = 0; /* The ct field has moved so reset */
  5289. /* words0-2 bpl convert bde */
  5290. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5291. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5292. sizeof(struct ulp_bde64);
  5293. bpl = (struct ulp_bde64 *)
  5294. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5295. if (!bpl)
  5296. return IOCB_ERROR;
  5297. /* Should already be byte swapped. */
  5298. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5299. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5300. /* swap the size field back to the cpu so we
  5301. * can assign it to the sgl.
  5302. */
  5303. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5304. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5305. total_len = 0;
  5306. for (i = 0; i < numBdes; i++) {
  5307. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5308. total_len += bde.tus.f.bdeSize;
  5309. }
  5310. } else
  5311. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5312. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5313. cmnd = iocbq->iocb.ulpCommand;
  5314. switch (iocbq->iocb.ulpCommand) {
  5315. case CMD_ELS_REQUEST64_CR:
  5316. if (!iocbq->iocb.ulpLe) {
  5317. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5318. "2007 Only Limited Edition cmd Format"
  5319. " supported 0x%x\n",
  5320. iocbq->iocb.ulpCommand);
  5321. return IOCB_ERROR;
  5322. }
  5323. wqe->els_req.payload_len = xmit_len;
  5324. /* Els_reguest64 has a TMO */
  5325. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5326. iocbq->iocb.ulpTimeout);
  5327. /* Need a VF for word 4 set the vf bit*/
  5328. bf_set(els_req64_vf, &wqe->els_req, 0);
  5329. /* And a VFID for word 12 */
  5330. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5331. /*
  5332. * Set ct field to 3, indicates that the context_tag field
  5333. * contains the FCFI and remote N_Port_ID is
  5334. * in word 5.
  5335. */
  5336. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5337. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5338. iocbq->iocb.ulpContext);
  5339. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5340. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5341. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5342. if (command_type == ELS_COMMAND_FIP) {
  5343. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5344. >> LPFC_FIP_ELS_ID_SHIFT);
  5345. }
  5346. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5347. break;
  5348. case CMD_XMIT_SEQUENCE64_CX:
  5349. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5350. iocbq->iocb.un.ulpWord[3]);
  5351. wqe->generic.word3 = 0;
  5352. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5353. /* The entire sequence is transmitted for this IOCB */
  5354. xmit_len = total_len;
  5355. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5356. case CMD_XMIT_SEQUENCE64_CR:
  5357. /* word3 iocb=io_tag32 wqe=payload_offset */
  5358. /* payload offset used for multilpe outstanding
  5359. * sequences on the same exchange
  5360. */
  5361. wqe->words[3] = 0;
  5362. /* word4 relative_offset memcpy */
  5363. /* word5 r_ctl/df_ctl memcpy */
  5364. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5365. wqe->xmit_sequence.xmit_len = xmit_len;
  5366. command_type = OTHER_COMMAND;
  5367. break;
  5368. case CMD_XMIT_BCAST64_CN:
  5369. /* word3 iocb=iotag32 wqe=payload_len */
  5370. wqe->words[3] = 0; /* no definition for this in wqe */
  5371. /* word4 iocb=rsvd wqe=rsvd */
  5372. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5373. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5374. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5375. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5376. break;
  5377. case CMD_FCP_IWRITE64_CR:
  5378. command_type = FCP_COMMAND_DATA_OUT;
  5379. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5380. * confusing.
  5381. * word3 is payload_len: byte offset to the sgl entry for the
  5382. * fcp_command.
  5383. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5384. * word5 is initial xfer len 0 = wait for xfer-ready
  5385. */
  5386. /* Always wait for xfer-ready before sending data */
  5387. wqe->fcp_iwrite.initial_xfer_len = 0;
  5388. /* word 4 (xfer length) should have been set on the memcpy */
  5389. /* allow write to fall through to read */
  5390. case CMD_FCP_IREAD64_CR:
  5391. /* FCP_CMD is always the 1st sgl entry */
  5392. wqe->fcp_iread.payload_len =
  5393. xmit_len + sizeof(struct fcp_rsp);
  5394. /* word 4 (xfer length) should have been set on the memcpy */
  5395. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5396. iocbq->iocb.ulpFCP2Rcvy);
  5397. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5398. /* The XC bit and the XS bit are similar. The driver never
  5399. * tracked whether or not the exchange was previouslly open.
  5400. * XC = Exchange create, 0 is create. 1 is already open.
  5401. * XS = link cmd: 1 do not close the exchange after command.
  5402. * XS = 0 close exchange when command completes.
  5403. * The only time we would not set the XC bit is when the XS bit
  5404. * is set and we are sending our 2nd or greater command on
  5405. * this exchange.
  5406. */
  5407. /* Always open the exchange */
  5408. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5409. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5410. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5411. break;
  5412. case CMD_FCP_ICMND64_CR:
  5413. /* Always open the exchange */
  5414. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5415. wqe->words[4] = 0;
  5416. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5417. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5418. break;
  5419. case CMD_GEN_REQUEST64_CR:
  5420. /* word3 command length is described as byte offset to the
  5421. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5422. * sgl[0] = cmnd
  5423. * sgl[1] = rsp.
  5424. *
  5425. */
  5426. wqe->gen_req.command_len = xmit_len;
  5427. /* Word4 parameter copied in the memcpy */
  5428. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5429. /* word6 context tag copied in memcpy */
  5430. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5431. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5432. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5433. "2015 Invalid CT %x command 0x%x\n",
  5434. ct, iocbq->iocb.ulpCommand);
  5435. return IOCB_ERROR;
  5436. }
  5437. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5438. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5439. iocbq->iocb.ulpTimeout);
  5440. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5441. command_type = OTHER_COMMAND;
  5442. break;
  5443. case CMD_XMIT_ELS_RSP64_CX:
  5444. /* words0-2 BDE memcpy */
  5445. /* word3 iocb=iotag32 wqe=rsvd */
  5446. wqe->words[3] = 0;
  5447. /* word4 iocb=did wge=rsvd. */
  5448. wqe->words[4] = 0;
  5449. /* word5 iocb=rsvd wge=did */
  5450. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5451. iocbq->iocb.un.elsreq64.remoteID);
  5452. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5453. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5454. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5455. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5456. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5457. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5458. iocbq->vport->vpi + phba->vpi_base);
  5459. command_type = OTHER_COMMAND;
  5460. break;
  5461. case CMD_CLOSE_XRI_CN:
  5462. case CMD_ABORT_XRI_CN:
  5463. case CMD_ABORT_XRI_CX:
  5464. /* words 0-2 memcpy should be 0 rserved */
  5465. /* port will send abts */
  5466. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5467. /*
  5468. * The link is down so the fw does not need to send abts
  5469. * on the wire.
  5470. */
  5471. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5472. else
  5473. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5474. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5475. wqe->words[5] = 0;
  5476. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5477. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5478. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5479. /*
  5480. * The abort handler will send us CMD_ABORT_XRI_CN or
  5481. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5482. */
  5483. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5484. cmnd = CMD_ABORT_XRI_CX;
  5485. command_type = OTHER_COMMAND;
  5486. xritag = 0;
  5487. break;
  5488. case CMD_XMIT_BLS_RSP64_CX:
  5489. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5490. * we re-construct this WQE here based on information in
  5491. * iocbq from scratch.
  5492. */
  5493. memset(wqe, 0, sizeof(union lpfc_wqe));
  5494. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5495. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5496. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5497. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5498. LPFC_ABTS_UNSOL_INT) {
  5499. /* ABTS sent by initiator to CT exchange, the
  5500. * RX_ID field will be filled with the newly
  5501. * allocated responder XRI.
  5502. */
  5503. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5504. iocbq->sli4_xritag);
  5505. } else {
  5506. /* ABTS sent by responder to CT exchange, the
  5507. * RX_ID field will be filled with the responder
  5508. * RX_ID from ABTS.
  5509. */
  5510. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5511. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5512. }
  5513. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5514. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5515. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5516. iocbq->iocb.ulpContext);
  5517. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5518. command_type = OTHER_COMMAND;
  5519. break;
  5520. case CMD_XRI_ABORTED_CX:
  5521. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5522. /* words0-2 are all 0's no bde */
  5523. /* word3 and word4 are rsvrd */
  5524. wqe->words[3] = 0;
  5525. wqe->words[4] = 0;
  5526. /* word5 iocb=rsvd wge=did */
  5527. /* There is no remote port id in the IOCB? */
  5528. /* Let this fall through and fail */
  5529. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5530. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5531. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5532. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5533. default:
  5534. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5535. "2014 Invalid command 0x%x\n",
  5536. iocbq->iocb.ulpCommand);
  5537. return IOCB_ERROR;
  5538. break;
  5539. }
  5540. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5541. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5542. wqe->generic.abort_tag = abort_tag;
  5543. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5544. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5545. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5546. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5547. return 0;
  5548. }
  5549. /**
  5550. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5551. * @phba: Pointer to HBA context object.
  5552. * @ring_number: SLI ring number to issue iocb on.
  5553. * @piocb: Pointer to command iocb.
  5554. * @flag: Flag indicating if this command can be put into txq.
  5555. *
  5556. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5557. * an iocb command to an HBA with SLI-4 interface spec.
  5558. *
  5559. * This function is called with hbalock held. The function will return success
  5560. * after it successfully submit the iocb to firmware or after adding to the
  5561. * txq.
  5562. **/
  5563. static int
  5564. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5565. struct lpfc_iocbq *piocb, uint32_t flag)
  5566. {
  5567. struct lpfc_sglq *sglq;
  5568. uint16_t xritag;
  5569. union lpfc_wqe wqe;
  5570. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5571. if (piocb->sli4_xritag == NO_XRI) {
  5572. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5573. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5574. sglq = NULL;
  5575. else {
  5576. sglq = __lpfc_sli_get_sglq(phba);
  5577. if (!sglq)
  5578. return IOCB_ERROR;
  5579. piocb->sli4_xritag = sglq->sli4_xritag;
  5580. }
  5581. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5582. sglq = NULL; /* These IO's already have an XRI and
  5583. * a mapped sgl.
  5584. */
  5585. } else {
  5586. /* This is a continuation of a commandi,(CX) so this
  5587. * sglq is on the active list
  5588. */
  5589. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5590. if (!sglq)
  5591. return IOCB_ERROR;
  5592. }
  5593. if (sglq) {
  5594. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5595. if (xritag != sglq->sli4_xritag)
  5596. return IOCB_ERROR;
  5597. }
  5598. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5599. return IOCB_ERROR;
  5600. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5601. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5602. /*
  5603. * For FCP command IOCB, get a new WQ index to distribute
  5604. * WQE across the WQsr. On the other hand, for abort IOCB,
  5605. * it carries the same WQ index to the original command
  5606. * IOCB.
  5607. */
  5608. if (piocb->iocb_flag & LPFC_IO_FCP)
  5609. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5610. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5611. &wqe))
  5612. return IOCB_ERROR;
  5613. } else {
  5614. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5615. return IOCB_ERROR;
  5616. }
  5617. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5618. return 0;
  5619. }
  5620. /**
  5621. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5622. *
  5623. * This routine wraps the actual lockless version for issusing IOCB function
  5624. * pointer from the lpfc_hba struct.
  5625. *
  5626. * Return codes:
  5627. * IOCB_ERROR - Error
  5628. * IOCB_SUCCESS - Success
  5629. * IOCB_BUSY - Busy
  5630. **/
  5631. static inline int
  5632. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5633. struct lpfc_iocbq *piocb, uint32_t flag)
  5634. {
  5635. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5636. }
  5637. /**
  5638. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5639. * @phba: The hba struct for which this call is being executed.
  5640. * @dev_grp: The HBA PCI-Device group number.
  5641. *
  5642. * This routine sets up the SLI interface API function jump table in @phba
  5643. * struct.
  5644. * Returns: 0 - success, -ENODEV - failure.
  5645. **/
  5646. int
  5647. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5648. {
  5649. switch (dev_grp) {
  5650. case LPFC_PCI_DEV_LP:
  5651. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5652. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5653. break;
  5654. case LPFC_PCI_DEV_OC:
  5655. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5656. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5657. break;
  5658. default:
  5659. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5660. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5661. dev_grp);
  5662. return -ENODEV;
  5663. break;
  5664. }
  5665. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5666. return 0;
  5667. }
  5668. /**
  5669. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5670. * @phba: Pointer to HBA context object.
  5671. * @pring: Pointer to driver SLI ring object.
  5672. * @piocb: Pointer to command iocb.
  5673. * @flag: Flag indicating if this command can be put into txq.
  5674. *
  5675. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5676. * function. This function gets the hbalock and calls
  5677. * __lpfc_sli_issue_iocb function and will return the error returned
  5678. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5679. * functions which do not hold hbalock.
  5680. **/
  5681. int
  5682. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5683. struct lpfc_iocbq *piocb, uint32_t flag)
  5684. {
  5685. unsigned long iflags;
  5686. int rc;
  5687. spin_lock_irqsave(&phba->hbalock, iflags);
  5688. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5689. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5690. return rc;
  5691. }
  5692. /**
  5693. * lpfc_extra_ring_setup - Extra ring setup function
  5694. * @phba: Pointer to HBA context object.
  5695. *
  5696. * This function is called while driver attaches with the
  5697. * HBA to setup the extra ring. The extra ring is used
  5698. * only when driver needs to support target mode functionality
  5699. * or IP over FC functionalities.
  5700. *
  5701. * This function is called with no lock held.
  5702. **/
  5703. static int
  5704. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5705. {
  5706. struct lpfc_sli *psli;
  5707. struct lpfc_sli_ring *pring;
  5708. psli = &phba->sli;
  5709. /* Adjust cmd/rsp ring iocb entries more evenly */
  5710. /* Take some away from the FCP ring */
  5711. pring = &psli->ring[psli->fcp_ring];
  5712. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5713. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5714. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5715. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5716. /* and give them to the extra ring */
  5717. pring = &psli->ring[psli->extra_ring];
  5718. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5719. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5720. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5721. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5722. /* Setup default profile for this ring */
  5723. pring->iotag_max = 4096;
  5724. pring->num_mask = 1;
  5725. pring->prt[0].profile = 0; /* Mask 0 */
  5726. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5727. pring->prt[0].type = phba->cfg_multi_ring_type;
  5728. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5729. return 0;
  5730. }
  5731. /**
  5732. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5733. * @phba: Pointer to HBA context object.
  5734. * @pring: Pointer to driver SLI ring object.
  5735. * @iocbq: Pointer to iocb object.
  5736. *
  5737. * This function is called by the slow ring event handler
  5738. * function when there is an ASYNC event iocb in the ring.
  5739. * This function is called with no lock held.
  5740. * Currently this function handles only temperature related
  5741. * ASYNC events. The function decodes the temperature sensor
  5742. * event message and posts events for the management applications.
  5743. **/
  5744. static void
  5745. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5746. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5747. {
  5748. IOCB_t *icmd;
  5749. uint16_t evt_code;
  5750. uint16_t temp;
  5751. struct temp_event temp_event_data;
  5752. struct Scsi_Host *shost;
  5753. uint32_t *iocb_w;
  5754. icmd = &iocbq->iocb;
  5755. evt_code = icmd->un.asyncstat.evt_code;
  5756. temp = icmd->ulpContext;
  5757. if ((evt_code != ASYNC_TEMP_WARN) &&
  5758. (evt_code != ASYNC_TEMP_SAFE)) {
  5759. iocb_w = (uint32_t *) icmd;
  5760. lpfc_printf_log(phba,
  5761. KERN_ERR,
  5762. LOG_SLI,
  5763. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5764. " evt_code 0x%x\n"
  5765. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5766. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5767. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5768. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5769. pring->ringno,
  5770. icmd->un.asyncstat.evt_code,
  5771. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5772. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5773. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5774. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5775. return;
  5776. }
  5777. temp_event_data.data = (uint32_t)temp;
  5778. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5779. if (evt_code == ASYNC_TEMP_WARN) {
  5780. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5781. lpfc_printf_log(phba,
  5782. KERN_ERR,
  5783. LOG_TEMP,
  5784. "0347 Adapter is very hot, please take "
  5785. "corrective action. temperature : %d Celsius\n",
  5786. temp);
  5787. }
  5788. if (evt_code == ASYNC_TEMP_SAFE) {
  5789. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5790. lpfc_printf_log(phba,
  5791. KERN_ERR,
  5792. LOG_TEMP,
  5793. "0340 Adapter temperature is OK now. "
  5794. "temperature : %d Celsius\n",
  5795. temp);
  5796. }
  5797. /* Send temperature change event to applications */
  5798. shost = lpfc_shost_from_vport(phba->pport);
  5799. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5800. sizeof(temp_event_data), (char *) &temp_event_data,
  5801. LPFC_NL_VENDOR_ID);
  5802. }
  5803. /**
  5804. * lpfc_sli_setup - SLI ring setup function
  5805. * @phba: Pointer to HBA context object.
  5806. *
  5807. * lpfc_sli_setup sets up rings of the SLI interface with
  5808. * number of iocbs per ring and iotags. This function is
  5809. * called while driver attach to the HBA and before the
  5810. * interrupts are enabled. So there is no need for locking.
  5811. *
  5812. * This function always returns 0.
  5813. **/
  5814. int
  5815. lpfc_sli_setup(struct lpfc_hba *phba)
  5816. {
  5817. int i, totiocbsize = 0;
  5818. struct lpfc_sli *psli = &phba->sli;
  5819. struct lpfc_sli_ring *pring;
  5820. psli->num_rings = MAX_CONFIGURED_RINGS;
  5821. psli->sli_flag = 0;
  5822. psli->fcp_ring = LPFC_FCP_RING;
  5823. psli->next_ring = LPFC_FCP_NEXT_RING;
  5824. psli->extra_ring = LPFC_EXTRA_RING;
  5825. psli->iocbq_lookup = NULL;
  5826. psli->iocbq_lookup_len = 0;
  5827. psli->last_iotag = 0;
  5828. for (i = 0; i < psli->num_rings; i++) {
  5829. pring = &psli->ring[i];
  5830. switch (i) {
  5831. case LPFC_FCP_RING: /* ring 0 - FCP */
  5832. /* numCiocb and numRiocb are used in config_port */
  5833. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5834. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5835. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5836. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5837. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5838. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5839. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5840. SLI3_IOCB_CMD_SIZE :
  5841. SLI2_IOCB_CMD_SIZE;
  5842. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5843. SLI3_IOCB_RSP_SIZE :
  5844. SLI2_IOCB_RSP_SIZE;
  5845. pring->iotag_ctr = 0;
  5846. pring->iotag_max =
  5847. (phba->cfg_hba_queue_depth * 2);
  5848. pring->fast_iotag = pring->iotag_max;
  5849. pring->num_mask = 0;
  5850. break;
  5851. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5852. /* numCiocb and numRiocb are used in config_port */
  5853. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5854. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5855. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5856. SLI3_IOCB_CMD_SIZE :
  5857. SLI2_IOCB_CMD_SIZE;
  5858. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5859. SLI3_IOCB_RSP_SIZE :
  5860. SLI2_IOCB_RSP_SIZE;
  5861. pring->iotag_max = phba->cfg_hba_queue_depth;
  5862. pring->num_mask = 0;
  5863. break;
  5864. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5865. /* numCiocb and numRiocb are used in config_port */
  5866. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5867. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5868. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5869. SLI3_IOCB_CMD_SIZE :
  5870. SLI2_IOCB_CMD_SIZE;
  5871. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5872. SLI3_IOCB_RSP_SIZE :
  5873. SLI2_IOCB_RSP_SIZE;
  5874. pring->fast_iotag = 0;
  5875. pring->iotag_ctr = 0;
  5876. pring->iotag_max = 4096;
  5877. pring->lpfc_sli_rcv_async_status =
  5878. lpfc_sli_async_event_handler;
  5879. pring->num_mask = LPFC_MAX_RING_MASK;
  5880. pring->prt[0].profile = 0; /* Mask 0 */
  5881. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5882. pring->prt[0].type = FC_TYPE_ELS;
  5883. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5884. lpfc_els_unsol_event;
  5885. pring->prt[1].profile = 0; /* Mask 1 */
  5886. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5887. pring->prt[1].type = FC_TYPE_ELS;
  5888. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5889. lpfc_els_unsol_event;
  5890. pring->prt[2].profile = 0; /* Mask 2 */
  5891. /* NameServer Inquiry */
  5892. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5893. /* NameServer */
  5894. pring->prt[2].type = FC_TYPE_CT;
  5895. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5896. lpfc_ct_unsol_event;
  5897. pring->prt[3].profile = 0; /* Mask 3 */
  5898. /* NameServer response */
  5899. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  5900. /* NameServer */
  5901. pring->prt[3].type = FC_TYPE_CT;
  5902. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5903. lpfc_ct_unsol_event;
  5904. /* abort unsolicited sequence */
  5905. pring->prt[4].profile = 0; /* Mask 4 */
  5906. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  5907. pring->prt[4].type = FC_TYPE_BLS;
  5908. pring->prt[4].lpfc_sli_rcv_unsol_event =
  5909. lpfc_sli4_ct_abort_unsol_event;
  5910. break;
  5911. }
  5912. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5913. (pring->numRiocb * pring->sizeRiocb);
  5914. }
  5915. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5916. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5917. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5918. "SLI2 SLIM Data: x%x x%lx\n",
  5919. phba->brd_no, totiocbsize,
  5920. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5921. }
  5922. if (phba->cfg_multi_ring_support == 2)
  5923. lpfc_extra_ring_setup(phba);
  5924. return 0;
  5925. }
  5926. /**
  5927. * lpfc_sli_queue_setup - Queue initialization function
  5928. * @phba: Pointer to HBA context object.
  5929. *
  5930. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5931. * ring. This function also initializes ring indices of each ring.
  5932. * This function is called during the initialization of the SLI
  5933. * interface of an HBA.
  5934. * This function is called with no lock held and always returns
  5935. * 1.
  5936. **/
  5937. int
  5938. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5939. {
  5940. struct lpfc_sli *psli;
  5941. struct lpfc_sli_ring *pring;
  5942. int i;
  5943. psli = &phba->sli;
  5944. spin_lock_irq(&phba->hbalock);
  5945. INIT_LIST_HEAD(&psli->mboxq);
  5946. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5947. /* Initialize list headers for txq and txcmplq as double linked lists */
  5948. for (i = 0; i < psli->num_rings; i++) {
  5949. pring = &psli->ring[i];
  5950. pring->ringno = i;
  5951. pring->next_cmdidx = 0;
  5952. pring->local_getidx = 0;
  5953. pring->cmdidx = 0;
  5954. INIT_LIST_HEAD(&pring->txq);
  5955. INIT_LIST_HEAD(&pring->txcmplq);
  5956. INIT_LIST_HEAD(&pring->iocb_continueq);
  5957. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5958. INIT_LIST_HEAD(&pring->postbufq);
  5959. }
  5960. spin_unlock_irq(&phba->hbalock);
  5961. return 1;
  5962. }
  5963. /**
  5964. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5965. * @phba: Pointer to HBA context object.
  5966. *
  5967. * This routine flushes the mailbox command subsystem. It will unconditionally
  5968. * flush all the mailbox commands in the three possible stages in the mailbox
  5969. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5970. * command; and completed mailbox command queue. It is caller's responsibility
  5971. * to make sure that the driver is in the proper state to flush the mailbox
  5972. * command sub-system. Namely, the posting of mailbox commands into the
  5973. * pending mailbox command queue from the various clients must be stopped;
  5974. * either the HBA is in a state that it will never works on the outstanding
  5975. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  5976. * mailbox command has been completed.
  5977. **/
  5978. static void
  5979. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  5980. {
  5981. LIST_HEAD(completions);
  5982. struct lpfc_sli *psli = &phba->sli;
  5983. LPFC_MBOXQ_t *pmb;
  5984. unsigned long iflag;
  5985. /* Flush all the mailbox commands in the mbox system */
  5986. spin_lock_irqsave(&phba->hbalock, iflag);
  5987. /* The pending mailbox command queue */
  5988. list_splice_init(&phba->sli.mboxq, &completions);
  5989. /* The outstanding active mailbox command */
  5990. if (psli->mbox_active) {
  5991. list_add_tail(&psli->mbox_active->list, &completions);
  5992. psli->mbox_active = NULL;
  5993. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5994. }
  5995. /* The completed mailbox command queue */
  5996. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  5997. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5998. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  5999. while (!list_empty(&completions)) {
  6000. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6001. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6002. if (pmb->mbox_cmpl)
  6003. pmb->mbox_cmpl(phba, pmb);
  6004. }
  6005. }
  6006. /**
  6007. * lpfc_sli_host_down - Vport cleanup function
  6008. * @vport: Pointer to virtual port object.
  6009. *
  6010. * lpfc_sli_host_down is called to clean up the resources
  6011. * associated with a vport before destroying virtual
  6012. * port data structures.
  6013. * This function does following operations:
  6014. * - Free discovery resources associated with this virtual
  6015. * port.
  6016. * - Free iocbs associated with this virtual port in
  6017. * the txq.
  6018. * - Send abort for all iocb commands associated with this
  6019. * vport in txcmplq.
  6020. *
  6021. * This function is called with no lock held and always returns 1.
  6022. **/
  6023. int
  6024. lpfc_sli_host_down(struct lpfc_vport *vport)
  6025. {
  6026. LIST_HEAD(completions);
  6027. struct lpfc_hba *phba = vport->phba;
  6028. struct lpfc_sli *psli = &phba->sli;
  6029. struct lpfc_sli_ring *pring;
  6030. struct lpfc_iocbq *iocb, *next_iocb;
  6031. int i;
  6032. unsigned long flags = 0;
  6033. uint16_t prev_pring_flag;
  6034. lpfc_cleanup_discovery_resources(vport);
  6035. spin_lock_irqsave(&phba->hbalock, flags);
  6036. for (i = 0; i < psli->num_rings; i++) {
  6037. pring = &psli->ring[i];
  6038. prev_pring_flag = pring->flag;
  6039. /* Only slow rings */
  6040. if (pring->ringno == LPFC_ELS_RING) {
  6041. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6042. /* Set the lpfc data pending flag */
  6043. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6044. }
  6045. /*
  6046. * Error everything on the txq since these iocbs have not been
  6047. * given to the FW yet.
  6048. */
  6049. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6050. if (iocb->vport != vport)
  6051. continue;
  6052. list_move_tail(&iocb->list, &completions);
  6053. pring->txq_cnt--;
  6054. }
  6055. /* Next issue ABTS for everything on the txcmplq */
  6056. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6057. list) {
  6058. if (iocb->vport != vport)
  6059. continue;
  6060. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6061. }
  6062. pring->flag = prev_pring_flag;
  6063. }
  6064. spin_unlock_irqrestore(&phba->hbalock, flags);
  6065. /* Cancel all the IOCBs from the completions list */
  6066. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6067. IOERR_SLI_DOWN);
  6068. return 1;
  6069. }
  6070. /**
  6071. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6072. * @phba: Pointer to HBA context object.
  6073. *
  6074. * This function cleans up all iocb, buffers, mailbox commands
  6075. * while shutting down the HBA. This function is called with no
  6076. * lock held and always returns 1.
  6077. * This function does the following to cleanup driver resources:
  6078. * - Free discovery resources for each virtual port
  6079. * - Cleanup any pending fabric iocbs
  6080. * - Iterate through the iocb txq and free each entry
  6081. * in the list.
  6082. * - Free up any buffer posted to the HBA
  6083. * - Free mailbox commands in the mailbox queue.
  6084. **/
  6085. int
  6086. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6087. {
  6088. LIST_HEAD(completions);
  6089. struct lpfc_sli *psli = &phba->sli;
  6090. struct lpfc_sli_ring *pring;
  6091. struct lpfc_dmabuf *buf_ptr;
  6092. unsigned long flags = 0;
  6093. int i;
  6094. /* Shutdown the mailbox command sub-system */
  6095. lpfc_sli_mbox_sys_shutdown(phba);
  6096. lpfc_hba_down_prep(phba);
  6097. lpfc_fabric_abort_hba(phba);
  6098. spin_lock_irqsave(&phba->hbalock, flags);
  6099. for (i = 0; i < psli->num_rings; i++) {
  6100. pring = &psli->ring[i];
  6101. /* Only slow rings */
  6102. if (pring->ringno == LPFC_ELS_RING) {
  6103. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6104. /* Set the lpfc data pending flag */
  6105. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6106. }
  6107. /*
  6108. * Error everything on the txq since these iocbs have not been
  6109. * given to the FW yet.
  6110. */
  6111. list_splice_init(&pring->txq, &completions);
  6112. pring->txq_cnt = 0;
  6113. }
  6114. spin_unlock_irqrestore(&phba->hbalock, flags);
  6115. /* Cancel all the IOCBs from the completions list */
  6116. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6117. IOERR_SLI_DOWN);
  6118. spin_lock_irqsave(&phba->hbalock, flags);
  6119. list_splice_init(&phba->elsbuf, &completions);
  6120. phba->elsbuf_cnt = 0;
  6121. phba->elsbuf_prev_cnt = 0;
  6122. spin_unlock_irqrestore(&phba->hbalock, flags);
  6123. while (!list_empty(&completions)) {
  6124. list_remove_head(&completions, buf_ptr,
  6125. struct lpfc_dmabuf, list);
  6126. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6127. kfree(buf_ptr);
  6128. }
  6129. /* Return any active mbox cmds */
  6130. del_timer_sync(&psli->mbox_tmo);
  6131. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6132. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6133. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6134. return 1;
  6135. }
  6136. /**
  6137. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6138. * @phba: Pointer to HBA context object.
  6139. *
  6140. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6141. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6142. * lock held and always returns 1.
  6143. *
  6144. * This function does the following to cleanup driver FCoE function resources:
  6145. * - Free discovery resources for each virtual port
  6146. * - Cleanup any pending fabric iocbs
  6147. * - Iterate through the iocb txq and free each entry in the list.
  6148. * - Free up any buffer posted to the HBA.
  6149. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6150. * - Free mailbox commands in the mailbox queue.
  6151. **/
  6152. int
  6153. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6154. {
  6155. /* Stop the SLI4 device port */
  6156. lpfc_stop_port(phba);
  6157. /* Tear down the queues in the HBA */
  6158. lpfc_sli4_queue_unset(phba);
  6159. /* unregister default FCFI from the HBA */
  6160. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6161. return 1;
  6162. }
  6163. /**
  6164. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6165. * @srcp: Source memory pointer.
  6166. * @destp: Destination memory pointer.
  6167. * @cnt: Number of words required to be copied.
  6168. *
  6169. * This function is used for copying data between driver memory
  6170. * and the SLI memory. This function also changes the endianness
  6171. * of each word if native endianness is different from SLI
  6172. * endianness. This function can be called with or without
  6173. * lock.
  6174. **/
  6175. void
  6176. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6177. {
  6178. uint32_t *src = srcp;
  6179. uint32_t *dest = destp;
  6180. uint32_t ldata;
  6181. int i;
  6182. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6183. ldata = *src;
  6184. ldata = le32_to_cpu(ldata);
  6185. *dest = ldata;
  6186. src++;
  6187. dest++;
  6188. }
  6189. }
  6190. /**
  6191. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6192. * @srcp: Source memory pointer.
  6193. * @destp: Destination memory pointer.
  6194. * @cnt: Number of words required to be copied.
  6195. *
  6196. * This function is used for copying data between a data structure
  6197. * with big endian representation to local endianness.
  6198. * This function can be called with or without lock.
  6199. **/
  6200. void
  6201. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6202. {
  6203. uint32_t *src = srcp;
  6204. uint32_t *dest = destp;
  6205. uint32_t ldata;
  6206. int i;
  6207. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6208. ldata = *src;
  6209. ldata = be32_to_cpu(ldata);
  6210. *dest = ldata;
  6211. src++;
  6212. dest++;
  6213. }
  6214. }
  6215. /**
  6216. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6217. * @phba: Pointer to HBA context object.
  6218. * @pring: Pointer to driver SLI ring object.
  6219. * @mp: Pointer to driver buffer object.
  6220. *
  6221. * This function is called with no lock held.
  6222. * It always return zero after adding the buffer to the postbufq
  6223. * buffer list.
  6224. **/
  6225. int
  6226. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6227. struct lpfc_dmabuf *mp)
  6228. {
  6229. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6230. later */
  6231. spin_lock_irq(&phba->hbalock);
  6232. list_add_tail(&mp->list, &pring->postbufq);
  6233. pring->postbufq_cnt++;
  6234. spin_unlock_irq(&phba->hbalock);
  6235. return 0;
  6236. }
  6237. /**
  6238. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6239. * @phba: Pointer to HBA context object.
  6240. *
  6241. * When HBQ is enabled, buffers are searched based on tags. This function
  6242. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6243. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6244. * does not conflict with tags of buffer posted for unsolicited events.
  6245. * The function returns the allocated tag. The function is called with
  6246. * no locks held.
  6247. **/
  6248. uint32_t
  6249. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6250. {
  6251. spin_lock_irq(&phba->hbalock);
  6252. phba->buffer_tag_count++;
  6253. /*
  6254. * Always set the QUE_BUFTAG_BIT to distiguish between
  6255. * a tag assigned by HBQ.
  6256. */
  6257. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6258. spin_unlock_irq(&phba->hbalock);
  6259. return phba->buffer_tag_count;
  6260. }
  6261. /**
  6262. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6263. * @phba: Pointer to HBA context object.
  6264. * @pring: Pointer to driver SLI ring object.
  6265. * @tag: Buffer tag.
  6266. *
  6267. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6268. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6269. * iocb is posted to the response ring with the tag of the buffer.
  6270. * This function searches the pring->postbufq list using the tag
  6271. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6272. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6273. * buffer is returned to the caller else NULL is returned.
  6274. * This function is called with no lock held.
  6275. **/
  6276. struct lpfc_dmabuf *
  6277. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6278. uint32_t tag)
  6279. {
  6280. struct lpfc_dmabuf *mp, *next_mp;
  6281. struct list_head *slp = &pring->postbufq;
  6282. /* Search postbufq, from the begining, looking for a match on tag */
  6283. spin_lock_irq(&phba->hbalock);
  6284. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6285. if (mp->buffer_tag == tag) {
  6286. list_del_init(&mp->list);
  6287. pring->postbufq_cnt--;
  6288. spin_unlock_irq(&phba->hbalock);
  6289. return mp;
  6290. }
  6291. }
  6292. spin_unlock_irq(&phba->hbalock);
  6293. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6294. "0402 Cannot find virtual addr for buffer tag on "
  6295. "ring %d Data x%lx x%p x%p x%x\n",
  6296. pring->ringno, (unsigned long) tag,
  6297. slp->next, slp->prev, pring->postbufq_cnt);
  6298. return NULL;
  6299. }
  6300. /**
  6301. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6302. * @phba: Pointer to HBA context object.
  6303. * @pring: Pointer to driver SLI ring object.
  6304. * @phys: DMA address of the buffer.
  6305. *
  6306. * This function searches the buffer list using the dma_address
  6307. * of unsolicited event to find the driver's lpfc_dmabuf object
  6308. * corresponding to the dma_address. The function returns the
  6309. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6310. * This function is called by the ct and els unsolicited event
  6311. * handlers to get the buffer associated with the unsolicited
  6312. * event.
  6313. *
  6314. * This function is called with no lock held.
  6315. **/
  6316. struct lpfc_dmabuf *
  6317. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6318. dma_addr_t phys)
  6319. {
  6320. struct lpfc_dmabuf *mp, *next_mp;
  6321. struct list_head *slp = &pring->postbufq;
  6322. /* Search postbufq, from the begining, looking for a match on phys */
  6323. spin_lock_irq(&phba->hbalock);
  6324. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6325. if (mp->phys == phys) {
  6326. list_del_init(&mp->list);
  6327. pring->postbufq_cnt--;
  6328. spin_unlock_irq(&phba->hbalock);
  6329. return mp;
  6330. }
  6331. }
  6332. spin_unlock_irq(&phba->hbalock);
  6333. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6334. "0410 Cannot find virtual addr for mapped buf on "
  6335. "ring %d Data x%llx x%p x%p x%x\n",
  6336. pring->ringno, (unsigned long long)phys,
  6337. slp->next, slp->prev, pring->postbufq_cnt);
  6338. return NULL;
  6339. }
  6340. /**
  6341. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6342. * @phba: Pointer to HBA context object.
  6343. * @cmdiocb: Pointer to driver command iocb object.
  6344. * @rspiocb: Pointer to driver response iocb object.
  6345. *
  6346. * This function is the completion handler for the abort iocbs for
  6347. * ELS commands. This function is called from the ELS ring event
  6348. * handler with no lock held. This function frees memory resources
  6349. * associated with the abort iocb.
  6350. **/
  6351. static void
  6352. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6353. struct lpfc_iocbq *rspiocb)
  6354. {
  6355. IOCB_t *irsp = &rspiocb->iocb;
  6356. uint16_t abort_iotag, abort_context;
  6357. struct lpfc_iocbq *abort_iocb;
  6358. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6359. abort_iocb = NULL;
  6360. if (irsp->ulpStatus) {
  6361. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6362. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6363. spin_lock_irq(&phba->hbalock);
  6364. if (phba->sli_rev < LPFC_SLI_REV4) {
  6365. if (abort_iotag != 0 &&
  6366. abort_iotag <= phba->sli.last_iotag)
  6367. abort_iocb =
  6368. phba->sli.iocbq_lookup[abort_iotag];
  6369. } else
  6370. /* For sli4 the abort_tag is the XRI,
  6371. * so the abort routine puts the iotag of the iocb
  6372. * being aborted in the context field of the abort
  6373. * IOCB.
  6374. */
  6375. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6376. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6377. "0327 Cannot abort els iocb %p "
  6378. "with tag %x context %x, abort status %x, "
  6379. "abort code %x\n",
  6380. abort_iocb, abort_iotag, abort_context,
  6381. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6382. /*
  6383. * If the iocb is not found in Firmware queue the iocb
  6384. * might have completed already. Do not free it again.
  6385. */
  6386. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6387. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6388. spin_unlock_irq(&phba->hbalock);
  6389. lpfc_sli_release_iocbq(phba, cmdiocb);
  6390. return;
  6391. }
  6392. /* For SLI4 the ulpContext field for abort IOCB
  6393. * holds the iotag of the IOCB being aborted so
  6394. * the local abort_context needs to be reset to
  6395. * match the aborted IOCBs ulpContext.
  6396. */
  6397. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6398. abort_context = abort_iocb->iocb.ulpContext;
  6399. }
  6400. /*
  6401. * make sure we have the right iocbq before taking it
  6402. * off the txcmplq and try to call completion routine.
  6403. */
  6404. if (!abort_iocb ||
  6405. abort_iocb->iocb.ulpContext != abort_context ||
  6406. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6407. spin_unlock_irq(&phba->hbalock);
  6408. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6409. /*
  6410. * leave the SLI4 aborted command on the txcmplq
  6411. * list and the command complete WCQE's XB bit
  6412. * will tell whether the SGL (XRI) can be released
  6413. * immediately or to the aborted SGL list for the
  6414. * following abort XRI from the HBA.
  6415. */
  6416. list_del_init(&abort_iocb->list);
  6417. pring->txcmplq_cnt--;
  6418. spin_unlock_irq(&phba->hbalock);
  6419. /* Firmware could still be in progress of DMAing
  6420. * payload, so don't free data buffer till after
  6421. * a hbeat.
  6422. */
  6423. spin_lock_irq(&phba->hbalock);
  6424. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6425. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6426. spin_unlock_irq(&phba->hbalock);
  6427. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6428. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6429. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6430. }
  6431. }
  6432. lpfc_sli_release_iocbq(phba, cmdiocb);
  6433. return;
  6434. }
  6435. /**
  6436. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6437. * @phba: Pointer to HBA context object.
  6438. * @cmdiocb: Pointer to driver command iocb object.
  6439. * @rspiocb: Pointer to driver response iocb object.
  6440. *
  6441. * The function is called from SLI ring event handler with no
  6442. * lock held. This function is the completion handler for ELS commands
  6443. * which are aborted. The function frees memory resources used for
  6444. * the aborted ELS commands.
  6445. **/
  6446. static void
  6447. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6448. struct lpfc_iocbq *rspiocb)
  6449. {
  6450. IOCB_t *irsp = &rspiocb->iocb;
  6451. /* ELS cmd tag <ulpIoTag> completes */
  6452. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6453. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6454. "x%x x%x x%x\n",
  6455. irsp->ulpIoTag, irsp->ulpStatus,
  6456. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6457. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6458. lpfc_ct_free_iocb(phba, cmdiocb);
  6459. else
  6460. lpfc_els_free_iocb(phba, cmdiocb);
  6461. return;
  6462. }
  6463. /**
  6464. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6465. * @phba: Pointer to HBA context object.
  6466. * @pring: Pointer to driver SLI ring object.
  6467. * @cmdiocb: Pointer to driver command iocb object.
  6468. *
  6469. * This function issues an abort iocb for the provided command
  6470. * iocb. This function is called with hbalock held.
  6471. * The function returns 0 when it fails due to memory allocation
  6472. * failure or when the command iocb is an abort request.
  6473. **/
  6474. int
  6475. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6476. struct lpfc_iocbq *cmdiocb)
  6477. {
  6478. struct lpfc_vport *vport = cmdiocb->vport;
  6479. struct lpfc_iocbq *abtsiocbp;
  6480. IOCB_t *icmd = NULL;
  6481. IOCB_t *iabt = NULL;
  6482. int retval = IOCB_ERROR;
  6483. /*
  6484. * There are certain command types we don't want to abort. And we
  6485. * don't want to abort commands that are already in the process of
  6486. * being aborted.
  6487. */
  6488. icmd = &cmdiocb->iocb;
  6489. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6490. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6491. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6492. return 0;
  6493. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6494. * callback so that nothing happens when it finishes.
  6495. */
  6496. if ((vport->load_flag & FC_UNLOADING) &&
  6497. (pring->ringno == LPFC_ELS_RING)) {
  6498. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6499. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6500. else
  6501. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6502. goto abort_iotag_exit;
  6503. }
  6504. /* issue ABTS for this IOCB based on iotag */
  6505. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6506. if (abtsiocbp == NULL)
  6507. return 0;
  6508. /* This signals the response to set the correct status
  6509. * before calling the completion handler
  6510. */
  6511. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6512. iabt = &abtsiocbp->iocb;
  6513. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6514. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6515. if (phba->sli_rev == LPFC_SLI_REV4) {
  6516. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6517. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6518. }
  6519. else
  6520. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6521. iabt->ulpLe = 1;
  6522. iabt->ulpClass = icmd->ulpClass;
  6523. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6524. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6525. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6526. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6527. if (phba->link_state >= LPFC_LINK_UP)
  6528. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6529. else
  6530. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6531. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6532. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6533. "0339 Abort xri x%x, original iotag x%x, "
  6534. "abort cmd iotag x%x\n",
  6535. iabt->un.acxri.abortContextTag,
  6536. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6537. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6538. if (retval)
  6539. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6540. abort_iotag_exit:
  6541. /*
  6542. * Caller to this routine should check for IOCB_ERROR
  6543. * and handle it properly. This routine no longer removes
  6544. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6545. */
  6546. return retval;
  6547. }
  6548. /**
  6549. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6550. * @iocbq: Pointer to driver iocb object.
  6551. * @vport: Pointer to driver virtual port object.
  6552. * @tgt_id: SCSI ID of the target.
  6553. * @lun_id: LUN ID of the scsi device.
  6554. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6555. *
  6556. * This function acts as an iocb filter for functions which abort or count
  6557. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6558. * 0 if the filtering criteria is met for the given iocb and will return
  6559. * 1 if the filtering criteria is not met.
  6560. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6561. * given iocb is for the SCSI device specified by vport, tgt_id and
  6562. * lun_id parameter.
  6563. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6564. * given iocb is for the SCSI target specified by vport and tgt_id
  6565. * parameters.
  6566. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6567. * given iocb is for the SCSI host associated with the given vport.
  6568. * This function is called with no locks held.
  6569. **/
  6570. static int
  6571. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6572. uint16_t tgt_id, uint64_t lun_id,
  6573. lpfc_ctx_cmd ctx_cmd)
  6574. {
  6575. struct lpfc_scsi_buf *lpfc_cmd;
  6576. int rc = 1;
  6577. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6578. return rc;
  6579. if (iocbq->vport != vport)
  6580. return rc;
  6581. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6582. if (lpfc_cmd->pCmd == NULL)
  6583. return rc;
  6584. switch (ctx_cmd) {
  6585. case LPFC_CTX_LUN:
  6586. if ((lpfc_cmd->rdata->pnode) &&
  6587. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6588. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6589. rc = 0;
  6590. break;
  6591. case LPFC_CTX_TGT:
  6592. if ((lpfc_cmd->rdata->pnode) &&
  6593. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6594. rc = 0;
  6595. break;
  6596. case LPFC_CTX_HOST:
  6597. rc = 0;
  6598. break;
  6599. default:
  6600. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6601. __func__, ctx_cmd);
  6602. break;
  6603. }
  6604. return rc;
  6605. }
  6606. /**
  6607. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6608. * @vport: Pointer to virtual port.
  6609. * @tgt_id: SCSI ID of the target.
  6610. * @lun_id: LUN ID of the scsi device.
  6611. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6612. *
  6613. * This function returns number of FCP commands pending for the vport.
  6614. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6615. * commands pending on the vport associated with SCSI device specified
  6616. * by tgt_id and lun_id parameters.
  6617. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6618. * commands pending on the vport associated with SCSI target specified
  6619. * by tgt_id parameter.
  6620. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6621. * commands pending on the vport.
  6622. * This function returns the number of iocbs which satisfy the filter.
  6623. * This function is called without any lock held.
  6624. **/
  6625. int
  6626. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6627. lpfc_ctx_cmd ctx_cmd)
  6628. {
  6629. struct lpfc_hba *phba = vport->phba;
  6630. struct lpfc_iocbq *iocbq;
  6631. int sum, i;
  6632. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6633. iocbq = phba->sli.iocbq_lookup[i];
  6634. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6635. ctx_cmd) == 0)
  6636. sum++;
  6637. }
  6638. return sum;
  6639. }
  6640. /**
  6641. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6642. * @phba: Pointer to HBA context object
  6643. * @cmdiocb: Pointer to command iocb object.
  6644. * @rspiocb: Pointer to response iocb object.
  6645. *
  6646. * This function is called when an aborted FCP iocb completes. This
  6647. * function is called by the ring event handler with no lock held.
  6648. * This function frees the iocb.
  6649. **/
  6650. void
  6651. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6652. struct lpfc_iocbq *rspiocb)
  6653. {
  6654. lpfc_sli_release_iocbq(phba, cmdiocb);
  6655. return;
  6656. }
  6657. /**
  6658. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6659. * @vport: Pointer to virtual port.
  6660. * @pring: Pointer to driver SLI ring object.
  6661. * @tgt_id: SCSI ID of the target.
  6662. * @lun_id: LUN ID of the scsi device.
  6663. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6664. *
  6665. * This function sends an abort command for every SCSI command
  6666. * associated with the given virtual port pending on the ring
  6667. * filtered by lpfc_sli_validate_fcp_iocb function.
  6668. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6669. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6670. * parameters
  6671. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6672. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6673. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6674. * FCP iocbs associated with virtual port.
  6675. * This function returns number of iocbs it failed to abort.
  6676. * This function is called with no locks held.
  6677. **/
  6678. int
  6679. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6680. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6681. {
  6682. struct lpfc_hba *phba = vport->phba;
  6683. struct lpfc_iocbq *iocbq;
  6684. struct lpfc_iocbq *abtsiocb;
  6685. IOCB_t *cmd = NULL;
  6686. int errcnt = 0, ret_val = 0;
  6687. int i;
  6688. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6689. iocbq = phba->sli.iocbq_lookup[i];
  6690. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6691. abort_cmd) != 0)
  6692. continue;
  6693. /* issue ABTS for this IOCB based on iotag */
  6694. abtsiocb = lpfc_sli_get_iocbq(phba);
  6695. if (abtsiocb == NULL) {
  6696. errcnt++;
  6697. continue;
  6698. }
  6699. cmd = &iocbq->iocb;
  6700. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6701. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6702. if (phba->sli_rev == LPFC_SLI_REV4)
  6703. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6704. else
  6705. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6706. abtsiocb->iocb.ulpLe = 1;
  6707. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6708. abtsiocb->vport = phba->pport;
  6709. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6710. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6711. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6712. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6713. if (lpfc_is_link_up(phba))
  6714. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6715. else
  6716. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6717. /* Setup callback routine and issue the command. */
  6718. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6719. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6720. abtsiocb, 0);
  6721. if (ret_val == IOCB_ERROR) {
  6722. lpfc_sli_release_iocbq(phba, abtsiocb);
  6723. errcnt++;
  6724. continue;
  6725. }
  6726. }
  6727. return errcnt;
  6728. }
  6729. /**
  6730. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6731. * @phba: Pointer to HBA context object.
  6732. * @cmdiocbq: Pointer to command iocb.
  6733. * @rspiocbq: Pointer to response iocb.
  6734. *
  6735. * This function is the completion handler for iocbs issued using
  6736. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6737. * ring event handler function without any lock held. This function
  6738. * can be called from both worker thread context and interrupt
  6739. * context. This function also can be called from other thread which
  6740. * cleans up the SLI layer objects.
  6741. * This function copy the contents of the response iocb to the
  6742. * response iocb memory object provided by the caller of
  6743. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6744. * sleeps for the iocb completion.
  6745. **/
  6746. static void
  6747. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6748. struct lpfc_iocbq *cmdiocbq,
  6749. struct lpfc_iocbq *rspiocbq)
  6750. {
  6751. wait_queue_head_t *pdone_q;
  6752. unsigned long iflags;
  6753. spin_lock_irqsave(&phba->hbalock, iflags);
  6754. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6755. if (cmdiocbq->context2 && rspiocbq)
  6756. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6757. &rspiocbq->iocb, sizeof(IOCB_t));
  6758. pdone_q = cmdiocbq->context_un.wait_queue;
  6759. if (pdone_q)
  6760. wake_up(pdone_q);
  6761. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6762. return;
  6763. }
  6764. /**
  6765. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6766. * @phba: Pointer to HBA context object..
  6767. * @piocbq: Pointer to command iocb.
  6768. * @flag: Flag to test.
  6769. *
  6770. * This routine grabs the hbalock and then test the iocb_flag to
  6771. * see if the passed in flag is set.
  6772. * Returns:
  6773. * 1 if flag is set.
  6774. * 0 if flag is not set.
  6775. **/
  6776. static int
  6777. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6778. struct lpfc_iocbq *piocbq, uint32_t flag)
  6779. {
  6780. unsigned long iflags;
  6781. int ret;
  6782. spin_lock_irqsave(&phba->hbalock, iflags);
  6783. ret = piocbq->iocb_flag & flag;
  6784. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6785. return ret;
  6786. }
  6787. /**
  6788. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6789. * @phba: Pointer to HBA context object..
  6790. * @pring: Pointer to sli ring.
  6791. * @piocb: Pointer to command iocb.
  6792. * @prspiocbq: Pointer to response iocb.
  6793. * @timeout: Timeout in number of seconds.
  6794. *
  6795. * This function issues the iocb to firmware and waits for the
  6796. * iocb to complete. If the iocb command is not
  6797. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6798. * Caller should not free the iocb resources if this function
  6799. * returns IOCB_TIMEDOUT.
  6800. * The function waits for the iocb completion using an
  6801. * non-interruptible wait.
  6802. * This function will sleep while waiting for iocb completion.
  6803. * So, this function should not be called from any context which
  6804. * does not allow sleeping. Due to the same reason, this function
  6805. * cannot be called with interrupt disabled.
  6806. * This function assumes that the iocb completions occur while
  6807. * this function sleep. So, this function cannot be called from
  6808. * the thread which process iocb completion for this ring.
  6809. * This function clears the iocb_flag of the iocb object before
  6810. * issuing the iocb and the iocb completion handler sets this
  6811. * flag and wakes this thread when the iocb completes.
  6812. * The contents of the response iocb will be copied to prspiocbq
  6813. * by the completion handler when the command completes.
  6814. * This function returns IOCB_SUCCESS when success.
  6815. * This function is called with no lock held.
  6816. **/
  6817. int
  6818. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6819. uint32_t ring_number,
  6820. struct lpfc_iocbq *piocb,
  6821. struct lpfc_iocbq *prspiocbq,
  6822. uint32_t timeout)
  6823. {
  6824. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6825. long timeleft, timeout_req = 0;
  6826. int retval = IOCB_SUCCESS;
  6827. uint32_t creg_val;
  6828. /*
  6829. * If the caller has provided a response iocbq buffer, then context2
  6830. * is NULL or its an error.
  6831. */
  6832. if (prspiocbq) {
  6833. if (piocb->context2)
  6834. return IOCB_ERROR;
  6835. piocb->context2 = prspiocbq;
  6836. }
  6837. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6838. piocb->context_un.wait_queue = &done_q;
  6839. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6840. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6841. creg_val = readl(phba->HCregaddr);
  6842. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6843. writel(creg_val, phba->HCregaddr);
  6844. readl(phba->HCregaddr); /* flush */
  6845. }
  6846. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6847. if (retval == IOCB_SUCCESS) {
  6848. timeout_req = timeout * HZ;
  6849. timeleft = wait_event_timeout(done_q,
  6850. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6851. timeout_req);
  6852. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6853. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6854. "0331 IOCB wake signaled\n");
  6855. } else if (timeleft == 0) {
  6856. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6857. "0338 IOCB wait timeout error - no "
  6858. "wake response Data x%x\n", timeout);
  6859. retval = IOCB_TIMEDOUT;
  6860. } else {
  6861. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6862. "0330 IOCB wake NOT set, "
  6863. "Data x%x x%lx\n",
  6864. timeout, (timeleft / jiffies));
  6865. retval = IOCB_TIMEDOUT;
  6866. }
  6867. } else {
  6868. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6869. "0332 IOCB wait issue failed, Data x%x\n",
  6870. retval);
  6871. retval = IOCB_ERROR;
  6872. }
  6873. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6874. creg_val = readl(phba->HCregaddr);
  6875. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6876. writel(creg_val, phba->HCregaddr);
  6877. readl(phba->HCregaddr); /* flush */
  6878. }
  6879. if (prspiocbq)
  6880. piocb->context2 = NULL;
  6881. piocb->context_un.wait_queue = NULL;
  6882. piocb->iocb_cmpl = NULL;
  6883. return retval;
  6884. }
  6885. /**
  6886. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6887. * @phba: Pointer to HBA context object.
  6888. * @pmboxq: Pointer to driver mailbox object.
  6889. * @timeout: Timeout in number of seconds.
  6890. *
  6891. * This function issues the mailbox to firmware and waits for the
  6892. * mailbox command to complete. If the mailbox command is not
  6893. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6894. * The function waits for the mailbox completion using an
  6895. * interruptible wait. If the thread is woken up due to a
  6896. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6897. * should not free the mailbox resources, if this function returns
  6898. * MBX_TIMEOUT.
  6899. * This function will sleep while waiting for mailbox completion.
  6900. * So, this function should not be called from any context which
  6901. * does not allow sleeping. Due to the same reason, this function
  6902. * cannot be called with interrupt disabled.
  6903. * This function assumes that the mailbox completion occurs while
  6904. * this function sleep. So, this function cannot be called from
  6905. * the worker thread which processes mailbox completion.
  6906. * This function is called in the context of HBA management
  6907. * applications.
  6908. * This function returns MBX_SUCCESS when successful.
  6909. * This function is called with no lock held.
  6910. **/
  6911. int
  6912. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6913. uint32_t timeout)
  6914. {
  6915. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6916. int retval;
  6917. unsigned long flag;
  6918. /* The caller must leave context1 empty. */
  6919. if (pmboxq->context1)
  6920. return MBX_NOT_FINISHED;
  6921. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6922. /* setup wake call as IOCB callback */
  6923. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6924. /* setup context field to pass wait_queue pointer to wake function */
  6925. pmboxq->context1 = &done_q;
  6926. /* now issue the command */
  6927. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6928. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6929. wait_event_interruptible_timeout(done_q,
  6930. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6931. timeout * HZ);
  6932. spin_lock_irqsave(&phba->hbalock, flag);
  6933. pmboxq->context1 = NULL;
  6934. /*
  6935. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6936. * else do not free the resources.
  6937. */
  6938. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6939. retval = MBX_SUCCESS;
  6940. else {
  6941. retval = MBX_TIMEOUT;
  6942. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6943. }
  6944. spin_unlock_irqrestore(&phba->hbalock, flag);
  6945. }
  6946. return retval;
  6947. }
  6948. /**
  6949. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6950. * @phba: Pointer to HBA context.
  6951. *
  6952. * This function is called to shutdown the driver's mailbox sub-system.
  6953. * It first marks the mailbox sub-system is in a block state to prevent
  6954. * the asynchronous mailbox command from issued off the pending mailbox
  6955. * command queue. If the mailbox command sub-system shutdown is due to
  6956. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6957. * the mailbox sub-system flush routine to forcefully bring down the
  6958. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6959. * as with offline or HBA function reset), this routine will wait for the
  6960. * outstanding mailbox command to complete before invoking the mailbox
  6961. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6962. **/
  6963. void
  6964. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6965. {
  6966. struct lpfc_sli *psli = &phba->sli;
  6967. uint8_t actcmd = MBX_HEARTBEAT;
  6968. unsigned long timeout;
  6969. spin_lock_irq(&phba->hbalock);
  6970. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6971. spin_unlock_irq(&phba->hbalock);
  6972. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6973. spin_lock_irq(&phba->hbalock);
  6974. if (phba->sli.mbox_active)
  6975. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  6976. spin_unlock_irq(&phba->hbalock);
  6977. /* Determine how long we might wait for the active mailbox
  6978. * command to be gracefully completed by firmware.
  6979. */
  6980. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  6981. 1000) + jiffies;
  6982. while (phba->sli.mbox_active) {
  6983. /* Check active mailbox complete status every 2ms */
  6984. msleep(2);
  6985. if (time_after(jiffies, timeout))
  6986. /* Timeout, let the mailbox flush routine to
  6987. * forcefully release active mailbox command
  6988. */
  6989. break;
  6990. }
  6991. }
  6992. lpfc_sli_mbox_sys_flush(phba);
  6993. }
  6994. /**
  6995. * lpfc_sli_eratt_read - read sli-3 error attention events
  6996. * @phba: Pointer to HBA context.
  6997. *
  6998. * This function is called to read the SLI3 device error attention registers
  6999. * for possible error attention events. The caller must hold the hostlock
  7000. * with spin_lock_irq().
  7001. *
  7002. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7003. * Register and returns 0 otherwise.
  7004. **/
  7005. static int
  7006. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7007. {
  7008. uint32_t ha_copy;
  7009. /* Read chip Host Attention (HA) register */
  7010. ha_copy = readl(phba->HAregaddr);
  7011. if (ha_copy & HA_ERATT) {
  7012. /* Read host status register to retrieve error event */
  7013. lpfc_sli_read_hs(phba);
  7014. /* Check if there is a deferred error condition is active */
  7015. if ((HS_FFER1 & phba->work_hs) &&
  7016. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7017. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7018. phba->hba_flag |= DEFER_ERATT;
  7019. /* Clear all interrupt enable conditions */
  7020. writel(0, phba->HCregaddr);
  7021. readl(phba->HCregaddr);
  7022. }
  7023. /* Set the driver HA work bitmap */
  7024. phba->work_ha |= HA_ERATT;
  7025. /* Indicate polling handles this ERATT */
  7026. phba->hba_flag |= HBA_ERATT_HANDLED;
  7027. return 1;
  7028. }
  7029. return 0;
  7030. }
  7031. /**
  7032. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7033. * @phba: Pointer to HBA context.
  7034. *
  7035. * This function is called to read the SLI4 device error attention registers
  7036. * for possible error attention events. The caller must hold the hostlock
  7037. * with spin_lock_irq().
  7038. *
  7039. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7040. * Register and returns 0 otherwise.
  7041. **/
  7042. static int
  7043. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7044. {
  7045. uint32_t uerr_sta_hi, uerr_sta_lo;
  7046. /* For now, use the SLI4 device internal unrecoverable error
  7047. * registers for error attention. This can be changed later.
  7048. */
  7049. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7050. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7051. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7052. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7053. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7054. "1423 HBA Unrecoverable error: "
  7055. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7056. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7057. uerr_sta_lo, uerr_sta_hi,
  7058. phba->sli4_hba.ue_mask_lo,
  7059. phba->sli4_hba.ue_mask_hi);
  7060. phba->work_status[0] = uerr_sta_lo;
  7061. phba->work_status[1] = uerr_sta_hi;
  7062. /* Set the driver HA work bitmap */
  7063. phba->work_ha |= HA_ERATT;
  7064. /* Indicate polling handles this ERATT */
  7065. phba->hba_flag |= HBA_ERATT_HANDLED;
  7066. return 1;
  7067. }
  7068. return 0;
  7069. }
  7070. /**
  7071. * lpfc_sli_check_eratt - check error attention events
  7072. * @phba: Pointer to HBA context.
  7073. *
  7074. * This function is called from timer soft interrupt context to check HBA's
  7075. * error attention register bit for error attention events.
  7076. *
  7077. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7078. * Register and returns 0 otherwise.
  7079. **/
  7080. int
  7081. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7082. {
  7083. uint32_t ha_copy;
  7084. /* If somebody is waiting to handle an eratt, don't process it
  7085. * here. The brdkill function will do this.
  7086. */
  7087. if (phba->link_flag & LS_IGNORE_ERATT)
  7088. return 0;
  7089. /* Check if interrupt handler handles this ERATT */
  7090. spin_lock_irq(&phba->hbalock);
  7091. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7092. /* Interrupt handler has handled ERATT */
  7093. spin_unlock_irq(&phba->hbalock);
  7094. return 0;
  7095. }
  7096. /*
  7097. * If there is deferred error attention, do not check for error
  7098. * attention
  7099. */
  7100. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7101. spin_unlock_irq(&phba->hbalock);
  7102. return 0;
  7103. }
  7104. /* If PCI channel is offline, don't process it */
  7105. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7106. spin_unlock_irq(&phba->hbalock);
  7107. return 0;
  7108. }
  7109. switch (phba->sli_rev) {
  7110. case LPFC_SLI_REV2:
  7111. case LPFC_SLI_REV3:
  7112. /* Read chip Host Attention (HA) register */
  7113. ha_copy = lpfc_sli_eratt_read(phba);
  7114. break;
  7115. case LPFC_SLI_REV4:
  7116. /* Read devcie Uncoverable Error (UERR) registers */
  7117. ha_copy = lpfc_sli4_eratt_read(phba);
  7118. break;
  7119. default:
  7120. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7121. "0299 Invalid SLI revision (%d)\n",
  7122. phba->sli_rev);
  7123. ha_copy = 0;
  7124. break;
  7125. }
  7126. spin_unlock_irq(&phba->hbalock);
  7127. return ha_copy;
  7128. }
  7129. /**
  7130. * lpfc_intr_state_check - Check device state for interrupt handling
  7131. * @phba: Pointer to HBA context.
  7132. *
  7133. * This inline routine checks whether a device or its PCI slot is in a state
  7134. * that the interrupt should be handled.
  7135. *
  7136. * This function returns 0 if the device or the PCI slot is in a state that
  7137. * interrupt should be handled, otherwise -EIO.
  7138. */
  7139. static inline int
  7140. lpfc_intr_state_check(struct lpfc_hba *phba)
  7141. {
  7142. /* If the pci channel is offline, ignore all the interrupts */
  7143. if (unlikely(pci_channel_offline(phba->pcidev)))
  7144. return -EIO;
  7145. /* Update device level interrupt statistics */
  7146. phba->sli.slistat.sli_intr++;
  7147. /* Ignore all interrupts during initialization. */
  7148. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7149. return -EIO;
  7150. return 0;
  7151. }
  7152. /**
  7153. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7154. * @irq: Interrupt number.
  7155. * @dev_id: The device context pointer.
  7156. *
  7157. * This function is directly called from the PCI layer as an interrupt
  7158. * service routine when device with SLI-3 interface spec is enabled with
  7159. * MSI-X multi-message interrupt mode and there are slow-path events in
  7160. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7161. * interrupt mode, this function is called as part of the device-level
  7162. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7163. * is undergoing initialization, the interrupt handler will not process
  7164. * the interrupt. The link attention and ELS ring attention events are
  7165. * handled by the worker thread. The interrupt handler signals the worker
  7166. * thread and returns for these events. This function is called without
  7167. * any lock held. It gets the hbalock to access and update SLI data
  7168. * structures.
  7169. *
  7170. * This function returns IRQ_HANDLED when interrupt is handled else it
  7171. * returns IRQ_NONE.
  7172. **/
  7173. irqreturn_t
  7174. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7175. {
  7176. struct lpfc_hba *phba;
  7177. uint32_t ha_copy, hc_copy;
  7178. uint32_t work_ha_copy;
  7179. unsigned long status;
  7180. unsigned long iflag;
  7181. uint32_t control;
  7182. MAILBOX_t *mbox, *pmbox;
  7183. struct lpfc_vport *vport;
  7184. struct lpfc_nodelist *ndlp;
  7185. struct lpfc_dmabuf *mp;
  7186. LPFC_MBOXQ_t *pmb;
  7187. int rc;
  7188. /*
  7189. * Get the driver's phba structure from the dev_id and
  7190. * assume the HBA is not interrupting.
  7191. */
  7192. phba = (struct lpfc_hba *)dev_id;
  7193. if (unlikely(!phba))
  7194. return IRQ_NONE;
  7195. /*
  7196. * Stuff needs to be attented to when this function is invoked as an
  7197. * individual interrupt handler in MSI-X multi-message interrupt mode
  7198. */
  7199. if (phba->intr_type == MSIX) {
  7200. /* Check device state for handling interrupt */
  7201. if (lpfc_intr_state_check(phba))
  7202. return IRQ_NONE;
  7203. /* Need to read HA REG for slow-path events */
  7204. spin_lock_irqsave(&phba->hbalock, iflag);
  7205. ha_copy = readl(phba->HAregaddr);
  7206. /* If somebody is waiting to handle an eratt don't process it
  7207. * here. The brdkill function will do this.
  7208. */
  7209. if (phba->link_flag & LS_IGNORE_ERATT)
  7210. ha_copy &= ~HA_ERATT;
  7211. /* Check the need for handling ERATT in interrupt handler */
  7212. if (ha_copy & HA_ERATT) {
  7213. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7214. /* ERATT polling has handled ERATT */
  7215. ha_copy &= ~HA_ERATT;
  7216. else
  7217. /* Indicate interrupt handler handles ERATT */
  7218. phba->hba_flag |= HBA_ERATT_HANDLED;
  7219. }
  7220. /*
  7221. * If there is deferred error attention, do not check for any
  7222. * interrupt.
  7223. */
  7224. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7225. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7226. return IRQ_NONE;
  7227. }
  7228. /* Clear up only attention source related to slow-path */
  7229. hc_copy = readl(phba->HCregaddr);
  7230. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7231. HC_LAINT_ENA | HC_ERINT_ENA),
  7232. phba->HCregaddr);
  7233. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7234. phba->HAregaddr);
  7235. writel(hc_copy, phba->HCregaddr);
  7236. readl(phba->HAregaddr); /* flush */
  7237. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7238. } else
  7239. ha_copy = phba->ha_copy;
  7240. work_ha_copy = ha_copy & phba->work_ha_mask;
  7241. if (work_ha_copy) {
  7242. if (work_ha_copy & HA_LATT) {
  7243. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7244. /*
  7245. * Turn off Link Attention interrupts
  7246. * until CLEAR_LA done
  7247. */
  7248. spin_lock_irqsave(&phba->hbalock, iflag);
  7249. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7250. control = readl(phba->HCregaddr);
  7251. control &= ~HC_LAINT_ENA;
  7252. writel(control, phba->HCregaddr);
  7253. readl(phba->HCregaddr); /* flush */
  7254. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7255. }
  7256. else
  7257. work_ha_copy &= ~HA_LATT;
  7258. }
  7259. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7260. /*
  7261. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7262. * the only slow ring.
  7263. */
  7264. status = (work_ha_copy &
  7265. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7266. status >>= (4*LPFC_ELS_RING);
  7267. if (status & HA_RXMASK) {
  7268. spin_lock_irqsave(&phba->hbalock, iflag);
  7269. control = readl(phba->HCregaddr);
  7270. lpfc_debugfs_slow_ring_trc(phba,
  7271. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7272. control, status,
  7273. (uint32_t)phba->sli.slistat.sli_intr);
  7274. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7275. lpfc_debugfs_slow_ring_trc(phba,
  7276. "ISR Disable ring:"
  7277. "pwork:x%x hawork:x%x wait:x%x",
  7278. phba->work_ha, work_ha_copy,
  7279. (uint32_t)((unsigned long)
  7280. &phba->work_waitq));
  7281. control &=
  7282. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7283. writel(control, phba->HCregaddr);
  7284. readl(phba->HCregaddr); /* flush */
  7285. }
  7286. else {
  7287. lpfc_debugfs_slow_ring_trc(phba,
  7288. "ISR slow ring: pwork:"
  7289. "x%x hawork:x%x wait:x%x",
  7290. phba->work_ha, work_ha_copy,
  7291. (uint32_t)((unsigned long)
  7292. &phba->work_waitq));
  7293. }
  7294. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7295. }
  7296. }
  7297. spin_lock_irqsave(&phba->hbalock, iflag);
  7298. if (work_ha_copy & HA_ERATT) {
  7299. lpfc_sli_read_hs(phba);
  7300. /*
  7301. * Check if there is a deferred error condition
  7302. * is active
  7303. */
  7304. if ((HS_FFER1 & phba->work_hs) &&
  7305. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7306. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7307. phba->hba_flag |= DEFER_ERATT;
  7308. /* Clear all interrupt enable conditions */
  7309. writel(0, phba->HCregaddr);
  7310. readl(phba->HCregaddr);
  7311. }
  7312. }
  7313. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7314. pmb = phba->sli.mbox_active;
  7315. pmbox = &pmb->u.mb;
  7316. mbox = phba->mbox;
  7317. vport = pmb->vport;
  7318. /* First check out the status word */
  7319. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7320. if (pmbox->mbxOwner != OWN_HOST) {
  7321. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7322. /*
  7323. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7324. * mbxStatus <status>
  7325. */
  7326. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7327. LOG_SLI,
  7328. "(%d):0304 Stray Mailbox "
  7329. "Interrupt mbxCommand x%x "
  7330. "mbxStatus x%x\n",
  7331. (vport ? vport->vpi : 0),
  7332. pmbox->mbxCommand,
  7333. pmbox->mbxStatus);
  7334. /* clear mailbox attention bit */
  7335. work_ha_copy &= ~HA_MBATT;
  7336. } else {
  7337. phba->sli.mbox_active = NULL;
  7338. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7339. phba->last_completion_time = jiffies;
  7340. del_timer(&phba->sli.mbox_tmo);
  7341. if (pmb->mbox_cmpl) {
  7342. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7343. MAILBOX_CMD_SIZE);
  7344. }
  7345. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7346. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7347. lpfc_debugfs_disc_trc(vport,
  7348. LPFC_DISC_TRC_MBOX_VPORT,
  7349. "MBOX dflt rpi: : "
  7350. "status:x%x rpi:x%x",
  7351. (uint32_t)pmbox->mbxStatus,
  7352. pmbox->un.varWords[0], 0);
  7353. if (!pmbox->mbxStatus) {
  7354. mp = (struct lpfc_dmabuf *)
  7355. (pmb->context1);
  7356. ndlp = (struct lpfc_nodelist *)
  7357. pmb->context2;
  7358. /* Reg_LOGIN of dflt RPI was
  7359. * successful. new lets get
  7360. * rid of the RPI using the
  7361. * same mbox buffer.
  7362. */
  7363. lpfc_unreg_login(phba,
  7364. vport->vpi,
  7365. pmbox->un.varWords[0],
  7366. pmb);
  7367. pmb->mbox_cmpl =
  7368. lpfc_mbx_cmpl_dflt_rpi;
  7369. pmb->context1 = mp;
  7370. pmb->context2 = ndlp;
  7371. pmb->vport = vport;
  7372. rc = lpfc_sli_issue_mbox(phba,
  7373. pmb,
  7374. MBX_NOWAIT);
  7375. if (rc != MBX_BUSY)
  7376. lpfc_printf_log(phba,
  7377. KERN_ERR,
  7378. LOG_MBOX | LOG_SLI,
  7379. "0350 rc should have"
  7380. "been MBX_BUSY\n");
  7381. if (rc != MBX_NOT_FINISHED)
  7382. goto send_current_mbox;
  7383. }
  7384. }
  7385. spin_lock_irqsave(
  7386. &phba->pport->work_port_lock,
  7387. iflag);
  7388. phba->pport->work_port_events &=
  7389. ~WORKER_MBOX_TMO;
  7390. spin_unlock_irqrestore(
  7391. &phba->pport->work_port_lock,
  7392. iflag);
  7393. lpfc_mbox_cmpl_put(phba, pmb);
  7394. }
  7395. } else
  7396. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7397. if ((work_ha_copy & HA_MBATT) &&
  7398. (phba->sli.mbox_active == NULL)) {
  7399. send_current_mbox:
  7400. /* Process next mailbox command if there is one */
  7401. do {
  7402. rc = lpfc_sli_issue_mbox(phba, NULL,
  7403. MBX_NOWAIT);
  7404. } while (rc == MBX_NOT_FINISHED);
  7405. if (rc != MBX_SUCCESS)
  7406. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7407. LOG_SLI, "0349 rc should be "
  7408. "MBX_SUCCESS\n");
  7409. }
  7410. spin_lock_irqsave(&phba->hbalock, iflag);
  7411. phba->work_ha |= work_ha_copy;
  7412. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7413. lpfc_worker_wake_up(phba);
  7414. }
  7415. return IRQ_HANDLED;
  7416. } /* lpfc_sli_sp_intr_handler */
  7417. /**
  7418. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7419. * @irq: Interrupt number.
  7420. * @dev_id: The device context pointer.
  7421. *
  7422. * This function is directly called from the PCI layer as an interrupt
  7423. * service routine when device with SLI-3 interface spec is enabled with
  7424. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7425. * ring event in the HBA. However, when the device is enabled with either
  7426. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7427. * device-level interrupt handler. When the PCI slot is in error recovery
  7428. * or the HBA is undergoing initialization, the interrupt handler will not
  7429. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7430. * the intrrupt context. This function is called without any lock held.
  7431. * It gets the hbalock to access and update SLI data structures.
  7432. *
  7433. * This function returns IRQ_HANDLED when interrupt is handled else it
  7434. * returns IRQ_NONE.
  7435. **/
  7436. irqreturn_t
  7437. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7438. {
  7439. struct lpfc_hba *phba;
  7440. uint32_t ha_copy;
  7441. unsigned long status;
  7442. unsigned long iflag;
  7443. /* Get the driver's phba structure from the dev_id and
  7444. * assume the HBA is not interrupting.
  7445. */
  7446. phba = (struct lpfc_hba *) dev_id;
  7447. if (unlikely(!phba))
  7448. return IRQ_NONE;
  7449. /*
  7450. * Stuff needs to be attented to when this function is invoked as an
  7451. * individual interrupt handler in MSI-X multi-message interrupt mode
  7452. */
  7453. if (phba->intr_type == MSIX) {
  7454. /* Check device state for handling interrupt */
  7455. if (lpfc_intr_state_check(phba))
  7456. return IRQ_NONE;
  7457. /* Need to read HA REG for FCP ring and other ring events */
  7458. ha_copy = readl(phba->HAregaddr);
  7459. /* Clear up only attention source related to fast-path */
  7460. spin_lock_irqsave(&phba->hbalock, iflag);
  7461. /*
  7462. * If there is deferred error attention, do not check for
  7463. * any interrupt.
  7464. */
  7465. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7466. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7467. return IRQ_NONE;
  7468. }
  7469. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7470. phba->HAregaddr);
  7471. readl(phba->HAregaddr); /* flush */
  7472. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7473. } else
  7474. ha_copy = phba->ha_copy;
  7475. /*
  7476. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7477. */
  7478. ha_copy &= ~(phba->work_ha_mask);
  7479. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7480. status >>= (4*LPFC_FCP_RING);
  7481. if (status & HA_RXMASK)
  7482. lpfc_sli_handle_fast_ring_event(phba,
  7483. &phba->sli.ring[LPFC_FCP_RING],
  7484. status);
  7485. if (phba->cfg_multi_ring_support == 2) {
  7486. /*
  7487. * Process all events on extra ring. Take the optimized path
  7488. * for extra ring IO.
  7489. */
  7490. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7491. status >>= (4*LPFC_EXTRA_RING);
  7492. if (status & HA_RXMASK) {
  7493. lpfc_sli_handle_fast_ring_event(phba,
  7494. &phba->sli.ring[LPFC_EXTRA_RING],
  7495. status);
  7496. }
  7497. }
  7498. return IRQ_HANDLED;
  7499. } /* lpfc_sli_fp_intr_handler */
  7500. /**
  7501. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7502. * @irq: Interrupt number.
  7503. * @dev_id: The device context pointer.
  7504. *
  7505. * This function is the HBA device-level interrupt handler to device with
  7506. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7507. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7508. * requires driver attention. This function invokes the slow-path interrupt
  7509. * attention handling function and fast-path interrupt attention handling
  7510. * function in turn to process the relevant HBA attention events. This
  7511. * function is called without any lock held. It gets the hbalock to access
  7512. * and update SLI data structures.
  7513. *
  7514. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7515. * returns IRQ_NONE.
  7516. **/
  7517. irqreturn_t
  7518. lpfc_sli_intr_handler(int irq, void *dev_id)
  7519. {
  7520. struct lpfc_hba *phba;
  7521. irqreturn_t sp_irq_rc, fp_irq_rc;
  7522. unsigned long status1, status2;
  7523. uint32_t hc_copy;
  7524. /*
  7525. * Get the driver's phba structure from the dev_id and
  7526. * assume the HBA is not interrupting.
  7527. */
  7528. phba = (struct lpfc_hba *) dev_id;
  7529. if (unlikely(!phba))
  7530. return IRQ_NONE;
  7531. /* Check device state for handling interrupt */
  7532. if (lpfc_intr_state_check(phba))
  7533. return IRQ_NONE;
  7534. spin_lock(&phba->hbalock);
  7535. phba->ha_copy = readl(phba->HAregaddr);
  7536. if (unlikely(!phba->ha_copy)) {
  7537. spin_unlock(&phba->hbalock);
  7538. return IRQ_NONE;
  7539. } else if (phba->ha_copy & HA_ERATT) {
  7540. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7541. /* ERATT polling has handled ERATT */
  7542. phba->ha_copy &= ~HA_ERATT;
  7543. else
  7544. /* Indicate interrupt handler handles ERATT */
  7545. phba->hba_flag |= HBA_ERATT_HANDLED;
  7546. }
  7547. /*
  7548. * If there is deferred error attention, do not check for any interrupt.
  7549. */
  7550. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7551. spin_unlock_irq(&phba->hbalock);
  7552. return IRQ_NONE;
  7553. }
  7554. /* Clear attention sources except link and error attentions */
  7555. hc_copy = readl(phba->HCregaddr);
  7556. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7557. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7558. phba->HCregaddr);
  7559. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7560. writel(hc_copy, phba->HCregaddr);
  7561. readl(phba->HAregaddr); /* flush */
  7562. spin_unlock(&phba->hbalock);
  7563. /*
  7564. * Invokes slow-path host attention interrupt handling as appropriate.
  7565. */
  7566. /* status of events with mailbox and link attention */
  7567. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7568. /* status of events with ELS ring */
  7569. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7570. status2 >>= (4*LPFC_ELS_RING);
  7571. if (status1 || (status2 & HA_RXMASK))
  7572. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7573. else
  7574. sp_irq_rc = IRQ_NONE;
  7575. /*
  7576. * Invoke fast-path host attention interrupt handling as appropriate.
  7577. */
  7578. /* status of events with FCP ring */
  7579. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7580. status1 >>= (4*LPFC_FCP_RING);
  7581. /* status of events with extra ring */
  7582. if (phba->cfg_multi_ring_support == 2) {
  7583. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7584. status2 >>= (4*LPFC_EXTRA_RING);
  7585. } else
  7586. status2 = 0;
  7587. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7588. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7589. else
  7590. fp_irq_rc = IRQ_NONE;
  7591. /* Return device-level interrupt handling status */
  7592. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7593. } /* lpfc_sli_intr_handler */
  7594. /**
  7595. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7596. * @phba: pointer to lpfc hba data structure.
  7597. *
  7598. * This routine is invoked by the worker thread to process all the pending
  7599. * SLI4 FCP abort XRI events.
  7600. **/
  7601. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7602. {
  7603. struct lpfc_cq_event *cq_event;
  7604. /* First, declare the fcp xri abort event has been handled */
  7605. spin_lock_irq(&phba->hbalock);
  7606. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7607. spin_unlock_irq(&phba->hbalock);
  7608. /* Now, handle all the fcp xri abort events */
  7609. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7610. /* Get the first event from the head of the event queue */
  7611. spin_lock_irq(&phba->hbalock);
  7612. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7613. cq_event, struct lpfc_cq_event, list);
  7614. spin_unlock_irq(&phba->hbalock);
  7615. /* Notify aborted XRI for FCP work queue */
  7616. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7617. /* Free the event processed back to the free pool */
  7618. lpfc_sli4_cq_event_release(phba, cq_event);
  7619. }
  7620. }
  7621. /**
  7622. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7623. * @phba: pointer to lpfc hba data structure.
  7624. *
  7625. * This routine is invoked by the worker thread to process all the pending
  7626. * SLI4 els abort xri events.
  7627. **/
  7628. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7629. {
  7630. struct lpfc_cq_event *cq_event;
  7631. /* First, declare the els xri abort event has been handled */
  7632. spin_lock_irq(&phba->hbalock);
  7633. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7634. spin_unlock_irq(&phba->hbalock);
  7635. /* Now, handle all the els xri abort events */
  7636. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7637. /* Get the first event from the head of the event queue */
  7638. spin_lock_irq(&phba->hbalock);
  7639. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7640. cq_event, struct lpfc_cq_event, list);
  7641. spin_unlock_irq(&phba->hbalock);
  7642. /* Notify aborted XRI for ELS work queue */
  7643. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7644. /* Free the event processed back to the free pool */
  7645. lpfc_sli4_cq_event_release(phba, cq_event);
  7646. }
  7647. }
  7648. /**
  7649. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7650. * @phba: pointer to lpfc hba data structure
  7651. * @pIocbIn: pointer to the rspiocbq
  7652. * @pIocbOut: pointer to the cmdiocbq
  7653. * @wcqe: pointer to the complete wcqe
  7654. *
  7655. * This routine transfers the fields of a command iocbq to a response iocbq
  7656. * by copying all the IOCB fields from command iocbq and transferring the
  7657. * completion status information from the complete wcqe.
  7658. **/
  7659. static void
  7660. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7661. struct lpfc_iocbq *pIocbIn,
  7662. struct lpfc_iocbq *pIocbOut,
  7663. struct lpfc_wcqe_complete *wcqe)
  7664. {
  7665. unsigned long iflags;
  7666. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7667. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7668. sizeof(struct lpfc_iocbq) - offset);
  7669. /* Map WCQE parameters into irspiocb parameters */
  7670. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7671. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7672. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7673. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7674. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7675. wcqe->total_data_placed;
  7676. else
  7677. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7678. else {
  7679. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7680. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7681. }
  7682. /* Pick up HBA exchange busy condition */
  7683. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7684. spin_lock_irqsave(&phba->hbalock, iflags);
  7685. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7686. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7687. }
  7688. }
  7689. /**
  7690. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7691. * @phba: Pointer to HBA context object.
  7692. * @wcqe: Pointer to work-queue completion queue entry.
  7693. *
  7694. * This routine handles an ELS work-queue completion event and construct
  7695. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7696. * discovery engine to handle.
  7697. *
  7698. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7699. **/
  7700. static struct lpfc_iocbq *
  7701. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7702. struct lpfc_iocbq *irspiocbq)
  7703. {
  7704. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7705. struct lpfc_iocbq *cmdiocbq;
  7706. struct lpfc_wcqe_complete *wcqe;
  7707. unsigned long iflags;
  7708. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7709. spin_lock_irqsave(&phba->hbalock, iflags);
  7710. pring->stats.iocb_event++;
  7711. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7712. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7713. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7714. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7715. if (unlikely(!cmdiocbq)) {
  7716. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7717. "0386 ELS complete with no corresponding "
  7718. "cmdiocb: iotag (%d)\n",
  7719. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7720. lpfc_sli_release_iocbq(phba, irspiocbq);
  7721. return NULL;
  7722. }
  7723. /* Fake the irspiocbq and copy necessary response information */
  7724. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  7725. return irspiocbq;
  7726. }
  7727. /**
  7728. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7729. * @phba: Pointer to HBA context object.
  7730. * @cqe: Pointer to mailbox completion queue entry.
  7731. *
  7732. * This routine process a mailbox completion queue entry with asynchrous
  7733. * event.
  7734. *
  7735. * Return: true if work posted to worker thread, otherwise false.
  7736. **/
  7737. static bool
  7738. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7739. {
  7740. struct lpfc_cq_event *cq_event;
  7741. unsigned long iflags;
  7742. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7743. "0392 Async Event: word0:x%x, word1:x%x, "
  7744. "word2:x%x, word3:x%x\n", mcqe->word0,
  7745. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7746. /* Allocate a new internal CQ_EVENT entry */
  7747. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7748. if (!cq_event) {
  7749. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7750. "0394 Failed to allocate CQ_EVENT entry\n");
  7751. return false;
  7752. }
  7753. /* Move the CQE into an asynchronous event entry */
  7754. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7755. spin_lock_irqsave(&phba->hbalock, iflags);
  7756. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7757. /* Set the async event flag */
  7758. phba->hba_flag |= ASYNC_EVENT;
  7759. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7760. return true;
  7761. }
  7762. /**
  7763. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7764. * @phba: Pointer to HBA context object.
  7765. * @cqe: Pointer to mailbox completion queue entry.
  7766. *
  7767. * This routine process a mailbox completion queue entry with mailbox
  7768. * completion event.
  7769. *
  7770. * Return: true if work posted to worker thread, otherwise false.
  7771. **/
  7772. static bool
  7773. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7774. {
  7775. uint32_t mcqe_status;
  7776. MAILBOX_t *mbox, *pmbox;
  7777. struct lpfc_mqe *mqe;
  7778. struct lpfc_vport *vport;
  7779. struct lpfc_nodelist *ndlp;
  7780. struct lpfc_dmabuf *mp;
  7781. unsigned long iflags;
  7782. LPFC_MBOXQ_t *pmb;
  7783. bool workposted = false;
  7784. int rc;
  7785. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7786. if (!bf_get(lpfc_trailer_completed, mcqe))
  7787. goto out_no_mqe_complete;
  7788. /* Get the reference to the active mbox command */
  7789. spin_lock_irqsave(&phba->hbalock, iflags);
  7790. pmb = phba->sli.mbox_active;
  7791. if (unlikely(!pmb)) {
  7792. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7793. "1832 No pending MBOX command to handle\n");
  7794. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7795. goto out_no_mqe_complete;
  7796. }
  7797. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7798. mqe = &pmb->u.mqe;
  7799. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7800. mbox = phba->mbox;
  7801. vport = pmb->vport;
  7802. /* Reset heartbeat timer */
  7803. phba->last_completion_time = jiffies;
  7804. del_timer(&phba->sli.mbox_tmo);
  7805. /* Move mbox data to caller's mailbox region, do endian swapping */
  7806. if (pmb->mbox_cmpl && mbox)
  7807. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7808. /* Set the mailbox status with SLI4 range 0x4000 */
  7809. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7810. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7811. bf_set(lpfc_mqe_status, mqe,
  7812. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7813. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7814. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7815. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7816. "MBOX dflt rpi: status:x%x rpi:x%x",
  7817. mcqe_status,
  7818. pmbox->un.varWords[0], 0);
  7819. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7820. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7821. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7822. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7823. * RID of the PPI using the same mbox buffer.
  7824. */
  7825. lpfc_unreg_login(phba, vport->vpi,
  7826. pmbox->un.varWords[0], pmb);
  7827. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7828. pmb->context1 = mp;
  7829. pmb->context2 = ndlp;
  7830. pmb->vport = vport;
  7831. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7832. if (rc != MBX_BUSY)
  7833. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7834. LOG_SLI, "0385 rc should "
  7835. "have been MBX_BUSY\n");
  7836. if (rc != MBX_NOT_FINISHED)
  7837. goto send_current_mbox;
  7838. }
  7839. }
  7840. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7841. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7842. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7843. /* There is mailbox completion work to do */
  7844. spin_lock_irqsave(&phba->hbalock, iflags);
  7845. __lpfc_mbox_cmpl_put(phba, pmb);
  7846. phba->work_ha |= HA_MBATT;
  7847. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7848. workposted = true;
  7849. send_current_mbox:
  7850. spin_lock_irqsave(&phba->hbalock, iflags);
  7851. /* Release the mailbox command posting token */
  7852. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7853. /* Setting active mailbox pointer need to be in sync to flag clear */
  7854. phba->sli.mbox_active = NULL;
  7855. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7856. /* Wake up worker thread to post the next pending mailbox command */
  7857. lpfc_worker_wake_up(phba);
  7858. out_no_mqe_complete:
  7859. if (bf_get(lpfc_trailer_consumed, mcqe))
  7860. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7861. return workposted;
  7862. }
  7863. /**
  7864. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7865. * @phba: Pointer to HBA context object.
  7866. * @cqe: Pointer to mailbox completion queue entry.
  7867. *
  7868. * This routine process a mailbox completion queue entry, it invokes the
  7869. * proper mailbox complete handling or asynchrous event handling routine
  7870. * according to the MCQE's async bit.
  7871. *
  7872. * Return: true if work posted to worker thread, otherwise false.
  7873. **/
  7874. static bool
  7875. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7876. {
  7877. struct lpfc_mcqe mcqe;
  7878. bool workposted;
  7879. /* Copy the mailbox MCQE and convert endian order as needed */
  7880. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7881. /* Invoke the proper event handling routine */
  7882. if (!bf_get(lpfc_trailer_async, &mcqe))
  7883. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7884. else
  7885. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7886. return workposted;
  7887. }
  7888. /**
  7889. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7890. * @phba: Pointer to HBA context object.
  7891. * @wcqe: Pointer to work-queue completion queue entry.
  7892. *
  7893. * This routine handles an ELS work-queue completion event.
  7894. *
  7895. * Return: true if work posted to worker thread, otherwise false.
  7896. **/
  7897. static bool
  7898. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7899. struct lpfc_wcqe_complete *wcqe)
  7900. {
  7901. struct lpfc_iocbq *irspiocbq;
  7902. unsigned long iflags;
  7903. /* Get an irspiocbq for later ELS response processing use */
  7904. irspiocbq = lpfc_sli_get_iocbq(phba);
  7905. if (!irspiocbq) {
  7906. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7907. "0387 Failed to allocate an iocbq\n");
  7908. return false;
  7909. }
  7910. /* Save off the slow-path queue event for work thread to process */
  7911. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  7912. spin_lock_irqsave(&phba->hbalock, iflags);
  7913. list_add_tail(&irspiocbq->cq_event.list,
  7914. &phba->sli4_hba.sp_queue_event);
  7915. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7916. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7917. return true;
  7918. }
  7919. /**
  7920. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7921. * @phba: Pointer to HBA context object.
  7922. * @wcqe: Pointer to work-queue completion queue entry.
  7923. *
  7924. * This routine handles slow-path WQ entry comsumed event by invoking the
  7925. * proper WQ release routine to the slow-path WQ.
  7926. **/
  7927. static void
  7928. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7929. struct lpfc_wcqe_release *wcqe)
  7930. {
  7931. /* Check for the slow-path ELS work queue */
  7932. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7933. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7934. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7935. else
  7936. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7937. "2579 Slow-path wqe consume event carries "
  7938. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7939. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7940. phba->sli4_hba.els_wq->queue_id);
  7941. }
  7942. /**
  7943. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7944. * @phba: Pointer to HBA context object.
  7945. * @cq: Pointer to a WQ completion queue.
  7946. * @wcqe: Pointer to work-queue completion queue entry.
  7947. *
  7948. * This routine handles an XRI abort event.
  7949. *
  7950. * Return: true if work posted to worker thread, otherwise false.
  7951. **/
  7952. static bool
  7953. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7954. struct lpfc_queue *cq,
  7955. struct sli4_wcqe_xri_aborted *wcqe)
  7956. {
  7957. bool workposted = false;
  7958. struct lpfc_cq_event *cq_event;
  7959. unsigned long iflags;
  7960. /* Allocate a new internal CQ_EVENT entry */
  7961. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7962. if (!cq_event) {
  7963. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7964. "0602 Failed to allocate CQ_EVENT entry\n");
  7965. return false;
  7966. }
  7967. /* Move the CQE into the proper xri abort event list */
  7968. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  7969. switch (cq->subtype) {
  7970. case LPFC_FCP:
  7971. spin_lock_irqsave(&phba->hbalock, iflags);
  7972. list_add_tail(&cq_event->list,
  7973. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  7974. /* Set the fcp xri abort event flag */
  7975. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  7976. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7977. workposted = true;
  7978. break;
  7979. case LPFC_ELS:
  7980. spin_lock_irqsave(&phba->hbalock, iflags);
  7981. list_add_tail(&cq_event->list,
  7982. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  7983. /* Set the els xri abort event flag */
  7984. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  7985. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7986. workposted = true;
  7987. break;
  7988. default:
  7989. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7990. "0603 Invalid work queue CQE subtype (x%x)\n",
  7991. cq->subtype);
  7992. workposted = false;
  7993. break;
  7994. }
  7995. return workposted;
  7996. }
  7997. /**
  7998. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  7999. * @phba: Pointer to HBA context object.
  8000. * @rcqe: Pointer to receive-queue completion queue entry.
  8001. *
  8002. * This routine process a receive-queue completion queue entry.
  8003. *
  8004. * Return: true if work posted to worker thread, otherwise false.
  8005. **/
  8006. static bool
  8007. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8008. {
  8009. bool workposted = false;
  8010. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8011. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8012. struct hbq_dmabuf *dma_buf;
  8013. uint32_t status;
  8014. unsigned long iflags;
  8015. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8016. goto out;
  8017. status = bf_get(lpfc_rcqe_status, rcqe);
  8018. switch (status) {
  8019. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8020. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8021. "2537 Receive Frame Truncated!!\n");
  8022. case FC_STATUS_RQ_SUCCESS:
  8023. lpfc_sli4_rq_release(hrq, drq);
  8024. spin_lock_irqsave(&phba->hbalock, iflags);
  8025. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8026. if (!dma_buf) {
  8027. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8028. goto out;
  8029. }
  8030. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8031. /* save off the frame for the word thread to process */
  8032. list_add_tail(&dma_buf->cq_event.list,
  8033. &phba->sli4_hba.sp_queue_event);
  8034. /* Frame received */
  8035. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8036. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8037. workposted = true;
  8038. break;
  8039. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8040. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8041. /* Post more buffers if possible */
  8042. spin_lock_irqsave(&phba->hbalock, iflags);
  8043. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8044. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8045. workposted = true;
  8046. break;
  8047. }
  8048. out:
  8049. return workposted;
  8050. }
  8051. /**
  8052. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8053. * @phba: Pointer to HBA context object.
  8054. * @cq: Pointer to the completion queue.
  8055. * @wcqe: Pointer to a completion queue entry.
  8056. *
  8057. * This routine process a slow-path work-queue or recieve queue completion queue
  8058. * entry.
  8059. *
  8060. * Return: true if work posted to worker thread, otherwise false.
  8061. **/
  8062. static bool
  8063. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8064. struct lpfc_cqe *cqe)
  8065. {
  8066. struct lpfc_cqe cqevt;
  8067. bool workposted = false;
  8068. /* Copy the work queue CQE and convert endian order if needed */
  8069. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8070. /* Check and process for different type of WCQE and dispatch */
  8071. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8072. case CQE_CODE_COMPL_WQE:
  8073. /* Process the WQ/RQ complete event */
  8074. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8075. (struct lpfc_wcqe_complete *)&cqevt);
  8076. break;
  8077. case CQE_CODE_RELEASE_WQE:
  8078. /* Process the WQ release event */
  8079. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8080. (struct lpfc_wcqe_release *)&cqevt);
  8081. break;
  8082. case CQE_CODE_XRI_ABORTED:
  8083. /* Process the WQ XRI abort event */
  8084. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8085. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8086. break;
  8087. case CQE_CODE_RECEIVE:
  8088. /* Process the RQ event */
  8089. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8090. (struct lpfc_rcqe *)&cqevt);
  8091. break;
  8092. default:
  8093. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8094. "0388 Not a valid WCQE code: x%x\n",
  8095. bf_get(lpfc_cqe_code, &cqevt));
  8096. break;
  8097. }
  8098. return workposted;
  8099. }
  8100. /**
  8101. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8102. * @phba: Pointer to HBA context object.
  8103. * @eqe: Pointer to fast-path event queue entry.
  8104. *
  8105. * This routine process a event queue entry from the slow-path event queue.
  8106. * It will check the MajorCode and MinorCode to determine this is for a
  8107. * completion event on a completion queue, if not, an error shall be logged
  8108. * and just return. Otherwise, it will get to the corresponding completion
  8109. * queue and process all the entries on that completion queue, rearm the
  8110. * completion queue, and then return.
  8111. *
  8112. **/
  8113. static void
  8114. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8115. {
  8116. struct lpfc_queue *cq = NULL, *childq, *speq;
  8117. struct lpfc_cqe *cqe;
  8118. bool workposted = false;
  8119. int ecount = 0;
  8120. uint16_t cqid;
  8121. if (bf_get(lpfc_eqe_major_code, eqe) != 0) {
  8122. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8123. "0359 Not a valid slow-path completion "
  8124. "event: majorcode=x%x, minorcode=x%x\n",
  8125. bf_get(lpfc_eqe_major_code, eqe),
  8126. bf_get(lpfc_eqe_minor_code, eqe));
  8127. return;
  8128. }
  8129. /* Get the reference to the corresponding CQ */
  8130. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8131. /* Search for completion queue pointer matching this cqid */
  8132. speq = phba->sli4_hba.sp_eq;
  8133. list_for_each_entry(childq, &speq->child_list, list) {
  8134. if (childq->queue_id == cqid) {
  8135. cq = childq;
  8136. break;
  8137. }
  8138. }
  8139. if (unlikely(!cq)) {
  8140. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8141. "0365 Slow-path CQ identifier (%d) does "
  8142. "not exist\n", cqid);
  8143. return;
  8144. }
  8145. /* Process all the entries to the CQ */
  8146. switch (cq->type) {
  8147. case LPFC_MCQ:
  8148. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8149. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8150. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8151. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8152. }
  8153. break;
  8154. case LPFC_WCQ:
  8155. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8156. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8157. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8158. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8159. }
  8160. break;
  8161. default:
  8162. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8163. "0370 Invalid completion queue type (%d)\n",
  8164. cq->type);
  8165. return;
  8166. }
  8167. /* Catch the no cq entry condition, log an error */
  8168. if (unlikely(ecount == 0))
  8169. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8170. "0371 No entry from the CQ: identifier "
  8171. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8172. /* In any case, flash and re-arm the RCQ */
  8173. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8174. /* wake up worker thread if there are works to be done */
  8175. if (workposted)
  8176. lpfc_worker_wake_up(phba);
  8177. }
  8178. /**
  8179. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8180. * @eqe: Pointer to fast-path completion queue entry.
  8181. *
  8182. * This routine process a fast-path work queue completion entry from fast-path
  8183. * event queue for FCP command response completion.
  8184. **/
  8185. static void
  8186. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8187. struct lpfc_wcqe_complete *wcqe)
  8188. {
  8189. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8190. struct lpfc_iocbq *cmdiocbq;
  8191. struct lpfc_iocbq irspiocbq;
  8192. unsigned long iflags;
  8193. spin_lock_irqsave(&phba->hbalock, iflags);
  8194. pring->stats.iocb_event++;
  8195. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8196. /* Check for response status */
  8197. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8198. /* If resource errors reported from HBA, reduce queue
  8199. * depth of the SCSI device.
  8200. */
  8201. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8202. IOSTAT_LOCAL_REJECT) &&
  8203. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8204. phba->lpfc_rampdown_queue_depth(phba);
  8205. }
  8206. /* Log the error status */
  8207. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8208. "0373 FCP complete error: status=x%x, "
  8209. "hw_status=x%x, total_data_specified=%d, "
  8210. "parameter=x%x, word3=x%x\n",
  8211. bf_get(lpfc_wcqe_c_status, wcqe),
  8212. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8213. wcqe->total_data_placed, wcqe->parameter,
  8214. wcqe->word3);
  8215. }
  8216. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8217. spin_lock_irqsave(&phba->hbalock, iflags);
  8218. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8219. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8220. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8221. if (unlikely(!cmdiocbq)) {
  8222. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8223. "0374 FCP complete with no corresponding "
  8224. "cmdiocb: iotag (%d)\n",
  8225. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8226. return;
  8227. }
  8228. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8229. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8230. "0375 FCP cmdiocb not callback function "
  8231. "iotag: (%d)\n",
  8232. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8233. return;
  8234. }
  8235. /* Fake the irspiocb and copy necessary response information */
  8236. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8237. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8238. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8239. }
  8240. /**
  8241. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8242. * @phba: Pointer to HBA context object.
  8243. * @cq: Pointer to completion queue.
  8244. * @wcqe: Pointer to work-queue completion queue entry.
  8245. *
  8246. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8247. * proper WQ release routine to the slow-path WQ.
  8248. **/
  8249. static void
  8250. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8251. struct lpfc_wcqe_release *wcqe)
  8252. {
  8253. struct lpfc_queue *childwq;
  8254. bool wqid_matched = false;
  8255. uint16_t fcp_wqid;
  8256. /* Check for fast-path FCP work queue release */
  8257. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8258. list_for_each_entry(childwq, &cq->child_list, list) {
  8259. if (childwq->queue_id == fcp_wqid) {
  8260. lpfc_sli4_wq_release(childwq,
  8261. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8262. wqid_matched = true;
  8263. break;
  8264. }
  8265. }
  8266. /* Report warning log message if no match found */
  8267. if (wqid_matched != true)
  8268. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8269. "2580 Fast-path wqe consume event carries "
  8270. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8271. }
  8272. /**
  8273. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8274. * @cq: Pointer to the completion queue.
  8275. * @eqe: Pointer to fast-path completion queue entry.
  8276. *
  8277. * This routine process a fast-path work queue completion entry from fast-path
  8278. * event queue for FCP command response completion.
  8279. **/
  8280. static int
  8281. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8282. struct lpfc_cqe *cqe)
  8283. {
  8284. struct lpfc_wcqe_release wcqe;
  8285. bool workposted = false;
  8286. /* Copy the work queue CQE and convert endian order if needed */
  8287. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8288. /* Check and process for different type of WCQE and dispatch */
  8289. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8290. case CQE_CODE_COMPL_WQE:
  8291. /* Process the WQ complete event */
  8292. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8293. (struct lpfc_wcqe_complete *)&wcqe);
  8294. break;
  8295. case CQE_CODE_RELEASE_WQE:
  8296. /* Process the WQ release event */
  8297. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8298. (struct lpfc_wcqe_release *)&wcqe);
  8299. break;
  8300. case CQE_CODE_XRI_ABORTED:
  8301. /* Process the WQ XRI abort event */
  8302. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8303. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8304. break;
  8305. default:
  8306. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8307. "0144 Not a valid WCQE code: x%x\n",
  8308. bf_get(lpfc_wcqe_c_code, &wcqe));
  8309. break;
  8310. }
  8311. return workposted;
  8312. }
  8313. /**
  8314. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8315. * @phba: Pointer to HBA context object.
  8316. * @eqe: Pointer to fast-path event queue entry.
  8317. *
  8318. * This routine process a event queue entry from the fast-path event queue.
  8319. * It will check the MajorCode and MinorCode to determine this is for a
  8320. * completion event on a completion queue, if not, an error shall be logged
  8321. * and just return. Otherwise, it will get to the corresponding completion
  8322. * queue and process all the entries on the completion queue, rearm the
  8323. * completion queue, and then return.
  8324. **/
  8325. static void
  8326. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8327. uint32_t fcp_cqidx)
  8328. {
  8329. struct lpfc_queue *cq;
  8330. struct lpfc_cqe *cqe;
  8331. bool workposted = false;
  8332. uint16_t cqid;
  8333. int ecount = 0;
  8334. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0)) {
  8335. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8336. "0366 Not a valid fast-path completion "
  8337. "event: majorcode=x%x, minorcode=x%x\n",
  8338. bf_get(lpfc_eqe_major_code, eqe),
  8339. bf_get(lpfc_eqe_minor_code, eqe));
  8340. return;
  8341. }
  8342. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8343. if (unlikely(!cq)) {
  8344. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8345. "0367 Fast-path completion queue does not "
  8346. "exist\n");
  8347. return;
  8348. }
  8349. /* Get the reference to the corresponding CQ */
  8350. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8351. if (unlikely(cqid != cq->queue_id)) {
  8352. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8353. "0368 Miss-matched fast-path completion "
  8354. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8355. cqid, cq->queue_id);
  8356. return;
  8357. }
  8358. /* Process all the entries to the CQ */
  8359. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8360. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8361. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8362. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8363. }
  8364. /* Catch the no cq entry condition */
  8365. if (unlikely(ecount == 0))
  8366. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8367. "0369 No entry from fast-path completion "
  8368. "queue fcpcqid=%d\n", cq->queue_id);
  8369. /* In any case, flash and re-arm the CQ */
  8370. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8371. /* wake up worker thread if there are works to be done */
  8372. if (workposted)
  8373. lpfc_worker_wake_up(phba);
  8374. }
  8375. static void
  8376. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8377. {
  8378. struct lpfc_eqe *eqe;
  8379. /* walk all the EQ entries and drop on the floor */
  8380. while ((eqe = lpfc_sli4_eq_get(eq)))
  8381. ;
  8382. /* Clear and re-arm the EQ */
  8383. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8384. }
  8385. /**
  8386. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8387. * @irq: Interrupt number.
  8388. * @dev_id: The device context pointer.
  8389. *
  8390. * This function is directly called from the PCI layer as an interrupt
  8391. * service routine when device with SLI-4 interface spec is enabled with
  8392. * MSI-X multi-message interrupt mode and there are slow-path events in
  8393. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8394. * interrupt mode, this function is called as part of the device-level
  8395. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8396. * undergoing initialization, the interrupt handler will not process the
  8397. * interrupt. The link attention and ELS ring attention events are handled
  8398. * by the worker thread. The interrupt handler signals the worker thread
  8399. * and returns for these events. This function is called without any lock
  8400. * held. It gets the hbalock to access and update SLI data structures.
  8401. *
  8402. * This function returns IRQ_HANDLED when interrupt is handled else it
  8403. * returns IRQ_NONE.
  8404. **/
  8405. irqreturn_t
  8406. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8407. {
  8408. struct lpfc_hba *phba;
  8409. struct lpfc_queue *speq;
  8410. struct lpfc_eqe *eqe;
  8411. unsigned long iflag;
  8412. int ecount = 0;
  8413. /*
  8414. * Get the driver's phba structure from the dev_id
  8415. */
  8416. phba = (struct lpfc_hba *)dev_id;
  8417. if (unlikely(!phba))
  8418. return IRQ_NONE;
  8419. /* Get to the EQ struct associated with this vector */
  8420. speq = phba->sli4_hba.sp_eq;
  8421. /* Check device state for handling interrupt */
  8422. if (unlikely(lpfc_intr_state_check(phba))) {
  8423. /* Check again for link_state with lock held */
  8424. spin_lock_irqsave(&phba->hbalock, iflag);
  8425. if (phba->link_state < LPFC_LINK_DOWN)
  8426. /* Flush, clear interrupt, and rearm the EQ */
  8427. lpfc_sli4_eq_flush(phba, speq);
  8428. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8429. return IRQ_NONE;
  8430. }
  8431. /*
  8432. * Process all the event on FCP slow-path EQ
  8433. */
  8434. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8435. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8436. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8437. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8438. }
  8439. /* Always clear and re-arm the slow-path EQ */
  8440. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8441. /* Catch the no cq entry condition */
  8442. if (unlikely(ecount == 0)) {
  8443. if (phba->intr_type == MSIX)
  8444. /* MSI-X treated interrupt served as no EQ share INT */
  8445. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8446. "0357 MSI-X interrupt with no EQE\n");
  8447. else
  8448. /* Non MSI-X treated on interrupt as EQ share INT */
  8449. return IRQ_NONE;
  8450. }
  8451. return IRQ_HANDLED;
  8452. } /* lpfc_sli4_sp_intr_handler */
  8453. /**
  8454. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8455. * @irq: Interrupt number.
  8456. * @dev_id: The device context pointer.
  8457. *
  8458. * This function is directly called from the PCI layer as an interrupt
  8459. * service routine when device with SLI-4 interface spec is enabled with
  8460. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8461. * ring event in the HBA. However, when the device is enabled with either
  8462. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8463. * device-level interrupt handler. When the PCI slot is in error recovery
  8464. * or the HBA is undergoing initialization, the interrupt handler will not
  8465. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8466. * the intrrupt context. This function is called without any lock held.
  8467. * It gets the hbalock to access and update SLI data structures. Note that,
  8468. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8469. * equal to that of FCP CQ index.
  8470. *
  8471. * This function returns IRQ_HANDLED when interrupt is handled else it
  8472. * returns IRQ_NONE.
  8473. **/
  8474. irqreturn_t
  8475. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8476. {
  8477. struct lpfc_hba *phba;
  8478. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8479. struct lpfc_queue *fpeq;
  8480. struct lpfc_eqe *eqe;
  8481. unsigned long iflag;
  8482. int ecount = 0;
  8483. uint32_t fcp_eqidx;
  8484. /* Get the driver's phba structure from the dev_id */
  8485. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8486. phba = fcp_eq_hdl->phba;
  8487. fcp_eqidx = fcp_eq_hdl->idx;
  8488. if (unlikely(!phba))
  8489. return IRQ_NONE;
  8490. /* Get to the EQ struct associated with this vector */
  8491. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8492. /* Check device state for handling interrupt */
  8493. if (unlikely(lpfc_intr_state_check(phba))) {
  8494. /* Check again for link_state with lock held */
  8495. spin_lock_irqsave(&phba->hbalock, iflag);
  8496. if (phba->link_state < LPFC_LINK_DOWN)
  8497. /* Flush, clear interrupt, and rearm the EQ */
  8498. lpfc_sli4_eq_flush(phba, fpeq);
  8499. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8500. return IRQ_NONE;
  8501. }
  8502. /*
  8503. * Process all the event on FCP fast-path EQ
  8504. */
  8505. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8506. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8507. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8508. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8509. }
  8510. /* Always clear and re-arm the fast-path EQ */
  8511. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8512. if (unlikely(ecount == 0)) {
  8513. if (phba->intr_type == MSIX)
  8514. /* MSI-X treated interrupt served as no EQ share INT */
  8515. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8516. "0358 MSI-X interrupt with no EQE\n");
  8517. else
  8518. /* Non MSI-X treated on interrupt as EQ share INT */
  8519. return IRQ_NONE;
  8520. }
  8521. return IRQ_HANDLED;
  8522. } /* lpfc_sli4_fp_intr_handler */
  8523. /**
  8524. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8525. * @irq: Interrupt number.
  8526. * @dev_id: The device context pointer.
  8527. *
  8528. * This function is the device-level interrupt handler to device with SLI-4
  8529. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8530. * interrupt mode is enabled and there is an event in the HBA which requires
  8531. * driver attention. This function invokes the slow-path interrupt attention
  8532. * handling function and fast-path interrupt attention handling function in
  8533. * turn to process the relevant HBA attention events. This function is called
  8534. * without any lock held. It gets the hbalock to access and update SLI data
  8535. * structures.
  8536. *
  8537. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8538. * returns IRQ_NONE.
  8539. **/
  8540. irqreturn_t
  8541. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8542. {
  8543. struct lpfc_hba *phba;
  8544. irqreturn_t sp_irq_rc, fp_irq_rc;
  8545. bool fp_handled = false;
  8546. uint32_t fcp_eqidx;
  8547. /* Get the driver's phba structure from the dev_id */
  8548. phba = (struct lpfc_hba *)dev_id;
  8549. if (unlikely(!phba))
  8550. return IRQ_NONE;
  8551. /*
  8552. * Invokes slow-path host attention interrupt handling as appropriate.
  8553. */
  8554. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8555. /*
  8556. * Invoke fast-path host attention interrupt handling as appropriate.
  8557. */
  8558. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8559. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8560. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8561. if (fp_irq_rc == IRQ_HANDLED)
  8562. fp_handled |= true;
  8563. }
  8564. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8565. } /* lpfc_sli4_intr_handler */
  8566. /**
  8567. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8568. * @queue: The queue structure to free.
  8569. *
  8570. * This function frees a queue structure and the DMAable memeory used for
  8571. * the host resident queue. This function must be called after destroying the
  8572. * queue on the HBA.
  8573. **/
  8574. void
  8575. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8576. {
  8577. struct lpfc_dmabuf *dmabuf;
  8578. if (!queue)
  8579. return;
  8580. while (!list_empty(&queue->page_list)) {
  8581. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8582. list);
  8583. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8584. dmabuf->virt, dmabuf->phys);
  8585. kfree(dmabuf);
  8586. }
  8587. kfree(queue);
  8588. return;
  8589. }
  8590. /**
  8591. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8592. * @phba: The HBA that this queue is being created on.
  8593. * @entry_size: The size of each queue entry for this queue.
  8594. * @entry count: The number of entries that this queue will handle.
  8595. *
  8596. * This function allocates a queue structure and the DMAable memory used for
  8597. * the host resident queue. This function must be called before creating the
  8598. * queue on the HBA.
  8599. **/
  8600. struct lpfc_queue *
  8601. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8602. uint32_t entry_count)
  8603. {
  8604. struct lpfc_queue *queue;
  8605. struct lpfc_dmabuf *dmabuf;
  8606. int x, total_qe_count;
  8607. void *dma_pointer;
  8608. queue = kzalloc(sizeof(struct lpfc_queue) +
  8609. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8610. if (!queue)
  8611. return NULL;
  8612. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8613. INIT_LIST_HEAD(&queue->list);
  8614. INIT_LIST_HEAD(&queue->page_list);
  8615. INIT_LIST_HEAD(&queue->child_list);
  8616. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8617. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8618. if (!dmabuf)
  8619. goto out_fail;
  8620. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8621. PAGE_SIZE, &dmabuf->phys,
  8622. GFP_KERNEL);
  8623. if (!dmabuf->virt) {
  8624. kfree(dmabuf);
  8625. goto out_fail;
  8626. }
  8627. memset(dmabuf->virt, 0, PAGE_SIZE);
  8628. dmabuf->buffer_tag = x;
  8629. list_add_tail(&dmabuf->list, &queue->page_list);
  8630. /* initialize queue's entry array */
  8631. dma_pointer = dmabuf->virt;
  8632. for (; total_qe_count < entry_count &&
  8633. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8634. total_qe_count++, dma_pointer += entry_size) {
  8635. queue->qe[total_qe_count].address = dma_pointer;
  8636. }
  8637. }
  8638. queue->entry_size = entry_size;
  8639. queue->entry_count = entry_count;
  8640. queue->phba = phba;
  8641. return queue;
  8642. out_fail:
  8643. lpfc_sli4_queue_free(queue);
  8644. return NULL;
  8645. }
  8646. /**
  8647. * lpfc_eq_create - Create an Event Queue on the HBA
  8648. * @phba: HBA structure that indicates port to create a queue on.
  8649. * @eq: The queue structure to use to create the event queue.
  8650. * @imax: The maximum interrupt per second limit.
  8651. *
  8652. * This function creates an event queue, as detailed in @eq, on a port,
  8653. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8654. *
  8655. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8656. * is used to get the entry count and entry size that are necessary to
  8657. * determine the number of pages to allocate and use for this queue. This
  8658. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8659. * event queue. This function is asynchronous and will wait for the mailbox
  8660. * command to finish before continuing.
  8661. *
  8662. * On success this function will return a zero. If unable to allocate enough
  8663. * memory this function will return ENOMEM. If the queue create mailbox command
  8664. * fails this function will return ENXIO.
  8665. **/
  8666. uint32_t
  8667. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8668. {
  8669. struct lpfc_mbx_eq_create *eq_create;
  8670. LPFC_MBOXQ_t *mbox;
  8671. int rc, length, status = 0;
  8672. struct lpfc_dmabuf *dmabuf;
  8673. uint32_t shdr_status, shdr_add_status;
  8674. union lpfc_sli4_cfg_shdr *shdr;
  8675. uint16_t dmult;
  8676. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8677. if (!mbox)
  8678. return -ENOMEM;
  8679. length = (sizeof(struct lpfc_mbx_eq_create) -
  8680. sizeof(struct lpfc_sli4_cfg_mhdr));
  8681. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8682. LPFC_MBOX_OPCODE_EQ_CREATE,
  8683. length, LPFC_SLI4_MBX_EMBED);
  8684. eq_create = &mbox->u.mqe.un.eq_create;
  8685. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8686. eq->page_count);
  8687. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8688. LPFC_EQE_SIZE);
  8689. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8690. /* Calculate delay multiper from maximum interrupt per second */
  8691. dmult = LPFC_DMULT_CONST/imax - 1;
  8692. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8693. dmult);
  8694. switch (eq->entry_count) {
  8695. default:
  8696. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8697. "0360 Unsupported EQ count. (%d)\n",
  8698. eq->entry_count);
  8699. if (eq->entry_count < 256)
  8700. return -EINVAL;
  8701. /* otherwise default to smallest count (drop through) */
  8702. case 256:
  8703. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8704. LPFC_EQ_CNT_256);
  8705. break;
  8706. case 512:
  8707. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8708. LPFC_EQ_CNT_512);
  8709. break;
  8710. case 1024:
  8711. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8712. LPFC_EQ_CNT_1024);
  8713. break;
  8714. case 2048:
  8715. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8716. LPFC_EQ_CNT_2048);
  8717. break;
  8718. case 4096:
  8719. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8720. LPFC_EQ_CNT_4096);
  8721. break;
  8722. }
  8723. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8724. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8725. putPaddrLow(dmabuf->phys);
  8726. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8727. putPaddrHigh(dmabuf->phys);
  8728. }
  8729. mbox->vport = phba->pport;
  8730. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8731. mbox->context1 = NULL;
  8732. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8733. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8734. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8735. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8736. if (shdr_status || shdr_add_status || rc) {
  8737. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8738. "2500 EQ_CREATE mailbox failed with "
  8739. "status x%x add_status x%x, mbx status x%x\n",
  8740. shdr_status, shdr_add_status, rc);
  8741. status = -ENXIO;
  8742. }
  8743. eq->type = LPFC_EQ;
  8744. eq->subtype = LPFC_NONE;
  8745. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8746. if (eq->queue_id == 0xFFFF)
  8747. status = -ENXIO;
  8748. eq->host_index = 0;
  8749. eq->hba_index = 0;
  8750. mempool_free(mbox, phba->mbox_mem_pool);
  8751. return status;
  8752. }
  8753. /**
  8754. * lpfc_cq_create - Create a Completion Queue on the HBA
  8755. * @phba: HBA structure that indicates port to create a queue on.
  8756. * @cq: The queue structure to use to create the completion queue.
  8757. * @eq: The event queue to bind this completion queue to.
  8758. *
  8759. * This function creates a completion queue, as detailed in @wq, on a port,
  8760. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8761. *
  8762. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8763. * is used to get the entry count and entry size that are necessary to
  8764. * determine the number of pages to allocate and use for this queue. The @eq
  8765. * is used to indicate which event queue to bind this completion queue to. This
  8766. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8767. * completion queue. This function is asynchronous and will wait for the mailbox
  8768. * command to finish before continuing.
  8769. *
  8770. * On success this function will return a zero. If unable to allocate enough
  8771. * memory this function will return ENOMEM. If the queue create mailbox command
  8772. * fails this function will return ENXIO.
  8773. **/
  8774. uint32_t
  8775. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8776. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8777. {
  8778. struct lpfc_mbx_cq_create *cq_create;
  8779. struct lpfc_dmabuf *dmabuf;
  8780. LPFC_MBOXQ_t *mbox;
  8781. int rc, length, status = 0;
  8782. uint32_t shdr_status, shdr_add_status;
  8783. union lpfc_sli4_cfg_shdr *shdr;
  8784. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8785. if (!mbox)
  8786. return -ENOMEM;
  8787. length = (sizeof(struct lpfc_mbx_cq_create) -
  8788. sizeof(struct lpfc_sli4_cfg_mhdr));
  8789. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8790. LPFC_MBOX_OPCODE_CQ_CREATE,
  8791. length, LPFC_SLI4_MBX_EMBED);
  8792. cq_create = &mbox->u.mqe.un.cq_create;
  8793. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8794. cq->page_count);
  8795. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8796. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8797. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8798. switch (cq->entry_count) {
  8799. default:
  8800. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8801. "0361 Unsupported CQ count. (%d)\n",
  8802. cq->entry_count);
  8803. if (cq->entry_count < 256)
  8804. return -EINVAL;
  8805. /* otherwise default to smallest count (drop through) */
  8806. case 256:
  8807. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8808. LPFC_CQ_CNT_256);
  8809. break;
  8810. case 512:
  8811. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8812. LPFC_CQ_CNT_512);
  8813. break;
  8814. case 1024:
  8815. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8816. LPFC_CQ_CNT_1024);
  8817. break;
  8818. }
  8819. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8820. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8821. putPaddrLow(dmabuf->phys);
  8822. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8823. putPaddrHigh(dmabuf->phys);
  8824. }
  8825. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8826. /* The IOCTL status is embedded in the mailbox subheader. */
  8827. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8828. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8829. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8830. if (shdr_status || shdr_add_status || rc) {
  8831. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8832. "2501 CQ_CREATE mailbox failed with "
  8833. "status x%x add_status x%x, mbx status x%x\n",
  8834. shdr_status, shdr_add_status, rc);
  8835. status = -ENXIO;
  8836. goto out;
  8837. }
  8838. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8839. if (cq->queue_id == 0xFFFF) {
  8840. status = -ENXIO;
  8841. goto out;
  8842. }
  8843. /* link the cq onto the parent eq child list */
  8844. list_add_tail(&cq->list, &eq->child_list);
  8845. /* Set up completion queue's type and subtype */
  8846. cq->type = type;
  8847. cq->subtype = subtype;
  8848. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8849. cq->host_index = 0;
  8850. cq->hba_index = 0;
  8851. out:
  8852. mempool_free(mbox, phba->mbox_mem_pool);
  8853. return status;
  8854. }
  8855. /**
  8856. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8857. * @phba: HBA structure that indicates port to create a queue on.
  8858. * @mq: The queue structure to use to create the mailbox queue.
  8859. *
  8860. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8861. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8862. *
  8863. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8864. * is used to get the entry count and entry size that are necessary to
  8865. * determine the number of pages to allocate and use for this queue. This
  8866. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8867. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8868. * command to finish before continuing.
  8869. *
  8870. * On success this function will return a zero. If unable to allocate enough
  8871. * memory this function will return ENOMEM. If the queue create mailbox command
  8872. * fails this function will return ENXIO.
  8873. **/
  8874. uint32_t
  8875. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8876. struct lpfc_queue *cq, uint32_t subtype)
  8877. {
  8878. struct lpfc_mbx_mq_create *mq_create;
  8879. struct lpfc_dmabuf *dmabuf;
  8880. LPFC_MBOXQ_t *mbox;
  8881. int rc, length, status = 0;
  8882. uint32_t shdr_status, shdr_add_status;
  8883. union lpfc_sli4_cfg_shdr *shdr;
  8884. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8885. if (!mbox)
  8886. return -ENOMEM;
  8887. length = (sizeof(struct lpfc_mbx_mq_create) -
  8888. sizeof(struct lpfc_sli4_cfg_mhdr));
  8889. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8890. LPFC_MBOX_OPCODE_MQ_CREATE,
  8891. length, LPFC_SLI4_MBX_EMBED);
  8892. mq_create = &mbox->u.mqe.un.mq_create;
  8893. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8894. mq->page_count);
  8895. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8896. cq->queue_id);
  8897. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8898. switch (mq->entry_count) {
  8899. default:
  8900. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8901. "0362 Unsupported MQ count. (%d)\n",
  8902. mq->entry_count);
  8903. if (mq->entry_count < 16)
  8904. return -EINVAL;
  8905. /* otherwise default to smallest count (drop through) */
  8906. case 16:
  8907. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8908. LPFC_MQ_CNT_16);
  8909. break;
  8910. case 32:
  8911. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8912. LPFC_MQ_CNT_32);
  8913. break;
  8914. case 64:
  8915. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8916. LPFC_MQ_CNT_64);
  8917. break;
  8918. case 128:
  8919. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8920. LPFC_MQ_CNT_128);
  8921. break;
  8922. }
  8923. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8924. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8925. putPaddrLow(dmabuf->phys);
  8926. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8927. putPaddrHigh(dmabuf->phys);
  8928. }
  8929. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8930. /* The IOCTL status is embedded in the mailbox subheader. */
  8931. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8932. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8933. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8934. if (shdr_status || shdr_add_status || rc) {
  8935. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8936. "2502 MQ_CREATE mailbox failed with "
  8937. "status x%x add_status x%x, mbx status x%x\n",
  8938. shdr_status, shdr_add_status, rc);
  8939. status = -ENXIO;
  8940. goto out;
  8941. }
  8942. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8943. if (mq->queue_id == 0xFFFF) {
  8944. status = -ENXIO;
  8945. goto out;
  8946. }
  8947. mq->type = LPFC_MQ;
  8948. mq->subtype = subtype;
  8949. mq->host_index = 0;
  8950. mq->hba_index = 0;
  8951. /* link the mq onto the parent cq child list */
  8952. list_add_tail(&mq->list, &cq->child_list);
  8953. out:
  8954. mempool_free(mbox, phba->mbox_mem_pool);
  8955. return status;
  8956. }
  8957. /**
  8958. * lpfc_wq_create - Create a Work Queue on the HBA
  8959. * @phba: HBA structure that indicates port to create a queue on.
  8960. * @wq: The queue structure to use to create the work queue.
  8961. * @cq: The completion queue to bind this work queue to.
  8962. * @subtype: The subtype of the work queue indicating its functionality.
  8963. *
  8964. * This function creates a work queue, as detailed in @wq, on a port, described
  8965. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  8966. *
  8967. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  8968. * is used to get the entry count and entry size that are necessary to
  8969. * determine the number of pages to allocate and use for this queue. The @cq
  8970. * is used to indicate which completion queue to bind this work queue to. This
  8971. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  8972. * work queue. This function is asynchronous and will wait for the mailbox
  8973. * command to finish before continuing.
  8974. *
  8975. * On success this function will return a zero. If unable to allocate enough
  8976. * memory this function will return ENOMEM. If the queue create mailbox command
  8977. * fails this function will return ENXIO.
  8978. **/
  8979. uint32_t
  8980. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  8981. struct lpfc_queue *cq, uint32_t subtype)
  8982. {
  8983. struct lpfc_mbx_wq_create *wq_create;
  8984. struct lpfc_dmabuf *dmabuf;
  8985. LPFC_MBOXQ_t *mbox;
  8986. int rc, length, status = 0;
  8987. uint32_t shdr_status, shdr_add_status;
  8988. union lpfc_sli4_cfg_shdr *shdr;
  8989. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8990. if (!mbox)
  8991. return -ENOMEM;
  8992. length = (sizeof(struct lpfc_mbx_wq_create) -
  8993. sizeof(struct lpfc_sli4_cfg_mhdr));
  8994. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8995. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  8996. length, LPFC_SLI4_MBX_EMBED);
  8997. wq_create = &mbox->u.mqe.un.wq_create;
  8998. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  8999. wq->page_count);
  9000. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9001. cq->queue_id);
  9002. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9003. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9004. putPaddrLow(dmabuf->phys);
  9005. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9006. putPaddrHigh(dmabuf->phys);
  9007. }
  9008. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9009. /* The IOCTL status is embedded in the mailbox subheader. */
  9010. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9011. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9012. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9013. if (shdr_status || shdr_add_status || rc) {
  9014. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9015. "2503 WQ_CREATE mailbox failed with "
  9016. "status x%x add_status x%x, mbx status x%x\n",
  9017. shdr_status, shdr_add_status, rc);
  9018. status = -ENXIO;
  9019. goto out;
  9020. }
  9021. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9022. if (wq->queue_id == 0xFFFF) {
  9023. status = -ENXIO;
  9024. goto out;
  9025. }
  9026. wq->type = LPFC_WQ;
  9027. wq->subtype = subtype;
  9028. wq->host_index = 0;
  9029. wq->hba_index = 0;
  9030. /* link the wq onto the parent cq child list */
  9031. list_add_tail(&wq->list, &cq->child_list);
  9032. out:
  9033. mempool_free(mbox, phba->mbox_mem_pool);
  9034. return status;
  9035. }
  9036. /**
  9037. * lpfc_rq_create - Create a Receive Queue on the HBA
  9038. * @phba: HBA structure that indicates port to create a queue on.
  9039. * @hrq: The queue structure to use to create the header receive queue.
  9040. * @drq: The queue structure to use to create the data receive queue.
  9041. * @cq: The completion queue to bind this work queue to.
  9042. *
  9043. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9044. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9045. * to the HBA.
  9046. *
  9047. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9048. * struct is used to get the entry count that is necessary to determine the
  9049. * number of pages to use for this queue. The @cq is used to indicate which
  9050. * completion queue to bind received buffers that are posted to these queues to.
  9051. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9052. * receive queue pair. This function is asynchronous and will wait for the
  9053. * mailbox command to finish before continuing.
  9054. *
  9055. * On success this function will return a zero. If unable to allocate enough
  9056. * memory this function will return ENOMEM. If the queue create mailbox command
  9057. * fails this function will return ENXIO.
  9058. **/
  9059. uint32_t
  9060. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9061. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9062. {
  9063. struct lpfc_mbx_rq_create *rq_create;
  9064. struct lpfc_dmabuf *dmabuf;
  9065. LPFC_MBOXQ_t *mbox;
  9066. int rc, length, status = 0;
  9067. uint32_t shdr_status, shdr_add_status;
  9068. union lpfc_sli4_cfg_shdr *shdr;
  9069. if (hrq->entry_count != drq->entry_count)
  9070. return -EINVAL;
  9071. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9072. if (!mbox)
  9073. return -ENOMEM;
  9074. length = (sizeof(struct lpfc_mbx_rq_create) -
  9075. sizeof(struct lpfc_sli4_cfg_mhdr));
  9076. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9077. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9078. length, LPFC_SLI4_MBX_EMBED);
  9079. rq_create = &mbox->u.mqe.un.rq_create;
  9080. switch (hrq->entry_count) {
  9081. default:
  9082. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9083. "2535 Unsupported RQ count. (%d)\n",
  9084. hrq->entry_count);
  9085. if (hrq->entry_count < 512)
  9086. return -EINVAL;
  9087. /* otherwise default to smallest count (drop through) */
  9088. case 512:
  9089. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9090. LPFC_RQ_RING_SIZE_512);
  9091. break;
  9092. case 1024:
  9093. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9094. LPFC_RQ_RING_SIZE_1024);
  9095. break;
  9096. case 2048:
  9097. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9098. LPFC_RQ_RING_SIZE_2048);
  9099. break;
  9100. case 4096:
  9101. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9102. LPFC_RQ_RING_SIZE_4096);
  9103. break;
  9104. }
  9105. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9106. cq->queue_id);
  9107. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9108. hrq->page_count);
  9109. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9110. LPFC_HDR_BUF_SIZE);
  9111. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9112. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9113. putPaddrLow(dmabuf->phys);
  9114. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9115. putPaddrHigh(dmabuf->phys);
  9116. }
  9117. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9118. /* The IOCTL status is embedded in the mailbox subheader. */
  9119. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9120. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9121. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9122. if (shdr_status || shdr_add_status || rc) {
  9123. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9124. "2504 RQ_CREATE mailbox failed with "
  9125. "status x%x add_status x%x, mbx status x%x\n",
  9126. shdr_status, shdr_add_status, rc);
  9127. status = -ENXIO;
  9128. goto out;
  9129. }
  9130. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9131. if (hrq->queue_id == 0xFFFF) {
  9132. status = -ENXIO;
  9133. goto out;
  9134. }
  9135. hrq->type = LPFC_HRQ;
  9136. hrq->subtype = subtype;
  9137. hrq->host_index = 0;
  9138. hrq->hba_index = 0;
  9139. /* now create the data queue */
  9140. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9141. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9142. length, LPFC_SLI4_MBX_EMBED);
  9143. switch (drq->entry_count) {
  9144. default:
  9145. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9146. "2536 Unsupported RQ count. (%d)\n",
  9147. drq->entry_count);
  9148. if (drq->entry_count < 512)
  9149. return -EINVAL;
  9150. /* otherwise default to smallest count (drop through) */
  9151. case 512:
  9152. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9153. LPFC_RQ_RING_SIZE_512);
  9154. break;
  9155. case 1024:
  9156. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9157. LPFC_RQ_RING_SIZE_1024);
  9158. break;
  9159. case 2048:
  9160. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9161. LPFC_RQ_RING_SIZE_2048);
  9162. break;
  9163. case 4096:
  9164. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9165. LPFC_RQ_RING_SIZE_4096);
  9166. break;
  9167. }
  9168. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9169. cq->queue_id);
  9170. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9171. drq->page_count);
  9172. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9173. LPFC_DATA_BUF_SIZE);
  9174. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9175. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9176. putPaddrLow(dmabuf->phys);
  9177. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9178. putPaddrHigh(dmabuf->phys);
  9179. }
  9180. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9181. /* The IOCTL status is embedded in the mailbox subheader. */
  9182. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9183. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9184. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9185. if (shdr_status || shdr_add_status || rc) {
  9186. status = -ENXIO;
  9187. goto out;
  9188. }
  9189. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9190. if (drq->queue_id == 0xFFFF) {
  9191. status = -ENXIO;
  9192. goto out;
  9193. }
  9194. drq->type = LPFC_DRQ;
  9195. drq->subtype = subtype;
  9196. drq->host_index = 0;
  9197. drq->hba_index = 0;
  9198. /* link the header and data RQs onto the parent cq child list */
  9199. list_add_tail(&hrq->list, &cq->child_list);
  9200. list_add_tail(&drq->list, &cq->child_list);
  9201. out:
  9202. mempool_free(mbox, phba->mbox_mem_pool);
  9203. return status;
  9204. }
  9205. /**
  9206. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9207. * @eq: The queue structure associated with the queue to destroy.
  9208. *
  9209. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9210. * command, specific to the type of queue, to the HBA.
  9211. *
  9212. * The @eq struct is used to get the queue ID of the queue to destroy.
  9213. *
  9214. * On success this function will return a zero. If the queue destroy mailbox
  9215. * command fails this function will return ENXIO.
  9216. **/
  9217. uint32_t
  9218. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9219. {
  9220. LPFC_MBOXQ_t *mbox;
  9221. int rc, length, status = 0;
  9222. uint32_t shdr_status, shdr_add_status;
  9223. union lpfc_sli4_cfg_shdr *shdr;
  9224. if (!eq)
  9225. return -ENODEV;
  9226. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9227. if (!mbox)
  9228. return -ENOMEM;
  9229. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9230. sizeof(struct lpfc_sli4_cfg_mhdr));
  9231. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9232. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9233. length, LPFC_SLI4_MBX_EMBED);
  9234. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9235. eq->queue_id);
  9236. mbox->vport = eq->phba->pport;
  9237. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9238. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9239. /* The IOCTL status is embedded in the mailbox subheader. */
  9240. shdr = (union lpfc_sli4_cfg_shdr *)
  9241. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9242. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9243. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9244. if (shdr_status || shdr_add_status || rc) {
  9245. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9246. "2505 EQ_DESTROY mailbox failed with "
  9247. "status x%x add_status x%x, mbx status x%x\n",
  9248. shdr_status, shdr_add_status, rc);
  9249. status = -ENXIO;
  9250. }
  9251. /* Remove eq from any list */
  9252. list_del_init(&eq->list);
  9253. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9254. return status;
  9255. }
  9256. /**
  9257. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9258. * @cq: The queue structure associated with the queue to destroy.
  9259. *
  9260. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9261. * command, specific to the type of queue, to the HBA.
  9262. *
  9263. * The @cq struct is used to get the queue ID of the queue to destroy.
  9264. *
  9265. * On success this function will return a zero. If the queue destroy mailbox
  9266. * command fails this function will return ENXIO.
  9267. **/
  9268. uint32_t
  9269. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9270. {
  9271. LPFC_MBOXQ_t *mbox;
  9272. int rc, length, status = 0;
  9273. uint32_t shdr_status, shdr_add_status;
  9274. union lpfc_sli4_cfg_shdr *shdr;
  9275. if (!cq)
  9276. return -ENODEV;
  9277. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9278. if (!mbox)
  9279. return -ENOMEM;
  9280. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9281. sizeof(struct lpfc_sli4_cfg_mhdr));
  9282. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9283. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9284. length, LPFC_SLI4_MBX_EMBED);
  9285. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9286. cq->queue_id);
  9287. mbox->vport = cq->phba->pport;
  9288. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9289. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9290. /* The IOCTL status is embedded in the mailbox subheader. */
  9291. shdr = (union lpfc_sli4_cfg_shdr *)
  9292. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9293. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9294. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9295. if (shdr_status || shdr_add_status || rc) {
  9296. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9297. "2506 CQ_DESTROY mailbox failed with "
  9298. "status x%x add_status x%x, mbx status x%x\n",
  9299. shdr_status, shdr_add_status, rc);
  9300. status = -ENXIO;
  9301. }
  9302. /* Remove cq from any list */
  9303. list_del_init(&cq->list);
  9304. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9305. return status;
  9306. }
  9307. /**
  9308. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9309. * @qm: The queue structure associated with the queue to destroy.
  9310. *
  9311. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9312. * command, specific to the type of queue, to the HBA.
  9313. *
  9314. * The @mq struct is used to get the queue ID of the queue to destroy.
  9315. *
  9316. * On success this function will return a zero. If the queue destroy mailbox
  9317. * command fails this function will return ENXIO.
  9318. **/
  9319. uint32_t
  9320. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9321. {
  9322. LPFC_MBOXQ_t *mbox;
  9323. int rc, length, status = 0;
  9324. uint32_t shdr_status, shdr_add_status;
  9325. union lpfc_sli4_cfg_shdr *shdr;
  9326. if (!mq)
  9327. return -ENODEV;
  9328. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9329. if (!mbox)
  9330. return -ENOMEM;
  9331. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9332. sizeof(struct lpfc_sli4_cfg_mhdr));
  9333. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9334. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9335. length, LPFC_SLI4_MBX_EMBED);
  9336. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9337. mq->queue_id);
  9338. mbox->vport = mq->phba->pport;
  9339. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9340. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9341. /* The IOCTL status is embedded in the mailbox subheader. */
  9342. shdr = (union lpfc_sli4_cfg_shdr *)
  9343. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9344. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9345. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9346. if (shdr_status || shdr_add_status || rc) {
  9347. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9348. "2507 MQ_DESTROY mailbox failed with "
  9349. "status x%x add_status x%x, mbx status x%x\n",
  9350. shdr_status, shdr_add_status, rc);
  9351. status = -ENXIO;
  9352. }
  9353. /* Remove mq from any list */
  9354. list_del_init(&mq->list);
  9355. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9356. return status;
  9357. }
  9358. /**
  9359. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9360. * @wq: The queue structure associated with the queue to destroy.
  9361. *
  9362. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9363. * command, specific to the type of queue, to the HBA.
  9364. *
  9365. * The @wq struct is used to get the queue ID of the queue to destroy.
  9366. *
  9367. * On success this function will return a zero. If the queue destroy mailbox
  9368. * command fails this function will return ENXIO.
  9369. **/
  9370. uint32_t
  9371. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9372. {
  9373. LPFC_MBOXQ_t *mbox;
  9374. int rc, length, status = 0;
  9375. uint32_t shdr_status, shdr_add_status;
  9376. union lpfc_sli4_cfg_shdr *shdr;
  9377. if (!wq)
  9378. return -ENODEV;
  9379. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9380. if (!mbox)
  9381. return -ENOMEM;
  9382. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9383. sizeof(struct lpfc_sli4_cfg_mhdr));
  9384. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9385. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9386. length, LPFC_SLI4_MBX_EMBED);
  9387. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9388. wq->queue_id);
  9389. mbox->vport = wq->phba->pport;
  9390. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9391. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9392. shdr = (union lpfc_sli4_cfg_shdr *)
  9393. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9394. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9395. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9396. if (shdr_status || shdr_add_status || rc) {
  9397. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9398. "2508 WQ_DESTROY mailbox failed with "
  9399. "status x%x add_status x%x, mbx status x%x\n",
  9400. shdr_status, shdr_add_status, rc);
  9401. status = -ENXIO;
  9402. }
  9403. /* Remove wq from any list */
  9404. list_del_init(&wq->list);
  9405. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9406. return status;
  9407. }
  9408. /**
  9409. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9410. * @rq: The queue structure associated with the queue to destroy.
  9411. *
  9412. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9413. * command, specific to the type of queue, to the HBA.
  9414. *
  9415. * The @rq struct is used to get the queue ID of the queue to destroy.
  9416. *
  9417. * On success this function will return a zero. If the queue destroy mailbox
  9418. * command fails this function will return ENXIO.
  9419. **/
  9420. uint32_t
  9421. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9422. struct lpfc_queue *drq)
  9423. {
  9424. LPFC_MBOXQ_t *mbox;
  9425. int rc, length, status = 0;
  9426. uint32_t shdr_status, shdr_add_status;
  9427. union lpfc_sli4_cfg_shdr *shdr;
  9428. if (!hrq || !drq)
  9429. return -ENODEV;
  9430. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9431. if (!mbox)
  9432. return -ENOMEM;
  9433. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9434. sizeof(struct mbox_header));
  9435. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9436. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9437. length, LPFC_SLI4_MBX_EMBED);
  9438. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9439. hrq->queue_id);
  9440. mbox->vport = hrq->phba->pport;
  9441. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9442. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9443. /* The IOCTL status is embedded in the mailbox subheader. */
  9444. shdr = (union lpfc_sli4_cfg_shdr *)
  9445. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9446. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9447. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9448. if (shdr_status || shdr_add_status || rc) {
  9449. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9450. "2509 RQ_DESTROY mailbox failed with "
  9451. "status x%x add_status x%x, mbx status x%x\n",
  9452. shdr_status, shdr_add_status, rc);
  9453. if (rc != MBX_TIMEOUT)
  9454. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9455. return -ENXIO;
  9456. }
  9457. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9458. drq->queue_id);
  9459. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9460. shdr = (union lpfc_sli4_cfg_shdr *)
  9461. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9462. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9463. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9464. if (shdr_status || shdr_add_status || rc) {
  9465. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9466. "2510 RQ_DESTROY mailbox failed with "
  9467. "status x%x add_status x%x, mbx status x%x\n",
  9468. shdr_status, shdr_add_status, rc);
  9469. status = -ENXIO;
  9470. }
  9471. list_del_init(&hrq->list);
  9472. list_del_init(&drq->list);
  9473. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9474. return status;
  9475. }
  9476. /**
  9477. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9478. * @phba: The virtual port for which this call being executed.
  9479. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9480. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9481. * @xritag: the xritag that ties this io to the SGL pages.
  9482. *
  9483. * This routine will post the sgl pages for the IO that has the xritag
  9484. * that is in the iocbq structure. The xritag is assigned during iocbq
  9485. * creation and persists for as long as the driver is loaded.
  9486. * if the caller has fewer than 256 scatter gather segments to map then
  9487. * pdma_phys_addr1 should be 0.
  9488. * If the caller needs to map more than 256 scatter gather segment then
  9489. * pdma_phys_addr1 should be a valid physical address.
  9490. * physical address for SGLs must be 64 byte aligned.
  9491. * If you are going to map 2 SGL's then the first one must have 256 entries
  9492. * the second sgl can have between 1 and 256 entries.
  9493. *
  9494. * Return codes:
  9495. * 0 - Success
  9496. * -ENXIO, -ENOMEM - Failure
  9497. **/
  9498. int
  9499. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9500. dma_addr_t pdma_phys_addr0,
  9501. dma_addr_t pdma_phys_addr1,
  9502. uint16_t xritag)
  9503. {
  9504. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9505. LPFC_MBOXQ_t *mbox;
  9506. int rc;
  9507. uint32_t shdr_status, shdr_add_status;
  9508. union lpfc_sli4_cfg_shdr *shdr;
  9509. if (xritag == NO_XRI) {
  9510. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9511. "0364 Invalid param:\n");
  9512. return -EINVAL;
  9513. }
  9514. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9515. if (!mbox)
  9516. return -ENOMEM;
  9517. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9518. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9519. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9520. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9521. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9522. &mbox->u.mqe.un.post_sgl_pages;
  9523. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9524. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9525. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9526. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9527. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9528. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9529. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9530. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9531. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9532. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9533. if (!phba->sli4_hba.intr_enable)
  9534. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9535. else
  9536. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9537. /* The IOCTL status is embedded in the mailbox subheader. */
  9538. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9539. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9540. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9541. if (rc != MBX_TIMEOUT)
  9542. mempool_free(mbox, phba->mbox_mem_pool);
  9543. if (shdr_status || shdr_add_status || rc) {
  9544. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9545. "2511 POST_SGL mailbox failed with "
  9546. "status x%x add_status x%x, mbx status x%x\n",
  9547. shdr_status, shdr_add_status, rc);
  9548. rc = -ENXIO;
  9549. }
  9550. return 0;
  9551. }
  9552. /**
  9553. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9554. * @phba: The virtual port for which this call being executed.
  9555. *
  9556. * This routine will remove all of the sgl pages registered with the hba.
  9557. *
  9558. * Return codes:
  9559. * 0 - Success
  9560. * -ENXIO, -ENOMEM - Failure
  9561. **/
  9562. int
  9563. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9564. {
  9565. LPFC_MBOXQ_t *mbox;
  9566. int rc;
  9567. uint32_t shdr_status, shdr_add_status;
  9568. union lpfc_sli4_cfg_shdr *shdr;
  9569. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9570. if (!mbox)
  9571. return -ENOMEM;
  9572. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9573. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9574. LPFC_SLI4_MBX_EMBED);
  9575. if (!phba->sli4_hba.intr_enable)
  9576. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9577. else
  9578. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9579. /* The IOCTL status is embedded in the mailbox subheader. */
  9580. shdr = (union lpfc_sli4_cfg_shdr *)
  9581. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9582. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9583. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9584. if (rc != MBX_TIMEOUT)
  9585. mempool_free(mbox, phba->mbox_mem_pool);
  9586. if (shdr_status || shdr_add_status || rc) {
  9587. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9588. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9589. "status x%x add_status x%x, mbx status x%x\n",
  9590. shdr_status, shdr_add_status, rc);
  9591. rc = -ENXIO;
  9592. }
  9593. return rc;
  9594. }
  9595. /**
  9596. * lpfc_sli4_next_xritag - Get an xritag for the io
  9597. * @phba: Pointer to HBA context object.
  9598. *
  9599. * This function gets an xritag for the iocb. If there is no unused xritag
  9600. * it will return 0xffff.
  9601. * The function returns the allocated xritag if successful, else returns zero.
  9602. * Zero is not a valid xritag.
  9603. * The caller is not required to hold any lock.
  9604. **/
  9605. uint16_t
  9606. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9607. {
  9608. uint16_t xritag;
  9609. spin_lock_irq(&phba->hbalock);
  9610. xritag = phba->sli4_hba.next_xri;
  9611. if ((xritag != (uint16_t) -1) && xritag <
  9612. (phba->sli4_hba.max_cfg_param.max_xri
  9613. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9614. phba->sli4_hba.next_xri++;
  9615. phba->sli4_hba.max_cfg_param.xri_used++;
  9616. spin_unlock_irq(&phba->hbalock);
  9617. return xritag;
  9618. }
  9619. spin_unlock_irq(&phba->hbalock);
  9620. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9621. "2004 Failed to allocate XRI.last XRITAG is %d"
  9622. " Max XRI is %d, Used XRI is %d\n",
  9623. phba->sli4_hba.next_xri,
  9624. phba->sli4_hba.max_cfg_param.max_xri,
  9625. phba->sli4_hba.max_cfg_param.xri_used);
  9626. return -1;
  9627. }
  9628. /**
  9629. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9630. * @phba: pointer to lpfc hba data structure.
  9631. *
  9632. * This routine is invoked to post a block of driver's sgl pages to the
  9633. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9634. * is only called when the driver is loading and after all IO has been
  9635. * stopped.
  9636. **/
  9637. int
  9638. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9639. {
  9640. struct lpfc_sglq *sglq_entry;
  9641. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9642. struct sgl_page_pairs *sgl_pg_pairs;
  9643. void *viraddr;
  9644. LPFC_MBOXQ_t *mbox;
  9645. uint32_t reqlen, alloclen, pg_pairs;
  9646. uint32_t mbox_tmo;
  9647. uint16_t xritag_start = 0;
  9648. int els_xri_cnt, rc = 0;
  9649. uint32_t shdr_status, shdr_add_status;
  9650. union lpfc_sli4_cfg_shdr *shdr;
  9651. /* The number of sgls to be posted */
  9652. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9653. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9654. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9655. if (reqlen > PAGE_SIZE) {
  9656. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9657. "2559 Block sgl registration required DMA "
  9658. "size (%d) great than a page\n", reqlen);
  9659. return -ENOMEM;
  9660. }
  9661. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9662. if (!mbox) {
  9663. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9664. "2560 Failed to allocate mbox cmd memory\n");
  9665. return -ENOMEM;
  9666. }
  9667. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9668. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9669. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9670. LPFC_SLI4_MBX_NEMBED);
  9671. if (alloclen < reqlen) {
  9672. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9673. "0285 Allocated DMA memory size (%d) is "
  9674. "less than the requested DMA memory "
  9675. "size (%d)\n", alloclen, reqlen);
  9676. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9677. return -ENOMEM;
  9678. }
  9679. /* Get the first SGE entry from the non-embedded DMA memory */
  9680. viraddr = mbox->sge_array->addr[0];
  9681. /* Set up the SGL pages in the non-embedded DMA pages */
  9682. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9683. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9684. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9685. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9686. /* Set up the sge entry */
  9687. sgl_pg_pairs->sgl_pg0_addr_lo =
  9688. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9689. sgl_pg_pairs->sgl_pg0_addr_hi =
  9690. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9691. sgl_pg_pairs->sgl_pg1_addr_lo =
  9692. cpu_to_le32(putPaddrLow(0));
  9693. sgl_pg_pairs->sgl_pg1_addr_hi =
  9694. cpu_to_le32(putPaddrHigh(0));
  9695. /* Keep the first xritag on the list */
  9696. if (pg_pairs == 0)
  9697. xritag_start = sglq_entry->sli4_xritag;
  9698. sgl_pg_pairs++;
  9699. }
  9700. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9701. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9702. /* Perform endian conversion if necessary */
  9703. sgl->word0 = cpu_to_le32(sgl->word0);
  9704. if (!phba->sli4_hba.intr_enable)
  9705. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9706. else {
  9707. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9708. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9709. }
  9710. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9711. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9712. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9713. if (rc != MBX_TIMEOUT)
  9714. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9715. if (shdr_status || shdr_add_status || rc) {
  9716. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9717. "2513 POST_SGL_BLOCK mailbox command failed "
  9718. "status x%x add_status x%x mbx status x%x\n",
  9719. shdr_status, shdr_add_status, rc);
  9720. rc = -ENXIO;
  9721. }
  9722. return rc;
  9723. }
  9724. /**
  9725. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9726. * @phba: pointer to lpfc hba data structure.
  9727. * @sblist: pointer to scsi buffer list.
  9728. * @count: number of scsi buffers on the list.
  9729. *
  9730. * This routine is invoked to post a block of @count scsi sgl pages from a
  9731. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9732. * No Lock is held.
  9733. *
  9734. **/
  9735. int
  9736. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9737. int cnt)
  9738. {
  9739. struct lpfc_scsi_buf *psb;
  9740. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9741. struct sgl_page_pairs *sgl_pg_pairs;
  9742. void *viraddr;
  9743. LPFC_MBOXQ_t *mbox;
  9744. uint32_t reqlen, alloclen, pg_pairs;
  9745. uint32_t mbox_tmo;
  9746. uint16_t xritag_start = 0;
  9747. int rc = 0;
  9748. uint32_t shdr_status, shdr_add_status;
  9749. dma_addr_t pdma_phys_bpl1;
  9750. union lpfc_sli4_cfg_shdr *shdr;
  9751. /* Calculate the requested length of the dma memory */
  9752. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9753. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9754. if (reqlen > PAGE_SIZE) {
  9755. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9756. "0217 Block sgl registration required DMA "
  9757. "size (%d) great than a page\n", reqlen);
  9758. return -ENOMEM;
  9759. }
  9760. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9761. if (!mbox) {
  9762. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9763. "0283 Failed to allocate mbox cmd memory\n");
  9764. return -ENOMEM;
  9765. }
  9766. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9767. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9768. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9769. LPFC_SLI4_MBX_NEMBED);
  9770. if (alloclen < reqlen) {
  9771. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9772. "2561 Allocated DMA memory size (%d) is "
  9773. "less than the requested DMA memory "
  9774. "size (%d)\n", alloclen, reqlen);
  9775. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9776. return -ENOMEM;
  9777. }
  9778. /* Get the first SGE entry from the non-embedded DMA memory */
  9779. viraddr = mbox->sge_array->addr[0];
  9780. /* Set up the SGL pages in the non-embedded DMA pages */
  9781. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9782. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9783. pg_pairs = 0;
  9784. list_for_each_entry(psb, sblist, list) {
  9785. /* Set up the sge entry */
  9786. sgl_pg_pairs->sgl_pg0_addr_lo =
  9787. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9788. sgl_pg_pairs->sgl_pg0_addr_hi =
  9789. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9790. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9791. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9792. else
  9793. pdma_phys_bpl1 = 0;
  9794. sgl_pg_pairs->sgl_pg1_addr_lo =
  9795. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9796. sgl_pg_pairs->sgl_pg1_addr_hi =
  9797. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9798. /* Keep the first xritag on the list */
  9799. if (pg_pairs == 0)
  9800. xritag_start = psb->cur_iocbq.sli4_xritag;
  9801. sgl_pg_pairs++;
  9802. pg_pairs++;
  9803. }
  9804. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9805. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9806. /* Perform endian conversion if necessary */
  9807. sgl->word0 = cpu_to_le32(sgl->word0);
  9808. if (!phba->sli4_hba.intr_enable)
  9809. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9810. else {
  9811. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9812. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9813. }
  9814. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9815. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9816. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9817. if (rc != MBX_TIMEOUT)
  9818. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9819. if (shdr_status || shdr_add_status || rc) {
  9820. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9821. "2564 POST_SGL_BLOCK mailbox command failed "
  9822. "status x%x add_status x%x mbx status x%x\n",
  9823. shdr_status, shdr_add_status, rc);
  9824. rc = -ENXIO;
  9825. }
  9826. return rc;
  9827. }
  9828. /**
  9829. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9830. * @phba: pointer to lpfc_hba struct that the frame was received on
  9831. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9832. *
  9833. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9834. * valid type of frame that the LPFC driver will handle. This function will
  9835. * return a zero if the frame is a valid frame or a non zero value when the
  9836. * frame does not pass the check.
  9837. **/
  9838. static int
  9839. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9840. {
  9841. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9842. char *type_names[] = FC_TYPE_NAMES_INIT;
  9843. struct fc_vft_header *fc_vft_hdr;
  9844. switch (fc_hdr->fh_r_ctl) {
  9845. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9846. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9847. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9848. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9849. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9850. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9851. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9852. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9853. case FC_RCTL_ELS_REQ: /* extended link services request */
  9854. case FC_RCTL_ELS_REP: /* extended link services reply */
  9855. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9856. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9857. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9858. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9859. case FC_RCTL_BA_RMC: /* remove connection */
  9860. case FC_RCTL_BA_ACC: /* basic accept */
  9861. case FC_RCTL_BA_RJT: /* basic reject */
  9862. case FC_RCTL_BA_PRMT:
  9863. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9864. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9865. case FC_RCTL_P_RJT: /* port reject */
  9866. case FC_RCTL_F_RJT: /* fabric reject */
  9867. case FC_RCTL_P_BSY: /* port busy */
  9868. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9869. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9870. case FC_RCTL_LCR: /* link credit reset */
  9871. case FC_RCTL_END: /* end */
  9872. break;
  9873. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9874. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9875. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9876. return lpfc_fc_frame_check(phba, fc_hdr);
  9877. default:
  9878. goto drop;
  9879. }
  9880. switch (fc_hdr->fh_type) {
  9881. case FC_TYPE_BLS:
  9882. case FC_TYPE_ELS:
  9883. case FC_TYPE_FCP:
  9884. case FC_TYPE_CT:
  9885. break;
  9886. case FC_TYPE_IP:
  9887. case FC_TYPE_ILS:
  9888. default:
  9889. goto drop;
  9890. }
  9891. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9892. "2538 Received frame rctl:%s type:%s\n",
  9893. rctl_names[fc_hdr->fh_r_ctl],
  9894. type_names[fc_hdr->fh_type]);
  9895. return 0;
  9896. drop:
  9897. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9898. "2539 Dropped frame rctl:%s type:%s\n",
  9899. rctl_names[fc_hdr->fh_r_ctl],
  9900. type_names[fc_hdr->fh_type]);
  9901. return 1;
  9902. }
  9903. /**
  9904. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9905. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9906. *
  9907. * This function processes the FC header to retrieve the VFI from the VF
  9908. * header, if one exists. This function will return the VFI if one exists
  9909. * or 0 if no VSAN Header exists.
  9910. **/
  9911. static uint32_t
  9912. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9913. {
  9914. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9915. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9916. return 0;
  9917. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9918. }
  9919. /**
  9920. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9921. * @phba: Pointer to the HBA structure to search for the vport on
  9922. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9923. * @fcfi: The FC Fabric ID that the frame came from
  9924. *
  9925. * This function searches the @phba for a vport that matches the content of the
  9926. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9927. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9928. * returns the matching vport pointer or NULL if unable to match frame to a
  9929. * vport.
  9930. **/
  9931. static struct lpfc_vport *
  9932. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9933. uint16_t fcfi)
  9934. {
  9935. struct lpfc_vport **vports;
  9936. struct lpfc_vport *vport = NULL;
  9937. int i;
  9938. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9939. fc_hdr->fh_d_id[1] << 8 |
  9940. fc_hdr->fh_d_id[2]);
  9941. vports = lpfc_create_vport_work_array(phba);
  9942. if (vports != NULL)
  9943. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9944. if (phba->fcf.fcfi == fcfi &&
  9945. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9946. vports[i]->fc_myDID == did) {
  9947. vport = vports[i];
  9948. break;
  9949. }
  9950. }
  9951. lpfc_destroy_vport_work_array(phba, vports);
  9952. return vport;
  9953. }
  9954. /**
  9955. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  9956. * @vport: The vport to work on.
  9957. *
  9958. * This function updates the receive sequence time stamp for this vport. The
  9959. * receive sequence time stamp indicates the time that the last frame of the
  9960. * the sequence that has been idle for the longest amount of time was received.
  9961. * the driver uses this time stamp to indicate if any received sequences have
  9962. * timed out.
  9963. **/
  9964. void
  9965. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  9966. {
  9967. struct lpfc_dmabuf *h_buf;
  9968. struct hbq_dmabuf *dmabuf = NULL;
  9969. /* get the oldest sequence on the rcv list */
  9970. h_buf = list_get_first(&vport->rcv_buffer_list,
  9971. struct lpfc_dmabuf, list);
  9972. if (!h_buf)
  9973. return;
  9974. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9975. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  9976. }
  9977. /**
  9978. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  9979. * @vport: The vport that the received sequences were sent to.
  9980. *
  9981. * This function cleans up all outstanding received sequences. This is called
  9982. * by the driver when a link event or user action invalidates all the received
  9983. * sequences.
  9984. **/
  9985. void
  9986. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  9987. {
  9988. struct lpfc_dmabuf *h_buf, *hnext;
  9989. struct lpfc_dmabuf *d_buf, *dnext;
  9990. struct hbq_dmabuf *dmabuf = NULL;
  9991. /* start with the oldest sequence on the rcv list */
  9992. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  9993. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9994. list_del_init(&dmabuf->hbuf.list);
  9995. list_for_each_entry_safe(d_buf, dnext,
  9996. &dmabuf->dbuf.list, list) {
  9997. list_del_init(&d_buf->list);
  9998. lpfc_in_buf_free(vport->phba, d_buf);
  9999. }
  10000. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10001. }
  10002. }
  10003. /**
  10004. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10005. * @vport: The vport that the received sequences were sent to.
  10006. *
  10007. * This function determines whether any received sequences have timed out by
  10008. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10009. * indicates that there is at least one timed out sequence this routine will
  10010. * go through the received sequences one at a time from most inactive to most
  10011. * active to determine which ones need to be cleaned up. Once it has determined
  10012. * that a sequence needs to be cleaned up it will simply free up the resources
  10013. * without sending an abort.
  10014. **/
  10015. void
  10016. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10017. {
  10018. struct lpfc_dmabuf *h_buf, *hnext;
  10019. struct lpfc_dmabuf *d_buf, *dnext;
  10020. struct hbq_dmabuf *dmabuf = NULL;
  10021. unsigned long timeout;
  10022. int abort_count = 0;
  10023. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10024. vport->rcv_buffer_time_stamp);
  10025. if (list_empty(&vport->rcv_buffer_list) ||
  10026. time_before(jiffies, timeout))
  10027. return;
  10028. /* start with the oldest sequence on the rcv list */
  10029. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10030. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10031. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10032. dmabuf->time_stamp);
  10033. if (time_before(jiffies, timeout))
  10034. break;
  10035. abort_count++;
  10036. list_del_init(&dmabuf->hbuf.list);
  10037. list_for_each_entry_safe(d_buf, dnext,
  10038. &dmabuf->dbuf.list, list) {
  10039. list_del_init(&d_buf->list);
  10040. lpfc_in_buf_free(vport->phba, d_buf);
  10041. }
  10042. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10043. }
  10044. if (abort_count)
  10045. lpfc_update_rcv_time_stamp(vport);
  10046. }
  10047. /**
  10048. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10049. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10050. *
  10051. * This function searches through the existing incomplete sequences that have
  10052. * been sent to this @vport. If the frame matches one of the incomplete
  10053. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10054. * make up that sequence. If no sequence is found that matches this frame then
  10055. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10056. * This function returns a pointer to the first dmabuf in the sequence list that
  10057. * the frame was linked to.
  10058. **/
  10059. static struct hbq_dmabuf *
  10060. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10061. {
  10062. struct fc_frame_header *new_hdr;
  10063. struct fc_frame_header *temp_hdr;
  10064. struct lpfc_dmabuf *d_buf;
  10065. struct lpfc_dmabuf *h_buf;
  10066. struct hbq_dmabuf *seq_dmabuf = NULL;
  10067. struct hbq_dmabuf *temp_dmabuf = NULL;
  10068. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10069. dmabuf->time_stamp = jiffies;
  10070. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10071. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10072. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10073. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10074. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10075. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10076. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10077. continue;
  10078. /* found a pending sequence that matches this frame */
  10079. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10080. break;
  10081. }
  10082. if (!seq_dmabuf) {
  10083. /*
  10084. * This indicates first frame received for this sequence.
  10085. * Queue the buffer on the vport's rcv_buffer_list.
  10086. */
  10087. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10088. lpfc_update_rcv_time_stamp(vport);
  10089. return dmabuf;
  10090. }
  10091. temp_hdr = seq_dmabuf->hbuf.virt;
  10092. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10093. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10094. list_del_init(&seq_dmabuf->hbuf.list);
  10095. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10096. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10097. lpfc_update_rcv_time_stamp(vport);
  10098. return dmabuf;
  10099. }
  10100. /* move this sequence to the tail to indicate a young sequence */
  10101. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10102. seq_dmabuf->time_stamp = jiffies;
  10103. lpfc_update_rcv_time_stamp(vport);
  10104. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10105. temp_hdr = dmabuf->hbuf.virt;
  10106. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10107. return seq_dmabuf;
  10108. }
  10109. /* find the correct place in the sequence to insert this frame */
  10110. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10111. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10112. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10113. /*
  10114. * If the frame's sequence count is greater than the frame on
  10115. * the list then insert the frame right after this frame
  10116. */
  10117. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10118. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10119. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10120. return seq_dmabuf;
  10121. }
  10122. }
  10123. return NULL;
  10124. }
  10125. /**
  10126. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10127. * @vport: pointer to a vitural port
  10128. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10129. *
  10130. * This function tries to abort from the partially assembed sequence, described
  10131. * by the information from basic abbort @dmabuf. It checks to see whether such
  10132. * partially assembled sequence held by the driver. If so, it shall free up all
  10133. * the frames from the partially assembled sequence.
  10134. *
  10135. * Return
  10136. * true -- if there is matching partially assembled sequence present and all
  10137. * the frames freed with the sequence;
  10138. * false -- if there is no matching partially assembled sequence present so
  10139. * nothing got aborted in the lower layer driver
  10140. **/
  10141. static bool
  10142. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10143. struct hbq_dmabuf *dmabuf)
  10144. {
  10145. struct fc_frame_header *new_hdr;
  10146. struct fc_frame_header *temp_hdr;
  10147. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10148. struct hbq_dmabuf *seq_dmabuf = NULL;
  10149. /* Use the hdr_buf to find the sequence that matches this frame */
  10150. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10151. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10152. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10153. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10154. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10155. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10156. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10157. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10158. continue;
  10159. /* found a pending sequence that matches this frame */
  10160. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10161. break;
  10162. }
  10163. /* Free up all the frames from the partially assembled sequence */
  10164. if (seq_dmabuf) {
  10165. list_for_each_entry_safe(d_buf, n_buf,
  10166. &seq_dmabuf->dbuf.list, list) {
  10167. list_del_init(&d_buf->list);
  10168. lpfc_in_buf_free(vport->phba, d_buf);
  10169. }
  10170. return true;
  10171. }
  10172. return false;
  10173. }
  10174. /**
  10175. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10176. * @phba: Pointer to HBA context object.
  10177. * @cmd_iocbq: pointer to the command iocbq structure.
  10178. * @rsp_iocbq: pointer to the response iocbq structure.
  10179. *
  10180. * This function handles the sequence abort accept iocb command complete
  10181. * event. It properly releases the memory allocated to the sequence abort
  10182. * accept iocb.
  10183. **/
  10184. static void
  10185. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10186. struct lpfc_iocbq *cmd_iocbq,
  10187. struct lpfc_iocbq *rsp_iocbq)
  10188. {
  10189. if (cmd_iocbq)
  10190. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10191. }
  10192. /**
  10193. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10194. * @phba: Pointer to HBA context object.
  10195. * @fc_hdr: pointer to a FC frame header.
  10196. *
  10197. * This function sends a basic accept to a previous unsol sequence abort
  10198. * event after aborting the sequence handling.
  10199. **/
  10200. static void
  10201. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10202. struct fc_frame_header *fc_hdr)
  10203. {
  10204. struct lpfc_iocbq *ctiocb = NULL;
  10205. struct lpfc_nodelist *ndlp;
  10206. uint16_t oxid, rxid;
  10207. uint32_t sid, fctl;
  10208. IOCB_t *icmd;
  10209. if (!lpfc_is_link_up(phba))
  10210. return;
  10211. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10212. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10213. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10214. ndlp = lpfc_findnode_did(phba->pport, sid);
  10215. if (!ndlp) {
  10216. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10217. "1268 Find ndlp returned NULL for oxid:x%x "
  10218. "SID:x%x\n", oxid, sid);
  10219. return;
  10220. }
  10221. /* Allocate buffer for acc iocb */
  10222. ctiocb = lpfc_sli_get_iocbq(phba);
  10223. if (!ctiocb)
  10224. return;
  10225. /* Extract the F_CTL field from FC_HDR */
  10226. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10227. icmd = &ctiocb->iocb;
  10228. icmd->un.xseq64.bdl.bdeSize = 0;
  10229. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10230. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10231. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10232. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10233. /* Fill in the rest of iocb fields */
  10234. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10235. icmd->ulpBdeCount = 0;
  10236. icmd->ulpLe = 1;
  10237. icmd->ulpClass = CLASS3;
  10238. icmd->ulpContext = ndlp->nlp_rpi;
  10239. ctiocb->iocb_cmpl = NULL;
  10240. ctiocb->vport = phba->pport;
  10241. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10242. if (fctl & FC_FC_EX_CTX) {
  10243. /* ABTS sent by responder to CT exchange, construction
  10244. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10245. * field and RX_ID from ABTS for RX_ID field.
  10246. */
  10247. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10248. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10249. ctiocb->sli4_xritag = oxid;
  10250. } else {
  10251. /* ABTS sent by initiator to CT exchange, construction
  10252. * of BA_ACC will need to allocate a new XRI as for the
  10253. * XRI_TAG and RX_ID fields.
  10254. */
  10255. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10256. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10257. ctiocb->sli4_xritag = NO_XRI;
  10258. }
  10259. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10260. /* Xmit CT abts accept on exchange <xid> */
  10261. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10262. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10263. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10264. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10265. }
  10266. /**
  10267. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10268. * @vport: Pointer to the vport on which this sequence was received
  10269. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10270. *
  10271. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10272. * receive sequence is only partially assembed by the driver, it shall abort
  10273. * the partially assembled frames for the sequence. Otherwise, if the
  10274. * unsolicited receive sequence has been completely assembled and passed to
  10275. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10276. * unsolicited sequence has been aborted. After that, it will issue a basic
  10277. * accept to accept the abort.
  10278. **/
  10279. void
  10280. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10281. struct hbq_dmabuf *dmabuf)
  10282. {
  10283. struct lpfc_hba *phba = vport->phba;
  10284. struct fc_frame_header fc_hdr;
  10285. uint32_t fctl;
  10286. bool abts_par;
  10287. /* Make a copy of fc_hdr before the dmabuf being released */
  10288. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10289. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10290. if (fctl & FC_FC_EX_CTX) {
  10291. /*
  10292. * ABTS sent by responder to exchange, just free the buffer
  10293. */
  10294. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10295. } else {
  10296. /*
  10297. * ABTS sent by initiator to exchange, need to do cleanup
  10298. */
  10299. /* Try to abort partially assembled seq */
  10300. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10301. /* Send abort to ULP if partially seq abort failed */
  10302. if (abts_par == false)
  10303. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10304. else
  10305. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10306. }
  10307. /* Send basic accept (BA_ACC) to the abort requester */
  10308. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10309. }
  10310. /**
  10311. * lpfc_seq_complete - Indicates if a sequence is complete
  10312. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10313. *
  10314. * This function checks the sequence, starting with the frame described by
  10315. * @dmabuf, to see if all the frames associated with this sequence are present.
  10316. * the frames associated with this sequence are linked to the @dmabuf using the
  10317. * dbuf list. This function looks for two major things. 1) That the first frame
  10318. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10319. * set. 3) That there are no holes in the sequence count. The function will
  10320. * return 1 when the sequence is complete, otherwise it will return 0.
  10321. **/
  10322. static int
  10323. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10324. {
  10325. struct fc_frame_header *hdr;
  10326. struct lpfc_dmabuf *d_buf;
  10327. struct hbq_dmabuf *seq_dmabuf;
  10328. uint32_t fctl;
  10329. int seq_count = 0;
  10330. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10331. /* make sure first fame of sequence has a sequence count of zero */
  10332. if (hdr->fh_seq_cnt != seq_count)
  10333. return 0;
  10334. fctl = (hdr->fh_f_ctl[0] << 16 |
  10335. hdr->fh_f_ctl[1] << 8 |
  10336. hdr->fh_f_ctl[2]);
  10337. /* If last frame of sequence we can return success. */
  10338. if (fctl & FC_FC_END_SEQ)
  10339. return 1;
  10340. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10341. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10342. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10343. /* If there is a hole in the sequence count then fail. */
  10344. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10345. return 0;
  10346. fctl = (hdr->fh_f_ctl[0] << 16 |
  10347. hdr->fh_f_ctl[1] << 8 |
  10348. hdr->fh_f_ctl[2]);
  10349. /* If last frame of sequence we can return success. */
  10350. if (fctl & FC_FC_END_SEQ)
  10351. return 1;
  10352. }
  10353. return 0;
  10354. }
  10355. /**
  10356. * lpfc_prep_seq - Prep sequence for ULP processing
  10357. * @vport: Pointer to the vport on which this sequence was received
  10358. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10359. *
  10360. * This function takes a sequence, described by a list of frames, and creates
  10361. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10362. * used to issue to the generic unsolicited sequence handler. This routine
  10363. * returns a pointer to the first iocbq in the list. If the function is unable
  10364. * to allocate an iocbq then it throw out the received frames that were not
  10365. * able to be described and return a pointer to the first iocbq. If unable to
  10366. * allocate any iocbqs (including the first) this function will return NULL.
  10367. **/
  10368. static struct lpfc_iocbq *
  10369. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10370. {
  10371. struct lpfc_dmabuf *d_buf, *n_buf;
  10372. struct lpfc_iocbq *first_iocbq, *iocbq;
  10373. struct fc_frame_header *fc_hdr;
  10374. uint32_t sid;
  10375. struct ulp_bde64 *pbde;
  10376. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10377. /* remove from receive buffer list */
  10378. list_del_init(&seq_dmabuf->hbuf.list);
  10379. lpfc_update_rcv_time_stamp(vport);
  10380. /* get the Remote Port's SID */
  10381. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10382. /* Get an iocbq struct to fill in. */
  10383. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10384. if (first_iocbq) {
  10385. /* Initialize the first IOCB. */
  10386. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10387. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10388. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10389. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10390. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10391. vport->vpi + vport->phba->vpi_base;
  10392. /* put the first buffer into the first IOCBq */
  10393. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10394. first_iocbq->context3 = NULL;
  10395. first_iocbq->iocb.ulpBdeCount = 1;
  10396. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10397. LPFC_DATA_BUF_SIZE;
  10398. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10399. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10400. bf_get(lpfc_rcqe_length,
  10401. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10402. }
  10403. iocbq = first_iocbq;
  10404. /*
  10405. * Each IOCBq can have two Buffers assigned, so go through the list
  10406. * of buffers for this sequence and save two buffers in each IOCBq
  10407. */
  10408. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10409. if (!iocbq) {
  10410. lpfc_in_buf_free(vport->phba, d_buf);
  10411. continue;
  10412. }
  10413. if (!iocbq->context3) {
  10414. iocbq->context3 = d_buf;
  10415. iocbq->iocb.ulpBdeCount++;
  10416. pbde = (struct ulp_bde64 *)
  10417. &iocbq->iocb.unsli3.sli3Words[4];
  10418. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10419. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10420. bf_get(lpfc_rcqe_length,
  10421. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10422. } else {
  10423. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10424. if (!iocbq) {
  10425. if (first_iocbq) {
  10426. first_iocbq->iocb.ulpStatus =
  10427. IOSTAT_FCP_RSP_ERROR;
  10428. first_iocbq->iocb.un.ulpWord[4] =
  10429. IOERR_NO_RESOURCES;
  10430. }
  10431. lpfc_in_buf_free(vport->phba, d_buf);
  10432. continue;
  10433. }
  10434. iocbq->context2 = d_buf;
  10435. iocbq->context3 = NULL;
  10436. iocbq->iocb.ulpBdeCount = 1;
  10437. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10438. LPFC_DATA_BUF_SIZE;
  10439. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10440. bf_get(lpfc_rcqe_length,
  10441. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10442. iocbq->iocb.un.rcvels.remoteID = sid;
  10443. list_add_tail(&iocbq->list, &first_iocbq->list);
  10444. }
  10445. }
  10446. return first_iocbq;
  10447. }
  10448. static void
  10449. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10450. struct hbq_dmabuf *seq_dmabuf)
  10451. {
  10452. struct fc_frame_header *fc_hdr;
  10453. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10454. struct lpfc_hba *phba = vport->phba;
  10455. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10456. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10457. if (!iocbq) {
  10458. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10459. "2707 Ring %d handler: Failed to allocate "
  10460. "iocb Rctl x%x Type x%x received\n",
  10461. LPFC_ELS_RING,
  10462. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10463. return;
  10464. }
  10465. if (!lpfc_complete_unsol_iocb(phba,
  10466. &phba->sli.ring[LPFC_ELS_RING],
  10467. iocbq, fc_hdr->fh_r_ctl,
  10468. fc_hdr->fh_type))
  10469. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10470. "2540 Ring %d handler: unexpected Rctl "
  10471. "x%x Type x%x received\n",
  10472. LPFC_ELS_RING,
  10473. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10474. /* Free iocb created in lpfc_prep_seq */
  10475. list_for_each_entry_safe(curr_iocb, next_iocb,
  10476. &iocbq->list, list) {
  10477. list_del_init(&curr_iocb->list);
  10478. lpfc_sli_release_iocbq(phba, curr_iocb);
  10479. }
  10480. lpfc_sli_release_iocbq(phba, iocbq);
  10481. }
  10482. /**
  10483. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10484. * @phba: Pointer to HBA context object.
  10485. *
  10486. * This function is called with no lock held. This function processes all
  10487. * the received buffers and gives it to upper layers when a received buffer
  10488. * indicates that it is the final frame in the sequence. The interrupt
  10489. * service routine processes received buffers at interrupt contexts and adds
  10490. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10491. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10492. * appropriate receive function when the final frame in a sequence is received.
  10493. **/
  10494. void
  10495. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10496. struct hbq_dmabuf *dmabuf)
  10497. {
  10498. struct hbq_dmabuf *seq_dmabuf;
  10499. struct fc_frame_header *fc_hdr;
  10500. struct lpfc_vport *vport;
  10501. uint32_t fcfi;
  10502. /* Process each received buffer */
  10503. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10504. /* check to see if this a valid type of frame */
  10505. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10506. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10507. return;
  10508. }
  10509. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10510. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10511. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10512. /* throw out the frame */
  10513. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10514. return;
  10515. }
  10516. /* Handle the basic abort sequence (BA_ABTS) event */
  10517. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10518. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10519. return;
  10520. }
  10521. /* Link this frame */
  10522. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10523. if (!seq_dmabuf) {
  10524. /* unable to add frame to vport - throw it out */
  10525. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10526. return;
  10527. }
  10528. /* If not last frame in sequence continue processing frames. */
  10529. if (!lpfc_seq_complete(seq_dmabuf))
  10530. return;
  10531. /* Send the complete sequence to the upper layer protocol */
  10532. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10533. }
  10534. /**
  10535. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10536. * @phba: pointer to lpfc hba data structure.
  10537. *
  10538. * This routine is invoked to post rpi header templates to the
  10539. * HBA consistent with the SLI-4 interface spec. This routine
  10540. * posts a PAGE_SIZE memory region to the port to hold up to
  10541. * PAGE_SIZE modulo 64 rpi context headers.
  10542. *
  10543. * This routine does not require any locks. It's usage is expected
  10544. * to be driver load or reset recovery when the driver is
  10545. * sequential.
  10546. *
  10547. * Return codes
  10548. * 0 - successful
  10549. * EIO - The mailbox failed to complete successfully.
  10550. * When this error occurs, the driver is not guaranteed
  10551. * to have any rpi regions posted to the device and
  10552. * must either attempt to repost the regions or take a
  10553. * fatal error.
  10554. **/
  10555. int
  10556. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10557. {
  10558. struct lpfc_rpi_hdr *rpi_page;
  10559. uint32_t rc = 0;
  10560. /* Post all rpi memory regions to the port. */
  10561. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10562. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10563. if (rc != MBX_SUCCESS) {
  10564. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10565. "2008 Error %d posting all rpi "
  10566. "headers\n", rc);
  10567. rc = -EIO;
  10568. break;
  10569. }
  10570. }
  10571. return rc;
  10572. }
  10573. /**
  10574. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10575. * @phba: pointer to lpfc hba data structure.
  10576. * @rpi_page: pointer to the rpi memory region.
  10577. *
  10578. * This routine is invoked to post a single rpi header to the
  10579. * HBA consistent with the SLI-4 interface spec. This memory region
  10580. * maps up to 64 rpi context regions.
  10581. *
  10582. * Return codes
  10583. * 0 - successful
  10584. * ENOMEM - No available memory
  10585. * EIO - The mailbox failed to complete successfully.
  10586. **/
  10587. int
  10588. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10589. {
  10590. LPFC_MBOXQ_t *mboxq;
  10591. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10592. uint32_t rc = 0;
  10593. uint32_t mbox_tmo;
  10594. uint32_t shdr_status, shdr_add_status;
  10595. union lpfc_sli4_cfg_shdr *shdr;
  10596. /* The port is notified of the header region via a mailbox command. */
  10597. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10598. if (!mboxq) {
  10599. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10600. "2001 Unable to allocate memory for issuing "
  10601. "SLI_CONFIG_SPECIAL mailbox command\n");
  10602. return -ENOMEM;
  10603. }
  10604. /* Post all rpi memory regions to the port. */
  10605. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10606. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10607. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10608. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10609. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10610. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10611. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10612. hdr_tmpl, rpi_page->page_count);
  10613. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10614. rpi_page->start_rpi);
  10615. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10616. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10617. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10618. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10619. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10620. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10621. if (rc != MBX_TIMEOUT)
  10622. mempool_free(mboxq, phba->mbox_mem_pool);
  10623. if (shdr_status || shdr_add_status || rc) {
  10624. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10625. "2514 POST_RPI_HDR mailbox failed with "
  10626. "status x%x add_status x%x, mbx status x%x\n",
  10627. shdr_status, shdr_add_status, rc);
  10628. rc = -ENXIO;
  10629. }
  10630. return rc;
  10631. }
  10632. /**
  10633. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10634. * @phba: pointer to lpfc hba data structure.
  10635. *
  10636. * This routine is invoked to post rpi header templates to the
  10637. * HBA consistent with the SLI-4 interface spec. This routine
  10638. * posts a PAGE_SIZE memory region to the port to hold up to
  10639. * PAGE_SIZE modulo 64 rpi context headers.
  10640. *
  10641. * Returns
  10642. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10643. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10644. **/
  10645. int
  10646. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10647. {
  10648. int rpi;
  10649. uint16_t max_rpi, rpi_base, rpi_limit;
  10650. uint16_t rpi_remaining;
  10651. struct lpfc_rpi_hdr *rpi_hdr;
  10652. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10653. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10654. rpi_limit = phba->sli4_hba.next_rpi;
  10655. /*
  10656. * The valid rpi range is not guaranteed to be zero-based. Start
  10657. * the search at the rpi_base as reported by the port.
  10658. */
  10659. spin_lock_irq(&phba->hbalock);
  10660. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10661. if (rpi >= rpi_limit || rpi < rpi_base)
  10662. rpi = LPFC_RPI_ALLOC_ERROR;
  10663. else {
  10664. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10665. phba->sli4_hba.max_cfg_param.rpi_used++;
  10666. phba->sli4_hba.rpi_count++;
  10667. }
  10668. /*
  10669. * Don't try to allocate more rpi header regions if the device limit
  10670. * on available rpis max has been exhausted.
  10671. */
  10672. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10673. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10674. spin_unlock_irq(&phba->hbalock);
  10675. return rpi;
  10676. }
  10677. /*
  10678. * If the driver is running low on rpi resources, allocate another
  10679. * page now. Note that the next_rpi value is used because
  10680. * it represents how many are actually in use whereas max_rpi notes
  10681. * how many are supported max by the device.
  10682. */
  10683. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10684. phba->sli4_hba.rpi_count;
  10685. spin_unlock_irq(&phba->hbalock);
  10686. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10687. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10688. if (!rpi_hdr) {
  10689. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10690. "2002 Error Could not grow rpi "
  10691. "count\n");
  10692. } else {
  10693. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10694. }
  10695. }
  10696. return rpi;
  10697. }
  10698. /**
  10699. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10700. * @phba: pointer to lpfc hba data structure.
  10701. *
  10702. * This routine is invoked to release an rpi to the pool of
  10703. * available rpis maintained by the driver.
  10704. **/
  10705. void
  10706. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10707. {
  10708. spin_lock_irq(&phba->hbalock);
  10709. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10710. phba->sli4_hba.rpi_count--;
  10711. phba->sli4_hba.max_cfg_param.rpi_used--;
  10712. spin_unlock_irq(&phba->hbalock);
  10713. }
  10714. /**
  10715. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10716. * @phba: pointer to lpfc hba data structure.
  10717. *
  10718. * This routine is invoked to remove the memory region that
  10719. * provided rpi via a bitmask.
  10720. **/
  10721. void
  10722. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10723. {
  10724. kfree(phba->sli4_hba.rpi_bmask);
  10725. }
  10726. /**
  10727. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10728. * @phba: pointer to lpfc hba data structure.
  10729. *
  10730. * This routine is invoked to remove the memory region that
  10731. * provided rpi via a bitmask.
  10732. **/
  10733. int
  10734. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10735. {
  10736. LPFC_MBOXQ_t *mboxq;
  10737. struct lpfc_hba *phba = ndlp->phba;
  10738. int rc;
  10739. /* The port is notified of the header region via a mailbox command. */
  10740. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10741. if (!mboxq)
  10742. return -ENOMEM;
  10743. /* Post all rpi memory regions to the port. */
  10744. lpfc_resume_rpi(mboxq, ndlp);
  10745. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10746. if (rc == MBX_NOT_FINISHED) {
  10747. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10748. "2010 Resume RPI Mailbox failed "
  10749. "status %d, mbxStatus x%x\n", rc,
  10750. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10751. mempool_free(mboxq, phba->mbox_mem_pool);
  10752. return -EIO;
  10753. }
  10754. return 0;
  10755. }
  10756. /**
  10757. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10758. * @phba: pointer to lpfc hba data structure.
  10759. * @vpi: vpi value to activate with the port.
  10760. *
  10761. * This routine is invoked to activate a vpi with the
  10762. * port when the host intends to use vports with a
  10763. * nonzero vpi.
  10764. *
  10765. * Returns:
  10766. * 0 success
  10767. * -Evalue otherwise
  10768. **/
  10769. int
  10770. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10771. {
  10772. LPFC_MBOXQ_t *mboxq;
  10773. int rc = 0;
  10774. int retval = MBX_SUCCESS;
  10775. uint32_t mbox_tmo;
  10776. if (vpi == 0)
  10777. return -EINVAL;
  10778. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10779. if (!mboxq)
  10780. return -ENOMEM;
  10781. lpfc_init_vpi(phba, mboxq, vpi);
  10782. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10783. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10784. if (rc != MBX_SUCCESS) {
  10785. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10786. "2022 INIT VPI Mailbox failed "
  10787. "status %d, mbxStatus x%x\n", rc,
  10788. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10789. retval = -EIO;
  10790. }
  10791. if (rc != MBX_TIMEOUT)
  10792. mempool_free(mboxq, phba->mbox_mem_pool);
  10793. return retval;
  10794. }
  10795. /**
  10796. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10797. * @phba: pointer to lpfc hba data structure.
  10798. * @mboxq: Pointer to mailbox object.
  10799. *
  10800. * This routine is invoked to manually add a single FCF record. The caller
  10801. * must pass a completely initialized FCF_Record. This routine takes
  10802. * care of the nonembedded mailbox operations.
  10803. **/
  10804. static void
  10805. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10806. {
  10807. void *virt_addr;
  10808. union lpfc_sli4_cfg_shdr *shdr;
  10809. uint32_t shdr_status, shdr_add_status;
  10810. virt_addr = mboxq->sge_array->addr[0];
  10811. /* The IOCTL status is embedded in the mailbox subheader. */
  10812. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10813. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10814. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10815. if ((shdr_status || shdr_add_status) &&
  10816. (shdr_status != STATUS_FCF_IN_USE))
  10817. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10818. "2558 ADD_FCF_RECORD mailbox failed with "
  10819. "status x%x add_status x%x\n",
  10820. shdr_status, shdr_add_status);
  10821. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10822. }
  10823. /**
  10824. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10825. * @phba: pointer to lpfc hba data structure.
  10826. * @fcf_record: pointer to the initialized fcf record to add.
  10827. *
  10828. * This routine is invoked to manually add a single FCF record. The caller
  10829. * must pass a completely initialized FCF_Record. This routine takes
  10830. * care of the nonembedded mailbox operations.
  10831. **/
  10832. int
  10833. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10834. {
  10835. int rc = 0;
  10836. LPFC_MBOXQ_t *mboxq;
  10837. uint8_t *bytep;
  10838. void *virt_addr;
  10839. dma_addr_t phys_addr;
  10840. struct lpfc_mbx_sge sge;
  10841. uint32_t alloc_len, req_len;
  10842. uint32_t fcfindex;
  10843. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10844. if (!mboxq) {
  10845. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10846. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10847. return -ENOMEM;
  10848. }
  10849. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10850. sizeof(uint32_t);
  10851. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10852. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10853. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10854. req_len, LPFC_SLI4_MBX_NEMBED);
  10855. if (alloc_len < req_len) {
  10856. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10857. "2523 Allocated DMA memory size (x%x) is "
  10858. "less than the requested DMA memory "
  10859. "size (x%x)\n", alloc_len, req_len);
  10860. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10861. return -ENOMEM;
  10862. }
  10863. /*
  10864. * Get the first SGE entry from the non-embedded DMA memory. This
  10865. * routine only uses a single SGE.
  10866. */
  10867. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10868. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10869. virt_addr = mboxq->sge_array->addr[0];
  10870. /*
  10871. * Configure the FCF record for FCFI 0. This is the driver's
  10872. * hardcoded default and gets used in nonFIP mode.
  10873. */
  10874. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10875. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10876. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10877. /*
  10878. * Copy the fcf_index and the FCF Record Data. The data starts after
  10879. * the FCoE header plus word10. The data copy needs to be endian
  10880. * correct.
  10881. */
  10882. bytep += sizeof(uint32_t);
  10883. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10884. mboxq->vport = phba->pport;
  10885. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10886. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10887. if (rc == MBX_NOT_FINISHED) {
  10888. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10889. "2515 ADD_FCF_RECORD mailbox failed with "
  10890. "status 0x%x\n", rc);
  10891. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10892. rc = -EIO;
  10893. } else
  10894. rc = 0;
  10895. return rc;
  10896. }
  10897. /**
  10898. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10899. * @phba: pointer to lpfc hba data structure.
  10900. * @fcf_record: pointer to the fcf record to write the default data.
  10901. * @fcf_index: FCF table entry index.
  10902. *
  10903. * This routine is invoked to build the driver's default FCF record. The
  10904. * values used are hardcoded. This routine handles memory initialization.
  10905. *
  10906. **/
  10907. void
  10908. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10909. struct fcf_record *fcf_record,
  10910. uint16_t fcf_index)
  10911. {
  10912. memset(fcf_record, 0, sizeof(struct fcf_record));
  10913. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10914. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10915. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10916. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10917. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10918. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10919. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10920. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10921. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10922. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10923. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10924. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10925. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10926. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  10927. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10928. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10929. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10930. /* Set the VLAN bit map */
  10931. if (phba->valid_vlan) {
  10932. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10933. = 1 << (phba->vlan_id % 8);
  10934. }
  10935. }
  10936. /**
  10937. * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
  10938. * @phba: pointer to lpfc hba data structure.
  10939. * @fcf_index: FCF table entry offset.
  10940. *
  10941. * This routine is invoked to read up to @fcf_num of FCF record from the
  10942. * device starting with the given @fcf_index.
  10943. **/
  10944. int
  10945. lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
  10946. {
  10947. int rc = 0, error;
  10948. LPFC_MBOXQ_t *mboxq;
  10949. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  10950. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10951. if (!mboxq) {
  10952. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10953. "2000 Failed to allocate mbox for "
  10954. "READ_FCF cmd\n");
  10955. error = -ENOMEM;
  10956. goto fail_fcfscan;
  10957. }
  10958. /* Construct the read FCF record mailbox command */
  10959. rc = lpfc_sli4_mbx_read_fcf_record(phba, mboxq, fcf_index);
  10960. if (rc) {
  10961. error = -EINVAL;
  10962. goto fail_fcfscan;
  10963. }
  10964. /* Issue the mailbox command asynchronously */
  10965. mboxq->vport = phba->pport;
  10966. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
  10967. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10968. if (rc == MBX_NOT_FINISHED)
  10969. error = -EIO;
  10970. else {
  10971. spin_lock_irq(&phba->hbalock);
  10972. phba->hba_flag |= FCF_DISC_INPROGRESS;
  10973. spin_unlock_irq(&phba->hbalock);
  10974. error = 0;
  10975. }
  10976. fail_fcfscan:
  10977. if (error) {
  10978. if (mboxq)
  10979. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10980. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  10981. spin_lock_irq(&phba->hbalock);
  10982. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  10983. spin_unlock_irq(&phba->hbalock);
  10984. }
  10985. return error;
  10986. }
  10987. /**
  10988. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  10989. * @phba: pointer to lpfc hba data structure.
  10990. *
  10991. * This routine is the completion routine for the rediscover FCF table mailbox
  10992. * command. If the mailbox command returned failure, it will try to stop the
  10993. * FCF rediscover wait timer.
  10994. **/
  10995. void
  10996. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  10997. {
  10998. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  10999. uint32_t shdr_status, shdr_add_status;
  11000. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11001. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11002. &redisc_fcf->header.cfg_shdr.response);
  11003. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11004. &redisc_fcf->header.cfg_shdr.response);
  11005. if (shdr_status || shdr_add_status) {
  11006. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11007. "2746 Requesting for FCF rediscovery failed "
  11008. "status x%x add_status x%x\n",
  11009. shdr_status, shdr_add_status);
  11010. /*
  11011. * Request failed, last resort to re-try current
  11012. * registered FCF entry
  11013. */
  11014. lpfc_retry_pport_discovery(phba);
  11015. } else
  11016. /*
  11017. * Start FCF rediscovery wait timer for pending FCF
  11018. * before rescan FCF record table.
  11019. */
  11020. lpfc_fcf_redisc_wait_start_timer(phba);
  11021. mempool_free(mbox, phba->mbox_mem_pool);
  11022. }
  11023. /**
  11024. * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
  11025. * @phba: pointer to lpfc hba data structure.
  11026. *
  11027. * This routine is invoked to request for rediscovery of the entire FCF table
  11028. * by the port.
  11029. **/
  11030. int
  11031. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11032. {
  11033. LPFC_MBOXQ_t *mbox;
  11034. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11035. int rc, length;
  11036. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11037. if (!mbox) {
  11038. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11039. "2745 Failed to allocate mbox for "
  11040. "requesting FCF rediscover.\n");
  11041. return -ENOMEM;
  11042. }
  11043. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11044. sizeof(struct lpfc_sli4_cfg_mhdr));
  11045. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11046. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11047. length, LPFC_SLI4_MBX_EMBED);
  11048. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11049. /* Set count to 0 for invalidating the entire FCF database */
  11050. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11051. /* Issue the mailbox command asynchronously */
  11052. mbox->vport = phba->pport;
  11053. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11054. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11055. if (rc == MBX_NOT_FINISHED) {
  11056. mempool_free(mbox, phba->mbox_mem_pool);
  11057. return -EIO;
  11058. }
  11059. return 0;
  11060. }
  11061. /**
  11062. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11063. * @phba: pointer to lpfc hba data structure.
  11064. *
  11065. * This function read region 23 and parse TLV for port status to
  11066. * decide if the user disaled the port. If the TLV indicates the
  11067. * port is disabled, the hba_flag is set accordingly.
  11068. **/
  11069. void
  11070. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11071. {
  11072. LPFC_MBOXQ_t *pmb = NULL;
  11073. MAILBOX_t *mb;
  11074. uint8_t *rgn23_data = NULL;
  11075. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11076. int rc;
  11077. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11078. if (!pmb) {
  11079. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11080. "2600 lpfc_sli_read_serdes_param failed to"
  11081. " allocate mailbox memory\n");
  11082. goto out;
  11083. }
  11084. mb = &pmb->u.mb;
  11085. /* Get adapter Region 23 data */
  11086. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11087. if (!rgn23_data)
  11088. goto out;
  11089. do {
  11090. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11091. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11092. if (rc != MBX_SUCCESS) {
  11093. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11094. "2601 lpfc_sli_read_link_ste failed to"
  11095. " read config region 23 rc 0x%x Status 0x%x\n",
  11096. rc, mb->mbxStatus);
  11097. mb->un.varDmp.word_cnt = 0;
  11098. }
  11099. /*
  11100. * dump mem may return a zero when finished or we got a
  11101. * mailbox error, either way we are done.
  11102. */
  11103. if (mb->un.varDmp.word_cnt == 0)
  11104. break;
  11105. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11106. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11107. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11108. rgn23_data + offset,
  11109. mb->un.varDmp.word_cnt);
  11110. offset += mb->un.varDmp.word_cnt;
  11111. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11112. data_size = offset;
  11113. offset = 0;
  11114. if (!data_size)
  11115. goto out;
  11116. /* Check the region signature first */
  11117. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11118. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11119. "2619 Config region 23 has bad signature\n");
  11120. goto out;
  11121. }
  11122. offset += 4;
  11123. /* Check the data structure version */
  11124. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11125. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11126. "2620 Config region 23 has bad version\n");
  11127. goto out;
  11128. }
  11129. offset += 4;
  11130. /* Parse TLV entries in the region */
  11131. while (offset < data_size) {
  11132. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11133. break;
  11134. /*
  11135. * If the TLV is not driver specific TLV or driver id is
  11136. * not linux driver id, skip the record.
  11137. */
  11138. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11139. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11140. (rgn23_data[offset + 3] != 0)) {
  11141. offset += rgn23_data[offset + 1] * 4 + 4;
  11142. continue;
  11143. }
  11144. /* Driver found a driver specific TLV in the config region */
  11145. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11146. offset += 4;
  11147. tlv_offset = 0;
  11148. /*
  11149. * Search for configured port state sub-TLV.
  11150. */
  11151. while ((offset < data_size) &&
  11152. (tlv_offset < sub_tlv_len)) {
  11153. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11154. offset += 4;
  11155. tlv_offset += 4;
  11156. break;
  11157. }
  11158. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11159. offset += rgn23_data[offset + 1] * 4 + 4;
  11160. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11161. continue;
  11162. }
  11163. /* This HBA contains PORT_STE configured */
  11164. if (!rgn23_data[offset + 2])
  11165. phba->hba_flag |= LINK_DISABLED;
  11166. goto out;
  11167. }
  11168. }
  11169. out:
  11170. if (pmb)
  11171. mempool_free(pmb, phba->mbox_mem_pool);
  11172. kfree(rgn23_data);
  11173. return;
  11174. }
  11175. /**
  11176. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11177. * @vport: pointer to vport data structure.
  11178. *
  11179. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11180. * and REG_VPI mailbox commands associated with the vport. This function
  11181. * is called when driver want to restart discovery of the vport due to
  11182. * a Clear Virtual Link event.
  11183. **/
  11184. void
  11185. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11186. {
  11187. struct lpfc_hba *phba = vport->phba;
  11188. LPFC_MBOXQ_t *mb, *nextmb;
  11189. struct lpfc_dmabuf *mp;
  11190. spin_lock_irq(&phba->hbalock);
  11191. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11192. if (mb->vport != vport)
  11193. continue;
  11194. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11195. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11196. continue;
  11197. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11198. mp = (struct lpfc_dmabuf *) (mb->context1);
  11199. if (mp) {
  11200. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11201. kfree(mp);
  11202. }
  11203. }
  11204. list_del(&mb->list);
  11205. mempool_free(mb, phba->mbox_mem_pool);
  11206. }
  11207. mb = phba->sli.mbox_active;
  11208. if (mb && (mb->vport == vport)) {
  11209. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11210. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11211. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11212. }
  11213. spin_unlock_irq(&phba->hbalock);
  11214. }