lpfc_sli.c 375 KB

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