lpfc_sli.c 396 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static IOCB_t *
  63. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  64. {
  65. return &iocbq->iocb;
  66. }
  67. /**
  68. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  69. * @q: The Work Queue to operate on.
  70. * @wqe: The work Queue Entry to put on the Work queue.
  71. *
  72. * This routine will copy the contents of @wqe to the next available entry on
  73. * the @q. This function will then ring the Work Queue Doorbell to signal the
  74. * HBA to start processing the Work Queue Entry. This function returns 0 if
  75. * successful. If no entries are available on @q then this function will return
  76. * -ENOMEM.
  77. * The caller is expected to hold the hbalock when calling this routine.
  78. **/
  79. static uint32_t
  80. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  81. {
  82. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  83. struct lpfc_register doorbell;
  84. uint32_t host_index;
  85. /* If the host has not yet processed the next entry then we are done */
  86. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  87. return -ENOMEM;
  88. /* set consumption flag every once in a while */
  89. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  90. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  91. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  92. /* Update the host index before invoking device */
  93. host_index = q->host_index;
  94. q->host_index = ((q->host_index + 1) % q->entry_count);
  95. /* Ring Doorbell */
  96. doorbell.word0 = 0;
  97. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  98. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  99. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  100. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  101. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  102. return 0;
  103. }
  104. /**
  105. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  106. * @q: The Work Queue to operate on.
  107. * @index: The index to advance the hba index to.
  108. *
  109. * This routine will update the HBA index of a queue to reflect consumption of
  110. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  111. * an entry the host calls this function to update the queue's internal
  112. * pointers. This routine returns the number of entries that were consumed by
  113. * the HBA.
  114. **/
  115. static uint32_t
  116. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  117. {
  118. uint32_t released = 0;
  119. if (q->hba_index == index)
  120. return 0;
  121. do {
  122. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  123. released++;
  124. } while (q->hba_index != index);
  125. return released;
  126. }
  127. /**
  128. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  129. * @q: The Mailbox Queue to operate on.
  130. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  131. *
  132. * This routine will copy the contents of @mqe to the next available entry on
  133. * the @q. This function will then ring the Work Queue Doorbell to signal the
  134. * HBA to start processing the Work Queue Entry. This function returns 0 if
  135. * successful. If no entries are available on @q then this function will return
  136. * -ENOMEM.
  137. * The caller is expected to hold the hbalock when calling this routine.
  138. **/
  139. static uint32_t
  140. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  141. {
  142. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  143. struct lpfc_register doorbell;
  144. uint32_t host_index;
  145. /* If the host has not yet processed the next entry then we are done */
  146. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  147. return -ENOMEM;
  148. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  149. /* Save off the mailbox pointer for completion */
  150. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  151. /* Update the host index before invoking device */
  152. host_index = q->host_index;
  153. q->host_index = ((q->host_index + 1) % q->entry_count);
  154. /* Ring Doorbell */
  155. doorbell.word0 = 0;
  156. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  157. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  158. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  159. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  160. return 0;
  161. }
  162. /**
  163. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  164. * @q: The Mailbox Queue to operate on.
  165. *
  166. * This routine will update the HBA index of a queue to reflect consumption of
  167. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  168. * an entry the host calls this function to update the queue's internal
  169. * pointers. This routine returns the number of entries that were consumed by
  170. * the HBA.
  171. **/
  172. static uint32_t
  173. lpfc_sli4_mq_release(struct lpfc_queue *q)
  174. {
  175. /* Clear the mailbox pointer for completion */
  176. q->phba->mbox = NULL;
  177. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  178. return 1;
  179. }
  180. /**
  181. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  182. * @q: The Event Queue to get the first valid EQE from
  183. *
  184. * This routine will get the first valid Event Queue Entry from @q, update
  185. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  186. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  187. * processed, but not popped back to the HBA then this routine will return NULL.
  188. **/
  189. static struct lpfc_eqe *
  190. lpfc_sli4_eq_get(struct lpfc_queue *q)
  191. {
  192. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  193. /* If the next EQE is not valid then we are done */
  194. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  195. return NULL;
  196. /* If the host has not yet processed the next entry then we are done */
  197. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  198. return NULL;
  199. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  200. return eqe;
  201. }
  202. /**
  203. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  204. * @q: The Event Queue that the host has completed processing for.
  205. * @arm: Indicates whether the host wants to arms this CQ.
  206. *
  207. * This routine will mark all Event Queue Entries on @q, from the last
  208. * known completed entry to the last entry that was processed, as completed
  209. * by clearing the valid bit for each completion queue entry. Then it will
  210. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  211. * The internal host index in the @q will be updated by this routine to indicate
  212. * that the host has finished processing the entries. The @arm parameter
  213. * indicates that the queue should be rearmed when ringing the doorbell.
  214. *
  215. * This function will return the number of EQEs that were popped.
  216. **/
  217. uint32_t
  218. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  219. {
  220. uint32_t released = 0;
  221. struct lpfc_eqe *temp_eqe;
  222. struct lpfc_register doorbell;
  223. /* while there are valid entries */
  224. while (q->hba_index != q->host_index) {
  225. temp_eqe = q->qe[q->host_index].eqe;
  226. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  227. released++;
  228. q->host_index = ((q->host_index + 1) % q->entry_count);
  229. }
  230. if (unlikely(released == 0 && !arm))
  231. return 0;
  232. /* ring doorbell for number popped */
  233. doorbell.word0 = 0;
  234. if (arm) {
  235. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  236. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  237. }
  238. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  239. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  240. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  241. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  242. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  243. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  244. readl(q->phba->sli4_hba.EQCQDBregaddr);
  245. return released;
  246. }
  247. /**
  248. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  249. * @q: The Completion Queue to get the first valid CQE from
  250. *
  251. * This routine will get the first valid Completion Queue Entry from @q, update
  252. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  253. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  254. * processed, but not popped back to the HBA then this routine will return NULL.
  255. **/
  256. static struct lpfc_cqe *
  257. lpfc_sli4_cq_get(struct lpfc_queue *q)
  258. {
  259. struct lpfc_cqe *cqe;
  260. /* If the next CQE is not valid then we are done */
  261. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  262. return NULL;
  263. /* If the host has not yet processed the next entry then we are done */
  264. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  265. return NULL;
  266. cqe = q->qe[q->hba_index].cqe;
  267. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  268. return cqe;
  269. }
  270. /**
  271. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  272. * @q: The Completion Queue that the host has completed processing for.
  273. * @arm: Indicates whether the host wants to arms this CQ.
  274. *
  275. * This routine will mark all Completion queue entries on @q, from the last
  276. * known completed entry to the last entry that was processed, as completed
  277. * by clearing the valid bit for each completion queue entry. Then it will
  278. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  279. * The internal host index in the @q will be updated by this routine to indicate
  280. * that the host has finished processing the entries. The @arm parameter
  281. * indicates that the queue should be rearmed when ringing the doorbell.
  282. *
  283. * This function will return the number of CQEs that were released.
  284. **/
  285. uint32_t
  286. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  287. {
  288. uint32_t released = 0;
  289. struct lpfc_cqe *temp_qe;
  290. struct lpfc_register doorbell;
  291. /* while there are valid entries */
  292. while (q->hba_index != q->host_index) {
  293. temp_qe = q->qe[q->host_index].cqe;
  294. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  295. released++;
  296. q->host_index = ((q->host_index + 1) % q->entry_count);
  297. }
  298. if (unlikely(released == 0 && !arm))
  299. return 0;
  300. /* ring doorbell for number popped */
  301. doorbell.word0 = 0;
  302. if (arm)
  303. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  304. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  305. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  306. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  307. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  308. return released;
  309. }
  310. /**
  311. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  312. * @q: The Header Receive Queue to operate on.
  313. * @wqe: The Receive Queue Entry to put on the Receive queue.
  314. *
  315. * This routine will copy the contents of @wqe to the next available entry on
  316. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  317. * HBA to start processing the Receive Queue Entry. This function returns the
  318. * index that the rqe was copied to if successful. If no entries are available
  319. * on @q then this function will return -ENOMEM.
  320. * The caller is expected to hold the hbalock when calling this routine.
  321. **/
  322. static int
  323. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  324. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  325. {
  326. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  327. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  328. struct lpfc_register doorbell;
  329. int put_index = hq->host_index;
  330. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  331. return -EINVAL;
  332. if (hq->host_index != dq->host_index)
  333. return -EINVAL;
  334. /* If the host has not yet processed the next entry then we are done */
  335. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  336. return -EBUSY;
  337. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  338. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  339. /* Update the host index to point to the next slot */
  340. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  341. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  342. /* Ring The Header Receive Queue Doorbell */
  343. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  344. doorbell.word0 = 0;
  345. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  346. LPFC_RQ_POST_BATCH);
  347. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  348. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  349. }
  350. return put_index;
  351. }
  352. /**
  353. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  354. * @q: The Header Receive Queue to operate on.
  355. *
  356. * This routine will update the HBA index of a queue to reflect consumption of
  357. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  358. * consumed an entry the host calls this function to update the queue's
  359. * internal pointers. This routine returns the number of entries that were
  360. * consumed by the HBA.
  361. **/
  362. static uint32_t
  363. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  364. {
  365. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  366. return 0;
  367. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  368. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  369. return 1;
  370. }
  371. /**
  372. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  373. * @phba: Pointer to HBA context object.
  374. * @pring: Pointer to driver SLI ring object.
  375. *
  376. * This function returns pointer to next command iocb entry
  377. * in the command ring. The caller must hold hbalock to prevent
  378. * other threads consume the next command iocb.
  379. * SLI-2/SLI-3 provide different sized iocbs.
  380. **/
  381. static inline IOCB_t *
  382. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  383. {
  384. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  385. pring->cmdidx * phba->iocb_cmd_size);
  386. }
  387. /**
  388. * lpfc_resp_iocb - Get next response iocb entry in the ring
  389. * @phba: Pointer to HBA context object.
  390. * @pring: Pointer to driver SLI ring object.
  391. *
  392. * This function returns pointer to next response iocb entry
  393. * in the response ring. The caller must hold hbalock to make sure
  394. * that no other thread consume the next response iocb.
  395. * SLI-2/SLI-3 provide different sized iocbs.
  396. **/
  397. static inline IOCB_t *
  398. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  399. {
  400. return (IOCB_t *) (((char *) pring->rspringaddr) +
  401. pring->rspidx * phba->iocb_rsp_size);
  402. }
  403. /**
  404. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  405. * @phba: Pointer to HBA context object.
  406. *
  407. * This function is called with hbalock held. This function
  408. * allocates a new driver iocb object from the iocb pool. If the
  409. * allocation is successful, it returns pointer to the newly
  410. * allocated iocb object else it returns NULL.
  411. **/
  412. static struct lpfc_iocbq *
  413. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  414. {
  415. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  416. struct lpfc_iocbq * iocbq = NULL;
  417. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  418. if (iocbq)
  419. phba->iocb_cnt++;
  420. if (phba->iocb_cnt > phba->iocb_max)
  421. phba->iocb_max = phba->iocb_cnt;
  422. return iocbq;
  423. }
  424. /**
  425. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  426. * @phba: Pointer to HBA context object.
  427. * @xritag: XRI value.
  428. *
  429. * This function clears the sglq pointer from the array of acive
  430. * sglq's. The xritag that is passed in is used to index into the
  431. * array. Before the xritag can be used it needs to be adjusted
  432. * by subtracting the xribase.
  433. *
  434. * Returns sglq ponter = success, NULL = Failure.
  435. **/
  436. static struct lpfc_sglq *
  437. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  438. {
  439. uint16_t adj_xri;
  440. struct lpfc_sglq *sglq;
  441. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  442. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  443. return NULL;
  444. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  445. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  446. return sglq;
  447. }
  448. /**
  449. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  450. * @phba: Pointer to HBA context object.
  451. * @xritag: XRI value.
  452. *
  453. * This function returns the sglq pointer from the array of acive
  454. * sglq's. The xritag that is passed in is used to index into the
  455. * array. Before the xritag can be used it needs to be adjusted
  456. * by subtracting the xribase.
  457. *
  458. * Returns sglq ponter = success, NULL = Failure.
  459. **/
  460. struct lpfc_sglq *
  461. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  462. {
  463. uint16_t adj_xri;
  464. struct lpfc_sglq *sglq;
  465. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  466. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  467. return NULL;
  468. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  469. return sglq;
  470. }
  471. /**
  472. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  473. * @phba: Pointer to HBA context object.
  474. *
  475. * This function is called with hbalock held. This function
  476. * Gets a new driver sglq object from the sglq list. If the
  477. * list is not empty then it is successful, it returns pointer to the newly
  478. * allocated sglq object else it returns NULL.
  479. **/
  480. static struct lpfc_sglq *
  481. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  482. {
  483. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  484. struct lpfc_sglq *sglq = NULL;
  485. uint16_t adj_xri;
  486. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  487. if (!sglq)
  488. return NULL;
  489. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  490. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  491. sglq->state = SGL_ALLOCATED;
  492. return sglq;
  493. }
  494. /**
  495. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  496. * @phba: Pointer to HBA context object.
  497. *
  498. * This function is called with no lock held. This function
  499. * allocates a new driver iocb object from the iocb pool. If the
  500. * allocation is successful, it returns pointer to the newly
  501. * allocated iocb object else it returns NULL.
  502. **/
  503. struct lpfc_iocbq *
  504. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  505. {
  506. struct lpfc_iocbq * iocbq = NULL;
  507. unsigned long iflags;
  508. spin_lock_irqsave(&phba->hbalock, iflags);
  509. iocbq = __lpfc_sli_get_iocbq(phba);
  510. spin_unlock_irqrestore(&phba->hbalock, iflags);
  511. return iocbq;
  512. }
  513. /**
  514. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  515. * @phba: Pointer to HBA context object.
  516. * @iocbq: Pointer to driver iocb object.
  517. *
  518. * This function is called with hbalock held to release driver
  519. * iocb object to the iocb pool. The iotag in the iocb object
  520. * does not change for each use of the iocb object. This function
  521. * clears all other fields of the iocb object when it is freed.
  522. * The sqlq structure that holds the xritag and phys and virtual
  523. * mappings for the scatter gather list is retrieved from the
  524. * active array of sglq. The get of the sglq pointer also clears
  525. * the entry in the array. If the status of the IO indiactes that
  526. * this IO was aborted then the sglq entry it put on the
  527. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  528. * IO has good status or fails for any other reason then the sglq
  529. * entry is added to the free list (lpfc_sgl_list).
  530. **/
  531. static void
  532. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  533. {
  534. struct lpfc_sglq *sglq;
  535. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  536. unsigned long iflag = 0;
  537. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  538. if (iocbq->sli4_xritag == NO_XRI)
  539. sglq = NULL;
  540. else
  541. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  542. if (sglq) {
  543. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  544. (sglq->state != SGL_XRI_ABORTED)) {
  545. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  546. iflag);
  547. list_add(&sglq->list,
  548. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  549. spin_unlock_irqrestore(
  550. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  551. } else {
  552. sglq->state = SGL_FREED;
  553. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  554. /* Check if TXQ queue needs to be serviced */
  555. if (pring->txq_cnt) {
  556. spin_lock_irqsave(
  557. &phba->pport->work_port_lock, iflag);
  558. phba->pport->work_port_events |=
  559. WORKER_SERVICE_TXQ;
  560. lpfc_worker_wake_up(phba);
  561. spin_unlock_irqrestore(
  562. &phba->pport->work_port_lock, iflag);
  563. }
  564. }
  565. }
  566. /*
  567. * Clean all volatile data fields, preserve iotag and node struct.
  568. */
  569. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  570. iocbq->sli4_xritag = NO_XRI;
  571. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  572. }
  573. /**
  574. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  575. * @phba: Pointer to HBA context object.
  576. * @iocbq: Pointer to driver iocb object.
  577. *
  578. * This function is called with hbalock held to release driver
  579. * iocb object to the iocb pool. The iotag in the iocb object
  580. * does not change for each use of the iocb object. This function
  581. * clears all other fields of the iocb object when it is freed.
  582. **/
  583. static void
  584. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  585. {
  586. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  587. /*
  588. * Clean all volatile data fields, preserve iotag and node struct.
  589. */
  590. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  591. iocbq->sli4_xritag = NO_XRI;
  592. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  593. }
  594. /**
  595. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  596. * @phba: Pointer to HBA context object.
  597. * @iocbq: Pointer to driver iocb object.
  598. *
  599. * This function is called with hbalock held to release driver
  600. * iocb object to the iocb pool. The iotag in the iocb object
  601. * does not change for each use of the iocb object. This function
  602. * clears all other fields of the iocb object when it is freed.
  603. **/
  604. static void
  605. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  606. {
  607. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  608. phba->iocb_cnt--;
  609. }
  610. /**
  611. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  612. * @phba: Pointer to HBA context object.
  613. * @iocbq: Pointer to driver iocb object.
  614. *
  615. * This function is called with no lock held to release the iocb to
  616. * iocb pool.
  617. **/
  618. void
  619. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  620. {
  621. unsigned long iflags;
  622. /*
  623. * Clean all volatile data fields, preserve iotag and node struct.
  624. */
  625. spin_lock_irqsave(&phba->hbalock, iflags);
  626. __lpfc_sli_release_iocbq(phba, iocbq);
  627. spin_unlock_irqrestore(&phba->hbalock, iflags);
  628. }
  629. /**
  630. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  631. * @phba: Pointer to HBA context object.
  632. * @iocblist: List of IOCBs.
  633. * @ulpstatus: ULP status in IOCB command field.
  634. * @ulpWord4: ULP word-4 in IOCB command field.
  635. *
  636. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  637. * on the list by invoking the complete callback function associated with the
  638. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  639. * fields.
  640. **/
  641. void
  642. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  643. uint32_t ulpstatus, uint32_t ulpWord4)
  644. {
  645. struct lpfc_iocbq *piocb;
  646. while (!list_empty(iocblist)) {
  647. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  648. if (!piocb->iocb_cmpl)
  649. lpfc_sli_release_iocbq(phba, piocb);
  650. else {
  651. piocb->iocb.ulpStatus = ulpstatus;
  652. piocb->iocb.un.ulpWord[4] = ulpWord4;
  653. (piocb->iocb_cmpl) (phba, piocb, piocb);
  654. }
  655. }
  656. return;
  657. }
  658. /**
  659. * lpfc_sli_iocb_cmd_type - Get the iocb type
  660. * @iocb_cmnd: iocb command code.
  661. *
  662. * This function is called by ring event handler function to get the iocb type.
  663. * This function translates the iocb command to an iocb command type used to
  664. * decide the final disposition of each completed IOCB.
  665. * The function returns
  666. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  667. * LPFC_SOL_IOCB if it is a solicited iocb completion
  668. * LPFC_ABORT_IOCB if it is an abort iocb
  669. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  670. *
  671. * The caller is not required to hold any lock.
  672. **/
  673. static lpfc_iocb_type
  674. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  675. {
  676. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  677. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  678. return 0;
  679. switch (iocb_cmnd) {
  680. case CMD_XMIT_SEQUENCE_CR:
  681. case CMD_XMIT_SEQUENCE_CX:
  682. case CMD_XMIT_BCAST_CN:
  683. case CMD_XMIT_BCAST_CX:
  684. case CMD_ELS_REQUEST_CR:
  685. case CMD_ELS_REQUEST_CX:
  686. case CMD_CREATE_XRI_CR:
  687. case CMD_CREATE_XRI_CX:
  688. case CMD_GET_RPI_CN:
  689. case CMD_XMIT_ELS_RSP_CX:
  690. case CMD_GET_RPI_CR:
  691. case CMD_FCP_IWRITE_CR:
  692. case CMD_FCP_IWRITE_CX:
  693. case CMD_FCP_IREAD_CR:
  694. case CMD_FCP_IREAD_CX:
  695. case CMD_FCP_ICMND_CR:
  696. case CMD_FCP_ICMND_CX:
  697. case CMD_FCP_TSEND_CX:
  698. case CMD_FCP_TRSP_CX:
  699. case CMD_FCP_TRECEIVE_CX:
  700. case CMD_FCP_AUTO_TRSP_CX:
  701. case CMD_ADAPTER_MSG:
  702. case CMD_ADAPTER_DUMP:
  703. case CMD_XMIT_SEQUENCE64_CR:
  704. case CMD_XMIT_SEQUENCE64_CX:
  705. case CMD_XMIT_BCAST64_CN:
  706. case CMD_XMIT_BCAST64_CX:
  707. case CMD_ELS_REQUEST64_CR:
  708. case CMD_ELS_REQUEST64_CX:
  709. case CMD_FCP_IWRITE64_CR:
  710. case CMD_FCP_IWRITE64_CX:
  711. case CMD_FCP_IREAD64_CR:
  712. case CMD_FCP_IREAD64_CX:
  713. case CMD_FCP_ICMND64_CR:
  714. case CMD_FCP_ICMND64_CX:
  715. case CMD_FCP_TSEND64_CX:
  716. case CMD_FCP_TRSP64_CX:
  717. case CMD_FCP_TRECEIVE64_CX:
  718. case CMD_GEN_REQUEST64_CR:
  719. case CMD_GEN_REQUEST64_CX:
  720. case CMD_XMIT_ELS_RSP64_CX:
  721. case DSSCMD_IWRITE64_CR:
  722. case DSSCMD_IWRITE64_CX:
  723. case DSSCMD_IREAD64_CR:
  724. case DSSCMD_IREAD64_CX:
  725. type = LPFC_SOL_IOCB;
  726. break;
  727. case CMD_ABORT_XRI_CN:
  728. case CMD_ABORT_XRI_CX:
  729. case CMD_CLOSE_XRI_CN:
  730. case CMD_CLOSE_XRI_CX:
  731. case CMD_XRI_ABORTED_CX:
  732. case CMD_ABORT_MXRI64_CN:
  733. case CMD_XMIT_BLS_RSP64_CX:
  734. type = LPFC_ABORT_IOCB;
  735. break;
  736. case CMD_RCV_SEQUENCE_CX:
  737. case CMD_RCV_ELS_REQ_CX:
  738. case CMD_RCV_SEQUENCE64_CX:
  739. case CMD_RCV_ELS_REQ64_CX:
  740. case CMD_ASYNC_STATUS:
  741. case CMD_IOCB_RCV_SEQ64_CX:
  742. case CMD_IOCB_RCV_ELS64_CX:
  743. case CMD_IOCB_RCV_CONT64_CX:
  744. case CMD_IOCB_RET_XRI64_CX:
  745. type = LPFC_UNSOL_IOCB;
  746. break;
  747. case CMD_IOCB_XMIT_MSEQ64_CR:
  748. case CMD_IOCB_XMIT_MSEQ64_CX:
  749. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  750. case CMD_IOCB_RCV_ELS_LIST64_CX:
  751. case CMD_IOCB_CLOSE_EXTENDED_CN:
  752. case CMD_IOCB_ABORT_EXTENDED_CN:
  753. case CMD_IOCB_RET_HBQE64_CN:
  754. case CMD_IOCB_FCP_IBIDIR64_CR:
  755. case CMD_IOCB_FCP_IBIDIR64_CX:
  756. case CMD_IOCB_FCP_ITASKMGT64_CX:
  757. case CMD_IOCB_LOGENTRY_CN:
  758. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  759. printk("%s - Unhandled SLI-3 Command x%x\n",
  760. __func__, iocb_cmnd);
  761. type = LPFC_UNKNOWN_IOCB;
  762. break;
  763. default:
  764. type = LPFC_UNKNOWN_IOCB;
  765. break;
  766. }
  767. return type;
  768. }
  769. /**
  770. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  771. * @phba: Pointer to HBA context object.
  772. *
  773. * This function is called from SLI initialization code
  774. * to configure every ring of the HBA's SLI interface. The
  775. * caller is not required to hold any lock. This function issues
  776. * a config_ring mailbox command for each ring.
  777. * This function returns zero if successful else returns a negative
  778. * error code.
  779. **/
  780. static int
  781. lpfc_sli_ring_map(struct lpfc_hba *phba)
  782. {
  783. struct lpfc_sli *psli = &phba->sli;
  784. LPFC_MBOXQ_t *pmb;
  785. MAILBOX_t *pmbox;
  786. int i, rc, ret = 0;
  787. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  788. if (!pmb)
  789. return -ENOMEM;
  790. pmbox = &pmb->u.mb;
  791. phba->link_state = LPFC_INIT_MBX_CMDS;
  792. for (i = 0; i < psli->num_rings; i++) {
  793. lpfc_config_ring(phba, i, pmb);
  794. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  795. if (rc != MBX_SUCCESS) {
  796. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  797. "0446 Adapter failed to init (%d), "
  798. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  799. "ring %d\n",
  800. rc, pmbox->mbxCommand,
  801. pmbox->mbxStatus, i);
  802. phba->link_state = LPFC_HBA_ERROR;
  803. ret = -ENXIO;
  804. break;
  805. }
  806. }
  807. mempool_free(pmb, phba->mbox_mem_pool);
  808. return ret;
  809. }
  810. /**
  811. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  812. * @phba: Pointer to HBA context object.
  813. * @pring: Pointer to driver SLI ring object.
  814. * @piocb: Pointer to the driver iocb object.
  815. *
  816. * This function is called with hbalock held. The function adds the
  817. * new iocb to txcmplq of the given ring. This function always returns
  818. * 0. If this function is called for ELS ring, this function checks if
  819. * there is a vport associated with the ELS command. This function also
  820. * starts els_tmofunc timer if this is an ELS command.
  821. **/
  822. static int
  823. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  824. struct lpfc_iocbq *piocb)
  825. {
  826. list_add_tail(&piocb->list, &pring->txcmplq);
  827. piocb->iocb_flag |= LPFC_IO_ON_Q;
  828. pring->txcmplq_cnt++;
  829. if (pring->txcmplq_cnt > pring->txcmplq_max)
  830. pring->txcmplq_max = pring->txcmplq_cnt;
  831. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  832. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  833. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  834. if (!piocb->vport)
  835. BUG();
  836. else
  837. mod_timer(&piocb->vport->els_tmofunc,
  838. jiffies + HZ * (phba->fc_ratov << 1));
  839. }
  840. return 0;
  841. }
  842. /**
  843. * lpfc_sli_ringtx_get - Get first element of the txq
  844. * @phba: Pointer to HBA context object.
  845. * @pring: Pointer to driver SLI ring object.
  846. *
  847. * This function is called with hbalock held to get next
  848. * iocb in txq of the given ring. If there is any iocb in
  849. * the txq, the function returns first iocb in the list after
  850. * removing the iocb from the list, else it returns NULL.
  851. **/
  852. struct lpfc_iocbq *
  853. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  854. {
  855. struct lpfc_iocbq *cmd_iocb;
  856. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  857. if (cmd_iocb != NULL)
  858. pring->txq_cnt--;
  859. return cmd_iocb;
  860. }
  861. /**
  862. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  863. * @phba: Pointer to HBA context object.
  864. * @pring: Pointer to driver SLI ring object.
  865. *
  866. * This function is called with hbalock held and the caller must post the
  867. * iocb without releasing the lock. If the caller releases the lock,
  868. * iocb slot returned by the function is not guaranteed to be available.
  869. * The function returns pointer to the next available iocb slot if there
  870. * is available slot in the ring, else it returns NULL.
  871. * If the get index of the ring is ahead of the put index, the function
  872. * will post an error attention event to the worker thread to take the
  873. * HBA to offline state.
  874. **/
  875. static IOCB_t *
  876. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  877. {
  878. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  879. uint32_t max_cmd_idx = pring->numCiocb;
  880. if ((pring->next_cmdidx == pring->cmdidx) &&
  881. (++pring->next_cmdidx >= max_cmd_idx))
  882. pring->next_cmdidx = 0;
  883. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  884. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  885. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  886. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  887. "0315 Ring %d issue: portCmdGet %d "
  888. "is bigger than cmd ring %d\n",
  889. pring->ringno,
  890. pring->local_getidx, max_cmd_idx);
  891. phba->link_state = LPFC_HBA_ERROR;
  892. /*
  893. * All error attention handlers are posted to
  894. * worker thread
  895. */
  896. phba->work_ha |= HA_ERATT;
  897. phba->work_hs = HS_FFER3;
  898. lpfc_worker_wake_up(phba);
  899. return NULL;
  900. }
  901. if (pring->local_getidx == pring->next_cmdidx)
  902. return NULL;
  903. }
  904. return lpfc_cmd_iocb(phba, pring);
  905. }
  906. /**
  907. * lpfc_sli_next_iotag - Get an iotag for the iocb
  908. * @phba: Pointer to HBA context object.
  909. * @iocbq: Pointer to driver iocb object.
  910. *
  911. * This function gets an iotag for the iocb. If there is no unused iotag and
  912. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  913. * array and assigns a new iotag.
  914. * The function returns the allocated iotag if successful, else returns zero.
  915. * Zero is not a valid iotag.
  916. * The caller is not required to hold any lock.
  917. **/
  918. uint16_t
  919. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  920. {
  921. struct lpfc_iocbq **new_arr;
  922. struct lpfc_iocbq **old_arr;
  923. size_t new_len;
  924. struct lpfc_sli *psli = &phba->sli;
  925. uint16_t iotag;
  926. spin_lock_irq(&phba->hbalock);
  927. iotag = psli->last_iotag;
  928. if(++iotag < psli->iocbq_lookup_len) {
  929. psli->last_iotag = iotag;
  930. psli->iocbq_lookup[iotag] = iocbq;
  931. spin_unlock_irq(&phba->hbalock);
  932. iocbq->iotag = iotag;
  933. return iotag;
  934. } else if (psli->iocbq_lookup_len < (0xffff
  935. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  936. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  937. spin_unlock_irq(&phba->hbalock);
  938. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  939. GFP_KERNEL);
  940. if (new_arr) {
  941. spin_lock_irq(&phba->hbalock);
  942. old_arr = psli->iocbq_lookup;
  943. if (new_len <= psli->iocbq_lookup_len) {
  944. /* highly unprobable case */
  945. kfree(new_arr);
  946. iotag = psli->last_iotag;
  947. if(++iotag < psli->iocbq_lookup_len) {
  948. psli->last_iotag = iotag;
  949. psli->iocbq_lookup[iotag] = iocbq;
  950. spin_unlock_irq(&phba->hbalock);
  951. iocbq->iotag = iotag;
  952. return iotag;
  953. }
  954. spin_unlock_irq(&phba->hbalock);
  955. return 0;
  956. }
  957. if (psli->iocbq_lookup)
  958. memcpy(new_arr, old_arr,
  959. ((psli->last_iotag + 1) *
  960. sizeof (struct lpfc_iocbq *)));
  961. psli->iocbq_lookup = new_arr;
  962. psli->iocbq_lookup_len = new_len;
  963. psli->last_iotag = iotag;
  964. psli->iocbq_lookup[iotag] = iocbq;
  965. spin_unlock_irq(&phba->hbalock);
  966. iocbq->iotag = iotag;
  967. kfree(old_arr);
  968. return iotag;
  969. }
  970. } else
  971. spin_unlock_irq(&phba->hbalock);
  972. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  973. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  974. psli->last_iotag);
  975. return 0;
  976. }
  977. /**
  978. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  979. * @phba: Pointer to HBA context object.
  980. * @pring: Pointer to driver SLI ring object.
  981. * @iocb: Pointer to iocb slot in the ring.
  982. * @nextiocb: Pointer to driver iocb object which need to be
  983. * posted to firmware.
  984. *
  985. * This function is called with hbalock held to post a new iocb to
  986. * the firmware. This function copies the new iocb to ring iocb slot and
  987. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  988. * a completion call back for this iocb else the function will free the
  989. * iocb object.
  990. **/
  991. static void
  992. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  993. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  994. {
  995. /*
  996. * Set up an iotag
  997. */
  998. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  999. if (pring->ringno == LPFC_ELS_RING) {
  1000. lpfc_debugfs_slow_ring_trc(phba,
  1001. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1002. *(((uint32_t *) &nextiocb->iocb) + 4),
  1003. *(((uint32_t *) &nextiocb->iocb) + 6),
  1004. *(((uint32_t *) &nextiocb->iocb) + 7));
  1005. }
  1006. /*
  1007. * Issue iocb command to adapter
  1008. */
  1009. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1010. wmb();
  1011. pring->stats.iocb_cmd++;
  1012. /*
  1013. * If there is no completion routine to call, we can release the
  1014. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1015. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1016. */
  1017. if (nextiocb->iocb_cmpl)
  1018. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1019. else
  1020. __lpfc_sli_release_iocbq(phba, nextiocb);
  1021. /*
  1022. * Let the HBA know what IOCB slot will be the next one the
  1023. * driver will put a command into.
  1024. */
  1025. pring->cmdidx = pring->next_cmdidx;
  1026. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1027. }
  1028. /**
  1029. * lpfc_sli_update_full_ring - Update the chip attention register
  1030. * @phba: Pointer to HBA context object.
  1031. * @pring: Pointer to driver SLI ring object.
  1032. *
  1033. * The caller is not required to hold any lock for calling this function.
  1034. * This function updates the chip attention bits for the ring to inform firmware
  1035. * that there are pending work to be done for this ring and requests an
  1036. * interrupt when there is space available in the ring. This function is
  1037. * called when the driver is unable to post more iocbs to the ring due
  1038. * to unavailability of space in the ring.
  1039. **/
  1040. static void
  1041. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1042. {
  1043. int ringno = pring->ringno;
  1044. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1045. wmb();
  1046. /*
  1047. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1048. * The HBA will tell us when an IOCB entry is available.
  1049. */
  1050. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1051. readl(phba->CAregaddr); /* flush */
  1052. pring->stats.iocb_cmd_full++;
  1053. }
  1054. /**
  1055. * lpfc_sli_update_ring - Update chip attention register
  1056. * @phba: Pointer to HBA context object.
  1057. * @pring: Pointer to driver SLI ring object.
  1058. *
  1059. * This function updates the chip attention register bit for the
  1060. * given ring to inform HBA that there is more work to be done
  1061. * in this ring. The caller is not required to hold any lock.
  1062. **/
  1063. static void
  1064. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1065. {
  1066. int ringno = pring->ringno;
  1067. /*
  1068. * Tell the HBA that there is work to do in this ring.
  1069. */
  1070. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1071. wmb();
  1072. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1073. readl(phba->CAregaddr); /* flush */
  1074. }
  1075. }
  1076. /**
  1077. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1078. * @phba: Pointer to HBA context object.
  1079. * @pring: Pointer to driver SLI ring object.
  1080. *
  1081. * This function is called with hbalock held to post pending iocbs
  1082. * in the txq to the firmware. This function is called when driver
  1083. * detects space available in the ring.
  1084. **/
  1085. static void
  1086. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1087. {
  1088. IOCB_t *iocb;
  1089. struct lpfc_iocbq *nextiocb;
  1090. /*
  1091. * Check to see if:
  1092. * (a) there is anything on the txq to send
  1093. * (b) link is up
  1094. * (c) link attention events can be processed (fcp ring only)
  1095. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1096. */
  1097. if (pring->txq_cnt &&
  1098. lpfc_is_link_up(phba) &&
  1099. (pring->ringno != phba->sli.fcp_ring ||
  1100. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1101. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1102. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1103. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1104. if (iocb)
  1105. lpfc_sli_update_ring(phba, pring);
  1106. else
  1107. lpfc_sli_update_full_ring(phba, pring);
  1108. }
  1109. return;
  1110. }
  1111. /**
  1112. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1113. * @phba: Pointer to HBA context object.
  1114. * @hbqno: HBQ number.
  1115. *
  1116. * This function is called with hbalock held to get the next
  1117. * available slot for the given HBQ. If there is free slot
  1118. * available for the HBQ it will return pointer to the next available
  1119. * HBQ entry else it will return NULL.
  1120. **/
  1121. static struct lpfc_hbq_entry *
  1122. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1123. {
  1124. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1125. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1126. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1127. hbqp->next_hbqPutIdx = 0;
  1128. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1129. uint32_t raw_index = phba->hbq_get[hbqno];
  1130. uint32_t getidx = le32_to_cpu(raw_index);
  1131. hbqp->local_hbqGetIdx = getidx;
  1132. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1133. lpfc_printf_log(phba, KERN_ERR,
  1134. LOG_SLI | LOG_VPORT,
  1135. "1802 HBQ %d: local_hbqGetIdx "
  1136. "%u is > than hbqp->entry_count %u\n",
  1137. hbqno, hbqp->local_hbqGetIdx,
  1138. hbqp->entry_count);
  1139. phba->link_state = LPFC_HBA_ERROR;
  1140. return NULL;
  1141. }
  1142. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1143. return NULL;
  1144. }
  1145. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1146. hbqp->hbqPutIdx;
  1147. }
  1148. /**
  1149. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1150. * @phba: Pointer to HBA context object.
  1151. *
  1152. * This function is called with no lock held to free all the
  1153. * hbq buffers while uninitializing the SLI interface. It also
  1154. * frees the HBQ buffers returned by the firmware but not yet
  1155. * processed by the upper layers.
  1156. **/
  1157. void
  1158. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1159. {
  1160. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1161. struct hbq_dmabuf *hbq_buf;
  1162. unsigned long flags;
  1163. int i, hbq_count;
  1164. uint32_t hbqno;
  1165. hbq_count = lpfc_sli_hbq_count();
  1166. /* Return all memory used by all HBQs */
  1167. spin_lock_irqsave(&phba->hbalock, flags);
  1168. for (i = 0; i < hbq_count; ++i) {
  1169. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1170. &phba->hbqs[i].hbq_buffer_list, list) {
  1171. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1172. list_del(&hbq_buf->dbuf.list);
  1173. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1174. }
  1175. phba->hbqs[i].buffer_count = 0;
  1176. }
  1177. /* Return all HBQ buffer that are in-fly */
  1178. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1179. list) {
  1180. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1181. list_del(&hbq_buf->dbuf.list);
  1182. if (hbq_buf->tag == -1) {
  1183. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1184. (phba, hbq_buf);
  1185. } else {
  1186. hbqno = hbq_buf->tag >> 16;
  1187. if (hbqno >= LPFC_MAX_HBQS)
  1188. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1189. (phba, hbq_buf);
  1190. else
  1191. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1192. hbq_buf);
  1193. }
  1194. }
  1195. /* Mark the HBQs not in use */
  1196. phba->hbq_in_use = 0;
  1197. spin_unlock_irqrestore(&phba->hbalock, flags);
  1198. }
  1199. /**
  1200. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1201. * @phba: Pointer to HBA context object.
  1202. * @hbqno: HBQ number.
  1203. * @hbq_buf: Pointer to HBQ buffer.
  1204. *
  1205. * This function is called with the hbalock held to post a
  1206. * hbq buffer to the firmware. If the function finds an empty
  1207. * slot in the HBQ, it will post the buffer. The function will return
  1208. * pointer to the hbq entry if it successfully post the buffer
  1209. * else it will return NULL.
  1210. **/
  1211. static int
  1212. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1213. struct hbq_dmabuf *hbq_buf)
  1214. {
  1215. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1216. }
  1217. /**
  1218. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1219. * @phba: Pointer to HBA context object.
  1220. * @hbqno: HBQ number.
  1221. * @hbq_buf: Pointer to HBQ buffer.
  1222. *
  1223. * This function is called with the hbalock held to post a hbq buffer to the
  1224. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1225. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1226. * it successfully post the buffer else it will return an error.
  1227. **/
  1228. static int
  1229. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1230. struct hbq_dmabuf *hbq_buf)
  1231. {
  1232. struct lpfc_hbq_entry *hbqe;
  1233. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1234. /* Get next HBQ entry slot to use */
  1235. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1236. if (hbqe) {
  1237. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1238. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1239. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1240. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1241. hbqe->bde.tus.f.bdeFlags = 0;
  1242. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1243. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1244. /* Sync SLIM */
  1245. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1246. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1247. /* flush */
  1248. readl(phba->hbq_put + hbqno);
  1249. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1250. return 0;
  1251. } else
  1252. return -ENOMEM;
  1253. }
  1254. /**
  1255. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1256. * @phba: Pointer to HBA context object.
  1257. * @hbqno: HBQ number.
  1258. * @hbq_buf: Pointer to HBQ buffer.
  1259. *
  1260. * This function is called with the hbalock held to post an RQE to the SLI4
  1261. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1262. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1263. **/
  1264. static int
  1265. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1266. struct hbq_dmabuf *hbq_buf)
  1267. {
  1268. int rc;
  1269. struct lpfc_rqe hrqe;
  1270. struct lpfc_rqe drqe;
  1271. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1272. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1273. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1274. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1275. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1276. &hrqe, &drqe);
  1277. if (rc < 0)
  1278. return rc;
  1279. hbq_buf->tag = rc;
  1280. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1281. return 0;
  1282. }
  1283. /* HBQ for ELS and CT traffic. */
  1284. static struct lpfc_hbq_init lpfc_els_hbq = {
  1285. .rn = 1,
  1286. .entry_count = 256,
  1287. .mask_count = 0,
  1288. .profile = 0,
  1289. .ring_mask = (1 << LPFC_ELS_RING),
  1290. .buffer_count = 0,
  1291. .init_count = 40,
  1292. .add_count = 40,
  1293. };
  1294. /* HBQ for the extra ring if needed */
  1295. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1296. .rn = 1,
  1297. .entry_count = 200,
  1298. .mask_count = 0,
  1299. .profile = 0,
  1300. .ring_mask = (1 << LPFC_EXTRA_RING),
  1301. .buffer_count = 0,
  1302. .init_count = 0,
  1303. .add_count = 5,
  1304. };
  1305. /* Array of HBQs */
  1306. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1307. &lpfc_els_hbq,
  1308. &lpfc_extra_hbq,
  1309. };
  1310. /**
  1311. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1312. * @phba: Pointer to HBA context object.
  1313. * @hbqno: HBQ number.
  1314. * @count: Number of HBQ buffers to be posted.
  1315. *
  1316. * This function is called with no lock held to post more hbq buffers to the
  1317. * given HBQ. The function returns the number of HBQ buffers successfully
  1318. * posted.
  1319. **/
  1320. static int
  1321. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1322. {
  1323. uint32_t i, posted = 0;
  1324. unsigned long flags;
  1325. struct hbq_dmabuf *hbq_buffer;
  1326. LIST_HEAD(hbq_buf_list);
  1327. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1328. return 0;
  1329. if ((phba->hbqs[hbqno].buffer_count + count) >
  1330. lpfc_hbq_defs[hbqno]->entry_count)
  1331. count = lpfc_hbq_defs[hbqno]->entry_count -
  1332. phba->hbqs[hbqno].buffer_count;
  1333. if (!count)
  1334. return 0;
  1335. /* Allocate HBQ entries */
  1336. for (i = 0; i < count; i++) {
  1337. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1338. if (!hbq_buffer)
  1339. break;
  1340. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1341. }
  1342. /* Check whether HBQ is still in use */
  1343. spin_lock_irqsave(&phba->hbalock, flags);
  1344. if (!phba->hbq_in_use)
  1345. goto err;
  1346. while (!list_empty(&hbq_buf_list)) {
  1347. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1348. dbuf.list);
  1349. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1350. (hbqno << 16));
  1351. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1352. phba->hbqs[hbqno].buffer_count++;
  1353. posted++;
  1354. } else
  1355. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1356. }
  1357. spin_unlock_irqrestore(&phba->hbalock, flags);
  1358. return posted;
  1359. err:
  1360. spin_unlock_irqrestore(&phba->hbalock, flags);
  1361. while (!list_empty(&hbq_buf_list)) {
  1362. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1363. dbuf.list);
  1364. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1365. }
  1366. return 0;
  1367. }
  1368. /**
  1369. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1370. * @phba: Pointer to HBA context object.
  1371. * @qno: HBQ number.
  1372. *
  1373. * This function posts more buffers to the HBQ. This function
  1374. * is called with no lock held. The function returns the number of HBQ entries
  1375. * successfully allocated.
  1376. **/
  1377. int
  1378. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1379. {
  1380. if (phba->sli_rev == LPFC_SLI_REV4)
  1381. return 0;
  1382. else
  1383. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1384. lpfc_hbq_defs[qno]->add_count);
  1385. }
  1386. /**
  1387. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1388. * @phba: Pointer to HBA context object.
  1389. * @qno: HBQ queue number.
  1390. *
  1391. * This function is called from SLI initialization code path with
  1392. * no lock held to post initial HBQ buffers to firmware. The
  1393. * function returns the number of HBQ entries successfully allocated.
  1394. **/
  1395. static int
  1396. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1397. {
  1398. if (phba->sli_rev == LPFC_SLI_REV4)
  1399. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1400. lpfc_hbq_defs[qno]->entry_count);
  1401. else
  1402. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1403. lpfc_hbq_defs[qno]->init_count);
  1404. }
  1405. /**
  1406. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1407. * @phba: Pointer to HBA context object.
  1408. * @hbqno: HBQ number.
  1409. *
  1410. * This function removes the first hbq buffer on an hbq list and returns a
  1411. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1412. **/
  1413. static struct hbq_dmabuf *
  1414. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1415. {
  1416. struct lpfc_dmabuf *d_buf;
  1417. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1418. if (!d_buf)
  1419. return NULL;
  1420. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1421. }
  1422. /**
  1423. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1424. * @phba: Pointer to HBA context object.
  1425. * @tag: Tag of the hbq buffer.
  1426. *
  1427. * This function is called with hbalock held. This function searches
  1428. * for the hbq buffer associated with the given tag in the hbq buffer
  1429. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1430. * it returns NULL.
  1431. **/
  1432. static struct hbq_dmabuf *
  1433. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1434. {
  1435. struct lpfc_dmabuf *d_buf;
  1436. struct hbq_dmabuf *hbq_buf;
  1437. uint32_t hbqno;
  1438. hbqno = tag >> 16;
  1439. if (hbqno >= LPFC_MAX_HBQS)
  1440. return NULL;
  1441. spin_lock_irq(&phba->hbalock);
  1442. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1443. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1444. if (hbq_buf->tag == tag) {
  1445. spin_unlock_irq(&phba->hbalock);
  1446. return hbq_buf;
  1447. }
  1448. }
  1449. spin_unlock_irq(&phba->hbalock);
  1450. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1451. "1803 Bad hbq tag. Data: x%x x%x\n",
  1452. tag, phba->hbqs[tag >> 16].buffer_count);
  1453. return NULL;
  1454. }
  1455. /**
  1456. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1457. * @phba: Pointer to HBA context object.
  1458. * @hbq_buffer: Pointer to HBQ buffer.
  1459. *
  1460. * This function is called with hbalock. This function gives back
  1461. * the hbq buffer to firmware. If the HBQ does not have space to
  1462. * post the buffer, it will free the buffer.
  1463. **/
  1464. void
  1465. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1466. {
  1467. uint32_t hbqno;
  1468. if (hbq_buffer) {
  1469. hbqno = hbq_buffer->tag >> 16;
  1470. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1471. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1472. }
  1473. }
  1474. /**
  1475. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1476. * @mbxCommand: mailbox command code.
  1477. *
  1478. * This function is called by the mailbox event handler function to verify
  1479. * that the completed mailbox command is a legitimate mailbox command. If the
  1480. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1481. * and the mailbox event handler will take the HBA offline.
  1482. **/
  1483. static int
  1484. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1485. {
  1486. uint8_t ret;
  1487. switch (mbxCommand) {
  1488. case MBX_LOAD_SM:
  1489. case MBX_READ_NV:
  1490. case MBX_WRITE_NV:
  1491. case MBX_WRITE_VPARMS:
  1492. case MBX_RUN_BIU_DIAG:
  1493. case MBX_INIT_LINK:
  1494. case MBX_DOWN_LINK:
  1495. case MBX_CONFIG_LINK:
  1496. case MBX_CONFIG_RING:
  1497. case MBX_RESET_RING:
  1498. case MBX_READ_CONFIG:
  1499. case MBX_READ_RCONFIG:
  1500. case MBX_READ_SPARM:
  1501. case MBX_READ_STATUS:
  1502. case MBX_READ_RPI:
  1503. case MBX_READ_XRI:
  1504. case MBX_READ_REV:
  1505. case MBX_READ_LNK_STAT:
  1506. case MBX_REG_LOGIN:
  1507. case MBX_UNREG_LOGIN:
  1508. case MBX_READ_LA:
  1509. case MBX_CLEAR_LA:
  1510. case MBX_DUMP_MEMORY:
  1511. case MBX_DUMP_CONTEXT:
  1512. case MBX_RUN_DIAGS:
  1513. case MBX_RESTART:
  1514. case MBX_UPDATE_CFG:
  1515. case MBX_DOWN_LOAD:
  1516. case MBX_DEL_LD_ENTRY:
  1517. case MBX_RUN_PROGRAM:
  1518. case MBX_SET_MASK:
  1519. case MBX_SET_VARIABLE:
  1520. case MBX_UNREG_D_ID:
  1521. case MBX_KILL_BOARD:
  1522. case MBX_CONFIG_FARP:
  1523. case MBX_BEACON:
  1524. case MBX_LOAD_AREA:
  1525. case MBX_RUN_BIU_DIAG64:
  1526. case MBX_CONFIG_PORT:
  1527. case MBX_READ_SPARM64:
  1528. case MBX_READ_RPI64:
  1529. case MBX_REG_LOGIN64:
  1530. case MBX_READ_LA64:
  1531. case MBX_WRITE_WWN:
  1532. case MBX_SET_DEBUG:
  1533. case MBX_LOAD_EXP_ROM:
  1534. case MBX_ASYNCEVT_ENABLE:
  1535. case MBX_REG_VPI:
  1536. case MBX_UNREG_VPI:
  1537. case MBX_HEARTBEAT:
  1538. case MBX_PORT_CAPABILITIES:
  1539. case MBX_PORT_IOV_CONTROL:
  1540. case MBX_SLI4_CONFIG:
  1541. case MBX_SLI4_REQ_FTRS:
  1542. case MBX_REG_FCFI:
  1543. case MBX_UNREG_FCFI:
  1544. case MBX_REG_VFI:
  1545. case MBX_UNREG_VFI:
  1546. case MBX_INIT_VPI:
  1547. case MBX_INIT_VFI:
  1548. case MBX_RESUME_RPI:
  1549. case MBX_READ_EVENT_LOG_STATUS:
  1550. case MBX_READ_EVENT_LOG:
  1551. ret = mbxCommand;
  1552. break;
  1553. default:
  1554. ret = MBX_SHUTDOWN;
  1555. break;
  1556. }
  1557. return ret;
  1558. }
  1559. /**
  1560. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1561. * @phba: Pointer to HBA context object.
  1562. * @pmboxq: Pointer to mailbox command.
  1563. *
  1564. * This is completion handler function for mailbox commands issued from
  1565. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1566. * mailbox event handler function with no lock held. This function
  1567. * will wake up thread waiting on the wait queue pointed by context1
  1568. * of the mailbox.
  1569. **/
  1570. void
  1571. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1572. {
  1573. wait_queue_head_t *pdone_q;
  1574. unsigned long drvr_flag;
  1575. /*
  1576. * If pdone_q is empty, the driver thread gave up waiting and
  1577. * continued running.
  1578. */
  1579. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1580. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1581. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1582. if (pdone_q)
  1583. wake_up_interruptible(pdone_q);
  1584. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1585. return;
  1586. }
  1587. /**
  1588. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1589. * @phba: Pointer to HBA context object.
  1590. * @pmb: Pointer to mailbox object.
  1591. *
  1592. * This function is the default mailbox completion handler. It
  1593. * frees the memory resources associated with the completed mailbox
  1594. * command. If the completed command is a REG_LOGIN mailbox command,
  1595. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1596. **/
  1597. void
  1598. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1599. {
  1600. struct lpfc_dmabuf *mp;
  1601. uint16_t rpi, vpi;
  1602. int rc;
  1603. struct lpfc_vport *vport = pmb->vport;
  1604. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1605. if (mp) {
  1606. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1607. kfree(mp);
  1608. }
  1609. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1610. (phba->sli_rev == LPFC_SLI_REV4))
  1611. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1612. /*
  1613. * If a REG_LOGIN succeeded after node is destroyed or node
  1614. * is in re-discovery driver need to cleanup the RPI.
  1615. */
  1616. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1617. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1618. !pmb->u.mb.mbxStatus) {
  1619. rpi = pmb->u.mb.un.varWords[0];
  1620. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1621. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1622. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1623. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1624. if (rc != MBX_NOT_FINISHED)
  1625. return;
  1626. }
  1627. /* Unreg VPI, if the REG_VPI succeed after VLink failure */
  1628. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1629. !(phba->pport->load_flag & FC_UNLOADING) &&
  1630. !pmb->u.mb.mbxStatus) {
  1631. lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb);
  1632. pmb->vport = vport;
  1633. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1634. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1635. if (rc != MBX_NOT_FINISHED)
  1636. return;
  1637. }
  1638. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1639. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1640. else
  1641. mempool_free(pmb, phba->mbox_mem_pool);
  1642. }
  1643. /**
  1644. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1645. * @phba: Pointer to HBA context object.
  1646. *
  1647. * This function is called with no lock held. This function processes all
  1648. * the completed mailbox commands and gives it to upper layers. The interrupt
  1649. * service routine processes mailbox completion interrupt and adds completed
  1650. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1651. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1652. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1653. * function returns the mailbox commands to the upper layer by calling the
  1654. * completion handler function of each mailbox.
  1655. **/
  1656. int
  1657. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1658. {
  1659. MAILBOX_t *pmbox;
  1660. LPFC_MBOXQ_t *pmb;
  1661. int rc;
  1662. LIST_HEAD(cmplq);
  1663. phba->sli.slistat.mbox_event++;
  1664. /* Get all completed mailboxe buffers into the cmplq */
  1665. spin_lock_irq(&phba->hbalock);
  1666. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1667. spin_unlock_irq(&phba->hbalock);
  1668. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1669. do {
  1670. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1671. if (pmb == NULL)
  1672. break;
  1673. pmbox = &pmb->u.mb;
  1674. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1675. if (pmb->vport) {
  1676. lpfc_debugfs_disc_trc(pmb->vport,
  1677. LPFC_DISC_TRC_MBOX_VPORT,
  1678. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1679. (uint32_t)pmbox->mbxCommand,
  1680. pmbox->un.varWords[0],
  1681. pmbox->un.varWords[1]);
  1682. }
  1683. else {
  1684. lpfc_debugfs_disc_trc(phba->pport,
  1685. LPFC_DISC_TRC_MBOX,
  1686. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1687. (uint32_t)pmbox->mbxCommand,
  1688. pmbox->un.varWords[0],
  1689. pmbox->un.varWords[1]);
  1690. }
  1691. }
  1692. /*
  1693. * It is a fatal error if unknown mbox command completion.
  1694. */
  1695. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1696. MBX_SHUTDOWN) {
  1697. /* Unknown mailbox command compl */
  1698. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1699. "(%d):0323 Unknown Mailbox command "
  1700. "x%x (x%x) Cmpl\n",
  1701. pmb->vport ? pmb->vport->vpi : 0,
  1702. pmbox->mbxCommand,
  1703. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1704. phba->link_state = LPFC_HBA_ERROR;
  1705. phba->work_hs = HS_FFER3;
  1706. lpfc_handle_eratt(phba);
  1707. continue;
  1708. }
  1709. if (pmbox->mbxStatus) {
  1710. phba->sli.slistat.mbox_stat_err++;
  1711. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1712. /* Mbox cmd cmpl error - RETRYing */
  1713. lpfc_printf_log(phba, KERN_INFO,
  1714. LOG_MBOX | LOG_SLI,
  1715. "(%d):0305 Mbox cmd cmpl "
  1716. "error - RETRYing Data: x%x "
  1717. "(x%x) x%x x%x x%x\n",
  1718. pmb->vport ? pmb->vport->vpi :0,
  1719. pmbox->mbxCommand,
  1720. lpfc_sli4_mbox_opcode_get(phba,
  1721. pmb),
  1722. pmbox->mbxStatus,
  1723. pmbox->un.varWords[0],
  1724. pmb->vport->port_state);
  1725. pmbox->mbxStatus = 0;
  1726. pmbox->mbxOwner = OWN_HOST;
  1727. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1728. if (rc != MBX_NOT_FINISHED)
  1729. continue;
  1730. }
  1731. }
  1732. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1733. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1734. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1735. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1736. pmb->vport ? pmb->vport->vpi : 0,
  1737. pmbox->mbxCommand,
  1738. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1739. pmb->mbox_cmpl,
  1740. *((uint32_t *) pmbox),
  1741. pmbox->un.varWords[0],
  1742. pmbox->un.varWords[1],
  1743. pmbox->un.varWords[2],
  1744. pmbox->un.varWords[3],
  1745. pmbox->un.varWords[4],
  1746. pmbox->un.varWords[5],
  1747. pmbox->un.varWords[6],
  1748. pmbox->un.varWords[7]);
  1749. if (pmb->mbox_cmpl)
  1750. pmb->mbox_cmpl(phba,pmb);
  1751. } while (1);
  1752. return 0;
  1753. }
  1754. /**
  1755. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1756. * @phba: Pointer to HBA context object.
  1757. * @pring: Pointer to driver SLI ring object.
  1758. * @tag: buffer tag.
  1759. *
  1760. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1761. * is set in the tag the buffer is posted for a particular exchange,
  1762. * the function will return the buffer without replacing the buffer.
  1763. * If the buffer is for unsolicited ELS or CT traffic, this function
  1764. * returns the buffer and also posts another buffer to the firmware.
  1765. **/
  1766. static struct lpfc_dmabuf *
  1767. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1768. struct lpfc_sli_ring *pring,
  1769. uint32_t tag)
  1770. {
  1771. struct hbq_dmabuf *hbq_entry;
  1772. if (tag & QUE_BUFTAG_BIT)
  1773. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1774. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1775. if (!hbq_entry)
  1776. return NULL;
  1777. return &hbq_entry->dbuf;
  1778. }
  1779. /**
  1780. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1781. * @phba: Pointer to HBA context object.
  1782. * @pring: Pointer to driver SLI ring object.
  1783. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1784. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1785. * @fch_type: the type for the first frame of the sequence.
  1786. *
  1787. * This function is called with no lock held. This function uses the r_ctl and
  1788. * type of the received sequence to find the correct callback function to call
  1789. * to process the sequence.
  1790. **/
  1791. static int
  1792. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1793. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1794. uint32_t fch_type)
  1795. {
  1796. int i;
  1797. /* unSolicited Responses */
  1798. if (pring->prt[0].profile) {
  1799. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1800. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1801. saveq);
  1802. return 1;
  1803. }
  1804. /* We must search, based on rctl / type
  1805. for the right routine */
  1806. for (i = 0; i < pring->num_mask; i++) {
  1807. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1808. (pring->prt[i].type == fch_type)) {
  1809. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1810. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1811. (phba, pring, saveq);
  1812. return 1;
  1813. }
  1814. }
  1815. return 0;
  1816. }
  1817. /**
  1818. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1819. * @phba: Pointer to HBA context object.
  1820. * @pring: Pointer to driver SLI ring object.
  1821. * @saveq: Pointer to the unsolicited iocb.
  1822. *
  1823. * This function is called with no lock held by the ring event handler
  1824. * when there is an unsolicited iocb posted to the response ring by the
  1825. * firmware. This function gets the buffer associated with the iocbs
  1826. * and calls the event handler for the ring. This function handles both
  1827. * qring buffers and hbq buffers.
  1828. * When the function returns 1 the caller can free the iocb object otherwise
  1829. * upper layer functions will free the iocb objects.
  1830. **/
  1831. static int
  1832. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1833. struct lpfc_iocbq *saveq)
  1834. {
  1835. IOCB_t * irsp;
  1836. WORD5 * w5p;
  1837. uint32_t Rctl, Type;
  1838. uint32_t match;
  1839. struct lpfc_iocbq *iocbq;
  1840. struct lpfc_dmabuf *dmzbuf;
  1841. match = 0;
  1842. irsp = &(saveq->iocb);
  1843. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1844. if (pring->lpfc_sli_rcv_async_status)
  1845. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1846. else
  1847. lpfc_printf_log(phba,
  1848. KERN_WARNING,
  1849. LOG_SLI,
  1850. "0316 Ring %d handler: unexpected "
  1851. "ASYNC_STATUS iocb received evt_code "
  1852. "0x%x\n",
  1853. pring->ringno,
  1854. irsp->un.asyncstat.evt_code);
  1855. return 1;
  1856. }
  1857. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1858. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1859. if (irsp->ulpBdeCount > 0) {
  1860. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1861. irsp->un.ulpWord[3]);
  1862. lpfc_in_buf_free(phba, dmzbuf);
  1863. }
  1864. if (irsp->ulpBdeCount > 1) {
  1865. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1866. irsp->unsli3.sli3Words[3]);
  1867. lpfc_in_buf_free(phba, dmzbuf);
  1868. }
  1869. if (irsp->ulpBdeCount > 2) {
  1870. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1871. irsp->unsli3.sli3Words[7]);
  1872. lpfc_in_buf_free(phba, dmzbuf);
  1873. }
  1874. return 1;
  1875. }
  1876. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1877. if (irsp->ulpBdeCount != 0) {
  1878. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1879. irsp->un.ulpWord[3]);
  1880. if (!saveq->context2)
  1881. lpfc_printf_log(phba,
  1882. KERN_ERR,
  1883. LOG_SLI,
  1884. "0341 Ring %d Cannot find buffer for "
  1885. "an unsolicited iocb. tag 0x%x\n",
  1886. pring->ringno,
  1887. irsp->un.ulpWord[3]);
  1888. }
  1889. if (irsp->ulpBdeCount == 2) {
  1890. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1891. irsp->unsli3.sli3Words[7]);
  1892. if (!saveq->context3)
  1893. lpfc_printf_log(phba,
  1894. KERN_ERR,
  1895. LOG_SLI,
  1896. "0342 Ring %d Cannot find buffer for an"
  1897. " unsolicited iocb. tag 0x%x\n",
  1898. pring->ringno,
  1899. irsp->unsli3.sli3Words[7]);
  1900. }
  1901. list_for_each_entry(iocbq, &saveq->list, list) {
  1902. irsp = &(iocbq->iocb);
  1903. if (irsp->ulpBdeCount != 0) {
  1904. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1905. irsp->un.ulpWord[3]);
  1906. if (!iocbq->context2)
  1907. lpfc_printf_log(phba,
  1908. KERN_ERR,
  1909. LOG_SLI,
  1910. "0343 Ring %d Cannot find "
  1911. "buffer for an unsolicited iocb"
  1912. ". tag 0x%x\n", pring->ringno,
  1913. irsp->un.ulpWord[3]);
  1914. }
  1915. if (irsp->ulpBdeCount == 2) {
  1916. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1917. irsp->unsli3.sli3Words[7]);
  1918. if (!iocbq->context3)
  1919. lpfc_printf_log(phba,
  1920. KERN_ERR,
  1921. LOG_SLI,
  1922. "0344 Ring %d Cannot find "
  1923. "buffer for an unsolicited "
  1924. "iocb. tag 0x%x\n",
  1925. pring->ringno,
  1926. irsp->unsli3.sli3Words[7]);
  1927. }
  1928. }
  1929. }
  1930. if (irsp->ulpBdeCount != 0 &&
  1931. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1932. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1933. int found = 0;
  1934. /* search continue save q for same XRI */
  1935. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1936. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1937. list_add_tail(&saveq->list, &iocbq->list);
  1938. found = 1;
  1939. break;
  1940. }
  1941. }
  1942. if (!found)
  1943. list_add_tail(&saveq->clist,
  1944. &pring->iocb_continue_saveq);
  1945. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1946. list_del_init(&iocbq->clist);
  1947. saveq = iocbq;
  1948. irsp = &(saveq->iocb);
  1949. } else
  1950. return 0;
  1951. }
  1952. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1953. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1954. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1955. Rctl = FC_RCTL_ELS_REQ;
  1956. Type = FC_TYPE_ELS;
  1957. } else {
  1958. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1959. Rctl = w5p->hcsw.Rctl;
  1960. Type = w5p->hcsw.Type;
  1961. /* Firmware Workaround */
  1962. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1963. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1964. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1965. Rctl = FC_RCTL_ELS_REQ;
  1966. Type = FC_TYPE_ELS;
  1967. w5p->hcsw.Rctl = Rctl;
  1968. w5p->hcsw.Type = Type;
  1969. }
  1970. }
  1971. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1972. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1973. "0313 Ring %d handler: unexpected Rctl x%x "
  1974. "Type x%x received\n",
  1975. pring->ringno, Rctl, Type);
  1976. return 1;
  1977. }
  1978. /**
  1979. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1980. * @phba: Pointer to HBA context object.
  1981. * @pring: Pointer to driver SLI ring object.
  1982. * @prspiocb: Pointer to response iocb object.
  1983. *
  1984. * This function looks up the iocb_lookup table to get the command iocb
  1985. * corresponding to the given response iocb using the iotag of the
  1986. * response iocb. This function is called with the hbalock held.
  1987. * This function returns the command iocb object if it finds the command
  1988. * iocb else returns NULL.
  1989. **/
  1990. static struct lpfc_iocbq *
  1991. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1992. struct lpfc_sli_ring *pring,
  1993. struct lpfc_iocbq *prspiocb)
  1994. {
  1995. struct lpfc_iocbq *cmd_iocb = NULL;
  1996. uint16_t iotag;
  1997. iotag = prspiocb->iocb.ulpIoTag;
  1998. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1999. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2000. list_del_init(&cmd_iocb->list);
  2001. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2002. pring->txcmplq_cnt--;
  2003. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2004. }
  2005. return cmd_iocb;
  2006. }
  2007. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2008. "0317 iotag x%x is out off "
  2009. "range: max iotag x%x wd0 x%x\n",
  2010. iotag, phba->sli.last_iotag,
  2011. *(((uint32_t *) &prspiocb->iocb) + 7));
  2012. return NULL;
  2013. }
  2014. /**
  2015. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2016. * @phba: Pointer to HBA context object.
  2017. * @pring: Pointer to driver SLI ring object.
  2018. * @iotag: IOCB tag.
  2019. *
  2020. * This function looks up the iocb_lookup table to get the command iocb
  2021. * corresponding to the given iotag. This function is called with the
  2022. * hbalock held.
  2023. * This function returns the command iocb object if it finds the command
  2024. * iocb else returns NULL.
  2025. **/
  2026. static struct lpfc_iocbq *
  2027. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2028. struct lpfc_sli_ring *pring, uint16_t iotag)
  2029. {
  2030. struct lpfc_iocbq *cmd_iocb;
  2031. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2032. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2033. list_del_init(&cmd_iocb->list);
  2034. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2035. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2036. pring->txcmplq_cnt--;
  2037. }
  2038. return cmd_iocb;
  2039. }
  2040. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2041. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2042. iotag, phba->sli.last_iotag);
  2043. return NULL;
  2044. }
  2045. /**
  2046. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2047. * @phba: Pointer to HBA context object.
  2048. * @pring: Pointer to driver SLI ring object.
  2049. * @saveq: Pointer to the response iocb to be processed.
  2050. *
  2051. * This function is called by the ring event handler for non-fcp
  2052. * rings when there is a new response iocb in the response ring.
  2053. * The caller is not required to hold any locks. This function
  2054. * gets the command iocb associated with the response iocb and
  2055. * calls the completion handler for the command iocb. If there
  2056. * is no completion handler, the function will free the resources
  2057. * associated with command iocb. If the response iocb is for
  2058. * an already aborted command iocb, the status of the completion
  2059. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2060. * This function always returns 1.
  2061. **/
  2062. static int
  2063. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2064. struct lpfc_iocbq *saveq)
  2065. {
  2066. struct lpfc_iocbq *cmdiocbp;
  2067. int rc = 1;
  2068. unsigned long iflag;
  2069. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2070. spin_lock_irqsave(&phba->hbalock, iflag);
  2071. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2072. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2073. if (cmdiocbp) {
  2074. if (cmdiocbp->iocb_cmpl) {
  2075. /*
  2076. * If an ELS command failed send an event to mgmt
  2077. * application.
  2078. */
  2079. if (saveq->iocb.ulpStatus &&
  2080. (pring->ringno == LPFC_ELS_RING) &&
  2081. (cmdiocbp->iocb.ulpCommand ==
  2082. CMD_ELS_REQUEST64_CR))
  2083. lpfc_send_els_failure_event(phba,
  2084. cmdiocbp, saveq);
  2085. /*
  2086. * Post all ELS completions to the worker thread.
  2087. * All other are passed to the completion callback.
  2088. */
  2089. if (pring->ringno == LPFC_ELS_RING) {
  2090. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2091. (cmdiocbp->iocb_flag &
  2092. LPFC_DRIVER_ABORTED)) {
  2093. spin_lock_irqsave(&phba->hbalock,
  2094. iflag);
  2095. cmdiocbp->iocb_flag &=
  2096. ~LPFC_DRIVER_ABORTED;
  2097. spin_unlock_irqrestore(&phba->hbalock,
  2098. iflag);
  2099. saveq->iocb.ulpStatus =
  2100. IOSTAT_LOCAL_REJECT;
  2101. saveq->iocb.un.ulpWord[4] =
  2102. IOERR_SLI_ABORTED;
  2103. /* Firmware could still be in progress
  2104. * of DMAing payload, so don't free data
  2105. * buffer till after a hbeat.
  2106. */
  2107. spin_lock_irqsave(&phba->hbalock,
  2108. iflag);
  2109. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2110. spin_unlock_irqrestore(&phba->hbalock,
  2111. iflag);
  2112. }
  2113. if (phba->sli_rev == LPFC_SLI_REV4) {
  2114. if (saveq->iocb_flag &
  2115. LPFC_EXCHANGE_BUSY) {
  2116. /* Set cmdiocb flag for the
  2117. * exchange busy so sgl (xri)
  2118. * will not be released until
  2119. * the abort xri is received
  2120. * from hba.
  2121. */
  2122. spin_lock_irqsave(
  2123. &phba->hbalock, iflag);
  2124. cmdiocbp->iocb_flag |=
  2125. LPFC_EXCHANGE_BUSY;
  2126. spin_unlock_irqrestore(
  2127. &phba->hbalock, iflag);
  2128. }
  2129. if (cmdiocbp->iocb_flag &
  2130. LPFC_DRIVER_ABORTED) {
  2131. /*
  2132. * Clear LPFC_DRIVER_ABORTED
  2133. * bit in case it was driver
  2134. * initiated abort.
  2135. */
  2136. spin_lock_irqsave(
  2137. &phba->hbalock, iflag);
  2138. cmdiocbp->iocb_flag &=
  2139. ~LPFC_DRIVER_ABORTED;
  2140. spin_unlock_irqrestore(
  2141. &phba->hbalock, iflag);
  2142. cmdiocbp->iocb.ulpStatus =
  2143. IOSTAT_LOCAL_REJECT;
  2144. cmdiocbp->iocb.un.ulpWord[4] =
  2145. IOERR_ABORT_REQUESTED;
  2146. /*
  2147. * For SLI4, irsiocb contains
  2148. * NO_XRI in sli_xritag, it
  2149. * shall not affect releasing
  2150. * sgl (xri) process.
  2151. */
  2152. saveq->iocb.ulpStatus =
  2153. IOSTAT_LOCAL_REJECT;
  2154. saveq->iocb.un.ulpWord[4] =
  2155. IOERR_SLI_ABORTED;
  2156. spin_lock_irqsave(
  2157. &phba->hbalock, iflag);
  2158. saveq->iocb_flag |=
  2159. LPFC_DELAY_MEM_FREE;
  2160. spin_unlock_irqrestore(
  2161. &phba->hbalock, iflag);
  2162. }
  2163. }
  2164. }
  2165. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2166. } else
  2167. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2168. } else {
  2169. /*
  2170. * Unknown initiating command based on the response iotag.
  2171. * This could be the case on the ELS ring because of
  2172. * lpfc_els_abort().
  2173. */
  2174. if (pring->ringno != LPFC_ELS_RING) {
  2175. /*
  2176. * Ring <ringno> handler: unexpected completion IoTag
  2177. * <IoTag>
  2178. */
  2179. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2180. "0322 Ring %d handler: "
  2181. "unexpected completion IoTag x%x "
  2182. "Data: x%x x%x x%x x%x\n",
  2183. pring->ringno,
  2184. saveq->iocb.ulpIoTag,
  2185. saveq->iocb.ulpStatus,
  2186. saveq->iocb.un.ulpWord[4],
  2187. saveq->iocb.ulpCommand,
  2188. saveq->iocb.ulpContext);
  2189. }
  2190. }
  2191. return rc;
  2192. }
  2193. /**
  2194. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2195. * @phba: Pointer to HBA context object.
  2196. * @pring: Pointer to driver SLI ring object.
  2197. *
  2198. * This function is called from the iocb ring event handlers when
  2199. * put pointer is ahead of the get pointer for a ring. This function signal
  2200. * an error attention condition to the worker thread and the worker
  2201. * thread will transition the HBA to offline state.
  2202. **/
  2203. static void
  2204. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2205. {
  2206. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2207. /*
  2208. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2209. * rsp ring <portRspMax>
  2210. */
  2211. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2212. "0312 Ring %d handler: portRspPut %d "
  2213. "is bigger than rsp ring %d\n",
  2214. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2215. pring->numRiocb);
  2216. phba->link_state = LPFC_HBA_ERROR;
  2217. /*
  2218. * All error attention handlers are posted to
  2219. * worker thread
  2220. */
  2221. phba->work_ha |= HA_ERATT;
  2222. phba->work_hs = HS_FFER3;
  2223. lpfc_worker_wake_up(phba);
  2224. return;
  2225. }
  2226. /**
  2227. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2228. * @ptr: Pointer to address of HBA context object.
  2229. *
  2230. * This function is invoked by the Error Attention polling timer when the
  2231. * timer times out. It will check the SLI Error Attention register for
  2232. * possible attention events. If so, it will post an Error Attention event
  2233. * and wake up worker thread to process it. Otherwise, it will set up the
  2234. * Error Attention polling timer for the next poll.
  2235. **/
  2236. void lpfc_poll_eratt(unsigned long ptr)
  2237. {
  2238. struct lpfc_hba *phba;
  2239. uint32_t eratt = 0;
  2240. phba = (struct lpfc_hba *)ptr;
  2241. /* Check chip HA register for error event */
  2242. eratt = lpfc_sli_check_eratt(phba);
  2243. if (eratt)
  2244. /* Tell the worker thread there is work to do */
  2245. lpfc_worker_wake_up(phba);
  2246. else
  2247. /* Restart the timer for next eratt poll */
  2248. mod_timer(&phba->eratt_poll, jiffies +
  2249. HZ * LPFC_ERATT_POLL_INTERVAL);
  2250. return;
  2251. }
  2252. /**
  2253. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2254. * @phba: Pointer to HBA context object.
  2255. * @pring: Pointer to driver SLI ring object.
  2256. * @mask: Host attention register mask for this ring.
  2257. *
  2258. * This function is called from the interrupt context when there is a ring
  2259. * event for the fcp ring. The caller does not hold any lock.
  2260. * The function processes each response iocb in the response ring until it
  2261. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2262. * LE bit set. The function will call the completion handler of the command iocb
  2263. * if the response iocb indicates a completion for a command iocb or it is
  2264. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2265. * function if this is an unsolicited iocb.
  2266. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2267. * to check it explicitly.
  2268. */
  2269. int
  2270. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2271. struct lpfc_sli_ring *pring, uint32_t mask)
  2272. {
  2273. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2274. IOCB_t *irsp = NULL;
  2275. IOCB_t *entry = NULL;
  2276. struct lpfc_iocbq *cmdiocbq = NULL;
  2277. struct lpfc_iocbq rspiocbq;
  2278. uint32_t status;
  2279. uint32_t portRspPut, portRspMax;
  2280. int rc = 1;
  2281. lpfc_iocb_type type;
  2282. unsigned long iflag;
  2283. uint32_t rsp_cmpl = 0;
  2284. spin_lock_irqsave(&phba->hbalock, iflag);
  2285. pring->stats.iocb_event++;
  2286. /*
  2287. * The next available response entry should never exceed the maximum
  2288. * entries. If it does, treat it as an adapter hardware error.
  2289. */
  2290. portRspMax = pring->numRiocb;
  2291. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2292. if (unlikely(portRspPut >= portRspMax)) {
  2293. lpfc_sli_rsp_pointers_error(phba, pring);
  2294. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2295. return 1;
  2296. }
  2297. if (phba->fcp_ring_in_use) {
  2298. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2299. return 1;
  2300. } else
  2301. phba->fcp_ring_in_use = 1;
  2302. rmb();
  2303. while (pring->rspidx != portRspPut) {
  2304. /*
  2305. * Fetch an entry off the ring and copy it into a local data
  2306. * structure. The copy involves a byte-swap since the
  2307. * network byte order and pci byte orders are different.
  2308. */
  2309. entry = lpfc_resp_iocb(phba, pring);
  2310. phba->last_completion_time = jiffies;
  2311. if (++pring->rspidx >= portRspMax)
  2312. pring->rspidx = 0;
  2313. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2314. (uint32_t *) &rspiocbq.iocb,
  2315. phba->iocb_rsp_size);
  2316. INIT_LIST_HEAD(&(rspiocbq.list));
  2317. irsp = &rspiocbq.iocb;
  2318. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2319. pring->stats.iocb_rsp++;
  2320. rsp_cmpl++;
  2321. if (unlikely(irsp->ulpStatus)) {
  2322. /*
  2323. * If resource errors reported from HBA, reduce
  2324. * queuedepths of the SCSI device.
  2325. */
  2326. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2327. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2328. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2329. phba->lpfc_rampdown_queue_depth(phba);
  2330. spin_lock_irqsave(&phba->hbalock, iflag);
  2331. }
  2332. /* Rsp ring <ringno> error: IOCB */
  2333. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2334. "0336 Rsp Ring %d error: IOCB Data: "
  2335. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2336. pring->ringno,
  2337. irsp->un.ulpWord[0],
  2338. irsp->un.ulpWord[1],
  2339. irsp->un.ulpWord[2],
  2340. irsp->un.ulpWord[3],
  2341. irsp->un.ulpWord[4],
  2342. irsp->un.ulpWord[5],
  2343. *(uint32_t *)&irsp->un1,
  2344. *((uint32_t *)&irsp->un1 + 1));
  2345. }
  2346. switch (type) {
  2347. case LPFC_ABORT_IOCB:
  2348. case LPFC_SOL_IOCB:
  2349. /*
  2350. * Idle exchange closed via ABTS from port. No iocb
  2351. * resources need to be recovered.
  2352. */
  2353. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2354. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2355. "0333 IOCB cmd 0x%x"
  2356. " processed. Skipping"
  2357. " completion\n",
  2358. irsp->ulpCommand);
  2359. break;
  2360. }
  2361. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2362. &rspiocbq);
  2363. if (unlikely(!cmdiocbq))
  2364. break;
  2365. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2366. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2367. if (cmdiocbq->iocb_cmpl) {
  2368. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2369. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2370. &rspiocbq);
  2371. spin_lock_irqsave(&phba->hbalock, iflag);
  2372. }
  2373. break;
  2374. case LPFC_UNSOL_IOCB:
  2375. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2376. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2377. spin_lock_irqsave(&phba->hbalock, iflag);
  2378. break;
  2379. default:
  2380. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2381. char adaptermsg[LPFC_MAX_ADPTMSG];
  2382. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2383. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2384. MAX_MSG_DATA);
  2385. dev_warn(&((phba->pcidev)->dev),
  2386. "lpfc%d: %s\n",
  2387. phba->brd_no, adaptermsg);
  2388. } else {
  2389. /* Unknown IOCB command */
  2390. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2391. "0334 Unknown IOCB command "
  2392. "Data: x%x, x%x x%x x%x x%x\n",
  2393. type, irsp->ulpCommand,
  2394. irsp->ulpStatus,
  2395. irsp->ulpIoTag,
  2396. irsp->ulpContext);
  2397. }
  2398. break;
  2399. }
  2400. /*
  2401. * The response IOCB has been processed. Update the ring
  2402. * pointer in SLIM. If the port response put pointer has not
  2403. * been updated, sync the pgp->rspPutInx and fetch the new port
  2404. * response put pointer.
  2405. */
  2406. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2407. if (pring->rspidx == portRspPut)
  2408. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2409. }
  2410. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2411. pring->stats.iocb_rsp_full++;
  2412. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2413. writel(status, phba->CAregaddr);
  2414. readl(phba->CAregaddr);
  2415. }
  2416. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2417. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2418. pring->stats.iocb_cmd_empty++;
  2419. /* Force update of the local copy of cmdGetInx */
  2420. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2421. lpfc_sli_resume_iocb(phba, pring);
  2422. if ((pring->lpfc_sli_cmd_available))
  2423. (pring->lpfc_sli_cmd_available) (phba, pring);
  2424. }
  2425. phba->fcp_ring_in_use = 0;
  2426. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2427. return rc;
  2428. }
  2429. /**
  2430. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2431. * @phba: Pointer to HBA context object.
  2432. * @pring: Pointer to driver SLI ring object.
  2433. * @rspiocbp: Pointer to driver response IOCB object.
  2434. *
  2435. * This function is called from the worker thread when there is a slow-path
  2436. * response IOCB to process. This function chains all the response iocbs until
  2437. * seeing the iocb with the LE bit set. The function will call
  2438. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2439. * completion of a command iocb. The function will call the
  2440. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2441. * The function frees the resources or calls the completion handler if this
  2442. * iocb is an abort completion. The function returns NULL when the response
  2443. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2444. * this function shall chain the iocb on to the iocb_continueq and return the
  2445. * response iocb passed in.
  2446. **/
  2447. static struct lpfc_iocbq *
  2448. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2449. struct lpfc_iocbq *rspiocbp)
  2450. {
  2451. struct lpfc_iocbq *saveq;
  2452. struct lpfc_iocbq *cmdiocbp;
  2453. struct lpfc_iocbq *next_iocb;
  2454. IOCB_t *irsp = NULL;
  2455. uint32_t free_saveq;
  2456. uint8_t iocb_cmd_type;
  2457. lpfc_iocb_type type;
  2458. unsigned long iflag;
  2459. int rc;
  2460. spin_lock_irqsave(&phba->hbalock, iflag);
  2461. /* First add the response iocb to the countinueq list */
  2462. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2463. pring->iocb_continueq_cnt++;
  2464. /* Now, determine whetehr the list is completed for processing */
  2465. irsp = &rspiocbp->iocb;
  2466. if (irsp->ulpLe) {
  2467. /*
  2468. * By default, the driver expects to free all resources
  2469. * associated with this iocb completion.
  2470. */
  2471. free_saveq = 1;
  2472. saveq = list_get_first(&pring->iocb_continueq,
  2473. struct lpfc_iocbq, list);
  2474. irsp = &(saveq->iocb);
  2475. list_del_init(&pring->iocb_continueq);
  2476. pring->iocb_continueq_cnt = 0;
  2477. pring->stats.iocb_rsp++;
  2478. /*
  2479. * If resource errors reported from HBA, reduce
  2480. * queuedepths of the SCSI device.
  2481. */
  2482. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2483. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2484. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2485. phba->lpfc_rampdown_queue_depth(phba);
  2486. spin_lock_irqsave(&phba->hbalock, iflag);
  2487. }
  2488. if (irsp->ulpStatus) {
  2489. /* Rsp ring <ringno> error: IOCB */
  2490. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2491. "0328 Rsp Ring %d error: "
  2492. "IOCB Data: "
  2493. "x%x x%x x%x x%x "
  2494. "x%x x%x x%x x%x "
  2495. "x%x x%x x%x x%x "
  2496. "x%x x%x x%x x%x\n",
  2497. pring->ringno,
  2498. irsp->un.ulpWord[0],
  2499. irsp->un.ulpWord[1],
  2500. irsp->un.ulpWord[2],
  2501. irsp->un.ulpWord[3],
  2502. irsp->un.ulpWord[4],
  2503. irsp->un.ulpWord[5],
  2504. *(((uint32_t *) irsp) + 6),
  2505. *(((uint32_t *) irsp) + 7),
  2506. *(((uint32_t *) irsp) + 8),
  2507. *(((uint32_t *) irsp) + 9),
  2508. *(((uint32_t *) irsp) + 10),
  2509. *(((uint32_t *) irsp) + 11),
  2510. *(((uint32_t *) irsp) + 12),
  2511. *(((uint32_t *) irsp) + 13),
  2512. *(((uint32_t *) irsp) + 14),
  2513. *(((uint32_t *) irsp) + 15));
  2514. }
  2515. /*
  2516. * Fetch the IOCB command type and call the correct completion
  2517. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2518. * get freed back to the lpfc_iocb_list by the discovery
  2519. * kernel thread.
  2520. */
  2521. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2522. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2523. switch (type) {
  2524. case LPFC_SOL_IOCB:
  2525. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2526. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2527. spin_lock_irqsave(&phba->hbalock, iflag);
  2528. break;
  2529. case LPFC_UNSOL_IOCB:
  2530. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2531. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2532. spin_lock_irqsave(&phba->hbalock, iflag);
  2533. if (!rc)
  2534. free_saveq = 0;
  2535. break;
  2536. case LPFC_ABORT_IOCB:
  2537. cmdiocbp = NULL;
  2538. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2539. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2540. saveq);
  2541. if (cmdiocbp) {
  2542. /* Call the specified completion routine */
  2543. if (cmdiocbp->iocb_cmpl) {
  2544. spin_unlock_irqrestore(&phba->hbalock,
  2545. iflag);
  2546. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2547. saveq);
  2548. spin_lock_irqsave(&phba->hbalock,
  2549. iflag);
  2550. } else
  2551. __lpfc_sli_release_iocbq(phba,
  2552. cmdiocbp);
  2553. }
  2554. break;
  2555. case LPFC_UNKNOWN_IOCB:
  2556. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2557. char adaptermsg[LPFC_MAX_ADPTMSG];
  2558. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2559. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2560. MAX_MSG_DATA);
  2561. dev_warn(&((phba->pcidev)->dev),
  2562. "lpfc%d: %s\n",
  2563. phba->brd_no, adaptermsg);
  2564. } else {
  2565. /* Unknown IOCB command */
  2566. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2567. "0335 Unknown IOCB "
  2568. "command Data: x%x "
  2569. "x%x x%x x%x\n",
  2570. irsp->ulpCommand,
  2571. irsp->ulpStatus,
  2572. irsp->ulpIoTag,
  2573. irsp->ulpContext);
  2574. }
  2575. break;
  2576. }
  2577. if (free_saveq) {
  2578. list_for_each_entry_safe(rspiocbp, next_iocb,
  2579. &saveq->list, list) {
  2580. list_del(&rspiocbp->list);
  2581. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2582. }
  2583. __lpfc_sli_release_iocbq(phba, saveq);
  2584. }
  2585. rspiocbp = NULL;
  2586. }
  2587. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2588. return rspiocbp;
  2589. }
  2590. /**
  2591. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2592. * @phba: Pointer to HBA context object.
  2593. * @pring: Pointer to driver SLI ring object.
  2594. * @mask: Host attention register mask for this ring.
  2595. *
  2596. * This routine wraps the actual slow_ring event process routine from the
  2597. * API jump table function pointer from the lpfc_hba struct.
  2598. **/
  2599. void
  2600. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2601. struct lpfc_sli_ring *pring, uint32_t mask)
  2602. {
  2603. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2604. }
  2605. /**
  2606. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2607. * @phba: Pointer to HBA context object.
  2608. * @pring: Pointer to driver SLI ring object.
  2609. * @mask: Host attention register mask for this ring.
  2610. *
  2611. * This function is called from the worker thread when there is a ring event
  2612. * for non-fcp rings. The caller does not hold any lock. The function will
  2613. * remove each response iocb in the response ring and calls the handle
  2614. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2615. **/
  2616. static void
  2617. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2618. struct lpfc_sli_ring *pring, uint32_t mask)
  2619. {
  2620. struct lpfc_pgp *pgp;
  2621. IOCB_t *entry;
  2622. IOCB_t *irsp = NULL;
  2623. struct lpfc_iocbq *rspiocbp = NULL;
  2624. uint32_t portRspPut, portRspMax;
  2625. unsigned long iflag;
  2626. uint32_t status;
  2627. pgp = &phba->port_gp[pring->ringno];
  2628. spin_lock_irqsave(&phba->hbalock, iflag);
  2629. pring->stats.iocb_event++;
  2630. /*
  2631. * The next available response entry should never exceed the maximum
  2632. * entries. If it does, treat it as an adapter hardware error.
  2633. */
  2634. portRspMax = pring->numRiocb;
  2635. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2636. if (portRspPut >= portRspMax) {
  2637. /*
  2638. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2639. * rsp ring <portRspMax>
  2640. */
  2641. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2642. "0303 Ring %d handler: portRspPut %d "
  2643. "is bigger than rsp ring %d\n",
  2644. pring->ringno, portRspPut, portRspMax);
  2645. phba->link_state = LPFC_HBA_ERROR;
  2646. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2647. phba->work_hs = HS_FFER3;
  2648. lpfc_handle_eratt(phba);
  2649. return;
  2650. }
  2651. rmb();
  2652. while (pring->rspidx != portRspPut) {
  2653. /*
  2654. * Build a completion list and call the appropriate handler.
  2655. * The process is to get the next available response iocb, get
  2656. * a free iocb from the list, copy the response data into the
  2657. * free iocb, insert to the continuation list, and update the
  2658. * next response index to slim. This process makes response
  2659. * iocb's in the ring available to DMA as fast as possible but
  2660. * pays a penalty for a copy operation. Since the iocb is
  2661. * only 32 bytes, this penalty is considered small relative to
  2662. * the PCI reads for register values and a slim write. When
  2663. * the ulpLe field is set, the entire Command has been
  2664. * received.
  2665. */
  2666. entry = lpfc_resp_iocb(phba, pring);
  2667. phba->last_completion_time = jiffies;
  2668. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2669. if (rspiocbp == NULL) {
  2670. printk(KERN_ERR "%s: out of buffers! Failing "
  2671. "completion.\n", __func__);
  2672. break;
  2673. }
  2674. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2675. phba->iocb_rsp_size);
  2676. irsp = &rspiocbp->iocb;
  2677. if (++pring->rspidx >= portRspMax)
  2678. pring->rspidx = 0;
  2679. if (pring->ringno == LPFC_ELS_RING) {
  2680. lpfc_debugfs_slow_ring_trc(phba,
  2681. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2682. *(((uint32_t *) irsp) + 4),
  2683. *(((uint32_t *) irsp) + 6),
  2684. *(((uint32_t *) irsp) + 7));
  2685. }
  2686. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2687. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2688. /* Handle the response IOCB */
  2689. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2690. spin_lock_irqsave(&phba->hbalock, iflag);
  2691. /*
  2692. * If the port response put pointer has not been updated, sync
  2693. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2694. * response put pointer.
  2695. */
  2696. if (pring->rspidx == portRspPut) {
  2697. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2698. }
  2699. } /* while (pring->rspidx != portRspPut) */
  2700. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2701. /* At least one response entry has been freed */
  2702. pring->stats.iocb_rsp_full++;
  2703. /* SET RxRE_RSP in Chip Att register */
  2704. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2705. writel(status, phba->CAregaddr);
  2706. readl(phba->CAregaddr); /* flush */
  2707. }
  2708. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2709. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2710. pring->stats.iocb_cmd_empty++;
  2711. /* Force update of the local copy of cmdGetInx */
  2712. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2713. lpfc_sli_resume_iocb(phba, pring);
  2714. if ((pring->lpfc_sli_cmd_available))
  2715. (pring->lpfc_sli_cmd_available) (phba, pring);
  2716. }
  2717. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2718. return;
  2719. }
  2720. /**
  2721. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2722. * @phba: Pointer to HBA context object.
  2723. * @pring: Pointer to driver SLI ring object.
  2724. * @mask: Host attention register mask for this ring.
  2725. *
  2726. * This function is called from the worker thread when there is a pending
  2727. * ELS response iocb on the driver internal slow-path response iocb worker
  2728. * queue. The caller does not hold any lock. The function will remove each
  2729. * response iocb from the response worker queue and calls the handle
  2730. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2731. **/
  2732. static void
  2733. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2734. struct lpfc_sli_ring *pring, uint32_t mask)
  2735. {
  2736. struct lpfc_iocbq *irspiocbq;
  2737. struct hbq_dmabuf *dmabuf;
  2738. struct lpfc_cq_event *cq_event;
  2739. unsigned long iflag;
  2740. spin_lock_irqsave(&phba->hbalock, iflag);
  2741. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2742. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2743. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2744. /* Get the response iocb from the head of work queue */
  2745. spin_lock_irqsave(&phba->hbalock, iflag);
  2746. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2747. cq_event, struct lpfc_cq_event, list);
  2748. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2749. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2750. case CQE_CODE_COMPL_WQE:
  2751. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2752. cq_event);
  2753. /* Translate ELS WCQE to response IOCBQ */
  2754. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2755. irspiocbq);
  2756. if (irspiocbq)
  2757. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2758. irspiocbq);
  2759. break;
  2760. case CQE_CODE_RECEIVE:
  2761. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2762. cq_event);
  2763. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2764. break;
  2765. default:
  2766. break;
  2767. }
  2768. }
  2769. }
  2770. /**
  2771. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2772. * @phba: Pointer to HBA context object.
  2773. * @pring: Pointer to driver SLI ring object.
  2774. *
  2775. * This function aborts all iocbs in the given ring and frees all the iocb
  2776. * objects in txq. This function issues an abort iocb for all the iocb commands
  2777. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2778. * the return of this function. The caller is not required to hold any locks.
  2779. **/
  2780. void
  2781. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2782. {
  2783. LIST_HEAD(completions);
  2784. struct lpfc_iocbq *iocb, *next_iocb;
  2785. if (pring->ringno == LPFC_ELS_RING) {
  2786. lpfc_fabric_abort_hba(phba);
  2787. }
  2788. /* Error everything on txq and txcmplq
  2789. * First do the txq.
  2790. */
  2791. spin_lock_irq(&phba->hbalock);
  2792. list_splice_init(&pring->txq, &completions);
  2793. pring->txq_cnt = 0;
  2794. /* Next issue ABTS for everything on the txcmplq */
  2795. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2796. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2797. spin_unlock_irq(&phba->hbalock);
  2798. /* Cancel all the IOCBs from the completions list */
  2799. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2800. IOERR_SLI_ABORTED);
  2801. }
  2802. /**
  2803. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2804. * @phba: Pointer to HBA context object.
  2805. *
  2806. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2807. * objects in txq and txcmplq. This function will not issue abort iocbs
  2808. * for all the iocb commands in txcmplq, they will just be returned with
  2809. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2810. * slot has been permanently disabled.
  2811. **/
  2812. void
  2813. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2814. {
  2815. LIST_HEAD(txq);
  2816. LIST_HEAD(txcmplq);
  2817. struct lpfc_sli *psli = &phba->sli;
  2818. struct lpfc_sli_ring *pring;
  2819. /* Currently, only one fcp ring */
  2820. pring = &psli->ring[psli->fcp_ring];
  2821. spin_lock_irq(&phba->hbalock);
  2822. /* Retrieve everything on txq */
  2823. list_splice_init(&pring->txq, &txq);
  2824. pring->txq_cnt = 0;
  2825. /* Retrieve everything on the txcmplq */
  2826. list_splice_init(&pring->txcmplq, &txcmplq);
  2827. pring->txcmplq_cnt = 0;
  2828. spin_unlock_irq(&phba->hbalock);
  2829. /* Flush the txq */
  2830. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2831. IOERR_SLI_DOWN);
  2832. /* Flush the txcmpq */
  2833. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2834. IOERR_SLI_DOWN);
  2835. }
  2836. /**
  2837. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2838. * @phba: Pointer to HBA context object.
  2839. * @mask: Bit mask to be checked.
  2840. *
  2841. * This function reads the host status register and compares
  2842. * with the provided bit mask to check if HBA completed
  2843. * the restart. This function will wait in a loop for the
  2844. * HBA to complete restart. If the HBA does not restart within
  2845. * 15 iterations, the function will reset the HBA again. The
  2846. * function returns 1 when HBA fail to restart otherwise returns
  2847. * zero.
  2848. **/
  2849. static int
  2850. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2851. {
  2852. uint32_t status;
  2853. int i = 0;
  2854. int retval = 0;
  2855. /* Read the HBA Host Status Register */
  2856. status = readl(phba->HSregaddr);
  2857. /*
  2858. * Check status register every 100ms for 5 retries, then every
  2859. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2860. * every 2.5 sec for 4.
  2861. * Break our of the loop if errors occurred during init.
  2862. */
  2863. while (((status & mask) != mask) &&
  2864. !(status & HS_FFERM) &&
  2865. i++ < 20) {
  2866. if (i <= 5)
  2867. msleep(10);
  2868. else if (i <= 10)
  2869. msleep(500);
  2870. else
  2871. msleep(2500);
  2872. if (i == 15) {
  2873. /* Do post */
  2874. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2875. lpfc_sli_brdrestart(phba);
  2876. }
  2877. /* Read the HBA Host Status Register */
  2878. status = readl(phba->HSregaddr);
  2879. }
  2880. /* Check to see if any errors occurred during init */
  2881. if ((status & HS_FFERM) || (i >= 20)) {
  2882. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2883. "2751 Adapter failed to restart, "
  2884. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  2885. status,
  2886. readl(phba->MBslimaddr + 0xa8),
  2887. readl(phba->MBslimaddr + 0xac));
  2888. phba->link_state = LPFC_HBA_ERROR;
  2889. retval = 1;
  2890. }
  2891. return retval;
  2892. }
  2893. /**
  2894. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2895. * @phba: Pointer to HBA context object.
  2896. * @mask: Bit mask to be checked.
  2897. *
  2898. * This function checks the host status register to check if HBA is
  2899. * ready. This function will wait in a loop for the HBA to be ready
  2900. * If the HBA is not ready , the function will will reset the HBA PCI
  2901. * function again. The function returns 1 when HBA fail to be ready
  2902. * otherwise returns zero.
  2903. **/
  2904. static int
  2905. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2906. {
  2907. uint32_t status;
  2908. int retval = 0;
  2909. /* Read the HBA Host Status Register */
  2910. status = lpfc_sli4_post_status_check(phba);
  2911. if (status) {
  2912. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2913. lpfc_sli_brdrestart(phba);
  2914. status = lpfc_sli4_post_status_check(phba);
  2915. }
  2916. /* Check to see if any errors occurred during init */
  2917. if (status) {
  2918. phba->link_state = LPFC_HBA_ERROR;
  2919. retval = 1;
  2920. } else
  2921. phba->sli4_hba.intr_enable = 0;
  2922. return retval;
  2923. }
  2924. /**
  2925. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2926. * @phba: Pointer to HBA context object.
  2927. * @mask: Bit mask to be checked.
  2928. *
  2929. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2930. * from the API jump table function pointer from the lpfc_hba struct.
  2931. **/
  2932. int
  2933. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2934. {
  2935. return phba->lpfc_sli_brdready(phba, mask);
  2936. }
  2937. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2938. /**
  2939. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2940. * @phba: Pointer to HBA context object.
  2941. *
  2942. * This function is called before resetting an HBA. This
  2943. * function requests HBA to quiesce DMAs before a reset.
  2944. **/
  2945. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2946. {
  2947. uint32_t __iomem *resp_buf;
  2948. uint32_t __iomem *mbox_buf;
  2949. volatile uint32_t mbox;
  2950. uint32_t hc_copy;
  2951. int i;
  2952. uint8_t hdrtype;
  2953. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2954. if (hdrtype != 0x80 ||
  2955. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2956. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2957. return;
  2958. /*
  2959. * Tell the other part of the chip to suspend temporarily all
  2960. * its DMA activity.
  2961. */
  2962. resp_buf = phba->MBslimaddr;
  2963. /* Disable the error attention */
  2964. hc_copy = readl(phba->HCregaddr);
  2965. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2966. readl(phba->HCregaddr); /* flush */
  2967. phba->link_flag |= LS_IGNORE_ERATT;
  2968. if (readl(phba->HAregaddr) & HA_ERATT) {
  2969. /* Clear Chip error bit */
  2970. writel(HA_ERATT, phba->HAregaddr);
  2971. phba->pport->stopped = 1;
  2972. }
  2973. mbox = 0;
  2974. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2975. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2976. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2977. mbox_buf = phba->MBslimaddr;
  2978. writel(mbox, mbox_buf);
  2979. for (i = 0;
  2980. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2981. mdelay(1);
  2982. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2983. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2984. phba->pport->stopped)
  2985. goto restore_hc;
  2986. else
  2987. goto clear_errat;
  2988. }
  2989. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2990. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2991. mdelay(1);
  2992. clear_errat:
  2993. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2994. mdelay(1);
  2995. if (readl(phba->HAregaddr) & HA_ERATT) {
  2996. writel(HA_ERATT, phba->HAregaddr);
  2997. phba->pport->stopped = 1;
  2998. }
  2999. restore_hc:
  3000. phba->link_flag &= ~LS_IGNORE_ERATT;
  3001. writel(hc_copy, phba->HCregaddr);
  3002. readl(phba->HCregaddr); /* flush */
  3003. }
  3004. /**
  3005. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3006. * @phba: Pointer to HBA context object.
  3007. *
  3008. * This function issues a kill_board mailbox command and waits for
  3009. * the error attention interrupt. This function is called for stopping
  3010. * the firmware processing. The caller is not required to hold any
  3011. * locks. This function calls lpfc_hba_down_post function to free
  3012. * any pending commands after the kill. The function will return 1 when it
  3013. * fails to kill the board else will return 0.
  3014. **/
  3015. int
  3016. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3017. {
  3018. struct lpfc_sli *psli;
  3019. LPFC_MBOXQ_t *pmb;
  3020. uint32_t status;
  3021. uint32_t ha_copy;
  3022. int retval;
  3023. int i = 0;
  3024. psli = &phba->sli;
  3025. /* Kill HBA */
  3026. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3027. "0329 Kill HBA Data: x%x x%x\n",
  3028. phba->pport->port_state, psli->sli_flag);
  3029. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3030. if (!pmb)
  3031. return 1;
  3032. /* Disable the error attention */
  3033. spin_lock_irq(&phba->hbalock);
  3034. status = readl(phba->HCregaddr);
  3035. status &= ~HC_ERINT_ENA;
  3036. writel(status, phba->HCregaddr);
  3037. readl(phba->HCregaddr); /* flush */
  3038. phba->link_flag |= LS_IGNORE_ERATT;
  3039. spin_unlock_irq(&phba->hbalock);
  3040. lpfc_kill_board(phba, pmb);
  3041. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3042. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3043. if (retval != MBX_SUCCESS) {
  3044. if (retval != MBX_BUSY)
  3045. mempool_free(pmb, phba->mbox_mem_pool);
  3046. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3047. "2752 KILL_BOARD command failed retval %d\n",
  3048. retval);
  3049. spin_lock_irq(&phba->hbalock);
  3050. phba->link_flag &= ~LS_IGNORE_ERATT;
  3051. spin_unlock_irq(&phba->hbalock);
  3052. return 1;
  3053. }
  3054. spin_lock_irq(&phba->hbalock);
  3055. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3056. spin_unlock_irq(&phba->hbalock);
  3057. mempool_free(pmb, phba->mbox_mem_pool);
  3058. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3059. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3060. * 3 seconds we still set HBA_ERROR state because the status of the
  3061. * board is now undefined.
  3062. */
  3063. ha_copy = readl(phba->HAregaddr);
  3064. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3065. mdelay(100);
  3066. ha_copy = readl(phba->HAregaddr);
  3067. }
  3068. del_timer_sync(&psli->mbox_tmo);
  3069. if (ha_copy & HA_ERATT) {
  3070. writel(HA_ERATT, phba->HAregaddr);
  3071. phba->pport->stopped = 1;
  3072. }
  3073. spin_lock_irq(&phba->hbalock);
  3074. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3075. psli->mbox_active = NULL;
  3076. phba->link_flag &= ~LS_IGNORE_ERATT;
  3077. spin_unlock_irq(&phba->hbalock);
  3078. lpfc_hba_down_post(phba);
  3079. phba->link_state = LPFC_HBA_ERROR;
  3080. return ha_copy & HA_ERATT ? 0 : 1;
  3081. }
  3082. /**
  3083. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3084. * @phba: Pointer to HBA context object.
  3085. *
  3086. * This function resets the HBA by writing HC_INITFF to the control
  3087. * register. After the HBA resets, this function resets all the iocb ring
  3088. * indices. This function disables PCI layer parity checking during
  3089. * the reset.
  3090. * This function returns 0 always.
  3091. * The caller is not required to hold any locks.
  3092. **/
  3093. int
  3094. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3095. {
  3096. struct lpfc_sli *psli;
  3097. struct lpfc_sli_ring *pring;
  3098. uint16_t cfg_value;
  3099. int i;
  3100. psli = &phba->sli;
  3101. /* Reset HBA */
  3102. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3103. "0325 Reset HBA Data: x%x x%x\n",
  3104. phba->pport->port_state, psli->sli_flag);
  3105. /* perform board reset */
  3106. phba->fc_eventTag = 0;
  3107. phba->link_events = 0;
  3108. phba->pport->fc_myDID = 0;
  3109. phba->pport->fc_prevDID = 0;
  3110. /* Turn off parity checking and serr during the physical reset */
  3111. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3112. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3113. (cfg_value &
  3114. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3115. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3116. /* Now toggle INITFF bit in the Host Control Register */
  3117. writel(HC_INITFF, phba->HCregaddr);
  3118. mdelay(1);
  3119. readl(phba->HCregaddr); /* flush */
  3120. writel(0, phba->HCregaddr);
  3121. readl(phba->HCregaddr); /* flush */
  3122. /* Restore PCI cmd register */
  3123. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3124. /* Initialize relevant SLI info */
  3125. for (i = 0; i < psli->num_rings; i++) {
  3126. pring = &psli->ring[i];
  3127. pring->flag = 0;
  3128. pring->rspidx = 0;
  3129. pring->next_cmdidx = 0;
  3130. pring->local_getidx = 0;
  3131. pring->cmdidx = 0;
  3132. pring->missbufcnt = 0;
  3133. }
  3134. phba->link_state = LPFC_WARM_START;
  3135. return 0;
  3136. }
  3137. /**
  3138. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3139. * @phba: Pointer to HBA context object.
  3140. *
  3141. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3142. * checking during resets the device. The caller is not required to hold
  3143. * any locks.
  3144. *
  3145. * This function returns 0 always.
  3146. **/
  3147. int
  3148. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3149. {
  3150. struct lpfc_sli *psli = &phba->sli;
  3151. uint16_t cfg_value;
  3152. uint8_t qindx;
  3153. /* Reset HBA */
  3154. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3155. "0295 Reset HBA Data: x%x x%x\n",
  3156. phba->pport->port_state, psli->sli_flag);
  3157. /* perform board reset */
  3158. phba->fc_eventTag = 0;
  3159. phba->link_events = 0;
  3160. phba->pport->fc_myDID = 0;
  3161. phba->pport->fc_prevDID = 0;
  3162. /* Turn off parity checking and serr during the physical reset */
  3163. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3164. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3165. (cfg_value &
  3166. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3167. spin_lock_irq(&phba->hbalock);
  3168. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3169. phba->fcf.fcf_flag = 0;
  3170. /* Clean up the child queue list for the CQs */
  3171. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3172. list_del_init(&phba->sli4_hba.els_wq->list);
  3173. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3174. list_del_init(&phba->sli4_hba.dat_rq->list);
  3175. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3176. list_del_init(&phba->sli4_hba.els_cq->list);
  3177. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3178. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3179. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3180. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3181. spin_unlock_irq(&phba->hbalock);
  3182. /* Now physically reset the device */
  3183. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3184. "0389 Performing PCI function reset!\n");
  3185. /* Perform FCoE PCI function reset */
  3186. lpfc_pci_function_reset(phba);
  3187. return 0;
  3188. }
  3189. /**
  3190. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3191. * @phba: Pointer to HBA context object.
  3192. *
  3193. * This function is called in the SLI initialization code path to
  3194. * restart the HBA. The caller is not required to hold any lock.
  3195. * This function writes MBX_RESTART mailbox command to the SLIM and
  3196. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3197. * function to free any pending commands. The function enables
  3198. * POST only during the first initialization. The function returns zero.
  3199. * The function does not guarantee completion of MBX_RESTART mailbox
  3200. * command before the return of this function.
  3201. **/
  3202. static int
  3203. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3204. {
  3205. MAILBOX_t *mb;
  3206. struct lpfc_sli *psli;
  3207. volatile uint32_t word0;
  3208. void __iomem *to_slim;
  3209. uint32_t hba_aer_enabled;
  3210. spin_lock_irq(&phba->hbalock);
  3211. /* Take PCIe device Advanced Error Reporting (AER) state */
  3212. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3213. psli = &phba->sli;
  3214. /* Restart HBA */
  3215. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3216. "0337 Restart HBA Data: x%x x%x\n",
  3217. phba->pport->port_state, psli->sli_flag);
  3218. word0 = 0;
  3219. mb = (MAILBOX_t *) &word0;
  3220. mb->mbxCommand = MBX_RESTART;
  3221. mb->mbxHc = 1;
  3222. lpfc_reset_barrier(phba);
  3223. to_slim = phba->MBslimaddr;
  3224. writel(*(uint32_t *) mb, to_slim);
  3225. readl(to_slim); /* flush */
  3226. /* Only skip post after fc_ffinit is completed */
  3227. if (phba->pport->port_state)
  3228. word0 = 1; /* This is really setting up word1 */
  3229. else
  3230. word0 = 0; /* This is really setting up word1 */
  3231. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3232. writel(*(uint32_t *) mb, to_slim);
  3233. readl(to_slim); /* flush */
  3234. lpfc_sli_brdreset(phba);
  3235. phba->pport->stopped = 0;
  3236. phba->link_state = LPFC_INIT_START;
  3237. phba->hba_flag = 0;
  3238. spin_unlock_irq(&phba->hbalock);
  3239. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3240. psli->stats_start = get_seconds();
  3241. /* Give the INITFF and Post time to settle. */
  3242. mdelay(100);
  3243. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3244. if (hba_aer_enabled)
  3245. pci_disable_pcie_error_reporting(phba->pcidev);
  3246. lpfc_hba_down_post(phba);
  3247. return 0;
  3248. }
  3249. /**
  3250. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3251. * @phba: Pointer to HBA context object.
  3252. *
  3253. * This function is called in the SLI initialization code path to restart
  3254. * a SLI4 HBA. The caller is not required to hold any lock.
  3255. * At the end of the function, it calls lpfc_hba_down_post function to
  3256. * free any pending commands.
  3257. **/
  3258. static int
  3259. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3260. {
  3261. struct lpfc_sli *psli = &phba->sli;
  3262. /* Restart HBA */
  3263. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3264. "0296 Restart HBA Data: x%x x%x\n",
  3265. phba->pport->port_state, psli->sli_flag);
  3266. lpfc_sli4_brdreset(phba);
  3267. spin_lock_irq(&phba->hbalock);
  3268. phba->pport->stopped = 0;
  3269. phba->link_state = LPFC_INIT_START;
  3270. phba->hba_flag = 0;
  3271. spin_unlock_irq(&phba->hbalock);
  3272. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3273. psli->stats_start = get_seconds();
  3274. lpfc_hba_down_post(phba);
  3275. return 0;
  3276. }
  3277. /**
  3278. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3279. * @phba: Pointer to HBA context object.
  3280. *
  3281. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3282. * API jump table function pointer from the lpfc_hba struct.
  3283. **/
  3284. int
  3285. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3286. {
  3287. return phba->lpfc_sli_brdrestart(phba);
  3288. }
  3289. /**
  3290. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3291. * @phba: Pointer to HBA context object.
  3292. *
  3293. * This function is called after a HBA restart to wait for successful
  3294. * restart of the HBA. Successful restart of the HBA is indicated by
  3295. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3296. * iteration, the function will restart the HBA again. The function returns
  3297. * zero if HBA successfully restarted else returns negative error code.
  3298. **/
  3299. static int
  3300. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3301. {
  3302. uint32_t status, i = 0;
  3303. /* Read the HBA Host Status Register */
  3304. status = readl(phba->HSregaddr);
  3305. /* Check status register to see what current state is */
  3306. i = 0;
  3307. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3308. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3309. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3310. * 4.
  3311. */
  3312. if (i++ >= 20) {
  3313. /* Adapter failed to init, timeout, status reg
  3314. <status> */
  3315. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3316. "0436 Adapter failed to init, "
  3317. "timeout, status reg x%x, "
  3318. "FW Data: A8 x%x AC x%x\n", status,
  3319. readl(phba->MBslimaddr + 0xa8),
  3320. readl(phba->MBslimaddr + 0xac));
  3321. phba->link_state = LPFC_HBA_ERROR;
  3322. return -ETIMEDOUT;
  3323. }
  3324. /* Check to see if any errors occurred during init */
  3325. if (status & HS_FFERM) {
  3326. /* ERROR: During chipset initialization */
  3327. /* Adapter failed to init, chipset, status reg
  3328. <status> */
  3329. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3330. "0437 Adapter failed to init, "
  3331. "chipset, status reg x%x, "
  3332. "FW Data: A8 x%x AC x%x\n", status,
  3333. readl(phba->MBslimaddr + 0xa8),
  3334. readl(phba->MBslimaddr + 0xac));
  3335. phba->link_state = LPFC_HBA_ERROR;
  3336. return -EIO;
  3337. }
  3338. if (i <= 5) {
  3339. msleep(10);
  3340. } else if (i <= 10) {
  3341. msleep(500);
  3342. } else {
  3343. msleep(2500);
  3344. }
  3345. if (i == 15) {
  3346. /* Do post */
  3347. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3348. lpfc_sli_brdrestart(phba);
  3349. }
  3350. /* Read the HBA Host Status Register */
  3351. status = readl(phba->HSregaddr);
  3352. }
  3353. /* Check to see if any errors occurred during init */
  3354. if (status & HS_FFERM) {
  3355. /* ERROR: During chipset initialization */
  3356. /* Adapter failed to init, chipset, status reg <status> */
  3357. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3358. "0438 Adapter failed to init, chipset, "
  3359. "status reg x%x, "
  3360. "FW Data: A8 x%x AC x%x\n", status,
  3361. readl(phba->MBslimaddr + 0xa8),
  3362. readl(phba->MBslimaddr + 0xac));
  3363. phba->link_state = LPFC_HBA_ERROR;
  3364. return -EIO;
  3365. }
  3366. /* Clear all interrupt enable conditions */
  3367. writel(0, phba->HCregaddr);
  3368. readl(phba->HCregaddr); /* flush */
  3369. /* setup host attn register */
  3370. writel(0xffffffff, phba->HAregaddr);
  3371. readl(phba->HAregaddr); /* flush */
  3372. return 0;
  3373. }
  3374. /**
  3375. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3376. *
  3377. * This function calculates and returns the number of HBQs required to be
  3378. * configured.
  3379. **/
  3380. int
  3381. lpfc_sli_hbq_count(void)
  3382. {
  3383. return ARRAY_SIZE(lpfc_hbq_defs);
  3384. }
  3385. /**
  3386. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3387. *
  3388. * This function adds the number of hbq entries in every HBQ to get
  3389. * the total number of hbq entries required for the HBA and returns
  3390. * the total count.
  3391. **/
  3392. static int
  3393. lpfc_sli_hbq_entry_count(void)
  3394. {
  3395. int hbq_count = lpfc_sli_hbq_count();
  3396. int count = 0;
  3397. int i;
  3398. for (i = 0; i < hbq_count; ++i)
  3399. count += lpfc_hbq_defs[i]->entry_count;
  3400. return count;
  3401. }
  3402. /**
  3403. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3404. *
  3405. * This function calculates amount of memory required for all hbq entries
  3406. * to be configured and returns the total memory required.
  3407. **/
  3408. int
  3409. lpfc_sli_hbq_size(void)
  3410. {
  3411. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3412. }
  3413. /**
  3414. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3415. * @phba: Pointer to HBA context object.
  3416. *
  3417. * This function is called during the SLI initialization to configure
  3418. * all the HBQs and post buffers to the HBQ. The caller is not
  3419. * required to hold any locks. This function will return zero if successful
  3420. * else it will return negative error code.
  3421. **/
  3422. static int
  3423. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3424. {
  3425. int hbq_count = lpfc_sli_hbq_count();
  3426. LPFC_MBOXQ_t *pmb;
  3427. MAILBOX_t *pmbox;
  3428. uint32_t hbqno;
  3429. uint32_t hbq_entry_index;
  3430. /* Get a Mailbox buffer to setup mailbox
  3431. * commands for HBA initialization
  3432. */
  3433. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3434. if (!pmb)
  3435. return -ENOMEM;
  3436. pmbox = &pmb->u.mb;
  3437. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3438. phba->link_state = LPFC_INIT_MBX_CMDS;
  3439. phba->hbq_in_use = 1;
  3440. hbq_entry_index = 0;
  3441. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3442. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3443. phba->hbqs[hbqno].hbqPutIdx = 0;
  3444. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3445. phba->hbqs[hbqno].entry_count =
  3446. lpfc_hbq_defs[hbqno]->entry_count;
  3447. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3448. hbq_entry_index, pmb);
  3449. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3450. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3451. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3452. mbxStatus <status>, ring <num> */
  3453. lpfc_printf_log(phba, KERN_ERR,
  3454. LOG_SLI | LOG_VPORT,
  3455. "1805 Adapter failed to init. "
  3456. "Data: x%x x%x x%x\n",
  3457. pmbox->mbxCommand,
  3458. pmbox->mbxStatus, hbqno);
  3459. phba->link_state = LPFC_HBA_ERROR;
  3460. mempool_free(pmb, phba->mbox_mem_pool);
  3461. return -ENXIO;
  3462. }
  3463. }
  3464. phba->hbq_count = hbq_count;
  3465. mempool_free(pmb, phba->mbox_mem_pool);
  3466. /* Initially populate or replenish the HBQs */
  3467. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3468. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3469. return 0;
  3470. }
  3471. /**
  3472. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3473. * @phba: Pointer to HBA context object.
  3474. *
  3475. * This function is called during the SLI initialization to configure
  3476. * all the HBQs and post buffers to the HBQ. The caller is not
  3477. * required to hold any locks. This function will return zero if successful
  3478. * else it will return negative error code.
  3479. **/
  3480. static int
  3481. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3482. {
  3483. phba->hbq_in_use = 1;
  3484. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3485. phba->hbq_count = 1;
  3486. /* Initially populate or replenish the HBQs */
  3487. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3488. return 0;
  3489. }
  3490. /**
  3491. * lpfc_sli_config_port - Issue config port mailbox command
  3492. * @phba: Pointer to HBA context object.
  3493. * @sli_mode: sli mode - 2/3
  3494. *
  3495. * This function is called by the sli intialization code path
  3496. * to issue config_port mailbox command. This function restarts the
  3497. * HBA firmware and issues a config_port mailbox command to configure
  3498. * the SLI interface in the sli mode specified by sli_mode
  3499. * variable. The caller is not required to hold any locks.
  3500. * The function returns 0 if successful, else returns negative error
  3501. * code.
  3502. **/
  3503. int
  3504. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3505. {
  3506. LPFC_MBOXQ_t *pmb;
  3507. uint32_t resetcount = 0, rc = 0, done = 0;
  3508. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3509. if (!pmb) {
  3510. phba->link_state = LPFC_HBA_ERROR;
  3511. return -ENOMEM;
  3512. }
  3513. phba->sli_rev = sli_mode;
  3514. while (resetcount < 2 && !done) {
  3515. spin_lock_irq(&phba->hbalock);
  3516. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3517. spin_unlock_irq(&phba->hbalock);
  3518. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3519. lpfc_sli_brdrestart(phba);
  3520. rc = lpfc_sli_chipset_init(phba);
  3521. if (rc)
  3522. break;
  3523. spin_lock_irq(&phba->hbalock);
  3524. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3525. spin_unlock_irq(&phba->hbalock);
  3526. resetcount++;
  3527. /* Call pre CONFIG_PORT mailbox command initialization. A
  3528. * value of 0 means the call was successful. Any other
  3529. * nonzero value is a failure, but if ERESTART is returned,
  3530. * the driver may reset the HBA and try again.
  3531. */
  3532. rc = lpfc_config_port_prep(phba);
  3533. if (rc == -ERESTART) {
  3534. phba->link_state = LPFC_LINK_UNKNOWN;
  3535. continue;
  3536. } else if (rc)
  3537. break;
  3538. phba->link_state = LPFC_INIT_MBX_CMDS;
  3539. lpfc_config_port(phba, pmb);
  3540. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3541. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3542. LPFC_SLI3_HBQ_ENABLED |
  3543. LPFC_SLI3_CRP_ENABLED |
  3544. LPFC_SLI3_BG_ENABLED);
  3545. if (rc != MBX_SUCCESS) {
  3546. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3547. "0442 Adapter failed to init, mbxCmd x%x "
  3548. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3549. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3550. spin_lock_irq(&phba->hbalock);
  3551. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3552. spin_unlock_irq(&phba->hbalock);
  3553. rc = -ENXIO;
  3554. } else {
  3555. /* Allow asynchronous mailbox command to go through */
  3556. spin_lock_irq(&phba->hbalock);
  3557. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3558. spin_unlock_irq(&phba->hbalock);
  3559. done = 1;
  3560. }
  3561. }
  3562. if (!done) {
  3563. rc = -EINVAL;
  3564. goto do_prep_failed;
  3565. }
  3566. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3567. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3568. rc = -ENXIO;
  3569. goto do_prep_failed;
  3570. }
  3571. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3572. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3573. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3574. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3575. phba->max_vpi : phba->max_vports;
  3576. } else
  3577. phba->max_vpi = 0;
  3578. if (pmb->u.mb.un.varCfgPort.gdss)
  3579. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3580. if (pmb->u.mb.un.varCfgPort.gerbm)
  3581. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3582. if (pmb->u.mb.un.varCfgPort.gcrp)
  3583. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3584. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3585. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3586. if (phba->cfg_enable_bg) {
  3587. if (pmb->u.mb.un.varCfgPort.gbg)
  3588. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3589. else
  3590. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3591. "0443 Adapter did not grant "
  3592. "BlockGuard\n");
  3593. }
  3594. } else {
  3595. phba->hbq_get = NULL;
  3596. phba->port_gp = phba->mbox->us.s2.port;
  3597. phba->max_vpi = 0;
  3598. }
  3599. do_prep_failed:
  3600. mempool_free(pmb, phba->mbox_mem_pool);
  3601. return rc;
  3602. }
  3603. /**
  3604. * lpfc_sli_hba_setup - SLI intialization function
  3605. * @phba: Pointer to HBA context object.
  3606. *
  3607. * This function is the main SLI intialization function. This function
  3608. * is called by the HBA intialization code, HBA reset code and HBA
  3609. * error attention handler code. Caller is not required to hold any
  3610. * locks. This function issues config_port mailbox command to configure
  3611. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3612. * calls the config_port_post function to issue init_link mailbox
  3613. * command and to start the discovery. The function will return zero
  3614. * if successful, else it will return negative error code.
  3615. **/
  3616. int
  3617. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3618. {
  3619. uint32_t rc;
  3620. int mode = 3;
  3621. switch (lpfc_sli_mode) {
  3622. case 2:
  3623. if (phba->cfg_enable_npiv) {
  3624. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3625. "1824 NPIV enabled: Override lpfc_sli_mode "
  3626. "parameter (%d) to auto (0).\n",
  3627. lpfc_sli_mode);
  3628. break;
  3629. }
  3630. mode = 2;
  3631. break;
  3632. case 0:
  3633. case 3:
  3634. break;
  3635. default:
  3636. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3637. "1819 Unrecognized lpfc_sli_mode "
  3638. "parameter: %d.\n", lpfc_sli_mode);
  3639. break;
  3640. }
  3641. rc = lpfc_sli_config_port(phba, mode);
  3642. if (rc && lpfc_sli_mode == 3)
  3643. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3644. "1820 Unable to select SLI-3. "
  3645. "Not supported by adapter.\n");
  3646. if (rc && mode != 2)
  3647. rc = lpfc_sli_config_port(phba, 2);
  3648. if (rc)
  3649. goto lpfc_sli_hba_setup_error;
  3650. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3651. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3652. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3653. if (!rc) {
  3654. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3655. "2709 This device supports "
  3656. "Advanced Error Reporting (AER)\n");
  3657. spin_lock_irq(&phba->hbalock);
  3658. phba->hba_flag |= HBA_AER_ENABLED;
  3659. spin_unlock_irq(&phba->hbalock);
  3660. } else {
  3661. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3662. "2708 This device does not support "
  3663. "Advanced Error Reporting (AER)\n");
  3664. phba->cfg_aer_support = 0;
  3665. }
  3666. }
  3667. if (phba->sli_rev == 3) {
  3668. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3669. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3670. } else {
  3671. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3672. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3673. phba->sli3_options = 0;
  3674. }
  3675. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3676. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3677. phba->sli_rev, phba->max_vpi);
  3678. rc = lpfc_sli_ring_map(phba);
  3679. if (rc)
  3680. goto lpfc_sli_hba_setup_error;
  3681. /* Init HBQs */
  3682. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3683. rc = lpfc_sli_hbq_setup(phba);
  3684. if (rc)
  3685. goto lpfc_sli_hba_setup_error;
  3686. }
  3687. spin_lock_irq(&phba->hbalock);
  3688. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3689. spin_unlock_irq(&phba->hbalock);
  3690. rc = lpfc_config_port_post(phba);
  3691. if (rc)
  3692. goto lpfc_sli_hba_setup_error;
  3693. return rc;
  3694. lpfc_sli_hba_setup_error:
  3695. phba->link_state = LPFC_HBA_ERROR;
  3696. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3697. "0445 Firmware initialization failed\n");
  3698. return rc;
  3699. }
  3700. /**
  3701. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3702. * @phba: Pointer to HBA context object.
  3703. * @mboxq: mailbox pointer.
  3704. * This function issue a dump mailbox command to read config region
  3705. * 23 and parse the records in the region and populate driver
  3706. * data structure.
  3707. **/
  3708. static int
  3709. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3710. LPFC_MBOXQ_t *mboxq)
  3711. {
  3712. struct lpfc_dmabuf *mp;
  3713. struct lpfc_mqe *mqe;
  3714. uint32_t data_length;
  3715. int rc;
  3716. /* Program the default value of vlan_id and fc_map */
  3717. phba->valid_vlan = 0;
  3718. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3719. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3720. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3721. mqe = &mboxq->u.mqe;
  3722. if (lpfc_dump_fcoe_param(phba, mboxq))
  3723. return -ENOMEM;
  3724. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3725. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3726. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3727. "(%d):2571 Mailbox cmd x%x Status x%x "
  3728. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3729. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3730. "CQ: x%x x%x x%x x%x\n",
  3731. mboxq->vport ? mboxq->vport->vpi : 0,
  3732. bf_get(lpfc_mqe_command, mqe),
  3733. bf_get(lpfc_mqe_status, mqe),
  3734. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3735. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3736. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3737. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3738. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3739. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3740. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3741. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3742. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3743. mboxq->mcqe.word0,
  3744. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3745. mboxq->mcqe.trailer);
  3746. if (rc) {
  3747. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3748. kfree(mp);
  3749. return -EIO;
  3750. }
  3751. data_length = mqe->un.mb_words[5];
  3752. if (data_length > DMP_RGN23_SIZE) {
  3753. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3754. kfree(mp);
  3755. return -EIO;
  3756. }
  3757. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3758. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3759. kfree(mp);
  3760. return 0;
  3761. }
  3762. /**
  3763. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3764. * @phba: pointer to lpfc hba data structure.
  3765. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3766. * @vpd: pointer to the memory to hold resulting port vpd data.
  3767. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3768. * On output, the number of data bytes in @vpd.
  3769. *
  3770. * This routine executes a READ_REV SLI4 mailbox command. In
  3771. * addition, this routine gets the port vpd data.
  3772. *
  3773. * Return codes
  3774. * 0 - successful
  3775. * ENOMEM - could not allocated memory.
  3776. **/
  3777. static int
  3778. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3779. uint8_t *vpd, uint32_t *vpd_size)
  3780. {
  3781. int rc = 0;
  3782. uint32_t dma_size;
  3783. struct lpfc_dmabuf *dmabuf;
  3784. struct lpfc_mqe *mqe;
  3785. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3786. if (!dmabuf)
  3787. return -ENOMEM;
  3788. /*
  3789. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3790. * mailbox command.
  3791. */
  3792. dma_size = *vpd_size;
  3793. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3794. dma_size,
  3795. &dmabuf->phys,
  3796. GFP_KERNEL);
  3797. if (!dmabuf->virt) {
  3798. kfree(dmabuf);
  3799. return -ENOMEM;
  3800. }
  3801. memset(dmabuf->virt, 0, dma_size);
  3802. /*
  3803. * The SLI4 implementation of READ_REV conflicts at word1,
  3804. * bits 31:16 and SLI4 adds vpd functionality not present
  3805. * in SLI3. This code corrects the conflicts.
  3806. */
  3807. lpfc_read_rev(phba, mboxq);
  3808. mqe = &mboxq->u.mqe;
  3809. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3810. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3811. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3812. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3813. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3814. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3815. if (rc) {
  3816. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3817. dmabuf->virt, dmabuf->phys);
  3818. kfree(dmabuf);
  3819. return -EIO;
  3820. }
  3821. /*
  3822. * The available vpd length cannot be bigger than the
  3823. * DMA buffer passed to the port. Catch the less than
  3824. * case and update the caller's size.
  3825. */
  3826. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3827. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3828. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3829. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3830. dmabuf->virt, dmabuf->phys);
  3831. kfree(dmabuf);
  3832. return 0;
  3833. }
  3834. /**
  3835. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3836. * @phba: pointer to lpfc hba data structure.
  3837. *
  3838. * This routine is called to explicitly arm the SLI4 device's completion and
  3839. * event queues
  3840. **/
  3841. static void
  3842. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3843. {
  3844. uint8_t fcp_eqidx;
  3845. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3846. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3847. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3848. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3849. LPFC_QUEUE_REARM);
  3850. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3851. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3852. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3853. LPFC_QUEUE_REARM);
  3854. }
  3855. /**
  3856. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3857. * @phba: Pointer to HBA context object.
  3858. *
  3859. * This function is the main SLI4 device intialization PCI function. This
  3860. * function is called by the HBA intialization code, HBA reset code and
  3861. * HBA error attention handler code. Caller is not required to hold any
  3862. * locks.
  3863. **/
  3864. int
  3865. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3866. {
  3867. int rc;
  3868. LPFC_MBOXQ_t *mboxq;
  3869. struct lpfc_mqe *mqe;
  3870. uint8_t *vpd;
  3871. uint32_t vpd_size;
  3872. uint32_t ftr_rsp = 0;
  3873. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3874. struct lpfc_vport *vport = phba->pport;
  3875. struct lpfc_dmabuf *mp;
  3876. /* Perform a PCI function reset to start from clean */
  3877. rc = lpfc_pci_function_reset(phba);
  3878. if (unlikely(rc))
  3879. return -ENODEV;
  3880. /* Check the HBA Host Status Register for readyness */
  3881. rc = lpfc_sli4_post_status_check(phba);
  3882. if (unlikely(rc))
  3883. return -ENODEV;
  3884. else {
  3885. spin_lock_irq(&phba->hbalock);
  3886. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3887. spin_unlock_irq(&phba->hbalock);
  3888. }
  3889. /*
  3890. * Allocate a single mailbox container for initializing the
  3891. * port.
  3892. */
  3893. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3894. if (!mboxq)
  3895. return -ENOMEM;
  3896. /*
  3897. * Continue initialization with default values even if driver failed
  3898. * to read FCoE param config regions
  3899. */
  3900. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3901. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3902. "2570 Failed to read FCoE parameters\n");
  3903. /* Issue READ_REV to collect vpd and FW information. */
  3904. vpd_size = SLI4_PAGE_SIZE;
  3905. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3906. if (!vpd) {
  3907. rc = -ENOMEM;
  3908. goto out_free_mbox;
  3909. }
  3910. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3911. if (unlikely(rc))
  3912. goto out_free_vpd;
  3913. mqe = &mboxq->u.mqe;
  3914. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3915. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3916. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3917. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3918. LPFC_DCBX_CEE_MODE)
  3919. phba->hba_flag |= HBA_FIP_SUPPORT;
  3920. else
  3921. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3922. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3923. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3924. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3925. "0376 READ_REV Error. SLI Level %d "
  3926. "FCoE enabled %d\n",
  3927. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3928. rc = -EIO;
  3929. goto out_free_vpd;
  3930. }
  3931. /*
  3932. * Evaluate the read rev and vpd data. Populate the driver
  3933. * state with the results. If this routine fails, the failure
  3934. * is not fatal as the driver will use generic values.
  3935. */
  3936. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3937. if (unlikely(!rc)) {
  3938. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3939. "0377 Error %d parsing vpd. "
  3940. "Using defaults.\n", rc);
  3941. rc = 0;
  3942. }
  3943. /* Save information as VPD data */
  3944. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3945. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3946. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3947. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3948. &mqe->un.read_rev);
  3949. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3950. &mqe->un.read_rev);
  3951. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3952. &mqe->un.read_rev);
  3953. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3954. &mqe->un.read_rev);
  3955. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3956. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3957. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3958. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3959. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3960. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3961. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3962. "(%d):0380 READ_REV Status x%x "
  3963. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3964. mboxq->vport ? mboxq->vport->vpi : 0,
  3965. bf_get(lpfc_mqe_status, mqe),
  3966. phba->vpd.rev.opFwName,
  3967. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3968. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3969. /*
  3970. * Discover the port's supported feature set and match it against the
  3971. * hosts requests.
  3972. */
  3973. lpfc_request_features(phba, mboxq);
  3974. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3975. if (unlikely(rc)) {
  3976. rc = -EIO;
  3977. goto out_free_vpd;
  3978. }
  3979. /*
  3980. * The port must support FCP initiator mode as this is the
  3981. * only mode running in the host.
  3982. */
  3983. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3984. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3985. "0378 No support for fcpi mode.\n");
  3986. ftr_rsp++;
  3987. }
  3988. /*
  3989. * If the port cannot support the host's requested features
  3990. * then turn off the global config parameters to disable the
  3991. * feature in the driver. This is not a fatal error.
  3992. */
  3993. if ((phba->cfg_enable_bg) &&
  3994. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3995. ftr_rsp++;
  3996. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3997. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3998. ftr_rsp++;
  3999. if (ftr_rsp) {
  4000. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4001. "0379 Feature Mismatch Data: x%08x %08x "
  4002. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4003. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4004. phba->cfg_enable_npiv, phba->max_vpi);
  4005. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4006. phba->cfg_enable_bg = 0;
  4007. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4008. phba->cfg_enable_npiv = 0;
  4009. }
  4010. /* These SLI3 features are assumed in SLI4 */
  4011. spin_lock_irq(&phba->hbalock);
  4012. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4013. spin_unlock_irq(&phba->hbalock);
  4014. /* Read the port's service parameters. */
  4015. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4016. if (rc) {
  4017. phba->link_state = LPFC_HBA_ERROR;
  4018. rc = -ENOMEM;
  4019. goto out_free_vpd;
  4020. }
  4021. mboxq->vport = vport;
  4022. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4023. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4024. if (rc == MBX_SUCCESS) {
  4025. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4026. rc = 0;
  4027. }
  4028. /*
  4029. * This memory was allocated by the lpfc_read_sparam routine. Release
  4030. * it to the mbuf pool.
  4031. */
  4032. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4033. kfree(mp);
  4034. mboxq->context1 = NULL;
  4035. if (unlikely(rc)) {
  4036. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4037. "0382 READ_SPARAM command failed "
  4038. "status %d, mbxStatus x%x\n",
  4039. rc, bf_get(lpfc_mqe_status, mqe));
  4040. phba->link_state = LPFC_HBA_ERROR;
  4041. rc = -EIO;
  4042. goto out_free_vpd;
  4043. }
  4044. if (phba->cfg_soft_wwnn)
  4045. u64_to_wwn(phba->cfg_soft_wwnn,
  4046. vport->fc_sparam.nodeName.u.wwn);
  4047. if (phba->cfg_soft_wwpn)
  4048. u64_to_wwn(phba->cfg_soft_wwpn,
  4049. vport->fc_sparam.portName.u.wwn);
  4050. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4051. sizeof(struct lpfc_name));
  4052. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4053. sizeof(struct lpfc_name));
  4054. /* Update the fc_host data structures with new wwn. */
  4055. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4056. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4057. /* Register SGL pool to the device using non-embedded mailbox command */
  4058. rc = lpfc_sli4_post_sgl_list(phba);
  4059. if (unlikely(rc)) {
  4060. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4061. "0582 Error %d during sgl post operation\n",
  4062. rc);
  4063. rc = -ENODEV;
  4064. goto out_free_vpd;
  4065. }
  4066. /* Register SCSI SGL pool to the device */
  4067. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4068. if (unlikely(rc)) {
  4069. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4070. "0383 Error %d during scsi sgl post "
  4071. "operation\n", rc);
  4072. /* Some Scsi buffers were moved to the abort scsi list */
  4073. /* A pci function reset will repost them */
  4074. rc = -ENODEV;
  4075. goto out_free_vpd;
  4076. }
  4077. /* Post the rpi header region to the device. */
  4078. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4079. if (unlikely(rc)) {
  4080. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4081. "0393 Error %d during rpi post operation\n",
  4082. rc);
  4083. rc = -ENODEV;
  4084. goto out_free_vpd;
  4085. }
  4086. /* Set up all the queues to the device */
  4087. rc = lpfc_sli4_queue_setup(phba);
  4088. if (unlikely(rc)) {
  4089. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4090. "0381 Error %d during queue setup.\n ", rc);
  4091. goto out_stop_timers;
  4092. }
  4093. /* Arm the CQs and then EQs on device */
  4094. lpfc_sli4_arm_cqeq_intr(phba);
  4095. /* Indicate device interrupt mode */
  4096. phba->sli4_hba.intr_enable = 1;
  4097. /* Allow asynchronous mailbox command to go through */
  4098. spin_lock_irq(&phba->hbalock);
  4099. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4100. spin_unlock_irq(&phba->hbalock);
  4101. /* Post receive buffers to the device */
  4102. lpfc_sli4_rb_setup(phba);
  4103. /* Reset HBA FCF states after HBA reset */
  4104. phba->fcf.fcf_flag = 0;
  4105. phba->fcf.current_rec.flag = 0;
  4106. /* Start the ELS watchdog timer */
  4107. mod_timer(&vport->els_tmofunc,
  4108. jiffies + HZ * (phba->fc_ratov * 2));
  4109. /* Start heart beat timer */
  4110. mod_timer(&phba->hb_tmofunc,
  4111. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4112. phba->hb_outstanding = 0;
  4113. phba->last_completion_time = jiffies;
  4114. /* Start error attention (ERATT) polling timer */
  4115. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4116. /*
  4117. * The port is ready, set the host's link state to LINK_DOWN
  4118. * in preparation for link interrupts.
  4119. */
  4120. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4121. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4122. lpfc_set_loopback_flag(phba);
  4123. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4124. spin_lock_irq(&phba->hbalock);
  4125. phba->link_state = LPFC_LINK_DOWN;
  4126. spin_unlock_irq(&phba->hbalock);
  4127. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4128. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4129. kfree(vpd);
  4130. return 0;
  4131. } else
  4132. rc = -EIO;
  4133. /* Unset all the queues set up in this routine when error out */
  4134. if (rc)
  4135. lpfc_sli4_queue_unset(phba);
  4136. out_stop_timers:
  4137. if (rc)
  4138. lpfc_stop_hba_timers(phba);
  4139. out_free_vpd:
  4140. kfree(vpd);
  4141. out_free_mbox:
  4142. mempool_free(mboxq, phba->mbox_mem_pool);
  4143. return rc;
  4144. }
  4145. /**
  4146. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4147. * @ptr: context object - pointer to hba structure.
  4148. *
  4149. * This is the callback function for mailbox timer. The mailbox
  4150. * timer is armed when a new mailbox command is issued and the timer
  4151. * is deleted when the mailbox complete. The function is called by
  4152. * the kernel timer code when a mailbox does not complete within
  4153. * expected time. This function wakes up the worker thread to
  4154. * process the mailbox timeout and returns. All the processing is
  4155. * done by the worker thread function lpfc_mbox_timeout_handler.
  4156. **/
  4157. void
  4158. lpfc_mbox_timeout(unsigned long ptr)
  4159. {
  4160. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4161. unsigned long iflag;
  4162. uint32_t tmo_posted;
  4163. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4164. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4165. if (!tmo_posted)
  4166. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4167. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4168. if (!tmo_posted)
  4169. lpfc_worker_wake_up(phba);
  4170. return;
  4171. }
  4172. /**
  4173. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4174. * @phba: Pointer to HBA context object.
  4175. *
  4176. * This function is called from worker thread when a mailbox command times out.
  4177. * The caller is not required to hold any locks. This function will reset the
  4178. * HBA and recover all the pending commands.
  4179. **/
  4180. void
  4181. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4182. {
  4183. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4184. MAILBOX_t *mb = &pmbox->u.mb;
  4185. struct lpfc_sli *psli = &phba->sli;
  4186. struct lpfc_sli_ring *pring;
  4187. /* Check the pmbox pointer first. There is a race condition
  4188. * between the mbox timeout handler getting executed in the
  4189. * worklist and the mailbox actually completing. When this
  4190. * race condition occurs, the mbox_active will be NULL.
  4191. */
  4192. spin_lock_irq(&phba->hbalock);
  4193. if (pmbox == NULL) {
  4194. lpfc_printf_log(phba, KERN_WARNING,
  4195. LOG_MBOX | LOG_SLI,
  4196. "0353 Active Mailbox cleared - mailbox timeout "
  4197. "exiting\n");
  4198. spin_unlock_irq(&phba->hbalock);
  4199. return;
  4200. }
  4201. /* Mbox cmd <mbxCommand> timeout */
  4202. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4203. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4204. mb->mbxCommand,
  4205. phba->pport->port_state,
  4206. phba->sli.sli_flag,
  4207. phba->sli.mbox_active);
  4208. spin_unlock_irq(&phba->hbalock);
  4209. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4210. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4211. * it to fail all oustanding SCSI IO.
  4212. */
  4213. spin_lock_irq(&phba->pport->work_port_lock);
  4214. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4215. spin_unlock_irq(&phba->pport->work_port_lock);
  4216. spin_lock_irq(&phba->hbalock);
  4217. phba->link_state = LPFC_LINK_UNKNOWN;
  4218. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4219. spin_unlock_irq(&phba->hbalock);
  4220. pring = &psli->ring[psli->fcp_ring];
  4221. lpfc_sli_abort_iocb_ring(phba, pring);
  4222. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4223. "0345 Resetting board due to mailbox timeout\n");
  4224. /* Reset the HBA device */
  4225. lpfc_reset_hba(phba);
  4226. }
  4227. /**
  4228. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4229. * @phba: Pointer to HBA context object.
  4230. * @pmbox: Pointer to mailbox object.
  4231. * @flag: Flag indicating how the mailbox need to be processed.
  4232. *
  4233. * This function is called by discovery code and HBA management code
  4234. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4235. * function gets the hbalock to protect the data structures.
  4236. * The mailbox command can be submitted in polling mode, in which case
  4237. * this function will wait in a polling loop for the completion of the
  4238. * mailbox.
  4239. * If the mailbox is submitted in no_wait mode (not polling) the
  4240. * function will submit the command and returns immediately without waiting
  4241. * for the mailbox completion. The no_wait is supported only when HBA
  4242. * is in SLI2/SLI3 mode - interrupts are enabled.
  4243. * The SLI interface allows only one mailbox pending at a time. If the
  4244. * mailbox is issued in polling mode and there is already a mailbox
  4245. * pending, then the function will return an error. If the mailbox is issued
  4246. * in NO_WAIT mode and there is a mailbox pending already, the function
  4247. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4248. * The sli layer owns the mailbox object until the completion of mailbox
  4249. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4250. * return codes the caller owns the mailbox command after the return of
  4251. * the function.
  4252. **/
  4253. static int
  4254. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4255. uint32_t flag)
  4256. {
  4257. MAILBOX_t *mb;
  4258. struct lpfc_sli *psli = &phba->sli;
  4259. uint32_t status, evtctr;
  4260. uint32_t ha_copy;
  4261. int i;
  4262. unsigned long timeout;
  4263. unsigned long drvr_flag = 0;
  4264. uint32_t word0, ldata;
  4265. void __iomem *to_slim;
  4266. int processing_queue = 0;
  4267. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4268. if (!pmbox) {
  4269. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4270. /* processing mbox queue from intr_handler */
  4271. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4272. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4273. return MBX_SUCCESS;
  4274. }
  4275. processing_queue = 1;
  4276. pmbox = lpfc_mbox_get(phba);
  4277. if (!pmbox) {
  4278. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4279. return MBX_SUCCESS;
  4280. }
  4281. }
  4282. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4283. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4284. if(!pmbox->vport) {
  4285. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4286. lpfc_printf_log(phba, KERN_ERR,
  4287. LOG_MBOX | LOG_VPORT,
  4288. "1806 Mbox x%x failed. No vport\n",
  4289. pmbox->u.mb.mbxCommand);
  4290. dump_stack();
  4291. goto out_not_finished;
  4292. }
  4293. }
  4294. /* If the PCI channel is in offline state, do not post mbox. */
  4295. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4296. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4297. goto out_not_finished;
  4298. }
  4299. /* If HBA has a deferred error attention, fail the iocb. */
  4300. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4301. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4302. goto out_not_finished;
  4303. }
  4304. psli = &phba->sli;
  4305. mb = &pmbox->u.mb;
  4306. status = MBX_SUCCESS;
  4307. if (phba->link_state == LPFC_HBA_ERROR) {
  4308. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4309. /* Mbox command <mbxCommand> cannot issue */
  4310. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4311. "(%d):0311 Mailbox command x%x cannot "
  4312. "issue Data: x%x x%x\n",
  4313. pmbox->vport ? pmbox->vport->vpi : 0,
  4314. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4315. goto out_not_finished;
  4316. }
  4317. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4318. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4319. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4320. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4321. "(%d):2528 Mailbox command x%x cannot "
  4322. "issue Data: x%x x%x\n",
  4323. pmbox->vport ? pmbox->vport->vpi : 0,
  4324. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4325. goto out_not_finished;
  4326. }
  4327. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4328. /* Polling for a mbox command when another one is already active
  4329. * is not allowed in SLI. Also, the driver must have established
  4330. * SLI2 mode to queue and process multiple mbox commands.
  4331. */
  4332. if (flag & MBX_POLL) {
  4333. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4334. /* Mbox command <mbxCommand> cannot issue */
  4335. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4336. "(%d):2529 Mailbox command x%x "
  4337. "cannot issue Data: x%x x%x\n",
  4338. pmbox->vport ? pmbox->vport->vpi : 0,
  4339. pmbox->u.mb.mbxCommand,
  4340. psli->sli_flag, flag);
  4341. goto out_not_finished;
  4342. }
  4343. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4344. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4345. /* Mbox command <mbxCommand> cannot issue */
  4346. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4347. "(%d):2530 Mailbox command x%x "
  4348. "cannot issue Data: x%x x%x\n",
  4349. pmbox->vport ? pmbox->vport->vpi : 0,
  4350. pmbox->u.mb.mbxCommand,
  4351. psli->sli_flag, flag);
  4352. goto out_not_finished;
  4353. }
  4354. /* Another mailbox command is still being processed, queue this
  4355. * command to be processed later.
  4356. */
  4357. lpfc_mbox_put(phba, pmbox);
  4358. /* Mbox cmd issue - BUSY */
  4359. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4360. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4361. "x%x x%x x%x x%x\n",
  4362. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4363. mb->mbxCommand, phba->pport->port_state,
  4364. psli->sli_flag, flag);
  4365. psli->slistat.mbox_busy++;
  4366. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4367. if (pmbox->vport) {
  4368. lpfc_debugfs_disc_trc(pmbox->vport,
  4369. LPFC_DISC_TRC_MBOX_VPORT,
  4370. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4371. (uint32_t)mb->mbxCommand,
  4372. mb->un.varWords[0], mb->un.varWords[1]);
  4373. }
  4374. else {
  4375. lpfc_debugfs_disc_trc(phba->pport,
  4376. LPFC_DISC_TRC_MBOX,
  4377. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4378. (uint32_t)mb->mbxCommand,
  4379. mb->un.varWords[0], mb->un.varWords[1]);
  4380. }
  4381. return MBX_BUSY;
  4382. }
  4383. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4384. /* If we are not polling, we MUST be in SLI2 mode */
  4385. if (flag != MBX_POLL) {
  4386. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4387. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4388. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4389. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4390. /* Mbox command <mbxCommand> cannot issue */
  4391. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4392. "(%d):2531 Mailbox command x%x "
  4393. "cannot issue Data: x%x x%x\n",
  4394. pmbox->vport ? pmbox->vport->vpi : 0,
  4395. pmbox->u.mb.mbxCommand,
  4396. psli->sli_flag, flag);
  4397. goto out_not_finished;
  4398. }
  4399. /* timeout active mbox command */
  4400. mod_timer(&psli->mbox_tmo, (jiffies +
  4401. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4402. }
  4403. /* Mailbox cmd <cmd> issue */
  4404. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4405. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4406. "x%x\n",
  4407. pmbox->vport ? pmbox->vport->vpi : 0,
  4408. mb->mbxCommand, phba->pport->port_state,
  4409. psli->sli_flag, flag);
  4410. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4411. if (pmbox->vport) {
  4412. lpfc_debugfs_disc_trc(pmbox->vport,
  4413. LPFC_DISC_TRC_MBOX_VPORT,
  4414. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4415. (uint32_t)mb->mbxCommand,
  4416. mb->un.varWords[0], mb->un.varWords[1]);
  4417. }
  4418. else {
  4419. lpfc_debugfs_disc_trc(phba->pport,
  4420. LPFC_DISC_TRC_MBOX,
  4421. "MBOX Send: cmd:x%x mb:x%x x%x",
  4422. (uint32_t)mb->mbxCommand,
  4423. mb->un.varWords[0], mb->un.varWords[1]);
  4424. }
  4425. }
  4426. psli->slistat.mbox_cmd++;
  4427. evtctr = psli->slistat.mbox_event;
  4428. /* next set own bit for the adapter and copy over command word */
  4429. mb->mbxOwner = OWN_CHIP;
  4430. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4431. /* Populate mbox extension offset word. */
  4432. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4433. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4434. = (uint8_t *)phba->mbox_ext
  4435. - (uint8_t *)phba->mbox;
  4436. }
  4437. /* Copy the mailbox extension data */
  4438. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4439. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4440. (uint8_t *)phba->mbox_ext,
  4441. pmbox->in_ext_byte_len);
  4442. }
  4443. /* Copy command data to host SLIM area */
  4444. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4445. } else {
  4446. /* Populate mbox extension offset word. */
  4447. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4448. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4449. = MAILBOX_HBA_EXT_OFFSET;
  4450. /* Copy the mailbox extension data */
  4451. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4452. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4453. MAILBOX_HBA_EXT_OFFSET,
  4454. pmbox->context2, pmbox->in_ext_byte_len);
  4455. }
  4456. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4457. /* copy command data into host mbox for cmpl */
  4458. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4459. }
  4460. /* First copy mbox command data to HBA SLIM, skip past first
  4461. word */
  4462. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4463. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4464. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4465. /* Next copy over first word, with mbxOwner set */
  4466. ldata = *((uint32_t *)mb);
  4467. to_slim = phba->MBslimaddr;
  4468. writel(ldata, to_slim);
  4469. readl(to_slim); /* flush */
  4470. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4471. /* switch over to host mailbox */
  4472. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4473. }
  4474. }
  4475. wmb();
  4476. switch (flag) {
  4477. case MBX_NOWAIT:
  4478. /* Set up reference to mailbox command */
  4479. psli->mbox_active = pmbox;
  4480. /* Interrupt board to do it */
  4481. writel(CA_MBATT, phba->CAregaddr);
  4482. readl(phba->CAregaddr); /* flush */
  4483. /* Don't wait for it to finish, just return */
  4484. break;
  4485. case MBX_POLL:
  4486. /* Set up null reference to mailbox command */
  4487. psli->mbox_active = NULL;
  4488. /* Interrupt board to do it */
  4489. writel(CA_MBATT, phba->CAregaddr);
  4490. readl(phba->CAregaddr); /* flush */
  4491. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4492. /* First read mbox status word */
  4493. word0 = *((uint32_t *)phba->mbox);
  4494. word0 = le32_to_cpu(word0);
  4495. } else {
  4496. /* First read mbox status word */
  4497. word0 = readl(phba->MBslimaddr);
  4498. }
  4499. /* Read the HBA Host Attention Register */
  4500. ha_copy = readl(phba->HAregaddr);
  4501. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4502. mb->mbxCommand) *
  4503. 1000) + jiffies;
  4504. i = 0;
  4505. /* Wait for command to complete */
  4506. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4507. (!(ha_copy & HA_MBATT) &&
  4508. (phba->link_state > LPFC_WARM_START))) {
  4509. if (time_after(jiffies, timeout)) {
  4510. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4511. spin_unlock_irqrestore(&phba->hbalock,
  4512. drvr_flag);
  4513. goto out_not_finished;
  4514. }
  4515. /* Check if we took a mbox interrupt while we were
  4516. polling */
  4517. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4518. && (evtctr != psli->slistat.mbox_event))
  4519. break;
  4520. if (i++ > 10) {
  4521. spin_unlock_irqrestore(&phba->hbalock,
  4522. drvr_flag);
  4523. msleep(1);
  4524. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4525. }
  4526. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4527. /* First copy command data */
  4528. word0 = *((uint32_t *)phba->mbox);
  4529. word0 = le32_to_cpu(word0);
  4530. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4531. MAILBOX_t *slimmb;
  4532. uint32_t slimword0;
  4533. /* Check real SLIM for any errors */
  4534. slimword0 = readl(phba->MBslimaddr);
  4535. slimmb = (MAILBOX_t *) & slimword0;
  4536. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4537. && slimmb->mbxStatus) {
  4538. psli->sli_flag &=
  4539. ~LPFC_SLI_ACTIVE;
  4540. word0 = slimword0;
  4541. }
  4542. }
  4543. } else {
  4544. /* First copy command data */
  4545. word0 = readl(phba->MBslimaddr);
  4546. }
  4547. /* Read the HBA Host Attention Register */
  4548. ha_copy = readl(phba->HAregaddr);
  4549. }
  4550. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4551. /* copy results back to user */
  4552. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4553. /* Copy the mailbox extension data */
  4554. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4555. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4556. pmbox->context2,
  4557. pmbox->out_ext_byte_len);
  4558. }
  4559. } else {
  4560. /* First copy command data */
  4561. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4562. MAILBOX_CMD_SIZE);
  4563. /* Copy the mailbox extension data */
  4564. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4565. lpfc_memcpy_from_slim(pmbox->context2,
  4566. phba->MBslimaddr +
  4567. MAILBOX_HBA_EXT_OFFSET,
  4568. pmbox->out_ext_byte_len);
  4569. }
  4570. }
  4571. writel(HA_MBATT, phba->HAregaddr);
  4572. readl(phba->HAregaddr); /* flush */
  4573. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4574. status = mb->mbxStatus;
  4575. }
  4576. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4577. return status;
  4578. out_not_finished:
  4579. if (processing_queue) {
  4580. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4581. lpfc_mbox_cmpl_put(phba, pmbox);
  4582. }
  4583. return MBX_NOT_FINISHED;
  4584. }
  4585. /**
  4586. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4587. * @phba: Pointer to HBA context object.
  4588. *
  4589. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4590. * the driver internal pending mailbox queue. It will then try to wait out the
  4591. * possible outstanding mailbox command before return.
  4592. *
  4593. * Returns:
  4594. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4595. * the outstanding mailbox command timed out.
  4596. **/
  4597. static int
  4598. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4599. {
  4600. struct lpfc_sli *psli = &phba->sli;
  4601. uint8_t actcmd = MBX_HEARTBEAT;
  4602. int rc = 0;
  4603. unsigned long timeout;
  4604. /* Mark the asynchronous mailbox command posting as blocked */
  4605. spin_lock_irq(&phba->hbalock);
  4606. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4607. if (phba->sli.mbox_active)
  4608. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4609. spin_unlock_irq(&phba->hbalock);
  4610. /* Determine how long we might wait for the active mailbox
  4611. * command to be gracefully completed by firmware.
  4612. */
  4613. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4614. jiffies;
  4615. /* Wait for the outstnading mailbox command to complete */
  4616. while (phba->sli.mbox_active) {
  4617. /* Check active mailbox complete status every 2ms */
  4618. msleep(2);
  4619. if (time_after(jiffies, timeout)) {
  4620. /* Timeout, marked the outstanding cmd not complete */
  4621. rc = 1;
  4622. break;
  4623. }
  4624. }
  4625. /* Can not cleanly block async mailbox command, fails it */
  4626. if (rc) {
  4627. spin_lock_irq(&phba->hbalock);
  4628. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4629. spin_unlock_irq(&phba->hbalock);
  4630. }
  4631. return rc;
  4632. }
  4633. /**
  4634. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4635. * @phba: Pointer to HBA context object.
  4636. *
  4637. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4638. * commands from the driver internal pending mailbox queue. It makes sure
  4639. * that there is no outstanding mailbox command before resuming posting
  4640. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4641. * mailbox command, it will try to wait it out before resuming asynchronous
  4642. * mailbox command posting.
  4643. **/
  4644. static void
  4645. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4646. {
  4647. struct lpfc_sli *psli = &phba->sli;
  4648. spin_lock_irq(&phba->hbalock);
  4649. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4650. /* Asynchronous mailbox posting is not blocked, do nothing */
  4651. spin_unlock_irq(&phba->hbalock);
  4652. return;
  4653. }
  4654. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4655. * successful or timeout, after timing-out the outstanding mailbox
  4656. * command shall always be removed, so just unblock posting async
  4657. * mailbox command and resume
  4658. */
  4659. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4660. spin_unlock_irq(&phba->hbalock);
  4661. /* wake up worker thread to post asynchronlous mailbox command */
  4662. lpfc_worker_wake_up(phba);
  4663. }
  4664. /**
  4665. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4666. * @phba: Pointer to HBA context object.
  4667. * @mboxq: Pointer to mailbox object.
  4668. *
  4669. * The function posts a mailbox to the port. The mailbox is expected
  4670. * to be comletely filled in and ready for the port to operate on it.
  4671. * This routine executes a synchronous completion operation on the
  4672. * mailbox by polling for its completion.
  4673. *
  4674. * The caller must not be holding any locks when calling this routine.
  4675. *
  4676. * Returns:
  4677. * MBX_SUCCESS - mailbox posted successfully
  4678. * Any of the MBX error values.
  4679. **/
  4680. static int
  4681. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4682. {
  4683. int rc = MBX_SUCCESS;
  4684. unsigned long iflag;
  4685. uint32_t db_ready;
  4686. uint32_t mcqe_status;
  4687. uint32_t mbx_cmnd;
  4688. unsigned long timeout;
  4689. struct lpfc_sli *psli = &phba->sli;
  4690. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4691. struct lpfc_bmbx_create *mbox_rgn;
  4692. struct dma_address *dma_address;
  4693. struct lpfc_register bmbx_reg;
  4694. /*
  4695. * Only one mailbox can be active to the bootstrap mailbox region
  4696. * at a time and there is no queueing provided.
  4697. */
  4698. spin_lock_irqsave(&phba->hbalock, iflag);
  4699. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4700. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4701. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4702. "(%d):2532 Mailbox command x%x (x%x) "
  4703. "cannot issue Data: x%x x%x\n",
  4704. mboxq->vport ? mboxq->vport->vpi : 0,
  4705. mboxq->u.mb.mbxCommand,
  4706. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4707. psli->sli_flag, MBX_POLL);
  4708. return MBXERR_ERROR;
  4709. }
  4710. /* The server grabs the token and owns it until release */
  4711. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4712. phba->sli.mbox_active = mboxq;
  4713. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4714. /*
  4715. * Initialize the bootstrap memory region to avoid stale data areas
  4716. * in the mailbox post. Then copy the caller's mailbox contents to
  4717. * the bmbx mailbox region.
  4718. */
  4719. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4720. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4721. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4722. sizeof(struct lpfc_mqe));
  4723. /* Post the high mailbox dma address to the port and wait for ready. */
  4724. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4725. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4726. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4727. * 1000) + jiffies;
  4728. do {
  4729. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4730. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4731. if (!db_ready)
  4732. msleep(2);
  4733. if (time_after(jiffies, timeout)) {
  4734. rc = MBXERR_ERROR;
  4735. goto exit;
  4736. }
  4737. } while (!db_ready);
  4738. /* Post the low mailbox dma address to the port. */
  4739. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4740. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4741. * 1000) + jiffies;
  4742. do {
  4743. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4744. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4745. if (!db_ready)
  4746. msleep(2);
  4747. if (time_after(jiffies, timeout)) {
  4748. rc = MBXERR_ERROR;
  4749. goto exit;
  4750. }
  4751. } while (!db_ready);
  4752. /*
  4753. * Read the CQ to ensure the mailbox has completed.
  4754. * If so, update the mailbox status so that the upper layers
  4755. * can complete the request normally.
  4756. */
  4757. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4758. sizeof(struct lpfc_mqe));
  4759. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4760. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4761. sizeof(struct lpfc_mcqe));
  4762. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4763. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4764. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4765. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4766. rc = MBXERR_ERROR;
  4767. }
  4768. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4769. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4770. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4771. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4772. mboxq->vport ? mboxq->vport->vpi : 0,
  4773. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4774. bf_get(lpfc_mqe_status, mb),
  4775. mb->un.mb_words[0], mb->un.mb_words[1],
  4776. mb->un.mb_words[2], mb->un.mb_words[3],
  4777. mb->un.mb_words[4], mb->un.mb_words[5],
  4778. mb->un.mb_words[6], mb->un.mb_words[7],
  4779. mb->un.mb_words[8], mb->un.mb_words[9],
  4780. mb->un.mb_words[10], mb->un.mb_words[11],
  4781. mb->un.mb_words[12], mboxq->mcqe.word0,
  4782. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4783. mboxq->mcqe.trailer);
  4784. exit:
  4785. /* We are holding the token, no needed for lock when release */
  4786. spin_lock_irqsave(&phba->hbalock, iflag);
  4787. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4788. phba->sli.mbox_active = NULL;
  4789. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4790. return rc;
  4791. }
  4792. /**
  4793. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4794. * @phba: Pointer to HBA context object.
  4795. * @pmbox: Pointer to mailbox object.
  4796. * @flag: Flag indicating how the mailbox need to be processed.
  4797. *
  4798. * This function is called by discovery code and HBA management code to submit
  4799. * a mailbox command to firmware with SLI-4 interface spec.
  4800. *
  4801. * Return codes the caller owns the mailbox command after the return of the
  4802. * function.
  4803. **/
  4804. static int
  4805. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4806. uint32_t flag)
  4807. {
  4808. struct lpfc_sli *psli = &phba->sli;
  4809. unsigned long iflags;
  4810. int rc;
  4811. rc = lpfc_mbox_dev_check(phba);
  4812. if (unlikely(rc)) {
  4813. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4814. "(%d):2544 Mailbox command x%x (x%x) "
  4815. "cannot issue Data: x%x x%x\n",
  4816. mboxq->vport ? mboxq->vport->vpi : 0,
  4817. mboxq->u.mb.mbxCommand,
  4818. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4819. psli->sli_flag, flag);
  4820. goto out_not_finished;
  4821. }
  4822. /* Detect polling mode and jump to a handler */
  4823. if (!phba->sli4_hba.intr_enable) {
  4824. if (flag == MBX_POLL)
  4825. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4826. else
  4827. rc = -EIO;
  4828. if (rc != MBX_SUCCESS)
  4829. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4830. "(%d):2541 Mailbox command x%x "
  4831. "(x%x) cannot issue Data: x%x x%x\n",
  4832. mboxq->vport ? mboxq->vport->vpi : 0,
  4833. mboxq->u.mb.mbxCommand,
  4834. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4835. psli->sli_flag, flag);
  4836. return rc;
  4837. } else if (flag == MBX_POLL) {
  4838. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4839. "(%d):2542 Try to issue mailbox command "
  4840. "x%x (x%x) synchronously ahead of async"
  4841. "mailbox command queue: x%x x%x\n",
  4842. mboxq->vport ? mboxq->vport->vpi : 0,
  4843. mboxq->u.mb.mbxCommand,
  4844. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4845. psli->sli_flag, flag);
  4846. /* Try to block the asynchronous mailbox posting */
  4847. rc = lpfc_sli4_async_mbox_block(phba);
  4848. if (!rc) {
  4849. /* Successfully blocked, now issue sync mbox cmd */
  4850. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4851. if (rc != MBX_SUCCESS)
  4852. lpfc_printf_log(phba, KERN_ERR,
  4853. LOG_MBOX | LOG_SLI,
  4854. "(%d):2597 Mailbox command "
  4855. "x%x (x%x) cannot issue "
  4856. "Data: x%x x%x\n",
  4857. mboxq->vport ?
  4858. mboxq->vport->vpi : 0,
  4859. mboxq->u.mb.mbxCommand,
  4860. lpfc_sli4_mbox_opcode_get(phba,
  4861. mboxq),
  4862. psli->sli_flag, flag);
  4863. /* Unblock the async mailbox posting afterward */
  4864. lpfc_sli4_async_mbox_unblock(phba);
  4865. }
  4866. return rc;
  4867. }
  4868. /* Now, interrupt mode asynchrous mailbox command */
  4869. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4870. if (rc) {
  4871. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4872. "(%d):2543 Mailbox command x%x (x%x) "
  4873. "cannot issue Data: x%x x%x\n",
  4874. mboxq->vport ? mboxq->vport->vpi : 0,
  4875. mboxq->u.mb.mbxCommand,
  4876. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4877. psli->sli_flag, flag);
  4878. goto out_not_finished;
  4879. }
  4880. /* Put the mailbox command to the driver internal FIFO */
  4881. psli->slistat.mbox_busy++;
  4882. spin_lock_irqsave(&phba->hbalock, iflags);
  4883. lpfc_mbox_put(phba, mboxq);
  4884. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4885. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4886. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4887. "x%x (x%x) x%x x%x x%x\n",
  4888. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4889. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4890. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4891. phba->pport->port_state,
  4892. psli->sli_flag, MBX_NOWAIT);
  4893. /* Wake up worker thread to transport mailbox command from head */
  4894. lpfc_worker_wake_up(phba);
  4895. return MBX_BUSY;
  4896. out_not_finished:
  4897. return MBX_NOT_FINISHED;
  4898. }
  4899. /**
  4900. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4901. * @phba: Pointer to HBA context object.
  4902. *
  4903. * This function is called by worker thread to send a mailbox command to
  4904. * SLI4 HBA firmware.
  4905. *
  4906. **/
  4907. int
  4908. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4909. {
  4910. struct lpfc_sli *psli = &phba->sli;
  4911. LPFC_MBOXQ_t *mboxq;
  4912. int rc = MBX_SUCCESS;
  4913. unsigned long iflags;
  4914. struct lpfc_mqe *mqe;
  4915. uint32_t mbx_cmnd;
  4916. /* Check interrupt mode before post async mailbox command */
  4917. if (unlikely(!phba->sli4_hba.intr_enable))
  4918. return MBX_NOT_FINISHED;
  4919. /* Check for mailbox command service token */
  4920. spin_lock_irqsave(&phba->hbalock, iflags);
  4921. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4922. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4923. return MBX_NOT_FINISHED;
  4924. }
  4925. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4926. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4927. return MBX_NOT_FINISHED;
  4928. }
  4929. if (unlikely(phba->sli.mbox_active)) {
  4930. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4931. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4932. "0384 There is pending active mailbox cmd\n");
  4933. return MBX_NOT_FINISHED;
  4934. }
  4935. /* Take the mailbox command service token */
  4936. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4937. /* Get the next mailbox command from head of queue */
  4938. mboxq = lpfc_mbox_get(phba);
  4939. /* If no more mailbox command waiting for post, we're done */
  4940. if (!mboxq) {
  4941. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4942. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4943. return MBX_SUCCESS;
  4944. }
  4945. phba->sli.mbox_active = mboxq;
  4946. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4947. /* Check device readiness for posting mailbox command */
  4948. rc = lpfc_mbox_dev_check(phba);
  4949. if (unlikely(rc))
  4950. /* Driver clean routine will clean up pending mailbox */
  4951. goto out_not_finished;
  4952. /* Prepare the mbox command to be posted */
  4953. mqe = &mboxq->u.mqe;
  4954. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4955. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4956. mod_timer(&psli->mbox_tmo, (jiffies +
  4957. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4958. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4959. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4960. "x%x x%x\n",
  4961. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4962. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4963. phba->pport->port_state, psli->sli_flag);
  4964. if (mbx_cmnd != MBX_HEARTBEAT) {
  4965. if (mboxq->vport) {
  4966. lpfc_debugfs_disc_trc(mboxq->vport,
  4967. LPFC_DISC_TRC_MBOX_VPORT,
  4968. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4969. mbx_cmnd, mqe->un.mb_words[0],
  4970. mqe->un.mb_words[1]);
  4971. } else {
  4972. lpfc_debugfs_disc_trc(phba->pport,
  4973. LPFC_DISC_TRC_MBOX,
  4974. "MBOX Send: cmd:x%x mb:x%x x%x",
  4975. mbx_cmnd, mqe->un.mb_words[0],
  4976. mqe->un.mb_words[1]);
  4977. }
  4978. }
  4979. psli->slistat.mbox_cmd++;
  4980. /* Post the mailbox command to the port */
  4981. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4982. if (rc != MBX_SUCCESS) {
  4983. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4984. "(%d):2533 Mailbox command x%x (x%x) "
  4985. "cannot issue Data: x%x x%x\n",
  4986. mboxq->vport ? mboxq->vport->vpi : 0,
  4987. mboxq->u.mb.mbxCommand,
  4988. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4989. psli->sli_flag, MBX_NOWAIT);
  4990. goto out_not_finished;
  4991. }
  4992. return rc;
  4993. out_not_finished:
  4994. spin_lock_irqsave(&phba->hbalock, iflags);
  4995. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4996. __lpfc_mbox_cmpl_put(phba, mboxq);
  4997. /* Release the token */
  4998. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4999. phba->sli.mbox_active = NULL;
  5000. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5001. return MBX_NOT_FINISHED;
  5002. }
  5003. /**
  5004. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5005. * @phba: Pointer to HBA context object.
  5006. * @pmbox: Pointer to mailbox object.
  5007. * @flag: Flag indicating how the mailbox need to be processed.
  5008. *
  5009. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5010. * the API jump table function pointer from the lpfc_hba struct.
  5011. *
  5012. * Return codes the caller owns the mailbox command after the return of the
  5013. * function.
  5014. **/
  5015. int
  5016. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5017. {
  5018. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5019. }
  5020. /**
  5021. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5022. * @phba: The hba struct for which this call is being executed.
  5023. * @dev_grp: The HBA PCI-Device group number.
  5024. *
  5025. * This routine sets up the mbox interface API function jump table in @phba
  5026. * struct.
  5027. * Returns: 0 - success, -ENODEV - failure.
  5028. **/
  5029. int
  5030. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5031. {
  5032. switch (dev_grp) {
  5033. case LPFC_PCI_DEV_LP:
  5034. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5035. phba->lpfc_sli_handle_slow_ring_event =
  5036. lpfc_sli_handle_slow_ring_event_s3;
  5037. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5038. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5039. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5040. break;
  5041. case LPFC_PCI_DEV_OC:
  5042. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5043. phba->lpfc_sli_handle_slow_ring_event =
  5044. lpfc_sli_handle_slow_ring_event_s4;
  5045. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5046. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5047. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5048. break;
  5049. default:
  5050. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5051. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5052. dev_grp);
  5053. return -ENODEV;
  5054. break;
  5055. }
  5056. return 0;
  5057. }
  5058. /**
  5059. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5060. * @phba: Pointer to HBA context object.
  5061. * @pring: Pointer to driver SLI ring object.
  5062. * @piocb: Pointer to address of newly added command iocb.
  5063. *
  5064. * This function is called with hbalock held to add a command
  5065. * iocb to the txq when SLI layer cannot submit the command iocb
  5066. * to the ring.
  5067. **/
  5068. void
  5069. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5070. struct lpfc_iocbq *piocb)
  5071. {
  5072. /* Insert the caller's iocb in the txq tail for later processing. */
  5073. list_add_tail(&piocb->list, &pring->txq);
  5074. pring->txq_cnt++;
  5075. }
  5076. /**
  5077. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5078. * @phba: Pointer to HBA context object.
  5079. * @pring: Pointer to driver SLI ring object.
  5080. * @piocb: Pointer to address of newly added command iocb.
  5081. *
  5082. * This function is called with hbalock held before a new
  5083. * iocb is submitted to the firmware. This function checks
  5084. * txq to flush the iocbs in txq to Firmware before
  5085. * submitting new iocbs to the Firmware.
  5086. * If there are iocbs in the txq which need to be submitted
  5087. * to firmware, lpfc_sli_next_iocb returns the first element
  5088. * of the txq after dequeuing it from txq.
  5089. * If there is no iocb in the txq then the function will return
  5090. * *piocb and *piocb is set to NULL. Caller needs to check
  5091. * *piocb to find if there are more commands in the txq.
  5092. **/
  5093. static struct lpfc_iocbq *
  5094. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5095. struct lpfc_iocbq **piocb)
  5096. {
  5097. struct lpfc_iocbq * nextiocb;
  5098. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5099. if (!nextiocb) {
  5100. nextiocb = *piocb;
  5101. *piocb = NULL;
  5102. }
  5103. return nextiocb;
  5104. }
  5105. /**
  5106. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5107. * @phba: Pointer to HBA context object.
  5108. * @ring_number: SLI ring number to issue iocb on.
  5109. * @piocb: Pointer to command iocb.
  5110. * @flag: Flag indicating if this command can be put into txq.
  5111. *
  5112. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5113. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5114. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5115. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5116. * this function allows only iocbs for posting buffers. This function finds
  5117. * next available slot in the command ring and posts the command to the
  5118. * available slot and writes the port attention register to request HBA start
  5119. * processing new iocb. If there is no slot available in the ring and
  5120. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5121. * the function returns IOCB_BUSY.
  5122. *
  5123. * This function is called with hbalock held. The function will return success
  5124. * after it successfully submit the iocb to firmware or after adding to the
  5125. * txq.
  5126. **/
  5127. static int
  5128. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5129. struct lpfc_iocbq *piocb, uint32_t flag)
  5130. {
  5131. struct lpfc_iocbq *nextiocb;
  5132. IOCB_t *iocb;
  5133. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5134. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5135. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5136. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5137. lpfc_printf_log(phba, KERN_ERR,
  5138. LOG_SLI | LOG_VPORT,
  5139. "1807 IOCB x%x failed. No vport\n",
  5140. piocb->iocb.ulpCommand);
  5141. dump_stack();
  5142. return IOCB_ERROR;
  5143. }
  5144. /* If the PCI channel is in offline state, do not post iocbs. */
  5145. if (unlikely(pci_channel_offline(phba->pcidev)))
  5146. return IOCB_ERROR;
  5147. /* If HBA has a deferred error attention, fail the iocb. */
  5148. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5149. return IOCB_ERROR;
  5150. /*
  5151. * We should never get an IOCB if we are in a < LINK_DOWN state
  5152. */
  5153. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5154. return IOCB_ERROR;
  5155. /*
  5156. * Check to see if we are blocking IOCB processing because of a
  5157. * outstanding event.
  5158. */
  5159. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5160. goto iocb_busy;
  5161. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5162. /*
  5163. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5164. * can be issued if the link is not up.
  5165. */
  5166. switch (piocb->iocb.ulpCommand) {
  5167. case CMD_GEN_REQUEST64_CR:
  5168. case CMD_GEN_REQUEST64_CX:
  5169. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5170. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5171. FC_RCTL_DD_UNSOL_CMD) ||
  5172. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5173. MENLO_TRANSPORT_TYPE))
  5174. goto iocb_busy;
  5175. break;
  5176. case CMD_QUE_RING_BUF_CN:
  5177. case CMD_QUE_RING_BUF64_CN:
  5178. /*
  5179. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5180. * completion, iocb_cmpl MUST be 0.
  5181. */
  5182. if (piocb->iocb_cmpl)
  5183. piocb->iocb_cmpl = NULL;
  5184. /*FALLTHROUGH*/
  5185. case CMD_CREATE_XRI_CR:
  5186. case CMD_CLOSE_XRI_CN:
  5187. case CMD_CLOSE_XRI_CX:
  5188. break;
  5189. default:
  5190. goto iocb_busy;
  5191. }
  5192. /*
  5193. * For FCP commands, we must be in a state where we can process link
  5194. * attention events.
  5195. */
  5196. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5197. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5198. goto iocb_busy;
  5199. }
  5200. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5201. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5202. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5203. if (iocb)
  5204. lpfc_sli_update_ring(phba, pring);
  5205. else
  5206. lpfc_sli_update_full_ring(phba, pring);
  5207. if (!piocb)
  5208. return IOCB_SUCCESS;
  5209. goto out_busy;
  5210. iocb_busy:
  5211. pring->stats.iocb_cmd_delay++;
  5212. out_busy:
  5213. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5214. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5215. return IOCB_SUCCESS;
  5216. }
  5217. return IOCB_BUSY;
  5218. }
  5219. /**
  5220. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5221. * @phba: Pointer to HBA context object.
  5222. * @piocb: Pointer to command iocb.
  5223. * @sglq: Pointer to the scatter gather queue object.
  5224. *
  5225. * This routine converts the bpl or bde that is in the IOCB
  5226. * to a sgl list for the sli4 hardware. The physical address
  5227. * of the bpl/bde is converted back to a virtual address.
  5228. * If the IOCB contains a BPL then the list of BDE's is
  5229. * converted to sli4_sge's. If the IOCB contains a single
  5230. * BDE then it is converted to a single sli_sge.
  5231. * The IOCB is still in cpu endianess so the contents of
  5232. * the bpl can be used without byte swapping.
  5233. *
  5234. * Returns valid XRI = Success, NO_XRI = Failure.
  5235. **/
  5236. static uint16_t
  5237. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5238. struct lpfc_sglq *sglq)
  5239. {
  5240. uint16_t xritag = NO_XRI;
  5241. struct ulp_bde64 *bpl = NULL;
  5242. struct ulp_bde64 bde;
  5243. struct sli4_sge *sgl = NULL;
  5244. IOCB_t *icmd;
  5245. int numBdes = 0;
  5246. int i = 0;
  5247. if (!piocbq || !sglq)
  5248. return xritag;
  5249. sgl = (struct sli4_sge *)sglq->sgl;
  5250. icmd = &piocbq->iocb;
  5251. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5252. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5253. sizeof(struct ulp_bde64);
  5254. /* The addrHigh and addrLow fields within the IOCB
  5255. * have not been byteswapped yet so there is no
  5256. * need to swap them back.
  5257. */
  5258. bpl = (struct ulp_bde64 *)
  5259. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5260. if (!bpl)
  5261. return xritag;
  5262. for (i = 0; i < numBdes; i++) {
  5263. /* Should already be byte swapped. */
  5264. sgl->addr_hi = bpl->addrHigh;
  5265. sgl->addr_lo = bpl->addrLow;
  5266. if ((i+1) == numBdes)
  5267. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5268. else
  5269. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5270. sgl->word2 = cpu_to_le32(sgl->word2);
  5271. /* swap the size field back to the cpu so we
  5272. * can assign it to the sgl.
  5273. */
  5274. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5275. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5276. bpl++;
  5277. sgl++;
  5278. }
  5279. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5280. /* The addrHigh and addrLow fields of the BDE have not
  5281. * been byteswapped yet so they need to be swapped
  5282. * before putting them in the sgl.
  5283. */
  5284. sgl->addr_hi =
  5285. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5286. sgl->addr_lo =
  5287. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5288. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5289. sgl->word2 = cpu_to_le32(sgl->word2);
  5290. sgl->sge_len =
  5291. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5292. }
  5293. return sglq->sli4_xritag;
  5294. }
  5295. /**
  5296. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5297. * @phba: Pointer to HBA context object.
  5298. *
  5299. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5300. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5301. * held.
  5302. *
  5303. * Return: index into SLI4 fast-path FCP queue index.
  5304. **/
  5305. static uint32_t
  5306. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5307. {
  5308. ++phba->fcp_qidx;
  5309. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5310. phba->fcp_qidx = 0;
  5311. return phba->fcp_qidx;
  5312. }
  5313. /**
  5314. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5315. * @phba: Pointer to HBA context object.
  5316. * @piocb: Pointer to command iocb.
  5317. * @wqe: Pointer to the work queue entry.
  5318. *
  5319. * This routine converts the iocb command to its Work Queue Entry
  5320. * equivalent. The wqe pointer should not have any fields set when
  5321. * this routine is called because it will memcpy over them.
  5322. * This routine does not set the CQ_ID or the WQEC bits in the
  5323. * wqe.
  5324. *
  5325. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5326. **/
  5327. static int
  5328. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5329. union lpfc_wqe *wqe)
  5330. {
  5331. uint32_t xmit_len = 0, total_len = 0;
  5332. uint8_t ct = 0;
  5333. uint32_t fip;
  5334. uint32_t abort_tag;
  5335. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5336. uint8_t cmnd;
  5337. uint16_t xritag;
  5338. struct ulp_bde64 *bpl = NULL;
  5339. uint32_t els_id = ELS_ID_DEFAULT;
  5340. int numBdes, i;
  5341. struct ulp_bde64 bde;
  5342. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5343. /* The fcp commands will set command type */
  5344. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5345. command_type = FCP_COMMAND;
  5346. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5347. command_type = ELS_COMMAND_FIP;
  5348. else
  5349. command_type = ELS_COMMAND_NON_FIP;
  5350. /* Some of the fields are in the right position already */
  5351. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5352. abort_tag = (uint32_t) iocbq->iotag;
  5353. xritag = iocbq->sli4_xritag;
  5354. wqe->words[7] = 0; /* The ct field has moved so reset */
  5355. /* words0-2 bpl convert bde */
  5356. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5357. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5358. sizeof(struct ulp_bde64);
  5359. bpl = (struct ulp_bde64 *)
  5360. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5361. if (!bpl)
  5362. return IOCB_ERROR;
  5363. /* Should already be byte swapped. */
  5364. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5365. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5366. /* swap the size field back to the cpu so we
  5367. * can assign it to the sgl.
  5368. */
  5369. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5370. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5371. total_len = 0;
  5372. for (i = 0; i < numBdes; i++) {
  5373. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5374. total_len += bde.tus.f.bdeSize;
  5375. }
  5376. } else
  5377. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5378. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5379. cmnd = iocbq->iocb.ulpCommand;
  5380. switch (iocbq->iocb.ulpCommand) {
  5381. case CMD_ELS_REQUEST64_CR:
  5382. if (!iocbq->iocb.ulpLe) {
  5383. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5384. "2007 Only Limited Edition cmd Format"
  5385. " supported 0x%x\n",
  5386. iocbq->iocb.ulpCommand);
  5387. return IOCB_ERROR;
  5388. }
  5389. wqe->els_req.payload_len = xmit_len;
  5390. /* Els_reguest64 has a TMO */
  5391. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5392. iocbq->iocb.ulpTimeout);
  5393. /* Need a VF for word 4 set the vf bit*/
  5394. bf_set(els_req64_vf, &wqe->els_req, 0);
  5395. /* And a VFID for word 12 */
  5396. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5397. /*
  5398. * Set ct field to 3, indicates that the context_tag field
  5399. * contains the FCFI and remote N_Port_ID is
  5400. * in word 5.
  5401. */
  5402. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5403. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5404. iocbq->iocb.ulpContext);
  5405. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5406. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5407. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5408. if (command_type == ELS_COMMAND_FIP) {
  5409. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5410. >> LPFC_FIP_ELS_ID_SHIFT);
  5411. }
  5412. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5413. break;
  5414. case CMD_XMIT_SEQUENCE64_CX:
  5415. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5416. iocbq->iocb.un.ulpWord[3]);
  5417. wqe->generic.word3 = 0;
  5418. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5419. /* The entire sequence is transmitted for this IOCB */
  5420. xmit_len = total_len;
  5421. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5422. case CMD_XMIT_SEQUENCE64_CR:
  5423. /* word3 iocb=io_tag32 wqe=payload_offset */
  5424. /* payload offset used for multilpe outstanding
  5425. * sequences on the same exchange
  5426. */
  5427. wqe->words[3] = 0;
  5428. /* word4 relative_offset memcpy */
  5429. /* word5 r_ctl/df_ctl memcpy */
  5430. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5431. wqe->xmit_sequence.xmit_len = xmit_len;
  5432. command_type = OTHER_COMMAND;
  5433. break;
  5434. case CMD_XMIT_BCAST64_CN:
  5435. /* word3 iocb=iotag32 wqe=payload_len */
  5436. wqe->words[3] = 0; /* no definition for this in wqe */
  5437. /* word4 iocb=rsvd wqe=rsvd */
  5438. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5439. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5440. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5441. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5442. break;
  5443. case CMD_FCP_IWRITE64_CR:
  5444. command_type = FCP_COMMAND_DATA_OUT;
  5445. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5446. * confusing.
  5447. * word3 is payload_len: byte offset to the sgl entry for the
  5448. * fcp_command.
  5449. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5450. * word5 is initial xfer len 0 = wait for xfer-ready
  5451. */
  5452. /* Always wait for xfer-ready before sending data */
  5453. wqe->fcp_iwrite.initial_xfer_len = 0;
  5454. /* word 4 (xfer length) should have been set on the memcpy */
  5455. /* allow write to fall through to read */
  5456. case CMD_FCP_IREAD64_CR:
  5457. /* FCP_CMD is always the 1st sgl entry */
  5458. wqe->fcp_iread.payload_len =
  5459. xmit_len + sizeof(struct fcp_rsp);
  5460. /* word 4 (xfer length) should have been set on the memcpy */
  5461. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5462. iocbq->iocb.ulpFCP2Rcvy);
  5463. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5464. /* The XC bit and the XS bit are similar. The driver never
  5465. * tracked whether or not the exchange was previouslly open.
  5466. * XC = Exchange create, 0 is create. 1 is already open.
  5467. * XS = link cmd: 1 do not close the exchange after command.
  5468. * XS = 0 close exchange when command completes.
  5469. * The only time we would not set the XC bit is when the XS bit
  5470. * is set and we are sending our 2nd or greater command on
  5471. * this exchange.
  5472. */
  5473. /* Always open the exchange */
  5474. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5475. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5476. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5477. break;
  5478. case CMD_FCP_ICMND64_CR:
  5479. /* Always open the exchange */
  5480. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5481. wqe->words[4] = 0;
  5482. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5483. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5484. break;
  5485. case CMD_GEN_REQUEST64_CR:
  5486. /* word3 command length is described as byte offset to the
  5487. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5488. * sgl[0] = cmnd
  5489. * sgl[1] = rsp.
  5490. *
  5491. */
  5492. wqe->gen_req.command_len = xmit_len;
  5493. /* Word4 parameter copied in the memcpy */
  5494. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5495. /* word6 context tag copied in memcpy */
  5496. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5497. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5498. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5499. "2015 Invalid CT %x command 0x%x\n",
  5500. ct, iocbq->iocb.ulpCommand);
  5501. return IOCB_ERROR;
  5502. }
  5503. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5504. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5505. iocbq->iocb.ulpTimeout);
  5506. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5507. command_type = OTHER_COMMAND;
  5508. break;
  5509. case CMD_XMIT_ELS_RSP64_CX:
  5510. /* words0-2 BDE memcpy */
  5511. /* word3 iocb=iotag32 wqe=rsvd */
  5512. wqe->words[3] = 0;
  5513. /* word4 iocb=did wge=rsvd. */
  5514. wqe->words[4] = 0;
  5515. /* word5 iocb=rsvd wge=did */
  5516. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5517. iocbq->iocb.un.elsreq64.remoteID);
  5518. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5519. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5520. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5521. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5522. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5523. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5524. iocbq->vport->vpi + phba->vpi_base);
  5525. command_type = OTHER_COMMAND;
  5526. break;
  5527. case CMD_CLOSE_XRI_CN:
  5528. case CMD_ABORT_XRI_CN:
  5529. case CMD_ABORT_XRI_CX:
  5530. /* words 0-2 memcpy should be 0 rserved */
  5531. /* port will send abts */
  5532. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5533. /*
  5534. * The link is down so the fw does not need to send abts
  5535. * on the wire.
  5536. */
  5537. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5538. else
  5539. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5540. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5541. wqe->words[5] = 0;
  5542. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5543. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5544. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5545. /*
  5546. * The abort handler will send us CMD_ABORT_XRI_CN or
  5547. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5548. */
  5549. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5550. cmnd = CMD_ABORT_XRI_CX;
  5551. command_type = OTHER_COMMAND;
  5552. xritag = 0;
  5553. break;
  5554. case CMD_XMIT_BLS_RSP64_CX:
  5555. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5556. * we re-construct this WQE here based on information in
  5557. * iocbq from scratch.
  5558. */
  5559. memset(wqe, 0, sizeof(union lpfc_wqe));
  5560. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5561. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5562. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5563. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5564. LPFC_ABTS_UNSOL_INT) {
  5565. /* ABTS sent by initiator to CT exchange, the
  5566. * RX_ID field will be filled with the newly
  5567. * allocated responder XRI.
  5568. */
  5569. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5570. iocbq->sli4_xritag);
  5571. } else {
  5572. /* ABTS sent by responder to CT exchange, the
  5573. * RX_ID field will be filled with the responder
  5574. * RX_ID from ABTS.
  5575. */
  5576. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5577. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5578. }
  5579. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5580. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5581. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5582. iocbq->iocb.ulpContext);
  5583. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5584. command_type = OTHER_COMMAND;
  5585. break;
  5586. case CMD_XRI_ABORTED_CX:
  5587. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5588. /* words0-2 are all 0's no bde */
  5589. /* word3 and word4 are rsvrd */
  5590. wqe->words[3] = 0;
  5591. wqe->words[4] = 0;
  5592. /* word5 iocb=rsvd wge=did */
  5593. /* There is no remote port id in the IOCB? */
  5594. /* Let this fall through and fail */
  5595. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5596. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5597. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5598. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5599. default:
  5600. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5601. "2014 Invalid command 0x%x\n",
  5602. iocbq->iocb.ulpCommand);
  5603. return IOCB_ERROR;
  5604. break;
  5605. }
  5606. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5607. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5608. wqe->generic.abort_tag = abort_tag;
  5609. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5610. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5611. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5612. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5613. return 0;
  5614. }
  5615. /**
  5616. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5617. * @phba: Pointer to HBA context object.
  5618. * @ring_number: SLI ring number to issue iocb on.
  5619. * @piocb: Pointer to command iocb.
  5620. * @flag: Flag indicating if this command can be put into txq.
  5621. *
  5622. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5623. * an iocb command to an HBA with SLI-4 interface spec.
  5624. *
  5625. * This function is called with hbalock held. The function will return success
  5626. * after it successfully submit the iocb to firmware or after adding to the
  5627. * txq.
  5628. **/
  5629. static int
  5630. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5631. struct lpfc_iocbq *piocb, uint32_t flag)
  5632. {
  5633. struct lpfc_sglq *sglq;
  5634. union lpfc_wqe wqe;
  5635. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5636. if (piocb->sli4_xritag == NO_XRI) {
  5637. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5638. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5639. sglq = NULL;
  5640. else {
  5641. if (pring->txq_cnt) {
  5642. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5643. __lpfc_sli_ringtx_put(phba,
  5644. pring, piocb);
  5645. return IOCB_SUCCESS;
  5646. } else {
  5647. return IOCB_BUSY;
  5648. }
  5649. } else {
  5650. sglq = __lpfc_sli_get_sglq(phba);
  5651. if (!sglq) {
  5652. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5653. __lpfc_sli_ringtx_put(phba,
  5654. pring,
  5655. piocb);
  5656. return IOCB_SUCCESS;
  5657. } else
  5658. return IOCB_BUSY;
  5659. }
  5660. }
  5661. }
  5662. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5663. sglq = NULL; /* These IO's already have an XRI and
  5664. * a mapped sgl.
  5665. */
  5666. } else {
  5667. /* This is a continuation of a commandi,(CX) so this
  5668. * sglq is on the active list
  5669. */
  5670. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5671. if (!sglq)
  5672. return IOCB_ERROR;
  5673. }
  5674. if (sglq) {
  5675. piocb->sli4_xritag = sglq->sli4_xritag;
  5676. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  5677. return IOCB_ERROR;
  5678. }
  5679. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5680. return IOCB_ERROR;
  5681. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5682. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5683. /*
  5684. * For FCP command IOCB, get a new WQ index to distribute
  5685. * WQE across the WQsr. On the other hand, for abort IOCB,
  5686. * it carries the same WQ index to the original command
  5687. * IOCB.
  5688. */
  5689. if (piocb->iocb_flag & LPFC_IO_FCP)
  5690. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5691. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5692. &wqe))
  5693. return IOCB_ERROR;
  5694. } else {
  5695. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5696. return IOCB_ERROR;
  5697. }
  5698. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5699. return 0;
  5700. }
  5701. /**
  5702. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5703. *
  5704. * This routine wraps the actual lockless version for issusing IOCB function
  5705. * pointer from the lpfc_hba struct.
  5706. *
  5707. * Return codes:
  5708. * IOCB_ERROR - Error
  5709. * IOCB_SUCCESS - Success
  5710. * IOCB_BUSY - Busy
  5711. **/
  5712. int
  5713. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5714. struct lpfc_iocbq *piocb, uint32_t flag)
  5715. {
  5716. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5717. }
  5718. /**
  5719. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5720. * @phba: The hba struct for which this call is being executed.
  5721. * @dev_grp: The HBA PCI-Device group number.
  5722. *
  5723. * This routine sets up the SLI interface API function jump table in @phba
  5724. * struct.
  5725. * Returns: 0 - success, -ENODEV - failure.
  5726. **/
  5727. int
  5728. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5729. {
  5730. switch (dev_grp) {
  5731. case LPFC_PCI_DEV_LP:
  5732. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5733. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5734. break;
  5735. case LPFC_PCI_DEV_OC:
  5736. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5737. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5738. break;
  5739. default:
  5740. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5741. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5742. dev_grp);
  5743. return -ENODEV;
  5744. break;
  5745. }
  5746. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5747. return 0;
  5748. }
  5749. /**
  5750. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5751. * @phba: Pointer to HBA context object.
  5752. * @pring: Pointer to driver SLI ring object.
  5753. * @piocb: Pointer to command iocb.
  5754. * @flag: Flag indicating if this command can be put into txq.
  5755. *
  5756. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5757. * function. This function gets the hbalock and calls
  5758. * __lpfc_sli_issue_iocb function and will return the error returned
  5759. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5760. * functions which do not hold hbalock.
  5761. **/
  5762. int
  5763. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5764. struct lpfc_iocbq *piocb, uint32_t flag)
  5765. {
  5766. unsigned long iflags;
  5767. int rc;
  5768. spin_lock_irqsave(&phba->hbalock, iflags);
  5769. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5770. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5771. return rc;
  5772. }
  5773. /**
  5774. * lpfc_extra_ring_setup - Extra ring setup function
  5775. * @phba: Pointer to HBA context object.
  5776. *
  5777. * This function is called while driver attaches with the
  5778. * HBA to setup the extra ring. The extra ring is used
  5779. * only when driver needs to support target mode functionality
  5780. * or IP over FC functionalities.
  5781. *
  5782. * This function is called with no lock held.
  5783. **/
  5784. static int
  5785. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5786. {
  5787. struct lpfc_sli *psli;
  5788. struct lpfc_sli_ring *pring;
  5789. psli = &phba->sli;
  5790. /* Adjust cmd/rsp ring iocb entries more evenly */
  5791. /* Take some away from the FCP ring */
  5792. pring = &psli->ring[psli->fcp_ring];
  5793. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5794. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5795. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5796. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5797. /* and give them to the extra ring */
  5798. pring = &psli->ring[psli->extra_ring];
  5799. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5800. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5801. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5802. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5803. /* Setup default profile for this ring */
  5804. pring->iotag_max = 4096;
  5805. pring->num_mask = 1;
  5806. pring->prt[0].profile = 0; /* Mask 0 */
  5807. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5808. pring->prt[0].type = phba->cfg_multi_ring_type;
  5809. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5810. return 0;
  5811. }
  5812. /**
  5813. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5814. * @phba: Pointer to HBA context object.
  5815. * @pring: Pointer to driver SLI ring object.
  5816. * @iocbq: Pointer to iocb object.
  5817. *
  5818. * This function is called by the slow ring event handler
  5819. * function when there is an ASYNC event iocb in the ring.
  5820. * This function is called with no lock held.
  5821. * Currently this function handles only temperature related
  5822. * ASYNC events. The function decodes the temperature sensor
  5823. * event message and posts events for the management applications.
  5824. **/
  5825. static void
  5826. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5827. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5828. {
  5829. IOCB_t *icmd;
  5830. uint16_t evt_code;
  5831. uint16_t temp;
  5832. struct temp_event temp_event_data;
  5833. struct Scsi_Host *shost;
  5834. uint32_t *iocb_w;
  5835. icmd = &iocbq->iocb;
  5836. evt_code = icmd->un.asyncstat.evt_code;
  5837. temp = icmd->ulpContext;
  5838. if ((evt_code != ASYNC_TEMP_WARN) &&
  5839. (evt_code != ASYNC_TEMP_SAFE)) {
  5840. iocb_w = (uint32_t *) icmd;
  5841. lpfc_printf_log(phba,
  5842. KERN_ERR,
  5843. LOG_SLI,
  5844. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5845. " evt_code 0x%x\n"
  5846. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5847. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5848. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5849. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5850. pring->ringno,
  5851. icmd->un.asyncstat.evt_code,
  5852. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5853. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5854. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5855. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5856. return;
  5857. }
  5858. temp_event_data.data = (uint32_t)temp;
  5859. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5860. if (evt_code == ASYNC_TEMP_WARN) {
  5861. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5862. lpfc_printf_log(phba,
  5863. KERN_ERR,
  5864. LOG_TEMP,
  5865. "0347 Adapter is very hot, please take "
  5866. "corrective action. temperature : %d Celsius\n",
  5867. temp);
  5868. }
  5869. if (evt_code == ASYNC_TEMP_SAFE) {
  5870. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5871. lpfc_printf_log(phba,
  5872. KERN_ERR,
  5873. LOG_TEMP,
  5874. "0340 Adapter temperature is OK now. "
  5875. "temperature : %d Celsius\n",
  5876. temp);
  5877. }
  5878. /* Send temperature change event to applications */
  5879. shost = lpfc_shost_from_vport(phba->pport);
  5880. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5881. sizeof(temp_event_data), (char *) &temp_event_data,
  5882. LPFC_NL_VENDOR_ID);
  5883. }
  5884. /**
  5885. * lpfc_sli_setup - SLI ring setup function
  5886. * @phba: Pointer to HBA context object.
  5887. *
  5888. * lpfc_sli_setup sets up rings of the SLI interface with
  5889. * number of iocbs per ring and iotags. This function is
  5890. * called while driver attach to the HBA and before the
  5891. * interrupts are enabled. So there is no need for locking.
  5892. *
  5893. * This function always returns 0.
  5894. **/
  5895. int
  5896. lpfc_sli_setup(struct lpfc_hba *phba)
  5897. {
  5898. int i, totiocbsize = 0;
  5899. struct lpfc_sli *psli = &phba->sli;
  5900. struct lpfc_sli_ring *pring;
  5901. psli->num_rings = MAX_CONFIGURED_RINGS;
  5902. psli->sli_flag = 0;
  5903. psli->fcp_ring = LPFC_FCP_RING;
  5904. psli->next_ring = LPFC_FCP_NEXT_RING;
  5905. psli->extra_ring = LPFC_EXTRA_RING;
  5906. psli->iocbq_lookup = NULL;
  5907. psli->iocbq_lookup_len = 0;
  5908. psli->last_iotag = 0;
  5909. for (i = 0; i < psli->num_rings; i++) {
  5910. pring = &psli->ring[i];
  5911. switch (i) {
  5912. case LPFC_FCP_RING: /* ring 0 - FCP */
  5913. /* numCiocb and numRiocb are used in config_port */
  5914. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5915. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5916. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5917. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5918. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5919. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5920. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5921. SLI3_IOCB_CMD_SIZE :
  5922. SLI2_IOCB_CMD_SIZE;
  5923. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5924. SLI3_IOCB_RSP_SIZE :
  5925. SLI2_IOCB_RSP_SIZE;
  5926. pring->iotag_ctr = 0;
  5927. pring->iotag_max =
  5928. (phba->cfg_hba_queue_depth * 2);
  5929. pring->fast_iotag = pring->iotag_max;
  5930. pring->num_mask = 0;
  5931. break;
  5932. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5933. /* numCiocb and numRiocb are used in config_port */
  5934. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5935. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5936. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5937. SLI3_IOCB_CMD_SIZE :
  5938. SLI2_IOCB_CMD_SIZE;
  5939. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5940. SLI3_IOCB_RSP_SIZE :
  5941. SLI2_IOCB_RSP_SIZE;
  5942. pring->iotag_max = phba->cfg_hba_queue_depth;
  5943. pring->num_mask = 0;
  5944. break;
  5945. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5946. /* numCiocb and numRiocb are used in config_port */
  5947. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5948. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5949. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5950. SLI3_IOCB_CMD_SIZE :
  5951. SLI2_IOCB_CMD_SIZE;
  5952. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5953. SLI3_IOCB_RSP_SIZE :
  5954. SLI2_IOCB_RSP_SIZE;
  5955. pring->fast_iotag = 0;
  5956. pring->iotag_ctr = 0;
  5957. pring->iotag_max = 4096;
  5958. pring->lpfc_sli_rcv_async_status =
  5959. lpfc_sli_async_event_handler;
  5960. pring->num_mask = LPFC_MAX_RING_MASK;
  5961. pring->prt[0].profile = 0; /* Mask 0 */
  5962. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5963. pring->prt[0].type = FC_TYPE_ELS;
  5964. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5965. lpfc_els_unsol_event;
  5966. pring->prt[1].profile = 0; /* Mask 1 */
  5967. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5968. pring->prt[1].type = FC_TYPE_ELS;
  5969. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5970. lpfc_els_unsol_event;
  5971. pring->prt[2].profile = 0; /* Mask 2 */
  5972. /* NameServer Inquiry */
  5973. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5974. /* NameServer */
  5975. pring->prt[2].type = FC_TYPE_CT;
  5976. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5977. lpfc_ct_unsol_event;
  5978. pring->prt[3].profile = 0; /* Mask 3 */
  5979. /* NameServer response */
  5980. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  5981. /* NameServer */
  5982. pring->prt[3].type = FC_TYPE_CT;
  5983. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5984. lpfc_ct_unsol_event;
  5985. /* abort unsolicited sequence */
  5986. pring->prt[4].profile = 0; /* Mask 4 */
  5987. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  5988. pring->prt[4].type = FC_TYPE_BLS;
  5989. pring->prt[4].lpfc_sli_rcv_unsol_event =
  5990. lpfc_sli4_ct_abort_unsol_event;
  5991. break;
  5992. }
  5993. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5994. (pring->numRiocb * pring->sizeRiocb);
  5995. }
  5996. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5997. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5998. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5999. "SLI2 SLIM Data: x%x x%lx\n",
  6000. phba->brd_no, totiocbsize,
  6001. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6002. }
  6003. if (phba->cfg_multi_ring_support == 2)
  6004. lpfc_extra_ring_setup(phba);
  6005. return 0;
  6006. }
  6007. /**
  6008. * lpfc_sli_queue_setup - Queue initialization function
  6009. * @phba: Pointer to HBA context object.
  6010. *
  6011. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6012. * ring. This function also initializes ring indices of each ring.
  6013. * This function is called during the initialization of the SLI
  6014. * interface of an HBA.
  6015. * This function is called with no lock held and always returns
  6016. * 1.
  6017. **/
  6018. int
  6019. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6020. {
  6021. struct lpfc_sli *psli;
  6022. struct lpfc_sli_ring *pring;
  6023. int i;
  6024. psli = &phba->sli;
  6025. spin_lock_irq(&phba->hbalock);
  6026. INIT_LIST_HEAD(&psli->mboxq);
  6027. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6028. /* Initialize list headers for txq and txcmplq as double linked lists */
  6029. for (i = 0; i < psli->num_rings; i++) {
  6030. pring = &psli->ring[i];
  6031. pring->ringno = i;
  6032. pring->next_cmdidx = 0;
  6033. pring->local_getidx = 0;
  6034. pring->cmdidx = 0;
  6035. INIT_LIST_HEAD(&pring->txq);
  6036. INIT_LIST_HEAD(&pring->txcmplq);
  6037. INIT_LIST_HEAD(&pring->iocb_continueq);
  6038. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6039. INIT_LIST_HEAD(&pring->postbufq);
  6040. }
  6041. spin_unlock_irq(&phba->hbalock);
  6042. return 1;
  6043. }
  6044. /**
  6045. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6046. * @phba: Pointer to HBA context object.
  6047. *
  6048. * This routine flushes the mailbox command subsystem. It will unconditionally
  6049. * flush all the mailbox commands in the three possible stages in the mailbox
  6050. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6051. * command; and completed mailbox command queue. It is caller's responsibility
  6052. * to make sure that the driver is in the proper state to flush the mailbox
  6053. * command sub-system. Namely, the posting of mailbox commands into the
  6054. * pending mailbox command queue from the various clients must be stopped;
  6055. * either the HBA is in a state that it will never works on the outstanding
  6056. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6057. * mailbox command has been completed.
  6058. **/
  6059. static void
  6060. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6061. {
  6062. LIST_HEAD(completions);
  6063. struct lpfc_sli *psli = &phba->sli;
  6064. LPFC_MBOXQ_t *pmb;
  6065. unsigned long iflag;
  6066. /* Flush all the mailbox commands in the mbox system */
  6067. spin_lock_irqsave(&phba->hbalock, iflag);
  6068. /* The pending mailbox command queue */
  6069. list_splice_init(&phba->sli.mboxq, &completions);
  6070. /* The outstanding active mailbox command */
  6071. if (psli->mbox_active) {
  6072. list_add_tail(&psli->mbox_active->list, &completions);
  6073. psli->mbox_active = NULL;
  6074. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6075. }
  6076. /* The completed mailbox command queue */
  6077. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6078. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6079. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6080. while (!list_empty(&completions)) {
  6081. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6082. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6083. if (pmb->mbox_cmpl)
  6084. pmb->mbox_cmpl(phba, pmb);
  6085. }
  6086. }
  6087. /**
  6088. * lpfc_sli_host_down - Vport cleanup function
  6089. * @vport: Pointer to virtual port object.
  6090. *
  6091. * lpfc_sli_host_down is called to clean up the resources
  6092. * associated with a vport before destroying virtual
  6093. * port data structures.
  6094. * This function does following operations:
  6095. * - Free discovery resources associated with this virtual
  6096. * port.
  6097. * - Free iocbs associated with this virtual port in
  6098. * the txq.
  6099. * - Send abort for all iocb commands associated with this
  6100. * vport in txcmplq.
  6101. *
  6102. * This function is called with no lock held and always returns 1.
  6103. **/
  6104. int
  6105. lpfc_sli_host_down(struct lpfc_vport *vport)
  6106. {
  6107. LIST_HEAD(completions);
  6108. struct lpfc_hba *phba = vport->phba;
  6109. struct lpfc_sli *psli = &phba->sli;
  6110. struct lpfc_sli_ring *pring;
  6111. struct lpfc_iocbq *iocb, *next_iocb;
  6112. int i;
  6113. unsigned long flags = 0;
  6114. uint16_t prev_pring_flag;
  6115. lpfc_cleanup_discovery_resources(vport);
  6116. spin_lock_irqsave(&phba->hbalock, flags);
  6117. for (i = 0; i < psli->num_rings; i++) {
  6118. pring = &psli->ring[i];
  6119. prev_pring_flag = pring->flag;
  6120. /* Only slow rings */
  6121. if (pring->ringno == LPFC_ELS_RING) {
  6122. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6123. /* Set the lpfc data pending flag */
  6124. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6125. }
  6126. /*
  6127. * Error everything on the txq since these iocbs have not been
  6128. * given to the FW yet.
  6129. */
  6130. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6131. if (iocb->vport != vport)
  6132. continue;
  6133. list_move_tail(&iocb->list, &completions);
  6134. pring->txq_cnt--;
  6135. }
  6136. /* Next issue ABTS for everything on the txcmplq */
  6137. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6138. list) {
  6139. if (iocb->vport != vport)
  6140. continue;
  6141. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6142. }
  6143. pring->flag = prev_pring_flag;
  6144. }
  6145. spin_unlock_irqrestore(&phba->hbalock, flags);
  6146. /* Cancel all the IOCBs from the completions list */
  6147. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6148. IOERR_SLI_DOWN);
  6149. return 1;
  6150. }
  6151. /**
  6152. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6153. * @phba: Pointer to HBA context object.
  6154. *
  6155. * This function cleans up all iocb, buffers, mailbox commands
  6156. * while shutting down the HBA. This function is called with no
  6157. * lock held and always returns 1.
  6158. * This function does the following to cleanup driver resources:
  6159. * - Free discovery resources for each virtual port
  6160. * - Cleanup any pending fabric iocbs
  6161. * - Iterate through the iocb txq and free each entry
  6162. * in the list.
  6163. * - Free up any buffer posted to the HBA
  6164. * - Free mailbox commands in the mailbox queue.
  6165. **/
  6166. int
  6167. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6168. {
  6169. LIST_HEAD(completions);
  6170. struct lpfc_sli *psli = &phba->sli;
  6171. struct lpfc_sli_ring *pring;
  6172. struct lpfc_dmabuf *buf_ptr;
  6173. unsigned long flags = 0;
  6174. int i;
  6175. /* Shutdown the mailbox command sub-system */
  6176. lpfc_sli_mbox_sys_shutdown(phba);
  6177. lpfc_hba_down_prep(phba);
  6178. lpfc_fabric_abort_hba(phba);
  6179. spin_lock_irqsave(&phba->hbalock, flags);
  6180. for (i = 0; i < psli->num_rings; i++) {
  6181. pring = &psli->ring[i];
  6182. /* Only slow rings */
  6183. if (pring->ringno == LPFC_ELS_RING) {
  6184. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6185. /* Set the lpfc data pending flag */
  6186. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6187. }
  6188. /*
  6189. * Error everything on the txq since these iocbs have not been
  6190. * given to the FW yet.
  6191. */
  6192. list_splice_init(&pring->txq, &completions);
  6193. pring->txq_cnt = 0;
  6194. }
  6195. spin_unlock_irqrestore(&phba->hbalock, flags);
  6196. /* Cancel all the IOCBs from the completions list */
  6197. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6198. IOERR_SLI_DOWN);
  6199. spin_lock_irqsave(&phba->hbalock, flags);
  6200. list_splice_init(&phba->elsbuf, &completions);
  6201. phba->elsbuf_cnt = 0;
  6202. phba->elsbuf_prev_cnt = 0;
  6203. spin_unlock_irqrestore(&phba->hbalock, flags);
  6204. while (!list_empty(&completions)) {
  6205. list_remove_head(&completions, buf_ptr,
  6206. struct lpfc_dmabuf, list);
  6207. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6208. kfree(buf_ptr);
  6209. }
  6210. /* Return any active mbox cmds */
  6211. del_timer_sync(&psli->mbox_tmo);
  6212. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6213. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6214. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6215. return 1;
  6216. }
  6217. /**
  6218. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6219. * @phba: Pointer to HBA context object.
  6220. *
  6221. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6222. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6223. * lock held and always returns 1.
  6224. *
  6225. * This function does the following to cleanup driver FCoE function resources:
  6226. * - Free discovery resources for each virtual port
  6227. * - Cleanup any pending fabric iocbs
  6228. * - Iterate through the iocb txq and free each entry in the list.
  6229. * - Free up any buffer posted to the HBA.
  6230. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6231. * - Free mailbox commands in the mailbox queue.
  6232. **/
  6233. int
  6234. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6235. {
  6236. /* Stop the SLI4 device port */
  6237. lpfc_stop_port(phba);
  6238. /* Tear down the queues in the HBA */
  6239. lpfc_sli4_queue_unset(phba);
  6240. /* unregister default FCFI from the HBA */
  6241. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6242. return 1;
  6243. }
  6244. /**
  6245. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6246. * @srcp: Source memory pointer.
  6247. * @destp: Destination memory pointer.
  6248. * @cnt: Number of words required to be copied.
  6249. *
  6250. * This function is used for copying data between driver memory
  6251. * and the SLI memory. This function also changes the endianness
  6252. * of each word if native endianness is different from SLI
  6253. * endianness. This function can be called with or without
  6254. * lock.
  6255. **/
  6256. void
  6257. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6258. {
  6259. uint32_t *src = srcp;
  6260. uint32_t *dest = destp;
  6261. uint32_t ldata;
  6262. int i;
  6263. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6264. ldata = *src;
  6265. ldata = le32_to_cpu(ldata);
  6266. *dest = ldata;
  6267. src++;
  6268. dest++;
  6269. }
  6270. }
  6271. /**
  6272. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6273. * @srcp: Source memory pointer.
  6274. * @destp: Destination memory pointer.
  6275. * @cnt: Number of words required to be copied.
  6276. *
  6277. * This function is used for copying data between a data structure
  6278. * with big endian representation to local endianness.
  6279. * This function can be called with or without lock.
  6280. **/
  6281. void
  6282. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6283. {
  6284. uint32_t *src = srcp;
  6285. uint32_t *dest = destp;
  6286. uint32_t ldata;
  6287. int i;
  6288. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6289. ldata = *src;
  6290. ldata = be32_to_cpu(ldata);
  6291. *dest = ldata;
  6292. src++;
  6293. dest++;
  6294. }
  6295. }
  6296. /**
  6297. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6298. * @phba: Pointer to HBA context object.
  6299. * @pring: Pointer to driver SLI ring object.
  6300. * @mp: Pointer to driver buffer object.
  6301. *
  6302. * This function is called with no lock held.
  6303. * It always return zero after adding the buffer to the postbufq
  6304. * buffer list.
  6305. **/
  6306. int
  6307. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6308. struct lpfc_dmabuf *mp)
  6309. {
  6310. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6311. later */
  6312. spin_lock_irq(&phba->hbalock);
  6313. list_add_tail(&mp->list, &pring->postbufq);
  6314. pring->postbufq_cnt++;
  6315. spin_unlock_irq(&phba->hbalock);
  6316. return 0;
  6317. }
  6318. /**
  6319. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6320. * @phba: Pointer to HBA context object.
  6321. *
  6322. * When HBQ is enabled, buffers are searched based on tags. This function
  6323. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6324. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6325. * does not conflict with tags of buffer posted for unsolicited events.
  6326. * The function returns the allocated tag. The function is called with
  6327. * no locks held.
  6328. **/
  6329. uint32_t
  6330. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6331. {
  6332. spin_lock_irq(&phba->hbalock);
  6333. phba->buffer_tag_count++;
  6334. /*
  6335. * Always set the QUE_BUFTAG_BIT to distiguish between
  6336. * a tag assigned by HBQ.
  6337. */
  6338. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6339. spin_unlock_irq(&phba->hbalock);
  6340. return phba->buffer_tag_count;
  6341. }
  6342. /**
  6343. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6344. * @phba: Pointer to HBA context object.
  6345. * @pring: Pointer to driver SLI ring object.
  6346. * @tag: Buffer tag.
  6347. *
  6348. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6349. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6350. * iocb is posted to the response ring with the tag of the buffer.
  6351. * This function searches the pring->postbufq list using the tag
  6352. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6353. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6354. * buffer is returned to the caller else NULL is returned.
  6355. * This function is called with no lock held.
  6356. **/
  6357. struct lpfc_dmabuf *
  6358. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6359. uint32_t tag)
  6360. {
  6361. struct lpfc_dmabuf *mp, *next_mp;
  6362. struct list_head *slp = &pring->postbufq;
  6363. /* Search postbufq, from the begining, looking for a match on tag */
  6364. spin_lock_irq(&phba->hbalock);
  6365. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6366. if (mp->buffer_tag == tag) {
  6367. list_del_init(&mp->list);
  6368. pring->postbufq_cnt--;
  6369. spin_unlock_irq(&phba->hbalock);
  6370. return mp;
  6371. }
  6372. }
  6373. spin_unlock_irq(&phba->hbalock);
  6374. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6375. "0402 Cannot find virtual addr for buffer tag on "
  6376. "ring %d Data x%lx x%p x%p x%x\n",
  6377. pring->ringno, (unsigned long) tag,
  6378. slp->next, slp->prev, pring->postbufq_cnt);
  6379. return NULL;
  6380. }
  6381. /**
  6382. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6383. * @phba: Pointer to HBA context object.
  6384. * @pring: Pointer to driver SLI ring object.
  6385. * @phys: DMA address of the buffer.
  6386. *
  6387. * This function searches the buffer list using the dma_address
  6388. * of unsolicited event to find the driver's lpfc_dmabuf object
  6389. * corresponding to the dma_address. The function returns the
  6390. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6391. * This function is called by the ct and els unsolicited event
  6392. * handlers to get the buffer associated with the unsolicited
  6393. * event.
  6394. *
  6395. * This function is called with no lock held.
  6396. **/
  6397. struct lpfc_dmabuf *
  6398. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6399. dma_addr_t phys)
  6400. {
  6401. struct lpfc_dmabuf *mp, *next_mp;
  6402. struct list_head *slp = &pring->postbufq;
  6403. /* Search postbufq, from the begining, looking for a match on phys */
  6404. spin_lock_irq(&phba->hbalock);
  6405. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6406. if (mp->phys == phys) {
  6407. list_del_init(&mp->list);
  6408. pring->postbufq_cnt--;
  6409. spin_unlock_irq(&phba->hbalock);
  6410. return mp;
  6411. }
  6412. }
  6413. spin_unlock_irq(&phba->hbalock);
  6414. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6415. "0410 Cannot find virtual addr for mapped buf on "
  6416. "ring %d Data x%llx x%p x%p x%x\n",
  6417. pring->ringno, (unsigned long long)phys,
  6418. slp->next, slp->prev, pring->postbufq_cnt);
  6419. return NULL;
  6420. }
  6421. /**
  6422. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6423. * @phba: Pointer to HBA context object.
  6424. * @cmdiocb: Pointer to driver command iocb object.
  6425. * @rspiocb: Pointer to driver response iocb object.
  6426. *
  6427. * This function is the completion handler for the abort iocbs for
  6428. * ELS commands. This function is called from the ELS ring event
  6429. * handler with no lock held. This function frees memory resources
  6430. * associated with the abort iocb.
  6431. **/
  6432. static void
  6433. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6434. struct lpfc_iocbq *rspiocb)
  6435. {
  6436. IOCB_t *irsp = &rspiocb->iocb;
  6437. uint16_t abort_iotag, abort_context;
  6438. struct lpfc_iocbq *abort_iocb;
  6439. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6440. abort_iocb = NULL;
  6441. if (irsp->ulpStatus) {
  6442. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6443. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6444. spin_lock_irq(&phba->hbalock);
  6445. if (phba->sli_rev < LPFC_SLI_REV4) {
  6446. if (abort_iotag != 0 &&
  6447. abort_iotag <= phba->sli.last_iotag)
  6448. abort_iocb =
  6449. phba->sli.iocbq_lookup[abort_iotag];
  6450. } else
  6451. /* For sli4 the abort_tag is the XRI,
  6452. * so the abort routine puts the iotag of the iocb
  6453. * being aborted in the context field of the abort
  6454. * IOCB.
  6455. */
  6456. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6457. /*
  6458. * If the iocb is not found in Firmware queue the iocb
  6459. * might have completed already. Do not free it again.
  6460. */
  6461. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6462. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6463. spin_unlock_irq(&phba->hbalock);
  6464. lpfc_sli_release_iocbq(phba, cmdiocb);
  6465. return;
  6466. }
  6467. /* For SLI4 the ulpContext field for abort IOCB
  6468. * holds the iotag of the IOCB being aborted so
  6469. * the local abort_context needs to be reset to
  6470. * match the aborted IOCBs ulpContext.
  6471. */
  6472. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6473. abort_context = abort_iocb->iocb.ulpContext;
  6474. }
  6475. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6476. "0327 Cannot abort els iocb %p "
  6477. "with tag %x context %x, abort status %x, "
  6478. "abort code %x\n",
  6479. abort_iocb, abort_iotag, abort_context,
  6480. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6481. /*
  6482. * make sure we have the right iocbq before taking it
  6483. * off the txcmplq and try to call completion routine.
  6484. */
  6485. if (!abort_iocb ||
  6486. abort_iocb->iocb.ulpContext != abort_context ||
  6487. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6488. spin_unlock_irq(&phba->hbalock);
  6489. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6490. /*
  6491. * leave the SLI4 aborted command on the txcmplq
  6492. * list and the command complete WCQE's XB bit
  6493. * will tell whether the SGL (XRI) can be released
  6494. * immediately or to the aborted SGL list for the
  6495. * following abort XRI from the HBA.
  6496. */
  6497. list_del_init(&abort_iocb->list);
  6498. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6499. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6500. pring->txcmplq_cnt--;
  6501. }
  6502. /* Firmware could still be in progress of DMAing
  6503. * payload, so don't free data buffer till after
  6504. * a hbeat.
  6505. */
  6506. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6507. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6508. spin_unlock_irq(&phba->hbalock);
  6509. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6510. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6511. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6512. } else
  6513. spin_unlock_irq(&phba->hbalock);
  6514. }
  6515. lpfc_sli_release_iocbq(phba, cmdiocb);
  6516. return;
  6517. }
  6518. /**
  6519. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6520. * @phba: Pointer to HBA context object.
  6521. * @cmdiocb: Pointer to driver command iocb object.
  6522. * @rspiocb: Pointer to driver response iocb object.
  6523. *
  6524. * The function is called from SLI ring event handler with no
  6525. * lock held. This function is the completion handler for ELS commands
  6526. * which are aborted. The function frees memory resources used for
  6527. * the aborted ELS commands.
  6528. **/
  6529. static void
  6530. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6531. struct lpfc_iocbq *rspiocb)
  6532. {
  6533. IOCB_t *irsp = &rspiocb->iocb;
  6534. /* ELS cmd tag <ulpIoTag> completes */
  6535. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6536. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6537. "x%x x%x x%x\n",
  6538. irsp->ulpIoTag, irsp->ulpStatus,
  6539. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6540. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6541. lpfc_ct_free_iocb(phba, cmdiocb);
  6542. else
  6543. lpfc_els_free_iocb(phba, cmdiocb);
  6544. return;
  6545. }
  6546. /**
  6547. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6548. * @phba: Pointer to HBA context object.
  6549. * @pring: Pointer to driver SLI ring object.
  6550. * @cmdiocb: Pointer to driver command iocb object.
  6551. *
  6552. * This function issues an abort iocb for the provided command
  6553. * iocb. This function is called with hbalock held.
  6554. * The function returns 0 when it fails due to memory allocation
  6555. * failure or when the command iocb is an abort request.
  6556. **/
  6557. int
  6558. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6559. struct lpfc_iocbq *cmdiocb)
  6560. {
  6561. struct lpfc_vport *vport = cmdiocb->vport;
  6562. struct lpfc_iocbq *abtsiocbp;
  6563. IOCB_t *icmd = NULL;
  6564. IOCB_t *iabt = NULL;
  6565. int retval = IOCB_ERROR;
  6566. /*
  6567. * There are certain command types we don't want to abort. And we
  6568. * don't want to abort commands that are already in the process of
  6569. * being aborted.
  6570. */
  6571. icmd = &cmdiocb->iocb;
  6572. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6573. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6574. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6575. return 0;
  6576. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6577. * callback so that nothing happens when it finishes.
  6578. */
  6579. if ((vport->load_flag & FC_UNLOADING) &&
  6580. (pring->ringno == LPFC_ELS_RING)) {
  6581. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6582. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6583. else
  6584. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6585. goto abort_iotag_exit;
  6586. }
  6587. /* issue ABTS for this IOCB based on iotag */
  6588. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6589. if (abtsiocbp == NULL)
  6590. return 0;
  6591. /* This signals the response to set the correct status
  6592. * before calling the completion handler
  6593. */
  6594. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6595. iabt = &abtsiocbp->iocb;
  6596. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6597. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6598. if (phba->sli_rev == LPFC_SLI_REV4) {
  6599. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6600. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6601. }
  6602. else
  6603. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6604. iabt->ulpLe = 1;
  6605. iabt->ulpClass = icmd->ulpClass;
  6606. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6607. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6608. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6609. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6610. if (phba->link_state >= LPFC_LINK_UP)
  6611. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6612. else
  6613. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6614. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6615. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6616. "0339 Abort xri x%x, original iotag x%x, "
  6617. "abort cmd iotag x%x\n",
  6618. iabt->un.acxri.abortIoTag,
  6619. iabt->un.acxri.abortContextTag,
  6620. abtsiocbp->iotag);
  6621. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6622. if (retval)
  6623. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6624. abort_iotag_exit:
  6625. /*
  6626. * Caller to this routine should check for IOCB_ERROR
  6627. * and handle it properly. This routine no longer removes
  6628. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6629. */
  6630. return retval;
  6631. }
  6632. /**
  6633. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6634. * @iocbq: Pointer to driver iocb object.
  6635. * @vport: Pointer to driver virtual port object.
  6636. * @tgt_id: SCSI ID of the target.
  6637. * @lun_id: LUN ID of the scsi device.
  6638. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6639. *
  6640. * This function acts as an iocb filter for functions which abort or count
  6641. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6642. * 0 if the filtering criteria is met for the given iocb and will return
  6643. * 1 if the filtering criteria is not met.
  6644. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6645. * given iocb is for the SCSI device specified by vport, tgt_id and
  6646. * lun_id parameter.
  6647. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6648. * given iocb is for the SCSI target specified by vport and tgt_id
  6649. * parameters.
  6650. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6651. * given iocb is for the SCSI host associated with the given vport.
  6652. * This function is called with no locks held.
  6653. **/
  6654. static int
  6655. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6656. uint16_t tgt_id, uint64_t lun_id,
  6657. lpfc_ctx_cmd ctx_cmd)
  6658. {
  6659. struct lpfc_scsi_buf *lpfc_cmd;
  6660. int rc = 1;
  6661. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6662. return rc;
  6663. if (iocbq->vport != vport)
  6664. return rc;
  6665. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6666. if (lpfc_cmd->pCmd == NULL)
  6667. return rc;
  6668. switch (ctx_cmd) {
  6669. case LPFC_CTX_LUN:
  6670. if ((lpfc_cmd->rdata->pnode) &&
  6671. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6672. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6673. rc = 0;
  6674. break;
  6675. case LPFC_CTX_TGT:
  6676. if ((lpfc_cmd->rdata->pnode) &&
  6677. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6678. rc = 0;
  6679. break;
  6680. case LPFC_CTX_HOST:
  6681. rc = 0;
  6682. break;
  6683. default:
  6684. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6685. __func__, ctx_cmd);
  6686. break;
  6687. }
  6688. return rc;
  6689. }
  6690. /**
  6691. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6692. * @vport: Pointer to virtual port.
  6693. * @tgt_id: SCSI ID of the target.
  6694. * @lun_id: LUN ID of the scsi device.
  6695. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6696. *
  6697. * This function returns number of FCP commands pending for the vport.
  6698. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6699. * commands pending on the vport associated with SCSI device specified
  6700. * by tgt_id and lun_id parameters.
  6701. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6702. * commands pending on the vport associated with SCSI target specified
  6703. * by tgt_id parameter.
  6704. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6705. * commands pending on the vport.
  6706. * This function returns the number of iocbs which satisfy the filter.
  6707. * This function is called without any lock held.
  6708. **/
  6709. int
  6710. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6711. lpfc_ctx_cmd ctx_cmd)
  6712. {
  6713. struct lpfc_hba *phba = vport->phba;
  6714. struct lpfc_iocbq *iocbq;
  6715. int sum, i;
  6716. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6717. iocbq = phba->sli.iocbq_lookup[i];
  6718. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6719. ctx_cmd) == 0)
  6720. sum++;
  6721. }
  6722. return sum;
  6723. }
  6724. /**
  6725. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6726. * @phba: Pointer to HBA context object
  6727. * @cmdiocb: Pointer to command iocb object.
  6728. * @rspiocb: Pointer to response iocb object.
  6729. *
  6730. * This function is called when an aborted FCP iocb completes. This
  6731. * function is called by the ring event handler with no lock held.
  6732. * This function frees the iocb.
  6733. **/
  6734. void
  6735. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6736. struct lpfc_iocbq *rspiocb)
  6737. {
  6738. lpfc_sli_release_iocbq(phba, cmdiocb);
  6739. return;
  6740. }
  6741. /**
  6742. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6743. * @vport: Pointer to virtual port.
  6744. * @pring: Pointer to driver SLI ring object.
  6745. * @tgt_id: SCSI ID of the target.
  6746. * @lun_id: LUN ID of the scsi device.
  6747. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6748. *
  6749. * This function sends an abort command for every SCSI command
  6750. * associated with the given virtual port pending on the ring
  6751. * filtered by lpfc_sli_validate_fcp_iocb function.
  6752. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6753. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6754. * parameters
  6755. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6756. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6757. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6758. * FCP iocbs associated with virtual port.
  6759. * This function returns number of iocbs it failed to abort.
  6760. * This function is called with no locks held.
  6761. **/
  6762. int
  6763. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6764. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6765. {
  6766. struct lpfc_hba *phba = vport->phba;
  6767. struct lpfc_iocbq *iocbq;
  6768. struct lpfc_iocbq *abtsiocb;
  6769. IOCB_t *cmd = NULL;
  6770. int errcnt = 0, ret_val = 0;
  6771. int i;
  6772. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6773. iocbq = phba->sli.iocbq_lookup[i];
  6774. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6775. abort_cmd) != 0)
  6776. continue;
  6777. /* issue ABTS for this IOCB based on iotag */
  6778. abtsiocb = lpfc_sli_get_iocbq(phba);
  6779. if (abtsiocb == NULL) {
  6780. errcnt++;
  6781. continue;
  6782. }
  6783. cmd = &iocbq->iocb;
  6784. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6785. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6786. if (phba->sli_rev == LPFC_SLI_REV4)
  6787. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6788. else
  6789. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6790. abtsiocb->iocb.ulpLe = 1;
  6791. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6792. abtsiocb->vport = phba->pport;
  6793. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6794. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6795. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6796. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6797. if (lpfc_is_link_up(phba))
  6798. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6799. else
  6800. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6801. /* Setup callback routine and issue the command. */
  6802. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6803. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6804. abtsiocb, 0);
  6805. if (ret_val == IOCB_ERROR) {
  6806. lpfc_sli_release_iocbq(phba, abtsiocb);
  6807. errcnt++;
  6808. continue;
  6809. }
  6810. }
  6811. return errcnt;
  6812. }
  6813. /**
  6814. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6815. * @phba: Pointer to HBA context object.
  6816. * @cmdiocbq: Pointer to command iocb.
  6817. * @rspiocbq: Pointer to response iocb.
  6818. *
  6819. * This function is the completion handler for iocbs issued using
  6820. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6821. * ring event handler function without any lock held. This function
  6822. * can be called from both worker thread context and interrupt
  6823. * context. This function also can be called from other thread which
  6824. * cleans up the SLI layer objects.
  6825. * This function copy the contents of the response iocb to the
  6826. * response iocb memory object provided by the caller of
  6827. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6828. * sleeps for the iocb completion.
  6829. **/
  6830. static void
  6831. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6832. struct lpfc_iocbq *cmdiocbq,
  6833. struct lpfc_iocbq *rspiocbq)
  6834. {
  6835. wait_queue_head_t *pdone_q;
  6836. unsigned long iflags;
  6837. struct lpfc_scsi_buf *lpfc_cmd;
  6838. spin_lock_irqsave(&phba->hbalock, iflags);
  6839. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6840. if (cmdiocbq->context2 && rspiocbq)
  6841. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6842. &rspiocbq->iocb, sizeof(IOCB_t));
  6843. /* Set the exchange busy flag for task management commands */
  6844. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  6845. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  6846. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  6847. cur_iocbq);
  6848. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  6849. }
  6850. pdone_q = cmdiocbq->context_un.wait_queue;
  6851. if (pdone_q)
  6852. wake_up(pdone_q);
  6853. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6854. return;
  6855. }
  6856. /**
  6857. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6858. * @phba: Pointer to HBA context object..
  6859. * @piocbq: Pointer to command iocb.
  6860. * @flag: Flag to test.
  6861. *
  6862. * This routine grabs the hbalock and then test the iocb_flag to
  6863. * see if the passed in flag is set.
  6864. * Returns:
  6865. * 1 if flag is set.
  6866. * 0 if flag is not set.
  6867. **/
  6868. static int
  6869. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6870. struct lpfc_iocbq *piocbq, uint32_t flag)
  6871. {
  6872. unsigned long iflags;
  6873. int ret;
  6874. spin_lock_irqsave(&phba->hbalock, iflags);
  6875. ret = piocbq->iocb_flag & flag;
  6876. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6877. return ret;
  6878. }
  6879. /**
  6880. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6881. * @phba: Pointer to HBA context object..
  6882. * @pring: Pointer to sli ring.
  6883. * @piocb: Pointer to command iocb.
  6884. * @prspiocbq: Pointer to response iocb.
  6885. * @timeout: Timeout in number of seconds.
  6886. *
  6887. * This function issues the iocb to firmware and waits for the
  6888. * iocb to complete. If the iocb command is not
  6889. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6890. * Caller should not free the iocb resources if this function
  6891. * returns IOCB_TIMEDOUT.
  6892. * The function waits for the iocb completion using an
  6893. * non-interruptible wait.
  6894. * This function will sleep while waiting for iocb completion.
  6895. * So, this function should not be called from any context which
  6896. * does not allow sleeping. Due to the same reason, this function
  6897. * cannot be called with interrupt disabled.
  6898. * This function assumes that the iocb completions occur while
  6899. * this function sleep. So, this function cannot be called from
  6900. * the thread which process iocb completion for this ring.
  6901. * This function clears the iocb_flag of the iocb object before
  6902. * issuing the iocb and the iocb completion handler sets this
  6903. * flag and wakes this thread when the iocb completes.
  6904. * The contents of the response iocb will be copied to prspiocbq
  6905. * by the completion handler when the command completes.
  6906. * This function returns IOCB_SUCCESS when success.
  6907. * This function is called with no lock held.
  6908. **/
  6909. int
  6910. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6911. uint32_t ring_number,
  6912. struct lpfc_iocbq *piocb,
  6913. struct lpfc_iocbq *prspiocbq,
  6914. uint32_t timeout)
  6915. {
  6916. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6917. long timeleft, timeout_req = 0;
  6918. int retval = IOCB_SUCCESS;
  6919. uint32_t creg_val;
  6920. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6921. /*
  6922. * If the caller has provided a response iocbq buffer, then context2
  6923. * is NULL or its an error.
  6924. */
  6925. if (prspiocbq) {
  6926. if (piocb->context2)
  6927. return IOCB_ERROR;
  6928. piocb->context2 = prspiocbq;
  6929. }
  6930. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6931. piocb->context_un.wait_queue = &done_q;
  6932. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6933. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6934. creg_val = readl(phba->HCregaddr);
  6935. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6936. writel(creg_val, phba->HCregaddr);
  6937. readl(phba->HCregaddr); /* flush */
  6938. }
  6939. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  6940. SLI_IOCB_RET_IOCB);
  6941. if (retval == IOCB_SUCCESS) {
  6942. timeout_req = timeout * HZ;
  6943. timeleft = wait_event_timeout(done_q,
  6944. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6945. timeout_req);
  6946. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6947. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6948. "0331 IOCB wake signaled\n");
  6949. } else if (timeleft == 0) {
  6950. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6951. "0338 IOCB wait timeout error - no "
  6952. "wake response Data x%x\n", timeout);
  6953. retval = IOCB_TIMEDOUT;
  6954. } else {
  6955. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6956. "0330 IOCB wake NOT set, "
  6957. "Data x%x x%lx\n",
  6958. timeout, (timeleft / jiffies));
  6959. retval = IOCB_TIMEDOUT;
  6960. }
  6961. } else if (retval == IOCB_BUSY) {
  6962. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6963. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  6964. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  6965. return retval;
  6966. } else {
  6967. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6968. "0332 IOCB wait issue failed, Data x%x\n",
  6969. retval);
  6970. retval = IOCB_ERROR;
  6971. }
  6972. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6973. creg_val = readl(phba->HCregaddr);
  6974. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6975. writel(creg_val, phba->HCregaddr);
  6976. readl(phba->HCregaddr); /* flush */
  6977. }
  6978. if (prspiocbq)
  6979. piocb->context2 = NULL;
  6980. piocb->context_un.wait_queue = NULL;
  6981. piocb->iocb_cmpl = NULL;
  6982. return retval;
  6983. }
  6984. /**
  6985. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6986. * @phba: Pointer to HBA context object.
  6987. * @pmboxq: Pointer to driver mailbox object.
  6988. * @timeout: Timeout in number of seconds.
  6989. *
  6990. * This function issues the mailbox to firmware and waits for the
  6991. * mailbox command to complete. If the mailbox command is not
  6992. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6993. * The function waits for the mailbox completion using an
  6994. * interruptible wait. If the thread is woken up due to a
  6995. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6996. * should not free the mailbox resources, if this function returns
  6997. * MBX_TIMEOUT.
  6998. * This function will sleep while waiting for mailbox completion.
  6999. * So, this function should not be called from any context which
  7000. * does not allow sleeping. Due to the same reason, this function
  7001. * cannot be called with interrupt disabled.
  7002. * This function assumes that the mailbox completion occurs while
  7003. * this function sleep. So, this function cannot be called from
  7004. * the worker thread which processes mailbox completion.
  7005. * This function is called in the context of HBA management
  7006. * applications.
  7007. * This function returns MBX_SUCCESS when successful.
  7008. * This function is called with no lock held.
  7009. **/
  7010. int
  7011. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7012. uint32_t timeout)
  7013. {
  7014. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7015. int retval;
  7016. unsigned long flag;
  7017. /* The caller must leave context1 empty. */
  7018. if (pmboxq->context1)
  7019. return MBX_NOT_FINISHED;
  7020. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7021. /* setup wake call as IOCB callback */
  7022. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7023. /* setup context field to pass wait_queue pointer to wake function */
  7024. pmboxq->context1 = &done_q;
  7025. /* now issue the command */
  7026. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7027. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7028. wait_event_interruptible_timeout(done_q,
  7029. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7030. timeout * HZ);
  7031. spin_lock_irqsave(&phba->hbalock, flag);
  7032. pmboxq->context1 = NULL;
  7033. /*
  7034. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7035. * else do not free the resources.
  7036. */
  7037. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  7038. retval = MBX_SUCCESS;
  7039. else {
  7040. retval = MBX_TIMEOUT;
  7041. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7042. }
  7043. spin_unlock_irqrestore(&phba->hbalock, flag);
  7044. }
  7045. return retval;
  7046. }
  7047. /**
  7048. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7049. * @phba: Pointer to HBA context.
  7050. *
  7051. * This function is called to shutdown the driver's mailbox sub-system.
  7052. * It first marks the mailbox sub-system is in a block state to prevent
  7053. * the asynchronous mailbox command from issued off the pending mailbox
  7054. * command queue. If the mailbox command sub-system shutdown is due to
  7055. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7056. * the mailbox sub-system flush routine to forcefully bring down the
  7057. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7058. * as with offline or HBA function reset), this routine will wait for the
  7059. * outstanding mailbox command to complete before invoking the mailbox
  7060. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7061. **/
  7062. void
  7063. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7064. {
  7065. struct lpfc_sli *psli = &phba->sli;
  7066. uint8_t actcmd = MBX_HEARTBEAT;
  7067. unsigned long timeout;
  7068. spin_lock_irq(&phba->hbalock);
  7069. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7070. spin_unlock_irq(&phba->hbalock);
  7071. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7072. spin_lock_irq(&phba->hbalock);
  7073. if (phba->sli.mbox_active)
  7074. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7075. spin_unlock_irq(&phba->hbalock);
  7076. /* Determine how long we might wait for the active mailbox
  7077. * command to be gracefully completed by firmware.
  7078. */
  7079. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7080. 1000) + jiffies;
  7081. while (phba->sli.mbox_active) {
  7082. /* Check active mailbox complete status every 2ms */
  7083. msleep(2);
  7084. if (time_after(jiffies, timeout))
  7085. /* Timeout, let the mailbox flush routine to
  7086. * forcefully release active mailbox command
  7087. */
  7088. break;
  7089. }
  7090. }
  7091. lpfc_sli_mbox_sys_flush(phba);
  7092. }
  7093. /**
  7094. * lpfc_sli_eratt_read - read sli-3 error attention events
  7095. * @phba: Pointer to HBA context.
  7096. *
  7097. * This function is called to read the SLI3 device error attention registers
  7098. * for possible error attention events. The caller must hold the hostlock
  7099. * with spin_lock_irq().
  7100. *
  7101. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7102. * Register and returns 0 otherwise.
  7103. **/
  7104. static int
  7105. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7106. {
  7107. uint32_t ha_copy;
  7108. /* Read chip Host Attention (HA) register */
  7109. ha_copy = readl(phba->HAregaddr);
  7110. if (ha_copy & HA_ERATT) {
  7111. /* Read host status register to retrieve error event */
  7112. lpfc_sli_read_hs(phba);
  7113. /* Check if there is a deferred error condition is active */
  7114. if ((HS_FFER1 & phba->work_hs) &&
  7115. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7116. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7117. phba->hba_flag |= DEFER_ERATT;
  7118. /* Clear all interrupt enable conditions */
  7119. writel(0, phba->HCregaddr);
  7120. readl(phba->HCregaddr);
  7121. }
  7122. /* Set the driver HA work bitmap */
  7123. phba->work_ha |= HA_ERATT;
  7124. /* Indicate polling handles this ERATT */
  7125. phba->hba_flag |= HBA_ERATT_HANDLED;
  7126. return 1;
  7127. }
  7128. return 0;
  7129. }
  7130. /**
  7131. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7132. * @phba: Pointer to HBA context.
  7133. *
  7134. * This function is called to read the SLI4 device error attention registers
  7135. * for possible error attention events. The caller must hold the hostlock
  7136. * with spin_lock_irq().
  7137. *
  7138. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7139. * Register and returns 0 otherwise.
  7140. **/
  7141. static int
  7142. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7143. {
  7144. uint32_t uerr_sta_hi, uerr_sta_lo;
  7145. /* For now, use the SLI4 device internal unrecoverable error
  7146. * registers for error attention. This can be changed later.
  7147. */
  7148. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7149. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7150. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7151. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7152. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7153. "1423 HBA Unrecoverable error: "
  7154. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7155. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7156. uerr_sta_lo, uerr_sta_hi,
  7157. phba->sli4_hba.ue_mask_lo,
  7158. phba->sli4_hba.ue_mask_hi);
  7159. phba->work_status[0] = uerr_sta_lo;
  7160. phba->work_status[1] = uerr_sta_hi;
  7161. /* Set the driver HA work bitmap */
  7162. phba->work_ha |= HA_ERATT;
  7163. /* Indicate polling handles this ERATT */
  7164. phba->hba_flag |= HBA_ERATT_HANDLED;
  7165. return 1;
  7166. }
  7167. return 0;
  7168. }
  7169. /**
  7170. * lpfc_sli_check_eratt - check error attention events
  7171. * @phba: Pointer to HBA context.
  7172. *
  7173. * This function is called from timer soft interrupt context to check HBA's
  7174. * error attention register bit for error attention events.
  7175. *
  7176. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7177. * Register and returns 0 otherwise.
  7178. **/
  7179. int
  7180. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7181. {
  7182. uint32_t ha_copy;
  7183. /* If somebody is waiting to handle an eratt, don't process it
  7184. * here. The brdkill function will do this.
  7185. */
  7186. if (phba->link_flag & LS_IGNORE_ERATT)
  7187. return 0;
  7188. /* Check if interrupt handler handles this ERATT */
  7189. spin_lock_irq(&phba->hbalock);
  7190. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7191. /* Interrupt handler has handled ERATT */
  7192. spin_unlock_irq(&phba->hbalock);
  7193. return 0;
  7194. }
  7195. /*
  7196. * If there is deferred error attention, do not check for error
  7197. * attention
  7198. */
  7199. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7200. spin_unlock_irq(&phba->hbalock);
  7201. return 0;
  7202. }
  7203. /* If PCI channel is offline, don't process it */
  7204. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7205. spin_unlock_irq(&phba->hbalock);
  7206. return 0;
  7207. }
  7208. switch (phba->sli_rev) {
  7209. case LPFC_SLI_REV2:
  7210. case LPFC_SLI_REV3:
  7211. /* Read chip Host Attention (HA) register */
  7212. ha_copy = lpfc_sli_eratt_read(phba);
  7213. break;
  7214. case LPFC_SLI_REV4:
  7215. /* Read devcie Uncoverable Error (UERR) registers */
  7216. ha_copy = lpfc_sli4_eratt_read(phba);
  7217. break;
  7218. default:
  7219. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7220. "0299 Invalid SLI revision (%d)\n",
  7221. phba->sli_rev);
  7222. ha_copy = 0;
  7223. break;
  7224. }
  7225. spin_unlock_irq(&phba->hbalock);
  7226. return ha_copy;
  7227. }
  7228. /**
  7229. * lpfc_intr_state_check - Check device state for interrupt handling
  7230. * @phba: Pointer to HBA context.
  7231. *
  7232. * This inline routine checks whether a device or its PCI slot is in a state
  7233. * that the interrupt should be handled.
  7234. *
  7235. * This function returns 0 if the device or the PCI slot is in a state that
  7236. * interrupt should be handled, otherwise -EIO.
  7237. */
  7238. static inline int
  7239. lpfc_intr_state_check(struct lpfc_hba *phba)
  7240. {
  7241. /* If the pci channel is offline, ignore all the interrupts */
  7242. if (unlikely(pci_channel_offline(phba->pcidev)))
  7243. return -EIO;
  7244. /* Update device level interrupt statistics */
  7245. phba->sli.slistat.sli_intr++;
  7246. /* Ignore all interrupts during initialization. */
  7247. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7248. return -EIO;
  7249. return 0;
  7250. }
  7251. /**
  7252. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7253. * @irq: Interrupt number.
  7254. * @dev_id: The device context pointer.
  7255. *
  7256. * This function is directly called from the PCI layer as an interrupt
  7257. * service routine when device with SLI-3 interface spec is enabled with
  7258. * MSI-X multi-message interrupt mode and there are slow-path events in
  7259. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7260. * interrupt mode, this function is called as part of the device-level
  7261. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7262. * is undergoing initialization, the interrupt handler will not process
  7263. * the interrupt. The link attention and ELS ring attention events are
  7264. * handled by the worker thread. The interrupt handler signals the worker
  7265. * thread and returns for these events. This function is called without
  7266. * any lock held. It gets the hbalock to access and update SLI data
  7267. * structures.
  7268. *
  7269. * This function returns IRQ_HANDLED when interrupt is handled else it
  7270. * returns IRQ_NONE.
  7271. **/
  7272. irqreturn_t
  7273. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7274. {
  7275. struct lpfc_hba *phba;
  7276. uint32_t ha_copy, hc_copy;
  7277. uint32_t work_ha_copy;
  7278. unsigned long status;
  7279. unsigned long iflag;
  7280. uint32_t control;
  7281. MAILBOX_t *mbox, *pmbox;
  7282. struct lpfc_vport *vport;
  7283. struct lpfc_nodelist *ndlp;
  7284. struct lpfc_dmabuf *mp;
  7285. LPFC_MBOXQ_t *pmb;
  7286. int rc;
  7287. /*
  7288. * Get the driver's phba structure from the dev_id and
  7289. * assume the HBA is not interrupting.
  7290. */
  7291. phba = (struct lpfc_hba *)dev_id;
  7292. if (unlikely(!phba))
  7293. return IRQ_NONE;
  7294. /*
  7295. * Stuff needs to be attented to when this function is invoked as an
  7296. * individual interrupt handler in MSI-X multi-message interrupt mode
  7297. */
  7298. if (phba->intr_type == MSIX) {
  7299. /* Check device state for handling interrupt */
  7300. if (lpfc_intr_state_check(phba))
  7301. return IRQ_NONE;
  7302. /* Need to read HA REG for slow-path events */
  7303. spin_lock_irqsave(&phba->hbalock, iflag);
  7304. ha_copy = readl(phba->HAregaddr);
  7305. /* If somebody is waiting to handle an eratt don't process it
  7306. * here. The brdkill function will do this.
  7307. */
  7308. if (phba->link_flag & LS_IGNORE_ERATT)
  7309. ha_copy &= ~HA_ERATT;
  7310. /* Check the need for handling ERATT in interrupt handler */
  7311. if (ha_copy & HA_ERATT) {
  7312. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7313. /* ERATT polling has handled ERATT */
  7314. ha_copy &= ~HA_ERATT;
  7315. else
  7316. /* Indicate interrupt handler handles ERATT */
  7317. phba->hba_flag |= HBA_ERATT_HANDLED;
  7318. }
  7319. /*
  7320. * If there is deferred error attention, do not check for any
  7321. * interrupt.
  7322. */
  7323. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7324. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7325. return IRQ_NONE;
  7326. }
  7327. /* Clear up only attention source related to slow-path */
  7328. hc_copy = readl(phba->HCregaddr);
  7329. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7330. HC_LAINT_ENA | HC_ERINT_ENA),
  7331. phba->HCregaddr);
  7332. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7333. phba->HAregaddr);
  7334. writel(hc_copy, phba->HCregaddr);
  7335. readl(phba->HAregaddr); /* flush */
  7336. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7337. } else
  7338. ha_copy = phba->ha_copy;
  7339. work_ha_copy = ha_copy & phba->work_ha_mask;
  7340. if (work_ha_copy) {
  7341. if (work_ha_copy & HA_LATT) {
  7342. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7343. /*
  7344. * Turn off Link Attention interrupts
  7345. * until CLEAR_LA done
  7346. */
  7347. spin_lock_irqsave(&phba->hbalock, iflag);
  7348. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7349. control = readl(phba->HCregaddr);
  7350. control &= ~HC_LAINT_ENA;
  7351. writel(control, phba->HCregaddr);
  7352. readl(phba->HCregaddr); /* flush */
  7353. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7354. }
  7355. else
  7356. work_ha_copy &= ~HA_LATT;
  7357. }
  7358. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7359. /*
  7360. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7361. * the only slow ring.
  7362. */
  7363. status = (work_ha_copy &
  7364. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7365. status >>= (4*LPFC_ELS_RING);
  7366. if (status & HA_RXMASK) {
  7367. spin_lock_irqsave(&phba->hbalock, iflag);
  7368. control = readl(phba->HCregaddr);
  7369. lpfc_debugfs_slow_ring_trc(phba,
  7370. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7371. control, status,
  7372. (uint32_t)phba->sli.slistat.sli_intr);
  7373. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7374. lpfc_debugfs_slow_ring_trc(phba,
  7375. "ISR Disable ring:"
  7376. "pwork:x%x hawork:x%x wait:x%x",
  7377. phba->work_ha, work_ha_copy,
  7378. (uint32_t)((unsigned long)
  7379. &phba->work_waitq));
  7380. control &=
  7381. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7382. writel(control, phba->HCregaddr);
  7383. readl(phba->HCregaddr); /* flush */
  7384. }
  7385. else {
  7386. lpfc_debugfs_slow_ring_trc(phba,
  7387. "ISR slow ring: pwork:"
  7388. "x%x hawork:x%x wait:x%x",
  7389. phba->work_ha, work_ha_copy,
  7390. (uint32_t)((unsigned long)
  7391. &phba->work_waitq));
  7392. }
  7393. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7394. }
  7395. }
  7396. spin_lock_irqsave(&phba->hbalock, iflag);
  7397. if (work_ha_copy & HA_ERATT) {
  7398. lpfc_sli_read_hs(phba);
  7399. /*
  7400. * Check if there is a deferred error condition
  7401. * is active
  7402. */
  7403. if ((HS_FFER1 & phba->work_hs) &&
  7404. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7405. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7406. phba->hba_flag |= DEFER_ERATT;
  7407. /* Clear all interrupt enable conditions */
  7408. writel(0, phba->HCregaddr);
  7409. readl(phba->HCregaddr);
  7410. }
  7411. }
  7412. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7413. pmb = phba->sli.mbox_active;
  7414. pmbox = &pmb->u.mb;
  7415. mbox = phba->mbox;
  7416. vport = pmb->vport;
  7417. /* First check out the status word */
  7418. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7419. if (pmbox->mbxOwner != OWN_HOST) {
  7420. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7421. /*
  7422. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7423. * mbxStatus <status>
  7424. */
  7425. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7426. LOG_SLI,
  7427. "(%d):0304 Stray Mailbox "
  7428. "Interrupt mbxCommand x%x "
  7429. "mbxStatus x%x\n",
  7430. (vport ? vport->vpi : 0),
  7431. pmbox->mbxCommand,
  7432. pmbox->mbxStatus);
  7433. /* clear mailbox attention bit */
  7434. work_ha_copy &= ~HA_MBATT;
  7435. } else {
  7436. phba->sli.mbox_active = NULL;
  7437. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7438. phba->last_completion_time = jiffies;
  7439. del_timer(&phba->sli.mbox_tmo);
  7440. if (pmb->mbox_cmpl) {
  7441. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7442. MAILBOX_CMD_SIZE);
  7443. if (pmb->out_ext_byte_len &&
  7444. pmb->context2)
  7445. lpfc_sli_pcimem_bcopy(
  7446. phba->mbox_ext,
  7447. pmb->context2,
  7448. pmb->out_ext_byte_len);
  7449. }
  7450. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7451. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7452. lpfc_debugfs_disc_trc(vport,
  7453. LPFC_DISC_TRC_MBOX_VPORT,
  7454. "MBOX dflt rpi: : "
  7455. "status:x%x rpi:x%x",
  7456. (uint32_t)pmbox->mbxStatus,
  7457. pmbox->un.varWords[0], 0);
  7458. if (!pmbox->mbxStatus) {
  7459. mp = (struct lpfc_dmabuf *)
  7460. (pmb->context1);
  7461. ndlp = (struct lpfc_nodelist *)
  7462. pmb->context2;
  7463. /* Reg_LOGIN of dflt RPI was
  7464. * successful. new lets get
  7465. * rid of the RPI using the
  7466. * same mbox buffer.
  7467. */
  7468. lpfc_unreg_login(phba,
  7469. vport->vpi,
  7470. pmbox->un.varWords[0],
  7471. pmb);
  7472. pmb->mbox_cmpl =
  7473. lpfc_mbx_cmpl_dflt_rpi;
  7474. pmb->context1 = mp;
  7475. pmb->context2 = ndlp;
  7476. pmb->vport = vport;
  7477. rc = lpfc_sli_issue_mbox(phba,
  7478. pmb,
  7479. MBX_NOWAIT);
  7480. if (rc != MBX_BUSY)
  7481. lpfc_printf_log(phba,
  7482. KERN_ERR,
  7483. LOG_MBOX | LOG_SLI,
  7484. "0350 rc should have"
  7485. "been MBX_BUSY\n");
  7486. if (rc != MBX_NOT_FINISHED)
  7487. goto send_current_mbox;
  7488. }
  7489. }
  7490. spin_lock_irqsave(
  7491. &phba->pport->work_port_lock,
  7492. iflag);
  7493. phba->pport->work_port_events &=
  7494. ~WORKER_MBOX_TMO;
  7495. spin_unlock_irqrestore(
  7496. &phba->pport->work_port_lock,
  7497. iflag);
  7498. lpfc_mbox_cmpl_put(phba, pmb);
  7499. }
  7500. } else
  7501. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7502. if ((work_ha_copy & HA_MBATT) &&
  7503. (phba->sli.mbox_active == NULL)) {
  7504. send_current_mbox:
  7505. /* Process next mailbox command if there is one */
  7506. do {
  7507. rc = lpfc_sli_issue_mbox(phba, NULL,
  7508. MBX_NOWAIT);
  7509. } while (rc == MBX_NOT_FINISHED);
  7510. if (rc != MBX_SUCCESS)
  7511. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7512. LOG_SLI, "0349 rc should be "
  7513. "MBX_SUCCESS\n");
  7514. }
  7515. spin_lock_irqsave(&phba->hbalock, iflag);
  7516. phba->work_ha |= work_ha_copy;
  7517. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7518. lpfc_worker_wake_up(phba);
  7519. }
  7520. return IRQ_HANDLED;
  7521. } /* lpfc_sli_sp_intr_handler */
  7522. /**
  7523. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7524. * @irq: Interrupt number.
  7525. * @dev_id: The device context pointer.
  7526. *
  7527. * This function is directly called from the PCI layer as an interrupt
  7528. * service routine when device with SLI-3 interface spec is enabled with
  7529. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7530. * ring event in the HBA. However, when the device is enabled with either
  7531. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7532. * device-level interrupt handler. When the PCI slot is in error recovery
  7533. * or the HBA is undergoing initialization, the interrupt handler will not
  7534. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7535. * the intrrupt context. This function is called without any lock held.
  7536. * It gets the hbalock to access and update SLI data structures.
  7537. *
  7538. * This function returns IRQ_HANDLED when interrupt is handled else it
  7539. * returns IRQ_NONE.
  7540. **/
  7541. irqreturn_t
  7542. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7543. {
  7544. struct lpfc_hba *phba;
  7545. uint32_t ha_copy;
  7546. unsigned long status;
  7547. unsigned long iflag;
  7548. /* Get the driver's phba structure from the dev_id and
  7549. * assume the HBA is not interrupting.
  7550. */
  7551. phba = (struct lpfc_hba *) dev_id;
  7552. if (unlikely(!phba))
  7553. return IRQ_NONE;
  7554. /*
  7555. * Stuff needs to be attented to when this function is invoked as an
  7556. * individual interrupt handler in MSI-X multi-message interrupt mode
  7557. */
  7558. if (phba->intr_type == MSIX) {
  7559. /* Check device state for handling interrupt */
  7560. if (lpfc_intr_state_check(phba))
  7561. return IRQ_NONE;
  7562. /* Need to read HA REG for FCP ring and other ring events */
  7563. ha_copy = readl(phba->HAregaddr);
  7564. /* Clear up only attention source related to fast-path */
  7565. spin_lock_irqsave(&phba->hbalock, iflag);
  7566. /*
  7567. * If there is deferred error attention, do not check for
  7568. * any interrupt.
  7569. */
  7570. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7571. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7572. return IRQ_NONE;
  7573. }
  7574. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7575. phba->HAregaddr);
  7576. readl(phba->HAregaddr); /* flush */
  7577. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7578. } else
  7579. ha_copy = phba->ha_copy;
  7580. /*
  7581. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7582. */
  7583. ha_copy &= ~(phba->work_ha_mask);
  7584. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7585. status >>= (4*LPFC_FCP_RING);
  7586. if (status & HA_RXMASK)
  7587. lpfc_sli_handle_fast_ring_event(phba,
  7588. &phba->sli.ring[LPFC_FCP_RING],
  7589. status);
  7590. if (phba->cfg_multi_ring_support == 2) {
  7591. /*
  7592. * Process all events on extra ring. Take the optimized path
  7593. * for extra ring IO.
  7594. */
  7595. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7596. status >>= (4*LPFC_EXTRA_RING);
  7597. if (status & HA_RXMASK) {
  7598. lpfc_sli_handle_fast_ring_event(phba,
  7599. &phba->sli.ring[LPFC_EXTRA_RING],
  7600. status);
  7601. }
  7602. }
  7603. return IRQ_HANDLED;
  7604. } /* lpfc_sli_fp_intr_handler */
  7605. /**
  7606. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7607. * @irq: Interrupt number.
  7608. * @dev_id: The device context pointer.
  7609. *
  7610. * This function is the HBA device-level interrupt handler to device with
  7611. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7612. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7613. * requires driver attention. This function invokes the slow-path interrupt
  7614. * attention handling function and fast-path interrupt attention handling
  7615. * function in turn to process the relevant HBA attention events. This
  7616. * function is called without any lock held. It gets the hbalock to access
  7617. * and update SLI data structures.
  7618. *
  7619. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7620. * returns IRQ_NONE.
  7621. **/
  7622. irqreturn_t
  7623. lpfc_sli_intr_handler(int irq, void *dev_id)
  7624. {
  7625. struct lpfc_hba *phba;
  7626. irqreturn_t sp_irq_rc, fp_irq_rc;
  7627. unsigned long status1, status2;
  7628. uint32_t hc_copy;
  7629. /*
  7630. * Get the driver's phba structure from the dev_id and
  7631. * assume the HBA is not interrupting.
  7632. */
  7633. phba = (struct lpfc_hba *) dev_id;
  7634. if (unlikely(!phba))
  7635. return IRQ_NONE;
  7636. /* Check device state for handling interrupt */
  7637. if (lpfc_intr_state_check(phba))
  7638. return IRQ_NONE;
  7639. spin_lock(&phba->hbalock);
  7640. phba->ha_copy = readl(phba->HAregaddr);
  7641. if (unlikely(!phba->ha_copy)) {
  7642. spin_unlock(&phba->hbalock);
  7643. return IRQ_NONE;
  7644. } else if (phba->ha_copy & HA_ERATT) {
  7645. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7646. /* ERATT polling has handled ERATT */
  7647. phba->ha_copy &= ~HA_ERATT;
  7648. else
  7649. /* Indicate interrupt handler handles ERATT */
  7650. phba->hba_flag |= HBA_ERATT_HANDLED;
  7651. }
  7652. /*
  7653. * If there is deferred error attention, do not check for any interrupt.
  7654. */
  7655. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7656. spin_unlock_irq(&phba->hbalock);
  7657. return IRQ_NONE;
  7658. }
  7659. /* Clear attention sources except link and error attentions */
  7660. hc_copy = readl(phba->HCregaddr);
  7661. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7662. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7663. phba->HCregaddr);
  7664. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7665. writel(hc_copy, phba->HCregaddr);
  7666. readl(phba->HAregaddr); /* flush */
  7667. spin_unlock(&phba->hbalock);
  7668. /*
  7669. * Invokes slow-path host attention interrupt handling as appropriate.
  7670. */
  7671. /* status of events with mailbox and link attention */
  7672. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7673. /* status of events with ELS ring */
  7674. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7675. status2 >>= (4*LPFC_ELS_RING);
  7676. if (status1 || (status2 & HA_RXMASK))
  7677. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7678. else
  7679. sp_irq_rc = IRQ_NONE;
  7680. /*
  7681. * Invoke fast-path host attention interrupt handling as appropriate.
  7682. */
  7683. /* status of events with FCP ring */
  7684. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7685. status1 >>= (4*LPFC_FCP_RING);
  7686. /* status of events with extra ring */
  7687. if (phba->cfg_multi_ring_support == 2) {
  7688. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7689. status2 >>= (4*LPFC_EXTRA_RING);
  7690. } else
  7691. status2 = 0;
  7692. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7693. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7694. else
  7695. fp_irq_rc = IRQ_NONE;
  7696. /* Return device-level interrupt handling status */
  7697. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7698. } /* lpfc_sli_intr_handler */
  7699. /**
  7700. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7701. * @phba: pointer to lpfc hba data structure.
  7702. *
  7703. * This routine is invoked by the worker thread to process all the pending
  7704. * SLI4 FCP abort XRI events.
  7705. **/
  7706. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7707. {
  7708. struct lpfc_cq_event *cq_event;
  7709. /* First, declare the fcp xri abort event has been handled */
  7710. spin_lock_irq(&phba->hbalock);
  7711. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7712. spin_unlock_irq(&phba->hbalock);
  7713. /* Now, handle all the fcp xri abort events */
  7714. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7715. /* Get the first event from the head of the event queue */
  7716. spin_lock_irq(&phba->hbalock);
  7717. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7718. cq_event, struct lpfc_cq_event, list);
  7719. spin_unlock_irq(&phba->hbalock);
  7720. /* Notify aborted XRI for FCP work queue */
  7721. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7722. /* Free the event processed back to the free pool */
  7723. lpfc_sli4_cq_event_release(phba, cq_event);
  7724. }
  7725. }
  7726. /**
  7727. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7728. * @phba: pointer to lpfc hba data structure.
  7729. *
  7730. * This routine is invoked by the worker thread to process all the pending
  7731. * SLI4 els abort xri events.
  7732. **/
  7733. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7734. {
  7735. struct lpfc_cq_event *cq_event;
  7736. /* First, declare the els xri abort event has been handled */
  7737. spin_lock_irq(&phba->hbalock);
  7738. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7739. spin_unlock_irq(&phba->hbalock);
  7740. /* Now, handle all the els xri abort events */
  7741. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7742. /* Get the first event from the head of the event queue */
  7743. spin_lock_irq(&phba->hbalock);
  7744. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7745. cq_event, struct lpfc_cq_event, list);
  7746. spin_unlock_irq(&phba->hbalock);
  7747. /* Notify aborted XRI for ELS work queue */
  7748. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7749. /* Free the event processed back to the free pool */
  7750. lpfc_sli4_cq_event_release(phba, cq_event);
  7751. }
  7752. }
  7753. /**
  7754. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7755. * @phba: pointer to lpfc hba data structure
  7756. * @pIocbIn: pointer to the rspiocbq
  7757. * @pIocbOut: pointer to the cmdiocbq
  7758. * @wcqe: pointer to the complete wcqe
  7759. *
  7760. * This routine transfers the fields of a command iocbq to a response iocbq
  7761. * by copying all the IOCB fields from command iocbq and transferring the
  7762. * completion status information from the complete wcqe.
  7763. **/
  7764. static void
  7765. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7766. struct lpfc_iocbq *pIocbIn,
  7767. struct lpfc_iocbq *pIocbOut,
  7768. struct lpfc_wcqe_complete *wcqe)
  7769. {
  7770. unsigned long iflags;
  7771. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7772. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7773. sizeof(struct lpfc_iocbq) - offset);
  7774. /* Map WCQE parameters into irspiocb parameters */
  7775. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7776. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7777. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7778. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7779. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7780. wcqe->total_data_placed;
  7781. else
  7782. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7783. else {
  7784. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7785. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7786. }
  7787. /* Pick up HBA exchange busy condition */
  7788. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7789. spin_lock_irqsave(&phba->hbalock, iflags);
  7790. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7791. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7792. }
  7793. }
  7794. /**
  7795. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7796. * @phba: Pointer to HBA context object.
  7797. * @wcqe: Pointer to work-queue completion queue entry.
  7798. *
  7799. * This routine handles an ELS work-queue completion event and construct
  7800. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7801. * discovery engine to handle.
  7802. *
  7803. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7804. **/
  7805. static struct lpfc_iocbq *
  7806. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7807. struct lpfc_iocbq *irspiocbq)
  7808. {
  7809. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7810. struct lpfc_iocbq *cmdiocbq;
  7811. struct lpfc_wcqe_complete *wcqe;
  7812. unsigned long iflags;
  7813. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7814. spin_lock_irqsave(&phba->hbalock, iflags);
  7815. pring->stats.iocb_event++;
  7816. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7817. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7818. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7819. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7820. if (unlikely(!cmdiocbq)) {
  7821. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7822. "0386 ELS complete with no corresponding "
  7823. "cmdiocb: iotag (%d)\n",
  7824. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7825. lpfc_sli_release_iocbq(phba, irspiocbq);
  7826. return NULL;
  7827. }
  7828. /* Fake the irspiocbq and copy necessary response information */
  7829. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  7830. return irspiocbq;
  7831. }
  7832. /**
  7833. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7834. * @phba: Pointer to HBA context object.
  7835. * @cqe: Pointer to mailbox completion queue entry.
  7836. *
  7837. * This routine process a mailbox completion queue entry with asynchrous
  7838. * event.
  7839. *
  7840. * Return: true if work posted to worker thread, otherwise false.
  7841. **/
  7842. static bool
  7843. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7844. {
  7845. struct lpfc_cq_event *cq_event;
  7846. unsigned long iflags;
  7847. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7848. "0392 Async Event: word0:x%x, word1:x%x, "
  7849. "word2:x%x, word3:x%x\n", mcqe->word0,
  7850. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7851. /* Allocate a new internal CQ_EVENT entry */
  7852. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7853. if (!cq_event) {
  7854. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7855. "0394 Failed to allocate CQ_EVENT entry\n");
  7856. return false;
  7857. }
  7858. /* Move the CQE into an asynchronous event entry */
  7859. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7860. spin_lock_irqsave(&phba->hbalock, iflags);
  7861. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7862. /* Set the async event flag */
  7863. phba->hba_flag |= ASYNC_EVENT;
  7864. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7865. return true;
  7866. }
  7867. /**
  7868. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7869. * @phba: Pointer to HBA context object.
  7870. * @cqe: Pointer to mailbox completion queue entry.
  7871. *
  7872. * This routine process a mailbox completion queue entry with mailbox
  7873. * completion event.
  7874. *
  7875. * Return: true if work posted to worker thread, otherwise false.
  7876. **/
  7877. static bool
  7878. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7879. {
  7880. uint32_t mcqe_status;
  7881. MAILBOX_t *mbox, *pmbox;
  7882. struct lpfc_mqe *mqe;
  7883. struct lpfc_vport *vport;
  7884. struct lpfc_nodelist *ndlp;
  7885. struct lpfc_dmabuf *mp;
  7886. unsigned long iflags;
  7887. LPFC_MBOXQ_t *pmb;
  7888. bool workposted = false;
  7889. int rc;
  7890. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7891. if (!bf_get(lpfc_trailer_completed, mcqe))
  7892. goto out_no_mqe_complete;
  7893. /* Get the reference to the active mbox command */
  7894. spin_lock_irqsave(&phba->hbalock, iflags);
  7895. pmb = phba->sli.mbox_active;
  7896. if (unlikely(!pmb)) {
  7897. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7898. "1832 No pending MBOX command to handle\n");
  7899. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7900. goto out_no_mqe_complete;
  7901. }
  7902. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7903. mqe = &pmb->u.mqe;
  7904. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7905. mbox = phba->mbox;
  7906. vport = pmb->vport;
  7907. /* Reset heartbeat timer */
  7908. phba->last_completion_time = jiffies;
  7909. del_timer(&phba->sli.mbox_tmo);
  7910. /* Move mbox data to caller's mailbox region, do endian swapping */
  7911. if (pmb->mbox_cmpl && mbox)
  7912. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7913. /* Set the mailbox status with SLI4 range 0x4000 */
  7914. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7915. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7916. bf_set(lpfc_mqe_status, mqe,
  7917. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7918. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7919. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7920. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7921. "MBOX dflt rpi: status:x%x rpi:x%x",
  7922. mcqe_status,
  7923. pmbox->un.varWords[0], 0);
  7924. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7925. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7926. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7927. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7928. * RID of the PPI using the same mbox buffer.
  7929. */
  7930. lpfc_unreg_login(phba, vport->vpi,
  7931. pmbox->un.varWords[0], pmb);
  7932. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7933. pmb->context1 = mp;
  7934. pmb->context2 = ndlp;
  7935. pmb->vport = vport;
  7936. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7937. if (rc != MBX_BUSY)
  7938. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7939. LOG_SLI, "0385 rc should "
  7940. "have been MBX_BUSY\n");
  7941. if (rc != MBX_NOT_FINISHED)
  7942. goto send_current_mbox;
  7943. }
  7944. }
  7945. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7946. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7947. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7948. /* There is mailbox completion work to do */
  7949. spin_lock_irqsave(&phba->hbalock, iflags);
  7950. __lpfc_mbox_cmpl_put(phba, pmb);
  7951. phba->work_ha |= HA_MBATT;
  7952. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7953. workposted = true;
  7954. send_current_mbox:
  7955. spin_lock_irqsave(&phba->hbalock, iflags);
  7956. /* Release the mailbox command posting token */
  7957. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7958. /* Setting active mailbox pointer need to be in sync to flag clear */
  7959. phba->sli.mbox_active = NULL;
  7960. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7961. /* Wake up worker thread to post the next pending mailbox command */
  7962. lpfc_worker_wake_up(phba);
  7963. out_no_mqe_complete:
  7964. if (bf_get(lpfc_trailer_consumed, mcqe))
  7965. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7966. return workposted;
  7967. }
  7968. /**
  7969. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7970. * @phba: Pointer to HBA context object.
  7971. * @cqe: Pointer to mailbox completion queue entry.
  7972. *
  7973. * This routine process a mailbox completion queue entry, it invokes the
  7974. * proper mailbox complete handling or asynchrous event handling routine
  7975. * according to the MCQE's async bit.
  7976. *
  7977. * Return: true if work posted to worker thread, otherwise false.
  7978. **/
  7979. static bool
  7980. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7981. {
  7982. struct lpfc_mcqe mcqe;
  7983. bool workposted;
  7984. /* Copy the mailbox MCQE and convert endian order as needed */
  7985. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7986. /* Invoke the proper event handling routine */
  7987. if (!bf_get(lpfc_trailer_async, &mcqe))
  7988. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7989. else
  7990. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7991. return workposted;
  7992. }
  7993. /**
  7994. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7995. * @phba: Pointer to HBA context object.
  7996. * @wcqe: Pointer to work-queue completion queue entry.
  7997. *
  7998. * This routine handles an ELS work-queue completion event.
  7999. *
  8000. * Return: true if work posted to worker thread, otherwise false.
  8001. **/
  8002. static bool
  8003. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8004. struct lpfc_wcqe_complete *wcqe)
  8005. {
  8006. struct lpfc_iocbq *irspiocbq;
  8007. unsigned long iflags;
  8008. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8009. /* Get an irspiocbq for later ELS response processing use */
  8010. irspiocbq = lpfc_sli_get_iocbq(phba);
  8011. if (!irspiocbq) {
  8012. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8013. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8014. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8015. pring->txq_cnt, phba->iocb_cnt,
  8016. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8017. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8018. return false;
  8019. }
  8020. /* Save off the slow-path queue event for work thread to process */
  8021. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8022. spin_lock_irqsave(&phba->hbalock, iflags);
  8023. list_add_tail(&irspiocbq->cq_event.list,
  8024. &phba->sli4_hba.sp_queue_event);
  8025. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8026. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8027. return true;
  8028. }
  8029. /**
  8030. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8031. * @phba: Pointer to HBA context object.
  8032. * @wcqe: Pointer to work-queue completion queue entry.
  8033. *
  8034. * This routine handles slow-path WQ entry comsumed event by invoking the
  8035. * proper WQ release routine to the slow-path WQ.
  8036. **/
  8037. static void
  8038. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8039. struct lpfc_wcqe_release *wcqe)
  8040. {
  8041. /* Check for the slow-path ELS work queue */
  8042. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8043. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8044. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8045. else
  8046. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8047. "2579 Slow-path wqe consume event carries "
  8048. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8049. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8050. phba->sli4_hba.els_wq->queue_id);
  8051. }
  8052. /**
  8053. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8054. * @phba: Pointer to HBA context object.
  8055. * @cq: Pointer to a WQ completion queue.
  8056. * @wcqe: Pointer to work-queue completion queue entry.
  8057. *
  8058. * This routine handles an XRI abort event.
  8059. *
  8060. * Return: true if work posted to worker thread, otherwise false.
  8061. **/
  8062. static bool
  8063. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8064. struct lpfc_queue *cq,
  8065. struct sli4_wcqe_xri_aborted *wcqe)
  8066. {
  8067. bool workposted = false;
  8068. struct lpfc_cq_event *cq_event;
  8069. unsigned long iflags;
  8070. /* Allocate a new internal CQ_EVENT entry */
  8071. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8072. if (!cq_event) {
  8073. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8074. "0602 Failed to allocate CQ_EVENT entry\n");
  8075. return false;
  8076. }
  8077. /* Move the CQE into the proper xri abort event list */
  8078. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8079. switch (cq->subtype) {
  8080. case LPFC_FCP:
  8081. spin_lock_irqsave(&phba->hbalock, iflags);
  8082. list_add_tail(&cq_event->list,
  8083. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8084. /* Set the fcp xri abort event flag */
  8085. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8086. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8087. workposted = true;
  8088. break;
  8089. case LPFC_ELS:
  8090. spin_lock_irqsave(&phba->hbalock, iflags);
  8091. list_add_tail(&cq_event->list,
  8092. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8093. /* Set the els xri abort event flag */
  8094. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8095. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8096. workposted = true;
  8097. break;
  8098. default:
  8099. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8100. "0603 Invalid work queue CQE subtype (x%x)\n",
  8101. cq->subtype);
  8102. workposted = false;
  8103. break;
  8104. }
  8105. return workposted;
  8106. }
  8107. /**
  8108. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8109. * @phba: Pointer to HBA context object.
  8110. * @rcqe: Pointer to receive-queue completion queue entry.
  8111. *
  8112. * This routine process a receive-queue completion queue entry.
  8113. *
  8114. * Return: true if work posted to worker thread, otherwise false.
  8115. **/
  8116. static bool
  8117. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8118. {
  8119. bool workposted = false;
  8120. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8121. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8122. struct hbq_dmabuf *dma_buf;
  8123. uint32_t status;
  8124. unsigned long iflags;
  8125. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8126. goto out;
  8127. status = bf_get(lpfc_rcqe_status, rcqe);
  8128. switch (status) {
  8129. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8130. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8131. "2537 Receive Frame Truncated!!\n");
  8132. case FC_STATUS_RQ_SUCCESS:
  8133. lpfc_sli4_rq_release(hrq, drq);
  8134. spin_lock_irqsave(&phba->hbalock, iflags);
  8135. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8136. if (!dma_buf) {
  8137. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8138. goto out;
  8139. }
  8140. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8141. /* save off the frame for the word thread to process */
  8142. list_add_tail(&dma_buf->cq_event.list,
  8143. &phba->sli4_hba.sp_queue_event);
  8144. /* Frame received */
  8145. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8146. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8147. workposted = true;
  8148. break;
  8149. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8150. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8151. /* Post more buffers if possible */
  8152. spin_lock_irqsave(&phba->hbalock, iflags);
  8153. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8154. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8155. workposted = true;
  8156. break;
  8157. }
  8158. out:
  8159. return workposted;
  8160. }
  8161. /**
  8162. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8163. * @phba: Pointer to HBA context object.
  8164. * @cq: Pointer to the completion queue.
  8165. * @wcqe: Pointer to a completion queue entry.
  8166. *
  8167. * This routine process a slow-path work-queue or recieve queue completion queue
  8168. * entry.
  8169. *
  8170. * Return: true if work posted to worker thread, otherwise false.
  8171. **/
  8172. static bool
  8173. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8174. struct lpfc_cqe *cqe)
  8175. {
  8176. struct lpfc_cqe cqevt;
  8177. bool workposted = false;
  8178. /* Copy the work queue CQE and convert endian order if needed */
  8179. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8180. /* Check and process for different type of WCQE and dispatch */
  8181. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8182. case CQE_CODE_COMPL_WQE:
  8183. /* Process the WQ/RQ complete event */
  8184. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8185. (struct lpfc_wcqe_complete *)&cqevt);
  8186. break;
  8187. case CQE_CODE_RELEASE_WQE:
  8188. /* Process the WQ release event */
  8189. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8190. (struct lpfc_wcqe_release *)&cqevt);
  8191. break;
  8192. case CQE_CODE_XRI_ABORTED:
  8193. /* Process the WQ XRI abort event */
  8194. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8195. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8196. break;
  8197. case CQE_CODE_RECEIVE:
  8198. /* Process the RQ event */
  8199. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8200. (struct lpfc_rcqe *)&cqevt);
  8201. break;
  8202. default:
  8203. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8204. "0388 Not a valid WCQE code: x%x\n",
  8205. bf_get(lpfc_cqe_code, &cqevt));
  8206. break;
  8207. }
  8208. return workposted;
  8209. }
  8210. /**
  8211. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8212. * @phba: Pointer to HBA context object.
  8213. * @eqe: Pointer to fast-path event queue entry.
  8214. *
  8215. * This routine process a event queue entry from the slow-path event queue.
  8216. * It will check the MajorCode and MinorCode to determine this is for a
  8217. * completion event on a completion queue, if not, an error shall be logged
  8218. * and just return. Otherwise, it will get to the corresponding completion
  8219. * queue and process all the entries on that completion queue, rearm the
  8220. * completion queue, and then return.
  8221. *
  8222. **/
  8223. static void
  8224. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8225. {
  8226. struct lpfc_queue *cq = NULL, *childq, *speq;
  8227. struct lpfc_cqe *cqe;
  8228. bool workposted = false;
  8229. int ecount = 0;
  8230. uint16_t cqid;
  8231. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8232. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8233. "0359 Not a valid slow-path completion "
  8234. "event: majorcode=x%x, minorcode=x%x\n",
  8235. bf_get_le32(lpfc_eqe_major_code, eqe),
  8236. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8237. return;
  8238. }
  8239. /* Get the reference to the corresponding CQ */
  8240. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8241. /* Search for completion queue pointer matching this cqid */
  8242. speq = phba->sli4_hba.sp_eq;
  8243. list_for_each_entry(childq, &speq->child_list, list) {
  8244. if (childq->queue_id == cqid) {
  8245. cq = childq;
  8246. break;
  8247. }
  8248. }
  8249. if (unlikely(!cq)) {
  8250. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8251. "0365 Slow-path CQ identifier (%d) does "
  8252. "not exist\n", cqid);
  8253. return;
  8254. }
  8255. /* Process all the entries to the CQ */
  8256. switch (cq->type) {
  8257. case LPFC_MCQ:
  8258. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8259. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8260. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8261. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8262. }
  8263. break;
  8264. case LPFC_WCQ:
  8265. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8266. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8267. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8268. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8269. }
  8270. break;
  8271. default:
  8272. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8273. "0370 Invalid completion queue type (%d)\n",
  8274. cq->type);
  8275. return;
  8276. }
  8277. /* Catch the no cq entry condition, log an error */
  8278. if (unlikely(ecount == 0))
  8279. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8280. "0371 No entry from the CQ: identifier "
  8281. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8282. /* In any case, flash and re-arm the RCQ */
  8283. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8284. /* wake up worker thread if there are works to be done */
  8285. if (workposted)
  8286. lpfc_worker_wake_up(phba);
  8287. }
  8288. /**
  8289. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8290. * @eqe: Pointer to fast-path completion queue entry.
  8291. *
  8292. * This routine process a fast-path work queue completion entry from fast-path
  8293. * event queue for FCP command response completion.
  8294. **/
  8295. static void
  8296. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8297. struct lpfc_wcqe_complete *wcqe)
  8298. {
  8299. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8300. struct lpfc_iocbq *cmdiocbq;
  8301. struct lpfc_iocbq irspiocbq;
  8302. unsigned long iflags;
  8303. spin_lock_irqsave(&phba->hbalock, iflags);
  8304. pring->stats.iocb_event++;
  8305. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8306. /* Check for response status */
  8307. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8308. /* If resource errors reported from HBA, reduce queue
  8309. * depth of the SCSI device.
  8310. */
  8311. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8312. IOSTAT_LOCAL_REJECT) &&
  8313. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8314. phba->lpfc_rampdown_queue_depth(phba);
  8315. }
  8316. /* Log the error status */
  8317. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8318. "0373 FCP complete error: status=x%x, "
  8319. "hw_status=x%x, total_data_specified=%d, "
  8320. "parameter=x%x, word3=x%x\n",
  8321. bf_get(lpfc_wcqe_c_status, wcqe),
  8322. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8323. wcqe->total_data_placed, wcqe->parameter,
  8324. wcqe->word3);
  8325. }
  8326. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8327. spin_lock_irqsave(&phba->hbalock, iflags);
  8328. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8329. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8330. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8331. if (unlikely(!cmdiocbq)) {
  8332. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8333. "0374 FCP complete with no corresponding "
  8334. "cmdiocb: iotag (%d)\n",
  8335. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8336. return;
  8337. }
  8338. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8339. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8340. "0375 FCP cmdiocb not callback function "
  8341. "iotag: (%d)\n",
  8342. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8343. return;
  8344. }
  8345. /* Fake the irspiocb and copy necessary response information */
  8346. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8347. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8348. spin_lock_irqsave(&phba->hbalock, iflags);
  8349. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8350. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8351. }
  8352. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8353. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8354. }
  8355. /**
  8356. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8357. * @phba: Pointer to HBA context object.
  8358. * @cq: Pointer to completion queue.
  8359. * @wcqe: Pointer to work-queue completion queue entry.
  8360. *
  8361. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8362. * proper WQ release routine to the slow-path WQ.
  8363. **/
  8364. static void
  8365. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8366. struct lpfc_wcqe_release *wcqe)
  8367. {
  8368. struct lpfc_queue *childwq;
  8369. bool wqid_matched = false;
  8370. uint16_t fcp_wqid;
  8371. /* Check for fast-path FCP work queue release */
  8372. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8373. list_for_each_entry(childwq, &cq->child_list, list) {
  8374. if (childwq->queue_id == fcp_wqid) {
  8375. lpfc_sli4_wq_release(childwq,
  8376. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8377. wqid_matched = true;
  8378. break;
  8379. }
  8380. }
  8381. /* Report warning log message if no match found */
  8382. if (wqid_matched != true)
  8383. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8384. "2580 Fast-path wqe consume event carries "
  8385. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8386. }
  8387. /**
  8388. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8389. * @cq: Pointer to the completion queue.
  8390. * @eqe: Pointer to fast-path completion queue entry.
  8391. *
  8392. * This routine process a fast-path work queue completion entry from fast-path
  8393. * event queue for FCP command response completion.
  8394. **/
  8395. static int
  8396. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8397. struct lpfc_cqe *cqe)
  8398. {
  8399. struct lpfc_wcqe_release wcqe;
  8400. bool workposted = false;
  8401. unsigned long iflag;
  8402. /* Copy the work queue CQE and convert endian order if needed */
  8403. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8404. /* Check and process for different type of WCQE and dispatch */
  8405. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8406. case CQE_CODE_COMPL_WQE:
  8407. /* Process the WQ complete event */
  8408. spin_lock_irqsave(&phba->hbalock, iflag);
  8409. phba->last_completion_time = jiffies;
  8410. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8411. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8412. (struct lpfc_wcqe_complete *)&wcqe);
  8413. break;
  8414. case CQE_CODE_RELEASE_WQE:
  8415. /* Process the WQ release event */
  8416. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8417. (struct lpfc_wcqe_release *)&wcqe);
  8418. break;
  8419. case CQE_CODE_XRI_ABORTED:
  8420. /* Process the WQ XRI abort event */
  8421. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8422. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8423. break;
  8424. default:
  8425. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8426. "0144 Not a valid WCQE code: x%x\n",
  8427. bf_get(lpfc_wcqe_c_code, &wcqe));
  8428. break;
  8429. }
  8430. return workposted;
  8431. }
  8432. /**
  8433. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8434. * @phba: Pointer to HBA context object.
  8435. * @eqe: Pointer to fast-path event queue entry.
  8436. *
  8437. * This routine process a event queue entry from the fast-path event queue.
  8438. * It will check the MajorCode and MinorCode to determine this is for a
  8439. * completion event on a completion queue, if not, an error shall be logged
  8440. * and just return. Otherwise, it will get to the corresponding completion
  8441. * queue and process all the entries on the completion queue, rearm the
  8442. * completion queue, and then return.
  8443. **/
  8444. static void
  8445. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8446. uint32_t fcp_cqidx)
  8447. {
  8448. struct lpfc_queue *cq;
  8449. struct lpfc_cqe *cqe;
  8450. bool workposted = false;
  8451. uint16_t cqid;
  8452. int ecount = 0;
  8453. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  8454. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8455. "0366 Not a valid fast-path completion "
  8456. "event: majorcode=x%x, minorcode=x%x\n",
  8457. bf_get_le32(lpfc_eqe_major_code, eqe),
  8458. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8459. return;
  8460. }
  8461. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8462. if (unlikely(!cq)) {
  8463. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8464. "0367 Fast-path completion queue does not "
  8465. "exist\n");
  8466. return;
  8467. }
  8468. /* Get the reference to the corresponding CQ */
  8469. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8470. if (unlikely(cqid != cq->queue_id)) {
  8471. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8472. "0368 Miss-matched fast-path completion "
  8473. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8474. cqid, cq->queue_id);
  8475. return;
  8476. }
  8477. /* Process all the entries to the CQ */
  8478. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8479. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8480. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8481. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8482. }
  8483. /* Catch the no cq entry condition */
  8484. if (unlikely(ecount == 0))
  8485. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8486. "0369 No entry from fast-path completion "
  8487. "queue fcpcqid=%d\n", cq->queue_id);
  8488. /* In any case, flash and re-arm the CQ */
  8489. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8490. /* wake up worker thread if there are works to be done */
  8491. if (workposted)
  8492. lpfc_worker_wake_up(phba);
  8493. }
  8494. static void
  8495. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8496. {
  8497. struct lpfc_eqe *eqe;
  8498. /* walk all the EQ entries and drop on the floor */
  8499. while ((eqe = lpfc_sli4_eq_get(eq)))
  8500. ;
  8501. /* Clear and re-arm the EQ */
  8502. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8503. }
  8504. /**
  8505. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8506. * @irq: Interrupt number.
  8507. * @dev_id: The device context pointer.
  8508. *
  8509. * This function is directly called from the PCI layer as an interrupt
  8510. * service routine when device with SLI-4 interface spec is enabled with
  8511. * MSI-X multi-message interrupt mode and there are slow-path events in
  8512. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8513. * interrupt mode, this function is called as part of the device-level
  8514. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8515. * undergoing initialization, the interrupt handler will not process the
  8516. * interrupt. The link attention and ELS ring attention events are handled
  8517. * by the worker thread. The interrupt handler signals the worker thread
  8518. * and returns for these events. This function is called without any lock
  8519. * held. It gets the hbalock to access and update SLI data structures.
  8520. *
  8521. * This function returns IRQ_HANDLED when interrupt is handled else it
  8522. * returns IRQ_NONE.
  8523. **/
  8524. irqreturn_t
  8525. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8526. {
  8527. struct lpfc_hba *phba;
  8528. struct lpfc_queue *speq;
  8529. struct lpfc_eqe *eqe;
  8530. unsigned long iflag;
  8531. int ecount = 0;
  8532. /*
  8533. * Get the driver's phba structure from the dev_id
  8534. */
  8535. phba = (struct lpfc_hba *)dev_id;
  8536. if (unlikely(!phba))
  8537. return IRQ_NONE;
  8538. /* Get to the EQ struct associated with this vector */
  8539. speq = phba->sli4_hba.sp_eq;
  8540. /* Check device state for handling interrupt */
  8541. if (unlikely(lpfc_intr_state_check(phba))) {
  8542. /* Check again for link_state with lock held */
  8543. spin_lock_irqsave(&phba->hbalock, iflag);
  8544. if (phba->link_state < LPFC_LINK_DOWN)
  8545. /* Flush, clear interrupt, and rearm the EQ */
  8546. lpfc_sli4_eq_flush(phba, speq);
  8547. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8548. return IRQ_NONE;
  8549. }
  8550. /*
  8551. * Process all the event on FCP slow-path EQ
  8552. */
  8553. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8554. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8555. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8556. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8557. }
  8558. /* Always clear and re-arm the slow-path EQ */
  8559. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8560. /* Catch the no cq entry condition */
  8561. if (unlikely(ecount == 0)) {
  8562. if (phba->intr_type == MSIX)
  8563. /* MSI-X treated interrupt served as no EQ share INT */
  8564. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8565. "0357 MSI-X interrupt with no EQE\n");
  8566. else
  8567. /* Non MSI-X treated on interrupt as EQ share INT */
  8568. return IRQ_NONE;
  8569. }
  8570. return IRQ_HANDLED;
  8571. } /* lpfc_sli4_sp_intr_handler */
  8572. /**
  8573. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8574. * @irq: Interrupt number.
  8575. * @dev_id: The device context pointer.
  8576. *
  8577. * This function is directly called from the PCI layer as an interrupt
  8578. * service routine when device with SLI-4 interface spec is enabled with
  8579. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8580. * ring event in the HBA. However, when the device is enabled with either
  8581. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8582. * device-level interrupt handler. When the PCI slot is in error recovery
  8583. * or the HBA is undergoing initialization, the interrupt handler will not
  8584. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8585. * the intrrupt context. This function is called without any lock held.
  8586. * It gets the hbalock to access and update SLI data structures. Note that,
  8587. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8588. * equal to that of FCP CQ index.
  8589. *
  8590. * This function returns IRQ_HANDLED when interrupt is handled else it
  8591. * returns IRQ_NONE.
  8592. **/
  8593. irqreturn_t
  8594. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8595. {
  8596. struct lpfc_hba *phba;
  8597. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8598. struct lpfc_queue *fpeq;
  8599. struct lpfc_eqe *eqe;
  8600. unsigned long iflag;
  8601. int ecount = 0;
  8602. uint32_t fcp_eqidx;
  8603. /* Get the driver's phba structure from the dev_id */
  8604. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8605. phba = fcp_eq_hdl->phba;
  8606. fcp_eqidx = fcp_eq_hdl->idx;
  8607. if (unlikely(!phba))
  8608. return IRQ_NONE;
  8609. /* Get to the EQ struct associated with this vector */
  8610. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8611. /* Check device state for handling interrupt */
  8612. if (unlikely(lpfc_intr_state_check(phba))) {
  8613. /* Check again for link_state with lock held */
  8614. spin_lock_irqsave(&phba->hbalock, iflag);
  8615. if (phba->link_state < LPFC_LINK_DOWN)
  8616. /* Flush, clear interrupt, and rearm the EQ */
  8617. lpfc_sli4_eq_flush(phba, fpeq);
  8618. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8619. return IRQ_NONE;
  8620. }
  8621. /*
  8622. * Process all the event on FCP fast-path EQ
  8623. */
  8624. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8625. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8626. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8627. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8628. }
  8629. /* Always clear and re-arm the fast-path EQ */
  8630. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8631. if (unlikely(ecount == 0)) {
  8632. if (phba->intr_type == MSIX)
  8633. /* MSI-X treated interrupt served as no EQ share INT */
  8634. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8635. "0358 MSI-X interrupt with no EQE\n");
  8636. else
  8637. /* Non MSI-X treated on interrupt as EQ share INT */
  8638. return IRQ_NONE;
  8639. }
  8640. return IRQ_HANDLED;
  8641. } /* lpfc_sli4_fp_intr_handler */
  8642. /**
  8643. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8644. * @irq: Interrupt number.
  8645. * @dev_id: The device context pointer.
  8646. *
  8647. * This function is the device-level interrupt handler to device with SLI-4
  8648. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8649. * interrupt mode is enabled and there is an event in the HBA which requires
  8650. * driver attention. This function invokes the slow-path interrupt attention
  8651. * handling function and fast-path interrupt attention handling function in
  8652. * turn to process the relevant HBA attention events. This function is called
  8653. * without any lock held. It gets the hbalock to access and update SLI data
  8654. * structures.
  8655. *
  8656. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8657. * returns IRQ_NONE.
  8658. **/
  8659. irqreturn_t
  8660. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8661. {
  8662. struct lpfc_hba *phba;
  8663. irqreturn_t sp_irq_rc, fp_irq_rc;
  8664. bool fp_handled = false;
  8665. uint32_t fcp_eqidx;
  8666. /* Get the driver's phba structure from the dev_id */
  8667. phba = (struct lpfc_hba *)dev_id;
  8668. if (unlikely(!phba))
  8669. return IRQ_NONE;
  8670. /*
  8671. * Invokes slow-path host attention interrupt handling as appropriate.
  8672. */
  8673. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8674. /*
  8675. * Invoke fast-path host attention interrupt handling as appropriate.
  8676. */
  8677. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8678. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8679. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8680. if (fp_irq_rc == IRQ_HANDLED)
  8681. fp_handled |= true;
  8682. }
  8683. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8684. } /* lpfc_sli4_intr_handler */
  8685. /**
  8686. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8687. * @queue: The queue structure to free.
  8688. *
  8689. * This function frees a queue structure and the DMAable memeory used for
  8690. * the host resident queue. This function must be called after destroying the
  8691. * queue on the HBA.
  8692. **/
  8693. void
  8694. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8695. {
  8696. struct lpfc_dmabuf *dmabuf;
  8697. if (!queue)
  8698. return;
  8699. while (!list_empty(&queue->page_list)) {
  8700. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8701. list);
  8702. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  8703. dmabuf->virt, dmabuf->phys);
  8704. kfree(dmabuf);
  8705. }
  8706. kfree(queue);
  8707. return;
  8708. }
  8709. /**
  8710. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8711. * @phba: The HBA that this queue is being created on.
  8712. * @entry_size: The size of each queue entry for this queue.
  8713. * @entry count: The number of entries that this queue will handle.
  8714. *
  8715. * This function allocates a queue structure and the DMAable memory used for
  8716. * the host resident queue. This function must be called before creating the
  8717. * queue on the HBA.
  8718. **/
  8719. struct lpfc_queue *
  8720. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8721. uint32_t entry_count)
  8722. {
  8723. struct lpfc_queue *queue;
  8724. struct lpfc_dmabuf *dmabuf;
  8725. int x, total_qe_count;
  8726. void *dma_pointer;
  8727. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8728. if (!phba->sli4_hba.pc_sli4_params.supported)
  8729. hw_page_size = SLI4_PAGE_SIZE;
  8730. queue = kzalloc(sizeof(struct lpfc_queue) +
  8731. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8732. if (!queue)
  8733. return NULL;
  8734. queue->page_count = (ALIGN(entry_size * entry_count,
  8735. hw_page_size))/hw_page_size;
  8736. INIT_LIST_HEAD(&queue->list);
  8737. INIT_LIST_HEAD(&queue->page_list);
  8738. INIT_LIST_HEAD(&queue->child_list);
  8739. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8740. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8741. if (!dmabuf)
  8742. goto out_fail;
  8743. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8744. hw_page_size, &dmabuf->phys,
  8745. GFP_KERNEL);
  8746. if (!dmabuf->virt) {
  8747. kfree(dmabuf);
  8748. goto out_fail;
  8749. }
  8750. memset(dmabuf->virt, 0, hw_page_size);
  8751. dmabuf->buffer_tag = x;
  8752. list_add_tail(&dmabuf->list, &queue->page_list);
  8753. /* initialize queue's entry array */
  8754. dma_pointer = dmabuf->virt;
  8755. for (; total_qe_count < entry_count &&
  8756. dma_pointer < (hw_page_size + dmabuf->virt);
  8757. total_qe_count++, dma_pointer += entry_size) {
  8758. queue->qe[total_qe_count].address = dma_pointer;
  8759. }
  8760. }
  8761. queue->entry_size = entry_size;
  8762. queue->entry_count = entry_count;
  8763. queue->phba = phba;
  8764. return queue;
  8765. out_fail:
  8766. lpfc_sli4_queue_free(queue);
  8767. return NULL;
  8768. }
  8769. /**
  8770. * lpfc_eq_create - Create an Event Queue on the HBA
  8771. * @phba: HBA structure that indicates port to create a queue on.
  8772. * @eq: The queue structure to use to create the event queue.
  8773. * @imax: The maximum interrupt per second limit.
  8774. *
  8775. * This function creates an event queue, as detailed in @eq, on a port,
  8776. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8777. *
  8778. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8779. * is used to get the entry count and entry size that are necessary to
  8780. * determine the number of pages to allocate and use for this queue. This
  8781. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8782. * event queue. This function is asynchronous and will wait for the mailbox
  8783. * command to finish before continuing.
  8784. *
  8785. * On success this function will return a zero. If unable to allocate enough
  8786. * memory this function will return ENOMEM. If the queue create mailbox command
  8787. * fails this function will return ENXIO.
  8788. **/
  8789. uint32_t
  8790. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8791. {
  8792. struct lpfc_mbx_eq_create *eq_create;
  8793. LPFC_MBOXQ_t *mbox;
  8794. int rc, length, status = 0;
  8795. struct lpfc_dmabuf *dmabuf;
  8796. uint32_t shdr_status, shdr_add_status;
  8797. union lpfc_sli4_cfg_shdr *shdr;
  8798. uint16_t dmult;
  8799. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8800. if (!phba->sli4_hba.pc_sli4_params.supported)
  8801. hw_page_size = SLI4_PAGE_SIZE;
  8802. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8803. if (!mbox)
  8804. return -ENOMEM;
  8805. length = (sizeof(struct lpfc_mbx_eq_create) -
  8806. sizeof(struct lpfc_sli4_cfg_mhdr));
  8807. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8808. LPFC_MBOX_OPCODE_EQ_CREATE,
  8809. length, LPFC_SLI4_MBX_EMBED);
  8810. eq_create = &mbox->u.mqe.un.eq_create;
  8811. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8812. eq->page_count);
  8813. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8814. LPFC_EQE_SIZE);
  8815. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8816. /* Calculate delay multiper from maximum interrupt per second */
  8817. dmult = LPFC_DMULT_CONST/imax - 1;
  8818. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8819. dmult);
  8820. switch (eq->entry_count) {
  8821. default:
  8822. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8823. "0360 Unsupported EQ count. (%d)\n",
  8824. eq->entry_count);
  8825. if (eq->entry_count < 256)
  8826. return -EINVAL;
  8827. /* otherwise default to smallest count (drop through) */
  8828. case 256:
  8829. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8830. LPFC_EQ_CNT_256);
  8831. break;
  8832. case 512:
  8833. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8834. LPFC_EQ_CNT_512);
  8835. break;
  8836. case 1024:
  8837. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8838. LPFC_EQ_CNT_1024);
  8839. break;
  8840. case 2048:
  8841. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8842. LPFC_EQ_CNT_2048);
  8843. break;
  8844. case 4096:
  8845. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8846. LPFC_EQ_CNT_4096);
  8847. break;
  8848. }
  8849. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8850. memset(dmabuf->virt, 0, hw_page_size);
  8851. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8852. putPaddrLow(dmabuf->phys);
  8853. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8854. putPaddrHigh(dmabuf->phys);
  8855. }
  8856. mbox->vport = phba->pport;
  8857. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8858. mbox->context1 = NULL;
  8859. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8860. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8861. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8862. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8863. if (shdr_status || shdr_add_status || rc) {
  8864. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8865. "2500 EQ_CREATE mailbox failed with "
  8866. "status x%x add_status x%x, mbx status x%x\n",
  8867. shdr_status, shdr_add_status, rc);
  8868. status = -ENXIO;
  8869. }
  8870. eq->type = LPFC_EQ;
  8871. eq->subtype = LPFC_NONE;
  8872. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8873. if (eq->queue_id == 0xFFFF)
  8874. status = -ENXIO;
  8875. eq->host_index = 0;
  8876. eq->hba_index = 0;
  8877. mempool_free(mbox, phba->mbox_mem_pool);
  8878. return status;
  8879. }
  8880. /**
  8881. * lpfc_cq_create - Create a Completion Queue on the HBA
  8882. * @phba: HBA structure that indicates port to create a queue on.
  8883. * @cq: The queue structure to use to create the completion queue.
  8884. * @eq: The event queue to bind this completion queue to.
  8885. *
  8886. * This function creates a completion queue, as detailed in @wq, on a port,
  8887. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8888. *
  8889. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8890. * is used to get the entry count and entry size that are necessary to
  8891. * determine the number of pages to allocate and use for this queue. The @eq
  8892. * is used to indicate which event queue to bind this completion queue to. This
  8893. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8894. * completion queue. This function is asynchronous and will wait for the mailbox
  8895. * command to finish before continuing.
  8896. *
  8897. * On success this function will return a zero. If unable to allocate enough
  8898. * memory this function will return ENOMEM. If the queue create mailbox command
  8899. * fails this function will return ENXIO.
  8900. **/
  8901. uint32_t
  8902. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8903. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8904. {
  8905. struct lpfc_mbx_cq_create *cq_create;
  8906. struct lpfc_dmabuf *dmabuf;
  8907. LPFC_MBOXQ_t *mbox;
  8908. int rc, length, status = 0;
  8909. uint32_t shdr_status, shdr_add_status;
  8910. union lpfc_sli4_cfg_shdr *shdr;
  8911. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8912. if (!phba->sli4_hba.pc_sli4_params.supported)
  8913. hw_page_size = SLI4_PAGE_SIZE;
  8914. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8915. if (!mbox)
  8916. return -ENOMEM;
  8917. length = (sizeof(struct lpfc_mbx_cq_create) -
  8918. sizeof(struct lpfc_sli4_cfg_mhdr));
  8919. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8920. LPFC_MBOX_OPCODE_CQ_CREATE,
  8921. length, LPFC_SLI4_MBX_EMBED);
  8922. cq_create = &mbox->u.mqe.un.cq_create;
  8923. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8924. cq->page_count);
  8925. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8926. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8927. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8928. switch (cq->entry_count) {
  8929. default:
  8930. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8931. "0361 Unsupported CQ count. (%d)\n",
  8932. cq->entry_count);
  8933. if (cq->entry_count < 256)
  8934. return -EINVAL;
  8935. /* otherwise default to smallest count (drop through) */
  8936. case 256:
  8937. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8938. LPFC_CQ_CNT_256);
  8939. break;
  8940. case 512:
  8941. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8942. LPFC_CQ_CNT_512);
  8943. break;
  8944. case 1024:
  8945. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8946. LPFC_CQ_CNT_1024);
  8947. break;
  8948. }
  8949. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8950. memset(dmabuf->virt, 0, hw_page_size);
  8951. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8952. putPaddrLow(dmabuf->phys);
  8953. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8954. putPaddrHigh(dmabuf->phys);
  8955. }
  8956. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8957. /* The IOCTL status is embedded in the mailbox subheader. */
  8958. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8959. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8960. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8961. if (shdr_status || shdr_add_status || rc) {
  8962. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8963. "2501 CQ_CREATE mailbox failed with "
  8964. "status x%x add_status x%x, mbx status x%x\n",
  8965. shdr_status, shdr_add_status, rc);
  8966. status = -ENXIO;
  8967. goto out;
  8968. }
  8969. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8970. if (cq->queue_id == 0xFFFF) {
  8971. status = -ENXIO;
  8972. goto out;
  8973. }
  8974. /* link the cq onto the parent eq child list */
  8975. list_add_tail(&cq->list, &eq->child_list);
  8976. /* Set up completion queue's type and subtype */
  8977. cq->type = type;
  8978. cq->subtype = subtype;
  8979. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8980. cq->host_index = 0;
  8981. cq->hba_index = 0;
  8982. out:
  8983. mempool_free(mbox, phba->mbox_mem_pool);
  8984. return status;
  8985. }
  8986. /**
  8987. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  8988. * @phba: HBA structure that indicates port to create a queue on.
  8989. * @mq: The queue structure to use to create the mailbox queue.
  8990. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  8991. * @cq: The completion queue to associate with this cq.
  8992. *
  8993. * This function provides failback (fb) functionality when the
  8994. * mq_create_ext fails on older FW generations. It's purpose is identical
  8995. * to mq_create_ext otherwise.
  8996. *
  8997. * This routine cannot fail as all attributes were previously accessed and
  8998. * initialized in mq_create_ext.
  8999. **/
  9000. static void
  9001. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9002. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9003. {
  9004. struct lpfc_mbx_mq_create *mq_create;
  9005. struct lpfc_dmabuf *dmabuf;
  9006. int length;
  9007. length = (sizeof(struct lpfc_mbx_mq_create) -
  9008. sizeof(struct lpfc_sli4_cfg_mhdr));
  9009. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9010. LPFC_MBOX_OPCODE_MQ_CREATE,
  9011. length, LPFC_SLI4_MBX_EMBED);
  9012. mq_create = &mbox->u.mqe.un.mq_create;
  9013. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9014. mq->page_count);
  9015. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9016. cq->queue_id);
  9017. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9018. switch (mq->entry_count) {
  9019. case 16:
  9020. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9021. LPFC_MQ_CNT_16);
  9022. break;
  9023. case 32:
  9024. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9025. LPFC_MQ_CNT_32);
  9026. break;
  9027. case 64:
  9028. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9029. LPFC_MQ_CNT_64);
  9030. break;
  9031. case 128:
  9032. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9033. LPFC_MQ_CNT_128);
  9034. break;
  9035. }
  9036. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9037. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9038. putPaddrLow(dmabuf->phys);
  9039. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9040. putPaddrHigh(dmabuf->phys);
  9041. }
  9042. }
  9043. /**
  9044. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9045. * @phba: HBA structure that indicates port to create a queue on.
  9046. * @mq: The queue structure to use to create the mailbox queue.
  9047. * @cq: The completion queue to associate with this cq.
  9048. * @subtype: The queue's subtype.
  9049. *
  9050. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9051. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9052. *
  9053. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9054. * is used to get the entry count and entry size that are necessary to
  9055. * determine the number of pages to allocate and use for this queue. This
  9056. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9057. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9058. * command to finish before continuing.
  9059. *
  9060. * On success this function will return a zero. If unable to allocate enough
  9061. * memory this function will return ENOMEM. If the queue create mailbox command
  9062. * fails this function will return ENXIO.
  9063. **/
  9064. int32_t
  9065. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9066. struct lpfc_queue *cq, uint32_t subtype)
  9067. {
  9068. struct lpfc_mbx_mq_create *mq_create;
  9069. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9070. struct lpfc_dmabuf *dmabuf;
  9071. LPFC_MBOXQ_t *mbox;
  9072. int rc, length, status = 0;
  9073. uint32_t shdr_status, shdr_add_status;
  9074. union lpfc_sli4_cfg_shdr *shdr;
  9075. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9076. if (!phba->sli4_hba.pc_sli4_params.supported)
  9077. hw_page_size = SLI4_PAGE_SIZE;
  9078. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9079. if (!mbox)
  9080. return -ENOMEM;
  9081. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9082. sizeof(struct lpfc_sli4_cfg_mhdr));
  9083. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9084. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9085. length, LPFC_SLI4_MBX_EMBED);
  9086. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9087. bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request,
  9088. mq->page_count);
  9089. bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request,
  9090. 1);
  9091. bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste,
  9092. &mq_create_ext->u.request, 1);
  9093. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9094. &mq_create_ext->u.request, 1);
  9095. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9096. cq->queue_id);
  9097. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9098. switch (mq->entry_count) {
  9099. default:
  9100. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9101. "0362 Unsupported MQ count. (%d)\n",
  9102. mq->entry_count);
  9103. if (mq->entry_count < 16)
  9104. return -EINVAL;
  9105. /* otherwise default to smallest count (drop through) */
  9106. case 16:
  9107. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9108. LPFC_MQ_CNT_16);
  9109. break;
  9110. case 32:
  9111. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9112. LPFC_MQ_CNT_32);
  9113. break;
  9114. case 64:
  9115. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9116. LPFC_MQ_CNT_64);
  9117. break;
  9118. case 128:
  9119. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9120. LPFC_MQ_CNT_128);
  9121. break;
  9122. }
  9123. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9124. memset(dmabuf->virt, 0, hw_page_size);
  9125. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9126. putPaddrLow(dmabuf->phys);
  9127. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9128. putPaddrHigh(dmabuf->phys);
  9129. }
  9130. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9131. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9132. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9133. &mq_create_ext->u.response);
  9134. if (rc != MBX_SUCCESS) {
  9135. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9136. "2795 MQ_CREATE_EXT failed with "
  9137. "status x%x. Failback to MQ_CREATE.\n",
  9138. rc);
  9139. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9140. mq_create = &mbox->u.mqe.un.mq_create;
  9141. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9142. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9143. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9144. &mq_create->u.response);
  9145. }
  9146. /* The IOCTL status is embedded in the mailbox subheader. */
  9147. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9148. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9149. if (shdr_status || shdr_add_status || rc) {
  9150. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9151. "2502 MQ_CREATE mailbox failed with "
  9152. "status x%x add_status x%x, mbx status x%x\n",
  9153. shdr_status, shdr_add_status, rc);
  9154. status = -ENXIO;
  9155. goto out;
  9156. }
  9157. if (mq->queue_id == 0xFFFF) {
  9158. status = -ENXIO;
  9159. goto out;
  9160. }
  9161. mq->type = LPFC_MQ;
  9162. mq->subtype = subtype;
  9163. mq->host_index = 0;
  9164. mq->hba_index = 0;
  9165. /* link the mq onto the parent cq child list */
  9166. list_add_tail(&mq->list, &cq->child_list);
  9167. out:
  9168. mempool_free(mbox, phba->mbox_mem_pool);
  9169. return status;
  9170. }
  9171. /**
  9172. * lpfc_wq_create - Create a Work Queue on the HBA
  9173. * @phba: HBA structure that indicates port to create a queue on.
  9174. * @wq: The queue structure to use to create the work queue.
  9175. * @cq: The completion queue to bind this work queue to.
  9176. * @subtype: The subtype of the work queue indicating its functionality.
  9177. *
  9178. * This function creates a work queue, as detailed in @wq, on a port, described
  9179. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9180. *
  9181. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9182. * is used to get the entry count and entry size that are necessary to
  9183. * determine the number of pages to allocate and use for this queue. The @cq
  9184. * is used to indicate which completion queue to bind this work queue to. This
  9185. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9186. * work queue. This function is asynchronous and will wait for the mailbox
  9187. * command to finish before continuing.
  9188. *
  9189. * On success this function will return a zero. If unable to allocate enough
  9190. * memory this function will return ENOMEM. If the queue create mailbox command
  9191. * fails this function will return ENXIO.
  9192. **/
  9193. uint32_t
  9194. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9195. struct lpfc_queue *cq, uint32_t subtype)
  9196. {
  9197. struct lpfc_mbx_wq_create *wq_create;
  9198. struct lpfc_dmabuf *dmabuf;
  9199. LPFC_MBOXQ_t *mbox;
  9200. int rc, length, status = 0;
  9201. uint32_t shdr_status, shdr_add_status;
  9202. union lpfc_sli4_cfg_shdr *shdr;
  9203. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9204. if (!phba->sli4_hba.pc_sli4_params.supported)
  9205. hw_page_size = SLI4_PAGE_SIZE;
  9206. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9207. if (!mbox)
  9208. return -ENOMEM;
  9209. length = (sizeof(struct lpfc_mbx_wq_create) -
  9210. sizeof(struct lpfc_sli4_cfg_mhdr));
  9211. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9212. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9213. length, LPFC_SLI4_MBX_EMBED);
  9214. wq_create = &mbox->u.mqe.un.wq_create;
  9215. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9216. wq->page_count);
  9217. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9218. cq->queue_id);
  9219. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9220. memset(dmabuf->virt, 0, hw_page_size);
  9221. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9222. putPaddrLow(dmabuf->phys);
  9223. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9224. putPaddrHigh(dmabuf->phys);
  9225. }
  9226. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9227. /* The IOCTL status is embedded in the mailbox subheader. */
  9228. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9229. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9230. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9231. if (shdr_status || shdr_add_status || rc) {
  9232. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9233. "2503 WQ_CREATE mailbox failed with "
  9234. "status x%x add_status x%x, mbx status x%x\n",
  9235. shdr_status, shdr_add_status, rc);
  9236. status = -ENXIO;
  9237. goto out;
  9238. }
  9239. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9240. if (wq->queue_id == 0xFFFF) {
  9241. status = -ENXIO;
  9242. goto out;
  9243. }
  9244. wq->type = LPFC_WQ;
  9245. wq->subtype = subtype;
  9246. wq->host_index = 0;
  9247. wq->hba_index = 0;
  9248. /* link the wq onto the parent cq child list */
  9249. list_add_tail(&wq->list, &cq->child_list);
  9250. out:
  9251. mempool_free(mbox, phba->mbox_mem_pool);
  9252. return status;
  9253. }
  9254. /**
  9255. * lpfc_rq_create - Create a Receive Queue on the HBA
  9256. * @phba: HBA structure that indicates port to create a queue on.
  9257. * @hrq: The queue structure to use to create the header receive queue.
  9258. * @drq: The queue structure to use to create the data receive queue.
  9259. * @cq: The completion queue to bind this work queue to.
  9260. *
  9261. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9262. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9263. * to the HBA.
  9264. *
  9265. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9266. * struct is used to get the entry count that is necessary to determine the
  9267. * number of pages to use for this queue. The @cq is used to indicate which
  9268. * completion queue to bind received buffers that are posted to these queues to.
  9269. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9270. * receive queue pair. This function is asynchronous and will wait for the
  9271. * mailbox command to finish before continuing.
  9272. *
  9273. * On success this function will return a zero. If unable to allocate enough
  9274. * memory this function will return ENOMEM. If the queue create mailbox command
  9275. * fails this function will return ENXIO.
  9276. **/
  9277. uint32_t
  9278. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9279. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9280. {
  9281. struct lpfc_mbx_rq_create *rq_create;
  9282. struct lpfc_dmabuf *dmabuf;
  9283. LPFC_MBOXQ_t *mbox;
  9284. int rc, length, status = 0;
  9285. uint32_t shdr_status, shdr_add_status;
  9286. union lpfc_sli4_cfg_shdr *shdr;
  9287. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9288. if (!phba->sli4_hba.pc_sli4_params.supported)
  9289. hw_page_size = SLI4_PAGE_SIZE;
  9290. if (hrq->entry_count != drq->entry_count)
  9291. return -EINVAL;
  9292. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9293. if (!mbox)
  9294. return -ENOMEM;
  9295. length = (sizeof(struct lpfc_mbx_rq_create) -
  9296. sizeof(struct lpfc_sli4_cfg_mhdr));
  9297. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9298. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9299. length, LPFC_SLI4_MBX_EMBED);
  9300. rq_create = &mbox->u.mqe.un.rq_create;
  9301. switch (hrq->entry_count) {
  9302. default:
  9303. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9304. "2535 Unsupported RQ count. (%d)\n",
  9305. hrq->entry_count);
  9306. if (hrq->entry_count < 512)
  9307. return -EINVAL;
  9308. /* otherwise default to smallest count (drop through) */
  9309. case 512:
  9310. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9311. LPFC_RQ_RING_SIZE_512);
  9312. break;
  9313. case 1024:
  9314. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9315. LPFC_RQ_RING_SIZE_1024);
  9316. break;
  9317. case 2048:
  9318. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9319. LPFC_RQ_RING_SIZE_2048);
  9320. break;
  9321. case 4096:
  9322. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9323. LPFC_RQ_RING_SIZE_4096);
  9324. break;
  9325. }
  9326. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9327. cq->queue_id);
  9328. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9329. hrq->page_count);
  9330. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9331. LPFC_HDR_BUF_SIZE);
  9332. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9333. memset(dmabuf->virt, 0, hw_page_size);
  9334. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9335. putPaddrLow(dmabuf->phys);
  9336. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9337. putPaddrHigh(dmabuf->phys);
  9338. }
  9339. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9340. /* The IOCTL status is embedded in the mailbox subheader. */
  9341. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9342. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9343. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9344. if (shdr_status || shdr_add_status || rc) {
  9345. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9346. "2504 RQ_CREATE mailbox failed with "
  9347. "status x%x add_status x%x, mbx status x%x\n",
  9348. shdr_status, shdr_add_status, rc);
  9349. status = -ENXIO;
  9350. goto out;
  9351. }
  9352. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9353. if (hrq->queue_id == 0xFFFF) {
  9354. status = -ENXIO;
  9355. goto out;
  9356. }
  9357. hrq->type = LPFC_HRQ;
  9358. hrq->subtype = subtype;
  9359. hrq->host_index = 0;
  9360. hrq->hba_index = 0;
  9361. /* now create the data queue */
  9362. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9363. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9364. length, LPFC_SLI4_MBX_EMBED);
  9365. switch (drq->entry_count) {
  9366. default:
  9367. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9368. "2536 Unsupported RQ count. (%d)\n",
  9369. drq->entry_count);
  9370. if (drq->entry_count < 512)
  9371. return -EINVAL;
  9372. /* otherwise default to smallest count (drop through) */
  9373. case 512:
  9374. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9375. LPFC_RQ_RING_SIZE_512);
  9376. break;
  9377. case 1024:
  9378. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9379. LPFC_RQ_RING_SIZE_1024);
  9380. break;
  9381. case 2048:
  9382. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9383. LPFC_RQ_RING_SIZE_2048);
  9384. break;
  9385. case 4096:
  9386. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9387. LPFC_RQ_RING_SIZE_4096);
  9388. break;
  9389. }
  9390. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9391. cq->queue_id);
  9392. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9393. drq->page_count);
  9394. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9395. LPFC_DATA_BUF_SIZE);
  9396. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9397. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9398. putPaddrLow(dmabuf->phys);
  9399. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9400. putPaddrHigh(dmabuf->phys);
  9401. }
  9402. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9403. /* The IOCTL status is embedded in the mailbox subheader. */
  9404. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9405. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9406. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9407. if (shdr_status || shdr_add_status || rc) {
  9408. status = -ENXIO;
  9409. goto out;
  9410. }
  9411. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9412. if (drq->queue_id == 0xFFFF) {
  9413. status = -ENXIO;
  9414. goto out;
  9415. }
  9416. drq->type = LPFC_DRQ;
  9417. drq->subtype = subtype;
  9418. drq->host_index = 0;
  9419. drq->hba_index = 0;
  9420. /* link the header and data RQs onto the parent cq child list */
  9421. list_add_tail(&hrq->list, &cq->child_list);
  9422. list_add_tail(&drq->list, &cq->child_list);
  9423. out:
  9424. mempool_free(mbox, phba->mbox_mem_pool);
  9425. return status;
  9426. }
  9427. /**
  9428. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9429. * @eq: The queue structure associated with the queue to destroy.
  9430. *
  9431. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9432. * command, specific to the type of queue, to the HBA.
  9433. *
  9434. * The @eq struct is used to get the queue ID of the queue to destroy.
  9435. *
  9436. * On success this function will return a zero. If the queue destroy mailbox
  9437. * command fails this function will return ENXIO.
  9438. **/
  9439. uint32_t
  9440. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9441. {
  9442. LPFC_MBOXQ_t *mbox;
  9443. int rc, length, status = 0;
  9444. uint32_t shdr_status, shdr_add_status;
  9445. union lpfc_sli4_cfg_shdr *shdr;
  9446. if (!eq)
  9447. return -ENODEV;
  9448. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9449. if (!mbox)
  9450. return -ENOMEM;
  9451. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9452. sizeof(struct lpfc_sli4_cfg_mhdr));
  9453. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9454. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9455. length, LPFC_SLI4_MBX_EMBED);
  9456. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9457. eq->queue_id);
  9458. mbox->vport = eq->phba->pport;
  9459. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9460. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9461. /* The IOCTL status is embedded in the mailbox subheader. */
  9462. shdr = (union lpfc_sli4_cfg_shdr *)
  9463. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9464. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9465. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9466. if (shdr_status || shdr_add_status || rc) {
  9467. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9468. "2505 EQ_DESTROY mailbox failed with "
  9469. "status x%x add_status x%x, mbx status x%x\n",
  9470. shdr_status, shdr_add_status, rc);
  9471. status = -ENXIO;
  9472. }
  9473. /* Remove eq from any list */
  9474. list_del_init(&eq->list);
  9475. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9476. return status;
  9477. }
  9478. /**
  9479. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9480. * @cq: The queue structure associated with the queue to destroy.
  9481. *
  9482. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9483. * command, specific to the type of queue, to the HBA.
  9484. *
  9485. * The @cq struct is used to get the queue ID of the queue to destroy.
  9486. *
  9487. * On success this function will return a zero. If the queue destroy mailbox
  9488. * command fails this function will return ENXIO.
  9489. **/
  9490. uint32_t
  9491. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9492. {
  9493. LPFC_MBOXQ_t *mbox;
  9494. int rc, length, status = 0;
  9495. uint32_t shdr_status, shdr_add_status;
  9496. union lpfc_sli4_cfg_shdr *shdr;
  9497. if (!cq)
  9498. return -ENODEV;
  9499. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9500. if (!mbox)
  9501. return -ENOMEM;
  9502. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9503. sizeof(struct lpfc_sli4_cfg_mhdr));
  9504. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9505. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9506. length, LPFC_SLI4_MBX_EMBED);
  9507. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9508. cq->queue_id);
  9509. mbox->vport = cq->phba->pport;
  9510. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9511. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9512. /* The IOCTL status is embedded in the mailbox subheader. */
  9513. shdr = (union lpfc_sli4_cfg_shdr *)
  9514. &mbox->u.mqe.un.wq_create.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 (shdr_status || shdr_add_status || rc) {
  9518. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9519. "2506 CQ_DESTROY mailbox failed with "
  9520. "status x%x add_status x%x, mbx status x%x\n",
  9521. shdr_status, shdr_add_status, rc);
  9522. status = -ENXIO;
  9523. }
  9524. /* Remove cq from any list */
  9525. list_del_init(&cq->list);
  9526. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9527. return status;
  9528. }
  9529. /**
  9530. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9531. * @qm: The queue structure associated with the queue to destroy.
  9532. *
  9533. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9534. * command, specific to the type of queue, to the HBA.
  9535. *
  9536. * The @mq struct is used to get the queue ID of the queue to destroy.
  9537. *
  9538. * On success this function will return a zero. If the queue destroy mailbox
  9539. * command fails this function will return ENXIO.
  9540. **/
  9541. uint32_t
  9542. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9543. {
  9544. LPFC_MBOXQ_t *mbox;
  9545. int rc, length, status = 0;
  9546. uint32_t shdr_status, shdr_add_status;
  9547. union lpfc_sli4_cfg_shdr *shdr;
  9548. if (!mq)
  9549. return -ENODEV;
  9550. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9551. if (!mbox)
  9552. return -ENOMEM;
  9553. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9554. sizeof(struct lpfc_sli4_cfg_mhdr));
  9555. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9556. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9557. length, LPFC_SLI4_MBX_EMBED);
  9558. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9559. mq->queue_id);
  9560. mbox->vport = mq->phba->pport;
  9561. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9562. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9563. /* The IOCTL status is embedded in the mailbox subheader. */
  9564. shdr = (union lpfc_sli4_cfg_shdr *)
  9565. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9566. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9567. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9568. if (shdr_status || shdr_add_status || rc) {
  9569. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9570. "2507 MQ_DESTROY mailbox failed with "
  9571. "status x%x add_status x%x, mbx status x%x\n",
  9572. shdr_status, shdr_add_status, rc);
  9573. status = -ENXIO;
  9574. }
  9575. /* Remove mq from any list */
  9576. list_del_init(&mq->list);
  9577. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9578. return status;
  9579. }
  9580. /**
  9581. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9582. * @wq: The queue structure associated with the queue to destroy.
  9583. *
  9584. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9585. * command, specific to the type of queue, to the HBA.
  9586. *
  9587. * The @wq struct is used to get the queue ID of the queue to destroy.
  9588. *
  9589. * On success this function will return a zero. If the queue destroy mailbox
  9590. * command fails this function will return ENXIO.
  9591. **/
  9592. uint32_t
  9593. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9594. {
  9595. LPFC_MBOXQ_t *mbox;
  9596. int rc, length, status = 0;
  9597. uint32_t shdr_status, shdr_add_status;
  9598. union lpfc_sli4_cfg_shdr *shdr;
  9599. if (!wq)
  9600. return -ENODEV;
  9601. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9602. if (!mbox)
  9603. return -ENOMEM;
  9604. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9605. sizeof(struct lpfc_sli4_cfg_mhdr));
  9606. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9607. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9608. length, LPFC_SLI4_MBX_EMBED);
  9609. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9610. wq->queue_id);
  9611. mbox->vport = wq->phba->pport;
  9612. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9613. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9614. shdr = (union lpfc_sli4_cfg_shdr *)
  9615. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9616. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9617. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9618. if (shdr_status || shdr_add_status || rc) {
  9619. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9620. "2508 WQ_DESTROY mailbox failed with "
  9621. "status x%x add_status x%x, mbx status x%x\n",
  9622. shdr_status, shdr_add_status, rc);
  9623. status = -ENXIO;
  9624. }
  9625. /* Remove wq from any list */
  9626. list_del_init(&wq->list);
  9627. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9628. return status;
  9629. }
  9630. /**
  9631. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9632. * @rq: The queue structure associated with the queue to destroy.
  9633. *
  9634. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9635. * command, specific to the type of queue, to the HBA.
  9636. *
  9637. * The @rq struct is used to get the queue ID of the queue to destroy.
  9638. *
  9639. * On success this function will return a zero. If the queue destroy mailbox
  9640. * command fails this function will return ENXIO.
  9641. **/
  9642. uint32_t
  9643. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9644. struct lpfc_queue *drq)
  9645. {
  9646. LPFC_MBOXQ_t *mbox;
  9647. int rc, length, status = 0;
  9648. uint32_t shdr_status, shdr_add_status;
  9649. union lpfc_sli4_cfg_shdr *shdr;
  9650. if (!hrq || !drq)
  9651. return -ENODEV;
  9652. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9653. if (!mbox)
  9654. return -ENOMEM;
  9655. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9656. sizeof(struct mbox_header));
  9657. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9658. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9659. length, LPFC_SLI4_MBX_EMBED);
  9660. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9661. hrq->queue_id);
  9662. mbox->vport = hrq->phba->pport;
  9663. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9664. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9665. /* The IOCTL status is embedded in the mailbox subheader. */
  9666. shdr = (union lpfc_sli4_cfg_shdr *)
  9667. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9668. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9669. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9670. if (shdr_status || shdr_add_status || rc) {
  9671. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9672. "2509 RQ_DESTROY mailbox failed with "
  9673. "status x%x add_status x%x, mbx status x%x\n",
  9674. shdr_status, shdr_add_status, rc);
  9675. if (rc != MBX_TIMEOUT)
  9676. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9677. return -ENXIO;
  9678. }
  9679. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9680. drq->queue_id);
  9681. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9682. shdr = (union lpfc_sli4_cfg_shdr *)
  9683. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9684. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9685. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9686. if (shdr_status || shdr_add_status || rc) {
  9687. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9688. "2510 RQ_DESTROY mailbox failed with "
  9689. "status x%x add_status x%x, mbx status x%x\n",
  9690. shdr_status, shdr_add_status, rc);
  9691. status = -ENXIO;
  9692. }
  9693. list_del_init(&hrq->list);
  9694. list_del_init(&drq->list);
  9695. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9696. return status;
  9697. }
  9698. /**
  9699. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9700. * @phba: The virtual port for which this call being executed.
  9701. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9702. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9703. * @xritag: the xritag that ties this io to the SGL pages.
  9704. *
  9705. * This routine will post the sgl pages for the IO that has the xritag
  9706. * that is in the iocbq structure. The xritag is assigned during iocbq
  9707. * creation and persists for as long as the driver is loaded.
  9708. * if the caller has fewer than 256 scatter gather segments to map then
  9709. * pdma_phys_addr1 should be 0.
  9710. * If the caller needs to map more than 256 scatter gather segment then
  9711. * pdma_phys_addr1 should be a valid physical address.
  9712. * physical address for SGLs must be 64 byte aligned.
  9713. * If you are going to map 2 SGL's then the first one must have 256 entries
  9714. * the second sgl can have between 1 and 256 entries.
  9715. *
  9716. * Return codes:
  9717. * 0 - Success
  9718. * -ENXIO, -ENOMEM - Failure
  9719. **/
  9720. int
  9721. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9722. dma_addr_t pdma_phys_addr0,
  9723. dma_addr_t pdma_phys_addr1,
  9724. uint16_t xritag)
  9725. {
  9726. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9727. LPFC_MBOXQ_t *mbox;
  9728. int rc;
  9729. uint32_t shdr_status, shdr_add_status;
  9730. union lpfc_sli4_cfg_shdr *shdr;
  9731. if (xritag == NO_XRI) {
  9732. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9733. "0364 Invalid param:\n");
  9734. return -EINVAL;
  9735. }
  9736. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9737. if (!mbox)
  9738. return -ENOMEM;
  9739. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9740. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9741. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9742. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9743. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9744. &mbox->u.mqe.un.post_sgl_pages;
  9745. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9746. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9747. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9748. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9749. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9750. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9751. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9752. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9753. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9754. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9755. if (!phba->sli4_hba.intr_enable)
  9756. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9757. else
  9758. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9759. /* The IOCTL status is embedded in the mailbox subheader. */
  9760. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9761. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9762. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9763. if (rc != MBX_TIMEOUT)
  9764. mempool_free(mbox, phba->mbox_mem_pool);
  9765. if (shdr_status || shdr_add_status || rc) {
  9766. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9767. "2511 POST_SGL mailbox failed with "
  9768. "status x%x add_status x%x, mbx status x%x\n",
  9769. shdr_status, shdr_add_status, rc);
  9770. rc = -ENXIO;
  9771. }
  9772. return 0;
  9773. }
  9774. /**
  9775. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9776. * @phba: The virtual port for which this call being executed.
  9777. *
  9778. * This routine will remove all of the sgl pages registered with the hba.
  9779. *
  9780. * Return codes:
  9781. * 0 - Success
  9782. * -ENXIO, -ENOMEM - Failure
  9783. **/
  9784. int
  9785. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9786. {
  9787. LPFC_MBOXQ_t *mbox;
  9788. int rc;
  9789. uint32_t shdr_status, shdr_add_status;
  9790. union lpfc_sli4_cfg_shdr *shdr;
  9791. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9792. if (!mbox)
  9793. return -ENOMEM;
  9794. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9795. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9796. LPFC_SLI4_MBX_EMBED);
  9797. if (!phba->sli4_hba.intr_enable)
  9798. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9799. else
  9800. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9801. /* The IOCTL status is embedded in the mailbox subheader. */
  9802. shdr = (union lpfc_sli4_cfg_shdr *)
  9803. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9804. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9805. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9806. if (rc != MBX_TIMEOUT)
  9807. mempool_free(mbox, phba->mbox_mem_pool);
  9808. if (shdr_status || shdr_add_status || rc) {
  9809. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9810. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9811. "status x%x add_status x%x, mbx status x%x\n",
  9812. shdr_status, shdr_add_status, rc);
  9813. rc = -ENXIO;
  9814. }
  9815. return rc;
  9816. }
  9817. /**
  9818. * lpfc_sli4_next_xritag - Get an xritag for the io
  9819. * @phba: Pointer to HBA context object.
  9820. *
  9821. * This function gets an xritag for the iocb. If there is no unused xritag
  9822. * it will return 0xffff.
  9823. * The function returns the allocated xritag if successful, else returns zero.
  9824. * Zero is not a valid xritag.
  9825. * The caller is not required to hold any lock.
  9826. **/
  9827. uint16_t
  9828. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9829. {
  9830. uint16_t xritag;
  9831. spin_lock_irq(&phba->hbalock);
  9832. xritag = phba->sli4_hba.next_xri;
  9833. if ((xritag != (uint16_t) -1) && xritag <
  9834. (phba->sli4_hba.max_cfg_param.max_xri
  9835. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9836. phba->sli4_hba.next_xri++;
  9837. phba->sli4_hba.max_cfg_param.xri_used++;
  9838. spin_unlock_irq(&phba->hbalock);
  9839. return xritag;
  9840. }
  9841. spin_unlock_irq(&phba->hbalock);
  9842. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9843. "2004 Failed to allocate XRI.last XRITAG is %d"
  9844. " Max XRI is %d, Used XRI is %d\n",
  9845. phba->sli4_hba.next_xri,
  9846. phba->sli4_hba.max_cfg_param.max_xri,
  9847. phba->sli4_hba.max_cfg_param.xri_used);
  9848. return -1;
  9849. }
  9850. /**
  9851. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9852. * @phba: pointer to lpfc hba data structure.
  9853. *
  9854. * This routine is invoked to post a block of driver's sgl pages to the
  9855. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9856. * is only called when the driver is loading and after all IO has been
  9857. * stopped.
  9858. **/
  9859. int
  9860. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9861. {
  9862. struct lpfc_sglq *sglq_entry;
  9863. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9864. struct sgl_page_pairs *sgl_pg_pairs;
  9865. void *viraddr;
  9866. LPFC_MBOXQ_t *mbox;
  9867. uint32_t reqlen, alloclen, pg_pairs;
  9868. uint32_t mbox_tmo;
  9869. uint16_t xritag_start = 0;
  9870. int els_xri_cnt, rc = 0;
  9871. uint32_t shdr_status, shdr_add_status;
  9872. union lpfc_sli4_cfg_shdr *shdr;
  9873. /* The number of sgls to be posted */
  9874. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9875. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9876. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9877. if (reqlen > SLI4_PAGE_SIZE) {
  9878. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9879. "2559 Block sgl registration required DMA "
  9880. "size (%d) great than a page\n", reqlen);
  9881. return -ENOMEM;
  9882. }
  9883. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9884. if (!mbox) {
  9885. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9886. "2560 Failed to allocate mbox cmd memory\n");
  9887. return -ENOMEM;
  9888. }
  9889. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9890. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9891. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9892. LPFC_SLI4_MBX_NEMBED);
  9893. if (alloclen < reqlen) {
  9894. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9895. "0285 Allocated DMA memory size (%d) is "
  9896. "less than the requested DMA memory "
  9897. "size (%d)\n", alloclen, reqlen);
  9898. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9899. return -ENOMEM;
  9900. }
  9901. /* Get the first SGE entry from the non-embedded DMA memory */
  9902. viraddr = mbox->sge_array->addr[0];
  9903. /* Set up the SGL pages in the non-embedded DMA pages */
  9904. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9905. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9906. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9907. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9908. /* Set up the sge entry */
  9909. sgl_pg_pairs->sgl_pg0_addr_lo =
  9910. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9911. sgl_pg_pairs->sgl_pg0_addr_hi =
  9912. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9913. sgl_pg_pairs->sgl_pg1_addr_lo =
  9914. cpu_to_le32(putPaddrLow(0));
  9915. sgl_pg_pairs->sgl_pg1_addr_hi =
  9916. cpu_to_le32(putPaddrHigh(0));
  9917. /* Keep the first xritag on the list */
  9918. if (pg_pairs == 0)
  9919. xritag_start = sglq_entry->sli4_xritag;
  9920. sgl_pg_pairs++;
  9921. }
  9922. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9923. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9924. /* Perform endian conversion if necessary */
  9925. sgl->word0 = cpu_to_le32(sgl->word0);
  9926. if (!phba->sli4_hba.intr_enable)
  9927. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9928. else {
  9929. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9930. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9931. }
  9932. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9933. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9934. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9935. if (rc != MBX_TIMEOUT)
  9936. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9937. if (shdr_status || shdr_add_status || rc) {
  9938. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9939. "2513 POST_SGL_BLOCK mailbox command failed "
  9940. "status x%x add_status x%x mbx status x%x\n",
  9941. shdr_status, shdr_add_status, rc);
  9942. rc = -ENXIO;
  9943. }
  9944. return rc;
  9945. }
  9946. /**
  9947. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9948. * @phba: pointer to lpfc hba data structure.
  9949. * @sblist: pointer to scsi buffer list.
  9950. * @count: number of scsi buffers on the list.
  9951. *
  9952. * This routine is invoked to post a block of @count scsi sgl pages from a
  9953. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9954. * No Lock is held.
  9955. *
  9956. **/
  9957. int
  9958. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9959. int cnt)
  9960. {
  9961. struct lpfc_scsi_buf *psb;
  9962. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9963. struct sgl_page_pairs *sgl_pg_pairs;
  9964. void *viraddr;
  9965. LPFC_MBOXQ_t *mbox;
  9966. uint32_t reqlen, alloclen, pg_pairs;
  9967. uint32_t mbox_tmo;
  9968. uint16_t xritag_start = 0;
  9969. int rc = 0;
  9970. uint32_t shdr_status, shdr_add_status;
  9971. dma_addr_t pdma_phys_bpl1;
  9972. union lpfc_sli4_cfg_shdr *shdr;
  9973. /* Calculate the requested length of the dma memory */
  9974. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9975. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9976. if (reqlen > SLI4_PAGE_SIZE) {
  9977. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9978. "0217 Block sgl registration required DMA "
  9979. "size (%d) great than a page\n", reqlen);
  9980. return -ENOMEM;
  9981. }
  9982. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9983. if (!mbox) {
  9984. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9985. "0283 Failed to allocate mbox cmd memory\n");
  9986. return -ENOMEM;
  9987. }
  9988. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9989. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9990. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9991. LPFC_SLI4_MBX_NEMBED);
  9992. if (alloclen < reqlen) {
  9993. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9994. "2561 Allocated DMA memory size (%d) is "
  9995. "less than the requested DMA memory "
  9996. "size (%d)\n", alloclen, reqlen);
  9997. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9998. return -ENOMEM;
  9999. }
  10000. /* Get the first SGE entry from the non-embedded DMA memory */
  10001. viraddr = mbox->sge_array->addr[0];
  10002. /* Set up the SGL pages in the non-embedded DMA pages */
  10003. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10004. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10005. pg_pairs = 0;
  10006. list_for_each_entry(psb, sblist, list) {
  10007. /* Set up the sge entry */
  10008. sgl_pg_pairs->sgl_pg0_addr_lo =
  10009. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10010. sgl_pg_pairs->sgl_pg0_addr_hi =
  10011. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10012. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10013. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10014. else
  10015. pdma_phys_bpl1 = 0;
  10016. sgl_pg_pairs->sgl_pg1_addr_lo =
  10017. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10018. sgl_pg_pairs->sgl_pg1_addr_hi =
  10019. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10020. /* Keep the first xritag on the list */
  10021. if (pg_pairs == 0)
  10022. xritag_start = psb->cur_iocbq.sli4_xritag;
  10023. sgl_pg_pairs++;
  10024. pg_pairs++;
  10025. }
  10026. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10027. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10028. /* Perform endian conversion if necessary */
  10029. sgl->word0 = cpu_to_le32(sgl->word0);
  10030. if (!phba->sli4_hba.intr_enable)
  10031. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10032. else {
  10033. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10034. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10035. }
  10036. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10037. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10038. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10039. if (rc != MBX_TIMEOUT)
  10040. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10041. if (shdr_status || shdr_add_status || rc) {
  10042. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10043. "2564 POST_SGL_BLOCK mailbox command failed "
  10044. "status x%x add_status x%x mbx status x%x\n",
  10045. shdr_status, shdr_add_status, rc);
  10046. rc = -ENXIO;
  10047. }
  10048. return rc;
  10049. }
  10050. /**
  10051. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10052. * @phba: pointer to lpfc_hba struct that the frame was received on
  10053. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10054. *
  10055. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10056. * valid type of frame that the LPFC driver will handle. This function will
  10057. * return a zero if the frame is a valid frame or a non zero value when the
  10058. * frame does not pass the check.
  10059. **/
  10060. static int
  10061. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10062. {
  10063. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10064. char *type_names[] = FC_TYPE_NAMES_INIT;
  10065. struct fc_vft_header *fc_vft_hdr;
  10066. switch (fc_hdr->fh_r_ctl) {
  10067. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10068. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10069. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10070. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10071. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10072. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10073. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10074. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10075. case FC_RCTL_ELS_REQ: /* extended link services request */
  10076. case FC_RCTL_ELS_REP: /* extended link services reply */
  10077. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10078. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10079. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10080. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10081. case FC_RCTL_BA_RMC: /* remove connection */
  10082. case FC_RCTL_BA_ACC: /* basic accept */
  10083. case FC_RCTL_BA_RJT: /* basic reject */
  10084. case FC_RCTL_BA_PRMT:
  10085. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10086. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10087. case FC_RCTL_P_RJT: /* port reject */
  10088. case FC_RCTL_F_RJT: /* fabric reject */
  10089. case FC_RCTL_P_BSY: /* port busy */
  10090. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10091. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10092. case FC_RCTL_LCR: /* link credit reset */
  10093. case FC_RCTL_END: /* end */
  10094. break;
  10095. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10096. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10097. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10098. return lpfc_fc_frame_check(phba, fc_hdr);
  10099. default:
  10100. goto drop;
  10101. }
  10102. switch (fc_hdr->fh_type) {
  10103. case FC_TYPE_BLS:
  10104. case FC_TYPE_ELS:
  10105. case FC_TYPE_FCP:
  10106. case FC_TYPE_CT:
  10107. break;
  10108. case FC_TYPE_IP:
  10109. case FC_TYPE_ILS:
  10110. default:
  10111. goto drop;
  10112. }
  10113. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10114. "2538 Received frame rctl:%s type:%s\n",
  10115. rctl_names[fc_hdr->fh_r_ctl],
  10116. type_names[fc_hdr->fh_type]);
  10117. return 0;
  10118. drop:
  10119. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10120. "2539 Dropped frame rctl:%s type:%s\n",
  10121. rctl_names[fc_hdr->fh_r_ctl],
  10122. type_names[fc_hdr->fh_type]);
  10123. return 1;
  10124. }
  10125. /**
  10126. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10127. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10128. *
  10129. * This function processes the FC header to retrieve the VFI from the VF
  10130. * header, if one exists. This function will return the VFI if one exists
  10131. * or 0 if no VSAN Header exists.
  10132. **/
  10133. static uint32_t
  10134. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10135. {
  10136. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10137. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10138. return 0;
  10139. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10140. }
  10141. /**
  10142. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10143. * @phba: Pointer to the HBA structure to search for the vport on
  10144. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10145. * @fcfi: The FC Fabric ID that the frame came from
  10146. *
  10147. * This function searches the @phba for a vport that matches the content of the
  10148. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10149. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10150. * returns the matching vport pointer or NULL if unable to match frame to a
  10151. * vport.
  10152. **/
  10153. static struct lpfc_vport *
  10154. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10155. uint16_t fcfi)
  10156. {
  10157. struct lpfc_vport **vports;
  10158. struct lpfc_vport *vport = NULL;
  10159. int i;
  10160. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10161. fc_hdr->fh_d_id[1] << 8 |
  10162. fc_hdr->fh_d_id[2]);
  10163. vports = lpfc_create_vport_work_array(phba);
  10164. if (vports != NULL)
  10165. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10166. if (phba->fcf.fcfi == fcfi &&
  10167. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10168. vports[i]->fc_myDID == did) {
  10169. vport = vports[i];
  10170. break;
  10171. }
  10172. }
  10173. lpfc_destroy_vport_work_array(phba, vports);
  10174. return vport;
  10175. }
  10176. /**
  10177. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10178. * @vport: The vport to work on.
  10179. *
  10180. * This function updates the receive sequence time stamp for this vport. The
  10181. * receive sequence time stamp indicates the time that the last frame of the
  10182. * the sequence that has been idle for the longest amount of time was received.
  10183. * the driver uses this time stamp to indicate if any received sequences have
  10184. * timed out.
  10185. **/
  10186. void
  10187. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10188. {
  10189. struct lpfc_dmabuf *h_buf;
  10190. struct hbq_dmabuf *dmabuf = NULL;
  10191. /* get the oldest sequence on the rcv list */
  10192. h_buf = list_get_first(&vport->rcv_buffer_list,
  10193. struct lpfc_dmabuf, list);
  10194. if (!h_buf)
  10195. return;
  10196. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10197. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10198. }
  10199. /**
  10200. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10201. * @vport: The vport that the received sequences were sent to.
  10202. *
  10203. * This function cleans up all outstanding received sequences. This is called
  10204. * by the driver when a link event or user action invalidates all the received
  10205. * sequences.
  10206. **/
  10207. void
  10208. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10209. {
  10210. struct lpfc_dmabuf *h_buf, *hnext;
  10211. struct lpfc_dmabuf *d_buf, *dnext;
  10212. struct hbq_dmabuf *dmabuf = NULL;
  10213. /* start with the oldest sequence on the rcv list */
  10214. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10215. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10216. list_del_init(&dmabuf->hbuf.list);
  10217. list_for_each_entry_safe(d_buf, dnext,
  10218. &dmabuf->dbuf.list, list) {
  10219. list_del_init(&d_buf->list);
  10220. lpfc_in_buf_free(vport->phba, d_buf);
  10221. }
  10222. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10223. }
  10224. }
  10225. /**
  10226. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10227. * @vport: The vport that the received sequences were sent to.
  10228. *
  10229. * This function determines whether any received sequences have timed out by
  10230. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10231. * indicates that there is at least one timed out sequence this routine will
  10232. * go through the received sequences one at a time from most inactive to most
  10233. * active to determine which ones need to be cleaned up. Once it has determined
  10234. * that a sequence needs to be cleaned up it will simply free up the resources
  10235. * without sending an abort.
  10236. **/
  10237. void
  10238. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10239. {
  10240. struct lpfc_dmabuf *h_buf, *hnext;
  10241. struct lpfc_dmabuf *d_buf, *dnext;
  10242. struct hbq_dmabuf *dmabuf = NULL;
  10243. unsigned long timeout;
  10244. int abort_count = 0;
  10245. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10246. vport->rcv_buffer_time_stamp);
  10247. if (list_empty(&vport->rcv_buffer_list) ||
  10248. time_before(jiffies, timeout))
  10249. return;
  10250. /* start with the oldest sequence on the rcv list */
  10251. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10252. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10253. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10254. dmabuf->time_stamp);
  10255. if (time_before(jiffies, timeout))
  10256. break;
  10257. abort_count++;
  10258. list_del_init(&dmabuf->hbuf.list);
  10259. list_for_each_entry_safe(d_buf, dnext,
  10260. &dmabuf->dbuf.list, list) {
  10261. list_del_init(&d_buf->list);
  10262. lpfc_in_buf_free(vport->phba, d_buf);
  10263. }
  10264. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10265. }
  10266. if (abort_count)
  10267. lpfc_update_rcv_time_stamp(vport);
  10268. }
  10269. /**
  10270. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10271. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10272. *
  10273. * This function searches through the existing incomplete sequences that have
  10274. * been sent to this @vport. If the frame matches one of the incomplete
  10275. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10276. * make up that sequence. If no sequence is found that matches this frame then
  10277. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10278. * This function returns a pointer to the first dmabuf in the sequence list that
  10279. * the frame was linked to.
  10280. **/
  10281. static struct hbq_dmabuf *
  10282. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10283. {
  10284. struct fc_frame_header *new_hdr;
  10285. struct fc_frame_header *temp_hdr;
  10286. struct lpfc_dmabuf *d_buf;
  10287. struct lpfc_dmabuf *h_buf;
  10288. struct hbq_dmabuf *seq_dmabuf = NULL;
  10289. struct hbq_dmabuf *temp_dmabuf = NULL;
  10290. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10291. dmabuf->time_stamp = jiffies;
  10292. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10293. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10294. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10295. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10296. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10297. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10298. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10299. continue;
  10300. /* found a pending sequence that matches this frame */
  10301. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10302. break;
  10303. }
  10304. if (!seq_dmabuf) {
  10305. /*
  10306. * This indicates first frame received for this sequence.
  10307. * Queue the buffer on the vport's rcv_buffer_list.
  10308. */
  10309. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10310. lpfc_update_rcv_time_stamp(vport);
  10311. return dmabuf;
  10312. }
  10313. temp_hdr = seq_dmabuf->hbuf.virt;
  10314. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10315. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10316. list_del_init(&seq_dmabuf->hbuf.list);
  10317. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10318. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10319. lpfc_update_rcv_time_stamp(vport);
  10320. return dmabuf;
  10321. }
  10322. /* move this sequence to the tail to indicate a young sequence */
  10323. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10324. seq_dmabuf->time_stamp = jiffies;
  10325. lpfc_update_rcv_time_stamp(vport);
  10326. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10327. temp_hdr = dmabuf->hbuf.virt;
  10328. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10329. return seq_dmabuf;
  10330. }
  10331. /* find the correct place in the sequence to insert this frame */
  10332. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10333. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10334. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10335. /*
  10336. * If the frame's sequence count is greater than the frame on
  10337. * the list then insert the frame right after this frame
  10338. */
  10339. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10340. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10341. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10342. return seq_dmabuf;
  10343. }
  10344. }
  10345. return NULL;
  10346. }
  10347. /**
  10348. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10349. * @vport: pointer to a vitural port
  10350. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10351. *
  10352. * This function tries to abort from the partially assembed sequence, described
  10353. * by the information from basic abbort @dmabuf. It checks to see whether such
  10354. * partially assembled sequence held by the driver. If so, it shall free up all
  10355. * the frames from the partially assembled sequence.
  10356. *
  10357. * Return
  10358. * true -- if there is matching partially assembled sequence present and all
  10359. * the frames freed with the sequence;
  10360. * false -- if there is no matching partially assembled sequence present so
  10361. * nothing got aborted in the lower layer driver
  10362. **/
  10363. static bool
  10364. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10365. struct hbq_dmabuf *dmabuf)
  10366. {
  10367. struct fc_frame_header *new_hdr;
  10368. struct fc_frame_header *temp_hdr;
  10369. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10370. struct hbq_dmabuf *seq_dmabuf = NULL;
  10371. /* Use the hdr_buf to find the sequence that matches this frame */
  10372. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10373. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10374. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10375. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10376. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10377. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10378. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10379. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10380. continue;
  10381. /* found a pending sequence that matches this frame */
  10382. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10383. break;
  10384. }
  10385. /* Free up all the frames from the partially assembled sequence */
  10386. if (seq_dmabuf) {
  10387. list_for_each_entry_safe(d_buf, n_buf,
  10388. &seq_dmabuf->dbuf.list, list) {
  10389. list_del_init(&d_buf->list);
  10390. lpfc_in_buf_free(vport->phba, d_buf);
  10391. }
  10392. return true;
  10393. }
  10394. return false;
  10395. }
  10396. /**
  10397. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10398. * @phba: Pointer to HBA context object.
  10399. * @cmd_iocbq: pointer to the command iocbq structure.
  10400. * @rsp_iocbq: pointer to the response iocbq structure.
  10401. *
  10402. * This function handles the sequence abort accept iocb command complete
  10403. * event. It properly releases the memory allocated to the sequence abort
  10404. * accept iocb.
  10405. **/
  10406. static void
  10407. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10408. struct lpfc_iocbq *cmd_iocbq,
  10409. struct lpfc_iocbq *rsp_iocbq)
  10410. {
  10411. if (cmd_iocbq)
  10412. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10413. }
  10414. /**
  10415. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10416. * @phba: Pointer to HBA context object.
  10417. * @fc_hdr: pointer to a FC frame header.
  10418. *
  10419. * This function sends a basic accept to a previous unsol sequence abort
  10420. * event after aborting the sequence handling.
  10421. **/
  10422. static void
  10423. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10424. struct fc_frame_header *fc_hdr)
  10425. {
  10426. struct lpfc_iocbq *ctiocb = NULL;
  10427. struct lpfc_nodelist *ndlp;
  10428. uint16_t oxid, rxid;
  10429. uint32_t sid, fctl;
  10430. IOCB_t *icmd;
  10431. if (!lpfc_is_link_up(phba))
  10432. return;
  10433. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10434. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10435. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10436. ndlp = lpfc_findnode_did(phba->pport, sid);
  10437. if (!ndlp) {
  10438. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10439. "1268 Find ndlp returned NULL for oxid:x%x "
  10440. "SID:x%x\n", oxid, sid);
  10441. return;
  10442. }
  10443. /* Allocate buffer for acc iocb */
  10444. ctiocb = lpfc_sli_get_iocbq(phba);
  10445. if (!ctiocb)
  10446. return;
  10447. /* Extract the F_CTL field from FC_HDR */
  10448. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10449. icmd = &ctiocb->iocb;
  10450. icmd->un.xseq64.bdl.bdeSize = 0;
  10451. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10452. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10453. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10454. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10455. /* Fill in the rest of iocb fields */
  10456. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10457. icmd->ulpBdeCount = 0;
  10458. icmd->ulpLe = 1;
  10459. icmd->ulpClass = CLASS3;
  10460. icmd->ulpContext = ndlp->nlp_rpi;
  10461. ctiocb->iocb_cmpl = NULL;
  10462. ctiocb->vport = phba->pport;
  10463. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10464. if (fctl & FC_FC_EX_CTX) {
  10465. /* ABTS sent by responder to CT exchange, construction
  10466. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10467. * field and RX_ID from ABTS for RX_ID field.
  10468. */
  10469. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10470. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10471. ctiocb->sli4_xritag = oxid;
  10472. } else {
  10473. /* ABTS sent by initiator to CT exchange, construction
  10474. * of BA_ACC will need to allocate a new XRI as for the
  10475. * XRI_TAG and RX_ID fields.
  10476. */
  10477. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10478. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10479. ctiocb->sli4_xritag = NO_XRI;
  10480. }
  10481. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10482. /* Xmit CT abts accept on exchange <xid> */
  10483. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10484. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10485. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10486. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10487. }
  10488. /**
  10489. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10490. * @vport: Pointer to the vport on which this sequence was received
  10491. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10492. *
  10493. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10494. * receive sequence is only partially assembed by the driver, it shall abort
  10495. * the partially assembled frames for the sequence. Otherwise, if the
  10496. * unsolicited receive sequence has been completely assembled and passed to
  10497. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10498. * unsolicited sequence has been aborted. After that, it will issue a basic
  10499. * accept to accept the abort.
  10500. **/
  10501. void
  10502. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10503. struct hbq_dmabuf *dmabuf)
  10504. {
  10505. struct lpfc_hba *phba = vport->phba;
  10506. struct fc_frame_header fc_hdr;
  10507. uint32_t fctl;
  10508. bool abts_par;
  10509. /* Make a copy of fc_hdr before the dmabuf being released */
  10510. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10511. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10512. if (fctl & FC_FC_EX_CTX) {
  10513. /*
  10514. * ABTS sent by responder to exchange, just free the buffer
  10515. */
  10516. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10517. } else {
  10518. /*
  10519. * ABTS sent by initiator to exchange, need to do cleanup
  10520. */
  10521. /* Try to abort partially assembled seq */
  10522. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10523. /* Send abort to ULP if partially seq abort failed */
  10524. if (abts_par == false)
  10525. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10526. else
  10527. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10528. }
  10529. /* Send basic accept (BA_ACC) to the abort requester */
  10530. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10531. }
  10532. /**
  10533. * lpfc_seq_complete - Indicates if a sequence is complete
  10534. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10535. *
  10536. * This function checks the sequence, starting with the frame described by
  10537. * @dmabuf, to see if all the frames associated with this sequence are present.
  10538. * the frames associated with this sequence are linked to the @dmabuf using the
  10539. * dbuf list. This function looks for two major things. 1) That the first frame
  10540. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10541. * set. 3) That there are no holes in the sequence count. The function will
  10542. * return 1 when the sequence is complete, otherwise it will return 0.
  10543. **/
  10544. static int
  10545. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10546. {
  10547. struct fc_frame_header *hdr;
  10548. struct lpfc_dmabuf *d_buf;
  10549. struct hbq_dmabuf *seq_dmabuf;
  10550. uint32_t fctl;
  10551. int seq_count = 0;
  10552. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10553. /* make sure first fame of sequence has a sequence count of zero */
  10554. if (hdr->fh_seq_cnt != seq_count)
  10555. return 0;
  10556. fctl = (hdr->fh_f_ctl[0] << 16 |
  10557. hdr->fh_f_ctl[1] << 8 |
  10558. hdr->fh_f_ctl[2]);
  10559. /* If last frame of sequence we can return success. */
  10560. if (fctl & FC_FC_END_SEQ)
  10561. return 1;
  10562. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10563. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10564. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10565. /* If there is a hole in the sequence count then fail. */
  10566. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10567. return 0;
  10568. fctl = (hdr->fh_f_ctl[0] << 16 |
  10569. hdr->fh_f_ctl[1] << 8 |
  10570. hdr->fh_f_ctl[2]);
  10571. /* If last frame of sequence we can return success. */
  10572. if (fctl & FC_FC_END_SEQ)
  10573. return 1;
  10574. }
  10575. return 0;
  10576. }
  10577. /**
  10578. * lpfc_prep_seq - Prep sequence for ULP processing
  10579. * @vport: Pointer to the vport on which this sequence was received
  10580. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10581. *
  10582. * This function takes a sequence, described by a list of frames, and creates
  10583. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10584. * used to issue to the generic unsolicited sequence handler. This routine
  10585. * returns a pointer to the first iocbq in the list. If the function is unable
  10586. * to allocate an iocbq then it throw out the received frames that were not
  10587. * able to be described and return a pointer to the first iocbq. If unable to
  10588. * allocate any iocbqs (including the first) this function will return NULL.
  10589. **/
  10590. static struct lpfc_iocbq *
  10591. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10592. {
  10593. struct lpfc_dmabuf *d_buf, *n_buf;
  10594. struct lpfc_iocbq *first_iocbq, *iocbq;
  10595. struct fc_frame_header *fc_hdr;
  10596. uint32_t sid;
  10597. struct ulp_bde64 *pbde;
  10598. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10599. /* remove from receive buffer list */
  10600. list_del_init(&seq_dmabuf->hbuf.list);
  10601. lpfc_update_rcv_time_stamp(vport);
  10602. /* get the Remote Port's SID */
  10603. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10604. /* Get an iocbq struct to fill in. */
  10605. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10606. if (first_iocbq) {
  10607. /* Initialize the first IOCB. */
  10608. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10609. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10610. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10611. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10612. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10613. vport->vpi + vport->phba->vpi_base;
  10614. /* put the first buffer into the first IOCBq */
  10615. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10616. first_iocbq->context3 = NULL;
  10617. first_iocbq->iocb.ulpBdeCount = 1;
  10618. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10619. LPFC_DATA_BUF_SIZE;
  10620. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10621. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10622. bf_get(lpfc_rcqe_length,
  10623. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10624. }
  10625. iocbq = first_iocbq;
  10626. /*
  10627. * Each IOCBq can have two Buffers assigned, so go through the list
  10628. * of buffers for this sequence and save two buffers in each IOCBq
  10629. */
  10630. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10631. if (!iocbq) {
  10632. lpfc_in_buf_free(vport->phba, d_buf);
  10633. continue;
  10634. }
  10635. if (!iocbq->context3) {
  10636. iocbq->context3 = d_buf;
  10637. iocbq->iocb.ulpBdeCount++;
  10638. pbde = (struct ulp_bde64 *)
  10639. &iocbq->iocb.unsli3.sli3Words[4];
  10640. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10641. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10642. bf_get(lpfc_rcqe_length,
  10643. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10644. } else {
  10645. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10646. if (!iocbq) {
  10647. if (first_iocbq) {
  10648. first_iocbq->iocb.ulpStatus =
  10649. IOSTAT_FCP_RSP_ERROR;
  10650. first_iocbq->iocb.un.ulpWord[4] =
  10651. IOERR_NO_RESOURCES;
  10652. }
  10653. lpfc_in_buf_free(vport->phba, d_buf);
  10654. continue;
  10655. }
  10656. iocbq->context2 = d_buf;
  10657. iocbq->context3 = NULL;
  10658. iocbq->iocb.ulpBdeCount = 1;
  10659. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10660. LPFC_DATA_BUF_SIZE;
  10661. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10662. bf_get(lpfc_rcqe_length,
  10663. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10664. iocbq->iocb.un.rcvels.remoteID = sid;
  10665. list_add_tail(&iocbq->list, &first_iocbq->list);
  10666. }
  10667. }
  10668. return first_iocbq;
  10669. }
  10670. static void
  10671. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10672. struct hbq_dmabuf *seq_dmabuf)
  10673. {
  10674. struct fc_frame_header *fc_hdr;
  10675. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10676. struct lpfc_hba *phba = vport->phba;
  10677. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10678. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10679. if (!iocbq) {
  10680. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10681. "2707 Ring %d handler: Failed to allocate "
  10682. "iocb Rctl x%x Type x%x received\n",
  10683. LPFC_ELS_RING,
  10684. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10685. return;
  10686. }
  10687. if (!lpfc_complete_unsol_iocb(phba,
  10688. &phba->sli.ring[LPFC_ELS_RING],
  10689. iocbq, fc_hdr->fh_r_ctl,
  10690. fc_hdr->fh_type))
  10691. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10692. "2540 Ring %d handler: unexpected Rctl "
  10693. "x%x Type x%x received\n",
  10694. LPFC_ELS_RING,
  10695. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10696. /* Free iocb created in lpfc_prep_seq */
  10697. list_for_each_entry_safe(curr_iocb, next_iocb,
  10698. &iocbq->list, list) {
  10699. list_del_init(&curr_iocb->list);
  10700. lpfc_sli_release_iocbq(phba, curr_iocb);
  10701. }
  10702. lpfc_sli_release_iocbq(phba, iocbq);
  10703. }
  10704. /**
  10705. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10706. * @phba: Pointer to HBA context object.
  10707. *
  10708. * This function is called with no lock held. This function processes all
  10709. * the received buffers and gives it to upper layers when a received buffer
  10710. * indicates that it is the final frame in the sequence. The interrupt
  10711. * service routine processes received buffers at interrupt contexts and adds
  10712. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10713. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10714. * appropriate receive function when the final frame in a sequence is received.
  10715. **/
  10716. void
  10717. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10718. struct hbq_dmabuf *dmabuf)
  10719. {
  10720. struct hbq_dmabuf *seq_dmabuf;
  10721. struct fc_frame_header *fc_hdr;
  10722. struct lpfc_vport *vport;
  10723. uint32_t fcfi;
  10724. /* Process each received buffer */
  10725. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10726. /* check to see if this a valid type of frame */
  10727. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10728. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10729. return;
  10730. }
  10731. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10732. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10733. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10734. /* throw out the frame */
  10735. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10736. return;
  10737. }
  10738. /* Handle the basic abort sequence (BA_ABTS) event */
  10739. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10740. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10741. return;
  10742. }
  10743. /* Link this frame */
  10744. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10745. if (!seq_dmabuf) {
  10746. /* unable to add frame to vport - throw it out */
  10747. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10748. return;
  10749. }
  10750. /* If not last frame in sequence continue processing frames. */
  10751. if (!lpfc_seq_complete(seq_dmabuf))
  10752. return;
  10753. /* Send the complete sequence to the upper layer protocol */
  10754. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10755. }
  10756. /**
  10757. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10758. * @phba: pointer to lpfc hba data structure.
  10759. *
  10760. * This routine is invoked to post rpi header templates to the
  10761. * HBA consistent with the SLI-4 interface spec. This routine
  10762. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10763. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10764. *
  10765. * This routine does not require any locks. It's usage is expected
  10766. * to be driver load or reset recovery when the driver is
  10767. * sequential.
  10768. *
  10769. * Return codes
  10770. * 0 - successful
  10771. * EIO - The mailbox failed to complete successfully.
  10772. * When this error occurs, the driver is not guaranteed
  10773. * to have any rpi regions posted to the device and
  10774. * must either attempt to repost the regions or take a
  10775. * fatal error.
  10776. **/
  10777. int
  10778. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10779. {
  10780. struct lpfc_rpi_hdr *rpi_page;
  10781. uint32_t rc = 0;
  10782. /* Post all rpi memory regions to the port. */
  10783. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10784. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10785. if (rc != MBX_SUCCESS) {
  10786. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10787. "2008 Error %d posting all rpi "
  10788. "headers\n", rc);
  10789. rc = -EIO;
  10790. break;
  10791. }
  10792. }
  10793. return rc;
  10794. }
  10795. /**
  10796. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10797. * @phba: pointer to lpfc hba data structure.
  10798. * @rpi_page: pointer to the rpi memory region.
  10799. *
  10800. * This routine is invoked to post a single rpi header to the
  10801. * HBA consistent with the SLI-4 interface spec. This memory region
  10802. * maps up to 64 rpi context regions.
  10803. *
  10804. * Return codes
  10805. * 0 - successful
  10806. * ENOMEM - No available memory
  10807. * EIO - The mailbox failed to complete successfully.
  10808. **/
  10809. int
  10810. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10811. {
  10812. LPFC_MBOXQ_t *mboxq;
  10813. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10814. uint32_t rc = 0;
  10815. uint32_t mbox_tmo;
  10816. uint32_t shdr_status, shdr_add_status;
  10817. union lpfc_sli4_cfg_shdr *shdr;
  10818. /* The port is notified of the header region via a mailbox command. */
  10819. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10820. if (!mboxq) {
  10821. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10822. "2001 Unable to allocate memory for issuing "
  10823. "SLI_CONFIG_SPECIAL mailbox command\n");
  10824. return -ENOMEM;
  10825. }
  10826. /* Post all rpi memory regions to the port. */
  10827. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10828. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10829. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10830. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10831. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10832. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10833. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10834. hdr_tmpl, rpi_page->page_count);
  10835. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10836. rpi_page->start_rpi);
  10837. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10838. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10839. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10840. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10841. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10842. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10843. if (rc != MBX_TIMEOUT)
  10844. mempool_free(mboxq, phba->mbox_mem_pool);
  10845. if (shdr_status || shdr_add_status || rc) {
  10846. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10847. "2514 POST_RPI_HDR mailbox failed with "
  10848. "status x%x add_status x%x, mbx status x%x\n",
  10849. shdr_status, shdr_add_status, rc);
  10850. rc = -ENXIO;
  10851. }
  10852. return rc;
  10853. }
  10854. /**
  10855. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10856. * @phba: pointer to lpfc hba data structure.
  10857. *
  10858. * This routine is invoked to post rpi header templates to the
  10859. * HBA consistent with the SLI-4 interface spec. This routine
  10860. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10861. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10862. *
  10863. * Returns
  10864. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10865. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10866. **/
  10867. int
  10868. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10869. {
  10870. int rpi;
  10871. uint16_t max_rpi, rpi_base, rpi_limit;
  10872. uint16_t rpi_remaining;
  10873. struct lpfc_rpi_hdr *rpi_hdr;
  10874. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10875. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10876. rpi_limit = phba->sli4_hba.next_rpi;
  10877. /*
  10878. * The valid rpi range is not guaranteed to be zero-based. Start
  10879. * the search at the rpi_base as reported by the port.
  10880. */
  10881. spin_lock_irq(&phba->hbalock);
  10882. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10883. if (rpi >= rpi_limit || rpi < rpi_base)
  10884. rpi = LPFC_RPI_ALLOC_ERROR;
  10885. else {
  10886. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10887. phba->sli4_hba.max_cfg_param.rpi_used++;
  10888. phba->sli4_hba.rpi_count++;
  10889. }
  10890. /*
  10891. * Don't try to allocate more rpi header regions if the device limit
  10892. * on available rpis max has been exhausted.
  10893. */
  10894. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10895. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10896. spin_unlock_irq(&phba->hbalock);
  10897. return rpi;
  10898. }
  10899. /*
  10900. * If the driver is running low on rpi resources, allocate another
  10901. * page now. Note that the next_rpi value is used because
  10902. * it represents how many are actually in use whereas max_rpi notes
  10903. * how many are supported max by the device.
  10904. */
  10905. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10906. phba->sli4_hba.rpi_count;
  10907. spin_unlock_irq(&phba->hbalock);
  10908. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10909. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10910. if (!rpi_hdr) {
  10911. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10912. "2002 Error Could not grow rpi "
  10913. "count\n");
  10914. } else {
  10915. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10916. }
  10917. }
  10918. return rpi;
  10919. }
  10920. /**
  10921. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10922. * @phba: pointer to lpfc hba data structure.
  10923. *
  10924. * This routine is invoked to release an rpi to the pool of
  10925. * available rpis maintained by the driver.
  10926. **/
  10927. void
  10928. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10929. {
  10930. spin_lock_irq(&phba->hbalock);
  10931. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10932. phba->sli4_hba.rpi_count--;
  10933. phba->sli4_hba.max_cfg_param.rpi_used--;
  10934. spin_unlock_irq(&phba->hbalock);
  10935. }
  10936. /**
  10937. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10938. * @phba: pointer to lpfc hba data structure.
  10939. *
  10940. * This routine is invoked to remove the memory region that
  10941. * provided rpi via a bitmask.
  10942. **/
  10943. void
  10944. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10945. {
  10946. kfree(phba->sli4_hba.rpi_bmask);
  10947. }
  10948. /**
  10949. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10950. * @phba: pointer to lpfc hba data structure.
  10951. *
  10952. * This routine is invoked to remove the memory region that
  10953. * provided rpi via a bitmask.
  10954. **/
  10955. int
  10956. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10957. {
  10958. LPFC_MBOXQ_t *mboxq;
  10959. struct lpfc_hba *phba = ndlp->phba;
  10960. int rc;
  10961. /* The port is notified of the header region via a mailbox command. */
  10962. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10963. if (!mboxq)
  10964. return -ENOMEM;
  10965. /* Post all rpi memory regions to the port. */
  10966. lpfc_resume_rpi(mboxq, ndlp);
  10967. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10968. if (rc == MBX_NOT_FINISHED) {
  10969. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10970. "2010 Resume RPI Mailbox failed "
  10971. "status %d, mbxStatus x%x\n", rc,
  10972. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10973. mempool_free(mboxq, phba->mbox_mem_pool);
  10974. return -EIO;
  10975. }
  10976. return 0;
  10977. }
  10978. /**
  10979. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10980. * @phba: pointer to lpfc hba data structure.
  10981. * @vpi: vpi value to activate with the port.
  10982. *
  10983. * This routine is invoked to activate a vpi with the
  10984. * port when the host intends to use vports with a
  10985. * nonzero vpi.
  10986. *
  10987. * Returns:
  10988. * 0 success
  10989. * -Evalue otherwise
  10990. **/
  10991. int
  10992. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10993. {
  10994. LPFC_MBOXQ_t *mboxq;
  10995. int rc = 0;
  10996. int retval = MBX_SUCCESS;
  10997. uint32_t mbox_tmo;
  10998. if (vpi == 0)
  10999. return -EINVAL;
  11000. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11001. if (!mboxq)
  11002. return -ENOMEM;
  11003. lpfc_init_vpi(phba, mboxq, vpi);
  11004. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11005. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11006. if (rc != MBX_SUCCESS) {
  11007. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11008. "2022 INIT VPI Mailbox failed "
  11009. "status %d, mbxStatus x%x\n", rc,
  11010. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11011. retval = -EIO;
  11012. }
  11013. if (rc != MBX_TIMEOUT)
  11014. mempool_free(mboxq, phba->mbox_mem_pool);
  11015. return retval;
  11016. }
  11017. /**
  11018. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11019. * @phba: pointer to lpfc hba data structure.
  11020. * @mboxq: Pointer to mailbox object.
  11021. *
  11022. * This routine is invoked to manually add a single FCF record. The caller
  11023. * must pass a completely initialized FCF_Record. This routine takes
  11024. * care of the nonembedded mailbox operations.
  11025. **/
  11026. static void
  11027. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11028. {
  11029. void *virt_addr;
  11030. union lpfc_sli4_cfg_shdr *shdr;
  11031. uint32_t shdr_status, shdr_add_status;
  11032. virt_addr = mboxq->sge_array->addr[0];
  11033. /* The IOCTL status is embedded in the mailbox subheader. */
  11034. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11035. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11036. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11037. if ((shdr_status || shdr_add_status) &&
  11038. (shdr_status != STATUS_FCF_IN_USE))
  11039. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11040. "2558 ADD_FCF_RECORD mailbox failed with "
  11041. "status x%x add_status x%x\n",
  11042. shdr_status, shdr_add_status);
  11043. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11044. }
  11045. /**
  11046. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11047. * @phba: pointer to lpfc hba data structure.
  11048. * @fcf_record: pointer to the initialized fcf record to add.
  11049. *
  11050. * This routine is invoked to manually add a single FCF record. The caller
  11051. * must pass a completely initialized FCF_Record. This routine takes
  11052. * care of the nonembedded mailbox operations.
  11053. **/
  11054. int
  11055. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11056. {
  11057. int rc = 0;
  11058. LPFC_MBOXQ_t *mboxq;
  11059. uint8_t *bytep;
  11060. void *virt_addr;
  11061. dma_addr_t phys_addr;
  11062. struct lpfc_mbx_sge sge;
  11063. uint32_t alloc_len, req_len;
  11064. uint32_t fcfindex;
  11065. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11066. if (!mboxq) {
  11067. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11068. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11069. return -ENOMEM;
  11070. }
  11071. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11072. sizeof(uint32_t);
  11073. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11074. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11075. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11076. req_len, LPFC_SLI4_MBX_NEMBED);
  11077. if (alloc_len < req_len) {
  11078. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11079. "2523 Allocated DMA memory size (x%x) is "
  11080. "less than the requested DMA memory "
  11081. "size (x%x)\n", alloc_len, req_len);
  11082. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11083. return -ENOMEM;
  11084. }
  11085. /*
  11086. * Get the first SGE entry from the non-embedded DMA memory. This
  11087. * routine only uses a single SGE.
  11088. */
  11089. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11090. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11091. virt_addr = mboxq->sge_array->addr[0];
  11092. /*
  11093. * Configure the FCF record for FCFI 0. This is the driver's
  11094. * hardcoded default and gets used in nonFIP mode.
  11095. */
  11096. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11097. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11098. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11099. /*
  11100. * Copy the fcf_index and the FCF Record Data. The data starts after
  11101. * the FCoE header plus word10. The data copy needs to be endian
  11102. * correct.
  11103. */
  11104. bytep += sizeof(uint32_t);
  11105. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11106. mboxq->vport = phba->pport;
  11107. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11108. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11109. if (rc == MBX_NOT_FINISHED) {
  11110. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11111. "2515 ADD_FCF_RECORD mailbox failed with "
  11112. "status 0x%x\n", rc);
  11113. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11114. rc = -EIO;
  11115. } else
  11116. rc = 0;
  11117. return rc;
  11118. }
  11119. /**
  11120. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11121. * @phba: pointer to lpfc hba data structure.
  11122. * @fcf_record: pointer to the fcf record to write the default data.
  11123. * @fcf_index: FCF table entry index.
  11124. *
  11125. * This routine is invoked to build the driver's default FCF record. The
  11126. * values used are hardcoded. This routine handles memory initialization.
  11127. *
  11128. **/
  11129. void
  11130. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11131. struct fcf_record *fcf_record,
  11132. uint16_t fcf_index)
  11133. {
  11134. memset(fcf_record, 0, sizeof(struct fcf_record));
  11135. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11136. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11137. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11138. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11139. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11140. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11141. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11142. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11143. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11144. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11145. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11146. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11147. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11148. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11149. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11150. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11151. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11152. /* Set the VLAN bit map */
  11153. if (phba->valid_vlan) {
  11154. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11155. = 1 << (phba->vlan_id % 8);
  11156. }
  11157. }
  11158. /**
  11159. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11160. * @phba: pointer to lpfc hba data structure.
  11161. * @fcf_index: FCF table entry offset.
  11162. *
  11163. * This routine is invoked to scan the entire FCF table by reading FCF
  11164. * record and processing it one at a time starting from the @fcf_index
  11165. * for initial FCF discovery or fast FCF failover rediscovery.
  11166. *
  11167. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11168. * otherwise.
  11169. **/
  11170. int
  11171. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11172. {
  11173. int rc = 0, error;
  11174. LPFC_MBOXQ_t *mboxq;
  11175. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11176. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11177. if (!mboxq) {
  11178. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11179. "2000 Failed to allocate mbox for "
  11180. "READ_FCF cmd\n");
  11181. error = -ENOMEM;
  11182. goto fail_fcf_scan;
  11183. }
  11184. /* Construct the read FCF record mailbox command */
  11185. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11186. if (rc) {
  11187. error = -EINVAL;
  11188. goto fail_fcf_scan;
  11189. }
  11190. /* Issue the mailbox command asynchronously */
  11191. mboxq->vport = phba->pport;
  11192. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11193. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11194. if (rc == MBX_NOT_FINISHED)
  11195. error = -EIO;
  11196. else {
  11197. spin_lock_irq(&phba->hbalock);
  11198. phba->hba_flag |= FCF_DISC_INPROGRESS;
  11199. spin_unlock_irq(&phba->hbalock);
  11200. /* Reset FCF round robin index bmask for new scan */
  11201. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) {
  11202. memset(phba->fcf.fcf_rr_bmask, 0,
  11203. sizeof(*phba->fcf.fcf_rr_bmask));
  11204. phba->fcf.eligible_fcf_cnt = 0;
  11205. }
  11206. error = 0;
  11207. }
  11208. fail_fcf_scan:
  11209. if (error) {
  11210. if (mboxq)
  11211. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11212. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  11213. spin_lock_irq(&phba->hbalock);
  11214. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  11215. spin_unlock_irq(&phba->hbalock);
  11216. }
  11217. return error;
  11218. }
  11219. /**
  11220. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf.
  11221. * @phba: pointer to lpfc hba data structure.
  11222. * @fcf_index: FCF table entry offset.
  11223. *
  11224. * This routine is invoked to read an FCF record indicated by @fcf_index
  11225. * and to use it for FLOGI round robin FCF failover.
  11226. *
  11227. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11228. * otherwise.
  11229. **/
  11230. int
  11231. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11232. {
  11233. int rc = 0, error;
  11234. LPFC_MBOXQ_t *mboxq;
  11235. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11236. if (!mboxq) {
  11237. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11238. "2763 Failed to allocate mbox for "
  11239. "READ_FCF cmd\n");
  11240. error = -ENOMEM;
  11241. goto fail_fcf_read;
  11242. }
  11243. /* Construct the read FCF record mailbox command */
  11244. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11245. if (rc) {
  11246. error = -EINVAL;
  11247. goto fail_fcf_read;
  11248. }
  11249. /* Issue the mailbox command asynchronously */
  11250. mboxq->vport = phba->pport;
  11251. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11252. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11253. if (rc == MBX_NOT_FINISHED)
  11254. error = -EIO;
  11255. else
  11256. error = 0;
  11257. fail_fcf_read:
  11258. if (error && mboxq)
  11259. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11260. return error;
  11261. }
  11262. /**
  11263. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11264. * @phba: pointer to lpfc hba data structure.
  11265. * @fcf_index: FCF table entry offset.
  11266. *
  11267. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11268. * determine whether it's eligible for FLOGI round robin failover list.
  11269. *
  11270. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11271. * otherwise.
  11272. **/
  11273. int
  11274. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11275. {
  11276. int rc = 0, error;
  11277. LPFC_MBOXQ_t *mboxq;
  11278. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11279. if (!mboxq) {
  11280. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11281. "2758 Failed to allocate mbox for "
  11282. "READ_FCF cmd\n");
  11283. error = -ENOMEM;
  11284. goto fail_fcf_read;
  11285. }
  11286. /* Construct the read FCF record mailbox command */
  11287. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11288. if (rc) {
  11289. error = -EINVAL;
  11290. goto fail_fcf_read;
  11291. }
  11292. /* Issue the mailbox command asynchronously */
  11293. mboxq->vport = phba->pport;
  11294. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11295. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11296. if (rc == MBX_NOT_FINISHED)
  11297. error = -EIO;
  11298. else
  11299. error = 0;
  11300. fail_fcf_read:
  11301. if (error && mboxq)
  11302. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11303. return error;
  11304. }
  11305. /**
  11306. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11307. * @phba: pointer to lpfc hba data structure.
  11308. *
  11309. * This routine is to get the next eligible FCF record index in a round
  11310. * robin fashion. If the next eligible FCF record index equals to the
  11311. * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11312. * shall be returned, otherwise, the next eligible FCF record's index
  11313. * shall be returned.
  11314. **/
  11315. uint16_t
  11316. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11317. {
  11318. uint16_t next_fcf_index;
  11319. /* Search from the currently registered FCF index */
  11320. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11321. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11322. phba->fcf.current_rec.fcf_indx);
  11323. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11324. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11325. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11326. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11327. /* Round robin failover stop condition */
  11328. if (next_fcf_index == phba->fcf.fcf_rr_init_indx)
  11329. return LPFC_FCOE_FCF_NEXT_NONE;
  11330. return next_fcf_index;
  11331. }
  11332. /**
  11333. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11334. * @phba: pointer to lpfc hba data structure.
  11335. *
  11336. * This routine sets the FCF record index in to the eligible bmask for
  11337. * round robin failover search. It checks to make sure that the index
  11338. * does not go beyond the range of the driver allocated bmask dimension
  11339. * before setting the bit.
  11340. *
  11341. * Returns 0 if the index bit successfully set, otherwise, it returns
  11342. * -EINVAL.
  11343. **/
  11344. int
  11345. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11346. {
  11347. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11348. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11349. "2610 HBA FCF index reached driver's "
  11350. "book keeping dimension: fcf_index:%d, "
  11351. "driver_bmask_max:%d\n",
  11352. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11353. return -EINVAL;
  11354. }
  11355. /* Set the eligible FCF record index bmask */
  11356. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11357. return 0;
  11358. }
  11359. /**
  11360. * lpfc_sli4_fcf_rr_index_set - Clear bmask from eligible fcf record index
  11361. * @phba: pointer to lpfc hba data structure.
  11362. *
  11363. * This routine clears the FCF record index from the eligible bmask for
  11364. * round robin failover search. It checks to make sure that the index
  11365. * does not go beyond the range of the driver allocated bmask dimension
  11366. * before clearing the bit.
  11367. **/
  11368. void
  11369. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11370. {
  11371. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11372. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11373. "2762 HBA FCF index goes beyond driver's "
  11374. "book keeping dimension: fcf_index:%d, "
  11375. "driver_bmask_max:%d\n",
  11376. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11377. return;
  11378. }
  11379. /* Clear the eligible FCF record index bmask */
  11380. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11381. }
  11382. /**
  11383. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11384. * @phba: pointer to lpfc hba data structure.
  11385. *
  11386. * This routine is the completion routine for the rediscover FCF table mailbox
  11387. * command. If the mailbox command returned failure, it will try to stop the
  11388. * FCF rediscover wait timer.
  11389. **/
  11390. void
  11391. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11392. {
  11393. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11394. uint32_t shdr_status, shdr_add_status;
  11395. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11396. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11397. &redisc_fcf->header.cfg_shdr.response);
  11398. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11399. &redisc_fcf->header.cfg_shdr.response);
  11400. if (shdr_status || shdr_add_status) {
  11401. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11402. "2746 Requesting for FCF rediscovery failed "
  11403. "status x%x add_status x%x\n",
  11404. shdr_status, shdr_add_status);
  11405. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11406. spin_lock_irq(&phba->hbalock);
  11407. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11408. spin_unlock_irq(&phba->hbalock);
  11409. /*
  11410. * CVL event triggered FCF rediscover request failed,
  11411. * last resort to re-try current registered FCF entry.
  11412. */
  11413. lpfc_retry_pport_discovery(phba);
  11414. } else {
  11415. spin_lock_irq(&phba->hbalock);
  11416. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11417. spin_unlock_irq(&phba->hbalock);
  11418. /*
  11419. * DEAD FCF event triggered FCF rediscover request
  11420. * failed, last resort to fail over as a link down
  11421. * to FCF registration.
  11422. */
  11423. lpfc_sli4_fcf_dead_failthrough(phba);
  11424. }
  11425. } else {
  11426. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11427. "2775 Start FCF rediscovery quiescent period "
  11428. "wait timer before scaning FCF table\n");
  11429. /*
  11430. * Start FCF rediscovery wait timer for pending FCF
  11431. * before rescan FCF record table.
  11432. */
  11433. lpfc_fcf_redisc_wait_start_timer(phba);
  11434. }
  11435. mempool_free(mbox, phba->mbox_mem_pool);
  11436. }
  11437. /**
  11438. * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
  11439. * @phba: pointer to lpfc hba data structure.
  11440. *
  11441. * This routine is invoked to request for rediscovery of the entire FCF table
  11442. * by the port.
  11443. **/
  11444. int
  11445. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11446. {
  11447. LPFC_MBOXQ_t *mbox;
  11448. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11449. int rc, length;
  11450. /* Cancel retry delay timers to all vports before FCF rediscover */
  11451. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11452. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11453. if (!mbox) {
  11454. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11455. "2745 Failed to allocate mbox for "
  11456. "requesting FCF rediscover.\n");
  11457. return -ENOMEM;
  11458. }
  11459. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11460. sizeof(struct lpfc_sli4_cfg_mhdr));
  11461. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11462. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11463. length, LPFC_SLI4_MBX_EMBED);
  11464. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11465. /* Set count to 0 for invalidating the entire FCF database */
  11466. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11467. /* Issue the mailbox command asynchronously */
  11468. mbox->vport = phba->pport;
  11469. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11470. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11471. if (rc == MBX_NOT_FINISHED) {
  11472. mempool_free(mbox, phba->mbox_mem_pool);
  11473. return -EIO;
  11474. }
  11475. return 0;
  11476. }
  11477. /**
  11478. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  11479. * @phba: pointer to lpfc hba data structure.
  11480. *
  11481. * This function is the failover routine as a last resort to the FCF DEAD
  11482. * event when driver failed to perform fast FCF failover.
  11483. **/
  11484. void
  11485. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  11486. {
  11487. uint32_t link_state;
  11488. /*
  11489. * Last resort as FCF DEAD event failover will treat this as
  11490. * a link down, but save the link state because we don't want
  11491. * it to be changed to Link Down unless it is already down.
  11492. */
  11493. link_state = phba->link_state;
  11494. lpfc_linkdown(phba);
  11495. phba->link_state = link_state;
  11496. /* Unregister FCF if no devices connected to it */
  11497. lpfc_unregister_unused_fcf(phba);
  11498. }
  11499. /**
  11500. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11501. * @phba: pointer to lpfc hba data structure.
  11502. *
  11503. * This function read region 23 and parse TLV for port status to
  11504. * decide if the user disaled the port. If the TLV indicates the
  11505. * port is disabled, the hba_flag is set accordingly.
  11506. **/
  11507. void
  11508. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11509. {
  11510. LPFC_MBOXQ_t *pmb = NULL;
  11511. MAILBOX_t *mb;
  11512. uint8_t *rgn23_data = NULL;
  11513. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11514. int rc;
  11515. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11516. if (!pmb) {
  11517. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11518. "2600 lpfc_sli_read_serdes_param failed to"
  11519. " allocate mailbox memory\n");
  11520. goto out;
  11521. }
  11522. mb = &pmb->u.mb;
  11523. /* Get adapter Region 23 data */
  11524. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11525. if (!rgn23_data)
  11526. goto out;
  11527. do {
  11528. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11529. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11530. if (rc != MBX_SUCCESS) {
  11531. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11532. "2601 lpfc_sli_read_link_ste failed to"
  11533. " read config region 23 rc 0x%x Status 0x%x\n",
  11534. rc, mb->mbxStatus);
  11535. mb->un.varDmp.word_cnt = 0;
  11536. }
  11537. /*
  11538. * dump mem may return a zero when finished or we got a
  11539. * mailbox error, either way we are done.
  11540. */
  11541. if (mb->un.varDmp.word_cnt == 0)
  11542. break;
  11543. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11544. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11545. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11546. rgn23_data + offset,
  11547. mb->un.varDmp.word_cnt);
  11548. offset += mb->un.varDmp.word_cnt;
  11549. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11550. data_size = offset;
  11551. offset = 0;
  11552. if (!data_size)
  11553. goto out;
  11554. /* Check the region signature first */
  11555. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11556. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11557. "2619 Config region 23 has bad signature\n");
  11558. goto out;
  11559. }
  11560. offset += 4;
  11561. /* Check the data structure version */
  11562. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11563. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11564. "2620 Config region 23 has bad version\n");
  11565. goto out;
  11566. }
  11567. offset += 4;
  11568. /* Parse TLV entries in the region */
  11569. while (offset < data_size) {
  11570. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11571. break;
  11572. /*
  11573. * If the TLV is not driver specific TLV or driver id is
  11574. * not linux driver id, skip the record.
  11575. */
  11576. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11577. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11578. (rgn23_data[offset + 3] != 0)) {
  11579. offset += rgn23_data[offset + 1] * 4 + 4;
  11580. continue;
  11581. }
  11582. /* Driver found a driver specific TLV in the config region */
  11583. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11584. offset += 4;
  11585. tlv_offset = 0;
  11586. /*
  11587. * Search for configured port state sub-TLV.
  11588. */
  11589. while ((offset < data_size) &&
  11590. (tlv_offset < sub_tlv_len)) {
  11591. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11592. offset += 4;
  11593. tlv_offset += 4;
  11594. break;
  11595. }
  11596. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11597. offset += rgn23_data[offset + 1] * 4 + 4;
  11598. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11599. continue;
  11600. }
  11601. /* This HBA contains PORT_STE configured */
  11602. if (!rgn23_data[offset + 2])
  11603. phba->hba_flag |= LINK_DISABLED;
  11604. goto out;
  11605. }
  11606. }
  11607. out:
  11608. if (pmb)
  11609. mempool_free(pmb, phba->mbox_mem_pool);
  11610. kfree(rgn23_data);
  11611. return;
  11612. }
  11613. /**
  11614. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11615. * @vport: pointer to vport data structure.
  11616. *
  11617. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11618. * and REG_VPI mailbox commands associated with the vport. This function
  11619. * is called when driver want to restart discovery of the vport due to
  11620. * a Clear Virtual Link event.
  11621. **/
  11622. void
  11623. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11624. {
  11625. struct lpfc_hba *phba = vport->phba;
  11626. LPFC_MBOXQ_t *mb, *nextmb;
  11627. struct lpfc_dmabuf *mp;
  11628. struct lpfc_nodelist *ndlp;
  11629. spin_lock_irq(&phba->hbalock);
  11630. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11631. if (mb->vport != vport)
  11632. continue;
  11633. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11634. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11635. continue;
  11636. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11637. mp = (struct lpfc_dmabuf *) (mb->context1);
  11638. if (mp) {
  11639. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11640. kfree(mp);
  11641. }
  11642. ndlp = (struct lpfc_nodelist *) mb->context2;
  11643. if (ndlp) {
  11644. lpfc_nlp_put(ndlp);
  11645. mb->context2 = NULL;
  11646. }
  11647. }
  11648. list_del(&mb->list);
  11649. mempool_free(mb, phba->mbox_mem_pool);
  11650. }
  11651. mb = phba->sli.mbox_active;
  11652. if (mb && (mb->vport == vport)) {
  11653. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11654. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11655. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11656. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11657. ndlp = (struct lpfc_nodelist *) mb->context2;
  11658. if (ndlp) {
  11659. lpfc_nlp_put(ndlp);
  11660. mb->context2 = NULL;
  11661. }
  11662. /* Unregister the RPI when mailbox complete */
  11663. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  11664. }
  11665. }
  11666. spin_unlock_irq(&phba->hbalock);
  11667. }
  11668. /**
  11669. * lpfc_drain_txq - Drain the txq
  11670. * @phba: Pointer to HBA context object.
  11671. *
  11672. * This function attempt to submit IOCBs on the txq
  11673. * to the adapter. For SLI4 adapters, the txq contains
  11674. * ELS IOCBs that have been deferred because the there
  11675. * are no SGLs. This congestion can occur with large
  11676. * vport counts during node discovery.
  11677. **/
  11678. uint32_t
  11679. lpfc_drain_txq(struct lpfc_hba *phba)
  11680. {
  11681. LIST_HEAD(completions);
  11682. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  11683. struct lpfc_iocbq *piocbq = 0;
  11684. unsigned long iflags = 0;
  11685. char *fail_msg = NULL;
  11686. struct lpfc_sglq *sglq;
  11687. union lpfc_wqe wqe;
  11688. spin_lock_irqsave(&phba->hbalock, iflags);
  11689. if (pring->txq_cnt > pring->txq_max)
  11690. pring->txq_max = pring->txq_cnt;
  11691. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11692. while (pring->txq_cnt) {
  11693. spin_lock_irqsave(&phba->hbalock, iflags);
  11694. sglq = __lpfc_sli_get_sglq(phba);
  11695. if (!sglq) {
  11696. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11697. break;
  11698. } else {
  11699. piocbq = lpfc_sli_ringtx_get(phba, pring);
  11700. if (!piocbq) {
  11701. /* The txq_cnt out of sync. This should
  11702. * never happen
  11703. */
  11704. sglq = __lpfc_clear_active_sglq(phba,
  11705. sglq->sli4_xritag);
  11706. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11707. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11708. "2823 txq empty and txq_cnt is %d\n ",
  11709. pring->txq_cnt);
  11710. break;
  11711. }
  11712. }
  11713. /* The xri and iocb resources secured,
  11714. * attempt to issue request
  11715. */
  11716. piocbq->sli4_xritag = sglq->sli4_xritag;
  11717. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  11718. fail_msg = "to convert bpl to sgl";
  11719. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  11720. fail_msg = "to convert iocb to wqe";
  11721. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  11722. fail_msg = " - Wq is full";
  11723. else
  11724. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  11725. if (fail_msg) {
  11726. /* Failed means we can't issue and need to cancel */
  11727. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11728. "2822 IOCB failed %s iotag 0x%x "
  11729. "xri 0x%x\n",
  11730. fail_msg,
  11731. piocbq->iotag, piocbq->sli4_xritag);
  11732. list_add_tail(&piocbq->list, &completions);
  11733. }
  11734. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11735. }
  11736. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  11737. phba->pport->work_port_events &= ~WORKER_SERVICE_TXQ;
  11738. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  11739. /* Cancel all the IOCBs that cannot be issued */
  11740. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  11741. IOERR_SLI_ABORTED);
  11742. return pring->txq_cnt;
  11743. }