lpfc_sli.c 378 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252
  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. phba->link_state = LPFC_HBA_ERROR;
  2834. retval = 1;
  2835. }
  2836. return retval;
  2837. }
  2838. /**
  2839. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2840. * @phba: Pointer to HBA context object.
  2841. * @mask: Bit mask to be checked.
  2842. *
  2843. * This function checks the host status register to check if HBA is
  2844. * ready. This function will wait in a loop for the HBA to be ready
  2845. * If the HBA is not ready , the function will will reset the HBA PCI
  2846. * function again. The function returns 1 when HBA fail to be ready
  2847. * otherwise returns zero.
  2848. **/
  2849. static int
  2850. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2851. {
  2852. uint32_t status;
  2853. int retval = 0;
  2854. /* Read the HBA Host Status Register */
  2855. status = lpfc_sli4_post_status_check(phba);
  2856. if (status) {
  2857. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2858. lpfc_sli_brdrestart(phba);
  2859. status = lpfc_sli4_post_status_check(phba);
  2860. }
  2861. /* Check to see if any errors occurred during init */
  2862. if (status) {
  2863. phba->link_state = LPFC_HBA_ERROR;
  2864. retval = 1;
  2865. } else
  2866. phba->sli4_hba.intr_enable = 0;
  2867. return retval;
  2868. }
  2869. /**
  2870. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2871. * @phba: Pointer to HBA context object.
  2872. * @mask: Bit mask to be checked.
  2873. *
  2874. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2875. * from the API jump table function pointer from the lpfc_hba struct.
  2876. **/
  2877. int
  2878. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2879. {
  2880. return phba->lpfc_sli_brdready(phba, mask);
  2881. }
  2882. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2883. /**
  2884. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2885. * @phba: Pointer to HBA context object.
  2886. *
  2887. * This function is called before resetting an HBA. This
  2888. * function requests HBA to quiesce DMAs before a reset.
  2889. **/
  2890. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2891. {
  2892. uint32_t __iomem *resp_buf;
  2893. uint32_t __iomem *mbox_buf;
  2894. volatile uint32_t mbox;
  2895. uint32_t hc_copy;
  2896. int i;
  2897. uint8_t hdrtype;
  2898. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2899. if (hdrtype != 0x80 ||
  2900. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2901. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2902. return;
  2903. /*
  2904. * Tell the other part of the chip to suspend temporarily all
  2905. * its DMA activity.
  2906. */
  2907. resp_buf = phba->MBslimaddr;
  2908. /* Disable the error attention */
  2909. hc_copy = readl(phba->HCregaddr);
  2910. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2911. readl(phba->HCregaddr); /* flush */
  2912. phba->link_flag |= LS_IGNORE_ERATT;
  2913. if (readl(phba->HAregaddr) & HA_ERATT) {
  2914. /* Clear Chip error bit */
  2915. writel(HA_ERATT, phba->HAregaddr);
  2916. phba->pport->stopped = 1;
  2917. }
  2918. mbox = 0;
  2919. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2920. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2921. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2922. mbox_buf = phba->MBslimaddr;
  2923. writel(mbox, mbox_buf);
  2924. for (i = 0;
  2925. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2926. mdelay(1);
  2927. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2928. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2929. phba->pport->stopped)
  2930. goto restore_hc;
  2931. else
  2932. goto clear_errat;
  2933. }
  2934. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2935. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2936. mdelay(1);
  2937. clear_errat:
  2938. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2939. mdelay(1);
  2940. if (readl(phba->HAregaddr) & HA_ERATT) {
  2941. writel(HA_ERATT, phba->HAregaddr);
  2942. phba->pport->stopped = 1;
  2943. }
  2944. restore_hc:
  2945. phba->link_flag &= ~LS_IGNORE_ERATT;
  2946. writel(hc_copy, phba->HCregaddr);
  2947. readl(phba->HCregaddr); /* flush */
  2948. }
  2949. /**
  2950. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  2951. * @phba: Pointer to HBA context object.
  2952. *
  2953. * This function issues a kill_board mailbox command and waits for
  2954. * the error attention interrupt. This function is called for stopping
  2955. * the firmware processing. The caller is not required to hold any
  2956. * locks. This function calls lpfc_hba_down_post function to free
  2957. * any pending commands after the kill. The function will return 1 when it
  2958. * fails to kill the board else will return 0.
  2959. **/
  2960. int
  2961. lpfc_sli_brdkill(struct lpfc_hba *phba)
  2962. {
  2963. struct lpfc_sli *psli;
  2964. LPFC_MBOXQ_t *pmb;
  2965. uint32_t status;
  2966. uint32_t ha_copy;
  2967. int retval;
  2968. int i = 0;
  2969. psli = &phba->sli;
  2970. /* Kill HBA */
  2971. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2972. "0329 Kill HBA Data: x%x x%x\n",
  2973. phba->pport->port_state, psli->sli_flag);
  2974. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2975. if (!pmb)
  2976. return 1;
  2977. /* Disable the error attention */
  2978. spin_lock_irq(&phba->hbalock);
  2979. status = readl(phba->HCregaddr);
  2980. status &= ~HC_ERINT_ENA;
  2981. writel(status, phba->HCregaddr);
  2982. readl(phba->HCregaddr); /* flush */
  2983. phba->link_flag |= LS_IGNORE_ERATT;
  2984. spin_unlock_irq(&phba->hbalock);
  2985. lpfc_kill_board(phba, pmb);
  2986. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2987. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2988. if (retval != MBX_SUCCESS) {
  2989. if (retval != MBX_BUSY)
  2990. mempool_free(pmb, phba->mbox_mem_pool);
  2991. spin_lock_irq(&phba->hbalock);
  2992. phba->link_flag &= ~LS_IGNORE_ERATT;
  2993. spin_unlock_irq(&phba->hbalock);
  2994. return 1;
  2995. }
  2996. spin_lock_irq(&phba->hbalock);
  2997. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  2998. spin_unlock_irq(&phba->hbalock);
  2999. mempool_free(pmb, phba->mbox_mem_pool);
  3000. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3001. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3002. * 3 seconds we still set HBA_ERROR state because the status of the
  3003. * board is now undefined.
  3004. */
  3005. ha_copy = readl(phba->HAregaddr);
  3006. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3007. mdelay(100);
  3008. ha_copy = readl(phba->HAregaddr);
  3009. }
  3010. del_timer_sync(&psli->mbox_tmo);
  3011. if (ha_copy & HA_ERATT) {
  3012. writel(HA_ERATT, phba->HAregaddr);
  3013. phba->pport->stopped = 1;
  3014. }
  3015. spin_lock_irq(&phba->hbalock);
  3016. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3017. psli->mbox_active = NULL;
  3018. phba->link_flag &= ~LS_IGNORE_ERATT;
  3019. spin_unlock_irq(&phba->hbalock);
  3020. lpfc_hba_down_post(phba);
  3021. phba->link_state = LPFC_HBA_ERROR;
  3022. return ha_copy & HA_ERATT ? 0 : 1;
  3023. }
  3024. /**
  3025. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3026. * @phba: Pointer to HBA context object.
  3027. *
  3028. * This function resets the HBA by writing HC_INITFF to the control
  3029. * register. After the HBA resets, this function resets all the iocb ring
  3030. * indices. This function disables PCI layer parity checking during
  3031. * the reset.
  3032. * This function returns 0 always.
  3033. * The caller is not required to hold any locks.
  3034. **/
  3035. int
  3036. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3037. {
  3038. struct lpfc_sli *psli;
  3039. struct lpfc_sli_ring *pring;
  3040. uint16_t cfg_value;
  3041. int i;
  3042. psli = &phba->sli;
  3043. /* Reset HBA */
  3044. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3045. "0325 Reset HBA Data: x%x x%x\n",
  3046. phba->pport->port_state, psli->sli_flag);
  3047. /* perform board reset */
  3048. phba->fc_eventTag = 0;
  3049. phba->link_events = 0;
  3050. phba->pport->fc_myDID = 0;
  3051. phba->pport->fc_prevDID = 0;
  3052. /* Turn off parity checking and serr during the physical reset */
  3053. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3054. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3055. (cfg_value &
  3056. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3057. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3058. /* Now toggle INITFF bit in the Host Control Register */
  3059. writel(HC_INITFF, phba->HCregaddr);
  3060. mdelay(1);
  3061. readl(phba->HCregaddr); /* flush */
  3062. writel(0, phba->HCregaddr);
  3063. readl(phba->HCregaddr); /* flush */
  3064. /* Restore PCI cmd register */
  3065. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3066. /* Initialize relevant SLI info */
  3067. for (i = 0; i < psli->num_rings; i++) {
  3068. pring = &psli->ring[i];
  3069. pring->flag = 0;
  3070. pring->rspidx = 0;
  3071. pring->next_cmdidx = 0;
  3072. pring->local_getidx = 0;
  3073. pring->cmdidx = 0;
  3074. pring->missbufcnt = 0;
  3075. }
  3076. phba->link_state = LPFC_WARM_START;
  3077. return 0;
  3078. }
  3079. /**
  3080. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3081. * @phba: Pointer to HBA context object.
  3082. *
  3083. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3084. * checking during resets the device. The caller is not required to hold
  3085. * any locks.
  3086. *
  3087. * This function returns 0 always.
  3088. **/
  3089. int
  3090. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3091. {
  3092. struct lpfc_sli *psli = &phba->sli;
  3093. uint16_t cfg_value;
  3094. uint8_t qindx;
  3095. /* Reset HBA */
  3096. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3097. "0295 Reset HBA Data: x%x x%x\n",
  3098. phba->pport->port_state, psli->sli_flag);
  3099. /* perform board reset */
  3100. phba->fc_eventTag = 0;
  3101. phba->link_events = 0;
  3102. phba->pport->fc_myDID = 0;
  3103. phba->pport->fc_prevDID = 0;
  3104. /* Turn off parity checking and serr during the physical reset */
  3105. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3106. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3107. (cfg_value &
  3108. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3109. spin_lock_irq(&phba->hbalock);
  3110. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3111. phba->fcf.fcf_flag = 0;
  3112. /* Clean up the child queue list for the CQs */
  3113. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3114. list_del_init(&phba->sli4_hba.els_wq->list);
  3115. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3116. list_del_init(&phba->sli4_hba.dat_rq->list);
  3117. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3118. list_del_init(&phba->sli4_hba.els_cq->list);
  3119. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3120. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3121. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3122. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3123. spin_unlock_irq(&phba->hbalock);
  3124. /* Now physically reset the device */
  3125. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3126. "0389 Performing PCI function reset!\n");
  3127. /* Perform FCoE PCI function reset */
  3128. lpfc_pci_function_reset(phba);
  3129. return 0;
  3130. }
  3131. /**
  3132. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3133. * @phba: Pointer to HBA context object.
  3134. *
  3135. * This function is called in the SLI initialization code path to
  3136. * restart the HBA. The caller is not required to hold any lock.
  3137. * This function writes MBX_RESTART mailbox command to the SLIM and
  3138. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3139. * function to free any pending commands. The function enables
  3140. * POST only during the first initialization. The function returns zero.
  3141. * The function does not guarantee completion of MBX_RESTART mailbox
  3142. * command before the return of this function.
  3143. **/
  3144. static int
  3145. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3146. {
  3147. MAILBOX_t *mb;
  3148. struct lpfc_sli *psli;
  3149. volatile uint32_t word0;
  3150. void __iomem *to_slim;
  3151. uint32_t hba_aer_enabled;
  3152. spin_lock_irq(&phba->hbalock);
  3153. /* Take PCIe device Advanced Error Reporting (AER) state */
  3154. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3155. psli = &phba->sli;
  3156. /* Restart HBA */
  3157. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3158. "0337 Restart HBA Data: x%x x%x\n",
  3159. phba->pport->port_state, psli->sli_flag);
  3160. word0 = 0;
  3161. mb = (MAILBOX_t *) &word0;
  3162. mb->mbxCommand = MBX_RESTART;
  3163. mb->mbxHc = 1;
  3164. lpfc_reset_barrier(phba);
  3165. to_slim = phba->MBslimaddr;
  3166. writel(*(uint32_t *) mb, to_slim);
  3167. readl(to_slim); /* flush */
  3168. /* Only skip post after fc_ffinit is completed */
  3169. if (phba->pport->port_state)
  3170. word0 = 1; /* This is really setting up word1 */
  3171. else
  3172. word0 = 0; /* This is really setting up word1 */
  3173. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3174. writel(*(uint32_t *) mb, to_slim);
  3175. readl(to_slim); /* flush */
  3176. lpfc_sli_brdreset(phba);
  3177. phba->pport->stopped = 0;
  3178. phba->link_state = LPFC_INIT_START;
  3179. phba->hba_flag = 0;
  3180. spin_unlock_irq(&phba->hbalock);
  3181. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3182. psli->stats_start = get_seconds();
  3183. /* Give the INITFF and Post time to settle. */
  3184. mdelay(100);
  3185. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3186. if (hba_aer_enabled)
  3187. pci_disable_pcie_error_reporting(phba->pcidev);
  3188. lpfc_hba_down_post(phba);
  3189. return 0;
  3190. }
  3191. /**
  3192. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3193. * @phba: Pointer to HBA context object.
  3194. *
  3195. * This function is called in the SLI initialization code path to restart
  3196. * a SLI4 HBA. The caller is not required to hold any lock.
  3197. * At the end of the function, it calls lpfc_hba_down_post function to
  3198. * free any pending commands.
  3199. **/
  3200. static int
  3201. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3202. {
  3203. struct lpfc_sli *psli = &phba->sli;
  3204. /* Restart HBA */
  3205. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3206. "0296 Restart HBA Data: x%x x%x\n",
  3207. phba->pport->port_state, psli->sli_flag);
  3208. lpfc_sli4_brdreset(phba);
  3209. spin_lock_irq(&phba->hbalock);
  3210. phba->pport->stopped = 0;
  3211. phba->link_state = LPFC_INIT_START;
  3212. phba->hba_flag = 0;
  3213. spin_unlock_irq(&phba->hbalock);
  3214. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3215. psli->stats_start = get_seconds();
  3216. lpfc_hba_down_post(phba);
  3217. return 0;
  3218. }
  3219. /**
  3220. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3221. * @phba: Pointer to HBA context object.
  3222. *
  3223. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3224. * API jump table function pointer from the lpfc_hba struct.
  3225. **/
  3226. int
  3227. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3228. {
  3229. return phba->lpfc_sli_brdrestart(phba);
  3230. }
  3231. /**
  3232. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3233. * @phba: Pointer to HBA context object.
  3234. *
  3235. * This function is called after a HBA restart to wait for successful
  3236. * restart of the HBA. Successful restart of the HBA is indicated by
  3237. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3238. * iteration, the function will restart the HBA again. The function returns
  3239. * zero if HBA successfully restarted else returns negative error code.
  3240. **/
  3241. static int
  3242. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3243. {
  3244. uint32_t status, i = 0;
  3245. /* Read the HBA Host Status Register */
  3246. status = readl(phba->HSregaddr);
  3247. /* Check status register to see what current state is */
  3248. i = 0;
  3249. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3250. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3251. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3252. * 4.
  3253. */
  3254. if (i++ >= 20) {
  3255. /* Adapter failed to init, timeout, status reg
  3256. <status> */
  3257. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3258. "0436 Adapter failed to init, "
  3259. "timeout, status reg x%x, "
  3260. "FW Data: A8 x%x AC x%x\n", status,
  3261. readl(phba->MBslimaddr + 0xa8),
  3262. readl(phba->MBslimaddr + 0xac));
  3263. phba->link_state = LPFC_HBA_ERROR;
  3264. return -ETIMEDOUT;
  3265. }
  3266. /* Check to see if any errors occurred during init */
  3267. if (status & HS_FFERM) {
  3268. /* ERROR: During chipset initialization */
  3269. /* Adapter failed to init, chipset, status reg
  3270. <status> */
  3271. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3272. "0437 Adapter failed to init, "
  3273. "chipset, status reg x%x, "
  3274. "FW Data: A8 x%x AC x%x\n", status,
  3275. readl(phba->MBslimaddr + 0xa8),
  3276. readl(phba->MBslimaddr + 0xac));
  3277. phba->link_state = LPFC_HBA_ERROR;
  3278. return -EIO;
  3279. }
  3280. if (i <= 5) {
  3281. msleep(10);
  3282. } else if (i <= 10) {
  3283. msleep(500);
  3284. } else {
  3285. msleep(2500);
  3286. }
  3287. if (i == 15) {
  3288. /* Do post */
  3289. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3290. lpfc_sli_brdrestart(phba);
  3291. }
  3292. /* Read the HBA Host Status Register */
  3293. status = readl(phba->HSregaddr);
  3294. }
  3295. /* Check to see if any errors occurred during init */
  3296. if (status & HS_FFERM) {
  3297. /* ERROR: During chipset initialization */
  3298. /* Adapter failed to init, chipset, status reg <status> */
  3299. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3300. "0438 Adapter failed to init, chipset, "
  3301. "status reg x%x, "
  3302. "FW Data: A8 x%x AC x%x\n", status,
  3303. readl(phba->MBslimaddr + 0xa8),
  3304. readl(phba->MBslimaddr + 0xac));
  3305. phba->link_state = LPFC_HBA_ERROR;
  3306. return -EIO;
  3307. }
  3308. /* Clear all interrupt enable conditions */
  3309. writel(0, phba->HCregaddr);
  3310. readl(phba->HCregaddr); /* flush */
  3311. /* setup host attn register */
  3312. writel(0xffffffff, phba->HAregaddr);
  3313. readl(phba->HAregaddr); /* flush */
  3314. return 0;
  3315. }
  3316. /**
  3317. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3318. *
  3319. * This function calculates and returns the number of HBQs required to be
  3320. * configured.
  3321. **/
  3322. int
  3323. lpfc_sli_hbq_count(void)
  3324. {
  3325. return ARRAY_SIZE(lpfc_hbq_defs);
  3326. }
  3327. /**
  3328. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3329. *
  3330. * This function adds the number of hbq entries in every HBQ to get
  3331. * the total number of hbq entries required for the HBA and returns
  3332. * the total count.
  3333. **/
  3334. static int
  3335. lpfc_sli_hbq_entry_count(void)
  3336. {
  3337. int hbq_count = lpfc_sli_hbq_count();
  3338. int count = 0;
  3339. int i;
  3340. for (i = 0; i < hbq_count; ++i)
  3341. count += lpfc_hbq_defs[i]->entry_count;
  3342. return count;
  3343. }
  3344. /**
  3345. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3346. *
  3347. * This function calculates amount of memory required for all hbq entries
  3348. * to be configured and returns the total memory required.
  3349. **/
  3350. int
  3351. lpfc_sli_hbq_size(void)
  3352. {
  3353. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3354. }
  3355. /**
  3356. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3357. * @phba: Pointer to HBA context object.
  3358. *
  3359. * This function is called during the SLI initialization to configure
  3360. * all the HBQs and post buffers to the HBQ. The caller is not
  3361. * required to hold any locks. This function will return zero if successful
  3362. * else it will return negative error code.
  3363. **/
  3364. static int
  3365. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3366. {
  3367. int hbq_count = lpfc_sli_hbq_count();
  3368. LPFC_MBOXQ_t *pmb;
  3369. MAILBOX_t *pmbox;
  3370. uint32_t hbqno;
  3371. uint32_t hbq_entry_index;
  3372. /* Get a Mailbox buffer to setup mailbox
  3373. * commands for HBA initialization
  3374. */
  3375. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3376. if (!pmb)
  3377. return -ENOMEM;
  3378. pmbox = &pmb->u.mb;
  3379. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3380. phba->link_state = LPFC_INIT_MBX_CMDS;
  3381. phba->hbq_in_use = 1;
  3382. hbq_entry_index = 0;
  3383. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3384. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3385. phba->hbqs[hbqno].hbqPutIdx = 0;
  3386. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3387. phba->hbqs[hbqno].entry_count =
  3388. lpfc_hbq_defs[hbqno]->entry_count;
  3389. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3390. hbq_entry_index, pmb);
  3391. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3392. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3393. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3394. mbxStatus <status>, ring <num> */
  3395. lpfc_printf_log(phba, KERN_ERR,
  3396. LOG_SLI | LOG_VPORT,
  3397. "1805 Adapter failed to init. "
  3398. "Data: x%x x%x x%x\n",
  3399. pmbox->mbxCommand,
  3400. pmbox->mbxStatus, hbqno);
  3401. phba->link_state = LPFC_HBA_ERROR;
  3402. mempool_free(pmb, phba->mbox_mem_pool);
  3403. return ENXIO;
  3404. }
  3405. }
  3406. phba->hbq_count = hbq_count;
  3407. mempool_free(pmb, phba->mbox_mem_pool);
  3408. /* Initially populate or replenish the HBQs */
  3409. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3410. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3411. return 0;
  3412. }
  3413. /**
  3414. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3415. * @phba: Pointer to HBA context object.
  3416. *
  3417. * This function is called during the SLI initialization to configure
  3418. * all the HBQs and post buffers to the HBQ. The caller is not
  3419. * required to hold any locks. This function will return zero if successful
  3420. * else it will return negative error code.
  3421. **/
  3422. static int
  3423. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3424. {
  3425. phba->hbq_in_use = 1;
  3426. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3427. phba->hbq_count = 1;
  3428. /* Initially populate or replenish the HBQs */
  3429. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3430. return 0;
  3431. }
  3432. /**
  3433. * lpfc_sli_config_port - Issue config port mailbox command
  3434. * @phba: Pointer to HBA context object.
  3435. * @sli_mode: sli mode - 2/3
  3436. *
  3437. * This function is called by the sli intialization code path
  3438. * to issue config_port mailbox command. This function restarts the
  3439. * HBA firmware and issues a config_port mailbox command to configure
  3440. * the SLI interface in the sli mode specified by sli_mode
  3441. * variable. The caller is not required to hold any locks.
  3442. * The function returns 0 if successful, else returns negative error
  3443. * code.
  3444. **/
  3445. int
  3446. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3447. {
  3448. LPFC_MBOXQ_t *pmb;
  3449. uint32_t resetcount = 0, rc = 0, done = 0;
  3450. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3451. if (!pmb) {
  3452. phba->link_state = LPFC_HBA_ERROR;
  3453. return -ENOMEM;
  3454. }
  3455. phba->sli_rev = sli_mode;
  3456. while (resetcount < 2 && !done) {
  3457. spin_lock_irq(&phba->hbalock);
  3458. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3459. spin_unlock_irq(&phba->hbalock);
  3460. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3461. lpfc_sli_brdrestart(phba);
  3462. rc = lpfc_sli_chipset_init(phba);
  3463. if (rc)
  3464. break;
  3465. spin_lock_irq(&phba->hbalock);
  3466. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3467. spin_unlock_irq(&phba->hbalock);
  3468. resetcount++;
  3469. /* Call pre CONFIG_PORT mailbox command initialization. A
  3470. * value of 0 means the call was successful. Any other
  3471. * nonzero value is a failure, but if ERESTART is returned,
  3472. * the driver may reset the HBA and try again.
  3473. */
  3474. rc = lpfc_config_port_prep(phba);
  3475. if (rc == -ERESTART) {
  3476. phba->link_state = LPFC_LINK_UNKNOWN;
  3477. continue;
  3478. } else if (rc)
  3479. break;
  3480. phba->link_state = LPFC_INIT_MBX_CMDS;
  3481. lpfc_config_port(phba, pmb);
  3482. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3483. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3484. LPFC_SLI3_HBQ_ENABLED |
  3485. LPFC_SLI3_CRP_ENABLED |
  3486. LPFC_SLI3_INB_ENABLED |
  3487. LPFC_SLI3_BG_ENABLED);
  3488. if (rc != MBX_SUCCESS) {
  3489. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3490. "0442 Adapter failed to init, mbxCmd x%x "
  3491. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3492. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3493. spin_lock_irq(&phba->hbalock);
  3494. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3495. spin_unlock_irq(&phba->hbalock);
  3496. rc = -ENXIO;
  3497. } else {
  3498. /* Allow asynchronous mailbox command to go through */
  3499. spin_lock_irq(&phba->hbalock);
  3500. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3501. spin_unlock_irq(&phba->hbalock);
  3502. done = 1;
  3503. }
  3504. }
  3505. if (!done) {
  3506. rc = -EINVAL;
  3507. goto do_prep_failed;
  3508. }
  3509. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3510. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3511. rc = -ENXIO;
  3512. goto do_prep_failed;
  3513. }
  3514. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3515. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3516. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3517. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3518. phba->max_vpi : phba->max_vports;
  3519. } else
  3520. phba->max_vpi = 0;
  3521. if (pmb->u.mb.un.varCfgPort.gdss)
  3522. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3523. if (pmb->u.mb.un.varCfgPort.gerbm)
  3524. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3525. if (pmb->u.mb.un.varCfgPort.gcrp)
  3526. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3527. if (pmb->u.mb.un.varCfgPort.ginb) {
  3528. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3529. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3530. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3531. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3532. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3533. phba->inb_last_counter =
  3534. phba->mbox->us.s3_inb_pgp.counter;
  3535. } else {
  3536. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3537. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3538. phba->inb_ha_copy = NULL;
  3539. phba->inb_counter = NULL;
  3540. }
  3541. if (phba->cfg_enable_bg) {
  3542. if (pmb->u.mb.un.varCfgPort.gbg)
  3543. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3544. else
  3545. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3546. "0443 Adapter did not grant "
  3547. "BlockGuard\n");
  3548. }
  3549. } else {
  3550. phba->hbq_get = NULL;
  3551. phba->port_gp = phba->mbox->us.s2.port;
  3552. phba->inb_ha_copy = NULL;
  3553. phba->inb_counter = NULL;
  3554. phba->max_vpi = 0;
  3555. }
  3556. do_prep_failed:
  3557. mempool_free(pmb, phba->mbox_mem_pool);
  3558. return rc;
  3559. }
  3560. /**
  3561. * lpfc_sli_hba_setup - SLI intialization function
  3562. * @phba: Pointer to HBA context object.
  3563. *
  3564. * This function is the main SLI intialization function. This function
  3565. * is called by the HBA intialization code, HBA reset code and HBA
  3566. * error attention handler code. Caller is not required to hold any
  3567. * locks. This function issues config_port mailbox command to configure
  3568. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3569. * calls the config_port_post function to issue init_link mailbox
  3570. * command and to start the discovery. The function will return zero
  3571. * if successful, else it will return negative error code.
  3572. **/
  3573. int
  3574. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3575. {
  3576. uint32_t rc;
  3577. int mode = 3;
  3578. switch (lpfc_sli_mode) {
  3579. case 2:
  3580. if (phba->cfg_enable_npiv) {
  3581. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3582. "1824 NPIV enabled: Override lpfc_sli_mode "
  3583. "parameter (%d) to auto (0).\n",
  3584. lpfc_sli_mode);
  3585. break;
  3586. }
  3587. mode = 2;
  3588. break;
  3589. case 0:
  3590. case 3:
  3591. break;
  3592. default:
  3593. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3594. "1819 Unrecognized lpfc_sli_mode "
  3595. "parameter: %d.\n", lpfc_sli_mode);
  3596. break;
  3597. }
  3598. rc = lpfc_sli_config_port(phba, mode);
  3599. if (rc && lpfc_sli_mode == 3)
  3600. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3601. "1820 Unable to select SLI-3. "
  3602. "Not supported by adapter.\n");
  3603. if (rc && mode != 2)
  3604. rc = lpfc_sli_config_port(phba, 2);
  3605. if (rc)
  3606. goto lpfc_sli_hba_setup_error;
  3607. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3608. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3609. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3610. if (!rc) {
  3611. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3612. "2709 This device supports "
  3613. "Advanced Error Reporting (AER)\n");
  3614. spin_lock_irq(&phba->hbalock);
  3615. phba->hba_flag |= HBA_AER_ENABLED;
  3616. spin_unlock_irq(&phba->hbalock);
  3617. } else {
  3618. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3619. "2708 This device does not support "
  3620. "Advanced Error Reporting (AER)\n");
  3621. phba->cfg_aer_support = 0;
  3622. }
  3623. }
  3624. if (phba->sli_rev == 3) {
  3625. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3626. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3627. } else {
  3628. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3629. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3630. phba->sli3_options = 0;
  3631. }
  3632. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3633. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3634. phba->sli_rev, phba->max_vpi);
  3635. rc = lpfc_sli_ring_map(phba);
  3636. if (rc)
  3637. goto lpfc_sli_hba_setup_error;
  3638. /* Init HBQs */
  3639. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3640. rc = lpfc_sli_hbq_setup(phba);
  3641. if (rc)
  3642. goto lpfc_sli_hba_setup_error;
  3643. }
  3644. spin_lock_irq(&phba->hbalock);
  3645. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3646. spin_unlock_irq(&phba->hbalock);
  3647. rc = lpfc_config_port_post(phba);
  3648. if (rc)
  3649. goto lpfc_sli_hba_setup_error;
  3650. return rc;
  3651. lpfc_sli_hba_setup_error:
  3652. phba->link_state = LPFC_HBA_ERROR;
  3653. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3654. "0445 Firmware initialization failed\n");
  3655. return rc;
  3656. }
  3657. /**
  3658. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3659. * @phba: Pointer to HBA context object.
  3660. * @mboxq: mailbox pointer.
  3661. * This function issue a dump mailbox command to read config region
  3662. * 23 and parse the records in the region and populate driver
  3663. * data structure.
  3664. **/
  3665. static int
  3666. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3667. LPFC_MBOXQ_t *mboxq)
  3668. {
  3669. struct lpfc_dmabuf *mp;
  3670. struct lpfc_mqe *mqe;
  3671. uint32_t data_length;
  3672. int rc;
  3673. /* Program the default value of vlan_id and fc_map */
  3674. phba->valid_vlan = 0;
  3675. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3676. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3677. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3678. mqe = &mboxq->u.mqe;
  3679. if (lpfc_dump_fcoe_param(phba, mboxq))
  3680. return -ENOMEM;
  3681. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3682. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3683. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3684. "(%d):2571 Mailbox cmd x%x Status x%x "
  3685. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3686. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3687. "CQ: x%x x%x x%x x%x\n",
  3688. mboxq->vport ? mboxq->vport->vpi : 0,
  3689. bf_get(lpfc_mqe_command, mqe),
  3690. bf_get(lpfc_mqe_status, mqe),
  3691. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3692. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3693. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3694. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3695. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3696. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3697. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3698. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3699. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3700. mboxq->mcqe.word0,
  3701. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3702. mboxq->mcqe.trailer);
  3703. if (rc) {
  3704. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3705. kfree(mp);
  3706. return -EIO;
  3707. }
  3708. data_length = mqe->un.mb_words[5];
  3709. if (data_length > DMP_RGN23_SIZE) {
  3710. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3711. kfree(mp);
  3712. return -EIO;
  3713. }
  3714. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3715. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3716. kfree(mp);
  3717. return 0;
  3718. }
  3719. /**
  3720. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3721. * @phba: pointer to lpfc hba data structure.
  3722. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3723. * @vpd: pointer to the memory to hold resulting port vpd data.
  3724. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3725. * On output, the number of data bytes in @vpd.
  3726. *
  3727. * This routine executes a READ_REV SLI4 mailbox command. In
  3728. * addition, this routine gets the port vpd data.
  3729. *
  3730. * Return codes
  3731. * 0 - successful
  3732. * ENOMEM - could not allocated memory.
  3733. **/
  3734. static int
  3735. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3736. uint8_t *vpd, uint32_t *vpd_size)
  3737. {
  3738. int rc = 0;
  3739. uint32_t dma_size;
  3740. struct lpfc_dmabuf *dmabuf;
  3741. struct lpfc_mqe *mqe;
  3742. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3743. if (!dmabuf)
  3744. return -ENOMEM;
  3745. /*
  3746. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3747. * mailbox command.
  3748. */
  3749. dma_size = *vpd_size;
  3750. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3751. dma_size,
  3752. &dmabuf->phys,
  3753. GFP_KERNEL);
  3754. if (!dmabuf->virt) {
  3755. kfree(dmabuf);
  3756. return -ENOMEM;
  3757. }
  3758. memset(dmabuf->virt, 0, dma_size);
  3759. /*
  3760. * The SLI4 implementation of READ_REV conflicts at word1,
  3761. * bits 31:16 and SLI4 adds vpd functionality not present
  3762. * in SLI3. This code corrects the conflicts.
  3763. */
  3764. lpfc_read_rev(phba, mboxq);
  3765. mqe = &mboxq->u.mqe;
  3766. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3767. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3768. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3769. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3770. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3771. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3772. if (rc) {
  3773. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3774. dmabuf->virt, dmabuf->phys);
  3775. kfree(dmabuf);
  3776. return -EIO;
  3777. }
  3778. /*
  3779. * The available vpd length cannot be bigger than the
  3780. * DMA buffer passed to the port. Catch the less than
  3781. * case and update the caller's size.
  3782. */
  3783. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3784. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3785. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3786. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3787. dmabuf->virt, dmabuf->phys);
  3788. kfree(dmabuf);
  3789. return 0;
  3790. }
  3791. /**
  3792. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3793. * @phba: pointer to lpfc hba data structure.
  3794. *
  3795. * This routine is called to explicitly arm the SLI4 device's completion and
  3796. * event queues
  3797. **/
  3798. static void
  3799. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3800. {
  3801. uint8_t fcp_eqidx;
  3802. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3803. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3804. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3805. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3806. LPFC_QUEUE_REARM);
  3807. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3808. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3809. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3810. LPFC_QUEUE_REARM);
  3811. }
  3812. /**
  3813. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3814. * @phba: Pointer to HBA context object.
  3815. *
  3816. * This function is the main SLI4 device intialization PCI function. This
  3817. * function is called by the HBA intialization code, HBA reset code and
  3818. * HBA error attention handler code. Caller is not required to hold any
  3819. * locks.
  3820. **/
  3821. int
  3822. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3823. {
  3824. int rc;
  3825. LPFC_MBOXQ_t *mboxq;
  3826. struct lpfc_mqe *mqe;
  3827. uint8_t *vpd;
  3828. uint32_t vpd_size;
  3829. uint32_t ftr_rsp = 0;
  3830. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3831. struct lpfc_vport *vport = phba->pport;
  3832. struct lpfc_dmabuf *mp;
  3833. /* Perform a PCI function reset to start from clean */
  3834. rc = lpfc_pci_function_reset(phba);
  3835. if (unlikely(rc))
  3836. return -ENODEV;
  3837. /* Check the HBA Host Status Register for readyness */
  3838. rc = lpfc_sli4_post_status_check(phba);
  3839. if (unlikely(rc))
  3840. return -ENODEV;
  3841. else {
  3842. spin_lock_irq(&phba->hbalock);
  3843. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3844. spin_unlock_irq(&phba->hbalock);
  3845. }
  3846. /*
  3847. * Allocate a single mailbox container for initializing the
  3848. * port.
  3849. */
  3850. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3851. if (!mboxq)
  3852. return -ENOMEM;
  3853. /*
  3854. * Continue initialization with default values even if driver failed
  3855. * to read FCoE param config regions
  3856. */
  3857. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3858. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3859. "2570 Failed to read FCoE parameters\n");
  3860. /* Issue READ_REV to collect vpd and FW information. */
  3861. vpd_size = PAGE_SIZE;
  3862. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3863. if (!vpd) {
  3864. rc = -ENOMEM;
  3865. goto out_free_mbox;
  3866. }
  3867. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3868. if (unlikely(rc))
  3869. goto out_free_vpd;
  3870. mqe = &mboxq->u.mqe;
  3871. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3872. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3873. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3874. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3875. LPFC_DCBX_CEE_MODE)
  3876. phba->hba_flag |= HBA_FIP_SUPPORT;
  3877. else
  3878. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3879. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3880. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3881. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3882. "0376 READ_REV Error. SLI Level %d "
  3883. "FCoE enabled %d\n",
  3884. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3885. rc = -EIO;
  3886. goto out_free_vpd;
  3887. }
  3888. /*
  3889. * Evaluate the read rev and vpd data. Populate the driver
  3890. * state with the results. If this routine fails, the failure
  3891. * is not fatal as the driver will use generic values.
  3892. */
  3893. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3894. if (unlikely(!rc)) {
  3895. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3896. "0377 Error %d parsing vpd. "
  3897. "Using defaults.\n", rc);
  3898. rc = 0;
  3899. }
  3900. /* Save information as VPD data */
  3901. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3902. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3903. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3904. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3905. &mqe->un.read_rev);
  3906. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3907. &mqe->un.read_rev);
  3908. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3909. &mqe->un.read_rev);
  3910. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3911. &mqe->un.read_rev);
  3912. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3913. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3914. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3915. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3916. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3917. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3918. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3919. "(%d):0380 READ_REV Status x%x "
  3920. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3921. mboxq->vport ? mboxq->vport->vpi : 0,
  3922. bf_get(lpfc_mqe_status, mqe),
  3923. phba->vpd.rev.opFwName,
  3924. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3925. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3926. /*
  3927. * Discover the port's supported feature set and match it against the
  3928. * hosts requests.
  3929. */
  3930. lpfc_request_features(phba, mboxq);
  3931. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3932. if (unlikely(rc)) {
  3933. rc = -EIO;
  3934. goto out_free_vpd;
  3935. }
  3936. /*
  3937. * The port must support FCP initiator mode as this is the
  3938. * only mode running in the host.
  3939. */
  3940. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3941. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3942. "0378 No support for fcpi mode.\n");
  3943. ftr_rsp++;
  3944. }
  3945. /*
  3946. * If the port cannot support the host's requested features
  3947. * then turn off the global config parameters to disable the
  3948. * feature in the driver. This is not a fatal error.
  3949. */
  3950. if ((phba->cfg_enable_bg) &&
  3951. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3952. ftr_rsp++;
  3953. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3954. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3955. ftr_rsp++;
  3956. if (ftr_rsp) {
  3957. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3958. "0379 Feature Mismatch Data: x%08x %08x "
  3959. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3960. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3961. phba->cfg_enable_npiv, phba->max_vpi);
  3962. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3963. phba->cfg_enable_bg = 0;
  3964. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3965. phba->cfg_enable_npiv = 0;
  3966. }
  3967. /* These SLI3 features are assumed in SLI4 */
  3968. spin_lock_irq(&phba->hbalock);
  3969. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  3970. spin_unlock_irq(&phba->hbalock);
  3971. /* Read the port's service parameters. */
  3972. lpfc_read_sparam(phba, mboxq, vport->vpi);
  3973. mboxq->vport = vport;
  3974. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3975. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3976. if (rc == MBX_SUCCESS) {
  3977. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  3978. rc = 0;
  3979. }
  3980. /*
  3981. * This memory was allocated by the lpfc_read_sparam routine. Release
  3982. * it to the mbuf pool.
  3983. */
  3984. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3985. kfree(mp);
  3986. mboxq->context1 = NULL;
  3987. if (unlikely(rc)) {
  3988. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3989. "0382 READ_SPARAM command failed "
  3990. "status %d, mbxStatus x%x\n",
  3991. rc, bf_get(lpfc_mqe_status, mqe));
  3992. phba->link_state = LPFC_HBA_ERROR;
  3993. rc = -EIO;
  3994. goto out_free_vpd;
  3995. }
  3996. if (phba->cfg_soft_wwnn)
  3997. u64_to_wwn(phba->cfg_soft_wwnn,
  3998. vport->fc_sparam.nodeName.u.wwn);
  3999. if (phba->cfg_soft_wwpn)
  4000. u64_to_wwn(phba->cfg_soft_wwpn,
  4001. vport->fc_sparam.portName.u.wwn);
  4002. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4003. sizeof(struct lpfc_name));
  4004. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4005. sizeof(struct lpfc_name));
  4006. /* Update the fc_host data structures with new wwn. */
  4007. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4008. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4009. /* Register SGL pool to the device using non-embedded mailbox command */
  4010. rc = lpfc_sli4_post_sgl_list(phba);
  4011. if (unlikely(rc)) {
  4012. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4013. "0582 Error %d during sgl post operation\n",
  4014. rc);
  4015. rc = -ENODEV;
  4016. goto out_free_vpd;
  4017. }
  4018. /* Register SCSI SGL pool to the device */
  4019. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4020. if (unlikely(rc)) {
  4021. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4022. "0383 Error %d during scsi sgl post "
  4023. "operation\n", rc);
  4024. /* Some Scsi buffers were moved to the abort scsi list */
  4025. /* A pci function reset will repost them */
  4026. rc = -ENODEV;
  4027. goto out_free_vpd;
  4028. }
  4029. /* Post the rpi header region to the device. */
  4030. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4031. if (unlikely(rc)) {
  4032. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4033. "0393 Error %d during rpi post operation\n",
  4034. rc);
  4035. rc = -ENODEV;
  4036. goto out_free_vpd;
  4037. }
  4038. /* Set up all the queues to the device */
  4039. rc = lpfc_sli4_queue_setup(phba);
  4040. if (unlikely(rc)) {
  4041. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4042. "0381 Error %d during queue setup.\n ", rc);
  4043. goto out_stop_timers;
  4044. }
  4045. /* Arm the CQs and then EQs on device */
  4046. lpfc_sli4_arm_cqeq_intr(phba);
  4047. /* Indicate device interrupt mode */
  4048. phba->sli4_hba.intr_enable = 1;
  4049. /* Allow asynchronous mailbox command to go through */
  4050. spin_lock_irq(&phba->hbalock);
  4051. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4052. spin_unlock_irq(&phba->hbalock);
  4053. /* Post receive buffers to the device */
  4054. lpfc_sli4_rb_setup(phba);
  4055. /* Start the ELS watchdog timer */
  4056. mod_timer(&vport->els_tmofunc,
  4057. jiffies + HZ * (phba->fc_ratov * 2));
  4058. /* Start heart beat timer */
  4059. mod_timer(&phba->hb_tmofunc,
  4060. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4061. phba->hb_outstanding = 0;
  4062. phba->last_completion_time = jiffies;
  4063. /* Start error attention (ERATT) polling timer */
  4064. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4065. /*
  4066. * The port is ready, set the host's link state to LINK_DOWN
  4067. * in preparation for link interrupts.
  4068. */
  4069. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4070. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4071. lpfc_set_loopback_flag(phba);
  4072. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4073. spin_lock_irq(&phba->hbalock);
  4074. phba->link_state = LPFC_LINK_DOWN;
  4075. spin_unlock_irq(&phba->hbalock);
  4076. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4077. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4078. kfree(vpd);
  4079. return 0;
  4080. } else
  4081. rc = -EIO;
  4082. /* Unset all the queues set up in this routine when error out */
  4083. if (rc)
  4084. lpfc_sli4_queue_unset(phba);
  4085. out_stop_timers:
  4086. if (rc)
  4087. lpfc_stop_hba_timers(phba);
  4088. out_free_vpd:
  4089. kfree(vpd);
  4090. out_free_mbox:
  4091. mempool_free(mboxq, phba->mbox_mem_pool);
  4092. return rc;
  4093. }
  4094. /**
  4095. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4096. * @ptr: context object - pointer to hba structure.
  4097. *
  4098. * This is the callback function for mailbox timer. The mailbox
  4099. * timer is armed when a new mailbox command is issued and the timer
  4100. * is deleted when the mailbox complete. The function is called by
  4101. * the kernel timer code when a mailbox does not complete within
  4102. * expected time. This function wakes up the worker thread to
  4103. * process the mailbox timeout and returns. All the processing is
  4104. * done by the worker thread function lpfc_mbox_timeout_handler.
  4105. **/
  4106. void
  4107. lpfc_mbox_timeout(unsigned long ptr)
  4108. {
  4109. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4110. unsigned long iflag;
  4111. uint32_t tmo_posted;
  4112. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4113. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4114. if (!tmo_posted)
  4115. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4116. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4117. if (!tmo_posted)
  4118. lpfc_worker_wake_up(phba);
  4119. return;
  4120. }
  4121. /**
  4122. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4123. * @phba: Pointer to HBA context object.
  4124. *
  4125. * This function is called from worker thread when a mailbox command times out.
  4126. * The caller is not required to hold any locks. This function will reset the
  4127. * HBA and recover all the pending commands.
  4128. **/
  4129. void
  4130. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4131. {
  4132. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4133. MAILBOX_t *mb = &pmbox->u.mb;
  4134. struct lpfc_sli *psli = &phba->sli;
  4135. struct lpfc_sli_ring *pring;
  4136. /* Check the pmbox pointer first. There is a race condition
  4137. * between the mbox timeout handler getting executed in the
  4138. * worklist and the mailbox actually completing. When this
  4139. * race condition occurs, the mbox_active will be NULL.
  4140. */
  4141. spin_lock_irq(&phba->hbalock);
  4142. if (pmbox == NULL) {
  4143. lpfc_printf_log(phba, KERN_WARNING,
  4144. LOG_MBOX | LOG_SLI,
  4145. "0353 Active Mailbox cleared - mailbox timeout "
  4146. "exiting\n");
  4147. spin_unlock_irq(&phba->hbalock);
  4148. return;
  4149. }
  4150. /* Mbox cmd <mbxCommand> timeout */
  4151. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4152. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4153. mb->mbxCommand,
  4154. phba->pport->port_state,
  4155. phba->sli.sli_flag,
  4156. phba->sli.mbox_active);
  4157. spin_unlock_irq(&phba->hbalock);
  4158. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4159. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4160. * it to fail all oustanding SCSI IO.
  4161. */
  4162. spin_lock_irq(&phba->pport->work_port_lock);
  4163. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4164. spin_unlock_irq(&phba->pport->work_port_lock);
  4165. spin_lock_irq(&phba->hbalock);
  4166. phba->link_state = LPFC_LINK_UNKNOWN;
  4167. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4168. spin_unlock_irq(&phba->hbalock);
  4169. pring = &psli->ring[psli->fcp_ring];
  4170. lpfc_sli_abort_iocb_ring(phba, pring);
  4171. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4172. "0345 Resetting board due to mailbox timeout\n");
  4173. /* Reset the HBA device */
  4174. lpfc_reset_hba(phba);
  4175. }
  4176. /**
  4177. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4178. * @phba: Pointer to HBA context object.
  4179. * @pmbox: Pointer to mailbox object.
  4180. * @flag: Flag indicating how the mailbox need to be processed.
  4181. *
  4182. * This function is called by discovery code and HBA management code
  4183. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4184. * function gets the hbalock to protect the data structures.
  4185. * The mailbox command can be submitted in polling mode, in which case
  4186. * this function will wait in a polling loop for the completion of the
  4187. * mailbox.
  4188. * If the mailbox is submitted in no_wait mode (not polling) the
  4189. * function will submit the command and returns immediately without waiting
  4190. * for the mailbox completion. The no_wait is supported only when HBA
  4191. * is in SLI2/SLI3 mode - interrupts are enabled.
  4192. * The SLI interface allows only one mailbox pending at a time. If the
  4193. * mailbox is issued in polling mode and there is already a mailbox
  4194. * pending, then the function will return an error. If the mailbox is issued
  4195. * in NO_WAIT mode and there is a mailbox pending already, the function
  4196. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4197. * The sli layer owns the mailbox object until the completion of mailbox
  4198. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4199. * return codes the caller owns the mailbox command after the return of
  4200. * the function.
  4201. **/
  4202. static int
  4203. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4204. uint32_t flag)
  4205. {
  4206. MAILBOX_t *mb;
  4207. struct lpfc_sli *psli = &phba->sli;
  4208. uint32_t status, evtctr;
  4209. uint32_t ha_copy;
  4210. int i;
  4211. unsigned long timeout;
  4212. unsigned long drvr_flag = 0;
  4213. uint32_t word0, ldata;
  4214. void __iomem *to_slim;
  4215. int processing_queue = 0;
  4216. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4217. if (!pmbox) {
  4218. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4219. /* processing mbox queue from intr_handler */
  4220. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4221. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4222. return MBX_SUCCESS;
  4223. }
  4224. processing_queue = 1;
  4225. pmbox = lpfc_mbox_get(phba);
  4226. if (!pmbox) {
  4227. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4228. return MBX_SUCCESS;
  4229. }
  4230. }
  4231. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4232. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4233. if(!pmbox->vport) {
  4234. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4235. lpfc_printf_log(phba, KERN_ERR,
  4236. LOG_MBOX | LOG_VPORT,
  4237. "1806 Mbox x%x failed. No vport\n",
  4238. pmbox->u.mb.mbxCommand);
  4239. dump_stack();
  4240. goto out_not_finished;
  4241. }
  4242. }
  4243. /* If the PCI channel is in offline state, do not post mbox. */
  4244. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4245. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4246. goto out_not_finished;
  4247. }
  4248. /* If HBA has a deferred error attention, fail the iocb. */
  4249. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4250. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4251. goto out_not_finished;
  4252. }
  4253. psli = &phba->sli;
  4254. mb = &pmbox->u.mb;
  4255. status = MBX_SUCCESS;
  4256. if (phba->link_state == LPFC_HBA_ERROR) {
  4257. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4258. /* Mbox command <mbxCommand> cannot issue */
  4259. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4260. "(%d):0311 Mailbox command x%x cannot "
  4261. "issue Data: x%x x%x\n",
  4262. pmbox->vport ? pmbox->vport->vpi : 0,
  4263. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4264. goto out_not_finished;
  4265. }
  4266. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4267. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4268. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4269. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4270. "(%d):2528 Mailbox command x%x cannot "
  4271. "issue Data: x%x x%x\n",
  4272. pmbox->vport ? pmbox->vport->vpi : 0,
  4273. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4274. goto out_not_finished;
  4275. }
  4276. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4277. /* Polling for a mbox command when another one is already active
  4278. * is not allowed in SLI. Also, the driver must have established
  4279. * SLI2 mode to queue and process multiple mbox commands.
  4280. */
  4281. if (flag & MBX_POLL) {
  4282. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4283. /* Mbox command <mbxCommand> cannot issue */
  4284. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4285. "(%d):2529 Mailbox command x%x "
  4286. "cannot issue Data: x%x x%x\n",
  4287. pmbox->vport ? pmbox->vport->vpi : 0,
  4288. pmbox->u.mb.mbxCommand,
  4289. psli->sli_flag, flag);
  4290. goto out_not_finished;
  4291. }
  4292. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4293. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4294. /* Mbox command <mbxCommand> cannot issue */
  4295. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4296. "(%d):2530 Mailbox command x%x "
  4297. "cannot issue Data: x%x x%x\n",
  4298. pmbox->vport ? pmbox->vport->vpi : 0,
  4299. pmbox->u.mb.mbxCommand,
  4300. psli->sli_flag, flag);
  4301. goto out_not_finished;
  4302. }
  4303. /* Another mailbox command is still being processed, queue this
  4304. * command to be processed later.
  4305. */
  4306. lpfc_mbox_put(phba, pmbox);
  4307. /* Mbox cmd issue - BUSY */
  4308. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4309. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4310. "x%x x%x x%x x%x\n",
  4311. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4312. mb->mbxCommand, phba->pport->port_state,
  4313. psli->sli_flag, flag);
  4314. psli->slistat.mbox_busy++;
  4315. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4316. if (pmbox->vport) {
  4317. lpfc_debugfs_disc_trc(pmbox->vport,
  4318. LPFC_DISC_TRC_MBOX_VPORT,
  4319. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4320. (uint32_t)mb->mbxCommand,
  4321. mb->un.varWords[0], mb->un.varWords[1]);
  4322. }
  4323. else {
  4324. lpfc_debugfs_disc_trc(phba->pport,
  4325. LPFC_DISC_TRC_MBOX,
  4326. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4327. (uint32_t)mb->mbxCommand,
  4328. mb->un.varWords[0], mb->un.varWords[1]);
  4329. }
  4330. return MBX_BUSY;
  4331. }
  4332. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4333. /* If we are not polling, we MUST be in SLI2 mode */
  4334. if (flag != MBX_POLL) {
  4335. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4336. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4337. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4338. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4339. /* Mbox command <mbxCommand> cannot issue */
  4340. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4341. "(%d):2531 Mailbox command x%x "
  4342. "cannot issue Data: x%x x%x\n",
  4343. pmbox->vport ? pmbox->vport->vpi : 0,
  4344. pmbox->u.mb.mbxCommand,
  4345. psli->sli_flag, flag);
  4346. goto out_not_finished;
  4347. }
  4348. /* timeout active mbox command */
  4349. mod_timer(&psli->mbox_tmo, (jiffies +
  4350. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4351. }
  4352. /* Mailbox cmd <cmd> issue */
  4353. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4354. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4355. "x%x\n",
  4356. pmbox->vport ? pmbox->vport->vpi : 0,
  4357. mb->mbxCommand, phba->pport->port_state,
  4358. psli->sli_flag, flag);
  4359. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4360. if (pmbox->vport) {
  4361. lpfc_debugfs_disc_trc(pmbox->vport,
  4362. LPFC_DISC_TRC_MBOX_VPORT,
  4363. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4364. (uint32_t)mb->mbxCommand,
  4365. mb->un.varWords[0], mb->un.varWords[1]);
  4366. }
  4367. else {
  4368. lpfc_debugfs_disc_trc(phba->pport,
  4369. LPFC_DISC_TRC_MBOX,
  4370. "MBOX Send: cmd:x%x mb:x%x x%x",
  4371. (uint32_t)mb->mbxCommand,
  4372. mb->un.varWords[0], mb->un.varWords[1]);
  4373. }
  4374. }
  4375. psli->slistat.mbox_cmd++;
  4376. evtctr = psli->slistat.mbox_event;
  4377. /* next set own bit for the adapter and copy over command word */
  4378. mb->mbxOwner = OWN_CHIP;
  4379. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4380. /* First copy command data to host SLIM area */
  4381. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4382. } else {
  4383. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4384. /* copy command data into host mbox for cmpl */
  4385. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4386. }
  4387. /* First copy mbox command data to HBA SLIM, skip past first
  4388. word */
  4389. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4390. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4391. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4392. /* Next copy over first word, with mbxOwner set */
  4393. ldata = *((uint32_t *)mb);
  4394. to_slim = phba->MBslimaddr;
  4395. writel(ldata, to_slim);
  4396. readl(to_slim); /* flush */
  4397. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4398. /* switch over to host mailbox */
  4399. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4400. }
  4401. }
  4402. wmb();
  4403. switch (flag) {
  4404. case MBX_NOWAIT:
  4405. /* Set up reference to mailbox command */
  4406. psli->mbox_active = pmbox;
  4407. /* Interrupt board to do it */
  4408. writel(CA_MBATT, phba->CAregaddr);
  4409. readl(phba->CAregaddr); /* flush */
  4410. /* Don't wait for it to finish, just return */
  4411. break;
  4412. case MBX_POLL:
  4413. /* Set up null reference to mailbox command */
  4414. psli->mbox_active = NULL;
  4415. /* Interrupt board to do it */
  4416. writel(CA_MBATT, phba->CAregaddr);
  4417. readl(phba->CAregaddr); /* flush */
  4418. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4419. /* First read mbox status word */
  4420. word0 = *((uint32_t *)phba->mbox);
  4421. word0 = le32_to_cpu(word0);
  4422. } else {
  4423. /* First read mbox status word */
  4424. word0 = readl(phba->MBslimaddr);
  4425. }
  4426. /* Read the HBA Host Attention Register */
  4427. ha_copy = readl(phba->HAregaddr);
  4428. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4429. mb->mbxCommand) *
  4430. 1000) + jiffies;
  4431. i = 0;
  4432. /* Wait for command to complete */
  4433. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4434. (!(ha_copy & HA_MBATT) &&
  4435. (phba->link_state > LPFC_WARM_START))) {
  4436. if (time_after(jiffies, timeout)) {
  4437. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4438. spin_unlock_irqrestore(&phba->hbalock,
  4439. drvr_flag);
  4440. goto out_not_finished;
  4441. }
  4442. /* Check if we took a mbox interrupt while we were
  4443. polling */
  4444. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4445. && (evtctr != psli->slistat.mbox_event))
  4446. break;
  4447. if (i++ > 10) {
  4448. spin_unlock_irqrestore(&phba->hbalock,
  4449. drvr_flag);
  4450. msleep(1);
  4451. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4452. }
  4453. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4454. /* First copy command data */
  4455. word0 = *((uint32_t *)phba->mbox);
  4456. word0 = le32_to_cpu(word0);
  4457. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4458. MAILBOX_t *slimmb;
  4459. uint32_t slimword0;
  4460. /* Check real SLIM for any errors */
  4461. slimword0 = readl(phba->MBslimaddr);
  4462. slimmb = (MAILBOX_t *) & slimword0;
  4463. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4464. && slimmb->mbxStatus) {
  4465. psli->sli_flag &=
  4466. ~LPFC_SLI_ACTIVE;
  4467. word0 = slimword0;
  4468. }
  4469. }
  4470. } else {
  4471. /* First copy command data */
  4472. word0 = readl(phba->MBslimaddr);
  4473. }
  4474. /* Read the HBA Host Attention Register */
  4475. ha_copy = readl(phba->HAregaddr);
  4476. }
  4477. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4478. /* copy results back to user */
  4479. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4480. } else {
  4481. /* First copy command data */
  4482. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4483. MAILBOX_CMD_SIZE);
  4484. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4485. pmbox->context2) {
  4486. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4487. phba->MBslimaddr + DMP_RSP_OFFSET,
  4488. mb->un.varDmp.word_cnt);
  4489. }
  4490. }
  4491. writel(HA_MBATT, phba->HAregaddr);
  4492. readl(phba->HAregaddr); /* flush */
  4493. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4494. status = mb->mbxStatus;
  4495. }
  4496. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4497. return status;
  4498. out_not_finished:
  4499. if (processing_queue) {
  4500. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4501. lpfc_mbox_cmpl_put(phba, pmbox);
  4502. }
  4503. return MBX_NOT_FINISHED;
  4504. }
  4505. /**
  4506. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4507. * @phba: Pointer to HBA context object.
  4508. *
  4509. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4510. * the driver internal pending mailbox queue. It will then try to wait out the
  4511. * possible outstanding mailbox command before return.
  4512. *
  4513. * Returns:
  4514. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4515. * the outstanding mailbox command timed out.
  4516. **/
  4517. static int
  4518. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4519. {
  4520. struct lpfc_sli *psli = &phba->sli;
  4521. uint8_t actcmd = MBX_HEARTBEAT;
  4522. int rc = 0;
  4523. unsigned long timeout;
  4524. /* Mark the asynchronous mailbox command posting as blocked */
  4525. spin_lock_irq(&phba->hbalock);
  4526. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4527. if (phba->sli.mbox_active)
  4528. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4529. spin_unlock_irq(&phba->hbalock);
  4530. /* Determine how long we might wait for the active mailbox
  4531. * command to be gracefully completed by firmware.
  4532. */
  4533. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4534. jiffies;
  4535. /* Wait for the outstnading mailbox command to complete */
  4536. while (phba->sli.mbox_active) {
  4537. /* Check active mailbox complete status every 2ms */
  4538. msleep(2);
  4539. if (time_after(jiffies, timeout)) {
  4540. /* Timeout, marked the outstanding cmd not complete */
  4541. rc = 1;
  4542. break;
  4543. }
  4544. }
  4545. /* Can not cleanly block async mailbox command, fails it */
  4546. if (rc) {
  4547. spin_lock_irq(&phba->hbalock);
  4548. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4549. spin_unlock_irq(&phba->hbalock);
  4550. }
  4551. return rc;
  4552. }
  4553. /**
  4554. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4555. * @phba: Pointer to HBA context object.
  4556. *
  4557. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4558. * commands from the driver internal pending mailbox queue. It makes sure
  4559. * that there is no outstanding mailbox command before resuming posting
  4560. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4561. * mailbox command, it will try to wait it out before resuming asynchronous
  4562. * mailbox command posting.
  4563. **/
  4564. static void
  4565. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4566. {
  4567. struct lpfc_sli *psli = &phba->sli;
  4568. spin_lock_irq(&phba->hbalock);
  4569. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4570. /* Asynchronous mailbox posting is not blocked, do nothing */
  4571. spin_unlock_irq(&phba->hbalock);
  4572. return;
  4573. }
  4574. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4575. * successful or timeout, after timing-out the outstanding mailbox
  4576. * command shall always be removed, so just unblock posting async
  4577. * mailbox command and resume
  4578. */
  4579. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4580. spin_unlock_irq(&phba->hbalock);
  4581. /* wake up worker thread to post asynchronlous mailbox command */
  4582. lpfc_worker_wake_up(phba);
  4583. }
  4584. /**
  4585. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4586. * @phba: Pointer to HBA context object.
  4587. * @mboxq: Pointer to mailbox object.
  4588. *
  4589. * The function posts a mailbox to the port. The mailbox is expected
  4590. * to be comletely filled in and ready for the port to operate on it.
  4591. * This routine executes a synchronous completion operation on the
  4592. * mailbox by polling for its completion.
  4593. *
  4594. * The caller must not be holding any locks when calling this routine.
  4595. *
  4596. * Returns:
  4597. * MBX_SUCCESS - mailbox posted successfully
  4598. * Any of the MBX error values.
  4599. **/
  4600. static int
  4601. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4602. {
  4603. int rc = MBX_SUCCESS;
  4604. unsigned long iflag;
  4605. uint32_t db_ready;
  4606. uint32_t mcqe_status;
  4607. uint32_t mbx_cmnd;
  4608. unsigned long timeout;
  4609. struct lpfc_sli *psli = &phba->sli;
  4610. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4611. struct lpfc_bmbx_create *mbox_rgn;
  4612. struct dma_address *dma_address;
  4613. struct lpfc_register bmbx_reg;
  4614. /*
  4615. * Only one mailbox can be active to the bootstrap mailbox region
  4616. * at a time and there is no queueing provided.
  4617. */
  4618. spin_lock_irqsave(&phba->hbalock, iflag);
  4619. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4620. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4621. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4622. "(%d):2532 Mailbox command x%x (x%x) "
  4623. "cannot issue Data: x%x x%x\n",
  4624. mboxq->vport ? mboxq->vport->vpi : 0,
  4625. mboxq->u.mb.mbxCommand,
  4626. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4627. psli->sli_flag, MBX_POLL);
  4628. return MBXERR_ERROR;
  4629. }
  4630. /* The server grabs the token and owns it until release */
  4631. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4632. phba->sli.mbox_active = mboxq;
  4633. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4634. /*
  4635. * Initialize the bootstrap memory region to avoid stale data areas
  4636. * in the mailbox post. Then copy the caller's mailbox contents to
  4637. * the bmbx mailbox region.
  4638. */
  4639. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4640. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4641. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4642. sizeof(struct lpfc_mqe));
  4643. /* Post the high mailbox dma address to the port and wait for ready. */
  4644. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4645. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4646. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4647. * 1000) + jiffies;
  4648. do {
  4649. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4650. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4651. if (!db_ready)
  4652. msleep(2);
  4653. if (time_after(jiffies, timeout)) {
  4654. rc = MBXERR_ERROR;
  4655. goto exit;
  4656. }
  4657. } while (!db_ready);
  4658. /* Post the low mailbox dma address to the port. */
  4659. writel(dma_address->addr_lo, 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. /*
  4673. * Read the CQ to ensure the mailbox has completed.
  4674. * If so, update the mailbox status so that the upper layers
  4675. * can complete the request normally.
  4676. */
  4677. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4678. sizeof(struct lpfc_mqe));
  4679. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4680. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4681. sizeof(struct lpfc_mcqe));
  4682. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4683. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4684. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4685. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4686. rc = MBXERR_ERROR;
  4687. }
  4688. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4689. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4690. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4691. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4692. mboxq->vport ? mboxq->vport->vpi : 0,
  4693. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4694. bf_get(lpfc_mqe_status, mb),
  4695. mb->un.mb_words[0], mb->un.mb_words[1],
  4696. mb->un.mb_words[2], mb->un.mb_words[3],
  4697. mb->un.mb_words[4], mb->un.mb_words[5],
  4698. mb->un.mb_words[6], mb->un.mb_words[7],
  4699. mb->un.mb_words[8], mb->un.mb_words[9],
  4700. mb->un.mb_words[10], mb->un.mb_words[11],
  4701. mb->un.mb_words[12], mboxq->mcqe.word0,
  4702. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4703. mboxq->mcqe.trailer);
  4704. exit:
  4705. /* We are holding the token, no needed for lock when release */
  4706. spin_lock_irqsave(&phba->hbalock, iflag);
  4707. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4708. phba->sli.mbox_active = NULL;
  4709. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4710. return rc;
  4711. }
  4712. /**
  4713. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4714. * @phba: Pointer to HBA context object.
  4715. * @pmbox: Pointer to mailbox object.
  4716. * @flag: Flag indicating how the mailbox need to be processed.
  4717. *
  4718. * This function is called by discovery code and HBA management code to submit
  4719. * a mailbox command to firmware with SLI-4 interface spec.
  4720. *
  4721. * Return codes the caller owns the mailbox command after the return of the
  4722. * function.
  4723. **/
  4724. static int
  4725. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4726. uint32_t flag)
  4727. {
  4728. struct lpfc_sli *psli = &phba->sli;
  4729. unsigned long iflags;
  4730. int rc;
  4731. rc = lpfc_mbox_dev_check(phba);
  4732. if (unlikely(rc)) {
  4733. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4734. "(%d):2544 Mailbox command x%x (x%x) "
  4735. "cannot issue Data: x%x x%x\n",
  4736. mboxq->vport ? mboxq->vport->vpi : 0,
  4737. mboxq->u.mb.mbxCommand,
  4738. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4739. psli->sli_flag, flag);
  4740. goto out_not_finished;
  4741. }
  4742. /* Detect polling mode and jump to a handler */
  4743. if (!phba->sli4_hba.intr_enable) {
  4744. if (flag == MBX_POLL)
  4745. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4746. else
  4747. rc = -EIO;
  4748. if (rc != MBX_SUCCESS)
  4749. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4750. "(%d):2541 Mailbox command x%x "
  4751. "(x%x) cannot issue Data: x%x x%x\n",
  4752. mboxq->vport ? mboxq->vport->vpi : 0,
  4753. mboxq->u.mb.mbxCommand,
  4754. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4755. psli->sli_flag, flag);
  4756. return rc;
  4757. } else if (flag == MBX_POLL) {
  4758. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4759. "(%d):2542 Try to issue mailbox command "
  4760. "x%x (x%x) synchronously ahead of async"
  4761. "mailbox command queue: x%x x%x\n",
  4762. mboxq->vport ? mboxq->vport->vpi : 0,
  4763. mboxq->u.mb.mbxCommand,
  4764. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4765. psli->sli_flag, flag);
  4766. /* Try to block the asynchronous mailbox posting */
  4767. rc = lpfc_sli4_async_mbox_block(phba);
  4768. if (!rc) {
  4769. /* Successfully blocked, now issue sync mbox cmd */
  4770. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4771. if (rc != MBX_SUCCESS)
  4772. lpfc_printf_log(phba, KERN_ERR,
  4773. LOG_MBOX | LOG_SLI,
  4774. "(%d):2597 Mailbox command "
  4775. "x%x (x%x) cannot issue "
  4776. "Data: x%x x%x\n",
  4777. mboxq->vport ?
  4778. mboxq->vport->vpi : 0,
  4779. mboxq->u.mb.mbxCommand,
  4780. lpfc_sli4_mbox_opcode_get(phba,
  4781. mboxq),
  4782. psli->sli_flag, flag);
  4783. /* Unblock the async mailbox posting afterward */
  4784. lpfc_sli4_async_mbox_unblock(phba);
  4785. }
  4786. return rc;
  4787. }
  4788. /* Now, interrupt mode asynchrous mailbox command */
  4789. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4790. if (rc) {
  4791. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4792. "(%d):2543 Mailbox command x%x (x%x) "
  4793. "cannot issue Data: x%x x%x\n",
  4794. mboxq->vport ? mboxq->vport->vpi : 0,
  4795. mboxq->u.mb.mbxCommand,
  4796. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4797. psli->sli_flag, flag);
  4798. goto out_not_finished;
  4799. }
  4800. /* Put the mailbox command to the driver internal FIFO */
  4801. psli->slistat.mbox_busy++;
  4802. spin_lock_irqsave(&phba->hbalock, iflags);
  4803. lpfc_mbox_put(phba, mboxq);
  4804. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4805. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4806. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4807. "x%x (x%x) x%x x%x x%x\n",
  4808. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4809. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4810. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4811. phba->pport->port_state,
  4812. psli->sli_flag, MBX_NOWAIT);
  4813. /* Wake up worker thread to transport mailbox command from head */
  4814. lpfc_worker_wake_up(phba);
  4815. return MBX_BUSY;
  4816. out_not_finished:
  4817. return MBX_NOT_FINISHED;
  4818. }
  4819. /**
  4820. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4821. * @phba: Pointer to HBA context object.
  4822. *
  4823. * This function is called by worker thread to send a mailbox command to
  4824. * SLI4 HBA firmware.
  4825. *
  4826. **/
  4827. int
  4828. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4829. {
  4830. struct lpfc_sli *psli = &phba->sli;
  4831. LPFC_MBOXQ_t *mboxq;
  4832. int rc = MBX_SUCCESS;
  4833. unsigned long iflags;
  4834. struct lpfc_mqe *mqe;
  4835. uint32_t mbx_cmnd;
  4836. /* Check interrupt mode before post async mailbox command */
  4837. if (unlikely(!phba->sli4_hba.intr_enable))
  4838. return MBX_NOT_FINISHED;
  4839. /* Check for mailbox command service token */
  4840. spin_lock_irqsave(&phba->hbalock, iflags);
  4841. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4842. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4843. return MBX_NOT_FINISHED;
  4844. }
  4845. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4846. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4847. return MBX_NOT_FINISHED;
  4848. }
  4849. if (unlikely(phba->sli.mbox_active)) {
  4850. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4851. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4852. "0384 There is pending active mailbox cmd\n");
  4853. return MBX_NOT_FINISHED;
  4854. }
  4855. /* Take the mailbox command service token */
  4856. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4857. /* Get the next mailbox command from head of queue */
  4858. mboxq = lpfc_mbox_get(phba);
  4859. /* If no more mailbox command waiting for post, we're done */
  4860. if (!mboxq) {
  4861. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4862. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4863. return MBX_SUCCESS;
  4864. }
  4865. phba->sli.mbox_active = mboxq;
  4866. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4867. /* Check device readiness for posting mailbox command */
  4868. rc = lpfc_mbox_dev_check(phba);
  4869. if (unlikely(rc))
  4870. /* Driver clean routine will clean up pending mailbox */
  4871. goto out_not_finished;
  4872. /* Prepare the mbox command to be posted */
  4873. mqe = &mboxq->u.mqe;
  4874. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4875. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4876. mod_timer(&psli->mbox_tmo, (jiffies +
  4877. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4878. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4879. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4880. "x%x x%x\n",
  4881. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4882. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4883. phba->pport->port_state, psli->sli_flag);
  4884. if (mbx_cmnd != MBX_HEARTBEAT) {
  4885. if (mboxq->vport) {
  4886. lpfc_debugfs_disc_trc(mboxq->vport,
  4887. LPFC_DISC_TRC_MBOX_VPORT,
  4888. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4889. mbx_cmnd, mqe->un.mb_words[0],
  4890. mqe->un.mb_words[1]);
  4891. } else {
  4892. lpfc_debugfs_disc_trc(phba->pport,
  4893. LPFC_DISC_TRC_MBOX,
  4894. "MBOX Send: cmd:x%x mb:x%x x%x",
  4895. mbx_cmnd, mqe->un.mb_words[0],
  4896. mqe->un.mb_words[1]);
  4897. }
  4898. }
  4899. psli->slistat.mbox_cmd++;
  4900. /* Post the mailbox command to the port */
  4901. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4902. if (rc != MBX_SUCCESS) {
  4903. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4904. "(%d):2533 Mailbox command x%x (x%x) "
  4905. "cannot issue Data: x%x x%x\n",
  4906. mboxq->vport ? mboxq->vport->vpi : 0,
  4907. mboxq->u.mb.mbxCommand,
  4908. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4909. psli->sli_flag, MBX_NOWAIT);
  4910. goto out_not_finished;
  4911. }
  4912. return rc;
  4913. out_not_finished:
  4914. spin_lock_irqsave(&phba->hbalock, iflags);
  4915. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4916. __lpfc_mbox_cmpl_put(phba, mboxq);
  4917. /* Release the token */
  4918. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4919. phba->sli.mbox_active = NULL;
  4920. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4921. return MBX_NOT_FINISHED;
  4922. }
  4923. /**
  4924. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4925. * @phba: Pointer to HBA context object.
  4926. * @pmbox: Pointer to mailbox object.
  4927. * @flag: Flag indicating how the mailbox need to be processed.
  4928. *
  4929. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4930. * the API jump table function pointer from the lpfc_hba struct.
  4931. *
  4932. * Return codes the caller owns the mailbox command after the return of the
  4933. * function.
  4934. **/
  4935. int
  4936. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4937. {
  4938. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4939. }
  4940. /**
  4941. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4942. * @phba: The hba struct for which this call is being executed.
  4943. * @dev_grp: The HBA PCI-Device group number.
  4944. *
  4945. * This routine sets up the mbox interface API function jump table in @phba
  4946. * struct.
  4947. * Returns: 0 - success, -ENODEV - failure.
  4948. **/
  4949. int
  4950. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4951. {
  4952. switch (dev_grp) {
  4953. case LPFC_PCI_DEV_LP:
  4954. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  4955. phba->lpfc_sli_handle_slow_ring_event =
  4956. lpfc_sli_handle_slow_ring_event_s3;
  4957. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  4958. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  4959. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  4960. break;
  4961. case LPFC_PCI_DEV_OC:
  4962. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  4963. phba->lpfc_sli_handle_slow_ring_event =
  4964. lpfc_sli_handle_slow_ring_event_s4;
  4965. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  4966. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  4967. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  4968. break;
  4969. default:
  4970. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4971. "1420 Invalid HBA PCI-device group: 0x%x\n",
  4972. dev_grp);
  4973. return -ENODEV;
  4974. break;
  4975. }
  4976. return 0;
  4977. }
  4978. /**
  4979. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  4980. * @phba: Pointer to HBA context object.
  4981. * @pring: Pointer to driver SLI ring object.
  4982. * @piocb: Pointer to address of newly added command iocb.
  4983. *
  4984. * This function is called with hbalock held to add a command
  4985. * iocb to the txq when SLI layer cannot submit the command iocb
  4986. * to the ring.
  4987. **/
  4988. static void
  4989. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  4990. struct lpfc_iocbq *piocb)
  4991. {
  4992. /* Insert the caller's iocb in the txq tail for later processing. */
  4993. list_add_tail(&piocb->list, &pring->txq);
  4994. pring->txq_cnt++;
  4995. }
  4996. /**
  4997. * lpfc_sli_next_iocb - Get the next iocb in the txq
  4998. * @phba: Pointer to HBA context object.
  4999. * @pring: Pointer to driver SLI ring object.
  5000. * @piocb: Pointer to address of newly added command iocb.
  5001. *
  5002. * This function is called with hbalock held before a new
  5003. * iocb is submitted to the firmware. This function checks
  5004. * txq to flush the iocbs in txq to Firmware before
  5005. * submitting new iocbs to the Firmware.
  5006. * If there are iocbs in the txq which need to be submitted
  5007. * to firmware, lpfc_sli_next_iocb returns the first element
  5008. * of the txq after dequeuing it from txq.
  5009. * If there is no iocb in the txq then the function will return
  5010. * *piocb and *piocb is set to NULL. Caller needs to check
  5011. * *piocb to find if there are more commands in the txq.
  5012. **/
  5013. static struct lpfc_iocbq *
  5014. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5015. struct lpfc_iocbq **piocb)
  5016. {
  5017. struct lpfc_iocbq * nextiocb;
  5018. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5019. if (!nextiocb) {
  5020. nextiocb = *piocb;
  5021. *piocb = NULL;
  5022. }
  5023. return nextiocb;
  5024. }
  5025. /**
  5026. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5027. * @phba: Pointer to HBA context object.
  5028. * @ring_number: SLI ring number to issue iocb on.
  5029. * @piocb: Pointer to command iocb.
  5030. * @flag: Flag indicating if this command can be put into txq.
  5031. *
  5032. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5033. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5034. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5035. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5036. * this function allows only iocbs for posting buffers. This function finds
  5037. * next available slot in the command ring and posts the command to the
  5038. * available slot and writes the port attention register to request HBA start
  5039. * processing new iocb. If there is no slot available in the ring and
  5040. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5041. * the function returns IOCB_BUSY.
  5042. *
  5043. * This function is called with hbalock held. The function will return success
  5044. * after it successfully submit the iocb to firmware or after adding to the
  5045. * txq.
  5046. **/
  5047. static int
  5048. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5049. struct lpfc_iocbq *piocb, uint32_t flag)
  5050. {
  5051. struct lpfc_iocbq *nextiocb;
  5052. IOCB_t *iocb;
  5053. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5054. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5055. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5056. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5057. lpfc_printf_log(phba, KERN_ERR,
  5058. LOG_SLI | LOG_VPORT,
  5059. "1807 IOCB x%x failed. No vport\n",
  5060. piocb->iocb.ulpCommand);
  5061. dump_stack();
  5062. return IOCB_ERROR;
  5063. }
  5064. /* If the PCI channel is in offline state, do not post iocbs. */
  5065. if (unlikely(pci_channel_offline(phba->pcidev)))
  5066. return IOCB_ERROR;
  5067. /* If HBA has a deferred error attention, fail the iocb. */
  5068. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5069. return IOCB_ERROR;
  5070. /*
  5071. * We should never get an IOCB if we are in a < LINK_DOWN state
  5072. */
  5073. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5074. return IOCB_ERROR;
  5075. /*
  5076. * Check to see if we are blocking IOCB processing because of a
  5077. * outstanding event.
  5078. */
  5079. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5080. goto iocb_busy;
  5081. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5082. /*
  5083. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5084. * can be issued if the link is not up.
  5085. */
  5086. switch (piocb->iocb.ulpCommand) {
  5087. case CMD_GEN_REQUEST64_CR:
  5088. case CMD_GEN_REQUEST64_CX:
  5089. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5090. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5091. FC_RCTL_DD_UNSOL_CMD) ||
  5092. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5093. MENLO_TRANSPORT_TYPE))
  5094. goto iocb_busy;
  5095. break;
  5096. case CMD_QUE_RING_BUF_CN:
  5097. case CMD_QUE_RING_BUF64_CN:
  5098. /*
  5099. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5100. * completion, iocb_cmpl MUST be 0.
  5101. */
  5102. if (piocb->iocb_cmpl)
  5103. piocb->iocb_cmpl = NULL;
  5104. /*FALLTHROUGH*/
  5105. case CMD_CREATE_XRI_CR:
  5106. case CMD_CLOSE_XRI_CN:
  5107. case CMD_CLOSE_XRI_CX:
  5108. break;
  5109. default:
  5110. goto iocb_busy;
  5111. }
  5112. /*
  5113. * For FCP commands, we must be in a state where we can process link
  5114. * attention events.
  5115. */
  5116. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5117. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5118. goto iocb_busy;
  5119. }
  5120. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5121. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5122. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5123. if (iocb)
  5124. lpfc_sli_update_ring(phba, pring);
  5125. else
  5126. lpfc_sli_update_full_ring(phba, pring);
  5127. if (!piocb)
  5128. return IOCB_SUCCESS;
  5129. goto out_busy;
  5130. iocb_busy:
  5131. pring->stats.iocb_cmd_delay++;
  5132. out_busy:
  5133. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5134. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5135. return IOCB_SUCCESS;
  5136. }
  5137. return IOCB_BUSY;
  5138. }
  5139. /**
  5140. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5141. * @phba: Pointer to HBA context object.
  5142. * @piocb: Pointer to command iocb.
  5143. * @sglq: Pointer to the scatter gather queue object.
  5144. *
  5145. * This routine converts the bpl or bde that is in the IOCB
  5146. * to a sgl list for the sli4 hardware. The physical address
  5147. * of the bpl/bde is converted back to a virtual address.
  5148. * If the IOCB contains a BPL then the list of BDE's is
  5149. * converted to sli4_sge's. If the IOCB contains a single
  5150. * BDE then it is converted to a single sli_sge.
  5151. * The IOCB is still in cpu endianess so the contents of
  5152. * the bpl can be used without byte swapping.
  5153. *
  5154. * Returns valid XRI = Success, NO_XRI = Failure.
  5155. **/
  5156. static uint16_t
  5157. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5158. struct lpfc_sglq *sglq)
  5159. {
  5160. uint16_t xritag = NO_XRI;
  5161. struct ulp_bde64 *bpl = NULL;
  5162. struct ulp_bde64 bde;
  5163. struct sli4_sge *sgl = NULL;
  5164. IOCB_t *icmd;
  5165. int numBdes = 0;
  5166. int i = 0;
  5167. if (!piocbq || !sglq)
  5168. return xritag;
  5169. sgl = (struct sli4_sge *)sglq->sgl;
  5170. icmd = &piocbq->iocb;
  5171. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5172. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5173. sizeof(struct ulp_bde64);
  5174. /* The addrHigh and addrLow fields within the IOCB
  5175. * have not been byteswapped yet so there is no
  5176. * need to swap them back.
  5177. */
  5178. bpl = (struct ulp_bde64 *)
  5179. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5180. if (!bpl)
  5181. return xritag;
  5182. for (i = 0; i < numBdes; i++) {
  5183. /* Should already be byte swapped. */
  5184. sgl->addr_hi = bpl->addrHigh;
  5185. sgl->addr_lo = bpl->addrLow;
  5186. if ((i+1) == numBdes)
  5187. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5188. else
  5189. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5190. sgl->word2 = cpu_to_le32(sgl->word2);
  5191. /* swap the size field back to the cpu so we
  5192. * can assign it to the sgl.
  5193. */
  5194. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5195. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5196. bpl++;
  5197. sgl++;
  5198. }
  5199. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5200. /* The addrHigh and addrLow fields of the BDE have not
  5201. * been byteswapped yet so they need to be swapped
  5202. * before putting them in the sgl.
  5203. */
  5204. sgl->addr_hi =
  5205. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5206. sgl->addr_lo =
  5207. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5208. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5209. sgl->word2 = cpu_to_le32(sgl->word2);
  5210. sgl->sge_len =
  5211. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5212. }
  5213. return sglq->sli4_xritag;
  5214. }
  5215. /**
  5216. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5217. * @phba: Pointer to HBA context object.
  5218. *
  5219. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5220. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5221. * held.
  5222. *
  5223. * Return: index into SLI4 fast-path FCP queue index.
  5224. **/
  5225. static uint32_t
  5226. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5227. {
  5228. ++phba->fcp_qidx;
  5229. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5230. phba->fcp_qidx = 0;
  5231. return phba->fcp_qidx;
  5232. }
  5233. /**
  5234. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5235. * @phba: Pointer to HBA context object.
  5236. * @piocb: Pointer to command iocb.
  5237. * @wqe: Pointer to the work queue entry.
  5238. *
  5239. * This routine converts the iocb command to its Work Queue Entry
  5240. * equivalent. The wqe pointer should not have any fields set when
  5241. * this routine is called because it will memcpy over them.
  5242. * This routine does not set the CQ_ID or the WQEC bits in the
  5243. * wqe.
  5244. *
  5245. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5246. **/
  5247. static int
  5248. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5249. union lpfc_wqe *wqe)
  5250. {
  5251. uint32_t xmit_len = 0, total_len = 0;
  5252. uint8_t ct = 0;
  5253. uint32_t fip;
  5254. uint32_t abort_tag;
  5255. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5256. uint8_t cmnd;
  5257. uint16_t xritag;
  5258. struct ulp_bde64 *bpl = NULL;
  5259. uint32_t els_id = ELS_ID_DEFAULT;
  5260. int numBdes, i;
  5261. struct ulp_bde64 bde;
  5262. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5263. /* The fcp commands will set command type */
  5264. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5265. command_type = FCP_COMMAND;
  5266. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5267. command_type = ELS_COMMAND_FIP;
  5268. else
  5269. command_type = ELS_COMMAND_NON_FIP;
  5270. /* Some of the fields are in the right position already */
  5271. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5272. abort_tag = (uint32_t) iocbq->iotag;
  5273. xritag = iocbq->sli4_xritag;
  5274. wqe->words[7] = 0; /* The ct field has moved so reset */
  5275. /* words0-2 bpl convert bde */
  5276. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5277. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5278. sizeof(struct ulp_bde64);
  5279. bpl = (struct ulp_bde64 *)
  5280. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5281. if (!bpl)
  5282. return IOCB_ERROR;
  5283. /* Should already be byte swapped. */
  5284. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5285. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5286. /* swap the size field back to the cpu so we
  5287. * can assign it to the sgl.
  5288. */
  5289. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5290. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5291. total_len = 0;
  5292. for (i = 0; i < numBdes; i++) {
  5293. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5294. total_len += bde.tus.f.bdeSize;
  5295. }
  5296. } else
  5297. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5298. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5299. cmnd = iocbq->iocb.ulpCommand;
  5300. switch (iocbq->iocb.ulpCommand) {
  5301. case CMD_ELS_REQUEST64_CR:
  5302. if (!iocbq->iocb.ulpLe) {
  5303. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5304. "2007 Only Limited Edition cmd Format"
  5305. " supported 0x%x\n",
  5306. iocbq->iocb.ulpCommand);
  5307. return IOCB_ERROR;
  5308. }
  5309. wqe->els_req.payload_len = xmit_len;
  5310. /* Els_reguest64 has a TMO */
  5311. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5312. iocbq->iocb.ulpTimeout);
  5313. /* Need a VF for word 4 set the vf bit*/
  5314. bf_set(els_req64_vf, &wqe->els_req, 0);
  5315. /* And a VFID for word 12 */
  5316. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5317. /*
  5318. * Set ct field to 3, indicates that the context_tag field
  5319. * contains the FCFI and remote N_Port_ID is
  5320. * in word 5.
  5321. */
  5322. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5323. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5324. iocbq->iocb.ulpContext);
  5325. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5326. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5327. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5328. if (command_type == ELS_COMMAND_FIP) {
  5329. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5330. >> LPFC_FIP_ELS_ID_SHIFT);
  5331. }
  5332. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5333. break;
  5334. case CMD_XMIT_SEQUENCE64_CX:
  5335. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5336. iocbq->iocb.un.ulpWord[3]);
  5337. wqe->generic.word3 = 0;
  5338. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5339. /* The entire sequence is transmitted for this IOCB */
  5340. xmit_len = total_len;
  5341. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5342. case CMD_XMIT_SEQUENCE64_CR:
  5343. /* word3 iocb=io_tag32 wqe=payload_offset */
  5344. /* payload offset used for multilpe outstanding
  5345. * sequences on the same exchange
  5346. */
  5347. wqe->words[3] = 0;
  5348. /* word4 relative_offset memcpy */
  5349. /* word5 r_ctl/df_ctl memcpy */
  5350. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5351. wqe->xmit_sequence.xmit_len = xmit_len;
  5352. command_type = OTHER_COMMAND;
  5353. break;
  5354. case CMD_XMIT_BCAST64_CN:
  5355. /* word3 iocb=iotag32 wqe=payload_len */
  5356. wqe->words[3] = 0; /* no definition for this in wqe */
  5357. /* word4 iocb=rsvd wqe=rsvd */
  5358. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5359. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5360. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5361. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5362. break;
  5363. case CMD_FCP_IWRITE64_CR:
  5364. command_type = FCP_COMMAND_DATA_OUT;
  5365. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5366. * confusing.
  5367. * word3 is payload_len: byte offset to the sgl entry for the
  5368. * fcp_command.
  5369. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5370. * word5 is initial xfer len 0 = wait for xfer-ready
  5371. */
  5372. /* Always wait for xfer-ready before sending data */
  5373. wqe->fcp_iwrite.initial_xfer_len = 0;
  5374. /* word 4 (xfer length) should have been set on the memcpy */
  5375. /* allow write to fall through to read */
  5376. case CMD_FCP_IREAD64_CR:
  5377. /* FCP_CMD is always the 1st sgl entry */
  5378. wqe->fcp_iread.payload_len =
  5379. xmit_len + sizeof(struct fcp_rsp);
  5380. /* word 4 (xfer length) should have been set on the memcpy */
  5381. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5382. iocbq->iocb.ulpFCP2Rcvy);
  5383. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5384. /* The XC bit and the XS bit are similar. The driver never
  5385. * tracked whether or not the exchange was previouslly open.
  5386. * XC = Exchange create, 0 is create. 1 is already open.
  5387. * XS = link cmd: 1 do not close the exchange after command.
  5388. * XS = 0 close exchange when command completes.
  5389. * The only time we would not set the XC bit is when the XS bit
  5390. * is set and we are sending our 2nd or greater command on
  5391. * this exchange.
  5392. */
  5393. /* Always open the exchange */
  5394. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5395. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5396. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5397. break;
  5398. case CMD_FCP_ICMND64_CR:
  5399. /* Always open the exchange */
  5400. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5401. wqe->words[4] = 0;
  5402. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5403. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5404. break;
  5405. case CMD_GEN_REQUEST64_CR:
  5406. /* word3 command length is described as byte offset to the
  5407. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5408. * sgl[0] = cmnd
  5409. * sgl[1] = rsp.
  5410. *
  5411. */
  5412. wqe->gen_req.command_len = xmit_len;
  5413. /* Word4 parameter copied in the memcpy */
  5414. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5415. /* word6 context tag copied in memcpy */
  5416. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5417. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5418. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5419. "2015 Invalid CT %x command 0x%x\n",
  5420. ct, iocbq->iocb.ulpCommand);
  5421. return IOCB_ERROR;
  5422. }
  5423. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5424. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5425. iocbq->iocb.ulpTimeout);
  5426. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5427. command_type = OTHER_COMMAND;
  5428. break;
  5429. case CMD_XMIT_ELS_RSP64_CX:
  5430. /* words0-2 BDE memcpy */
  5431. /* word3 iocb=iotag32 wqe=rsvd */
  5432. wqe->words[3] = 0;
  5433. /* word4 iocb=did wge=rsvd. */
  5434. wqe->words[4] = 0;
  5435. /* word5 iocb=rsvd wge=did */
  5436. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5437. iocbq->iocb.un.elsreq64.remoteID);
  5438. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5439. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5440. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5441. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5442. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5443. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5444. iocbq->vport->vpi + phba->vpi_base);
  5445. command_type = OTHER_COMMAND;
  5446. break;
  5447. case CMD_CLOSE_XRI_CN:
  5448. case CMD_ABORT_XRI_CN:
  5449. case CMD_ABORT_XRI_CX:
  5450. /* words 0-2 memcpy should be 0 rserved */
  5451. /* port will send abts */
  5452. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5453. /*
  5454. * The link is down so the fw does not need to send abts
  5455. * on the wire.
  5456. */
  5457. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5458. else
  5459. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5460. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5461. wqe->words[5] = 0;
  5462. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5463. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5464. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5465. /*
  5466. * The abort handler will send us CMD_ABORT_XRI_CN or
  5467. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5468. */
  5469. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5470. cmnd = CMD_ABORT_XRI_CX;
  5471. command_type = OTHER_COMMAND;
  5472. xritag = 0;
  5473. break;
  5474. case CMD_XMIT_BLS_RSP64_CX:
  5475. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5476. * we re-construct this WQE here based on information in
  5477. * iocbq from scratch.
  5478. */
  5479. memset(wqe, 0, sizeof(union lpfc_wqe));
  5480. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5481. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5482. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5483. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5484. LPFC_ABTS_UNSOL_INT) {
  5485. /* ABTS sent by initiator to CT exchange, the
  5486. * RX_ID field will be filled with the newly
  5487. * allocated responder XRI.
  5488. */
  5489. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5490. iocbq->sli4_xritag);
  5491. } else {
  5492. /* ABTS sent by responder to CT exchange, the
  5493. * RX_ID field will be filled with the responder
  5494. * RX_ID from ABTS.
  5495. */
  5496. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5497. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5498. }
  5499. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5500. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5501. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5502. iocbq->iocb.ulpContext);
  5503. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5504. command_type = OTHER_COMMAND;
  5505. break;
  5506. case CMD_XRI_ABORTED_CX:
  5507. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5508. /* words0-2 are all 0's no bde */
  5509. /* word3 and word4 are rsvrd */
  5510. wqe->words[3] = 0;
  5511. wqe->words[4] = 0;
  5512. /* word5 iocb=rsvd wge=did */
  5513. /* There is no remote port id in the IOCB? */
  5514. /* Let this fall through and fail */
  5515. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5516. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5517. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5518. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5519. default:
  5520. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5521. "2014 Invalid command 0x%x\n",
  5522. iocbq->iocb.ulpCommand);
  5523. return IOCB_ERROR;
  5524. break;
  5525. }
  5526. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5527. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5528. wqe->generic.abort_tag = abort_tag;
  5529. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5530. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5531. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5532. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5533. return 0;
  5534. }
  5535. /**
  5536. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5537. * @phba: Pointer to HBA context object.
  5538. * @ring_number: SLI ring number to issue iocb on.
  5539. * @piocb: Pointer to command iocb.
  5540. * @flag: Flag indicating if this command can be put into txq.
  5541. *
  5542. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5543. * an iocb command to an HBA with SLI-4 interface spec.
  5544. *
  5545. * This function is called with hbalock held. The function will return success
  5546. * after it successfully submit the iocb to firmware or after adding to the
  5547. * txq.
  5548. **/
  5549. static int
  5550. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5551. struct lpfc_iocbq *piocb, uint32_t flag)
  5552. {
  5553. struct lpfc_sglq *sglq;
  5554. uint16_t xritag;
  5555. union lpfc_wqe wqe;
  5556. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5557. if (piocb->sli4_xritag == NO_XRI) {
  5558. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5559. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5560. sglq = NULL;
  5561. else {
  5562. sglq = __lpfc_sli_get_sglq(phba);
  5563. if (!sglq)
  5564. return IOCB_ERROR;
  5565. piocb->sli4_xritag = sglq->sli4_xritag;
  5566. }
  5567. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5568. sglq = NULL; /* These IO's already have an XRI and
  5569. * a mapped sgl.
  5570. */
  5571. } else {
  5572. /* This is a continuation of a commandi,(CX) so this
  5573. * sglq is on the active list
  5574. */
  5575. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5576. if (!sglq)
  5577. return IOCB_ERROR;
  5578. }
  5579. if (sglq) {
  5580. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5581. if (xritag != sglq->sli4_xritag)
  5582. return IOCB_ERROR;
  5583. }
  5584. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5585. return IOCB_ERROR;
  5586. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5587. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5588. /*
  5589. * For FCP command IOCB, get a new WQ index to distribute
  5590. * WQE across the WQsr. On the other hand, for abort IOCB,
  5591. * it carries the same WQ index to the original command
  5592. * IOCB.
  5593. */
  5594. if (piocb->iocb_flag & LPFC_IO_FCP)
  5595. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5596. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5597. &wqe))
  5598. return IOCB_ERROR;
  5599. } else {
  5600. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5601. return IOCB_ERROR;
  5602. }
  5603. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5604. return 0;
  5605. }
  5606. /**
  5607. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5608. *
  5609. * This routine wraps the actual lockless version for issusing IOCB function
  5610. * pointer from the lpfc_hba struct.
  5611. *
  5612. * Return codes:
  5613. * IOCB_ERROR - Error
  5614. * IOCB_SUCCESS - Success
  5615. * IOCB_BUSY - Busy
  5616. **/
  5617. static inline int
  5618. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5619. struct lpfc_iocbq *piocb, uint32_t flag)
  5620. {
  5621. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5622. }
  5623. /**
  5624. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5625. * @phba: The hba struct for which this call is being executed.
  5626. * @dev_grp: The HBA PCI-Device group number.
  5627. *
  5628. * This routine sets up the SLI interface API function jump table in @phba
  5629. * struct.
  5630. * Returns: 0 - success, -ENODEV - failure.
  5631. **/
  5632. int
  5633. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5634. {
  5635. switch (dev_grp) {
  5636. case LPFC_PCI_DEV_LP:
  5637. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5638. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5639. break;
  5640. case LPFC_PCI_DEV_OC:
  5641. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5642. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5643. break;
  5644. default:
  5645. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5646. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5647. dev_grp);
  5648. return -ENODEV;
  5649. break;
  5650. }
  5651. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5652. return 0;
  5653. }
  5654. /**
  5655. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5656. * @phba: Pointer to HBA context object.
  5657. * @pring: Pointer to driver SLI ring object.
  5658. * @piocb: Pointer to command iocb.
  5659. * @flag: Flag indicating if this command can be put into txq.
  5660. *
  5661. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5662. * function. This function gets the hbalock and calls
  5663. * __lpfc_sli_issue_iocb function and will return the error returned
  5664. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5665. * functions which do not hold hbalock.
  5666. **/
  5667. int
  5668. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5669. struct lpfc_iocbq *piocb, uint32_t flag)
  5670. {
  5671. unsigned long iflags;
  5672. int rc;
  5673. spin_lock_irqsave(&phba->hbalock, iflags);
  5674. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5675. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5676. return rc;
  5677. }
  5678. /**
  5679. * lpfc_extra_ring_setup - Extra ring setup function
  5680. * @phba: Pointer to HBA context object.
  5681. *
  5682. * This function is called while driver attaches with the
  5683. * HBA to setup the extra ring. The extra ring is used
  5684. * only when driver needs to support target mode functionality
  5685. * or IP over FC functionalities.
  5686. *
  5687. * This function is called with no lock held.
  5688. **/
  5689. static int
  5690. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5691. {
  5692. struct lpfc_sli *psli;
  5693. struct lpfc_sli_ring *pring;
  5694. psli = &phba->sli;
  5695. /* Adjust cmd/rsp ring iocb entries more evenly */
  5696. /* Take some away from the FCP ring */
  5697. pring = &psli->ring[psli->fcp_ring];
  5698. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5699. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5700. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5701. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5702. /* and give them to the extra ring */
  5703. pring = &psli->ring[psli->extra_ring];
  5704. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5705. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5706. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5707. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5708. /* Setup default profile for this ring */
  5709. pring->iotag_max = 4096;
  5710. pring->num_mask = 1;
  5711. pring->prt[0].profile = 0; /* Mask 0 */
  5712. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5713. pring->prt[0].type = phba->cfg_multi_ring_type;
  5714. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5715. return 0;
  5716. }
  5717. /**
  5718. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5719. * @phba: Pointer to HBA context object.
  5720. * @pring: Pointer to driver SLI ring object.
  5721. * @iocbq: Pointer to iocb object.
  5722. *
  5723. * This function is called by the slow ring event handler
  5724. * function when there is an ASYNC event iocb in the ring.
  5725. * This function is called with no lock held.
  5726. * Currently this function handles only temperature related
  5727. * ASYNC events. The function decodes the temperature sensor
  5728. * event message and posts events for the management applications.
  5729. **/
  5730. static void
  5731. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5732. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5733. {
  5734. IOCB_t *icmd;
  5735. uint16_t evt_code;
  5736. uint16_t temp;
  5737. struct temp_event temp_event_data;
  5738. struct Scsi_Host *shost;
  5739. uint32_t *iocb_w;
  5740. icmd = &iocbq->iocb;
  5741. evt_code = icmd->un.asyncstat.evt_code;
  5742. temp = icmd->ulpContext;
  5743. if ((evt_code != ASYNC_TEMP_WARN) &&
  5744. (evt_code != ASYNC_TEMP_SAFE)) {
  5745. iocb_w = (uint32_t *) icmd;
  5746. lpfc_printf_log(phba,
  5747. KERN_ERR,
  5748. LOG_SLI,
  5749. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5750. " evt_code 0x%x\n"
  5751. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5752. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5753. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5754. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5755. pring->ringno,
  5756. icmd->un.asyncstat.evt_code,
  5757. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5758. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5759. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5760. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5761. return;
  5762. }
  5763. temp_event_data.data = (uint32_t)temp;
  5764. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5765. if (evt_code == ASYNC_TEMP_WARN) {
  5766. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5767. lpfc_printf_log(phba,
  5768. KERN_ERR,
  5769. LOG_TEMP,
  5770. "0347 Adapter is very hot, please take "
  5771. "corrective action. temperature : %d Celsius\n",
  5772. temp);
  5773. }
  5774. if (evt_code == ASYNC_TEMP_SAFE) {
  5775. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5776. lpfc_printf_log(phba,
  5777. KERN_ERR,
  5778. LOG_TEMP,
  5779. "0340 Adapter temperature is OK now. "
  5780. "temperature : %d Celsius\n",
  5781. temp);
  5782. }
  5783. /* Send temperature change event to applications */
  5784. shost = lpfc_shost_from_vport(phba->pport);
  5785. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5786. sizeof(temp_event_data), (char *) &temp_event_data,
  5787. LPFC_NL_VENDOR_ID);
  5788. }
  5789. /**
  5790. * lpfc_sli_setup - SLI ring setup function
  5791. * @phba: Pointer to HBA context object.
  5792. *
  5793. * lpfc_sli_setup sets up rings of the SLI interface with
  5794. * number of iocbs per ring and iotags. This function is
  5795. * called while driver attach to the HBA and before the
  5796. * interrupts are enabled. So there is no need for locking.
  5797. *
  5798. * This function always returns 0.
  5799. **/
  5800. int
  5801. lpfc_sli_setup(struct lpfc_hba *phba)
  5802. {
  5803. int i, totiocbsize = 0;
  5804. struct lpfc_sli *psli = &phba->sli;
  5805. struct lpfc_sli_ring *pring;
  5806. psli->num_rings = MAX_CONFIGURED_RINGS;
  5807. psli->sli_flag = 0;
  5808. psli->fcp_ring = LPFC_FCP_RING;
  5809. psli->next_ring = LPFC_FCP_NEXT_RING;
  5810. psli->extra_ring = LPFC_EXTRA_RING;
  5811. psli->iocbq_lookup = NULL;
  5812. psli->iocbq_lookup_len = 0;
  5813. psli->last_iotag = 0;
  5814. for (i = 0; i < psli->num_rings; i++) {
  5815. pring = &psli->ring[i];
  5816. switch (i) {
  5817. case LPFC_FCP_RING: /* ring 0 - FCP */
  5818. /* numCiocb and numRiocb are used in config_port */
  5819. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5820. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5821. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5822. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5823. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5824. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5825. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5826. SLI3_IOCB_CMD_SIZE :
  5827. SLI2_IOCB_CMD_SIZE;
  5828. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5829. SLI3_IOCB_RSP_SIZE :
  5830. SLI2_IOCB_RSP_SIZE;
  5831. pring->iotag_ctr = 0;
  5832. pring->iotag_max =
  5833. (phba->cfg_hba_queue_depth * 2);
  5834. pring->fast_iotag = pring->iotag_max;
  5835. pring->num_mask = 0;
  5836. break;
  5837. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5838. /* numCiocb and numRiocb are used in config_port */
  5839. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5840. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5841. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5842. SLI3_IOCB_CMD_SIZE :
  5843. SLI2_IOCB_CMD_SIZE;
  5844. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5845. SLI3_IOCB_RSP_SIZE :
  5846. SLI2_IOCB_RSP_SIZE;
  5847. pring->iotag_max = phba->cfg_hba_queue_depth;
  5848. pring->num_mask = 0;
  5849. break;
  5850. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5851. /* numCiocb and numRiocb are used in config_port */
  5852. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5853. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5854. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5855. SLI3_IOCB_CMD_SIZE :
  5856. SLI2_IOCB_CMD_SIZE;
  5857. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5858. SLI3_IOCB_RSP_SIZE :
  5859. SLI2_IOCB_RSP_SIZE;
  5860. pring->fast_iotag = 0;
  5861. pring->iotag_ctr = 0;
  5862. pring->iotag_max = 4096;
  5863. pring->lpfc_sli_rcv_async_status =
  5864. lpfc_sli_async_event_handler;
  5865. pring->num_mask = LPFC_MAX_RING_MASK;
  5866. pring->prt[0].profile = 0; /* Mask 0 */
  5867. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5868. pring->prt[0].type = FC_TYPE_ELS;
  5869. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5870. lpfc_els_unsol_event;
  5871. pring->prt[1].profile = 0; /* Mask 1 */
  5872. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5873. pring->prt[1].type = FC_TYPE_ELS;
  5874. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5875. lpfc_els_unsol_event;
  5876. pring->prt[2].profile = 0; /* Mask 2 */
  5877. /* NameServer Inquiry */
  5878. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5879. /* NameServer */
  5880. pring->prt[2].type = FC_TYPE_CT;
  5881. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5882. lpfc_ct_unsol_event;
  5883. pring->prt[3].profile = 0; /* Mask 3 */
  5884. /* NameServer response */
  5885. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  5886. /* NameServer */
  5887. pring->prt[3].type = FC_TYPE_CT;
  5888. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5889. lpfc_ct_unsol_event;
  5890. /* abort unsolicited sequence */
  5891. pring->prt[4].profile = 0; /* Mask 4 */
  5892. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  5893. pring->prt[4].type = FC_TYPE_BLS;
  5894. pring->prt[4].lpfc_sli_rcv_unsol_event =
  5895. lpfc_sli4_ct_abort_unsol_event;
  5896. break;
  5897. }
  5898. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5899. (pring->numRiocb * pring->sizeRiocb);
  5900. }
  5901. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5902. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5903. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5904. "SLI2 SLIM Data: x%x x%lx\n",
  5905. phba->brd_no, totiocbsize,
  5906. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5907. }
  5908. if (phba->cfg_multi_ring_support == 2)
  5909. lpfc_extra_ring_setup(phba);
  5910. return 0;
  5911. }
  5912. /**
  5913. * lpfc_sli_queue_setup - Queue initialization function
  5914. * @phba: Pointer to HBA context object.
  5915. *
  5916. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5917. * ring. This function also initializes ring indices of each ring.
  5918. * This function is called during the initialization of the SLI
  5919. * interface of an HBA.
  5920. * This function is called with no lock held and always returns
  5921. * 1.
  5922. **/
  5923. int
  5924. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5925. {
  5926. struct lpfc_sli *psli;
  5927. struct lpfc_sli_ring *pring;
  5928. int i;
  5929. psli = &phba->sli;
  5930. spin_lock_irq(&phba->hbalock);
  5931. INIT_LIST_HEAD(&psli->mboxq);
  5932. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5933. /* Initialize list headers for txq and txcmplq as double linked lists */
  5934. for (i = 0; i < psli->num_rings; i++) {
  5935. pring = &psli->ring[i];
  5936. pring->ringno = i;
  5937. pring->next_cmdidx = 0;
  5938. pring->local_getidx = 0;
  5939. pring->cmdidx = 0;
  5940. INIT_LIST_HEAD(&pring->txq);
  5941. INIT_LIST_HEAD(&pring->txcmplq);
  5942. INIT_LIST_HEAD(&pring->iocb_continueq);
  5943. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5944. INIT_LIST_HEAD(&pring->postbufq);
  5945. }
  5946. spin_unlock_irq(&phba->hbalock);
  5947. return 1;
  5948. }
  5949. /**
  5950. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5951. * @phba: Pointer to HBA context object.
  5952. *
  5953. * This routine flushes the mailbox command subsystem. It will unconditionally
  5954. * flush all the mailbox commands in the three possible stages in the mailbox
  5955. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5956. * command; and completed mailbox command queue. It is caller's responsibility
  5957. * to make sure that the driver is in the proper state to flush the mailbox
  5958. * command sub-system. Namely, the posting of mailbox commands into the
  5959. * pending mailbox command queue from the various clients must be stopped;
  5960. * either the HBA is in a state that it will never works on the outstanding
  5961. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  5962. * mailbox command has been completed.
  5963. **/
  5964. static void
  5965. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  5966. {
  5967. LIST_HEAD(completions);
  5968. struct lpfc_sli *psli = &phba->sli;
  5969. LPFC_MBOXQ_t *pmb;
  5970. unsigned long iflag;
  5971. /* Flush all the mailbox commands in the mbox system */
  5972. spin_lock_irqsave(&phba->hbalock, iflag);
  5973. /* The pending mailbox command queue */
  5974. list_splice_init(&phba->sli.mboxq, &completions);
  5975. /* The outstanding active mailbox command */
  5976. if (psli->mbox_active) {
  5977. list_add_tail(&psli->mbox_active->list, &completions);
  5978. psli->mbox_active = NULL;
  5979. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5980. }
  5981. /* The completed mailbox command queue */
  5982. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  5983. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5984. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  5985. while (!list_empty(&completions)) {
  5986. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  5987. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5988. if (pmb->mbox_cmpl)
  5989. pmb->mbox_cmpl(phba, pmb);
  5990. }
  5991. }
  5992. /**
  5993. * lpfc_sli_host_down - Vport cleanup function
  5994. * @vport: Pointer to virtual port object.
  5995. *
  5996. * lpfc_sli_host_down is called to clean up the resources
  5997. * associated with a vport before destroying virtual
  5998. * port data structures.
  5999. * This function does following operations:
  6000. * - Free discovery resources associated with this virtual
  6001. * port.
  6002. * - Free iocbs associated with this virtual port in
  6003. * the txq.
  6004. * - Send abort for all iocb commands associated with this
  6005. * vport in txcmplq.
  6006. *
  6007. * This function is called with no lock held and always returns 1.
  6008. **/
  6009. int
  6010. lpfc_sli_host_down(struct lpfc_vport *vport)
  6011. {
  6012. LIST_HEAD(completions);
  6013. struct lpfc_hba *phba = vport->phba;
  6014. struct lpfc_sli *psli = &phba->sli;
  6015. struct lpfc_sli_ring *pring;
  6016. struct lpfc_iocbq *iocb, *next_iocb;
  6017. int i;
  6018. unsigned long flags = 0;
  6019. uint16_t prev_pring_flag;
  6020. lpfc_cleanup_discovery_resources(vport);
  6021. spin_lock_irqsave(&phba->hbalock, flags);
  6022. for (i = 0; i < psli->num_rings; i++) {
  6023. pring = &psli->ring[i];
  6024. prev_pring_flag = pring->flag;
  6025. /* Only slow rings */
  6026. if (pring->ringno == LPFC_ELS_RING) {
  6027. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6028. /* Set the lpfc data pending flag */
  6029. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6030. }
  6031. /*
  6032. * Error everything on the txq since these iocbs have not been
  6033. * given to the FW yet.
  6034. */
  6035. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6036. if (iocb->vport != vport)
  6037. continue;
  6038. list_move_tail(&iocb->list, &completions);
  6039. pring->txq_cnt--;
  6040. }
  6041. /* Next issue ABTS for everything on the txcmplq */
  6042. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6043. list) {
  6044. if (iocb->vport != vport)
  6045. continue;
  6046. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6047. }
  6048. pring->flag = prev_pring_flag;
  6049. }
  6050. spin_unlock_irqrestore(&phba->hbalock, flags);
  6051. /* Cancel all the IOCBs from the completions list */
  6052. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6053. IOERR_SLI_DOWN);
  6054. return 1;
  6055. }
  6056. /**
  6057. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6058. * @phba: Pointer to HBA context object.
  6059. *
  6060. * This function cleans up all iocb, buffers, mailbox commands
  6061. * while shutting down the HBA. This function is called with no
  6062. * lock held and always returns 1.
  6063. * This function does the following to cleanup driver resources:
  6064. * - Free discovery resources for each virtual port
  6065. * - Cleanup any pending fabric iocbs
  6066. * - Iterate through the iocb txq and free each entry
  6067. * in the list.
  6068. * - Free up any buffer posted to the HBA
  6069. * - Free mailbox commands in the mailbox queue.
  6070. **/
  6071. int
  6072. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6073. {
  6074. LIST_HEAD(completions);
  6075. struct lpfc_sli *psli = &phba->sli;
  6076. struct lpfc_sli_ring *pring;
  6077. struct lpfc_dmabuf *buf_ptr;
  6078. unsigned long flags = 0;
  6079. int i;
  6080. /* Shutdown the mailbox command sub-system */
  6081. lpfc_sli_mbox_sys_shutdown(phba);
  6082. lpfc_hba_down_prep(phba);
  6083. lpfc_fabric_abort_hba(phba);
  6084. spin_lock_irqsave(&phba->hbalock, flags);
  6085. for (i = 0; i < psli->num_rings; i++) {
  6086. pring = &psli->ring[i];
  6087. /* Only slow rings */
  6088. if (pring->ringno == LPFC_ELS_RING) {
  6089. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6090. /* Set the lpfc data pending flag */
  6091. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6092. }
  6093. /*
  6094. * Error everything on the txq since these iocbs have not been
  6095. * given to the FW yet.
  6096. */
  6097. list_splice_init(&pring->txq, &completions);
  6098. pring->txq_cnt = 0;
  6099. }
  6100. spin_unlock_irqrestore(&phba->hbalock, flags);
  6101. /* Cancel all the IOCBs from the completions list */
  6102. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6103. IOERR_SLI_DOWN);
  6104. spin_lock_irqsave(&phba->hbalock, flags);
  6105. list_splice_init(&phba->elsbuf, &completions);
  6106. phba->elsbuf_cnt = 0;
  6107. phba->elsbuf_prev_cnt = 0;
  6108. spin_unlock_irqrestore(&phba->hbalock, flags);
  6109. while (!list_empty(&completions)) {
  6110. list_remove_head(&completions, buf_ptr,
  6111. struct lpfc_dmabuf, list);
  6112. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6113. kfree(buf_ptr);
  6114. }
  6115. /* Return any active mbox cmds */
  6116. del_timer_sync(&psli->mbox_tmo);
  6117. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6118. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6119. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6120. return 1;
  6121. }
  6122. /**
  6123. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6124. * @phba: Pointer to HBA context object.
  6125. *
  6126. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6127. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6128. * lock held and always returns 1.
  6129. *
  6130. * This function does the following to cleanup driver FCoE function resources:
  6131. * - Free discovery resources for each virtual port
  6132. * - Cleanup any pending fabric iocbs
  6133. * - Iterate through the iocb txq and free each entry in the list.
  6134. * - Free up any buffer posted to the HBA.
  6135. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6136. * - Free mailbox commands in the mailbox queue.
  6137. **/
  6138. int
  6139. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6140. {
  6141. /* Stop the SLI4 device port */
  6142. lpfc_stop_port(phba);
  6143. /* Tear down the queues in the HBA */
  6144. lpfc_sli4_queue_unset(phba);
  6145. /* unregister default FCFI from the HBA */
  6146. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6147. return 1;
  6148. }
  6149. /**
  6150. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6151. * @srcp: Source memory pointer.
  6152. * @destp: Destination memory pointer.
  6153. * @cnt: Number of words required to be copied.
  6154. *
  6155. * This function is used for copying data between driver memory
  6156. * and the SLI memory. This function also changes the endianness
  6157. * of each word if native endianness is different from SLI
  6158. * endianness. This function can be called with or without
  6159. * lock.
  6160. **/
  6161. void
  6162. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6163. {
  6164. uint32_t *src = srcp;
  6165. uint32_t *dest = destp;
  6166. uint32_t ldata;
  6167. int i;
  6168. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6169. ldata = *src;
  6170. ldata = le32_to_cpu(ldata);
  6171. *dest = ldata;
  6172. src++;
  6173. dest++;
  6174. }
  6175. }
  6176. /**
  6177. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6178. * @srcp: Source memory pointer.
  6179. * @destp: Destination memory pointer.
  6180. * @cnt: Number of words required to be copied.
  6181. *
  6182. * This function is used for copying data between a data structure
  6183. * with big endian representation to local endianness.
  6184. * This function can be called with or without lock.
  6185. **/
  6186. void
  6187. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6188. {
  6189. uint32_t *src = srcp;
  6190. uint32_t *dest = destp;
  6191. uint32_t ldata;
  6192. int i;
  6193. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6194. ldata = *src;
  6195. ldata = be32_to_cpu(ldata);
  6196. *dest = ldata;
  6197. src++;
  6198. dest++;
  6199. }
  6200. }
  6201. /**
  6202. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6203. * @phba: Pointer to HBA context object.
  6204. * @pring: Pointer to driver SLI ring object.
  6205. * @mp: Pointer to driver buffer object.
  6206. *
  6207. * This function is called with no lock held.
  6208. * It always return zero after adding the buffer to the postbufq
  6209. * buffer list.
  6210. **/
  6211. int
  6212. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6213. struct lpfc_dmabuf *mp)
  6214. {
  6215. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6216. later */
  6217. spin_lock_irq(&phba->hbalock);
  6218. list_add_tail(&mp->list, &pring->postbufq);
  6219. pring->postbufq_cnt++;
  6220. spin_unlock_irq(&phba->hbalock);
  6221. return 0;
  6222. }
  6223. /**
  6224. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6225. * @phba: Pointer to HBA context object.
  6226. *
  6227. * When HBQ is enabled, buffers are searched based on tags. This function
  6228. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6229. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6230. * does not conflict with tags of buffer posted for unsolicited events.
  6231. * The function returns the allocated tag. The function is called with
  6232. * no locks held.
  6233. **/
  6234. uint32_t
  6235. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6236. {
  6237. spin_lock_irq(&phba->hbalock);
  6238. phba->buffer_tag_count++;
  6239. /*
  6240. * Always set the QUE_BUFTAG_BIT to distiguish between
  6241. * a tag assigned by HBQ.
  6242. */
  6243. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6244. spin_unlock_irq(&phba->hbalock);
  6245. return phba->buffer_tag_count;
  6246. }
  6247. /**
  6248. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6249. * @phba: Pointer to HBA context object.
  6250. * @pring: Pointer to driver SLI ring object.
  6251. * @tag: Buffer tag.
  6252. *
  6253. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6254. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6255. * iocb is posted to the response ring with the tag of the buffer.
  6256. * This function searches the pring->postbufq list using the tag
  6257. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6258. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6259. * buffer is returned to the caller else NULL is returned.
  6260. * This function is called with no lock held.
  6261. **/
  6262. struct lpfc_dmabuf *
  6263. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6264. uint32_t tag)
  6265. {
  6266. struct lpfc_dmabuf *mp, *next_mp;
  6267. struct list_head *slp = &pring->postbufq;
  6268. /* Search postbufq, from the begining, looking for a match on tag */
  6269. spin_lock_irq(&phba->hbalock);
  6270. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6271. if (mp->buffer_tag == tag) {
  6272. list_del_init(&mp->list);
  6273. pring->postbufq_cnt--;
  6274. spin_unlock_irq(&phba->hbalock);
  6275. return mp;
  6276. }
  6277. }
  6278. spin_unlock_irq(&phba->hbalock);
  6279. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6280. "0402 Cannot find virtual addr for buffer tag on "
  6281. "ring %d Data x%lx x%p x%p x%x\n",
  6282. pring->ringno, (unsigned long) tag,
  6283. slp->next, slp->prev, pring->postbufq_cnt);
  6284. return NULL;
  6285. }
  6286. /**
  6287. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6288. * @phba: Pointer to HBA context object.
  6289. * @pring: Pointer to driver SLI ring object.
  6290. * @phys: DMA address of the buffer.
  6291. *
  6292. * This function searches the buffer list using the dma_address
  6293. * of unsolicited event to find the driver's lpfc_dmabuf object
  6294. * corresponding to the dma_address. The function returns the
  6295. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6296. * This function is called by the ct and els unsolicited event
  6297. * handlers to get the buffer associated with the unsolicited
  6298. * event.
  6299. *
  6300. * This function is called with no lock held.
  6301. **/
  6302. struct lpfc_dmabuf *
  6303. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6304. dma_addr_t phys)
  6305. {
  6306. struct lpfc_dmabuf *mp, *next_mp;
  6307. struct list_head *slp = &pring->postbufq;
  6308. /* Search postbufq, from the begining, looking for a match on phys */
  6309. spin_lock_irq(&phba->hbalock);
  6310. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6311. if (mp->phys == phys) {
  6312. list_del_init(&mp->list);
  6313. pring->postbufq_cnt--;
  6314. spin_unlock_irq(&phba->hbalock);
  6315. return mp;
  6316. }
  6317. }
  6318. spin_unlock_irq(&phba->hbalock);
  6319. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6320. "0410 Cannot find virtual addr for mapped buf on "
  6321. "ring %d Data x%llx x%p x%p x%x\n",
  6322. pring->ringno, (unsigned long long)phys,
  6323. slp->next, slp->prev, pring->postbufq_cnt);
  6324. return NULL;
  6325. }
  6326. /**
  6327. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6328. * @phba: Pointer to HBA context object.
  6329. * @cmdiocb: Pointer to driver command iocb object.
  6330. * @rspiocb: Pointer to driver response iocb object.
  6331. *
  6332. * This function is the completion handler for the abort iocbs for
  6333. * ELS commands. This function is called from the ELS ring event
  6334. * handler with no lock held. This function frees memory resources
  6335. * associated with the abort iocb.
  6336. **/
  6337. static void
  6338. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6339. struct lpfc_iocbq *rspiocb)
  6340. {
  6341. IOCB_t *irsp = &rspiocb->iocb;
  6342. uint16_t abort_iotag, abort_context;
  6343. struct lpfc_iocbq *abort_iocb;
  6344. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6345. abort_iocb = NULL;
  6346. if (irsp->ulpStatus) {
  6347. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6348. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6349. spin_lock_irq(&phba->hbalock);
  6350. if (phba->sli_rev < LPFC_SLI_REV4) {
  6351. if (abort_iotag != 0 &&
  6352. abort_iotag <= phba->sli.last_iotag)
  6353. abort_iocb =
  6354. phba->sli.iocbq_lookup[abort_iotag];
  6355. } else
  6356. /* For sli4 the abort_tag is the XRI,
  6357. * so the abort routine puts the iotag of the iocb
  6358. * being aborted in the context field of the abort
  6359. * IOCB.
  6360. */
  6361. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6362. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6363. "0327 Cannot abort els iocb %p "
  6364. "with tag %x context %x, abort status %x, "
  6365. "abort code %x\n",
  6366. abort_iocb, abort_iotag, abort_context,
  6367. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6368. /*
  6369. * If the iocb is not found in Firmware queue the iocb
  6370. * might have completed already. Do not free it again.
  6371. */
  6372. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6373. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6374. spin_unlock_irq(&phba->hbalock);
  6375. lpfc_sli_release_iocbq(phba, cmdiocb);
  6376. return;
  6377. }
  6378. /* For SLI4 the ulpContext field for abort IOCB
  6379. * holds the iotag of the IOCB being aborted so
  6380. * the local abort_context needs to be reset to
  6381. * match the aborted IOCBs ulpContext.
  6382. */
  6383. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6384. abort_context = abort_iocb->iocb.ulpContext;
  6385. }
  6386. /*
  6387. * make sure we have the right iocbq before taking it
  6388. * off the txcmplq and try to call completion routine.
  6389. */
  6390. if (!abort_iocb ||
  6391. abort_iocb->iocb.ulpContext != abort_context ||
  6392. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6393. spin_unlock_irq(&phba->hbalock);
  6394. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6395. /*
  6396. * leave the SLI4 aborted command on the txcmplq
  6397. * list and the command complete WCQE's XB bit
  6398. * will tell whether the SGL (XRI) can be released
  6399. * immediately or to the aborted SGL list for the
  6400. * following abort XRI from the HBA.
  6401. */
  6402. list_del_init(&abort_iocb->list);
  6403. pring->txcmplq_cnt--;
  6404. spin_unlock_irq(&phba->hbalock);
  6405. /* Firmware could still be in progress of DMAing
  6406. * payload, so don't free data buffer till after
  6407. * a hbeat.
  6408. */
  6409. spin_lock_irq(&phba->hbalock);
  6410. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6411. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6412. spin_unlock_irq(&phba->hbalock);
  6413. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6414. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6415. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6416. }
  6417. }
  6418. lpfc_sli_release_iocbq(phba, cmdiocb);
  6419. return;
  6420. }
  6421. /**
  6422. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6423. * @phba: Pointer to HBA context object.
  6424. * @cmdiocb: Pointer to driver command iocb object.
  6425. * @rspiocb: Pointer to driver response iocb object.
  6426. *
  6427. * The function is called from SLI ring event handler with no
  6428. * lock held. This function is the completion handler for ELS commands
  6429. * which are aborted. The function frees memory resources used for
  6430. * the aborted ELS commands.
  6431. **/
  6432. static void
  6433. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6434. struct lpfc_iocbq *rspiocb)
  6435. {
  6436. IOCB_t *irsp = &rspiocb->iocb;
  6437. /* ELS cmd tag <ulpIoTag> completes */
  6438. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6439. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6440. "x%x x%x x%x\n",
  6441. irsp->ulpIoTag, irsp->ulpStatus,
  6442. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6443. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6444. lpfc_ct_free_iocb(phba, cmdiocb);
  6445. else
  6446. lpfc_els_free_iocb(phba, cmdiocb);
  6447. return;
  6448. }
  6449. /**
  6450. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6451. * @phba: Pointer to HBA context object.
  6452. * @pring: Pointer to driver SLI ring object.
  6453. * @cmdiocb: Pointer to driver command iocb object.
  6454. *
  6455. * This function issues an abort iocb for the provided command
  6456. * iocb. This function is called with hbalock held.
  6457. * The function returns 0 when it fails due to memory allocation
  6458. * failure or when the command iocb is an abort request.
  6459. **/
  6460. int
  6461. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6462. struct lpfc_iocbq *cmdiocb)
  6463. {
  6464. struct lpfc_vport *vport = cmdiocb->vport;
  6465. struct lpfc_iocbq *abtsiocbp;
  6466. IOCB_t *icmd = NULL;
  6467. IOCB_t *iabt = NULL;
  6468. int retval = IOCB_ERROR;
  6469. /*
  6470. * There are certain command types we don't want to abort. And we
  6471. * don't want to abort commands that are already in the process of
  6472. * being aborted.
  6473. */
  6474. icmd = &cmdiocb->iocb;
  6475. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6476. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6477. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6478. return 0;
  6479. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6480. * callback so that nothing happens when it finishes.
  6481. */
  6482. if ((vport->load_flag & FC_UNLOADING) &&
  6483. (pring->ringno == LPFC_ELS_RING)) {
  6484. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6485. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6486. else
  6487. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6488. goto abort_iotag_exit;
  6489. }
  6490. /* issue ABTS for this IOCB based on iotag */
  6491. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6492. if (abtsiocbp == NULL)
  6493. return 0;
  6494. /* This signals the response to set the correct status
  6495. * before calling the completion handler
  6496. */
  6497. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6498. iabt = &abtsiocbp->iocb;
  6499. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6500. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6501. if (phba->sli_rev == LPFC_SLI_REV4) {
  6502. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6503. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6504. }
  6505. else
  6506. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6507. iabt->ulpLe = 1;
  6508. iabt->ulpClass = icmd->ulpClass;
  6509. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6510. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6511. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6512. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6513. if (phba->link_state >= LPFC_LINK_UP)
  6514. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6515. else
  6516. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6517. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6518. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6519. "0339 Abort xri x%x, original iotag x%x, "
  6520. "abort cmd iotag x%x\n",
  6521. iabt->un.acxri.abortContextTag,
  6522. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6523. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6524. if (retval)
  6525. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6526. abort_iotag_exit:
  6527. /*
  6528. * Caller to this routine should check for IOCB_ERROR
  6529. * and handle it properly. This routine no longer removes
  6530. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6531. */
  6532. return retval;
  6533. }
  6534. /**
  6535. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6536. * @iocbq: Pointer to driver iocb object.
  6537. * @vport: Pointer to driver virtual port object.
  6538. * @tgt_id: SCSI ID of the target.
  6539. * @lun_id: LUN ID of the scsi device.
  6540. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6541. *
  6542. * This function acts as an iocb filter for functions which abort or count
  6543. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6544. * 0 if the filtering criteria is met for the given iocb and will return
  6545. * 1 if the filtering criteria is not met.
  6546. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6547. * given iocb is for the SCSI device specified by vport, tgt_id and
  6548. * lun_id parameter.
  6549. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6550. * given iocb is for the SCSI target specified by vport and tgt_id
  6551. * parameters.
  6552. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6553. * given iocb is for the SCSI host associated with the given vport.
  6554. * This function is called with no locks held.
  6555. **/
  6556. static int
  6557. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6558. uint16_t tgt_id, uint64_t lun_id,
  6559. lpfc_ctx_cmd ctx_cmd)
  6560. {
  6561. struct lpfc_scsi_buf *lpfc_cmd;
  6562. int rc = 1;
  6563. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6564. return rc;
  6565. if (iocbq->vport != vport)
  6566. return rc;
  6567. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6568. if (lpfc_cmd->pCmd == NULL)
  6569. return rc;
  6570. switch (ctx_cmd) {
  6571. case LPFC_CTX_LUN:
  6572. if ((lpfc_cmd->rdata->pnode) &&
  6573. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6574. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6575. rc = 0;
  6576. break;
  6577. case LPFC_CTX_TGT:
  6578. if ((lpfc_cmd->rdata->pnode) &&
  6579. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6580. rc = 0;
  6581. break;
  6582. case LPFC_CTX_HOST:
  6583. rc = 0;
  6584. break;
  6585. default:
  6586. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6587. __func__, ctx_cmd);
  6588. break;
  6589. }
  6590. return rc;
  6591. }
  6592. /**
  6593. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6594. * @vport: Pointer to virtual port.
  6595. * @tgt_id: SCSI ID of the target.
  6596. * @lun_id: LUN ID of the scsi device.
  6597. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6598. *
  6599. * This function returns number of FCP commands pending for the vport.
  6600. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6601. * commands pending on the vport associated with SCSI device specified
  6602. * by tgt_id and lun_id parameters.
  6603. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6604. * commands pending on the vport associated with SCSI target specified
  6605. * by tgt_id parameter.
  6606. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6607. * commands pending on the vport.
  6608. * This function returns the number of iocbs which satisfy the filter.
  6609. * This function is called without any lock held.
  6610. **/
  6611. int
  6612. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6613. lpfc_ctx_cmd ctx_cmd)
  6614. {
  6615. struct lpfc_hba *phba = vport->phba;
  6616. struct lpfc_iocbq *iocbq;
  6617. int sum, i;
  6618. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6619. iocbq = phba->sli.iocbq_lookup[i];
  6620. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6621. ctx_cmd) == 0)
  6622. sum++;
  6623. }
  6624. return sum;
  6625. }
  6626. /**
  6627. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6628. * @phba: Pointer to HBA context object
  6629. * @cmdiocb: Pointer to command iocb object.
  6630. * @rspiocb: Pointer to response iocb object.
  6631. *
  6632. * This function is called when an aborted FCP iocb completes. This
  6633. * function is called by the ring event handler with no lock held.
  6634. * This function frees the iocb.
  6635. **/
  6636. void
  6637. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6638. struct lpfc_iocbq *rspiocb)
  6639. {
  6640. lpfc_sli_release_iocbq(phba, cmdiocb);
  6641. return;
  6642. }
  6643. /**
  6644. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6645. * @vport: Pointer to virtual port.
  6646. * @pring: Pointer to driver SLI ring object.
  6647. * @tgt_id: SCSI ID of the target.
  6648. * @lun_id: LUN ID of the scsi device.
  6649. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6650. *
  6651. * This function sends an abort command for every SCSI command
  6652. * associated with the given virtual port pending on the ring
  6653. * filtered by lpfc_sli_validate_fcp_iocb function.
  6654. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6655. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6656. * parameters
  6657. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6658. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6659. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6660. * FCP iocbs associated with virtual port.
  6661. * This function returns number of iocbs it failed to abort.
  6662. * This function is called with no locks held.
  6663. **/
  6664. int
  6665. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6666. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6667. {
  6668. struct lpfc_hba *phba = vport->phba;
  6669. struct lpfc_iocbq *iocbq;
  6670. struct lpfc_iocbq *abtsiocb;
  6671. IOCB_t *cmd = NULL;
  6672. int errcnt = 0, ret_val = 0;
  6673. int i;
  6674. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6675. iocbq = phba->sli.iocbq_lookup[i];
  6676. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6677. abort_cmd) != 0)
  6678. continue;
  6679. /* issue ABTS for this IOCB based on iotag */
  6680. abtsiocb = lpfc_sli_get_iocbq(phba);
  6681. if (abtsiocb == NULL) {
  6682. errcnt++;
  6683. continue;
  6684. }
  6685. cmd = &iocbq->iocb;
  6686. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6687. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6688. if (phba->sli_rev == LPFC_SLI_REV4)
  6689. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6690. else
  6691. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6692. abtsiocb->iocb.ulpLe = 1;
  6693. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6694. abtsiocb->vport = phba->pport;
  6695. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6696. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6697. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6698. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6699. if (lpfc_is_link_up(phba))
  6700. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6701. else
  6702. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6703. /* Setup callback routine and issue the command. */
  6704. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6705. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6706. abtsiocb, 0);
  6707. if (ret_val == IOCB_ERROR) {
  6708. lpfc_sli_release_iocbq(phba, abtsiocb);
  6709. errcnt++;
  6710. continue;
  6711. }
  6712. }
  6713. return errcnt;
  6714. }
  6715. /**
  6716. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6717. * @phba: Pointer to HBA context object.
  6718. * @cmdiocbq: Pointer to command iocb.
  6719. * @rspiocbq: Pointer to response iocb.
  6720. *
  6721. * This function is the completion handler for iocbs issued using
  6722. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6723. * ring event handler function without any lock held. This function
  6724. * can be called from both worker thread context and interrupt
  6725. * context. This function also can be called from other thread which
  6726. * cleans up the SLI layer objects.
  6727. * This function copy the contents of the response iocb to the
  6728. * response iocb memory object provided by the caller of
  6729. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6730. * sleeps for the iocb completion.
  6731. **/
  6732. static void
  6733. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6734. struct lpfc_iocbq *cmdiocbq,
  6735. struct lpfc_iocbq *rspiocbq)
  6736. {
  6737. wait_queue_head_t *pdone_q;
  6738. unsigned long iflags;
  6739. spin_lock_irqsave(&phba->hbalock, iflags);
  6740. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6741. if (cmdiocbq->context2 && rspiocbq)
  6742. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6743. &rspiocbq->iocb, sizeof(IOCB_t));
  6744. pdone_q = cmdiocbq->context_un.wait_queue;
  6745. if (pdone_q)
  6746. wake_up(pdone_q);
  6747. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6748. return;
  6749. }
  6750. /**
  6751. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6752. * @phba: Pointer to HBA context object..
  6753. * @piocbq: Pointer to command iocb.
  6754. * @flag: Flag to test.
  6755. *
  6756. * This routine grabs the hbalock and then test the iocb_flag to
  6757. * see if the passed in flag is set.
  6758. * Returns:
  6759. * 1 if flag is set.
  6760. * 0 if flag is not set.
  6761. **/
  6762. static int
  6763. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6764. struct lpfc_iocbq *piocbq, uint32_t flag)
  6765. {
  6766. unsigned long iflags;
  6767. int ret;
  6768. spin_lock_irqsave(&phba->hbalock, iflags);
  6769. ret = piocbq->iocb_flag & flag;
  6770. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6771. return ret;
  6772. }
  6773. /**
  6774. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6775. * @phba: Pointer to HBA context object..
  6776. * @pring: Pointer to sli ring.
  6777. * @piocb: Pointer to command iocb.
  6778. * @prspiocbq: Pointer to response iocb.
  6779. * @timeout: Timeout in number of seconds.
  6780. *
  6781. * This function issues the iocb to firmware and waits for the
  6782. * iocb to complete. If the iocb command is not
  6783. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6784. * Caller should not free the iocb resources if this function
  6785. * returns IOCB_TIMEDOUT.
  6786. * The function waits for the iocb completion using an
  6787. * non-interruptible wait.
  6788. * This function will sleep while waiting for iocb completion.
  6789. * So, this function should not be called from any context which
  6790. * does not allow sleeping. Due to the same reason, this function
  6791. * cannot be called with interrupt disabled.
  6792. * This function assumes that the iocb completions occur while
  6793. * this function sleep. So, this function cannot be called from
  6794. * the thread which process iocb completion for this ring.
  6795. * This function clears the iocb_flag of the iocb object before
  6796. * issuing the iocb and the iocb completion handler sets this
  6797. * flag and wakes this thread when the iocb completes.
  6798. * The contents of the response iocb will be copied to prspiocbq
  6799. * by the completion handler when the command completes.
  6800. * This function returns IOCB_SUCCESS when success.
  6801. * This function is called with no lock held.
  6802. **/
  6803. int
  6804. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6805. uint32_t ring_number,
  6806. struct lpfc_iocbq *piocb,
  6807. struct lpfc_iocbq *prspiocbq,
  6808. uint32_t timeout)
  6809. {
  6810. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6811. long timeleft, timeout_req = 0;
  6812. int retval = IOCB_SUCCESS;
  6813. uint32_t creg_val;
  6814. /*
  6815. * If the caller has provided a response iocbq buffer, then context2
  6816. * is NULL or its an error.
  6817. */
  6818. if (prspiocbq) {
  6819. if (piocb->context2)
  6820. return IOCB_ERROR;
  6821. piocb->context2 = prspiocbq;
  6822. }
  6823. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6824. piocb->context_un.wait_queue = &done_q;
  6825. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6826. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6827. creg_val = readl(phba->HCregaddr);
  6828. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6829. writel(creg_val, phba->HCregaddr);
  6830. readl(phba->HCregaddr); /* flush */
  6831. }
  6832. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6833. if (retval == IOCB_SUCCESS) {
  6834. timeout_req = timeout * HZ;
  6835. timeleft = wait_event_timeout(done_q,
  6836. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6837. timeout_req);
  6838. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6839. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6840. "0331 IOCB wake signaled\n");
  6841. } else if (timeleft == 0) {
  6842. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6843. "0338 IOCB wait timeout error - no "
  6844. "wake response Data x%x\n", timeout);
  6845. retval = IOCB_TIMEDOUT;
  6846. } else {
  6847. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6848. "0330 IOCB wake NOT set, "
  6849. "Data x%x x%lx\n",
  6850. timeout, (timeleft / jiffies));
  6851. retval = IOCB_TIMEDOUT;
  6852. }
  6853. } else {
  6854. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6855. "0332 IOCB wait issue failed, Data x%x\n",
  6856. retval);
  6857. retval = IOCB_ERROR;
  6858. }
  6859. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6860. creg_val = readl(phba->HCregaddr);
  6861. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6862. writel(creg_val, phba->HCregaddr);
  6863. readl(phba->HCregaddr); /* flush */
  6864. }
  6865. if (prspiocbq)
  6866. piocb->context2 = NULL;
  6867. piocb->context_un.wait_queue = NULL;
  6868. piocb->iocb_cmpl = NULL;
  6869. return retval;
  6870. }
  6871. /**
  6872. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6873. * @phba: Pointer to HBA context object.
  6874. * @pmboxq: Pointer to driver mailbox object.
  6875. * @timeout: Timeout in number of seconds.
  6876. *
  6877. * This function issues the mailbox to firmware and waits for the
  6878. * mailbox command to complete. If the mailbox command is not
  6879. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6880. * The function waits for the mailbox completion using an
  6881. * interruptible wait. If the thread is woken up due to a
  6882. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6883. * should not free the mailbox resources, if this function returns
  6884. * MBX_TIMEOUT.
  6885. * This function will sleep while waiting for mailbox completion.
  6886. * So, this function should not be called from any context which
  6887. * does not allow sleeping. Due to the same reason, this function
  6888. * cannot be called with interrupt disabled.
  6889. * This function assumes that the mailbox completion occurs while
  6890. * this function sleep. So, this function cannot be called from
  6891. * the worker thread which processes mailbox completion.
  6892. * This function is called in the context of HBA management
  6893. * applications.
  6894. * This function returns MBX_SUCCESS when successful.
  6895. * This function is called with no lock held.
  6896. **/
  6897. int
  6898. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6899. uint32_t timeout)
  6900. {
  6901. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6902. int retval;
  6903. unsigned long flag;
  6904. /* The caller must leave context1 empty. */
  6905. if (pmboxq->context1)
  6906. return MBX_NOT_FINISHED;
  6907. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6908. /* setup wake call as IOCB callback */
  6909. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6910. /* setup context field to pass wait_queue pointer to wake function */
  6911. pmboxq->context1 = &done_q;
  6912. /* now issue the command */
  6913. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6914. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6915. wait_event_interruptible_timeout(done_q,
  6916. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6917. timeout * HZ);
  6918. spin_lock_irqsave(&phba->hbalock, flag);
  6919. pmboxq->context1 = NULL;
  6920. /*
  6921. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6922. * else do not free the resources.
  6923. */
  6924. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6925. retval = MBX_SUCCESS;
  6926. else {
  6927. retval = MBX_TIMEOUT;
  6928. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6929. }
  6930. spin_unlock_irqrestore(&phba->hbalock, flag);
  6931. }
  6932. return retval;
  6933. }
  6934. /**
  6935. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6936. * @phba: Pointer to HBA context.
  6937. *
  6938. * This function is called to shutdown the driver's mailbox sub-system.
  6939. * It first marks the mailbox sub-system is in a block state to prevent
  6940. * the asynchronous mailbox command from issued off the pending mailbox
  6941. * command queue. If the mailbox command sub-system shutdown is due to
  6942. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6943. * the mailbox sub-system flush routine to forcefully bring down the
  6944. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6945. * as with offline or HBA function reset), this routine will wait for the
  6946. * outstanding mailbox command to complete before invoking the mailbox
  6947. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6948. **/
  6949. void
  6950. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6951. {
  6952. struct lpfc_sli *psli = &phba->sli;
  6953. uint8_t actcmd = MBX_HEARTBEAT;
  6954. unsigned long timeout;
  6955. spin_lock_irq(&phba->hbalock);
  6956. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6957. spin_unlock_irq(&phba->hbalock);
  6958. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6959. spin_lock_irq(&phba->hbalock);
  6960. if (phba->sli.mbox_active)
  6961. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  6962. spin_unlock_irq(&phba->hbalock);
  6963. /* Determine how long we might wait for the active mailbox
  6964. * command to be gracefully completed by firmware.
  6965. */
  6966. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  6967. 1000) + jiffies;
  6968. while (phba->sli.mbox_active) {
  6969. /* Check active mailbox complete status every 2ms */
  6970. msleep(2);
  6971. if (time_after(jiffies, timeout))
  6972. /* Timeout, let the mailbox flush routine to
  6973. * forcefully release active mailbox command
  6974. */
  6975. break;
  6976. }
  6977. }
  6978. lpfc_sli_mbox_sys_flush(phba);
  6979. }
  6980. /**
  6981. * lpfc_sli_eratt_read - read sli-3 error attention events
  6982. * @phba: Pointer to HBA context.
  6983. *
  6984. * This function is called to read the SLI3 device error attention registers
  6985. * for possible error attention events. The caller must hold the hostlock
  6986. * with spin_lock_irq().
  6987. *
  6988. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6989. * Register and returns 0 otherwise.
  6990. **/
  6991. static int
  6992. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  6993. {
  6994. uint32_t ha_copy;
  6995. /* Read chip Host Attention (HA) register */
  6996. ha_copy = readl(phba->HAregaddr);
  6997. if (ha_copy & HA_ERATT) {
  6998. /* Read host status register to retrieve error event */
  6999. lpfc_sli_read_hs(phba);
  7000. /* Check if there is a deferred error condition is active */
  7001. if ((HS_FFER1 & phba->work_hs) &&
  7002. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7003. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7004. phba->hba_flag |= DEFER_ERATT;
  7005. /* Clear all interrupt enable conditions */
  7006. writel(0, phba->HCregaddr);
  7007. readl(phba->HCregaddr);
  7008. }
  7009. /* Set the driver HA work bitmap */
  7010. phba->work_ha |= HA_ERATT;
  7011. /* Indicate polling handles this ERATT */
  7012. phba->hba_flag |= HBA_ERATT_HANDLED;
  7013. return 1;
  7014. }
  7015. return 0;
  7016. }
  7017. /**
  7018. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7019. * @phba: Pointer to HBA context.
  7020. *
  7021. * This function is called to read the SLI4 device error attention registers
  7022. * for possible error attention events. The caller must hold the hostlock
  7023. * with spin_lock_irq().
  7024. *
  7025. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7026. * Register and returns 0 otherwise.
  7027. **/
  7028. static int
  7029. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7030. {
  7031. uint32_t uerr_sta_hi, uerr_sta_lo;
  7032. /* For now, use the SLI4 device internal unrecoverable error
  7033. * registers for error attention. This can be changed later.
  7034. */
  7035. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7036. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7037. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7038. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7039. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7040. "1423 HBA Unrecoverable error: "
  7041. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7042. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7043. uerr_sta_lo, uerr_sta_hi,
  7044. phba->sli4_hba.ue_mask_lo,
  7045. phba->sli4_hba.ue_mask_hi);
  7046. phba->work_status[0] = uerr_sta_lo;
  7047. phba->work_status[1] = uerr_sta_hi;
  7048. /* Set the driver HA work bitmap */
  7049. phba->work_ha |= HA_ERATT;
  7050. /* Indicate polling handles this ERATT */
  7051. phba->hba_flag |= HBA_ERATT_HANDLED;
  7052. return 1;
  7053. }
  7054. return 0;
  7055. }
  7056. /**
  7057. * lpfc_sli_check_eratt - check error attention events
  7058. * @phba: Pointer to HBA context.
  7059. *
  7060. * This function is called from timer soft interrupt context to check HBA's
  7061. * error attention register bit for error attention events.
  7062. *
  7063. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7064. * Register and returns 0 otherwise.
  7065. **/
  7066. int
  7067. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7068. {
  7069. uint32_t ha_copy;
  7070. /* If somebody is waiting to handle an eratt, don't process it
  7071. * here. The brdkill function will do this.
  7072. */
  7073. if (phba->link_flag & LS_IGNORE_ERATT)
  7074. return 0;
  7075. /* Check if interrupt handler handles this ERATT */
  7076. spin_lock_irq(&phba->hbalock);
  7077. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7078. /* Interrupt handler has handled ERATT */
  7079. spin_unlock_irq(&phba->hbalock);
  7080. return 0;
  7081. }
  7082. /*
  7083. * If there is deferred error attention, do not check for error
  7084. * attention
  7085. */
  7086. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7087. spin_unlock_irq(&phba->hbalock);
  7088. return 0;
  7089. }
  7090. /* If PCI channel is offline, don't process it */
  7091. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7092. spin_unlock_irq(&phba->hbalock);
  7093. return 0;
  7094. }
  7095. switch (phba->sli_rev) {
  7096. case LPFC_SLI_REV2:
  7097. case LPFC_SLI_REV3:
  7098. /* Read chip Host Attention (HA) register */
  7099. ha_copy = lpfc_sli_eratt_read(phba);
  7100. break;
  7101. case LPFC_SLI_REV4:
  7102. /* Read devcie Uncoverable Error (UERR) registers */
  7103. ha_copy = lpfc_sli4_eratt_read(phba);
  7104. break;
  7105. default:
  7106. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7107. "0299 Invalid SLI revision (%d)\n",
  7108. phba->sli_rev);
  7109. ha_copy = 0;
  7110. break;
  7111. }
  7112. spin_unlock_irq(&phba->hbalock);
  7113. return ha_copy;
  7114. }
  7115. /**
  7116. * lpfc_intr_state_check - Check device state for interrupt handling
  7117. * @phba: Pointer to HBA context.
  7118. *
  7119. * This inline routine checks whether a device or its PCI slot is in a state
  7120. * that the interrupt should be handled.
  7121. *
  7122. * This function returns 0 if the device or the PCI slot is in a state that
  7123. * interrupt should be handled, otherwise -EIO.
  7124. */
  7125. static inline int
  7126. lpfc_intr_state_check(struct lpfc_hba *phba)
  7127. {
  7128. /* If the pci channel is offline, ignore all the interrupts */
  7129. if (unlikely(pci_channel_offline(phba->pcidev)))
  7130. return -EIO;
  7131. /* Update device level interrupt statistics */
  7132. phba->sli.slistat.sli_intr++;
  7133. /* Ignore all interrupts during initialization. */
  7134. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7135. return -EIO;
  7136. return 0;
  7137. }
  7138. /**
  7139. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7140. * @irq: Interrupt number.
  7141. * @dev_id: The device context pointer.
  7142. *
  7143. * This function is directly called from the PCI layer as an interrupt
  7144. * service routine when device with SLI-3 interface spec is enabled with
  7145. * MSI-X multi-message interrupt mode and there are slow-path events in
  7146. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7147. * interrupt mode, this function is called as part of the device-level
  7148. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7149. * is undergoing initialization, the interrupt handler will not process
  7150. * the interrupt. The link attention and ELS ring attention events are
  7151. * handled by the worker thread. The interrupt handler signals the worker
  7152. * thread and returns for these events. This function is called without
  7153. * any lock held. It gets the hbalock to access and update SLI data
  7154. * structures.
  7155. *
  7156. * This function returns IRQ_HANDLED when interrupt is handled else it
  7157. * returns IRQ_NONE.
  7158. **/
  7159. irqreturn_t
  7160. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7161. {
  7162. struct lpfc_hba *phba;
  7163. uint32_t ha_copy, hc_copy;
  7164. uint32_t work_ha_copy;
  7165. unsigned long status;
  7166. unsigned long iflag;
  7167. uint32_t control;
  7168. MAILBOX_t *mbox, *pmbox;
  7169. struct lpfc_vport *vport;
  7170. struct lpfc_nodelist *ndlp;
  7171. struct lpfc_dmabuf *mp;
  7172. LPFC_MBOXQ_t *pmb;
  7173. int rc;
  7174. /*
  7175. * Get the driver's phba structure from the dev_id and
  7176. * assume the HBA is not interrupting.
  7177. */
  7178. phba = (struct lpfc_hba *)dev_id;
  7179. if (unlikely(!phba))
  7180. return IRQ_NONE;
  7181. /*
  7182. * Stuff needs to be attented to when this function is invoked as an
  7183. * individual interrupt handler in MSI-X multi-message interrupt mode
  7184. */
  7185. if (phba->intr_type == MSIX) {
  7186. /* Check device state for handling interrupt */
  7187. if (lpfc_intr_state_check(phba))
  7188. return IRQ_NONE;
  7189. /* Need to read HA REG for slow-path events */
  7190. spin_lock_irqsave(&phba->hbalock, iflag);
  7191. ha_copy = readl(phba->HAregaddr);
  7192. /* If somebody is waiting to handle an eratt don't process it
  7193. * here. The brdkill function will do this.
  7194. */
  7195. if (phba->link_flag & LS_IGNORE_ERATT)
  7196. ha_copy &= ~HA_ERATT;
  7197. /* Check the need for handling ERATT in interrupt handler */
  7198. if (ha_copy & HA_ERATT) {
  7199. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7200. /* ERATT polling has handled ERATT */
  7201. ha_copy &= ~HA_ERATT;
  7202. else
  7203. /* Indicate interrupt handler handles ERATT */
  7204. phba->hba_flag |= HBA_ERATT_HANDLED;
  7205. }
  7206. /*
  7207. * If there is deferred error attention, do not check for any
  7208. * interrupt.
  7209. */
  7210. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7211. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7212. return IRQ_NONE;
  7213. }
  7214. /* Clear up only attention source related to slow-path */
  7215. hc_copy = readl(phba->HCregaddr);
  7216. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7217. HC_LAINT_ENA | HC_ERINT_ENA),
  7218. phba->HCregaddr);
  7219. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7220. phba->HAregaddr);
  7221. writel(hc_copy, phba->HCregaddr);
  7222. readl(phba->HAregaddr); /* flush */
  7223. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7224. } else
  7225. ha_copy = phba->ha_copy;
  7226. work_ha_copy = ha_copy & phba->work_ha_mask;
  7227. if (work_ha_copy) {
  7228. if (work_ha_copy & HA_LATT) {
  7229. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7230. /*
  7231. * Turn off Link Attention interrupts
  7232. * until CLEAR_LA done
  7233. */
  7234. spin_lock_irqsave(&phba->hbalock, iflag);
  7235. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7236. control = readl(phba->HCregaddr);
  7237. control &= ~HC_LAINT_ENA;
  7238. writel(control, phba->HCregaddr);
  7239. readl(phba->HCregaddr); /* flush */
  7240. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7241. }
  7242. else
  7243. work_ha_copy &= ~HA_LATT;
  7244. }
  7245. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7246. /*
  7247. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7248. * the only slow ring.
  7249. */
  7250. status = (work_ha_copy &
  7251. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7252. status >>= (4*LPFC_ELS_RING);
  7253. if (status & HA_RXMASK) {
  7254. spin_lock_irqsave(&phba->hbalock, iflag);
  7255. control = readl(phba->HCregaddr);
  7256. lpfc_debugfs_slow_ring_trc(phba,
  7257. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7258. control, status,
  7259. (uint32_t)phba->sli.slistat.sli_intr);
  7260. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7261. lpfc_debugfs_slow_ring_trc(phba,
  7262. "ISR Disable ring:"
  7263. "pwork:x%x hawork:x%x wait:x%x",
  7264. phba->work_ha, work_ha_copy,
  7265. (uint32_t)((unsigned long)
  7266. &phba->work_waitq));
  7267. control &=
  7268. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7269. writel(control, phba->HCregaddr);
  7270. readl(phba->HCregaddr); /* flush */
  7271. }
  7272. else {
  7273. lpfc_debugfs_slow_ring_trc(phba,
  7274. "ISR slow ring: pwork:"
  7275. "x%x hawork:x%x wait:x%x",
  7276. phba->work_ha, work_ha_copy,
  7277. (uint32_t)((unsigned long)
  7278. &phba->work_waitq));
  7279. }
  7280. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7281. }
  7282. }
  7283. spin_lock_irqsave(&phba->hbalock, iflag);
  7284. if (work_ha_copy & HA_ERATT) {
  7285. lpfc_sli_read_hs(phba);
  7286. /*
  7287. * Check if there is a deferred error condition
  7288. * is active
  7289. */
  7290. if ((HS_FFER1 & phba->work_hs) &&
  7291. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7292. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7293. phba->hba_flag |= DEFER_ERATT;
  7294. /* Clear all interrupt enable conditions */
  7295. writel(0, phba->HCregaddr);
  7296. readl(phba->HCregaddr);
  7297. }
  7298. }
  7299. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7300. pmb = phba->sli.mbox_active;
  7301. pmbox = &pmb->u.mb;
  7302. mbox = phba->mbox;
  7303. vport = pmb->vport;
  7304. /* First check out the status word */
  7305. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7306. if (pmbox->mbxOwner != OWN_HOST) {
  7307. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7308. /*
  7309. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7310. * mbxStatus <status>
  7311. */
  7312. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7313. LOG_SLI,
  7314. "(%d):0304 Stray Mailbox "
  7315. "Interrupt mbxCommand x%x "
  7316. "mbxStatus x%x\n",
  7317. (vport ? vport->vpi : 0),
  7318. pmbox->mbxCommand,
  7319. pmbox->mbxStatus);
  7320. /* clear mailbox attention bit */
  7321. work_ha_copy &= ~HA_MBATT;
  7322. } else {
  7323. phba->sli.mbox_active = NULL;
  7324. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7325. phba->last_completion_time = jiffies;
  7326. del_timer(&phba->sli.mbox_tmo);
  7327. if (pmb->mbox_cmpl) {
  7328. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7329. MAILBOX_CMD_SIZE);
  7330. }
  7331. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7332. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7333. lpfc_debugfs_disc_trc(vport,
  7334. LPFC_DISC_TRC_MBOX_VPORT,
  7335. "MBOX dflt rpi: : "
  7336. "status:x%x rpi:x%x",
  7337. (uint32_t)pmbox->mbxStatus,
  7338. pmbox->un.varWords[0], 0);
  7339. if (!pmbox->mbxStatus) {
  7340. mp = (struct lpfc_dmabuf *)
  7341. (pmb->context1);
  7342. ndlp = (struct lpfc_nodelist *)
  7343. pmb->context2;
  7344. /* Reg_LOGIN of dflt RPI was
  7345. * successful. new lets get
  7346. * rid of the RPI using the
  7347. * same mbox buffer.
  7348. */
  7349. lpfc_unreg_login(phba,
  7350. vport->vpi,
  7351. pmbox->un.varWords[0],
  7352. pmb);
  7353. pmb->mbox_cmpl =
  7354. lpfc_mbx_cmpl_dflt_rpi;
  7355. pmb->context1 = mp;
  7356. pmb->context2 = ndlp;
  7357. pmb->vport = vport;
  7358. rc = lpfc_sli_issue_mbox(phba,
  7359. pmb,
  7360. MBX_NOWAIT);
  7361. if (rc != MBX_BUSY)
  7362. lpfc_printf_log(phba,
  7363. KERN_ERR,
  7364. LOG_MBOX | LOG_SLI,
  7365. "0350 rc should have"
  7366. "been MBX_BUSY\n");
  7367. if (rc != MBX_NOT_FINISHED)
  7368. goto send_current_mbox;
  7369. }
  7370. }
  7371. spin_lock_irqsave(
  7372. &phba->pport->work_port_lock,
  7373. iflag);
  7374. phba->pport->work_port_events &=
  7375. ~WORKER_MBOX_TMO;
  7376. spin_unlock_irqrestore(
  7377. &phba->pport->work_port_lock,
  7378. iflag);
  7379. lpfc_mbox_cmpl_put(phba, pmb);
  7380. }
  7381. } else
  7382. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7383. if ((work_ha_copy & HA_MBATT) &&
  7384. (phba->sli.mbox_active == NULL)) {
  7385. send_current_mbox:
  7386. /* Process next mailbox command if there is one */
  7387. do {
  7388. rc = lpfc_sli_issue_mbox(phba, NULL,
  7389. MBX_NOWAIT);
  7390. } while (rc == MBX_NOT_FINISHED);
  7391. if (rc != MBX_SUCCESS)
  7392. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7393. LOG_SLI, "0349 rc should be "
  7394. "MBX_SUCCESS\n");
  7395. }
  7396. spin_lock_irqsave(&phba->hbalock, iflag);
  7397. phba->work_ha |= work_ha_copy;
  7398. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7399. lpfc_worker_wake_up(phba);
  7400. }
  7401. return IRQ_HANDLED;
  7402. } /* lpfc_sli_sp_intr_handler */
  7403. /**
  7404. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7405. * @irq: Interrupt number.
  7406. * @dev_id: The device context pointer.
  7407. *
  7408. * This function is directly called from the PCI layer as an interrupt
  7409. * service routine when device with SLI-3 interface spec is enabled with
  7410. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7411. * ring event in the HBA. However, when the device is enabled with either
  7412. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7413. * device-level interrupt handler. When the PCI slot is in error recovery
  7414. * or the HBA is undergoing initialization, the interrupt handler will not
  7415. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7416. * the intrrupt context. This function is called without any lock held.
  7417. * It gets the hbalock to access and update SLI data structures.
  7418. *
  7419. * This function returns IRQ_HANDLED when interrupt is handled else it
  7420. * returns IRQ_NONE.
  7421. **/
  7422. irqreturn_t
  7423. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7424. {
  7425. struct lpfc_hba *phba;
  7426. uint32_t ha_copy;
  7427. unsigned long status;
  7428. unsigned long iflag;
  7429. /* Get the driver's phba structure from the dev_id and
  7430. * assume the HBA is not interrupting.
  7431. */
  7432. phba = (struct lpfc_hba *) dev_id;
  7433. if (unlikely(!phba))
  7434. return IRQ_NONE;
  7435. /*
  7436. * Stuff needs to be attented to when this function is invoked as an
  7437. * individual interrupt handler in MSI-X multi-message interrupt mode
  7438. */
  7439. if (phba->intr_type == MSIX) {
  7440. /* Check device state for handling interrupt */
  7441. if (lpfc_intr_state_check(phba))
  7442. return IRQ_NONE;
  7443. /* Need to read HA REG for FCP ring and other ring events */
  7444. ha_copy = readl(phba->HAregaddr);
  7445. /* Clear up only attention source related to fast-path */
  7446. spin_lock_irqsave(&phba->hbalock, iflag);
  7447. /*
  7448. * If there is deferred error attention, do not check for
  7449. * any interrupt.
  7450. */
  7451. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7452. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7453. return IRQ_NONE;
  7454. }
  7455. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7456. phba->HAregaddr);
  7457. readl(phba->HAregaddr); /* flush */
  7458. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7459. } else
  7460. ha_copy = phba->ha_copy;
  7461. /*
  7462. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7463. */
  7464. ha_copy &= ~(phba->work_ha_mask);
  7465. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7466. status >>= (4*LPFC_FCP_RING);
  7467. if (status & HA_RXMASK)
  7468. lpfc_sli_handle_fast_ring_event(phba,
  7469. &phba->sli.ring[LPFC_FCP_RING],
  7470. status);
  7471. if (phba->cfg_multi_ring_support == 2) {
  7472. /*
  7473. * Process all events on extra ring. Take the optimized path
  7474. * for extra ring IO.
  7475. */
  7476. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7477. status >>= (4*LPFC_EXTRA_RING);
  7478. if (status & HA_RXMASK) {
  7479. lpfc_sli_handle_fast_ring_event(phba,
  7480. &phba->sli.ring[LPFC_EXTRA_RING],
  7481. status);
  7482. }
  7483. }
  7484. return IRQ_HANDLED;
  7485. } /* lpfc_sli_fp_intr_handler */
  7486. /**
  7487. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7488. * @irq: Interrupt number.
  7489. * @dev_id: The device context pointer.
  7490. *
  7491. * This function is the HBA device-level interrupt handler to device with
  7492. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7493. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7494. * requires driver attention. This function invokes the slow-path interrupt
  7495. * attention handling function and fast-path interrupt attention handling
  7496. * function in turn to process the relevant HBA attention events. This
  7497. * function is called without any lock held. It gets the hbalock to access
  7498. * and update SLI data structures.
  7499. *
  7500. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7501. * returns IRQ_NONE.
  7502. **/
  7503. irqreturn_t
  7504. lpfc_sli_intr_handler(int irq, void *dev_id)
  7505. {
  7506. struct lpfc_hba *phba;
  7507. irqreturn_t sp_irq_rc, fp_irq_rc;
  7508. unsigned long status1, status2;
  7509. uint32_t hc_copy;
  7510. /*
  7511. * Get the driver's phba structure from the dev_id and
  7512. * assume the HBA is not interrupting.
  7513. */
  7514. phba = (struct lpfc_hba *) dev_id;
  7515. if (unlikely(!phba))
  7516. return IRQ_NONE;
  7517. /* Check device state for handling interrupt */
  7518. if (lpfc_intr_state_check(phba))
  7519. return IRQ_NONE;
  7520. spin_lock(&phba->hbalock);
  7521. phba->ha_copy = readl(phba->HAregaddr);
  7522. if (unlikely(!phba->ha_copy)) {
  7523. spin_unlock(&phba->hbalock);
  7524. return IRQ_NONE;
  7525. } else if (phba->ha_copy & HA_ERATT) {
  7526. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7527. /* ERATT polling has handled ERATT */
  7528. phba->ha_copy &= ~HA_ERATT;
  7529. else
  7530. /* Indicate interrupt handler handles ERATT */
  7531. phba->hba_flag |= HBA_ERATT_HANDLED;
  7532. }
  7533. /*
  7534. * If there is deferred error attention, do not check for any interrupt.
  7535. */
  7536. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7537. spin_unlock_irq(&phba->hbalock);
  7538. return IRQ_NONE;
  7539. }
  7540. /* Clear attention sources except link and error attentions */
  7541. hc_copy = readl(phba->HCregaddr);
  7542. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7543. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7544. phba->HCregaddr);
  7545. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7546. writel(hc_copy, phba->HCregaddr);
  7547. readl(phba->HAregaddr); /* flush */
  7548. spin_unlock(&phba->hbalock);
  7549. /*
  7550. * Invokes slow-path host attention interrupt handling as appropriate.
  7551. */
  7552. /* status of events with mailbox and link attention */
  7553. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7554. /* status of events with ELS ring */
  7555. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7556. status2 >>= (4*LPFC_ELS_RING);
  7557. if (status1 || (status2 & HA_RXMASK))
  7558. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7559. else
  7560. sp_irq_rc = IRQ_NONE;
  7561. /*
  7562. * Invoke fast-path host attention interrupt handling as appropriate.
  7563. */
  7564. /* status of events with FCP ring */
  7565. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7566. status1 >>= (4*LPFC_FCP_RING);
  7567. /* status of events with extra ring */
  7568. if (phba->cfg_multi_ring_support == 2) {
  7569. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7570. status2 >>= (4*LPFC_EXTRA_RING);
  7571. } else
  7572. status2 = 0;
  7573. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7574. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7575. else
  7576. fp_irq_rc = IRQ_NONE;
  7577. /* Return device-level interrupt handling status */
  7578. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7579. } /* lpfc_sli_intr_handler */
  7580. /**
  7581. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7582. * @phba: pointer to lpfc hba data structure.
  7583. *
  7584. * This routine is invoked by the worker thread to process all the pending
  7585. * SLI4 FCP abort XRI events.
  7586. **/
  7587. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7588. {
  7589. struct lpfc_cq_event *cq_event;
  7590. /* First, declare the fcp xri abort event has been handled */
  7591. spin_lock_irq(&phba->hbalock);
  7592. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7593. spin_unlock_irq(&phba->hbalock);
  7594. /* Now, handle all the fcp xri abort events */
  7595. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7596. /* Get the first event from the head of the event queue */
  7597. spin_lock_irq(&phba->hbalock);
  7598. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7599. cq_event, struct lpfc_cq_event, list);
  7600. spin_unlock_irq(&phba->hbalock);
  7601. /* Notify aborted XRI for FCP work queue */
  7602. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7603. /* Free the event processed back to the free pool */
  7604. lpfc_sli4_cq_event_release(phba, cq_event);
  7605. }
  7606. }
  7607. /**
  7608. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7609. * @phba: pointer to lpfc hba data structure.
  7610. *
  7611. * This routine is invoked by the worker thread to process all the pending
  7612. * SLI4 els abort xri events.
  7613. **/
  7614. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7615. {
  7616. struct lpfc_cq_event *cq_event;
  7617. /* First, declare the els xri abort event has been handled */
  7618. spin_lock_irq(&phba->hbalock);
  7619. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7620. spin_unlock_irq(&phba->hbalock);
  7621. /* Now, handle all the els xri abort events */
  7622. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7623. /* Get the first event from the head of the event queue */
  7624. spin_lock_irq(&phba->hbalock);
  7625. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7626. cq_event, struct lpfc_cq_event, list);
  7627. spin_unlock_irq(&phba->hbalock);
  7628. /* Notify aborted XRI for ELS work queue */
  7629. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7630. /* Free the event processed back to the free pool */
  7631. lpfc_sli4_cq_event_release(phba, cq_event);
  7632. }
  7633. }
  7634. /**
  7635. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7636. * @phba: pointer to lpfc hba data structure
  7637. * @pIocbIn: pointer to the rspiocbq
  7638. * @pIocbOut: pointer to the cmdiocbq
  7639. * @wcqe: pointer to the complete wcqe
  7640. *
  7641. * This routine transfers the fields of a command iocbq to a response iocbq
  7642. * by copying all the IOCB fields from command iocbq and transferring the
  7643. * completion status information from the complete wcqe.
  7644. **/
  7645. static void
  7646. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7647. struct lpfc_iocbq *pIocbIn,
  7648. struct lpfc_iocbq *pIocbOut,
  7649. struct lpfc_wcqe_complete *wcqe)
  7650. {
  7651. unsigned long iflags;
  7652. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7653. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7654. sizeof(struct lpfc_iocbq) - offset);
  7655. /* Map WCQE parameters into irspiocb parameters */
  7656. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7657. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7658. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7659. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7660. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7661. wcqe->total_data_placed;
  7662. else
  7663. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7664. else {
  7665. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7666. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7667. }
  7668. /* Pick up HBA exchange busy condition */
  7669. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7670. spin_lock_irqsave(&phba->hbalock, iflags);
  7671. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7672. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7673. }
  7674. }
  7675. /**
  7676. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7677. * @phba: Pointer to HBA context object.
  7678. * @wcqe: Pointer to work-queue completion queue entry.
  7679. *
  7680. * This routine handles an ELS work-queue completion event and construct
  7681. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7682. * discovery engine to handle.
  7683. *
  7684. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7685. **/
  7686. static struct lpfc_iocbq *
  7687. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7688. struct lpfc_iocbq *irspiocbq)
  7689. {
  7690. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7691. struct lpfc_iocbq *cmdiocbq;
  7692. struct lpfc_wcqe_complete *wcqe;
  7693. unsigned long iflags;
  7694. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7695. spin_lock_irqsave(&phba->hbalock, iflags);
  7696. pring->stats.iocb_event++;
  7697. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7698. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7699. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7700. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7701. if (unlikely(!cmdiocbq)) {
  7702. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7703. "0386 ELS complete with no corresponding "
  7704. "cmdiocb: iotag (%d)\n",
  7705. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7706. lpfc_sli_release_iocbq(phba, irspiocbq);
  7707. return NULL;
  7708. }
  7709. /* Fake the irspiocbq and copy necessary response information */
  7710. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  7711. return irspiocbq;
  7712. }
  7713. /**
  7714. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7715. * @phba: Pointer to HBA context object.
  7716. * @cqe: Pointer to mailbox completion queue entry.
  7717. *
  7718. * This routine process a mailbox completion queue entry with asynchrous
  7719. * event.
  7720. *
  7721. * Return: true if work posted to worker thread, otherwise false.
  7722. **/
  7723. static bool
  7724. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7725. {
  7726. struct lpfc_cq_event *cq_event;
  7727. unsigned long iflags;
  7728. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7729. "0392 Async Event: word0:x%x, word1:x%x, "
  7730. "word2:x%x, word3:x%x\n", mcqe->word0,
  7731. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7732. /* Allocate a new internal CQ_EVENT entry */
  7733. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7734. if (!cq_event) {
  7735. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7736. "0394 Failed to allocate CQ_EVENT entry\n");
  7737. return false;
  7738. }
  7739. /* Move the CQE into an asynchronous event entry */
  7740. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7741. spin_lock_irqsave(&phba->hbalock, iflags);
  7742. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7743. /* Set the async event flag */
  7744. phba->hba_flag |= ASYNC_EVENT;
  7745. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7746. return true;
  7747. }
  7748. /**
  7749. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7750. * @phba: Pointer to HBA context object.
  7751. * @cqe: Pointer to mailbox completion queue entry.
  7752. *
  7753. * This routine process a mailbox completion queue entry with mailbox
  7754. * completion event.
  7755. *
  7756. * Return: true if work posted to worker thread, otherwise false.
  7757. **/
  7758. static bool
  7759. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7760. {
  7761. uint32_t mcqe_status;
  7762. MAILBOX_t *mbox, *pmbox;
  7763. struct lpfc_mqe *mqe;
  7764. struct lpfc_vport *vport;
  7765. struct lpfc_nodelist *ndlp;
  7766. struct lpfc_dmabuf *mp;
  7767. unsigned long iflags;
  7768. LPFC_MBOXQ_t *pmb;
  7769. bool workposted = false;
  7770. int rc;
  7771. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7772. if (!bf_get(lpfc_trailer_completed, mcqe))
  7773. goto out_no_mqe_complete;
  7774. /* Get the reference to the active mbox command */
  7775. spin_lock_irqsave(&phba->hbalock, iflags);
  7776. pmb = phba->sli.mbox_active;
  7777. if (unlikely(!pmb)) {
  7778. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7779. "1832 No pending MBOX command to handle\n");
  7780. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7781. goto out_no_mqe_complete;
  7782. }
  7783. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7784. mqe = &pmb->u.mqe;
  7785. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7786. mbox = phba->mbox;
  7787. vport = pmb->vport;
  7788. /* Reset heartbeat timer */
  7789. phba->last_completion_time = jiffies;
  7790. del_timer(&phba->sli.mbox_tmo);
  7791. /* Move mbox data to caller's mailbox region, do endian swapping */
  7792. if (pmb->mbox_cmpl && mbox)
  7793. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7794. /* Set the mailbox status with SLI4 range 0x4000 */
  7795. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7796. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7797. bf_set(lpfc_mqe_status, mqe,
  7798. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7799. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7800. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7801. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7802. "MBOX dflt rpi: status:x%x rpi:x%x",
  7803. mcqe_status,
  7804. pmbox->un.varWords[0], 0);
  7805. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7806. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7807. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7808. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7809. * RID of the PPI using the same mbox buffer.
  7810. */
  7811. lpfc_unreg_login(phba, vport->vpi,
  7812. pmbox->un.varWords[0], pmb);
  7813. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7814. pmb->context1 = mp;
  7815. pmb->context2 = ndlp;
  7816. pmb->vport = vport;
  7817. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7818. if (rc != MBX_BUSY)
  7819. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7820. LOG_SLI, "0385 rc should "
  7821. "have been MBX_BUSY\n");
  7822. if (rc != MBX_NOT_FINISHED)
  7823. goto send_current_mbox;
  7824. }
  7825. }
  7826. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7827. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7828. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7829. /* There is mailbox completion work to do */
  7830. spin_lock_irqsave(&phba->hbalock, iflags);
  7831. __lpfc_mbox_cmpl_put(phba, pmb);
  7832. phba->work_ha |= HA_MBATT;
  7833. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7834. workposted = true;
  7835. send_current_mbox:
  7836. spin_lock_irqsave(&phba->hbalock, iflags);
  7837. /* Release the mailbox command posting token */
  7838. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7839. /* Setting active mailbox pointer need to be in sync to flag clear */
  7840. phba->sli.mbox_active = NULL;
  7841. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7842. /* Wake up worker thread to post the next pending mailbox command */
  7843. lpfc_worker_wake_up(phba);
  7844. out_no_mqe_complete:
  7845. if (bf_get(lpfc_trailer_consumed, mcqe))
  7846. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7847. return workposted;
  7848. }
  7849. /**
  7850. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7851. * @phba: Pointer to HBA context object.
  7852. * @cqe: Pointer to mailbox completion queue entry.
  7853. *
  7854. * This routine process a mailbox completion queue entry, it invokes the
  7855. * proper mailbox complete handling or asynchrous event handling routine
  7856. * according to the MCQE's async bit.
  7857. *
  7858. * Return: true if work posted to worker thread, otherwise false.
  7859. **/
  7860. static bool
  7861. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7862. {
  7863. struct lpfc_mcqe mcqe;
  7864. bool workposted;
  7865. /* Copy the mailbox MCQE and convert endian order as needed */
  7866. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7867. /* Invoke the proper event handling routine */
  7868. if (!bf_get(lpfc_trailer_async, &mcqe))
  7869. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7870. else
  7871. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7872. return workposted;
  7873. }
  7874. /**
  7875. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7876. * @phba: Pointer to HBA context object.
  7877. * @wcqe: Pointer to work-queue completion queue entry.
  7878. *
  7879. * This routine handles an ELS work-queue completion event.
  7880. *
  7881. * Return: true if work posted to worker thread, otherwise false.
  7882. **/
  7883. static bool
  7884. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7885. struct lpfc_wcqe_complete *wcqe)
  7886. {
  7887. struct lpfc_iocbq *irspiocbq;
  7888. unsigned long iflags;
  7889. /* Get an irspiocbq for later ELS response processing use */
  7890. irspiocbq = lpfc_sli_get_iocbq(phba);
  7891. if (!irspiocbq) {
  7892. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7893. "0387 Failed to allocate an iocbq\n");
  7894. return false;
  7895. }
  7896. /* Save off the slow-path queue event for work thread to process */
  7897. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  7898. spin_lock_irqsave(&phba->hbalock, iflags);
  7899. list_add_tail(&irspiocbq->cq_event.list,
  7900. &phba->sli4_hba.sp_queue_event);
  7901. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7902. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7903. return true;
  7904. }
  7905. /**
  7906. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7907. * @phba: Pointer to HBA context object.
  7908. * @wcqe: Pointer to work-queue completion queue entry.
  7909. *
  7910. * This routine handles slow-path WQ entry comsumed event by invoking the
  7911. * proper WQ release routine to the slow-path WQ.
  7912. **/
  7913. static void
  7914. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7915. struct lpfc_wcqe_release *wcqe)
  7916. {
  7917. /* Check for the slow-path ELS work queue */
  7918. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7919. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7920. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7921. else
  7922. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7923. "2579 Slow-path wqe consume event carries "
  7924. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7925. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7926. phba->sli4_hba.els_wq->queue_id);
  7927. }
  7928. /**
  7929. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7930. * @phba: Pointer to HBA context object.
  7931. * @cq: Pointer to a WQ completion queue.
  7932. * @wcqe: Pointer to work-queue completion queue entry.
  7933. *
  7934. * This routine handles an XRI abort event.
  7935. *
  7936. * Return: true if work posted to worker thread, otherwise false.
  7937. **/
  7938. static bool
  7939. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7940. struct lpfc_queue *cq,
  7941. struct sli4_wcqe_xri_aborted *wcqe)
  7942. {
  7943. bool workposted = false;
  7944. struct lpfc_cq_event *cq_event;
  7945. unsigned long iflags;
  7946. /* Allocate a new internal CQ_EVENT entry */
  7947. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7948. if (!cq_event) {
  7949. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7950. "0602 Failed to allocate CQ_EVENT entry\n");
  7951. return false;
  7952. }
  7953. /* Move the CQE into the proper xri abort event list */
  7954. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  7955. switch (cq->subtype) {
  7956. case LPFC_FCP:
  7957. spin_lock_irqsave(&phba->hbalock, iflags);
  7958. list_add_tail(&cq_event->list,
  7959. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  7960. /* Set the fcp xri abort event flag */
  7961. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  7962. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7963. workposted = true;
  7964. break;
  7965. case LPFC_ELS:
  7966. spin_lock_irqsave(&phba->hbalock, iflags);
  7967. list_add_tail(&cq_event->list,
  7968. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  7969. /* Set the els xri abort event flag */
  7970. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  7971. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7972. workposted = true;
  7973. break;
  7974. default:
  7975. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7976. "0603 Invalid work queue CQE subtype (x%x)\n",
  7977. cq->subtype);
  7978. workposted = false;
  7979. break;
  7980. }
  7981. return workposted;
  7982. }
  7983. /**
  7984. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  7985. * @phba: Pointer to HBA context object.
  7986. * @rcqe: Pointer to receive-queue completion queue entry.
  7987. *
  7988. * This routine process a receive-queue completion queue entry.
  7989. *
  7990. * Return: true if work posted to worker thread, otherwise false.
  7991. **/
  7992. static bool
  7993. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  7994. {
  7995. bool workposted = false;
  7996. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  7997. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  7998. struct hbq_dmabuf *dma_buf;
  7999. uint32_t status;
  8000. unsigned long iflags;
  8001. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8002. goto out;
  8003. status = bf_get(lpfc_rcqe_status, rcqe);
  8004. switch (status) {
  8005. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8006. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8007. "2537 Receive Frame Truncated!!\n");
  8008. case FC_STATUS_RQ_SUCCESS:
  8009. lpfc_sli4_rq_release(hrq, drq);
  8010. spin_lock_irqsave(&phba->hbalock, iflags);
  8011. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8012. if (!dma_buf) {
  8013. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8014. goto out;
  8015. }
  8016. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8017. /* save off the frame for the word thread to process */
  8018. list_add_tail(&dma_buf->cq_event.list,
  8019. &phba->sli4_hba.sp_queue_event);
  8020. /* Frame received */
  8021. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8022. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8023. workposted = true;
  8024. break;
  8025. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8026. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8027. /* Post more buffers if possible */
  8028. spin_lock_irqsave(&phba->hbalock, iflags);
  8029. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8030. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8031. workposted = true;
  8032. break;
  8033. }
  8034. out:
  8035. return workposted;
  8036. }
  8037. /**
  8038. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8039. * @phba: Pointer to HBA context object.
  8040. * @cq: Pointer to the completion queue.
  8041. * @wcqe: Pointer to a completion queue entry.
  8042. *
  8043. * This routine process a slow-path work-queue or recieve queue completion queue
  8044. * entry.
  8045. *
  8046. * Return: true if work posted to worker thread, otherwise false.
  8047. **/
  8048. static bool
  8049. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8050. struct lpfc_cqe *cqe)
  8051. {
  8052. struct lpfc_cqe cqevt;
  8053. bool workposted = false;
  8054. /* Copy the work queue CQE and convert endian order if needed */
  8055. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8056. /* Check and process for different type of WCQE and dispatch */
  8057. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8058. case CQE_CODE_COMPL_WQE:
  8059. /* Process the WQ/RQ complete event */
  8060. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8061. (struct lpfc_wcqe_complete *)&cqevt);
  8062. break;
  8063. case CQE_CODE_RELEASE_WQE:
  8064. /* Process the WQ release event */
  8065. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8066. (struct lpfc_wcqe_release *)&cqevt);
  8067. break;
  8068. case CQE_CODE_XRI_ABORTED:
  8069. /* Process the WQ XRI abort event */
  8070. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8071. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8072. break;
  8073. case CQE_CODE_RECEIVE:
  8074. /* Process the RQ event */
  8075. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8076. (struct lpfc_rcqe *)&cqevt);
  8077. break;
  8078. default:
  8079. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8080. "0388 Not a valid WCQE code: x%x\n",
  8081. bf_get(lpfc_cqe_code, &cqevt));
  8082. break;
  8083. }
  8084. return workposted;
  8085. }
  8086. /**
  8087. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8088. * @phba: Pointer to HBA context object.
  8089. * @eqe: Pointer to fast-path event queue entry.
  8090. *
  8091. * This routine process a event queue entry from the slow-path event queue.
  8092. * It will check the MajorCode and MinorCode to determine this is for a
  8093. * completion event on a completion queue, if not, an error shall be logged
  8094. * and just return. Otherwise, it will get to the corresponding completion
  8095. * queue and process all the entries on that completion queue, rearm the
  8096. * completion queue, and then return.
  8097. *
  8098. **/
  8099. static void
  8100. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8101. {
  8102. struct lpfc_queue *cq = NULL, *childq, *speq;
  8103. struct lpfc_cqe *cqe;
  8104. bool workposted = false;
  8105. int ecount = 0;
  8106. uint16_t cqid;
  8107. if (bf_get(lpfc_eqe_major_code, eqe) != 0) {
  8108. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8109. "0359 Not a valid slow-path completion "
  8110. "event: majorcode=x%x, minorcode=x%x\n",
  8111. bf_get(lpfc_eqe_major_code, eqe),
  8112. bf_get(lpfc_eqe_minor_code, eqe));
  8113. return;
  8114. }
  8115. /* Get the reference to the corresponding CQ */
  8116. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8117. /* Search for completion queue pointer matching this cqid */
  8118. speq = phba->sli4_hba.sp_eq;
  8119. list_for_each_entry(childq, &speq->child_list, list) {
  8120. if (childq->queue_id == cqid) {
  8121. cq = childq;
  8122. break;
  8123. }
  8124. }
  8125. if (unlikely(!cq)) {
  8126. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8127. "0365 Slow-path CQ identifier (%d) does "
  8128. "not exist\n", cqid);
  8129. return;
  8130. }
  8131. /* Process all the entries to the CQ */
  8132. switch (cq->type) {
  8133. case LPFC_MCQ:
  8134. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8135. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8136. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8137. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8138. }
  8139. break;
  8140. case LPFC_WCQ:
  8141. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8142. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8143. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8144. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8145. }
  8146. break;
  8147. default:
  8148. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8149. "0370 Invalid completion queue type (%d)\n",
  8150. cq->type);
  8151. return;
  8152. }
  8153. /* Catch the no cq entry condition, log an error */
  8154. if (unlikely(ecount == 0))
  8155. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8156. "0371 No entry from the CQ: identifier "
  8157. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8158. /* In any case, flash and re-arm the RCQ */
  8159. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8160. /* wake up worker thread if there are works to be done */
  8161. if (workposted)
  8162. lpfc_worker_wake_up(phba);
  8163. }
  8164. /**
  8165. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8166. * @eqe: Pointer to fast-path completion queue entry.
  8167. *
  8168. * This routine process a fast-path work queue completion entry from fast-path
  8169. * event queue for FCP command response completion.
  8170. **/
  8171. static void
  8172. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8173. struct lpfc_wcqe_complete *wcqe)
  8174. {
  8175. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8176. struct lpfc_iocbq *cmdiocbq;
  8177. struct lpfc_iocbq irspiocbq;
  8178. unsigned long iflags;
  8179. spin_lock_irqsave(&phba->hbalock, iflags);
  8180. pring->stats.iocb_event++;
  8181. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8182. /* Check for response status */
  8183. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8184. /* If resource errors reported from HBA, reduce queue
  8185. * depth of the SCSI device.
  8186. */
  8187. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8188. IOSTAT_LOCAL_REJECT) &&
  8189. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8190. phba->lpfc_rampdown_queue_depth(phba);
  8191. }
  8192. /* Log the error status */
  8193. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8194. "0373 FCP complete error: status=x%x, "
  8195. "hw_status=x%x, total_data_specified=%d, "
  8196. "parameter=x%x, word3=x%x\n",
  8197. bf_get(lpfc_wcqe_c_status, wcqe),
  8198. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8199. wcqe->total_data_placed, wcqe->parameter,
  8200. wcqe->word3);
  8201. }
  8202. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8203. spin_lock_irqsave(&phba->hbalock, iflags);
  8204. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8205. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8206. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8207. if (unlikely(!cmdiocbq)) {
  8208. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8209. "0374 FCP complete with no corresponding "
  8210. "cmdiocb: iotag (%d)\n",
  8211. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8212. return;
  8213. }
  8214. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8215. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8216. "0375 FCP cmdiocb not callback function "
  8217. "iotag: (%d)\n",
  8218. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8219. return;
  8220. }
  8221. /* Fake the irspiocb and copy necessary response information */
  8222. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8223. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8224. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8225. }
  8226. /**
  8227. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8228. * @phba: Pointer to HBA context object.
  8229. * @cq: Pointer to completion queue.
  8230. * @wcqe: Pointer to work-queue completion queue entry.
  8231. *
  8232. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8233. * proper WQ release routine to the slow-path WQ.
  8234. **/
  8235. static void
  8236. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8237. struct lpfc_wcqe_release *wcqe)
  8238. {
  8239. struct lpfc_queue *childwq;
  8240. bool wqid_matched = false;
  8241. uint16_t fcp_wqid;
  8242. /* Check for fast-path FCP work queue release */
  8243. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8244. list_for_each_entry(childwq, &cq->child_list, list) {
  8245. if (childwq->queue_id == fcp_wqid) {
  8246. lpfc_sli4_wq_release(childwq,
  8247. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8248. wqid_matched = true;
  8249. break;
  8250. }
  8251. }
  8252. /* Report warning log message if no match found */
  8253. if (wqid_matched != true)
  8254. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8255. "2580 Fast-path wqe consume event carries "
  8256. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8257. }
  8258. /**
  8259. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8260. * @cq: Pointer to the completion queue.
  8261. * @eqe: Pointer to fast-path completion queue entry.
  8262. *
  8263. * This routine process a fast-path work queue completion entry from fast-path
  8264. * event queue for FCP command response completion.
  8265. **/
  8266. static int
  8267. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8268. struct lpfc_cqe *cqe)
  8269. {
  8270. struct lpfc_wcqe_release wcqe;
  8271. bool workposted = false;
  8272. /* Copy the work queue CQE and convert endian order if needed */
  8273. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8274. /* Check and process for different type of WCQE and dispatch */
  8275. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8276. case CQE_CODE_COMPL_WQE:
  8277. /* Process the WQ complete event */
  8278. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8279. (struct lpfc_wcqe_complete *)&wcqe);
  8280. break;
  8281. case CQE_CODE_RELEASE_WQE:
  8282. /* Process the WQ release event */
  8283. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8284. (struct lpfc_wcqe_release *)&wcqe);
  8285. break;
  8286. case CQE_CODE_XRI_ABORTED:
  8287. /* Process the WQ XRI abort event */
  8288. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8289. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8290. break;
  8291. default:
  8292. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8293. "0144 Not a valid WCQE code: x%x\n",
  8294. bf_get(lpfc_wcqe_c_code, &wcqe));
  8295. break;
  8296. }
  8297. return workposted;
  8298. }
  8299. /**
  8300. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8301. * @phba: Pointer to HBA context object.
  8302. * @eqe: Pointer to fast-path event queue entry.
  8303. *
  8304. * This routine process a event queue entry from the fast-path event queue.
  8305. * It will check the MajorCode and MinorCode to determine this is for a
  8306. * completion event on a completion queue, if not, an error shall be logged
  8307. * and just return. Otherwise, it will get to the corresponding completion
  8308. * queue and process all the entries on the completion queue, rearm the
  8309. * completion queue, and then return.
  8310. **/
  8311. static void
  8312. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8313. uint32_t fcp_cqidx)
  8314. {
  8315. struct lpfc_queue *cq;
  8316. struct lpfc_cqe *cqe;
  8317. bool workposted = false;
  8318. uint16_t cqid;
  8319. int ecount = 0;
  8320. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0)) {
  8321. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8322. "0366 Not a valid fast-path completion "
  8323. "event: majorcode=x%x, minorcode=x%x\n",
  8324. bf_get(lpfc_eqe_major_code, eqe),
  8325. bf_get(lpfc_eqe_minor_code, eqe));
  8326. return;
  8327. }
  8328. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8329. if (unlikely(!cq)) {
  8330. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8331. "0367 Fast-path completion queue does not "
  8332. "exist\n");
  8333. return;
  8334. }
  8335. /* Get the reference to the corresponding CQ */
  8336. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8337. if (unlikely(cqid != cq->queue_id)) {
  8338. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8339. "0368 Miss-matched fast-path completion "
  8340. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8341. cqid, cq->queue_id);
  8342. return;
  8343. }
  8344. /* Process all the entries to the CQ */
  8345. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8346. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8347. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8348. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8349. }
  8350. /* Catch the no cq entry condition */
  8351. if (unlikely(ecount == 0))
  8352. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8353. "0369 No entry from fast-path completion "
  8354. "queue fcpcqid=%d\n", cq->queue_id);
  8355. /* In any case, flash and re-arm the CQ */
  8356. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8357. /* wake up worker thread if there are works to be done */
  8358. if (workposted)
  8359. lpfc_worker_wake_up(phba);
  8360. }
  8361. static void
  8362. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8363. {
  8364. struct lpfc_eqe *eqe;
  8365. /* walk all the EQ entries and drop on the floor */
  8366. while ((eqe = lpfc_sli4_eq_get(eq)))
  8367. ;
  8368. /* Clear and re-arm the EQ */
  8369. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8370. }
  8371. /**
  8372. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8373. * @irq: Interrupt number.
  8374. * @dev_id: The device context pointer.
  8375. *
  8376. * This function is directly called from the PCI layer as an interrupt
  8377. * service routine when device with SLI-4 interface spec is enabled with
  8378. * MSI-X multi-message interrupt mode and there are slow-path events in
  8379. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8380. * interrupt mode, this function is called as part of the device-level
  8381. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8382. * undergoing initialization, the interrupt handler will not process the
  8383. * interrupt. The link attention and ELS ring attention events are handled
  8384. * by the worker thread. The interrupt handler signals the worker thread
  8385. * and returns for these events. This function is called without any lock
  8386. * held. It gets the hbalock to access and update SLI data structures.
  8387. *
  8388. * This function returns IRQ_HANDLED when interrupt is handled else it
  8389. * returns IRQ_NONE.
  8390. **/
  8391. irqreturn_t
  8392. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8393. {
  8394. struct lpfc_hba *phba;
  8395. struct lpfc_queue *speq;
  8396. struct lpfc_eqe *eqe;
  8397. unsigned long iflag;
  8398. int ecount = 0;
  8399. /*
  8400. * Get the driver's phba structure from the dev_id
  8401. */
  8402. phba = (struct lpfc_hba *)dev_id;
  8403. if (unlikely(!phba))
  8404. return IRQ_NONE;
  8405. /* Get to the EQ struct associated with this vector */
  8406. speq = phba->sli4_hba.sp_eq;
  8407. /* Check device state for handling interrupt */
  8408. if (unlikely(lpfc_intr_state_check(phba))) {
  8409. /* Check again for link_state with lock held */
  8410. spin_lock_irqsave(&phba->hbalock, iflag);
  8411. if (phba->link_state < LPFC_LINK_DOWN)
  8412. /* Flush, clear interrupt, and rearm the EQ */
  8413. lpfc_sli4_eq_flush(phba, speq);
  8414. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8415. return IRQ_NONE;
  8416. }
  8417. /*
  8418. * Process all the event on FCP slow-path EQ
  8419. */
  8420. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8421. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8422. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8423. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8424. }
  8425. /* Always clear and re-arm the slow-path EQ */
  8426. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8427. /* Catch the no cq entry condition */
  8428. if (unlikely(ecount == 0)) {
  8429. if (phba->intr_type == MSIX)
  8430. /* MSI-X treated interrupt served as no EQ share INT */
  8431. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8432. "0357 MSI-X interrupt with no EQE\n");
  8433. else
  8434. /* Non MSI-X treated on interrupt as EQ share INT */
  8435. return IRQ_NONE;
  8436. }
  8437. return IRQ_HANDLED;
  8438. } /* lpfc_sli4_sp_intr_handler */
  8439. /**
  8440. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8441. * @irq: Interrupt number.
  8442. * @dev_id: The device context pointer.
  8443. *
  8444. * This function is directly called from the PCI layer as an interrupt
  8445. * service routine when device with SLI-4 interface spec is enabled with
  8446. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8447. * ring event in the HBA. However, when the device is enabled with either
  8448. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8449. * device-level interrupt handler. When the PCI slot is in error recovery
  8450. * or the HBA is undergoing initialization, the interrupt handler will not
  8451. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8452. * the intrrupt context. This function is called without any lock held.
  8453. * It gets the hbalock to access and update SLI data structures. Note that,
  8454. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8455. * equal to that of FCP CQ index.
  8456. *
  8457. * This function returns IRQ_HANDLED when interrupt is handled else it
  8458. * returns IRQ_NONE.
  8459. **/
  8460. irqreturn_t
  8461. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8462. {
  8463. struct lpfc_hba *phba;
  8464. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8465. struct lpfc_queue *fpeq;
  8466. struct lpfc_eqe *eqe;
  8467. unsigned long iflag;
  8468. int ecount = 0;
  8469. uint32_t fcp_eqidx;
  8470. /* Get the driver's phba structure from the dev_id */
  8471. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8472. phba = fcp_eq_hdl->phba;
  8473. fcp_eqidx = fcp_eq_hdl->idx;
  8474. if (unlikely(!phba))
  8475. return IRQ_NONE;
  8476. /* Get to the EQ struct associated with this vector */
  8477. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8478. /* Check device state for handling interrupt */
  8479. if (unlikely(lpfc_intr_state_check(phba))) {
  8480. /* Check again for link_state with lock held */
  8481. spin_lock_irqsave(&phba->hbalock, iflag);
  8482. if (phba->link_state < LPFC_LINK_DOWN)
  8483. /* Flush, clear interrupt, and rearm the EQ */
  8484. lpfc_sli4_eq_flush(phba, fpeq);
  8485. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8486. return IRQ_NONE;
  8487. }
  8488. /*
  8489. * Process all the event on FCP fast-path EQ
  8490. */
  8491. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8492. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8493. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8494. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8495. }
  8496. /* Always clear and re-arm the fast-path EQ */
  8497. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8498. if (unlikely(ecount == 0)) {
  8499. if (phba->intr_type == MSIX)
  8500. /* MSI-X treated interrupt served as no EQ share INT */
  8501. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8502. "0358 MSI-X interrupt with no EQE\n");
  8503. else
  8504. /* Non MSI-X treated on interrupt as EQ share INT */
  8505. return IRQ_NONE;
  8506. }
  8507. return IRQ_HANDLED;
  8508. } /* lpfc_sli4_fp_intr_handler */
  8509. /**
  8510. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8511. * @irq: Interrupt number.
  8512. * @dev_id: The device context pointer.
  8513. *
  8514. * This function is the device-level interrupt handler to device with SLI-4
  8515. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8516. * interrupt mode is enabled and there is an event in the HBA which requires
  8517. * driver attention. This function invokes the slow-path interrupt attention
  8518. * handling function and fast-path interrupt attention handling function in
  8519. * turn to process the relevant HBA attention events. This function is called
  8520. * without any lock held. It gets the hbalock to access and update SLI data
  8521. * structures.
  8522. *
  8523. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8524. * returns IRQ_NONE.
  8525. **/
  8526. irqreturn_t
  8527. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8528. {
  8529. struct lpfc_hba *phba;
  8530. irqreturn_t sp_irq_rc, fp_irq_rc;
  8531. bool fp_handled = false;
  8532. uint32_t fcp_eqidx;
  8533. /* Get the driver's phba structure from the dev_id */
  8534. phba = (struct lpfc_hba *)dev_id;
  8535. if (unlikely(!phba))
  8536. return IRQ_NONE;
  8537. /*
  8538. * Invokes slow-path host attention interrupt handling as appropriate.
  8539. */
  8540. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8541. /*
  8542. * Invoke fast-path host attention interrupt handling as appropriate.
  8543. */
  8544. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8545. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8546. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8547. if (fp_irq_rc == IRQ_HANDLED)
  8548. fp_handled |= true;
  8549. }
  8550. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8551. } /* lpfc_sli4_intr_handler */
  8552. /**
  8553. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8554. * @queue: The queue structure to free.
  8555. *
  8556. * This function frees a queue structure and the DMAable memeory used for
  8557. * the host resident queue. This function must be called after destroying the
  8558. * queue on the HBA.
  8559. **/
  8560. void
  8561. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8562. {
  8563. struct lpfc_dmabuf *dmabuf;
  8564. if (!queue)
  8565. return;
  8566. while (!list_empty(&queue->page_list)) {
  8567. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8568. list);
  8569. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8570. dmabuf->virt, dmabuf->phys);
  8571. kfree(dmabuf);
  8572. }
  8573. kfree(queue);
  8574. return;
  8575. }
  8576. /**
  8577. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8578. * @phba: The HBA that this queue is being created on.
  8579. * @entry_size: The size of each queue entry for this queue.
  8580. * @entry count: The number of entries that this queue will handle.
  8581. *
  8582. * This function allocates a queue structure and the DMAable memory used for
  8583. * the host resident queue. This function must be called before creating the
  8584. * queue on the HBA.
  8585. **/
  8586. struct lpfc_queue *
  8587. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8588. uint32_t entry_count)
  8589. {
  8590. struct lpfc_queue *queue;
  8591. struct lpfc_dmabuf *dmabuf;
  8592. int x, total_qe_count;
  8593. void *dma_pointer;
  8594. queue = kzalloc(sizeof(struct lpfc_queue) +
  8595. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8596. if (!queue)
  8597. return NULL;
  8598. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8599. INIT_LIST_HEAD(&queue->list);
  8600. INIT_LIST_HEAD(&queue->page_list);
  8601. INIT_LIST_HEAD(&queue->child_list);
  8602. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8603. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8604. if (!dmabuf)
  8605. goto out_fail;
  8606. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8607. PAGE_SIZE, &dmabuf->phys,
  8608. GFP_KERNEL);
  8609. if (!dmabuf->virt) {
  8610. kfree(dmabuf);
  8611. goto out_fail;
  8612. }
  8613. memset(dmabuf->virt, 0, PAGE_SIZE);
  8614. dmabuf->buffer_tag = x;
  8615. list_add_tail(&dmabuf->list, &queue->page_list);
  8616. /* initialize queue's entry array */
  8617. dma_pointer = dmabuf->virt;
  8618. for (; total_qe_count < entry_count &&
  8619. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8620. total_qe_count++, dma_pointer += entry_size) {
  8621. queue->qe[total_qe_count].address = dma_pointer;
  8622. }
  8623. }
  8624. queue->entry_size = entry_size;
  8625. queue->entry_count = entry_count;
  8626. queue->phba = phba;
  8627. return queue;
  8628. out_fail:
  8629. lpfc_sli4_queue_free(queue);
  8630. return NULL;
  8631. }
  8632. /**
  8633. * lpfc_eq_create - Create an Event Queue on the HBA
  8634. * @phba: HBA structure that indicates port to create a queue on.
  8635. * @eq: The queue structure to use to create the event queue.
  8636. * @imax: The maximum interrupt per second limit.
  8637. *
  8638. * This function creates an event queue, as detailed in @eq, on a port,
  8639. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8640. *
  8641. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8642. * is used to get the entry count and entry size that are necessary to
  8643. * determine the number of pages to allocate and use for this queue. This
  8644. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8645. * event queue. This function is asynchronous and will wait for the mailbox
  8646. * command to finish before continuing.
  8647. *
  8648. * On success this function will return a zero. If unable to allocate enough
  8649. * memory this function will return ENOMEM. If the queue create mailbox command
  8650. * fails this function will return ENXIO.
  8651. **/
  8652. uint32_t
  8653. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8654. {
  8655. struct lpfc_mbx_eq_create *eq_create;
  8656. LPFC_MBOXQ_t *mbox;
  8657. int rc, length, status = 0;
  8658. struct lpfc_dmabuf *dmabuf;
  8659. uint32_t shdr_status, shdr_add_status;
  8660. union lpfc_sli4_cfg_shdr *shdr;
  8661. uint16_t dmult;
  8662. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8663. if (!mbox)
  8664. return -ENOMEM;
  8665. length = (sizeof(struct lpfc_mbx_eq_create) -
  8666. sizeof(struct lpfc_sli4_cfg_mhdr));
  8667. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8668. LPFC_MBOX_OPCODE_EQ_CREATE,
  8669. length, LPFC_SLI4_MBX_EMBED);
  8670. eq_create = &mbox->u.mqe.un.eq_create;
  8671. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8672. eq->page_count);
  8673. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8674. LPFC_EQE_SIZE);
  8675. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8676. /* Calculate delay multiper from maximum interrupt per second */
  8677. dmult = LPFC_DMULT_CONST/imax - 1;
  8678. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8679. dmult);
  8680. switch (eq->entry_count) {
  8681. default:
  8682. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8683. "0360 Unsupported EQ count. (%d)\n",
  8684. eq->entry_count);
  8685. if (eq->entry_count < 256)
  8686. return -EINVAL;
  8687. /* otherwise default to smallest count (drop through) */
  8688. case 256:
  8689. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8690. LPFC_EQ_CNT_256);
  8691. break;
  8692. case 512:
  8693. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8694. LPFC_EQ_CNT_512);
  8695. break;
  8696. case 1024:
  8697. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8698. LPFC_EQ_CNT_1024);
  8699. break;
  8700. case 2048:
  8701. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8702. LPFC_EQ_CNT_2048);
  8703. break;
  8704. case 4096:
  8705. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8706. LPFC_EQ_CNT_4096);
  8707. break;
  8708. }
  8709. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8710. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8711. putPaddrLow(dmabuf->phys);
  8712. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8713. putPaddrHigh(dmabuf->phys);
  8714. }
  8715. mbox->vport = phba->pport;
  8716. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8717. mbox->context1 = NULL;
  8718. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8719. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8720. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8721. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8722. if (shdr_status || shdr_add_status || rc) {
  8723. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8724. "2500 EQ_CREATE mailbox failed with "
  8725. "status x%x add_status x%x, mbx status x%x\n",
  8726. shdr_status, shdr_add_status, rc);
  8727. status = -ENXIO;
  8728. }
  8729. eq->type = LPFC_EQ;
  8730. eq->subtype = LPFC_NONE;
  8731. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8732. if (eq->queue_id == 0xFFFF)
  8733. status = -ENXIO;
  8734. eq->host_index = 0;
  8735. eq->hba_index = 0;
  8736. mempool_free(mbox, phba->mbox_mem_pool);
  8737. return status;
  8738. }
  8739. /**
  8740. * lpfc_cq_create - Create a Completion Queue on the HBA
  8741. * @phba: HBA structure that indicates port to create a queue on.
  8742. * @cq: The queue structure to use to create the completion queue.
  8743. * @eq: The event queue to bind this completion queue to.
  8744. *
  8745. * This function creates a completion queue, as detailed in @wq, on a port,
  8746. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8747. *
  8748. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8749. * is used to get the entry count and entry size that are necessary to
  8750. * determine the number of pages to allocate and use for this queue. The @eq
  8751. * is used to indicate which event queue to bind this completion queue to. This
  8752. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8753. * completion queue. This function is asynchronous and will wait for the mailbox
  8754. * command to finish before continuing.
  8755. *
  8756. * On success this function will return a zero. If unable to allocate enough
  8757. * memory this function will return ENOMEM. If the queue create mailbox command
  8758. * fails this function will return ENXIO.
  8759. **/
  8760. uint32_t
  8761. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8762. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8763. {
  8764. struct lpfc_mbx_cq_create *cq_create;
  8765. struct lpfc_dmabuf *dmabuf;
  8766. LPFC_MBOXQ_t *mbox;
  8767. int rc, length, status = 0;
  8768. uint32_t shdr_status, shdr_add_status;
  8769. union lpfc_sli4_cfg_shdr *shdr;
  8770. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8771. if (!mbox)
  8772. return -ENOMEM;
  8773. length = (sizeof(struct lpfc_mbx_cq_create) -
  8774. sizeof(struct lpfc_sli4_cfg_mhdr));
  8775. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8776. LPFC_MBOX_OPCODE_CQ_CREATE,
  8777. length, LPFC_SLI4_MBX_EMBED);
  8778. cq_create = &mbox->u.mqe.un.cq_create;
  8779. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8780. cq->page_count);
  8781. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8782. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8783. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8784. switch (cq->entry_count) {
  8785. default:
  8786. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8787. "0361 Unsupported CQ count. (%d)\n",
  8788. cq->entry_count);
  8789. if (cq->entry_count < 256)
  8790. return -EINVAL;
  8791. /* otherwise default to smallest count (drop through) */
  8792. case 256:
  8793. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8794. LPFC_CQ_CNT_256);
  8795. break;
  8796. case 512:
  8797. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8798. LPFC_CQ_CNT_512);
  8799. break;
  8800. case 1024:
  8801. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8802. LPFC_CQ_CNT_1024);
  8803. break;
  8804. }
  8805. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8806. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8807. putPaddrLow(dmabuf->phys);
  8808. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8809. putPaddrHigh(dmabuf->phys);
  8810. }
  8811. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8812. /* The IOCTL status is embedded in the mailbox subheader. */
  8813. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8814. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8815. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8816. if (shdr_status || shdr_add_status || rc) {
  8817. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8818. "2501 CQ_CREATE mailbox failed with "
  8819. "status x%x add_status x%x, mbx status x%x\n",
  8820. shdr_status, shdr_add_status, rc);
  8821. status = -ENXIO;
  8822. goto out;
  8823. }
  8824. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8825. if (cq->queue_id == 0xFFFF) {
  8826. status = -ENXIO;
  8827. goto out;
  8828. }
  8829. /* link the cq onto the parent eq child list */
  8830. list_add_tail(&cq->list, &eq->child_list);
  8831. /* Set up completion queue's type and subtype */
  8832. cq->type = type;
  8833. cq->subtype = subtype;
  8834. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8835. cq->host_index = 0;
  8836. cq->hba_index = 0;
  8837. out:
  8838. mempool_free(mbox, phba->mbox_mem_pool);
  8839. return status;
  8840. }
  8841. /**
  8842. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8843. * @phba: HBA structure that indicates port to create a queue on.
  8844. * @mq: The queue structure to use to create the mailbox queue.
  8845. *
  8846. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8847. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8848. *
  8849. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8850. * is used to get the entry count and entry size that are necessary to
  8851. * determine the number of pages to allocate and use for this queue. This
  8852. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8853. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8854. * command to finish before continuing.
  8855. *
  8856. * On success this function will return a zero. If unable to allocate enough
  8857. * memory this function will return ENOMEM. If the queue create mailbox command
  8858. * fails this function will return ENXIO.
  8859. **/
  8860. uint32_t
  8861. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8862. struct lpfc_queue *cq, uint32_t subtype)
  8863. {
  8864. struct lpfc_mbx_mq_create *mq_create;
  8865. struct lpfc_dmabuf *dmabuf;
  8866. LPFC_MBOXQ_t *mbox;
  8867. int rc, length, status = 0;
  8868. uint32_t shdr_status, shdr_add_status;
  8869. union lpfc_sli4_cfg_shdr *shdr;
  8870. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8871. if (!mbox)
  8872. return -ENOMEM;
  8873. length = (sizeof(struct lpfc_mbx_mq_create) -
  8874. sizeof(struct lpfc_sli4_cfg_mhdr));
  8875. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8876. LPFC_MBOX_OPCODE_MQ_CREATE,
  8877. length, LPFC_SLI4_MBX_EMBED);
  8878. mq_create = &mbox->u.mqe.un.mq_create;
  8879. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8880. mq->page_count);
  8881. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8882. cq->queue_id);
  8883. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8884. switch (mq->entry_count) {
  8885. default:
  8886. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8887. "0362 Unsupported MQ count. (%d)\n",
  8888. mq->entry_count);
  8889. if (mq->entry_count < 16)
  8890. return -EINVAL;
  8891. /* otherwise default to smallest count (drop through) */
  8892. case 16:
  8893. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8894. LPFC_MQ_CNT_16);
  8895. break;
  8896. case 32:
  8897. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8898. LPFC_MQ_CNT_32);
  8899. break;
  8900. case 64:
  8901. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8902. LPFC_MQ_CNT_64);
  8903. break;
  8904. case 128:
  8905. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8906. LPFC_MQ_CNT_128);
  8907. break;
  8908. }
  8909. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8910. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8911. putPaddrLow(dmabuf->phys);
  8912. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8913. putPaddrHigh(dmabuf->phys);
  8914. }
  8915. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8916. /* The IOCTL status is embedded in the mailbox subheader. */
  8917. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8918. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8919. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8920. if (shdr_status || shdr_add_status || rc) {
  8921. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8922. "2502 MQ_CREATE mailbox failed with "
  8923. "status x%x add_status x%x, mbx status x%x\n",
  8924. shdr_status, shdr_add_status, rc);
  8925. status = -ENXIO;
  8926. goto out;
  8927. }
  8928. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8929. if (mq->queue_id == 0xFFFF) {
  8930. status = -ENXIO;
  8931. goto out;
  8932. }
  8933. mq->type = LPFC_MQ;
  8934. mq->subtype = subtype;
  8935. mq->host_index = 0;
  8936. mq->hba_index = 0;
  8937. /* link the mq onto the parent cq child list */
  8938. list_add_tail(&mq->list, &cq->child_list);
  8939. out:
  8940. mempool_free(mbox, phba->mbox_mem_pool);
  8941. return status;
  8942. }
  8943. /**
  8944. * lpfc_wq_create - Create a Work Queue on the HBA
  8945. * @phba: HBA structure that indicates port to create a queue on.
  8946. * @wq: The queue structure to use to create the work queue.
  8947. * @cq: The completion queue to bind this work queue to.
  8948. * @subtype: The subtype of the work queue indicating its functionality.
  8949. *
  8950. * This function creates a work queue, as detailed in @wq, on a port, described
  8951. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  8952. *
  8953. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  8954. * is used to get the entry count and entry size that are necessary to
  8955. * determine the number of pages to allocate and use for this queue. The @cq
  8956. * is used to indicate which completion queue to bind this work queue to. This
  8957. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  8958. * work queue. This function is asynchronous and will wait for the mailbox
  8959. * command to finish before continuing.
  8960. *
  8961. * On success this function will return a zero. If unable to allocate enough
  8962. * memory this function will return ENOMEM. If the queue create mailbox command
  8963. * fails this function will return ENXIO.
  8964. **/
  8965. uint32_t
  8966. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  8967. struct lpfc_queue *cq, uint32_t subtype)
  8968. {
  8969. struct lpfc_mbx_wq_create *wq_create;
  8970. struct lpfc_dmabuf *dmabuf;
  8971. LPFC_MBOXQ_t *mbox;
  8972. int rc, length, status = 0;
  8973. uint32_t shdr_status, shdr_add_status;
  8974. union lpfc_sli4_cfg_shdr *shdr;
  8975. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8976. if (!mbox)
  8977. return -ENOMEM;
  8978. length = (sizeof(struct lpfc_mbx_wq_create) -
  8979. sizeof(struct lpfc_sli4_cfg_mhdr));
  8980. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8981. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  8982. length, LPFC_SLI4_MBX_EMBED);
  8983. wq_create = &mbox->u.mqe.un.wq_create;
  8984. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  8985. wq->page_count);
  8986. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  8987. cq->queue_id);
  8988. list_for_each_entry(dmabuf, &wq->page_list, list) {
  8989. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8990. putPaddrLow(dmabuf->phys);
  8991. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8992. putPaddrHigh(dmabuf->phys);
  8993. }
  8994. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8995. /* The IOCTL status is embedded in the mailbox subheader. */
  8996. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  8997. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8998. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8999. if (shdr_status || shdr_add_status || rc) {
  9000. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9001. "2503 WQ_CREATE mailbox failed with "
  9002. "status x%x add_status x%x, mbx status x%x\n",
  9003. shdr_status, shdr_add_status, rc);
  9004. status = -ENXIO;
  9005. goto out;
  9006. }
  9007. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9008. if (wq->queue_id == 0xFFFF) {
  9009. status = -ENXIO;
  9010. goto out;
  9011. }
  9012. wq->type = LPFC_WQ;
  9013. wq->subtype = subtype;
  9014. wq->host_index = 0;
  9015. wq->hba_index = 0;
  9016. /* link the wq onto the parent cq child list */
  9017. list_add_tail(&wq->list, &cq->child_list);
  9018. out:
  9019. mempool_free(mbox, phba->mbox_mem_pool);
  9020. return status;
  9021. }
  9022. /**
  9023. * lpfc_rq_create - Create a Receive Queue on the HBA
  9024. * @phba: HBA structure that indicates port to create a queue on.
  9025. * @hrq: The queue structure to use to create the header receive queue.
  9026. * @drq: The queue structure to use to create the data receive queue.
  9027. * @cq: The completion queue to bind this work queue to.
  9028. *
  9029. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9030. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9031. * to the HBA.
  9032. *
  9033. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9034. * struct is used to get the entry count that is necessary to determine the
  9035. * number of pages to use for this queue. The @cq is used to indicate which
  9036. * completion queue to bind received buffers that are posted to these queues to.
  9037. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9038. * receive queue pair. This function is asynchronous and will wait for the
  9039. * mailbox command to finish before continuing.
  9040. *
  9041. * On success this function will return a zero. If unable to allocate enough
  9042. * memory this function will return ENOMEM. If the queue create mailbox command
  9043. * fails this function will return ENXIO.
  9044. **/
  9045. uint32_t
  9046. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9047. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9048. {
  9049. struct lpfc_mbx_rq_create *rq_create;
  9050. struct lpfc_dmabuf *dmabuf;
  9051. LPFC_MBOXQ_t *mbox;
  9052. int rc, length, status = 0;
  9053. uint32_t shdr_status, shdr_add_status;
  9054. union lpfc_sli4_cfg_shdr *shdr;
  9055. if (hrq->entry_count != drq->entry_count)
  9056. return -EINVAL;
  9057. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9058. if (!mbox)
  9059. return -ENOMEM;
  9060. length = (sizeof(struct lpfc_mbx_rq_create) -
  9061. sizeof(struct lpfc_sli4_cfg_mhdr));
  9062. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9063. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9064. length, LPFC_SLI4_MBX_EMBED);
  9065. rq_create = &mbox->u.mqe.un.rq_create;
  9066. switch (hrq->entry_count) {
  9067. default:
  9068. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9069. "2535 Unsupported RQ count. (%d)\n",
  9070. hrq->entry_count);
  9071. if (hrq->entry_count < 512)
  9072. return -EINVAL;
  9073. /* otherwise default to smallest count (drop through) */
  9074. case 512:
  9075. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9076. LPFC_RQ_RING_SIZE_512);
  9077. break;
  9078. case 1024:
  9079. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9080. LPFC_RQ_RING_SIZE_1024);
  9081. break;
  9082. case 2048:
  9083. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9084. LPFC_RQ_RING_SIZE_2048);
  9085. break;
  9086. case 4096:
  9087. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9088. LPFC_RQ_RING_SIZE_4096);
  9089. break;
  9090. }
  9091. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9092. cq->queue_id);
  9093. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9094. hrq->page_count);
  9095. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9096. LPFC_HDR_BUF_SIZE);
  9097. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9098. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9099. putPaddrLow(dmabuf->phys);
  9100. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9101. putPaddrHigh(dmabuf->phys);
  9102. }
  9103. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9104. /* The IOCTL status is embedded in the mailbox subheader. */
  9105. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9106. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9107. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9108. if (shdr_status || shdr_add_status || rc) {
  9109. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9110. "2504 RQ_CREATE mailbox failed with "
  9111. "status x%x add_status x%x, mbx status x%x\n",
  9112. shdr_status, shdr_add_status, rc);
  9113. status = -ENXIO;
  9114. goto out;
  9115. }
  9116. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9117. if (hrq->queue_id == 0xFFFF) {
  9118. status = -ENXIO;
  9119. goto out;
  9120. }
  9121. hrq->type = LPFC_HRQ;
  9122. hrq->subtype = subtype;
  9123. hrq->host_index = 0;
  9124. hrq->hba_index = 0;
  9125. /* now create the data queue */
  9126. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9127. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9128. length, LPFC_SLI4_MBX_EMBED);
  9129. switch (drq->entry_count) {
  9130. default:
  9131. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9132. "2536 Unsupported RQ count. (%d)\n",
  9133. drq->entry_count);
  9134. if (drq->entry_count < 512)
  9135. return -EINVAL;
  9136. /* otherwise default to smallest count (drop through) */
  9137. case 512:
  9138. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9139. LPFC_RQ_RING_SIZE_512);
  9140. break;
  9141. case 1024:
  9142. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9143. LPFC_RQ_RING_SIZE_1024);
  9144. break;
  9145. case 2048:
  9146. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9147. LPFC_RQ_RING_SIZE_2048);
  9148. break;
  9149. case 4096:
  9150. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9151. LPFC_RQ_RING_SIZE_4096);
  9152. break;
  9153. }
  9154. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9155. cq->queue_id);
  9156. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9157. drq->page_count);
  9158. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9159. LPFC_DATA_BUF_SIZE);
  9160. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9161. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9162. putPaddrLow(dmabuf->phys);
  9163. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9164. putPaddrHigh(dmabuf->phys);
  9165. }
  9166. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9167. /* The IOCTL status is embedded in the mailbox subheader. */
  9168. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9169. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9170. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9171. if (shdr_status || shdr_add_status || rc) {
  9172. status = -ENXIO;
  9173. goto out;
  9174. }
  9175. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9176. if (drq->queue_id == 0xFFFF) {
  9177. status = -ENXIO;
  9178. goto out;
  9179. }
  9180. drq->type = LPFC_DRQ;
  9181. drq->subtype = subtype;
  9182. drq->host_index = 0;
  9183. drq->hba_index = 0;
  9184. /* link the header and data RQs onto the parent cq child list */
  9185. list_add_tail(&hrq->list, &cq->child_list);
  9186. list_add_tail(&drq->list, &cq->child_list);
  9187. out:
  9188. mempool_free(mbox, phba->mbox_mem_pool);
  9189. return status;
  9190. }
  9191. /**
  9192. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9193. * @eq: The queue structure associated with the queue to destroy.
  9194. *
  9195. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9196. * command, specific to the type of queue, to the HBA.
  9197. *
  9198. * The @eq struct is used to get the queue ID of the queue to destroy.
  9199. *
  9200. * On success this function will return a zero. If the queue destroy mailbox
  9201. * command fails this function will return ENXIO.
  9202. **/
  9203. uint32_t
  9204. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9205. {
  9206. LPFC_MBOXQ_t *mbox;
  9207. int rc, length, status = 0;
  9208. uint32_t shdr_status, shdr_add_status;
  9209. union lpfc_sli4_cfg_shdr *shdr;
  9210. if (!eq)
  9211. return -ENODEV;
  9212. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9213. if (!mbox)
  9214. return -ENOMEM;
  9215. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9216. sizeof(struct lpfc_sli4_cfg_mhdr));
  9217. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9218. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9219. length, LPFC_SLI4_MBX_EMBED);
  9220. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9221. eq->queue_id);
  9222. mbox->vport = eq->phba->pport;
  9223. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9224. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9225. /* The IOCTL status is embedded in the mailbox subheader. */
  9226. shdr = (union lpfc_sli4_cfg_shdr *)
  9227. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9228. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9229. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9230. if (shdr_status || shdr_add_status || rc) {
  9231. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9232. "2505 EQ_DESTROY mailbox failed with "
  9233. "status x%x add_status x%x, mbx status x%x\n",
  9234. shdr_status, shdr_add_status, rc);
  9235. status = -ENXIO;
  9236. }
  9237. /* Remove eq from any list */
  9238. list_del_init(&eq->list);
  9239. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9240. return status;
  9241. }
  9242. /**
  9243. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9244. * @cq: The queue structure associated with the queue to destroy.
  9245. *
  9246. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9247. * command, specific to the type of queue, to the HBA.
  9248. *
  9249. * The @cq struct is used to get the queue ID of the queue to destroy.
  9250. *
  9251. * On success this function will return a zero. If the queue destroy mailbox
  9252. * command fails this function will return ENXIO.
  9253. **/
  9254. uint32_t
  9255. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9256. {
  9257. LPFC_MBOXQ_t *mbox;
  9258. int rc, length, status = 0;
  9259. uint32_t shdr_status, shdr_add_status;
  9260. union lpfc_sli4_cfg_shdr *shdr;
  9261. if (!cq)
  9262. return -ENODEV;
  9263. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9264. if (!mbox)
  9265. return -ENOMEM;
  9266. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9267. sizeof(struct lpfc_sli4_cfg_mhdr));
  9268. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9269. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9270. length, LPFC_SLI4_MBX_EMBED);
  9271. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9272. cq->queue_id);
  9273. mbox->vport = cq->phba->pport;
  9274. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9275. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9276. /* The IOCTL status is embedded in the mailbox subheader. */
  9277. shdr = (union lpfc_sli4_cfg_shdr *)
  9278. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9279. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9280. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9281. if (shdr_status || shdr_add_status || rc) {
  9282. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9283. "2506 CQ_DESTROY mailbox failed with "
  9284. "status x%x add_status x%x, mbx status x%x\n",
  9285. shdr_status, shdr_add_status, rc);
  9286. status = -ENXIO;
  9287. }
  9288. /* Remove cq from any list */
  9289. list_del_init(&cq->list);
  9290. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9291. return status;
  9292. }
  9293. /**
  9294. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9295. * @qm: The queue structure associated with the queue to destroy.
  9296. *
  9297. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9298. * command, specific to the type of queue, to the HBA.
  9299. *
  9300. * The @mq struct is used to get the queue ID of the queue to destroy.
  9301. *
  9302. * On success this function will return a zero. If the queue destroy mailbox
  9303. * command fails this function will return ENXIO.
  9304. **/
  9305. uint32_t
  9306. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9307. {
  9308. LPFC_MBOXQ_t *mbox;
  9309. int rc, length, status = 0;
  9310. uint32_t shdr_status, shdr_add_status;
  9311. union lpfc_sli4_cfg_shdr *shdr;
  9312. if (!mq)
  9313. return -ENODEV;
  9314. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9315. if (!mbox)
  9316. return -ENOMEM;
  9317. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9318. sizeof(struct lpfc_sli4_cfg_mhdr));
  9319. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9320. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9321. length, LPFC_SLI4_MBX_EMBED);
  9322. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9323. mq->queue_id);
  9324. mbox->vport = mq->phba->pport;
  9325. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9326. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9327. /* The IOCTL status is embedded in the mailbox subheader. */
  9328. shdr = (union lpfc_sli4_cfg_shdr *)
  9329. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9330. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9331. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9332. if (shdr_status || shdr_add_status || rc) {
  9333. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9334. "2507 MQ_DESTROY mailbox failed with "
  9335. "status x%x add_status x%x, mbx status x%x\n",
  9336. shdr_status, shdr_add_status, rc);
  9337. status = -ENXIO;
  9338. }
  9339. /* Remove mq from any list */
  9340. list_del_init(&mq->list);
  9341. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9342. return status;
  9343. }
  9344. /**
  9345. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9346. * @wq: The queue structure associated with the queue to destroy.
  9347. *
  9348. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9349. * command, specific to the type of queue, to the HBA.
  9350. *
  9351. * The @wq struct is used to get the queue ID of the queue to destroy.
  9352. *
  9353. * On success this function will return a zero. If the queue destroy mailbox
  9354. * command fails this function will return ENXIO.
  9355. **/
  9356. uint32_t
  9357. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9358. {
  9359. LPFC_MBOXQ_t *mbox;
  9360. int rc, length, status = 0;
  9361. uint32_t shdr_status, shdr_add_status;
  9362. union lpfc_sli4_cfg_shdr *shdr;
  9363. if (!wq)
  9364. return -ENODEV;
  9365. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9366. if (!mbox)
  9367. return -ENOMEM;
  9368. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9369. sizeof(struct lpfc_sli4_cfg_mhdr));
  9370. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9371. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9372. length, LPFC_SLI4_MBX_EMBED);
  9373. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9374. wq->queue_id);
  9375. mbox->vport = wq->phba->pport;
  9376. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9377. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9378. shdr = (union lpfc_sli4_cfg_shdr *)
  9379. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9380. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9381. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9382. if (shdr_status || shdr_add_status || rc) {
  9383. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9384. "2508 WQ_DESTROY mailbox failed with "
  9385. "status x%x add_status x%x, mbx status x%x\n",
  9386. shdr_status, shdr_add_status, rc);
  9387. status = -ENXIO;
  9388. }
  9389. /* Remove wq from any list */
  9390. list_del_init(&wq->list);
  9391. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9392. return status;
  9393. }
  9394. /**
  9395. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9396. * @rq: The queue structure associated with the queue to destroy.
  9397. *
  9398. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9399. * command, specific to the type of queue, to the HBA.
  9400. *
  9401. * The @rq struct is used to get the queue ID of the queue to destroy.
  9402. *
  9403. * On success this function will return a zero. If the queue destroy mailbox
  9404. * command fails this function will return ENXIO.
  9405. **/
  9406. uint32_t
  9407. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9408. struct lpfc_queue *drq)
  9409. {
  9410. LPFC_MBOXQ_t *mbox;
  9411. int rc, length, status = 0;
  9412. uint32_t shdr_status, shdr_add_status;
  9413. union lpfc_sli4_cfg_shdr *shdr;
  9414. if (!hrq || !drq)
  9415. return -ENODEV;
  9416. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9417. if (!mbox)
  9418. return -ENOMEM;
  9419. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9420. sizeof(struct mbox_header));
  9421. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9422. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9423. length, LPFC_SLI4_MBX_EMBED);
  9424. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9425. hrq->queue_id);
  9426. mbox->vport = hrq->phba->pport;
  9427. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9428. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9429. /* The IOCTL status is embedded in the mailbox subheader. */
  9430. shdr = (union lpfc_sli4_cfg_shdr *)
  9431. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9432. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9433. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9434. if (shdr_status || shdr_add_status || rc) {
  9435. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9436. "2509 RQ_DESTROY mailbox failed with "
  9437. "status x%x add_status x%x, mbx status x%x\n",
  9438. shdr_status, shdr_add_status, rc);
  9439. if (rc != MBX_TIMEOUT)
  9440. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9441. return -ENXIO;
  9442. }
  9443. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9444. drq->queue_id);
  9445. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9446. shdr = (union lpfc_sli4_cfg_shdr *)
  9447. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9448. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9449. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9450. if (shdr_status || shdr_add_status || rc) {
  9451. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9452. "2510 RQ_DESTROY mailbox failed with "
  9453. "status x%x add_status x%x, mbx status x%x\n",
  9454. shdr_status, shdr_add_status, rc);
  9455. status = -ENXIO;
  9456. }
  9457. list_del_init(&hrq->list);
  9458. list_del_init(&drq->list);
  9459. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9460. return status;
  9461. }
  9462. /**
  9463. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9464. * @phba: The virtual port for which this call being executed.
  9465. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9466. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9467. * @xritag: the xritag that ties this io to the SGL pages.
  9468. *
  9469. * This routine will post the sgl pages for the IO that has the xritag
  9470. * that is in the iocbq structure. The xritag is assigned during iocbq
  9471. * creation and persists for as long as the driver is loaded.
  9472. * if the caller has fewer than 256 scatter gather segments to map then
  9473. * pdma_phys_addr1 should be 0.
  9474. * If the caller needs to map more than 256 scatter gather segment then
  9475. * pdma_phys_addr1 should be a valid physical address.
  9476. * physical address for SGLs must be 64 byte aligned.
  9477. * If you are going to map 2 SGL's then the first one must have 256 entries
  9478. * the second sgl can have between 1 and 256 entries.
  9479. *
  9480. * Return codes:
  9481. * 0 - Success
  9482. * -ENXIO, -ENOMEM - Failure
  9483. **/
  9484. int
  9485. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9486. dma_addr_t pdma_phys_addr0,
  9487. dma_addr_t pdma_phys_addr1,
  9488. uint16_t xritag)
  9489. {
  9490. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9491. LPFC_MBOXQ_t *mbox;
  9492. int rc;
  9493. uint32_t shdr_status, shdr_add_status;
  9494. union lpfc_sli4_cfg_shdr *shdr;
  9495. if (xritag == NO_XRI) {
  9496. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9497. "0364 Invalid param:\n");
  9498. return -EINVAL;
  9499. }
  9500. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9501. if (!mbox)
  9502. return -ENOMEM;
  9503. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9504. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9505. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9506. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9507. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9508. &mbox->u.mqe.un.post_sgl_pages;
  9509. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9510. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9511. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9512. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9513. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9514. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9515. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9516. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9517. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9518. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9519. if (!phba->sli4_hba.intr_enable)
  9520. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9521. else
  9522. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9523. /* The IOCTL status is embedded in the mailbox subheader. */
  9524. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9525. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9526. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9527. if (rc != MBX_TIMEOUT)
  9528. mempool_free(mbox, phba->mbox_mem_pool);
  9529. if (shdr_status || shdr_add_status || rc) {
  9530. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9531. "2511 POST_SGL mailbox failed with "
  9532. "status x%x add_status x%x, mbx status x%x\n",
  9533. shdr_status, shdr_add_status, rc);
  9534. rc = -ENXIO;
  9535. }
  9536. return 0;
  9537. }
  9538. /**
  9539. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9540. * @phba: The virtual port for which this call being executed.
  9541. *
  9542. * This routine will remove all of the sgl pages registered with the hba.
  9543. *
  9544. * Return codes:
  9545. * 0 - Success
  9546. * -ENXIO, -ENOMEM - Failure
  9547. **/
  9548. int
  9549. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9550. {
  9551. LPFC_MBOXQ_t *mbox;
  9552. int rc;
  9553. uint32_t shdr_status, shdr_add_status;
  9554. union lpfc_sli4_cfg_shdr *shdr;
  9555. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9556. if (!mbox)
  9557. return -ENOMEM;
  9558. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9559. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9560. LPFC_SLI4_MBX_EMBED);
  9561. if (!phba->sli4_hba.intr_enable)
  9562. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9563. else
  9564. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9565. /* The IOCTL status is embedded in the mailbox subheader. */
  9566. shdr = (union lpfc_sli4_cfg_shdr *)
  9567. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9568. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9569. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9570. if (rc != MBX_TIMEOUT)
  9571. mempool_free(mbox, phba->mbox_mem_pool);
  9572. if (shdr_status || shdr_add_status || rc) {
  9573. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9574. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9575. "status x%x add_status x%x, mbx status x%x\n",
  9576. shdr_status, shdr_add_status, rc);
  9577. rc = -ENXIO;
  9578. }
  9579. return rc;
  9580. }
  9581. /**
  9582. * lpfc_sli4_next_xritag - Get an xritag for the io
  9583. * @phba: Pointer to HBA context object.
  9584. *
  9585. * This function gets an xritag for the iocb. If there is no unused xritag
  9586. * it will return 0xffff.
  9587. * The function returns the allocated xritag if successful, else returns zero.
  9588. * Zero is not a valid xritag.
  9589. * The caller is not required to hold any lock.
  9590. **/
  9591. uint16_t
  9592. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9593. {
  9594. uint16_t xritag;
  9595. spin_lock_irq(&phba->hbalock);
  9596. xritag = phba->sli4_hba.next_xri;
  9597. if ((xritag != (uint16_t) -1) && xritag <
  9598. (phba->sli4_hba.max_cfg_param.max_xri
  9599. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9600. phba->sli4_hba.next_xri++;
  9601. phba->sli4_hba.max_cfg_param.xri_used++;
  9602. spin_unlock_irq(&phba->hbalock);
  9603. return xritag;
  9604. }
  9605. spin_unlock_irq(&phba->hbalock);
  9606. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9607. "2004 Failed to allocate XRI.last XRITAG is %d"
  9608. " Max XRI is %d, Used XRI is %d\n",
  9609. phba->sli4_hba.next_xri,
  9610. phba->sli4_hba.max_cfg_param.max_xri,
  9611. phba->sli4_hba.max_cfg_param.xri_used);
  9612. return -1;
  9613. }
  9614. /**
  9615. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9616. * @phba: pointer to lpfc hba data structure.
  9617. *
  9618. * This routine is invoked to post a block of driver's sgl pages to the
  9619. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9620. * is only called when the driver is loading and after all IO has been
  9621. * stopped.
  9622. **/
  9623. int
  9624. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9625. {
  9626. struct lpfc_sglq *sglq_entry;
  9627. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9628. struct sgl_page_pairs *sgl_pg_pairs;
  9629. void *viraddr;
  9630. LPFC_MBOXQ_t *mbox;
  9631. uint32_t reqlen, alloclen, pg_pairs;
  9632. uint32_t mbox_tmo;
  9633. uint16_t xritag_start = 0;
  9634. int els_xri_cnt, rc = 0;
  9635. uint32_t shdr_status, shdr_add_status;
  9636. union lpfc_sli4_cfg_shdr *shdr;
  9637. /* The number of sgls to be posted */
  9638. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9639. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9640. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9641. if (reqlen > PAGE_SIZE) {
  9642. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9643. "2559 Block sgl registration required DMA "
  9644. "size (%d) great than a page\n", reqlen);
  9645. return -ENOMEM;
  9646. }
  9647. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9648. if (!mbox) {
  9649. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9650. "2560 Failed to allocate mbox cmd memory\n");
  9651. return -ENOMEM;
  9652. }
  9653. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9654. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9655. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9656. LPFC_SLI4_MBX_NEMBED);
  9657. if (alloclen < reqlen) {
  9658. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9659. "0285 Allocated DMA memory size (%d) is "
  9660. "less than the requested DMA memory "
  9661. "size (%d)\n", alloclen, reqlen);
  9662. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9663. return -ENOMEM;
  9664. }
  9665. /* Get the first SGE entry from the non-embedded DMA memory */
  9666. viraddr = mbox->sge_array->addr[0];
  9667. /* Set up the SGL pages in the non-embedded DMA pages */
  9668. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9669. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9670. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9671. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9672. /* Set up the sge entry */
  9673. sgl_pg_pairs->sgl_pg0_addr_lo =
  9674. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9675. sgl_pg_pairs->sgl_pg0_addr_hi =
  9676. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9677. sgl_pg_pairs->sgl_pg1_addr_lo =
  9678. cpu_to_le32(putPaddrLow(0));
  9679. sgl_pg_pairs->sgl_pg1_addr_hi =
  9680. cpu_to_le32(putPaddrHigh(0));
  9681. /* Keep the first xritag on the list */
  9682. if (pg_pairs == 0)
  9683. xritag_start = sglq_entry->sli4_xritag;
  9684. sgl_pg_pairs++;
  9685. }
  9686. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9687. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9688. /* Perform endian conversion if necessary */
  9689. sgl->word0 = cpu_to_le32(sgl->word0);
  9690. if (!phba->sli4_hba.intr_enable)
  9691. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9692. else {
  9693. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9694. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9695. }
  9696. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9697. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9698. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9699. if (rc != MBX_TIMEOUT)
  9700. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9701. if (shdr_status || shdr_add_status || rc) {
  9702. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9703. "2513 POST_SGL_BLOCK mailbox command failed "
  9704. "status x%x add_status x%x mbx status x%x\n",
  9705. shdr_status, shdr_add_status, rc);
  9706. rc = -ENXIO;
  9707. }
  9708. return rc;
  9709. }
  9710. /**
  9711. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9712. * @phba: pointer to lpfc hba data structure.
  9713. * @sblist: pointer to scsi buffer list.
  9714. * @count: number of scsi buffers on the list.
  9715. *
  9716. * This routine is invoked to post a block of @count scsi sgl pages from a
  9717. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9718. * No Lock is held.
  9719. *
  9720. **/
  9721. int
  9722. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9723. int cnt)
  9724. {
  9725. struct lpfc_scsi_buf *psb;
  9726. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9727. struct sgl_page_pairs *sgl_pg_pairs;
  9728. void *viraddr;
  9729. LPFC_MBOXQ_t *mbox;
  9730. uint32_t reqlen, alloclen, pg_pairs;
  9731. uint32_t mbox_tmo;
  9732. uint16_t xritag_start = 0;
  9733. int rc = 0;
  9734. uint32_t shdr_status, shdr_add_status;
  9735. dma_addr_t pdma_phys_bpl1;
  9736. union lpfc_sli4_cfg_shdr *shdr;
  9737. /* Calculate the requested length of the dma memory */
  9738. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9739. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9740. if (reqlen > PAGE_SIZE) {
  9741. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9742. "0217 Block sgl registration required DMA "
  9743. "size (%d) great than a page\n", reqlen);
  9744. return -ENOMEM;
  9745. }
  9746. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9747. if (!mbox) {
  9748. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9749. "0283 Failed to allocate mbox cmd memory\n");
  9750. return -ENOMEM;
  9751. }
  9752. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9753. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9754. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9755. LPFC_SLI4_MBX_NEMBED);
  9756. if (alloclen < reqlen) {
  9757. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9758. "2561 Allocated DMA memory size (%d) is "
  9759. "less than the requested DMA memory "
  9760. "size (%d)\n", alloclen, reqlen);
  9761. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9762. return -ENOMEM;
  9763. }
  9764. /* Get the first SGE entry from the non-embedded DMA memory */
  9765. viraddr = mbox->sge_array->addr[0];
  9766. /* Set up the SGL pages in the non-embedded DMA pages */
  9767. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9768. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9769. pg_pairs = 0;
  9770. list_for_each_entry(psb, sblist, list) {
  9771. /* Set up the sge entry */
  9772. sgl_pg_pairs->sgl_pg0_addr_lo =
  9773. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9774. sgl_pg_pairs->sgl_pg0_addr_hi =
  9775. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9776. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9777. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9778. else
  9779. pdma_phys_bpl1 = 0;
  9780. sgl_pg_pairs->sgl_pg1_addr_lo =
  9781. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9782. sgl_pg_pairs->sgl_pg1_addr_hi =
  9783. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9784. /* Keep the first xritag on the list */
  9785. if (pg_pairs == 0)
  9786. xritag_start = psb->cur_iocbq.sli4_xritag;
  9787. sgl_pg_pairs++;
  9788. pg_pairs++;
  9789. }
  9790. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9791. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9792. /* Perform endian conversion if necessary */
  9793. sgl->word0 = cpu_to_le32(sgl->word0);
  9794. if (!phba->sli4_hba.intr_enable)
  9795. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9796. else {
  9797. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9798. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9799. }
  9800. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9801. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9802. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9803. if (rc != MBX_TIMEOUT)
  9804. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9805. if (shdr_status || shdr_add_status || rc) {
  9806. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9807. "2564 POST_SGL_BLOCK mailbox command failed "
  9808. "status x%x add_status x%x mbx status x%x\n",
  9809. shdr_status, shdr_add_status, rc);
  9810. rc = -ENXIO;
  9811. }
  9812. return rc;
  9813. }
  9814. /**
  9815. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9816. * @phba: pointer to lpfc_hba struct that the frame was received on
  9817. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9818. *
  9819. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9820. * valid type of frame that the LPFC driver will handle. This function will
  9821. * return a zero if the frame is a valid frame or a non zero value when the
  9822. * frame does not pass the check.
  9823. **/
  9824. static int
  9825. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9826. {
  9827. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9828. char *type_names[] = FC_TYPE_NAMES_INIT;
  9829. struct fc_vft_header *fc_vft_hdr;
  9830. switch (fc_hdr->fh_r_ctl) {
  9831. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9832. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9833. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9834. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9835. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9836. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9837. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9838. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9839. case FC_RCTL_ELS_REQ: /* extended link services request */
  9840. case FC_RCTL_ELS_REP: /* extended link services reply */
  9841. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9842. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9843. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9844. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9845. case FC_RCTL_BA_RMC: /* remove connection */
  9846. case FC_RCTL_BA_ACC: /* basic accept */
  9847. case FC_RCTL_BA_RJT: /* basic reject */
  9848. case FC_RCTL_BA_PRMT:
  9849. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9850. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9851. case FC_RCTL_P_RJT: /* port reject */
  9852. case FC_RCTL_F_RJT: /* fabric reject */
  9853. case FC_RCTL_P_BSY: /* port busy */
  9854. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9855. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9856. case FC_RCTL_LCR: /* link credit reset */
  9857. case FC_RCTL_END: /* end */
  9858. break;
  9859. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9860. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9861. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9862. return lpfc_fc_frame_check(phba, fc_hdr);
  9863. default:
  9864. goto drop;
  9865. }
  9866. switch (fc_hdr->fh_type) {
  9867. case FC_TYPE_BLS:
  9868. case FC_TYPE_ELS:
  9869. case FC_TYPE_FCP:
  9870. case FC_TYPE_CT:
  9871. break;
  9872. case FC_TYPE_IP:
  9873. case FC_TYPE_ILS:
  9874. default:
  9875. goto drop;
  9876. }
  9877. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9878. "2538 Received frame rctl:%s type:%s\n",
  9879. rctl_names[fc_hdr->fh_r_ctl],
  9880. type_names[fc_hdr->fh_type]);
  9881. return 0;
  9882. drop:
  9883. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9884. "2539 Dropped frame rctl:%s type:%s\n",
  9885. rctl_names[fc_hdr->fh_r_ctl],
  9886. type_names[fc_hdr->fh_type]);
  9887. return 1;
  9888. }
  9889. /**
  9890. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9891. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9892. *
  9893. * This function processes the FC header to retrieve the VFI from the VF
  9894. * header, if one exists. This function will return the VFI if one exists
  9895. * or 0 if no VSAN Header exists.
  9896. **/
  9897. static uint32_t
  9898. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9899. {
  9900. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9901. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9902. return 0;
  9903. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9904. }
  9905. /**
  9906. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9907. * @phba: Pointer to the HBA structure to search for the vport on
  9908. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9909. * @fcfi: The FC Fabric ID that the frame came from
  9910. *
  9911. * This function searches the @phba for a vport that matches the content of the
  9912. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9913. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9914. * returns the matching vport pointer or NULL if unable to match frame to a
  9915. * vport.
  9916. **/
  9917. static struct lpfc_vport *
  9918. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9919. uint16_t fcfi)
  9920. {
  9921. struct lpfc_vport **vports;
  9922. struct lpfc_vport *vport = NULL;
  9923. int i;
  9924. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9925. fc_hdr->fh_d_id[1] << 8 |
  9926. fc_hdr->fh_d_id[2]);
  9927. vports = lpfc_create_vport_work_array(phba);
  9928. if (vports != NULL)
  9929. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9930. if (phba->fcf.fcfi == fcfi &&
  9931. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9932. vports[i]->fc_myDID == did) {
  9933. vport = vports[i];
  9934. break;
  9935. }
  9936. }
  9937. lpfc_destroy_vport_work_array(phba, vports);
  9938. return vport;
  9939. }
  9940. /**
  9941. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  9942. * @vport: The vport to work on.
  9943. *
  9944. * This function updates the receive sequence time stamp for this vport. The
  9945. * receive sequence time stamp indicates the time that the last frame of the
  9946. * the sequence that has been idle for the longest amount of time was received.
  9947. * the driver uses this time stamp to indicate if any received sequences have
  9948. * timed out.
  9949. **/
  9950. void
  9951. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  9952. {
  9953. struct lpfc_dmabuf *h_buf;
  9954. struct hbq_dmabuf *dmabuf = NULL;
  9955. /* get the oldest sequence on the rcv list */
  9956. h_buf = list_get_first(&vport->rcv_buffer_list,
  9957. struct lpfc_dmabuf, list);
  9958. if (!h_buf)
  9959. return;
  9960. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9961. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  9962. }
  9963. /**
  9964. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  9965. * @vport: The vport that the received sequences were sent to.
  9966. *
  9967. * This function cleans up all outstanding received sequences. This is called
  9968. * by the driver when a link event or user action invalidates all the received
  9969. * sequences.
  9970. **/
  9971. void
  9972. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  9973. {
  9974. struct lpfc_dmabuf *h_buf, *hnext;
  9975. struct lpfc_dmabuf *d_buf, *dnext;
  9976. struct hbq_dmabuf *dmabuf = NULL;
  9977. /* start with the oldest sequence on the rcv list */
  9978. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  9979. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9980. list_del_init(&dmabuf->hbuf.list);
  9981. list_for_each_entry_safe(d_buf, dnext,
  9982. &dmabuf->dbuf.list, list) {
  9983. list_del_init(&d_buf->list);
  9984. lpfc_in_buf_free(vport->phba, d_buf);
  9985. }
  9986. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  9987. }
  9988. }
  9989. /**
  9990. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  9991. * @vport: The vport that the received sequences were sent to.
  9992. *
  9993. * This function determines whether any received sequences have timed out by
  9994. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  9995. * indicates that there is at least one timed out sequence this routine will
  9996. * go through the received sequences one at a time from most inactive to most
  9997. * active to determine which ones need to be cleaned up. Once it has determined
  9998. * that a sequence needs to be cleaned up it will simply free up the resources
  9999. * without sending an abort.
  10000. **/
  10001. void
  10002. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10003. {
  10004. struct lpfc_dmabuf *h_buf, *hnext;
  10005. struct lpfc_dmabuf *d_buf, *dnext;
  10006. struct hbq_dmabuf *dmabuf = NULL;
  10007. unsigned long timeout;
  10008. int abort_count = 0;
  10009. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10010. vport->rcv_buffer_time_stamp);
  10011. if (list_empty(&vport->rcv_buffer_list) ||
  10012. time_before(jiffies, timeout))
  10013. return;
  10014. /* start with the oldest sequence on the rcv list */
  10015. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10016. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10017. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10018. dmabuf->time_stamp);
  10019. if (time_before(jiffies, timeout))
  10020. break;
  10021. abort_count++;
  10022. list_del_init(&dmabuf->hbuf.list);
  10023. list_for_each_entry_safe(d_buf, dnext,
  10024. &dmabuf->dbuf.list, list) {
  10025. list_del_init(&d_buf->list);
  10026. lpfc_in_buf_free(vport->phba, d_buf);
  10027. }
  10028. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10029. }
  10030. if (abort_count)
  10031. lpfc_update_rcv_time_stamp(vport);
  10032. }
  10033. /**
  10034. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10035. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10036. *
  10037. * This function searches through the existing incomplete sequences that have
  10038. * been sent to this @vport. If the frame matches one of the incomplete
  10039. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10040. * make up that sequence. If no sequence is found that matches this frame then
  10041. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10042. * This function returns a pointer to the first dmabuf in the sequence list that
  10043. * the frame was linked to.
  10044. **/
  10045. static struct hbq_dmabuf *
  10046. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10047. {
  10048. struct fc_frame_header *new_hdr;
  10049. struct fc_frame_header *temp_hdr;
  10050. struct lpfc_dmabuf *d_buf;
  10051. struct lpfc_dmabuf *h_buf;
  10052. struct hbq_dmabuf *seq_dmabuf = NULL;
  10053. struct hbq_dmabuf *temp_dmabuf = NULL;
  10054. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10055. dmabuf->time_stamp = jiffies;
  10056. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10057. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10058. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10059. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10060. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10061. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10062. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10063. continue;
  10064. /* found a pending sequence that matches this frame */
  10065. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10066. break;
  10067. }
  10068. if (!seq_dmabuf) {
  10069. /*
  10070. * This indicates first frame received for this sequence.
  10071. * Queue the buffer on the vport's rcv_buffer_list.
  10072. */
  10073. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10074. lpfc_update_rcv_time_stamp(vport);
  10075. return dmabuf;
  10076. }
  10077. temp_hdr = seq_dmabuf->hbuf.virt;
  10078. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10079. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10080. list_del_init(&seq_dmabuf->hbuf.list);
  10081. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10082. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10083. lpfc_update_rcv_time_stamp(vport);
  10084. return dmabuf;
  10085. }
  10086. /* move this sequence to the tail to indicate a young sequence */
  10087. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10088. seq_dmabuf->time_stamp = jiffies;
  10089. lpfc_update_rcv_time_stamp(vport);
  10090. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10091. temp_hdr = dmabuf->hbuf.virt;
  10092. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10093. return seq_dmabuf;
  10094. }
  10095. /* find the correct place in the sequence to insert this frame */
  10096. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10097. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10098. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10099. /*
  10100. * If the frame's sequence count is greater than the frame on
  10101. * the list then insert the frame right after this frame
  10102. */
  10103. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10104. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10105. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10106. return seq_dmabuf;
  10107. }
  10108. }
  10109. return NULL;
  10110. }
  10111. /**
  10112. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10113. * @vport: pointer to a vitural port
  10114. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10115. *
  10116. * This function tries to abort from the partially assembed sequence, described
  10117. * by the information from basic abbort @dmabuf. It checks to see whether such
  10118. * partially assembled sequence held by the driver. If so, it shall free up all
  10119. * the frames from the partially assembled sequence.
  10120. *
  10121. * Return
  10122. * true -- if there is matching partially assembled sequence present and all
  10123. * the frames freed with the sequence;
  10124. * false -- if there is no matching partially assembled sequence present so
  10125. * nothing got aborted in the lower layer driver
  10126. **/
  10127. static bool
  10128. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10129. struct hbq_dmabuf *dmabuf)
  10130. {
  10131. struct fc_frame_header *new_hdr;
  10132. struct fc_frame_header *temp_hdr;
  10133. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10134. struct hbq_dmabuf *seq_dmabuf = NULL;
  10135. /* Use the hdr_buf to find the sequence that matches this frame */
  10136. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10137. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10138. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10139. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10140. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10141. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10142. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10143. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10144. continue;
  10145. /* found a pending sequence that matches this frame */
  10146. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10147. break;
  10148. }
  10149. /* Free up all the frames from the partially assembled sequence */
  10150. if (seq_dmabuf) {
  10151. list_for_each_entry_safe(d_buf, n_buf,
  10152. &seq_dmabuf->dbuf.list, list) {
  10153. list_del_init(&d_buf->list);
  10154. lpfc_in_buf_free(vport->phba, d_buf);
  10155. }
  10156. return true;
  10157. }
  10158. return false;
  10159. }
  10160. /**
  10161. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10162. * @phba: Pointer to HBA context object.
  10163. * @cmd_iocbq: pointer to the command iocbq structure.
  10164. * @rsp_iocbq: pointer to the response iocbq structure.
  10165. *
  10166. * This function handles the sequence abort accept iocb command complete
  10167. * event. It properly releases the memory allocated to the sequence abort
  10168. * accept iocb.
  10169. **/
  10170. static void
  10171. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10172. struct lpfc_iocbq *cmd_iocbq,
  10173. struct lpfc_iocbq *rsp_iocbq)
  10174. {
  10175. if (cmd_iocbq)
  10176. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10177. }
  10178. /**
  10179. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10180. * @phba: Pointer to HBA context object.
  10181. * @fc_hdr: pointer to a FC frame header.
  10182. *
  10183. * This function sends a basic accept to a previous unsol sequence abort
  10184. * event after aborting the sequence handling.
  10185. **/
  10186. static void
  10187. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10188. struct fc_frame_header *fc_hdr)
  10189. {
  10190. struct lpfc_iocbq *ctiocb = NULL;
  10191. struct lpfc_nodelist *ndlp;
  10192. uint16_t oxid, rxid;
  10193. uint32_t sid, fctl;
  10194. IOCB_t *icmd;
  10195. if (!lpfc_is_link_up(phba))
  10196. return;
  10197. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10198. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10199. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10200. ndlp = lpfc_findnode_did(phba->pport, sid);
  10201. if (!ndlp) {
  10202. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10203. "1268 Find ndlp returned NULL for oxid:x%x "
  10204. "SID:x%x\n", oxid, sid);
  10205. return;
  10206. }
  10207. /* Allocate buffer for acc iocb */
  10208. ctiocb = lpfc_sli_get_iocbq(phba);
  10209. if (!ctiocb)
  10210. return;
  10211. /* Extract the F_CTL field from FC_HDR */
  10212. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10213. icmd = &ctiocb->iocb;
  10214. icmd->un.xseq64.bdl.bdeSize = 0;
  10215. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10216. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10217. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10218. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10219. /* Fill in the rest of iocb fields */
  10220. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10221. icmd->ulpBdeCount = 0;
  10222. icmd->ulpLe = 1;
  10223. icmd->ulpClass = CLASS3;
  10224. icmd->ulpContext = ndlp->nlp_rpi;
  10225. ctiocb->iocb_cmpl = NULL;
  10226. ctiocb->vport = phba->pport;
  10227. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10228. if (fctl & FC_FC_EX_CTX) {
  10229. /* ABTS sent by responder to CT exchange, construction
  10230. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10231. * field and RX_ID from ABTS for RX_ID field.
  10232. */
  10233. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10234. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10235. ctiocb->sli4_xritag = oxid;
  10236. } else {
  10237. /* ABTS sent by initiator to CT exchange, construction
  10238. * of BA_ACC will need to allocate a new XRI as for the
  10239. * XRI_TAG and RX_ID fields.
  10240. */
  10241. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10242. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10243. ctiocb->sli4_xritag = NO_XRI;
  10244. }
  10245. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10246. /* Xmit CT abts accept on exchange <xid> */
  10247. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10248. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10249. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10250. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10251. }
  10252. /**
  10253. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10254. * @vport: Pointer to the vport on which this sequence was received
  10255. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10256. *
  10257. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10258. * receive sequence is only partially assembed by the driver, it shall abort
  10259. * the partially assembled frames for the sequence. Otherwise, if the
  10260. * unsolicited receive sequence has been completely assembled and passed to
  10261. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10262. * unsolicited sequence has been aborted. After that, it will issue a basic
  10263. * accept to accept the abort.
  10264. **/
  10265. void
  10266. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10267. struct hbq_dmabuf *dmabuf)
  10268. {
  10269. struct lpfc_hba *phba = vport->phba;
  10270. struct fc_frame_header fc_hdr;
  10271. uint32_t fctl;
  10272. bool abts_par;
  10273. /* Make a copy of fc_hdr before the dmabuf being released */
  10274. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10275. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10276. if (fctl & FC_FC_EX_CTX) {
  10277. /*
  10278. * ABTS sent by responder to exchange, just free the buffer
  10279. */
  10280. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10281. } else {
  10282. /*
  10283. * ABTS sent by initiator to exchange, need to do cleanup
  10284. */
  10285. /* Try to abort partially assembled seq */
  10286. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10287. /* Send abort to ULP if partially seq abort failed */
  10288. if (abts_par == false)
  10289. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10290. else
  10291. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10292. }
  10293. /* Send basic accept (BA_ACC) to the abort requester */
  10294. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10295. }
  10296. /**
  10297. * lpfc_seq_complete - Indicates if a sequence is complete
  10298. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10299. *
  10300. * This function checks the sequence, starting with the frame described by
  10301. * @dmabuf, to see if all the frames associated with this sequence are present.
  10302. * the frames associated with this sequence are linked to the @dmabuf using the
  10303. * dbuf list. This function looks for two major things. 1) That the first frame
  10304. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10305. * set. 3) That there are no holes in the sequence count. The function will
  10306. * return 1 when the sequence is complete, otherwise it will return 0.
  10307. **/
  10308. static int
  10309. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10310. {
  10311. struct fc_frame_header *hdr;
  10312. struct lpfc_dmabuf *d_buf;
  10313. struct hbq_dmabuf *seq_dmabuf;
  10314. uint32_t fctl;
  10315. int seq_count = 0;
  10316. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10317. /* make sure first fame of sequence has a sequence count of zero */
  10318. if (hdr->fh_seq_cnt != seq_count)
  10319. return 0;
  10320. fctl = (hdr->fh_f_ctl[0] << 16 |
  10321. hdr->fh_f_ctl[1] << 8 |
  10322. hdr->fh_f_ctl[2]);
  10323. /* If last frame of sequence we can return success. */
  10324. if (fctl & FC_FC_END_SEQ)
  10325. return 1;
  10326. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10327. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10328. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10329. /* If there is a hole in the sequence count then fail. */
  10330. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10331. return 0;
  10332. fctl = (hdr->fh_f_ctl[0] << 16 |
  10333. hdr->fh_f_ctl[1] << 8 |
  10334. hdr->fh_f_ctl[2]);
  10335. /* If last frame of sequence we can return success. */
  10336. if (fctl & FC_FC_END_SEQ)
  10337. return 1;
  10338. }
  10339. return 0;
  10340. }
  10341. /**
  10342. * lpfc_prep_seq - Prep sequence for ULP processing
  10343. * @vport: Pointer to the vport on which this sequence was received
  10344. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10345. *
  10346. * This function takes a sequence, described by a list of frames, and creates
  10347. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10348. * used to issue to the generic unsolicited sequence handler. This routine
  10349. * returns a pointer to the first iocbq in the list. If the function is unable
  10350. * to allocate an iocbq then it throw out the received frames that were not
  10351. * able to be described and return a pointer to the first iocbq. If unable to
  10352. * allocate any iocbqs (including the first) this function will return NULL.
  10353. **/
  10354. static struct lpfc_iocbq *
  10355. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10356. {
  10357. struct lpfc_dmabuf *d_buf, *n_buf;
  10358. struct lpfc_iocbq *first_iocbq, *iocbq;
  10359. struct fc_frame_header *fc_hdr;
  10360. uint32_t sid;
  10361. struct ulp_bde64 *pbde;
  10362. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10363. /* remove from receive buffer list */
  10364. list_del_init(&seq_dmabuf->hbuf.list);
  10365. lpfc_update_rcv_time_stamp(vport);
  10366. /* get the Remote Port's SID */
  10367. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10368. /* Get an iocbq struct to fill in. */
  10369. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10370. if (first_iocbq) {
  10371. /* Initialize the first IOCB. */
  10372. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10373. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10374. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10375. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10376. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10377. vport->vpi + vport->phba->vpi_base;
  10378. /* put the first buffer into the first IOCBq */
  10379. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10380. first_iocbq->context3 = NULL;
  10381. first_iocbq->iocb.ulpBdeCount = 1;
  10382. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10383. LPFC_DATA_BUF_SIZE;
  10384. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10385. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10386. bf_get(lpfc_rcqe_length,
  10387. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10388. }
  10389. iocbq = first_iocbq;
  10390. /*
  10391. * Each IOCBq can have two Buffers assigned, so go through the list
  10392. * of buffers for this sequence and save two buffers in each IOCBq
  10393. */
  10394. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10395. if (!iocbq) {
  10396. lpfc_in_buf_free(vport->phba, d_buf);
  10397. continue;
  10398. }
  10399. if (!iocbq->context3) {
  10400. iocbq->context3 = d_buf;
  10401. iocbq->iocb.ulpBdeCount++;
  10402. pbde = (struct ulp_bde64 *)
  10403. &iocbq->iocb.unsli3.sli3Words[4];
  10404. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10405. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10406. bf_get(lpfc_rcqe_length,
  10407. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10408. } else {
  10409. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10410. if (!iocbq) {
  10411. if (first_iocbq) {
  10412. first_iocbq->iocb.ulpStatus =
  10413. IOSTAT_FCP_RSP_ERROR;
  10414. first_iocbq->iocb.un.ulpWord[4] =
  10415. IOERR_NO_RESOURCES;
  10416. }
  10417. lpfc_in_buf_free(vport->phba, d_buf);
  10418. continue;
  10419. }
  10420. iocbq->context2 = d_buf;
  10421. iocbq->context3 = NULL;
  10422. iocbq->iocb.ulpBdeCount = 1;
  10423. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10424. LPFC_DATA_BUF_SIZE;
  10425. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10426. bf_get(lpfc_rcqe_length,
  10427. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10428. iocbq->iocb.un.rcvels.remoteID = sid;
  10429. list_add_tail(&iocbq->list, &first_iocbq->list);
  10430. }
  10431. }
  10432. return first_iocbq;
  10433. }
  10434. static void
  10435. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10436. struct hbq_dmabuf *seq_dmabuf)
  10437. {
  10438. struct fc_frame_header *fc_hdr;
  10439. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10440. struct lpfc_hba *phba = vport->phba;
  10441. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10442. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10443. if (!iocbq) {
  10444. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10445. "2707 Ring %d handler: Failed to allocate "
  10446. "iocb Rctl x%x Type x%x received\n",
  10447. LPFC_ELS_RING,
  10448. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10449. return;
  10450. }
  10451. if (!lpfc_complete_unsol_iocb(phba,
  10452. &phba->sli.ring[LPFC_ELS_RING],
  10453. iocbq, fc_hdr->fh_r_ctl,
  10454. fc_hdr->fh_type))
  10455. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10456. "2540 Ring %d handler: unexpected Rctl "
  10457. "x%x Type x%x received\n",
  10458. LPFC_ELS_RING,
  10459. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10460. /* Free iocb created in lpfc_prep_seq */
  10461. list_for_each_entry_safe(curr_iocb, next_iocb,
  10462. &iocbq->list, list) {
  10463. list_del_init(&curr_iocb->list);
  10464. lpfc_sli_release_iocbq(phba, curr_iocb);
  10465. }
  10466. lpfc_sli_release_iocbq(phba, iocbq);
  10467. }
  10468. /**
  10469. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10470. * @phba: Pointer to HBA context object.
  10471. *
  10472. * This function is called with no lock held. This function processes all
  10473. * the received buffers and gives it to upper layers when a received buffer
  10474. * indicates that it is the final frame in the sequence. The interrupt
  10475. * service routine processes received buffers at interrupt contexts and adds
  10476. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10477. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10478. * appropriate receive function when the final frame in a sequence is received.
  10479. **/
  10480. void
  10481. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10482. struct hbq_dmabuf *dmabuf)
  10483. {
  10484. struct hbq_dmabuf *seq_dmabuf;
  10485. struct fc_frame_header *fc_hdr;
  10486. struct lpfc_vport *vport;
  10487. uint32_t fcfi;
  10488. /* Process each received buffer */
  10489. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10490. /* check to see if this a valid type of frame */
  10491. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10492. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10493. return;
  10494. }
  10495. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10496. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10497. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10498. /* throw out the frame */
  10499. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10500. return;
  10501. }
  10502. /* Handle the basic abort sequence (BA_ABTS) event */
  10503. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10504. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10505. return;
  10506. }
  10507. /* Link this frame */
  10508. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10509. if (!seq_dmabuf) {
  10510. /* unable to add frame to vport - throw it out */
  10511. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10512. return;
  10513. }
  10514. /* If not last frame in sequence continue processing frames. */
  10515. if (!lpfc_seq_complete(seq_dmabuf))
  10516. return;
  10517. /* Send the complete sequence to the upper layer protocol */
  10518. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10519. }
  10520. /**
  10521. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10522. * @phba: pointer to lpfc hba data structure.
  10523. *
  10524. * This routine is invoked to post rpi header templates to the
  10525. * HBA consistent with the SLI-4 interface spec. This routine
  10526. * posts a PAGE_SIZE memory region to the port to hold up to
  10527. * PAGE_SIZE modulo 64 rpi context headers.
  10528. *
  10529. * This routine does not require any locks. It's usage is expected
  10530. * to be driver load or reset recovery when the driver is
  10531. * sequential.
  10532. *
  10533. * Return codes
  10534. * 0 - successful
  10535. * EIO - The mailbox failed to complete successfully.
  10536. * When this error occurs, the driver is not guaranteed
  10537. * to have any rpi regions posted to the device and
  10538. * must either attempt to repost the regions or take a
  10539. * fatal error.
  10540. **/
  10541. int
  10542. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10543. {
  10544. struct lpfc_rpi_hdr *rpi_page;
  10545. uint32_t rc = 0;
  10546. /* Post all rpi memory regions to the port. */
  10547. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10548. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10549. if (rc != MBX_SUCCESS) {
  10550. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10551. "2008 Error %d posting all rpi "
  10552. "headers\n", rc);
  10553. rc = -EIO;
  10554. break;
  10555. }
  10556. }
  10557. return rc;
  10558. }
  10559. /**
  10560. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10561. * @phba: pointer to lpfc hba data structure.
  10562. * @rpi_page: pointer to the rpi memory region.
  10563. *
  10564. * This routine is invoked to post a single rpi header to the
  10565. * HBA consistent with the SLI-4 interface spec. This memory region
  10566. * maps up to 64 rpi context regions.
  10567. *
  10568. * Return codes
  10569. * 0 - successful
  10570. * ENOMEM - No available memory
  10571. * EIO - The mailbox failed to complete successfully.
  10572. **/
  10573. int
  10574. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10575. {
  10576. LPFC_MBOXQ_t *mboxq;
  10577. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10578. uint32_t rc = 0;
  10579. uint32_t mbox_tmo;
  10580. uint32_t shdr_status, shdr_add_status;
  10581. union lpfc_sli4_cfg_shdr *shdr;
  10582. /* The port is notified of the header region via a mailbox command. */
  10583. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10584. if (!mboxq) {
  10585. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10586. "2001 Unable to allocate memory for issuing "
  10587. "SLI_CONFIG_SPECIAL mailbox command\n");
  10588. return -ENOMEM;
  10589. }
  10590. /* Post all rpi memory regions to the port. */
  10591. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10592. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10593. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10594. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10595. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10596. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10597. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10598. hdr_tmpl, rpi_page->page_count);
  10599. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10600. rpi_page->start_rpi);
  10601. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10602. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10603. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10604. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10605. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10606. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10607. if (rc != MBX_TIMEOUT)
  10608. mempool_free(mboxq, phba->mbox_mem_pool);
  10609. if (shdr_status || shdr_add_status || rc) {
  10610. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10611. "2514 POST_RPI_HDR mailbox failed with "
  10612. "status x%x add_status x%x, mbx status x%x\n",
  10613. shdr_status, shdr_add_status, rc);
  10614. rc = -ENXIO;
  10615. }
  10616. return rc;
  10617. }
  10618. /**
  10619. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10620. * @phba: pointer to lpfc hba data structure.
  10621. *
  10622. * This routine is invoked to post rpi header templates to the
  10623. * HBA consistent with the SLI-4 interface spec. This routine
  10624. * posts a PAGE_SIZE memory region to the port to hold up to
  10625. * PAGE_SIZE modulo 64 rpi context headers.
  10626. *
  10627. * Returns
  10628. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10629. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10630. **/
  10631. int
  10632. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10633. {
  10634. int rpi;
  10635. uint16_t max_rpi, rpi_base, rpi_limit;
  10636. uint16_t rpi_remaining;
  10637. struct lpfc_rpi_hdr *rpi_hdr;
  10638. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10639. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10640. rpi_limit = phba->sli4_hba.next_rpi;
  10641. /*
  10642. * The valid rpi range is not guaranteed to be zero-based. Start
  10643. * the search at the rpi_base as reported by the port.
  10644. */
  10645. spin_lock_irq(&phba->hbalock);
  10646. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10647. if (rpi >= rpi_limit || rpi < rpi_base)
  10648. rpi = LPFC_RPI_ALLOC_ERROR;
  10649. else {
  10650. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10651. phba->sli4_hba.max_cfg_param.rpi_used++;
  10652. phba->sli4_hba.rpi_count++;
  10653. }
  10654. /*
  10655. * Don't try to allocate more rpi header regions if the device limit
  10656. * on available rpis max has been exhausted.
  10657. */
  10658. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10659. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10660. spin_unlock_irq(&phba->hbalock);
  10661. return rpi;
  10662. }
  10663. /*
  10664. * If the driver is running low on rpi resources, allocate another
  10665. * page now. Note that the next_rpi value is used because
  10666. * it represents how many are actually in use whereas max_rpi notes
  10667. * how many are supported max by the device.
  10668. */
  10669. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10670. phba->sli4_hba.rpi_count;
  10671. spin_unlock_irq(&phba->hbalock);
  10672. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10673. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10674. if (!rpi_hdr) {
  10675. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10676. "2002 Error Could not grow rpi "
  10677. "count\n");
  10678. } else {
  10679. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10680. }
  10681. }
  10682. return rpi;
  10683. }
  10684. /**
  10685. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10686. * @phba: pointer to lpfc hba data structure.
  10687. *
  10688. * This routine is invoked to release an rpi to the pool of
  10689. * available rpis maintained by the driver.
  10690. **/
  10691. void
  10692. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10693. {
  10694. spin_lock_irq(&phba->hbalock);
  10695. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10696. phba->sli4_hba.rpi_count--;
  10697. phba->sli4_hba.max_cfg_param.rpi_used--;
  10698. spin_unlock_irq(&phba->hbalock);
  10699. }
  10700. /**
  10701. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10702. * @phba: pointer to lpfc hba data structure.
  10703. *
  10704. * This routine is invoked to remove the memory region that
  10705. * provided rpi via a bitmask.
  10706. **/
  10707. void
  10708. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10709. {
  10710. kfree(phba->sli4_hba.rpi_bmask);
  10711. }
  10712. /**
  10713. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10714. * @phba: pointer to lpfc hba data structure.
  10715. *
  10716. * This routine is invoked to remove the memory region that
  10717. * provided rpi via a bitmask.
  10718. **/
  10719. int
  10720. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10721. {
  10722. LPFC_MBOXQ_t *mboxq;
  10723. struct lpfc_hba *phba = ndlp->phba;
  10724. int rc;
  10725. /* The port is notified of the header region via a mailbox command. */
  10726. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10727. if (!mboxq)
  10728. return -ENOMEM;
  10729. /* Post all rpi memory regions to the port. */
  10730. lpfc_resume_rpi(mboxq, ndlp);
  10731. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10732. if (rc == MBX_NOT_FINISHED) {
  10733. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10734. "2010 Resume RPI Mailbox failed "
  10735. "status %d, mbxStatus x%x\n", rc,
  10736. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10737. mempool_free(mboxq, phba->mbox_mem_pool);
  10738. return -EIO;
  10739. }
  10740. return 0;
  10741. }
  10742. /**
  10743. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10744. * @phba: pointer to lpfc hba data structure.
  10745. * @vpi: vpi value to activate with the port.
  10746. *
  10747. * This routine is invoked to activate a vpi with the
  10748. * port when the host intends to use vports with a
  10749. * nonzero vpi.
  10750. *
  10751. * Returns:
  10752. * 0 success
  10753. * -Evalue otherwise
  10754. **/
  10755. int
  10756. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10757. {
  10758. LPFC_MBOXQ_t *mboxq;
  10759. int rc = 0;
  10760. int retval = MBX_SUCCESS;
  10761. uint32_t mbox_tmo;
  10762. if (vpi == 0)
  10763. return -EINVAL;
  10764. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10765. if (!mboxq)
  10766. return -ENOMEM;
  10767. lpfc_init_vpi(phba, mboxq, vpi);
  10768. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10769. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10770. if (rc != MBX_SUCCESS) {
  10771. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10772. "2022 INIT VPI Mailbox failed "
  10773. "status %d, mbxStatus x%x\n", rc,
  10774. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10775. retval = -EIO;
  10776. }
  10777. if (rc != MBX_TIMEOUT)
  10778. mempool_free(mboxq, phba->mbox_mem_pool);
  10779. return retval;
  10780. }
  10781. /**
  10782. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10783. * @phba: pointer to lpfc hba data structure.
  10784. * @mboxq: Pointer to mailbox object.
  10785. *
  10786. * This routine is invoked to manually add a single FCF record. The caller
  10787. * must pass a completely initialized FCF_Record. This routine takes
  10788. * care of the nonembedded mailbox operations.
  10789. **/
  10790. static void
  10791. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10792. {
  10793. void *virt_addr;
  10794. union lpfc_sli4_cfg_shdr *shdr;
  10795. uint32_t shdr_status, shdr_add_status;
  10796. virt_addr = mboxq->sge_array->addr[0];
  10797. /* The IOCTL status is embedded in the mailbox subheader. */
  10798. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10799. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10800. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10801. if ((shdr_status || shdr_add_status) &&
  10802. (shdr_status != STATUS_FCF_IN_USE))
  10803. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10804. "2558 ADD_FCF_RECORD mailbox failed with "
  10805. "status x%x add_status x%x\n",
  10806. shdr_status, shdr_add_status);
  10807. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10808. }
  10809. /**
  10810. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10811. * @phba: pointer to lpfc hba data structure.
  10812. * @fcf_record: pointer to the initialized fcf record to add.
  10813. *
  10814. * This routine is invoked to manually add a single FCF record. The caller
  10815. * must pass a completely initialized FCF_Record. This routine takes
  10816. * care of the nonembedded mailbox operations.
  10817. **/
  10818. int
  10819. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10820. {
  10821. int rc = 0;
  10822. LPFC_MBOXQ_t *mboxq;
  10823. uint8_t *bytep;
  10824. void *virt_addr;
  10825. dma_addr_t phys_addr;
  10826. struct lpfc_mbx_sge sge;
  10827. uint32_t alloc_len, req_len;
  10828. uint32_t fcfindex;
  10829. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10830. if (!mboxq) {
  10831. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10832. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10833. return -ENOMEM;
  10834. }
  10835. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10836. sizeof(uint32_t);
  10837. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10838. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10839. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10840. req_len, LPFC_SLI4_MBX_NEMBED);
  10841. if (alloc_len < req_len) {
  10842. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10843. "2523 Allocated DMA memory size (x%x) is "
  10844. "less than the requested DMA memory "
  10845. "size (x%x)\n", alloc_len, req_len);
  10846. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10847. return -ENOMEM;
  10848. }
  10849. /*
  10850. * Get the first SGE entry from the non-embedded DMA memory. This
  10851. * routine only uses a single SGE.
  10852. */
  10853. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10854. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10855. virt_addr = mboxq->sge_array->addr[0];
  10856. /*
  10857. * Configure the FCF record for FCFI 0. This is the driver's
  10858. * hardcoded default and gets used in nonFIP mode.
  10859. */
  10860. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10861. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10862. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10863. /*
  10864. * Copy the fcf_index and the FCF Record Data. The data starts after
  10865. * the FCoE header plus word10. The data copy needs to be endian
  10866. * correct.
  10867. */
  10868. bytep += sizeof(uint32_t);
  10869. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10870. mboxq->vport = phba->pport;
  10871. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10872. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10873. if (rc == MBX_NOT_FINISHED) {
  10874. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10875. "2515 ADD_FCF_RECORD mailbox failed with "
  10876. "status 0x%x\n", rc);
  10877. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10878. rc = -EIO;
  10879. } else
  10880. rc = 0;
  10881. return rc;
  10882. }
  10883. /**
  10884. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10885. * @phba: pointer to lpfc hba data structure.
  10886. * @fcf_record: pointer to the fcf record to write the default data.
  10887. * @fcf_index: FCF table entry index.
  10888. *
  10889. * This routine is invoked to build the driver's default FCF record. The
  10890. * values used are hardcoded. This routine handles memory initialization.
  10891. *
  10892. **/
  10893. void
  10894. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10895. struct fcf_record *fcf_record,
  10896. uint16_t fcf_index)
  10897. {
  10898. memset(fcf_record, 0, sizeof(struct fcf_record));
  10899. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10900. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10901. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10902. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10903. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10904. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10905. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10906. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10907. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10908. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10909. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10910. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10911. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10912. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  10913. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10914. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10915. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10916. /* Set the VLAN bit map */
  10917. if (phba->valid_vlan) {
  10918. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10919. = 1 << (phba->vlan_id % 8);
  10920. }
  10921. }
  10922. /**
  10923. * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
  10924. * @phba: pointer to lpfc hba data structure.
  10925. * @fcf_index: FCF table entry offset.
  10926. *
  10927. * This routine is invoked to read up to @fcf_num of FCF record from the
  10928. * device starting with the given @fcf_index.
  10929. **/
  10930. int
  10931. lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
  10932. {
  10933. int rc = 0, error;
  10934. LPFC_MBOXQ_t *mboxq;
  10935. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  10936. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10937. if (!mboxq) {
  10938. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10939. "2000 Failed to allocate mbox for "
  10940. "READ_FCF cmd\n");
  10941. error = -ENOMEM;
  10942. goto fail_fcfscan;
  10943. }
  10944. /* Construct the read FCF record mailbox command */
  10945. rc = lpfc_sli4_mbx_read_fcf_record(phba, mboxq, fcf_index);
  10946. if (rc) {
  10947. error = -EINVAL;
  10948. goto fail_fcfscan;
  10949. }
  10950. /* Issue the mailbox command asynchronously */
  10951. mboxq->vport = phba->pport;
  10952. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
  10953. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10954. if (rc == MBX_NOT_FINISHED)
  10955. error = -EIO;
  10956. else {
  10957. spin_lock_irq(&phba->hbalock);
  10958. phba->hba_flag |= FCF_DISC_INPROGRESS;
  10959. spin_unlock_irq(&phba->hbalock);
  10960. error = 0;
  10961. }
  10962. fail_fcfscan:
  10963. if (error) {
  10964. if (mboxq)
  10965. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10966. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  10967. spin_lock_irq(&phba->hbalock);
  10968. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  10969. spin_unlock_irq(&phba->hbalock);
  10970. }
  10971. return error;
  10972. }
  10973. /**
  10974. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  10975. * @phba: pointer to lpfc hba data structure.
  10976. *
  10977. * This routine is the completion routine for the rediscover FCF table mailbox
  10978. * command. If the mailbox command returned failure, it will try to stop the
  10979. * FCF rediscover wait timer.
  10980. **/
  10981. void
  10982. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  10983. {
  10984. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  10985. uint32_t shdr_status, shdr_add_status;
  10986. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  10987. shdr_status = bf_get(lpfc_mbox_hdr_status,
  10988. &redisc_fcf->header.cfg_shdr.response);
  10989. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  10990. &redisc_fcf->header.cfg_shdr.response);
  10991. if (shdr_status || shdr_add_status) {
  10992. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10993. "2746 Requesting for FCF rediscovery failed "
  10994. "status x%x add_status x%x\n",
  10995. shdr_status, shdr_add_status);
  10996. /*
  10997. * Request failed, last resort to re-try current
  10998. * registered FCF entry
  10999. */
  11000. lpfc_retry_pport_discovery(phba);
  11001. } else
  11002. /*
  11003. * Start FCF rediscovery wait timer for pending FCF
  11004. * before rescan FCF record table.
  11005. */
  11006. lpfc_fcf_redisc_wait_start_timer(phba);
  11007. mempool_free(mbox, phba->mbox_mem_pool);
  11008. }
  11009. /**
  11010. * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
  11011. * @phba: pointer to lpfc hba data structure.
  11012. *
  11013. * This routine is invoked to request for rediscovery of the entire FCF table
  11014. * by the port.
  11015. **/
  11016. int
  11017. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11018. {
  11019. LPFC_MBOXQ_t *mbox;
  11020. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11021. int rc, length;
  11022. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11023. if (!mbox) {
  11024. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11025. "2745 Failed to allocate mbox for "
  11026. "requesting FCF rediscover.\n");
  11027. return -ENOMEM;
  11028. }
  11029. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11030. sizeof(struct lpfc_sli4_cfg_mhdr));
  11031. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11032. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11033. length, LPFC_SLI4_MBX_EMBED);
  11034. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11035. /* Set count to 0 for invalidating the entire FCF database */
  11036. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11037. /* Issue the mailbox command asynchronously */
  11038. mbox->vport = phba->pport;
  11039. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11040. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11041. if (rc == MBX_NOT_FINISHED) {
  11042. mempool_free(mbox, phba->mbox_mem_pool);
  11043. return -EIO;
  11044. }
  11045. return 0;
  11046. }
  11047. /**
  11048. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11049. * @phba: pointer to lpfc hba data structure.
  11050. *
  11051. * This function read region 23 and parse TLV for port status to
  11052. * decide if the user disaled the port. If the TLV indicates the
  11053. * port is disabled, the hba_flag is set accordingly.
  11054. **/
  11055. void
  11056. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11057. {
  11058. LPFC_MBOXQ_t *pmb = NULL;
  11059. MAILBOX_t *mb;
  11060. uint8_t *rgn23_data = NULL;
  11061. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11062. int rc;
  11063. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11064. if (!pmb) {
  11065. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11066. "2600 lpfc_sli_read_serdes_param failed to"
  11067. " allocate mailbox memory\n");
  11068. goto out;
  11069. }
  11070. mb = &pmb->u.mb;
  11071. /* Get adapter Region 23 data */
  11072. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11073. if (!rgn23_data)
  11074. goto out;
  11075. do {
  11076. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11077. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11078. if (rc != MBX_SUCCESS) {
  11079. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11080. "2601 lpfc_sli_read_link_ste failed to"
  11081. " read config region 23 rc 0x%x Status 0x%x\n",
  11082. rc, mb->mbxStatus);
  11083. mb->un.varDmp.word_cnt = 0;
  11084. }
  11085. /*
  11086. * dump mem may return a zero when finished or we got a
  11087. * mailbox error, either way we are done.
  11088. */
  11089. if (mb->un.varDmp.word_cnt == 0)
  11090. break;
  11091. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11092. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11093. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11094. rgn23_data + offset,
  11095. mb->un.varDmp.word_cnt);
  11096. offset += mb->un.varDmp.word_cnt;
  11097. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11098. data_size = offset;
  11099. offset = 0;
  11100. if (!data_size)
  11101. goto out;
  11102. /* Check the region signature first */
  11103. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11104. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11105. "2619 Config region 23 has bad signature\n");
  11106. goto out;
  11107. }
  11108. offset += 4;
  11109. /* Check the data structure version */
  11110. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11111. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11112. "2620 Config region 23 has bad version\n");
  11113. goto out;
  11114. }
  11115. offset += 4;
  11116. /* Parse TLV entries in the region */
  11117. while (offset < data_size) {
  11118. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11119. break;
  11120. /*
  11121. * If the TLV is not driver specific TLV or driver id is
  11122. * not linux driver id, skip the record.
  11123. */
  11124. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11125. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11126. (rgn23_data[offset + 3] != 0)) {
  11127. offset += rgn23_data[offset + 1] * 4 + 4;
  11128. continue;
  11129. }
  11130. /* Driver found a driver specific TLV in the config region */
  11131. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11132. offset += 4;
  11133. tlv_offset = 0;
  11134. /*
  11135. * Search for configured port state sub-TLV.
  11136. */
  11137. while ((offset < data_size) &&
  11138. (tlv_offset < sub_tlv_len)) {
  11139. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11140. offset += 4;
  11141. tlv_offset += 4;
  11142. break;
  11143. }
  11144. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11145. offset += rgn23_data[offset + 1] * 4 + 4;
  11146. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11147. continue;
  11148. }
  11149. /* This HBA contains PORT_STE configured */
  11150. if (!rgn23_data[offset + 2])
  11151. phba->hba_flag |= LINK_DISABLED;
  11152. goto out;
  11153. }
  11154. }
  11155. out:
  11156. if (pmb)
  11157. mempool_free(pmb, phba->mbox_mem_pool);
  11158. kfree(rgn23_data);
  11159. return;
  11160. }
  11161. /**
  11162. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11163. * @vport: pointer to vport data structure.
  11164. *
  11165. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11166. * and REG_VPI mailbox commands associated with the vport. This function
  11167. * is called when driver want to restart discovery of the vport due to
  11168. * a Clear Virtual Link event.
  11169. **/
  11170. void
  11171. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11172. {
  11173. struct lpfc_hba *phba = vport->phba;
  11174. LPFC_MBOXQ_t *mb, *nextmb;
  11175. struct lpfc_dmabuf *mp;
  11176. spin_lock_irq(&phba->hbalock);
  11177. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11178. if (mb->vport != vport)
  11179. continue;
  11180. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11181. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11182. continue;
  11183. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11184. mp = (struct lpfc_dmabuf *) (mb->context1);
  11185. if (mp) {
  11186. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11187. kfree(mp);
  11188. }
  11189. }
  11190. list_del(&mb->list);
  11191. mempool_free(mb, phba->mbox_mem_pool);
  11192. }
  11193. mb = phba->sli.mbox_active;
  11194. if (mb && (mb->vport == vport)) {
  11195. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11196. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11197. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11198. }
  11199. spin_unlock_irq(&phba->hbalock);
  11200. }