lpfc_sli.c 386 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540
  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(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(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(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(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. return iocbq;
  419. }
  420. /**
  421. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  422. * @phba: Pointer to HBA context object.
  423. * @xritag: XRI value.
  424. *
  425. * This function clears the sglq pointer from the array of acive
  426. * sglq's. The xritag that is passed in is used to index into the
  427. * array. Before the xritag can be used it needs to be adjusted
  428. * by subtracting the xribase.
  429. *
  430. * Returns sglq ponter = success, NULL = Failure.
  431. **/
  432. static struct lpfc_sglq *
  433. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  434. {
  435. uint16_t adj_xri;
  436. struct lpfc_sglq *sglq;
  437. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  438. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  439. return NULL;
  440. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  441. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  442. return sglq;
  443. }
  444. /**
  445. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  446. * @phba: Pointer to HBA context object.
  447. * @xritag: XRI value.
  448. *
  449. * This function returns the sglq pointer from the array of acive
  450. * sglq's. The xritag that is passed in is used to index into the
  451. * array. Before the xritag can be used it needs to be adjusted
  452. * by subtracting the xribase.
  453. *
  454. * Returns sglq ponter = success, NULL = Failure.
  455. **/
  456. struct lpfc_sglq *
  457. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  458. {
  459. uint16_t adj_xri;
  460. struct lpfc_sglq *sglq;
  461. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  462. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  463. return NULL;
  464. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  465. return sglq;
  466. }
  467. /**
  468. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  469. * @phba: Pointer to HBA context object.
  470. *
  471. * This function is called with hbalock held. This function
  472. * Gets a new driver sglq object from the sglq list. If the
  473. * list is not empty then it is successful, it returns pointer to the newly
  474. * allocated sglq object else it returns NULL.
  475. **/
  476. static struct lpfc_sglq *
  477. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  478. {
  479. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  480. struct lpfc_sglq *sglq = NULL;
  481. uint16_t adj_xri;
  482. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  483. if (!sglq)
  484. return NULL;
  485. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  486. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  487. sglq->state = SGL_ALLOCATED;
  488. return sglq;
  489. }
  490. /**
  491. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  492. * @phba: Pointer to HBA context object.
  493. *
  494. * This function is called with no lock held. This function
  495. * allocates a new driver iocb object from the iocb pool. If the
  496. * allocation is successful, it returns pointer to the newly
  497. * allocated iocb object else it returns NULL.
  498. **/
  499. struct lpfc_iocbq *
  500. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  501. {
  502. struct lpfc_iocbq * iocbq = NULL;
  503. unsigned long iflags;
  504. spin_lock_irqsave(&phba->hbalock, iflags);
  505. iocbq = __lpfc_sli_get_iocbq(phba);
  506. spin_unlock_irqrestore(&phba->hbalock, iflags);
  507. return iocbq;
  508. }
  509. /**
  510. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  511. * @phba: Pointer to HBA context object.
  512. * @iocbq: Pointer to driver iocb object.
  513. *
  514. * This function is called with hbalock held to release driver
  515. * iocb object to the iocb pool. The iotag in the iocb object
  516. * does not change for each use of the iocb object. This function
  517. * clears all other fields of the iocb object when it is freed.
  518. * The sqlq structure that holds the xritag and phys and virtual
  519. * mappings for the scatter gather list is retrieved from the
  520. * active array of sglq. The get of the sglq pointer also clears
  521. * the entry in the array. If the status of the IO indiactes that
  522. * this IO was aborted then the sglq entry it put on the
  523. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  524. * IO has good status or fails for any other reason then the sglq
  525. * entry is added to the free list (lpfc_sgl_list).
  526. **/
  527. static void
  528. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  529. {
  530. struct lpfc_sglq *sglq;
  531. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  532. unsigned long iflag;
  533. if (iocbq->sli4_xritag == NO_XRI)
  534. sglq = NULL;
  535. else
  536. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  537. if (sglq) {
  538. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  539. (sglq->state != SGL_XRI_ABORTED)) {
  540. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  541. iflag);
  542. list_add(&sglq->list,
  543. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  544. spin_unlock_irqrestore(
  545. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  546. } else {
  547. sglq->state = SGL_FREED;
  548. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  549. }
  550. }
  551. /*
  552. * Clean all volatile data fields, preserve iotag and node struct.
  553. */
  554. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  555. iocbq->sli4_xritag = NO_XRI;
  556. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  557. }
  558. /**
  559. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  560. * @phba: Pointer to HBA context object.
  561. * @iocbq: Pointer to driver iocb object.
  562. *
  563. * This function is called with hbalock held to release driver
  564. * iocb object to the iocb pool. The iotag in the iocb object
  565. * does not change for each use of the iocb object. This function
  566. * clears all other fields of the iocb object when it is freed.
  567. **/
  568. static void
  569. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  570. {
  571. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  572. /*
  573. * Clean all volatile data fields, preserve iotag and node struct.
  574. */
  575. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  576. iocbq->sli4_xritag = NO_XRI;
  577. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  578. }
  579. /**
  580. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  581. * @phba: Pointer to HBA context object.
  582. * @iocbq: Pointer to driver iocb object.
  583. *
  584. * This function is called with hbalock held to release driver
  585. * iocb object to the iocb pool. The iotag in the iocb object
  586. * does not change for each use of the iocb object. This function
  587. * clears all other fields of the iocb object when it is freed.
  588. **/
  589. static void
  590. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  591. {
  592. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  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 no lock held to release the iocb to
  600. * iocb pool.
  601. **/
  602. void
  603. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  604. {
  605. unsigned long iflags;
  606. /*
  607. * Clean all volatile data fields, preserve iotag and node struct.
  608. */
  609. spin_lock_irqsave(&phba->hbalock, iflags);
  610. __lpfc_sli_release_iocbq(phba, iocbq);
  611. spin_unlock_irqrestore(&phba->hbalock, iflags);
  612. }
  613. /**
  614. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  615. * @phba: Pointer to HBA context object.
  616. * @iocblist: List of IOCBs.
  617. * @ulpstatus: ULP status in IOCB command field.
  618. * @ulpWord4: ULP word-4 in IOCB command field.
  619. *
  620. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  621. * on the list by invoking the complete callback function associated with the
  622. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  623. * fields.
  624. **/
  625. void
  626. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  627. uint32_t ulpstatus, uint32_t ulpWord4)
  628. {
  629. struct lpfc_iocbq *piocb;
  630. while (!list_empty(iocblist)) {
  631. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  632. if (!piocb->iocb_cmpl)
  633. lpfc_sli_release_iocbq(phba, piocb);
  634. else {
  635. piocb->iocb.ulpStatus = ulpstatus;
  636. piocb->iocb.un.ulpWord[4] = ulpWord4;
  637. (piocb->iocb_cmpl) (phba, piocb, piocb);
  638. }
  639. }
  640. return;
  641. }
  642. /**
  643. * lpfc_sli_iocb_cmd_type - Get the iocb type
  644. * @iocb_cmnd: iocb command code.
  645. *
  646. * This function is called by ring event handler function to get the iocb type.
  647. * This function translates the iocb command to an iocb command type used to
  648. * decide the final disposition of each completed IOCB.
  649. * The function returns
  650. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  651. * LPFC_SOL_IOCB if it is a solicited iocb completion
  652. * LPFC_ABORT_IOCB if it is an abort iocb
  653. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  654. *
  655. * The caller is not required to hold any lock.
  656. **/
  657. static lpfc_iocb_type
  658. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  659. {
  660. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  661. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  662. return 0;
  663. switch (iocb_cmnd) {
  664. case CMD_XMIT_SEQUENCE_CR:
  665. case CMD_XMIT_SEQUENCE_CX:
  666. case CMD_XMIT_BCAST_CN:
  667. case CMD_XMIT_BCAST_CX:
  668. case CMD_ELS_REQUEST_CR:
  669. case CMD_ELS_REQUEST_CX:
  670. case CMD_CREATE_XRI_CR:
  671. case CMD_CREATE_XRI_CX:
  672. case CMD_GET_RPI_CN:
  673. case CMD_XMIT_ELS_RSP_CX:
  674. case CMD_GET_RPI_CR:
  675. case CMD_FCP_IWRITE_CR:
  676. case CMD_FCP_IWRITE_CX:
  677. case CMD_FCP_IREAD_CR:
  678. case CMD_FCP_IREAD_CX:
  679. case CMD_FCP_ICMND_CR:
  680. case CMD_FCP_ICMND_CX:
  681. case CMD_FCP_TSEND_CX:
  682. case CMD_FCP_TRSP_CX:
  683. case CMD_FCP_TRECEIVE_CX:
  684. case CMD_FCP_AUTO_TRSP_CX:
  685. case CMD_ADAPTER_MSG:
  686. case CMD_ADAPTER_DUMP:
  687. case CMD_XMIT_SEQUENCE64_CR:
  688. case CMD_XMIT_SEQUENCE64_CX:
  689. case CMD_XMIT_BCAST64_CN:
  690. case CMD_XMIT_BCAST64_CX:
  691. case CMD_ELS_REQUEST64_CR:
  692. case CMD_ELS_REQUEST64_CX:
  693. case CMD_FCP_IWRITE64_CR:
  694. case CMD_FCP_IWRITE64_CX:
  695. case CMD_FCP_IREAD64_CR:
  696. case CMD_FCP_IREAD64_CX:
  697. case CMD_FCP_ICMND64_CR:
  698. case CMD_FCP_ICMND64_CX:
  699. case CMD_FCP_TSEND64_CX:
  700. case CMD_FCP_TRSP64_CX:
  701. case CMD_FCP_TRECEIVE64_CX:
  702. case CMD_GEN_REQUEST64_CR:
  703. case CMD_GEN_REQUEST64_CX:
  704. case CMD_XMIT_ELS_RSP64_CX:
  705. case DSSCMD_IWRITE64_CR:
  706. case DSSCMD_IWRITE64_CX:
  707. case DSSCMD_IREAD64_CR:
  708. case DSSCMD_IREAD64_CX:
  709. type = LPFC_SOL_IOCB;
  710. break;
  711. case CMD_ABORT_XRI_CN:
  712. case CMD_ABORT_XRI_CX:
  713. case CMD_CLOSE_XRI_CN:
  714. case CMD_CLOSE_XRI_CX:
  715. case CMD_XRI_ABORTED_CX:
  716. case CMD_ABORT_MXRI64_CN:
  717. case CMD_XMIT_BLS_RSP64_CX:
  718. type = LPFC_ABORT_IOCB;
  719. break;
  720. case CMD_RCV_SEQUENCE_CX:
  721. case CMD_RCV_ELS_REQ_CX:
  722. case CMD_RCV_SEQUENCE64_CX:
  723. case CMD_RCV_ELS_REQ64_CX:
  724. case CMD_ASYNC_STATUS:
  725. case CMD_IOCB_RCV_SEQ64_CX:
  726. case CMD_IOCB_RCV_ELS64_CX:
  727. case CMD_IOCB_RCV_CONT64_CX:
  728. case CMD_IOCB_RET_XRI64_CX:
  729. type = LPFC_UNSOL_IOCB;
  730. break;
  731. case CMD_IOCB_XMIT_MSEQ64_CR:
  732. case CMD_IOCB_XMIT_MSEQ64_CX:
  733. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  734. case CMD_IOCB_RCV_ELS_LIST64_CX:
  735. case CMD_IOCB_CLOSE_EXTENDED_CN:
  736. case CMD_IOCB_ABORT_EXTENDED_CN:
  737. case CMD_IOCB_RET_HBQE64_CN:
  738. case CMD_IOCB_FCP_IBIDIR64_CR:
  739. case CMD_IOCB_FCP_IBIDIR64_CX:
  740. case CMD_IOCB_FCP_ITASKMGT64_CX:
  741. case CMD_IOCB_LOGENTRY_CN:
  742. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  743. printk("%s - Unhandled SLI-3 Command x%x\n",
  744. __func__, iocb_cmnd);
  745. type = LPFC_UNKNOWN_IOCB;
  746. break;
  747. default:
  748. type = LPFC_UNKNOWN_IOCB;
  749. break;
  750. }
  751. return type;
  752. }
  753. /**
  754. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  755. * @phba: Pointer to HBA context object.
  756. *
  757. * This function is called from SLI initialization code
  758. * to configure every ring of the HBA's SLI interface. The
  759. * caller is not required to hold any lock. This function issues
  760. * a config_ring mailbox command for each ring.
  761. * This function returns zero if successful else returns a negative
  762. * error code.
  763. **/
  764. static int
  765. lpfc_sli_ring_map(struct lpfc_hba *phba)
  766. {
  767. struct lpfc_sli *psli = &phba->sli;
  768. LPFC_MBOXQ_t *pmb;
  769. MAILBOX_t *pmbox;
  770. int i, rc, ret = 0;
  771. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  772. if (!pmb)
  773. return -ENOMEM;
  774. pmbox = &pmb->u.mb;
  775. phba->link_state = LPFC_INIT_MBX_CMDS;
  776. for (i = 0; i < psli->num_rings; i++) {
  777. lpfc_config_ring(phba, i, pmb);
  778. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  779. if (rc != MBX_SUCCESS) {
  780. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  781. "0446 Adapter failed to init (%d), "
  782. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  783. "ring %d\n",
  784. rc, pmbox->mbxCommand,
  785. pmbox->mbxStatus, i);
  786. phba->link_state = LPFC_HBA_ERROR;
  787. ret = -ENXIO;
  788. break;
  789. }
  790. }
  791. mempool_free(pmb, phba->mbox_mem_pool);
  792. return ret;
  793. }
  794. /**
  795. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  796. * @phba: Pointer to HBA context object.
  797. * @pring: Pointer to driver SLI ring object.
  798. * @piocb: Pointer to the driver iocb object.
  799. *
  800. * This function is called with hbalock held. The function adds the
  801. * new iocb to txcmplq of the given ring. This function always returns
  802. * 0. If this function is called for ELS ring, this function checks if
  803. * there is a vport associated with the ELS command. This function also
  804. * starts els_tmofunc timer if this is an ELS command.
  805. **/
  806. static int
  807. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  808. struct lpfc_iocbq *piocb)
  809. {
  810. list_add_tail(&piocb->list, &pring->txcmplq);
  811. pring->txcmplq_cnt++;
  812. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  813. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  814. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  815. if (!piocb->vport)
  816. BUG();
  817. else
  818. mod_timer(&piocb->vport->els_tmofunc,
  819. jiffies + HZ * (phba->fc_ratov << 1));
  820. }
  821. return 0;
  822. }
  823. /**
  824. * lpfc_sli_ringtx_get - Get first element of the txq
  825. * @phba: Pointer to HBA context object.
  826. * @pring: Pointer to driver SLI ring object.
  827. *
  828. * This function is called with hbalock held to get next
  829. * iocb in txq of the given ring. If there is any iocb in
  830. * the txq, the function returns first iocb in the list after
  831. * removing the iocb from the list, else it returns NULL.
  832. **/
  833. static struct lpfc_iocbq *
  834. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  835. {
  836. struct lpfc_iocbq *cmd_iocb;
  837. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  838. if (cmd_iocb != NULL)
  839. pring->txq_cnt--;
  840. return cmd_iocb;
  841. }
  842. /**
  843. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  844. * @phba: Pointer to HBA context object.
  845. * @pring: Pointer to driver SLI ring object.
  846. *
  847. * This function is called with hbalock held and the caller must post the
  848. * iocb without releasing the lock. If the caller releases the lock,
  849. * iocb slot returned by the function is not guaranteed to be available.
  850. * The function returns pointer to the next available iocb slot if there
  851. * is available slot in the ring, else it returns NULL.
  852. * If the get index of the ring is ahead of the put index, the function
  853. * will post an error attention event to the worker thread to take the
  854. * HBA to offline state.
  855. **/
  856. static IOCB_t *
  857. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  858. {
  859. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  860. uint32_t max_cmd_idx = pring->numCiocb;
  861. if ((pring->next_cmdidx == pring->cmdidx) &&
  862. (++pring->next_cmdidx >= max_cmd_idx))
  863. pring->next_cmdidx = 0;
  864. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  865. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  866. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  867. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  868. "0315 Ring %d issue: portCmdGet %d "
  869. "is bigger than cmd ring %d\n",
  870. pring->ringno,
  871. pring->local_getidx, max_cmd_idx);
  872. phba->link_state = LPFC_HBA_ERROR;
  873. /*
  874. * All error attention handlers are posted to
  875. * worker thread
  876. */
  877. phba->work_ha |= HA_ERATT;
  878. phba->work_hs = HS_FFER3;
  879. lpfc_worker_wake_up(phba);
  880. return NULL;
  881. }
  882. if (pring->local_getidx == pring->next_cmdidx)
  883. return NULL;
  884. }
  885. return lpfc_cmd_iocb(phba, pring);
  886. }
  887. /**
  888. * lpfc_sli_next_iotag - Get an iotag for the iocb
  889. * @phba: Pointer to HBA context object.
  890. * @iocbq: Pointer to driver iocb object.
  891. *
  892. * This function gets an iotag for the iocb. If there is no unused iotag and
  893. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  894. * array and assigns a new iotag.
  895. * The function returns the allocated iotag if successful, else returns zero.
  896. * Zero is not a valid iotag.
  897. * The caller is not required to hold any lock.
  898. **/
  899. uint16_t
  900. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  901. {
  902. struct lpfc_iocbq **new_arr;
  903. struct lpfc_iocbq **old_arr;
  904. size_t new_len;
  905. struct lpfc_sli *psli = &phba->sli;
  906. uint16_t iotag;
  907. spin_lock_irq(&phba->hbalock);
  908. iotag = psli->last_iotag;
  909. if(++iotag < psli->iocbq_lookup_len) {
  910. psli->last_iotag = iotag;
  911. psli->iocbq_lookup[iotag] = iocbq;
  912. spin_unlock_irq(&phba->hbalock);
  913. iocbq->iotag = iotag;
  914. return iotag;
  915. } else if (psli->iocbq_lookup_len < (0xffff
  916. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  917. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  918. spin_unlock_irq(&phba->hbalock);
  919. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  920. GFP_KERNEL);
  921. if (new_arr) {
  922. spin_lock_irq(&phba->hbalock);
  923. old_arr = psli->iocbq_lookup;
  924. if (new_len <= psli->iocbq_lookup_len) {
  925. /* highly unprobable case */
  926. kfree(new_arr);
  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. }
  935. spin_unlock_irq(&phba->hbalock);
  936. return 0;
  937. }
  938. if (psli->iocbq_lookup)
  939. memcpy(new_arr, old_arr,
  940. ((psli->last_iotag + 1) *
  941. sizeof (struct lpfc_iocbq *)));
  942. psli->iocbq_lookup = new_arr;
  943. psli->iocbq_lookup_len = new_len;
  944. psli->last_iotag = iotag;
  945. psli->iocbq_lookup[iotag] = iocbq;
  946. spin_unlock_irq(&phba->hbalock);
  947. iocbq->iotag = iotag;
  948. kfree(old_arr);
  949. return iotag;
  950. }
  951. } else
  952. spin_unlock_irq(&phba->hbalock);
  953. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  954. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  955. psli->last_iotag);
  956. return 0;
  957. }
  958. /**
  959. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  960. * @phba: Pointer to HBA context object.
  961. * @pring: Pointer to driver SLI ring object.
  962. * @iocb: Pointer to iocb slot in the ring.
  963. * @nextiocb: Pointer to driver iocb object which need to be
  964. * posted to firmware.
  965. *
  966. * This function is called with hbalock held to post a new iocb to
  967. * the firmware. This function copies the new iocb to ring iocb slot and
  968. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  969. * a completion call back for this iocb else the function will free the
  970. * iocb object.
  971. **/
  972. static void
  973. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  974. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  975. {
  976. /*
  977. * Set up an iotag
  978. */
  979. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  980. if (pring->ringno == LPFC_ELS_RING) {
  981. lpfc_debugfs_slow_ring_trc(phba,
  982. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  983. *(((uint32_t *) &nextiocb->iocb) + 4),
  984. *(((uint32_t *) &nextiocb->iocb) + 6),
  985. *(((uint32_t *) &nextiocb->iocb) + 7));
  986. }
  987. /*
  988. * Issue iocb command to adapter
  989. */
  990. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  991. wmb();
  992. pring->stats.iocb_cmd++;
  993. /*
  994. * If there is no completion routine to call, we can release the
  995. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  996. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  997. */
  998. if (nextiocb->iocb_cmpl)
  999. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1000. else
  1001. __lpfc_sli_release_iocbq(phba, nextiocb);
  1002. /*
  1003. * Let the HBA know what IOCB slot will be the next one the
  1004. * driver will put a command into.
  1005. */
  1006. pring->cmdidx = pring->next_cmdidx;
  1007. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1008. }
  1009. /**
  1010. * lpfc_sli_update_full_ring - Update the chip attention register
  1011. * @phba: Pointer to HBA context object.
  1012. * @pring: Pointer to driver SLI ring object.
  1013. *
  1014. * The caller is not required to hold any lock for calling this function.
  1015. * This function updates the chip attention bits for the ring to inform firmware
  1016. * that there are pending work to be done for this ring and requests an
  1017. * interrupt when there is space available in the ring. This function is
  1018. * called when the driver is unable to post more iocbs to the ring due
  1019. * to unavailability of space in the ring.
  1020. **/
  1021. static void
  1022. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1023. {
  1024. int ringno = pring->ringno;
  1025. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1026. wmb();
  1027. /*
  1028. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1029. * The HBA will tell us when an IOCB entry is available.
  1030. */
  1031. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1032. readl(phba->CAregaddr); /* flush */
  1033. pring->stats.iocb_cmd_full++;
  1034. }
  1035. /**
  1036. * lpfc_sli_update_ring - Update chip attention register
  1037. * @phba: Pointer to HBA context object.
  1038. * @pring: Pointer to driver SLI ring object.
  1039. *
  1040. * This function updates the chip attention register bit for the
  1041. * given ring to inform HBA that there is more work to be done
  1042. * in this ring. The caller is not required to hold any lock.
  1043. **/
  1044. static void
  1045. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1046. {
  1047. int ringno = pring->ringno;
  1048. /*
  1049. * Tell the HBA that there is work to do in this ring.
  1050. */
  1051. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1052. wmb();
  1053. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1054. readl(phba->CAregaddr); /* flush */
  1055. }
  1056. }
  1057. /**
  1058. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1059. * @phba: Pointer to HBA context object.
  1060. * @pring: Pointer to driver SLI ring object.
  1061. *
  1062. * This function is called with hbalock held to post pending iocbs
  1063. * in the txq to the firmware. This function is called when driver
  1064. * detects space available in the ring.
  1065. **/
  1066. static void
  1067. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1068. {
  1069. IOCB_t *iocb;
  1070. struct lpfc_iocbq *nextiocb;
  1071. /*
  1072. * Check to see if:
  1073. * (a) there is anything on the txq to send
  1074. * (b) link is up
  1075. * (c) link attention events can be processed (fcp ring only)
  1076. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1077. */
  1078. if (pring->txq_cnt &&
  1079. lpfc_is_link_up(phba) &&
  1080. (pring->ringno != phba->sli.fcp_ring ||
  1081. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1082. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1083. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1084. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1085. if (iocb)
  1086. lpfc_sli_update_ring(phba, pring);
  1087. else
  1088. lpfc_sli_update_full_ring(phba, pring);
  1089. }
  1090. return;
  1091. }
  1092. /**
  1093. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1094. * @phba: Pointer to HBA context object.
  1095. * @hbqno: HBQ number.
  1096. *
  1097. * This function is called with hbalock held to get the next
  1098. * available slot for the given HBQ. If there is free slot
  1099. * available for the HBQ it will return pointer to the next available
  1100. * HBQ entry else it will return NULL.
  1101. **/
  1102. static struct lpfc_hbq_entry *
  1103. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1104. {
  1105. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1106. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1107. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1108. hbqp->next_hbqPutIdx = 0;
  1109. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1110. uint32_t raw_index = phba->hbq_get[hbqno];
  1111. uint32_t getidx = le32_to_cpu(raw_index);
  1112. hbqp->local_hbqGetIdx = getidx;
  1113. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1114. lpfc_printf_log(phba, KERN_ERR,
  1115. LOG_SLI | LOG_VPORT,
  1116. "1802 HBQ %d: local_hbqGetIdx "
  1117. "%u is > than hbqp->entry_count %u\n",
  1118. hbqno, hbqp->local_hbqGetIdx,
  1119. hbqp->entry_count);
  1120. phba->link_state = LPFC_HBA_ERROR;
  1121. return NULL;
  1122. }
  1123. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1124. return NULL;
  1125. }
  1126. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1127. hbqp->hbqPutIdx;
  1128. }
  1129. /**
  1130. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1131. * @phba: Pointer to HBA context object.
  1132. *
  1133. * This function is called with no lock held to free all the
  1134. * hbq buffers while uninitializing the SLI interface. It also
  1135. * frees the HBQ buffers returned by the firmware but not yet
  1136. * processed by the upper layers.
  1137. **/
  1138. void
  1139. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1140. {
  1141. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1142. struct hbq_dmabuf *hbq_buf;
  1143. unsigned long flags;
  1144. int i, hbq_count;
  1145. uint32_t hbqno;
  1146. hbq_count = lpfc_sli_hbq_count();
  1147. /* Return all memory used by all HBQs */
  1148. spin_lock_irqsave(&phba->hbalock, flags);
  1149. for (i = 0; i < hbq_count; ++i) {
  1150. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1151. &phba->hbqs[i].hbq_buffer_list, list) {
  1152. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1153. list_del(&hbq_buf->dbuf.list);
  1154. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1155. }
  1156. phba->hbqs[i].buffer_count = 0;
  1157. }
  1158. /* Return all HBQ buffer that are in-fly */
  1159. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1160. list) {
  1161. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1162. list_del(&hbq_buf->dbuf.list);
  1163. if (hbq_buf->tag == -1) {
  1164. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1165. (phba, hbq_buf);
  1166. } else {
  1167. hbqno = hbq_buf->tag >> 16;
  1168. if (hbqno >= LPFC_MAX_HBQS)
  1169. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1170. (phba, hbq_buf);
  1171. else
  1172. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1173. hbq_buf);
  1174. }
  1175. }
  1176. /* Mark the HBQs not in use */
  1177. phba->hbq_in_use = 0;
  1178. spin_unlock_irqrestore(&phba->hbalock, flags);
  1179. }
  1180. /**
  1181. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1182. * @phba: Pointer to HBA context object.
  1183. * @hbqno: HBQ number.
  1184. * @hbq_buf: Pointer to HBQ buffer.
  1185. *
  1186. * This function is called with the hbalock held to post a
  1187. * hbq buffer to the firmware. If the function finds an empty
  1188. * slot in the HBQ, it will post the buffer. The function will return
  1189. * pointer to the hbq entry if it successfully post the buffer
  1190. * else it will return NULL.
  1191. **/
  1192. static int
  1193. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1194. struct hbq_dmabuf *hbq_buf)
  1195. {
  1196. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1197. }
  1198. /**
  1199. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1200. * @phba: Pointer to HBA context object.
  1201. * @hbqno: HBQ number.
  1202. * @hbq_buf: Pointer to HBQ buffer.
  1203. *
  1204. * This function is called with the hbalock held to post a hbq buffer to the
  1205. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1206. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1207. * it successfully post the buffer else it will return an error.
  1208. **/
  1209. static int
  1210. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1211. struct hbq_dmabuf *hbq_buf)
  1212. {
  1213. struct lpfc_hbq_entry *hbqe;
  1214. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1215. /* Get next HBQ entry slot to use */
  1216. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1217. if (hbqe) {
  1218. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1219. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1220. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1221. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1222. hbqe->bde.tus.f.bdeFlags = 0;
  1223. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1224. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1225. /* Sync SLIM */
  1226. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1227. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1228. /* flush */
  1229. readl(phba->hbq_put + hbqno);
  1230. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1231. return 0;
  1232. } else
  1233. return -ENOMEM;
  1234. }
  1235. /**
  1236. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1237. * @phba: Pointer to HBA context object.
  1238. * @hbqno: HBQ number.
  1239. * @hbq_buf: Pointer to HBQ buffer.
  1240. *
  1241. * This function is called with the hbalock held to post an RQE to the SLI4
  1242. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1243. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1244. **/
  1245. static int
  1246. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1247. struct hbq_dmabuf *hbq_buf)
  1248. {
  1249. int rc;
  1250. struct lpfc_rqe hrqe;
  1251. struct lpfc_rqe drqe;
  1252. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1253. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1254. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1255. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1256. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1257. &hrqe, &drqe);
  1258. if (rc < 0)
  1259. return rc;
  1260. hbq_buf->tag = rc;
  1261. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1262. return 0;
  1263. }
  1264. /* HBQ for ELS and CT traffic. */
  1265. static struct lpfc_hbq_init lpfc_els_hbq = {
  1266. .rn = 1,
  1267. .entry_count = 256,
  1268. .mask_count = 0,
  1269. .profile = 0,
  1270. .ring_mask = (1 << LPFC_ELS_RING),
  1271. .buffer_count = 0,
  1272. .init_count = 40,
  1273. .add_count = 40,
  1274. };
  1275. /* HBQ for the extra ring if needed */
  1276. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1277. .rn = 1,
  1278. .entry_count = 200,
  1279. .mask_count = 0,
  1280. .profile = 0,
  1281. .ring_mask = (1 << LPFC_EXTRA_RING),
  1282. .buffer_count = 0,
  1283. .init_count = 0,
  1284. .add_count = 5,
  1285. };
  1286. /* Array of HBQs */
  1287. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1288. &lpfc_els_hbq,
  1289. &lpfc_extra_hbq,
  1290. };
  1291. /**
  1292. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1293. * @phba: Pointer to HBA context object.
  1294. * @hbqno: HBQ number.
  1295. * @count: Number of HBQ buffers to be posted.
  1296. *
  1297. * This function is called with no lock held to post more hbq buffers to the
  1298. * given HBQ. The function returns the number of HBQ buffers successfully
  1299. * posted.
  1300. **/
  1301. static int
  1302. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1303. {
  1304. uint32_t i, posted = 0;
  1305. unsigned long flags;
  1306. struct hbq_dmabuf *hbq_buffer;
  1307. LIST_HEAD(hbq_buf_list);
  1308. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1309. return 0;
  1310. if ((phba->hbqs[hbqno].buffer_count + count) >
  1311. lpfc_hbq_defs[hbqno]->entry_count)
  1312. count = lpfc_hbq_defs[hbqno]->entry_count -
  1313. phba->hbqs[hbqno].buffer_count;
  1314. if (!count)
  1315. return 0;
  1316. /* Allocate HBQ entries */
  1317. for (i = 0; i < count; i++) {
  1318. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1319. if (!hbq_buffer)
  1320. break;
  1321. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1322. }
  1323. /* Check whether HBQ is still in use */
  1324. spin_lock_irqsave(&phba->hbalock, flags);
  1325. if (!phba->hbq_in_use)
  1326. goto err;
  1327. while (!list_empty(&hbq_buf_list)) {
  1328. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1329. dbuf.list);
  1330. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1331. (hbqno << 16));
  1332. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1333. phba->hbqs[hbqno].buffer_count++;
  1334. posted++;
  1335. } else
  1336. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1337. }
  1338. spin_unlock_irqrestore(&phba->hbalock, flags);
  1339. return posted;
  1340. err:
  1341. spin_unlock_irqrestore(&phba->hbalock, flags);
  1342. while (!list_empty(&hbq_buf_list)) {
  1343. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1344. dbuf.list);
  1345. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1346. }
  1347. return 0;
  1348. }
  1349. /**
  1350. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1351. * @phba: Pointer to HBA context object.
  1352. * @qno: HBQ number.
  1353. *
  1354. * This function posts more buffers to the HBQ. This function
  1355. * is called with no lock held. The function returns the number of HBQ entries
  1356. * successfully allocated.
  1357. **/
  1358. int
  1359. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1360. {
  1361. if (phba->sli_rev == LPFC_SLI_REV4)
  1362. return 0;
  1363. else
  1364. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1365. lpfc_hbq_defs[qno]->add_count);
  1366. }
  1367. /**
  1368. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1369. * @phba: Pointer to HBA context object.
  1370. * @qno: HBQ queue number.
  1371. *
  1372. * This function is called from SLI initialization code path with
  1373. * no lock held to post initial HBQ buffers to firmware. The
  1374. * function returns the number of HBQ entries successfully allocated.
  1375. **/
  1376. static int
  1377. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1378. {
  1379. if (phba->sli_rev == LPFC_SLI_REV4)
  1380. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1381. lpfc_hbq_defs[qno]->entry_count);
  1382. else
  1383. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1384. lpfc_hbq_defs[qno]->init_count);
  1385. }
  1386. /**
  1387. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1388. * @phba: Pointer to HBA context object.
  1389. * @hbqno: HBQ number.
  1390. *
  1391. * This function removes the first hbq buffer on an hbq list and returns a
  1392. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1393. **/
  1394. static struct hbq_dmabuf *
  1395. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1396. {
  1397. struct lpfc_dmabuf *d_buf;
  1398. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1399. if (!d_buf)
  1400. return NULL;
  1401. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1402. }
  1403. /**
  1404. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1405. * @phba: Pointer to HBA context object.
  1406. * @tag: Tag of the hbq buffer.
  1407. *
  1408. * This function is called with hbalock held. This function searches
  1409. * for the hbq buffer associated with the given tag in the hbq buffer
  1410. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1411. * it returns NULL.
  1412. **/
  1413. static struct hbq_dmabuf *
  1414. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1415. {
  1416. struct lpfc_dmabuf *d_buf;
  1417. struct hbq_dmabuf *hbq_buf;
  1418. uint32_t hbqno;
  1419. hbqno = tag >> 16;
  1420. if (hbqno >= LPFC_MAX_HBQS)
  1421. return NULL;
  1422. spin_lock_irq(&phba->hbalock);
  1423. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1424. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1425. if (hbq_buf->tag == tag) {
  1426. spin_unlock_irq(&phba->hbalock);
  1427. return hbq_buf;
  1428. }
  1429. }
  1430. spin_unlock_irq(&phba->hbalock);
  1431. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1432. "1803 Bad hbq tag. Data: x%x x%x\n",
  1433. tag, phba->hbqs[tag >> 16].buffer_count);
  1434. return NULL;
  1435. }
  1436. /**
  1437. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1438. * @phba: Pointer to HBA context object.
  1439. * @hbq_buffer: Pointer to HBQ buffer.
  1440. *
  1441. * This function is called with hbalock. This function gives back
  1442. * the hbq buffer to firmware. If the HBQ does not have space to
  1443. * post the buffer, it will free the buffer.
  1444. **/
  1445. void
  1446. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1447. {
  1448. uint32_t hbqno;
  1449. if (hbq_buffer) {
  1450. hbqno = hbq_buffer->tag >> 16;
  1451. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1452. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1453. }
  1454. }
  1455. /**
  1456. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1457. * @mbxCommand: mailbox command code.
  1458. *
  1459. * This function is called by the mailbox event handler function to verify
  1460. * that the completed mailbox command is a legitimate mailbox command. If the
  1461. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1462. * and the mailbox event handler will take the HBA offline.
  1463. **/
  1464. static int
  1465. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1466. {
  1467. uint8_t ret;
  1468. switch (mbxCommand) {
  1469. case MBX_LOAD_SM:
  1470. case MBX_READ_NV:
  1471. case MBX_WRITE_NV:
  1472. case MBX_WRITE_VPARMS:
  1473. case MBX_RUN_BIU_DIAG:
  1474. case MBX_INIT_LINK:
  1475. case MBX_DOWN_LINK:
  1476. case MBX_CONFIG_LINK:
  1477. case MBX_CONFIG_RING:
  1478. case MBX_RESET_RING:
  1479. case MBX_READ_CONFIG:
  1480. case MBX_READ_RCONFIG:
  1481. case MBX_READ_SPARM:
  1482. case MBX_READ_STATUS:
  1483. case MBX_READ_RPI:
  1484. case MBX_READ_XRI:
  1485. case MBX_READ_REV:
  1486. case MBX_READ_LNK_STAT:
  1487. case MBX_REG_LOGIN:
  1488. case MBX_UNREG_LOGIN:
  1489. case MBX_READ_LA:
  1490. case MBX_CLEAR_LA:
  1491. case MBX_DUMP_MEMORY:
  1492. case MBX_DUMP_CONTEXT:
  1493. case MBX_RUN_DIAGS:
  1494. case MBX_RESTART:
  1495. case MBX_UPDATE_CFG:
  1496. case MBX_DOWN_LOAD:
  1497. case MBX_DEL_LD_ENTRY:
  1498. case MBX_RUN_PROGRAM:
  1499. case MBX_SET_MASK:
  1500. case MBX_SET_VARIABLE:
  1501. case MBX_UNREG_D_ID:
  1502. case MBX_KILL_BOARD:
  1503. case MBX_CONFIG_FARP:
  1504. case MBX_BEACON:
  1505. case MBX_LOAD_AREA:
  1506. case MBX_RUN_BIU_DIAG64:
  1507. case MBX_CONFIG_PORT:
  1508. case MBX_READ_SPARM64:
  1509. case MBX_READ_RPI64:
  1510. case MBX_REG_LOGIN64:
  1511. case MBX_READ_LA64:
  1512. case MBX_WRITE_WWN:
  1513. case MBX_SET_DEBUG:
  1514. case MBX_LOAD_EXP_ROM:
  1515. case MBX_ASYNCEVT_ENABLE:
  1516. case MBX_REG_VPI:
  1517. case MBX_UNREG_VPI:
  1518. case MBX_HEARTBEAT:
  1519. case MBX_PORT_CAPABILITIES:
  1520. case MBX_PORT_IOV_CONTROL:
  1521. case MBX_SLI4_CONFIG:
  1522. case MBX_SLI4_REQ_FTRS:
  1523. case MBX_REG_FCFI:
  1524. case MBX_UNREG_FCFI:
  1525. case MBX_REG_VFI:
  1526. case MBX_UNREG_VFI:
  1527. case MBX_INIT_VPI:
  1528. case MBX_INIT_VFI:
  1529. case MBX_RESUME_RPI:
  1530. ret = mbxCommand;
  1531. break;
  1532. default:
  1533. ret = MBX_SHUTDOWN;
  1534. break;
  1535. }
  1536. return ret;
  1537. }
  1538. /**
  1539. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1540. * @phba: Pointer to HBA context object.
  1541. * @pmboxq: Pointer to mailbox command.
  1542. *
  1543. * This is completion handler function for mailbox commands issued from
  1544. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1545. * mailbox event handler function with no lock held. This function
  1546. * will wake up thread waiting on the wait queue pointed by context1
  1547. * of the mailbox.
  1548. **/
  1549. void
  1550. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1551. {
  1552. wait_queue_head_t *pdone_q;
  1553. unsigned long drvr_flag;
  1554. /*
  1555. * If pdone_q is empty, the driver thread gave up waiting and
  1556. * continued running.
  1557. */
  1558. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1559. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1560. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1561. if (pdone_q)
  1562. wake_up_interruptible(pdone_q);
  1563. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1564. return;
  1565. }
  1566. /**
  1567. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1568. * @phba: Pointer to HBA context object.
  1569. * @pmb: Pointer to mailbox object.
  1570. *
  1571. * This function is the default mailbox completion handler. It
  1572. * frees the memory resources associated with the completed mailbox
  1573. * command. If the completed command is a REG_LOGIN mailbox command,
  1574. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1575. **/
  1576. void
  1577. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1578. {
  1579. struct lpfc_dmabuf *mp;
  1580. uint16_t rpi, vpi;
  1581. int rc;
  1582. struct lpfc_vport *vport = pmb->vport;
  1583. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1584. if (mp) {
  1585. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1586. kfree(mp);
  1587. }
  1588. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1589. (phba->sli_rev == LPFC_SLI_REV4))
  1590. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1591. /*
  1592. * If a REG_LOGIN succeeded after node is destroyed or node
  1593. * is in re-discovery driver need to cleanup the RPI.
  1594. */
  1595. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1596. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1597. !pmb->u.mb.mbxStatus) {
  1598. rpi = pmb->u.mb.un.varWords[0];
  1599. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1600. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1601. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1602. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1603. if (rc != MBX_NOT_FINISHED)
  1604. return;
  1605. }
  1606. /* Unreg VPI, if the REG_VPI succeed after VLink failure */
  1607. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1608. !(phba->pport->load_flag & FC_UNLOADING) &&
  1609. !pmb->u.mb.mbxStatus) {
  1610. lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb);
  1611. pmb->vport = vport;
  1612. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1613. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1614. if (rc != MBX_NOT_FINISHED)
  1615. return;
  1616. }
  1617. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1618. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1619. else
  1620. mempool_free(pmb, phba->mbox_mem_pool);
  1621. }
  1622. /**
  1623. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1624. * @phba: Pointer to HBA context object.
  1625. *
  1626. * This function is called with no lock held. This function processes all
  1627. * the completed mailbox commands and gives it to upper layers. The interrupt
  1628. * service routine processes mailbox completion interrupt and adds completed
  1629. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1630. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1631. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1632. * function returns the mailbox commands to the upper layer by calling the
  1633. * completion handler function of each mailbox.
  1634. **/
  1635. int
  1636. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1637. {
  1638. MAILBOX_t *pmbox;
  1639. LPFC_MBOXQ_t *pmb;
  1640. int rc;
  1641. LIST_HEAD(cmplq);
  1642. phba->sli.slistat.mbox_event++;
  1643. /* Get all completed mailboxe buffers into the cmplq */
  1644. spin_lock_irq(&phba->hbalock);
  1645. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1646. spin_unlock_irq(&phba->hbalock);
  1647. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1648. do {
  1649. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1650. if (pmb == NULL)
  1651. break;
  1652. pmbox = &pmb->u.mb;
  1653. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1654. if (pmb->vport) {
  1655. lpfc_debugfs_disc_trc(pmb->vport,
  1656. LPFC_DISC_TRC_MBOX_VPORT,
  1657. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1658. (uint32_t)pmbox->mbxCommand,
  1659. pmbox->un.varWords[0],
  1660. pmbox->un.varWords[1]);
  1661. }
  1662. else {
  1663. lpfc_debugfs_disc_trc(phba->pport,
  1664. LPFC_DISC_TRC_MBOX,
  1665. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1666. (uint32_t)pmbox->mbxCommand,
  1667. pmbox->un.varWords[0],
  1668. pmbox->un.varWords[1]);
  1669. }
  1670. }
  1671. /*
  1672. * It is a fatal error if unknown mbox command completion.
  1673. */
  1674. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1675. MBX_SHUTDOWN) {
  1676. /* Unknown mailbox command compl */
  1677. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1678. "(%d):0323 Unknown Mailbox command "
  1679. "x%x (x%x) Cmpl\n",
  1680. pmb->vport ? pmb->vport->vpi : 0,
  1681. pmbox->mbxCommand,
  1682. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1683. phba->link_state = LPFC_HBA_ERROR;
  1684. phba->work_hs = HS_FFER3;
  1685. lpfc_handle_eratt(phba);
  1686. continue;
  1687. }
  1688. if (pmbox->mbxStatus) {
  1689. phba->sli.slistat.mbox_stat_err++;
  1690. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1691. /* Mbox cmd cmpl error - RETRYing */
  1692. lpfc_printf_log(phba, KERN_INFO,
  1693. LOG_MBOX | LOG_SLI,
  1694. "(%d):0305 Mbox cmd cmpl "
  1695. "error - RETRYing Data: x%x "
  1696. "(x%x) x%x x%x x%x\n",
  1697. pmb->vport ? pmb->vport->vpi :0,
  1698. pmbox->mbxCommand,
  1699. lpfc_sli4_mbox_opcode_get(phba,
  1700. pmb),
  1701. pmbox->mbxStatus,
  1702. pmbox->un.varWords[0],
  1703. pmb->vport->port_state);
  1704. pmbox->mbxStatus = 0;
  1705. pmbox->mbxOwner = OWN_HOST;
  1706. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1707. if (rc != MBX_NOT_FINISHED)
  1708. continue;
  1709. }
  1710. }
  1711. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1712. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1713. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1714. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1715. pmb->vport ? pmb->vport->vpi : 0,
  1716. pmbox->mbxCommand,
  1717. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1718. pmb->mbox_cmpl,
  1719. *((uint32_t *) pmbox),
  1720. pmbox->un.varWords[0],
  1721. pmbox->un.varWords[1],
  1722. pmbox->un.varWords[2],
  1723. pmbox->un.varWords[3],
  1724. pmbox->un.varWords[4],
  1725. pmbox->un.varWords[5],
  1726. pmbox->un.varWords[6],
  1727. pmbox->un.varWords[7]);
  1728. if (pmb->mbox_cmpl)
  1729. pmb->mbox_cmpl(phba,pmb);
  1730. } while (1);
  1731. return 0;
  1732. }
  1733. /**
  1734. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1735. * @phba: Pointer to HBA context object.
  1736. * @pring: Pointer to driver SLI ring object.
  1737. * @tag: buffer tag.
  1738. *
  1739. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1740. * is set in the tag the buffer is posted for a particular exchange,
  1741. * the function will return the buffer without replacing the buffer.
  1742. * If the buffer is for unsolicited ELS or CT traffic, this function
  1743. * returns the buffer and also posts another buffer to the firmware.
  1744. **/
  1745. static struct lpfc_dmabuf *
  1746. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1747. struct lpfc_sli_ring *pring,
  1748. uint32_t tag)
  1749. {
  1750. struct hbq_dmabuf *hbq_entry;
  1751. if (tag & QUE_BUFTAG_BIT)
  1752. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1753. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1754. if (!hbq_entry)
  1755. return NULL;
  1756. return &hbq_entry->dbuf;
  1757. }
  1758. /**
  1759. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1760. * @phba: Pointer to HBA context object.
  1761. * @pring: Pointer to driver SLI ring object.
  1762. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1763. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1764. * @fch_type: the type for the first frame of the sequence.
  1765. *
  1766. * This function is called with no lock held. This function uses the r_ctl and
  1767. * type of the received sequence to find the correct callback function to call
  1768. * to process the sequence.
  1769. **/
  1770. static int
  1771. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1772. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1773. uint32_t fch_type)
  1774. {
  1775. int i;
  1776. /* unSolicited Responses */
  1777. if (pring->prt[0].profile) {
  1778. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1779. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1780. saveq);
  1781. return 1;
  1782. }
  1783. /* We must search, based on rctl / type
  1784. for the right routine */
  1785. for (i = 0; i < pring->num_mask; i++) {
  1786. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1787. (pring->prt[i].type == fch_type)) {
  1788. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1789. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1790. (phba, pring, saveq);
  1791. return 1;
  1792. }
  1793. }
  1794. return 0;
  1795. }
  1796. /**
  1797. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1798. * @phba: Pointer to HBA context object.
  1799. * @pring: Pointer to driver SLI ring object.
  1800. * @saveq: Pointer to the unsolicited iocb.
  1801. *
  1802. * This function is called with no lock held by the ring event handler
  1803. * when there is an unsolicited iocb posted to the response ring by the
  1804. * firmware. This function gets the buffer associated with the iocbs
  1805. * and calls the event handler for the ring. This function handles both
  1806. * qring buffers and hbq buffers.
  1807. * When the function returns 1 the caller can free the iocb object otherwise
  1808. * upper layer functions will free the iocb objects.
  1809. **/
  1810. static int
  1811. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1812. struct lpfc_iocbq *saveq)
  1813. {
  1814. IOCB_t * irsp;
  1815. WORD5 * w5p;
  1816. uint32_t Rctl, Type;
  1817. uint32_t match;
  1818. struct lpfc_iocbq *iocbq;
  1819. struct lpfc_dmabuf *dmzbuf;
  1820. match = 0;
  1821. irsp = &(saveq->iocb);
  1822. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1823. if (pring->lpfc_sli_rcv_async_status)
  1824. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1825. else
  1826. lpfc_printf_log(phba,
  1827. KERN_WARNING,
  1828. LOG_SLI,
  1829. "0316 Ring %d handler: unexpected "
  1830. "ASYNC_STATUS iocb received evt_code "
  1831. "0x%x\n",
  1832. pring->ringno,
  1833. irsp->un.asyncstat.evt_code);
  1834. return 1;
  1835. }
  1836. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1837. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1838. if (irsp->ulpBdeCount > 0) {
  1839. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1840. irsp->un.ulpWord[3]);
  1841. lpfc_in_buf_free(phba, dmzbuf);
  1842. }
  1843. if (irsp->ulpBdeCount > 1) {
  1844. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1845. irsp->unsli3.sli3Words[3]);
  1846. lpfc_in_buf_free(phba, dmzbuf);
  1847. }
  1848. if (irsp->ulpBdeCount > 2) {
  1849. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1850. irsp->unsli3.sli3Words[7]);
  1851. lpfc_in_buf_free(phba, dmzbuf);
  1852. }
  1853. return 1;
  1854. }
  1855. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1856. if (irsp->ulpBdeCount != 0) {
  1857. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1858. irsp->un.ulpWord[3]);
  1859. if (!saveq->context2)
  1860. lpfc_printf_log(phba,
  1861. KERN_ERR,
  1862. LOG_SLI,
  1863. "0341 Ring %d Cannot find buffer for "
  1864. "an unsolicited iocb. tag 0x%x\n",
  1865. pring->ringno,
  1866. irsp->un.ulpWord[3]);
  1867. }
  1868. if (irsp->ulpBdeCount == 2) {
  1869. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1870. irsp->unsli3.sli3Words[7]);
  1871. if (!saveq->context3)
  1872. lpfc_printf_log(phba,
  1873. KERN_ERR,
  1874. LOG_SLI,
  1875. "0342 Ring %d Cannot find buffer for an"
  1876. " unsolicited iocb. tag 0x%x\n",
  1877. pring->ringno,
  1878. irsp->unsli3.sli3Words[7]);
  1879. }
  1880. list_for_each_entry(iocbq, &saveq->list, list) {
  1881. irsp = &(iocbq->iocb);
  1882. if (irsp->ulpBdeCount != 0) {
  1883. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1884. irsp->un.ulpWord[3]);
  1885. if (!iocbq->context2)
  1886. lpfc_printf_log(phba,
  1887. KERN_ERR,
  1888. LOG_SLI,
  1889. "0343 Ring %d Cannot find "
  1890. "buffer for an unsolicited iocb"
  1891. ". tag 0x%x\n", pring->ringno,
  1892. irsp->un.ulpWord[3]);
  1893. }
  1894. if (irsp->ulpBdeCount == 2) {
  1895. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1896. irsp->unsli3.sli3Words[7]);
  1897. if (!iocbq->context3)
  1898. lpfc_printf_log(phba,
  1899. KERN_ERR,
  1900. LOG_SLI,
  1901. "0344 Ring %d Cannot find "
  1902. "buffer for an unsolicited "
  1903. "iocb. tag 0x%x\n",
  1904. pring->ringno,
  1905. irsp->unsli3.sli3Words[7]);
  1906. }
  1907. }
  1908. }
  1909. if (irsp->ulpBdeCount != 0 &&
  1910. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1911. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1912. int found = 0;
  1913. /* search continue save q for same XRI */
  1914. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1915. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1916. list_add_tail(&saveq->list, &iocbq->list);
  1917. found = 1;
  1918. break;
  1919. }
  1920. }
  1921. if (!found)
  1922. list_add_tail(&saveq->clist,
  1923. &pring->iocb_continue_saveq);
  1924. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1925. list_del_init(&iocbq->clist);
  1926. saveq = iocbq;
  1927. irsp = &(saveq->iocb);
  1928. } else
  1929. return 0;
  1930. }
  1931. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1932. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1933. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1934. Rctl = FC_RCTL_ELS_REQ;
  1935. Type = FC_TYPE_ELS;
  1936. } else {
  1937. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1938. Rctl = w5p->hcsw.Rctl;
  1939. Type = w5p->hcsw.Type;
  1940. /* Firmware Workaround */
  1941. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1942. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1943. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1944. Rctl = FC_RCTL_ELS_REQ;
  1945. Type = FC_TYPE_ELS;
  1946. w5p->hcsw.Rctl = Rctl;
  1947. w5p->hcsw.Type = Type;
  1948. }
  1949. }
  1950. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1951. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1952. "0313 Ring %d handler: unexpected Rctl x%x "
  1953. "Type x%x received\n",
  1954. pring->ringno, Rctl, Type);
  1955. return 1;
  1956. }
  1957. /**
  1958. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1959. * @phba: Pointer to HBA context object.
  1960. * @pring: Pointer to driver SLI ring object.
  1961. * @prspiocb: Pointer to response iocb object.
  1962. *
  1963. * This function looks up the iocb_lookup table to get the command iocb
  1964. * corresponding to the given response iocb using the iotag of the
  1965. * response iocb. This function is called with the hbalock held.
  1966. * This function returns the command iocb object if it finds the command
  1967. * iocb else returns NULL.
  1968. **/
  1969. static struct lpfc_iocbq *
  1970. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1971. struct lpfc_sli_ring *pring,
  1972. struct lpfc_iocbq *prspiocb)
  1973. {
  1974. struct lpfc_iocbq *cmd_iocb = NULL;
  1975. uint16_t iotag;
  1976. iotag = prspiocb->iocb.ulpIoTag;
  1977. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1978. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1979. list_del_init(&cmd_iocb->list);
  1980. pring->txcmplq_cnt--;
  1981. return cmd_iocb;
  1982. }
  1983. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1984. "0317 iotag x%x is out off "
  1985. "range: max iotag x%x wd0 x%x\n",
  1986. iotag, phba->sli.last_iotag,
  1987. *(((uint32_t *) &prspiocb->iocb) + 7));
  1988. return NULL;
  1989. }
  1990. /**
  1991. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1992. * @phba: Pointer to HBA context object.
  1993. * @pring: Pointer to driver SLI ring object.
  1994. * @iotag: IOCB tag.
  1995. *
  1996. * This function looks up the iocb_lookup table to get the command iocb
  1997. * corresponding to the given iotag. This function is called with the
  1998. * hbalock held.
  1999. * This function returns the command iocb object if it finds the command
  2000. * iocb else returns NULL.
  2001. **/
  2002. static struct lpfc_iocbq *
  2003. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2004. struct lpfc_sli_ring *pring, uint16_t iotag)
  2005. {
  2006. struct lpfc_iocbq *cmd_iocb;
  2007. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2008. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2009. list_del_init(&cmd_iocb->list);
  2010. pring->txcmplq_cnt--;
  2011. return cmd_iocb;
  2012. }
  2013. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2014. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2015. iotag, phba->sli.last_iotag);
  2016. return NULL;
  2017. }
  2018. /**
  2019. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2020. * @phba: Pointer to HBA context object.
  2021. * @pring: Pointer to driver SLI ring object.
  2022. * @saveq: Pointer to the response iocb to be processed.
  2023. *
  2024. * This function is called by the ring event handler for non-fcp
  2025. * rings when there is a new response iocb in the response ring.
  2026. * The caller is not required to hold any locks. This function
  2027. * gets the command iocb associated with the response iocb and
  2028. * calls the completion handler for the command iocb. If there
  2029. * is no completion handler, the function will free the resources
  2030. * associated with command iocb. If the response iocb is for
  2031. * an already aborted command iocb, the status of the completion
  2032. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2033. * This function always returns 1.
  2034. **/
  2035. static int
  2036. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2037. struct lpfc_iocbq *saveq)
  2038. {
  2039. struct lpfc_iocbq *cmdiocbp;
  2040. int rc = 1;
  2041. unsigned long iflag;
  2042. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2043. spin_lock_irqsave(&phba->hbalock, iflag);
  2044. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2045. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2046. if (cmdiocbp) {
  2047. if (cmdiocbp->iocb_cmpl) {
  2048. /*
  2049. * If an ELS command failed send an event to mgmt
  2050. * application.
  2051. */
  2052. if (saveq->iocb.ulpStatus &&
  2053. (pring->ringno == LPFC_ELS_RING) &&
  2054. (cmdiocbp->iocb.ulpCommand ==
  2055. CMD_ELS_REQUEST64_CR))
  2056. lpfc_send_els_failure_event(phba,
  2057. cmdiocbp, saveq);
  2058. /*
  2059. * Post all ELS completions to the worker thread.
  2060. * All other are passed to the completion callback.
  2061. */
  2062. if (pring->ringno == LPFC_ELS_RING) {
  2063. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2064. (cmdiocbp->iocb_flag &
  2065. LPFC_DRIVER_ABORTED)) {
  2066. spin_lock_irqsave(&phba->hbalock,
  2067. iflag);
  2068. cmdiocbp->iocb_flag &=
  2069. ~LPFC_DRIVER_ABORTED;
  2070. spin_unlock_irqrestore(&phba->hbalock,
  2071. iflag);
  2072. saveq->iocb.ulpStatus =
  2073. IOSTAT_LOCAL_REJECT;
  2074. saveq->iocb.un.ulpWord[4] =
  2075. IOERR_SLI_ABORTED;
  2076. /* Firmware could still be in progress
  2077. * of DMAing payload, so don't free data
  2078. * buffer till after a hbeat.
  2079. */
  2080. spin_lock_irqsave(&phba->hbalock,
  2081. iflag);
  2082. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2083. spin_unlock_irqrestore(&phba->hbalock,
  2084. iflag);
  2085. }
  2086. if (phba->sli_rev == LPFC_SLI_REV4) {
  2087. if (saveq->iocb_flag &
  2088. LPFC_EXCHANGE_BUSY) {
  2089. /* Set cmdiocb flag for the
  2090. * exchange busy so sgl (xri)
  2091. * will not be released until
  2092. * the abort xri is received
  2093. * from hba.
  2094. */
  2095. spin_lock_irqsave(
  2096. &phba->hbalock, iflag);
  2097. cmdiocbp->iocb_flag |=
  2098. LPFC_EXCHANGE_BUSY;
  2099. spin_unlock_irqrestore(
  2100. &phba->hbalock, iflag);
  2101. }
  2102. if (cmdiocbp->iocb_flag &
  2103. LPFC_DRIVER_ABORTED) {
  2104. /*
  2105. * Clear LPFC_DRIVER_ABORTED
  2106. * bit in case it was driver
  2107. * initiated abort.
  2108. */
  2109. spin_lock_irqsave(
  2110. &phba->hbalock, iflag);
  2111. cmdiocbp->iocb_flag &=
  2112. ~LPFC_DRIVER_ABORTED;
  2113. spin_unlock_irqrestore(
  2114. &phba->hbalock, iflag);
  2115. cmdiocbp->iocb.ulpStatus =
  2116. IOSTAT_LOCAL_REJECT;
  2117. cmdiocbp->iocb.un.ulpWord[4] =
  2118. IOERR_ABORT_REQUESTED;
  2119. /*
  2120. * For SLI4, irsiocb contains
  2121. * NO_XRI in sli_xritag, it
  2122. * shall not affect releasing
  2123. * sgl (xri) process.
  2124. */
  2125. saveq->iocb.ulpStatus =
  2126. IOSTAT_LOCAL_REJECT;
  2127. saveq->iocb.un.ulpWord[4] =
  2128. IOERR_SLI_ABORTED;
  2129. spin_lock_irqsave(
  2130. &phba->hbalock, iflag);
  2131. saveq->iocb_flag |=
  2132. LPFC_DELAY_MEM_FREE;
  2133. spin_unlock_irqrestore(
  2134. &phba->hbalock, iflag);
  2135. }
  2136. }
  2137. }
  2138. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2139. } else
  2140. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2141. } else {
  2142. /*
  2143. * Unknown initiating command based on the response iotag.
  2144. * This could be the case on the ELS ring because of
  2145. * lpfc_els_abort().
  2146. */
  2147. if (pring->ringno != LPFC_ELS_RING) {
  2148. /*
  2149. * Ring <ringno> handler: unexpected completion IoTag
  2150. * <IoTag>
  2151. */
  2152. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2153. "0322 Ring %d handler: "
  2154. "unexpected completion IoTag x%x "
  2155. "Data: x%x x%x x%x x%x\n",
  2156. pring->ringno,
  2157. saveq->iocb.ulpIoTag,
  2158. saveq->iocb.ulpStatus,
  2159. saveq->iocb.un.ulpWord[4],
  2160. saveq->iocb.ulpCommand,
  2161. saveq->iocb.ulpContext);
  2162. }
  2163. }
  2164. return rc;
  2165. }
  2166. /**
  2167. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2168. * @phba: Pointer to HBA context object.
  2169. * @pring: Pointer to driver SLI ring object.
  2170. *
  2171. * This function is called from the iocb ring event handlers when
  2172. * put pointer is ahead of the get pointer for a ring. This function signal
  2173. * an error attention condition to the worker thread and the worker
  2174. * thread will transition the HBA to offline state.
  2175. **/
  2176. static void
  2177. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2178. {
  2179. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2180. /*
  2181. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2182. * rsp ring <portRspMax>
  2183. */
  2184. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2185. "0312 Ring %d handler: portRspPut %d "
  2186. "is bigger than rsp ring %d\n",
  2187. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2188. pring->numRiocb);
  2189. phba->link_state = LPFC_HBA_ERROR;
  2190. /*
  2191. * All error attention handlers are posted to
  2192. * worker thread
  2193. */
  2194. phba->work_ha |= HA_ERATT;
  2195. phba->work_hs = HS_FFER3;
  2196. lpfc_worker_wake_up(phba);
  2197. return;
  2198. }
  2199. /**
  2200. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2201. * @ptr: Pointer to address of HBA context object.
  2202. *
  2203. * This function is invoked by the Error Attention polling timer when the
  2204. * timer times out. It will check the SLI Error Attention register for
  2205. * possible attention events. If so, it will post an Error Attention event
  2206. * and wake up worker thread to process it. Otherwise, it will set up the
  2207. * Error Attention polling timer for the next poll.
  2208. **/
  2209. void lpfc_poll_eratt(unsigned long ptr)
  2210. {
  2211. struct lpfc_hba *phba;
  2212. uint32_t eratt = 0;
  2213. phba = (struct lpfc_hba *)ptr;
  2214. /* Check chip HA register for error event */
  2215. eratt = lpfc_sli_check_eratt(phba);
  2216. if (eratt)
  2217. /* Tell the worker thread there is work to do */
  2218. lpfc_worker_wake_up(phba);
  2219. else
  2220. /* Restart the timer for next eratt poll */
  2221. mod_timer(&phba->eratt_poll, jiffies +
  2222. HZ * LPFC_ERATT_POLL_INTERVAL);
  2223. return;
  2224. }
  2225. /**
  2226. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2227. * @phba: Pointer to HBA context object.
  2228. * @pring: Pointer to driver SLI ring object.
  2229. * @mask: Host attention register mask for this ring.
  2230. *
  2231. * This function is called from the interrupt context when there is a ring
  2232. * event for the fcp ring. The caller does not hold any lock.
  2233. * The function processes each response iocb in the response ring until it
  2234. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2235. * LE bit set. The function will call the completion handler of the command iocb
  2236. * if the response iocb indicates a completion for a command iocb or it is
  2237. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2238. * function if this is an unsolicited iocb.
  2239. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2240. * to check it explicitly.
  2241. */
  2242. int
  2243. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2244. struct lpfc_sli_ring *pring, uint32_t mask)
  2245. {
  2246. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2247. IOCB_t *irsp = NULL;
  2248. IOCB_t *entry = NULL;
  2249. struct lpfc_iocbq *cmdiocbq = NULL;
  2250. struct lpfc_iocbq rspiocbq;
  2251. uint32_t status;
  2252. uint32_t portRspPut, portRspMax;
  2253. int rc = 1;
  2254. lpfc_iocb_type type;
  2255. unsigned long iflag;
  2256. uint32_t rsp_cmpl = 0;
  2257. spin_lock_irqsave(&phba->hbalock, iflag);
  2258. pring->stats.iocb_event++;
  2259. /*
  2260. * The next available response entry should never exceed the maximum
  2261. * entries. If it does, treat it as an adapter hardware error.
  2262. */
  2263. portRspMax = pring->numRiocb;
  2264. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2265. if (unlikely(portRspPut >= portRspMax)) {
  2266. lpfc_sli_rsp_pointers_error(phba, pring);
  2267. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2268. return 1;
  2269. }
  2270. if (phba->fcp_ring_in_use) {
  2271. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2272. return 1;
  2273. } else
  2274. phba->fcp_ring_in_use = 1;
  2275. rmb();
  2276. while (pring->rspidx != portRspPut) {
  2277. /*
  2278. * Fetch an entry off the ring and copy it into a local data
  2279. * structure. The copy involves a byte-swap since the
  2280. * network byte order and pci byte orders are different.
  2281. */
  2282. entry = lpfc_resp_iocb(phba, pring);
  2283. phba->last_completion_time = jiffies;
  2284. if (++pring->rspidx >= portRspMax)
  2285. pring->rspidx = 0;
  2286. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2287. (uint32_t *) &rspiocbq.iocb,
  2288. phba->iocb_rsp_size);
  2289. INIT_LIST_HEAD(&(rspiocbq.list));
  2290. irsp = &rspiocbq.iocb;
  2291. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2292. pring->stats.iocb_rsp++;
  2293. rsp_cmpl++;
  2294. if (unlikely(irsp->ulpStatus)) {
  2295. /*
  2296. * If resource errors reported from HBA, reduce
  2297. * queuedepths of the SCSI device.
  2298. */
  2299. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2300. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2301. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2302. phba->lpfc_rampdown_queue_depth(phba);
  2303. spin_lock_irqsave(&phba->hbalock, iflag);
  2304. }
  2305. /* Rsp ring <ringno> error: IOCB */
  2306. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2307. "0336 Rsp Ring %d error: IOCB Data: "
  2308. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2309. pring->ringno,
  2310. irsp->un.ulpWord[0],
  2311. irsp->un.ulpWord[1],
  2312. irsp->un.ulpWord[2],
  2313. irsp->un.ulpWord[3],
  2314. irsp->un.ulpWord[4],
  2315. irsp->un.ulpWord[5],
  2316. *(uint32_t *)&irsp->un1,
  2317. *((uint32_t *)&irsp->un1 + 1));
  2318. }
  2319. switch (type) {
  2320. case LPFC_ABORT_IOCB:
  2321. case LPFC_SOL_IOCB:
  2322. /*
  2323. * Idle exchange closed via ABTS from port. No iocb
  2324. * resources need to be recovered.
  2325. */
  2326. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2327. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2328. "0333 IOCB cmd 0x%x"
  2329. " processed. Skipping"
  2330. " completion\n",
  2331. irsp->ulpCommand);
  2332. break;
  2333. }
  2334. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2335. &rspiocbq);
  2336. if (unlikely(!cmdiocbq))
  2337. break;
  2338. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2339. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2340. if (cmdiocbq->iocb_cmpl) {
  2341. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2342. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2343. &rspiocbq);
  2344. spin_lock_irqsave(&phba->hbalock, iflag);
  2345. }
  2346. break;
  2347. case LPFC_UNSOL_IOCB:
  2348. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2349. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2350. spin_lock_irqsave(&phba->hbalock, iflag);
  2351. break;
  2352. default:
  2353. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2354. char adaptermsg[LPFC_MAX_ADPTMSG];
  2355. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2356. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2357. MAX_MSG_DATA);
  2358. dev_warn(&((phba->pcidev)->dev),
  2359. "lpfc%d: %s\n",
  2360. phba->brd_no, adaptermsg);
  2361. } else {
  2362. /* Unknown IOCB command */
  2363. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2364. "0334 Unknown IOCB command "
  2365. "Data: x%x, x%x x%x x%x x%x\n",
  2366. type, irsp->ulpCommand,
  2367. irsp->ulpStatus,
  2368. irsp->ulpIoTag,
  2369. irsp->ulpContext);
  2370. }
  2371. break;
  2372. }
  2373. /*
  2374. * The response IOCB has been processed. Update the ring
  2375. * pointer in SLIM. If the port response put pointer has not
  2376. * been updated, sync the pgp->rspPutInx and fetch the new port
  2377. * response put pointer.
  2378. */
  2379. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2380. if (pring->rspidx == portRspPut)
  2381. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2382. }
  2383. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2384. pring->stats.iocb_rsp_full++;
  2385. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2386. writel(status, phba->CAregaddr);
  2387. readl(phba->CAregaddr);
  2388. }
  2389. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2390. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2391. pring->stats.iocb_cmd_empty++;
  2392. /* Force update of the local copy of cmdGetInx */
  2393. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2394. lpfc_sli_resume_iocb(phba, pring);
  2395. if ((pring->lpfc_sli_cmd_available))
  2396. (pring->lpfc_sli_cmd_available) (phba, pring);
  2397. }
  2398. phba->fcp_ring_in_use = 0;
  2399. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2400. return rc;
  2401. }
  2402. /**
  2403. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2404. * @phba: Pointer to HBA context object.
  2405. * @pring: Pointer to driver SLI ring object.
  2406. * @rspiocbp: Pointer to driver response IOCB object.
  2407. *
  2408. * This function is called from the worker thread when there is a slow-path
  2409. * response IOCB to process. This function chains all the response iocbs until
  2410. * seeing the iocb with the LE bit set. The function will call
  2411. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2412. * completion of a command iocb. The function will call the
  2413. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2414. * The function frees the resources or calls the completion handler if this
  2415. * iocb is an abort completion. The function returns NULL when the response
  2416. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2417. * this function shall chain the iocb on to the iocb_continueq and return the
  2418. * response iocb passed in.
  2419. **/
  2420. static struct lpfc_iocbq *
  2421. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2422. struct lpfc_iocbq *rspiocbp)
  2423. {
  2424. struct lpfc_iocbq *saveq;
  2425. struct lpfc_iocbq *cmdiocbp;
  2426. struct lpfc_iocbq *next_iocb;
  2427. IOCB_t *irsp = NULL;
  2428. uint32_t free_saveq;
  2429. uint8_t iocb_cmd_type;
  2430. lpfc_iocb_type type;
  2431. unsigned long iflag;
  2432. int rc;
  2433. spin_lock_irqsave(&phba->hbalock, iflag);
  2434. /* First add the response iocb to the countinueq list */
  2435. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2436. pring->iocb_continueq_cnt++;
  2437. /* Now, determine whetehr the list is completed for processing */
  2438. irsp = &rspiocbp->iocb;
  2439. if (irsp->ulpLe) {
  2440. /*
  2441. * By default, the driver expects to free all resources
  2442. * associated with this iocb completion.
  2443. */
  2444. free_saveq = 1;
  2445. saveq = list_get_first(&pring->iocb_continueq,
  2446. struct lpfc_iocbq, list);
  2447. irsp = &(saveq->iocb);
  2448. list_del_init(&pring->iocb_continueq);
  2449. pring->iocb_continueq_cnt = 0;
  2450. pring->stats.iocb_rsp++;
  2451. /*
  2452. * If resource errors reported from HBA, reduce
  2453. * queuedepths of the SCSI device.
  2454. */
  2455. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2456. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2457. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2458. phba->lpfc_rampdown_queue_depth(phba);
  2459. spin_lock_irqsave(&phba->hbalock, iflag);
  2460. }
  2461. if (irsp->ulpStatus) {
  2462. /* Rsp ring <ringno> error: IOCB */
  2463. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2464. "0328 Rsp Ring %d error: "
  2465. "IOCB Data: "
  2466. "x%x x%x x%x x%x "
  2467. "x%x x%x x%x x%x "
  2468. "x%x x%x x%x x%x "
  2469. "x%x x%x x%x x%x\n",
  2470. pring->ringno,
  2471. irsp->un.ulpWord[0],
  2472. irsp->un.ulpWord[1],
  2473. irsp->un.ulpWord[2],
  2474. irsp->un.ulpWord[3],
  2475. irsp->un.ulpWord[4],
  2476. irsp->un.ulpWord[5],
  2477. *(((uint32_t *) irsp) + 6),
  2478. *(((uint32_t *) irsp) + 7),
  2479. *(((uint32_t *) irsp) + 8),
  2480. *(((uint32_t *) irsp) + 9),
  2481. *(((uint32_t *) irsp) + 10),
  2482. *(((uint32_t *) irsp) + 11),
  2483. *(((uint32_t *) irsp) + 12),
  2484. *(((uint32_t *) irsp) + 13),
  2485. *(((uint32_t *) irsp) + 14),
  2486. *(((uint32_t *) irsp) + 15));
  2487. }
  2488. /*
  2489. * Fetch the IOCB command type and call the correct completion
  2490. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2491. * get freed back to the lpfc_iocb_list by the discovery
  2492. * kernel thread.
  2493. */
  2494. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2495. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2496. switch (type) {
  2497. case LPFC_SOL_IOCB:
  2498. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2499. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2500. spin_lock_irqsave(&phba->hbalock, iflag);
  2501. break;
  2502. case LPFC_UNSOL_IOCB:
  2503. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2504. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2505. spin_lock_irqsave(&phba->hbalock, iflag);
  2506. if (!rc)
  2507. free_saveq = 0;
  2508. break;
  2509. case LPFC_ABORT_IOCB:
  2510. cmdiocbp = NULL;
  2511. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2512. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2513. saveq);
  2514. if (cmdiocbp) {
  2515. /* Call the specified completion routine */
  2516. if (cmdiocbp->iocb_cmpl) {
  2517. spin_unlock_irqrestore(&phba->hbalock,
  2518. iflag);
  2519. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2520. saveq);
  2521. spin_lock_irqsave(&phba->hbalock,
  2522. iflag);
  2523. } else
  2524. __lpfc_sli_release_iocbq(phba,
  2525. cmdiocbp);
  2526. }
  2527. break;
  2528. case LPFC_UNKNOWN_IOCB:
  2529. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2530. char adaptermsg[LPFC_MAX_ADPTMSG];
  2531. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2532. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2533. MAX_MSG_DATA);
  2534. dev_warn(&((phba->pcidev)->dev),
  2535. "lpfc%d: %s\n",
  2536. phba->brd_no, adaptermsg);
  2537. } else {
  2538. /* Unknown IOCB command */
  2539. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2540. "0335 Unknown IOCB "
  2541. "command Data: x%x "
  2542. "x%x x%x x%x\n",
  2543. irsp->ulpCommand,
  2544. irsp->ulpStatus,
  2545. irsp->ulpIoTag,
  2546. irsp->ulpContext);
  2547. }
  2548. break;
  2549. }
  2550. if (free_saveq) {
  2551. list_for_each_entry_safe(rspiocbp, next_iocb,
  2552. &saveq->list, list) {
  2553. list_del(&rspiocbp->list);
  2554. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2555. }
  2556. __lpfc_sli_release_iocbq(phba, saveq);
  2557. }
  2558. rspiocbp = NULL;
  2559. }
  2560. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2561. return rspiocbp;
  2562. }
  2563. /**
  2564. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2565. * @phba: Pointer to HBA context object.
  2566. * @pring: Pointer to driver SLI ring object.
  2567. * @mask: Host attention register mask for this ring.
  2568. *
  2569. * This routine wraps the actual slow_ring event process routine from the
  2570. * API jump table function pointer from the lpfc_hba struct.
  2571. **/
  2572. void
  2573. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2574. struct lpfc_sli_ring *pring, uint32_t mask)
  2575. {
  2576. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2577. }
  2578. /**
  2579. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2580. * @phba: Pointer to HBA context object.
  2581. * @pring: Pointer to driver SLI ring object.
  2582. * @mask: Host attention register mask for this ring.
  2583. *
  2584. * This function is called from the worker thread when there is a ring event
  2585. * for non-fcp rings. The caller does not hold any lock. The function will
  2586. * remove each response iocb in the response ring and calls the handle
  2587. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2588. **/
  2589. static void
  2590. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2591. struct lpfc_sli_ring *pring, uint32_t mask)
  2592. {
  2593. struct lpfc_pgp *pgp;
  2594. IOCB_t *entry;
  2595. IOCB_t *irsp = NULL;
  2596. struct lpfc_iocbq *rspiocbp = NULL;
  2597. uint32_t portRspPut, portRspMax;
  2598. unsigned long iflag;
  2599. uint32_t status;
  2600. pgp = &phba->port_gp[pring->ringno];
  2601. spin_lock_irqsave(&phba->hbalock, iflag);
  2602. pring->stats.iocb_event++;
  2603. /*
  2604. * The next available response entry should never exceed the maximum
  2605. * entries. If it does, treat it as an adapter hardware error.
  2606. */
  2607. portRspMax = pring->numRiocb;
  2608. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2609. if (portRspPut >= portRspMax) {
  2610. /*
  2611. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2612. * rsp ring <portRspMax>
  2613. */
  2614. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2615. "0303 Ring %d handler: portRspPut %d "
  2616. "is bigger than rsp ring %d\n",
  2617. pring->ringno, portRspPut, portRspMax);
  2618. phba->link_state = LPFC_HBA_ERROR;
  2619. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2620. phba->work_hs = HS_FFER3;
  2621. lpfc_handle_eratt(phba);
  2622. return;
  2623. }
  2624. rmb();
  2625. while (pring->rspidx != portRspPut) {
  2626. /*
  2627. * Build a completion list and call the appropriate handler.
  2628. * The process is to get the next available response iocb, get
  2629. * a free iocb from the list, copy the response data into the
  2630. * free iocb, insert to the continuation list, and update the
  2631. * next response index to slim. This process makes response
  2632. * iocb's in the ring available to DMA as fast as possible but
  2633. * pays a penalty for a copy operation. Since the iocb is
  2634. * only 32 bytes, this penalty is considered small relative to
  2635. * the PCI reads for register values and a slim write. When
  2636. * the ulpLe field is set, the entire Command has been
  2637. * received.
  2638. */
  2639. entry = lpfc_resp_iocb(phba, pring);
  2640. phba->last_completion_time = jiffies;
  2641. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2642. if (rspiocbp == NULL) {
  2643. printk(KERN_ERR "%s: out of buffers! Failing "
  2644. "completion.\n", __func__);
  2645. break;
  2646. }
  2647. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2648. phba->iocb_rsp_size);
  2649. irsp = &rspiocbp->iocb;
  2650. if (++pring->rspidx >= portRspMax)
  2651. pring->rspidx = 0;
  2652. if (pring->ringno == LPFC_ELS_RING) {
  2653. lpfc_debugfs_slow_ring_trc(phba,
  2654. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2655. *(((uint32_t *) irsp) + 4),
  2656. *(((uint32_t *) irsp) + 6),
  2657. *(((uint32_t *) irsp) + 7));
  2658. }
  2659. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2660. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2661. /* Handle the response IOCB */
  2662. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2663. spin_lock_irqsave(&phba->hbalock, iflag);
  2664. /*
  2665. * If the port response put pointer has not been updated, sync
  2666. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2667. * response put pointer.
  2668. */
  2669. if (pring->rspidx == portRspPut) {
  2670. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2671. }
  2672. } /* while (pring->rspidx != portRspPut) */
  2673. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2674. /* At least one response entry has been freed */
  2675. pring->stats.iocb_rsp_full++;
  2676. /* SET RxRE_RSP in Chip Att register */
  2677. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2678. writel(status, phba->CAregaddr);
  2679. readl(phba->CAregaddr); /* flush */
  2680. }
  2681. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2682. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2683. pring->stats.iocb_cmd_empty++;
  2684. /* Force update of the local copy of cmdGetInx */
  2685. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2686. lpfc_sli_resume_iocb(phba, pring);
  2687. if ((pring->lpfc_sli_cmd_available))
  2688. (pring->lpfc_sli_cmd_available) (phba, pring);
  2689. }
  2690. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2691. return;
  2692. }
  2693. /**
  2694. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2695. * @phba: Pointer to HBA context object.
  2696. * @pring: Pointer to driver SLI ring object.
  2697. * @mask: Host attention register mask for this ring.
  2698. *
  2699. * This function is called from the worker thread when there is a pending
  2700. * ELS response iocb on the driver internal slow-path response iocb worker
  2701. * queue. The caller does not hold any lock. The function will remove each
  2702. * response iocb from the response worker queue and calls the handle
  2703. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2704. **/
  2705. static void
  2706. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2707. struct lpfc_sli_ring *pring, uint32_t mask)
  2708. {
  2709. struct lpfc_iocbq *irspiocbq;
  2710. struct hbq_dmabuf *dmabuf;
  2711. struct lpfc_cq_event *cq_event;
  2712. unsigned long iflag;
  2713. spin_lock_irqsave(&phba->hbalock, iflag);
  2714. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2715. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2716. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2717. /* Get the response iocb from the head of work queue */
  2718. spin_lock_irqsave(&phba->hbalock, iflag);
  2719. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2720. cq_event, struct lpfc_cq_event, list);
  2721. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2722. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2723. case CQE_CODE_COMPL_WQE:
  2724. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2725. cq_event);
  2726. /* Translate ELS WCQE to response IOCBQ */
  2727. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2728. irspiocbq);
  2729. if (irspiocbq)
  2730. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2731. irspiocbq);
  2732. break;
  2733. case CQE_CODE_RECEIVE:
  2734. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2735. cq_event);
  2736. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2737. break;
  2738. default:
  2739. break;
  2740. }
  2741. }
  2742. }
  2743. /**
  2744. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2745. * @phba: Pointer to HBA context object.
  2746. * @pring: Pointer to driver SLI ring object.
  2747. *
  2748. * This function aborts all iocbs in the given ring and frees all the iocb
  2749. * objects in txq. This function issues an abort iocb for all the iocb commands
  2750. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2751. * the return of this function. The caller is not required to hold any locks.
  2752. **/
  2753. void
  2754. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2755. {
  2756. LIST_HEAD(completions);
  2757. struct lpfc_iocbq *iocb, *next_iocb;
  2758. if (pring->ringno == LPFC_ELS_RING) {
  2759. lpfc_fabric_abort_hba(phba);
  2760. }
  2761. /* Error everything on txq and txcmplq
  2762. * First do the txq.
  2763. */
  2764. spin_lock_irq(&phba->hbalock);
  2765. list_splice_init(&pring->txq, &completions);
  2766. pring->txq_cnt = 0;
  2767. /* Next issue ABTS for everything on the txcmplq */
  2768. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2769. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2770. spin_unlock_irq(&phba->hbalock);
  2771. /* Cancel all the IOCBs from the completions list */
  2772. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2773. IOERR_SLI_ABORTED);
  2774. }
  2775. /**
  2776. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2777. * @phba: Pointer to HBA context object.
  2778. *
  2779. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2780. * objects in txq and txcmplq. This function will not issue abort iocbs
  2781. * for all the iocb commands in txcmplq, they will just be returned with
  2782. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2783. * slot has been permanently disabled.
  2784. **/
  2785. void
  2786. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2787. {
  2788. LIST_HEAD(txq);
  2789. LIST_HEAD(txcmplq);
  2790. struct lpfc_sli *psli = &phba->sli;
  2791. struct lpfc_sli_ring *pring;
  2792. /* Currently, only one fcp ring */
  2793. pring = &psli->ring[psli->fcp_ring];
  2794. spin_lock_irq(&phba->hbalock);
  2795. /* Retrieve everything on txq */
  2796. list_splice_init(&pring->txq, &txq);
  2797. pring->txq_cnt = 0;
  2798. /* Retrieve everything on the txcmplq */
  2799. list_splice_init(&pring->txcmplq, &txcmplq);
  2800. pring->txcmplq_cnt = 0;
  2801. spin_unlock_irq(&phba->hbalock);
  2802. /* Flush the txq */
  2803. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2804. IOERR_SLI_DOWN);
  2805. /* Flush the txcmpq */
  2806. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2807. IOERR_SLI_DOWN);
  2808. }
  2809. /**
  2810. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2811. * @phba: Pointer to HBA context object.
  2812. * @mask: Bit mask to be checked.
  2813. *
  2814. * This function reads the host status register and compares
  2815. * with the provided bit mask to check if HBA completed
  2816. * the restart. This function will wait in a loop for the
  2817. * HBA to complete restart. If the HBA does not restart within
  2818. * 15 iterations, the function will reset the HBA again. The
  2819. * function returns 1 when HBA fail to restart otherwise returns
  2820. * zero.
  2821. **/
  2822. static int
  2823. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2824. {
  2825. uint32_t status;
  2826. int i = 0;
  2827. int retval = 0;
  2828. /* Read the HBA Host Status Register */
  2829. status = readl(phba->HSregaddr);
  2830. /*
  2831. * Check status register every 100ms for 5 retries, then every
  2832. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2833. * every 2.5 sec for 4.
  2834. * Break our of the loop if errors occurred during init.
  2835. */
  2836. while (((status & mask) != mask) &&
  2837. !(status & HS_FFERM) &&
  2838. i++ < 20) {
  2839. if (i <= 5)
  2840. msleep(10);
  2841. else if (i <= 10)
  2842. msleep(500);
  2843. else
  2844. msleep(2500);
  2845. if (i == 15) {
  2846. /* Do post */
  2847. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2848. lpfc_sli_brdrestart(phba);
  2849. }
  2850. /* Read the HBA Host Status Register */
  2851. status = readl(phba->HSregaddr);
  2852. }
  2853. /* Check to see if any errors occurred during init */
  2854. if ((status & HS_FFERM) || (i >= 20)) {
  2855. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2856. "2751 Adapter failed to restart, "
  2857. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  2858. status,
  2859. readl(phba->MBslimaddr + 0xa8),
  2860. readl(phba->MBslimaddr + 0xac));
  2861. phba->link_state = LPFC_HBA_ERROR;
  2862. retval = 1;
  2863. }
  2864. return retval;
  2865. }
  2866. /**
  2867. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2868. * @phba: Pointer to HBA context object.
  2869. * @mask: Bit mask to be checked.
  2870. *
  2871. * This function checks the host status register to check if HBA is
  2872. * ready. This function will wait in a loop for the HBA to be ready
  2873. * If the HBA is not ready , the function will will reset the HBA PCI
  2874. * function again. The function returns 1 when HBA fail to be ready
  2875. * otherwise returns zero.
  2876. **/
  2877. static int
  2878. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2879. {
  2880. uint32_t status;
  2881. int retval = 0;
  2882. /* Read the HBA Host Status Register */
  2883. status = lpfc_sli4_post_status_check(phba);
  2884. if (status) {
  2885. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2886. lpfc_sli_brdrestart(phba);
  2887. status = lpfc_sli4_post_status_check(phba);
  2888. }
  2889. /* Check to see if any errors occurred during init */
  2890. if (status) {
  2891. phba->link_state = LPFC_HBA_ERROR;
  2892. retval = 1;
  2893. } else
  2894. phba->sli4_hba.intr_enable = 0;
  2895. return retval;
  2896. }
  2897. /**
  2898. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2899. * @phba: Pointer to HBA context object.
  2900. * @mask: Bit mask to be checked.
  2901. *
  2902. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2903. * from the API jump table function pointer from the lpfc_hba struct.
  2904. **/
  2905. int
  2906. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2907. {
  2908. return phba->lpfc_sli_brdready(phba, mask);
  2909. }
  2910. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2911. /**
  2912. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2913. * @phba: Pointer to HBA context object.
  2914. *
  2915. * This function is called before resetting an HBA. This
  2916. * function requests HBA to quiesce DMAs before a reset.
  2917. **/
  2918. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2919. {
  2920. uint32_t __iomem *resp_buf;
  2921. uint32_t __iomem *mbox_buf;
  2922. volatile uint32_t mbox;
  2923. uint32_t hc_copy;
  2924. int i;
  2925. uint8_t hdrtype;
  2926. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2927. if (hdrtype != 0x80 ||
  2928. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2929. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2930. return;
  2931. /*
  2932. * Tell the other part of the chip to suspend temporarily all
  2933. * its DMA activity.
  2934. */
  2935. resp_buf = phba->MBslimaddr;
  2936. /* Disable the error attention */
  2937. hc_copy = readl(phba->HCregaddr);
  2938. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2939. readl(phba->HCregaddr); /* flush */
  2940. phba->link_flag |= LS_IGNORE_ERATT;
  2941. if (readl(phba->HAregaddr) & HA_ERATT) {
  2942. /* Clear Chip error bit */
  2943. writel(HA_ERATT, phba->HAregaddr);
  2944. phba->pport->stopped = 1;
  2945. }
  2946. mbox = 0;
  2947. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2948. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2949. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2950. mbox_buf = phba->MBslimaddr;
  2951. writel(mbox, mbox_buf);
  2952. for (i = 0;
  2953. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2954. mdelay(1);
  2955. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2956. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2957. phba->pport->stopped)
  2958. goto restore_hc;
  2959. else
  2960. goto clear_errat;
  2961. }
  2962. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2963. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2964. mdelay(1);
  2965. clear_errat:
  2966. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2967. mdelay(1);
  2968. if (readl(phba->HAregaddr) & HA_ERATT) {
  2969. writel(HA_ERATT, phba->HAregaddr);
  2970. phba->pport->stopped = 1;
  2971. }
  2972. restore_hc:
  2973. phba->link_flag &= ~LS_IGNORE_ERATT;
  2974. writel(hc_copy, phba->HCregaddr);
  2975. readl(phba->HCregaddr); /* flush */
  2976. }
  2977. /**
  2978. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  2979. * @phba: Pointer to HBA context object.
  2980. *
  2981. * This function issues a kill_board mailbox command and waits for
  2982. * the error attention interrupt. This function is called for stopping
  2983. * the firmware processing. The caller is not required to hold any
  2984. * locks. This function calls lpfc_hba_down_post function to free
  2985. * any pending commands after the kill. The function will return 1 when it
  2986. * fails to kill the board else will return 0.
  2987. **/
  2988. int
  2989. lpfc_sli_brdkill(struct lpfc_hba *phba)
  2990. {
  2991. struct lpfc_sli *psli;
  2992. LPFC_MBOXQ_t *pmb;
  2993. uint32_t status;
  2994. uint32_t ha_copy;
  2995. int retval;
  2996. int i = 0;
  2997. psli = &phba->sli;
  2998. /* Kill HBA */
  2999. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3000. "0329 Kill HBA Data: x%x x%x\n",
  3001. phba->pport->port_state, psli->sli_flag);
  3002. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3003. if (!pmb)
  3004. return 1;
  3005. /* Disable the error attention */
  3006. spin_lock_irq(&phba->hbalock);
  3007. status = readl(phba->HCregaddr);
  3008. status &= ~HC_ERINT_ENA;
  3009. writel(status, phba->HCregaddr);
  3010. readl(phba->HCregaddr); /* flush */
  3011. phba->link_flag |= LS_IGNORE_ERATT;
  3012. spin_unlock_irq(&phba->hbalock);
  3013. lpfc_kill_board(phba, pmb);
  3014. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3015. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3016. if (retval != MBX_SUCCESS) {
  3017. if (retval != MBX_BUSY)
  3018. mempool_free(pmb, phba->mbox_mem_pool);
  3019. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3020. "2752 KILL_BOARD command failed retval %d\n",
  3021. retval);
  3022. spin_lock_irq(&phba->hbalock);
  3023. phba->link_flag &= ~LS_IGNORE_ERATT;
  3024. spin_unlock_irq(&phba->hbalock);
  3025. return 1;
  3026. }
  3027. spin_lock_irq(&phba->hbalock);
  3028. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3029. spin_unlock_irq(&phba->hbalock);
  3030. mempool_free(pmb, phba->mbox_mem_pool);
  3031. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3032. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3033. * 3 seconds we still set HBA_ERROR state because the status of the
  3034. * board is now undefined.
  3035. */
  3036. ha_copy = readl(phba->HAregaddr);
  3037. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3038. mdelay(100);
  3039. ha_copy = readl(phba->HAregaddr);
  3040. }
  3041. del_timer_sync(&psli->mbox_tmo);
  3042. if (ha_copy & HA_ERATT) {
  3043. writel(HA_ERATT, phba->HAregaddr);
  3044. phba->pport->stopped = 1;
  3045. }
  3046. spin_lock_irq(&phba->hbalock);
  3047. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3048. psli->mbox_active = NULL;
  3049. phba->link_flag &= ~LS_IGNORE_ERATT;
  3050. spin_unlock_irq(&phba->hbalock);
  3051. lpfc_hba_down_post(phba);
  3052. phba->link_state = LPFC_HBA_ERROR;
  3053. return ha_copy & HA_ERATT ? 0 : 1;
  3054. }
  3055. /**
  3056. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3057. * @phba: Pointer to HBA context object.
  3058. *
  3059. * This function resets the HBA by writing HC_INITFF to the control
  3060. * register. After the HBA resets, this function resets all the iocb ring
  3061. * indices. This function disables PCI layer parity checking during
  3062. * the reset.
  3063. * This function returns 0 always.
  3064. * The caller is not required to hold any locks.
  3065. **/
  3066. int
  3067. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3068. {
  3069. struct lpfc_sli *psli;
  3070. struct lpfc_sli_ring *pring;
  3071. uint16_t cfg_value;
  3072. int i;
  3073. psli = &phba->sli;
  3074. /* Reset HBA */
  3075. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3076. "0325 Reset HBA Data: x%x x%x\n",
  3077. phba->pport->port_state, psli->sli_flag);
  3078. /* perform board reset */
  3079. phba->fc_eventTag = 0;
  3080. phba->link_events = 0;
  3081. phba->pport->fc_myDID = 0;
  3082. phba->pport->fc_prevDID = 0;
  3083. /* Turn off parity checking and serr during the physical reset */
  3084. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3085. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3086. (cfg_value &
  3087. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3088. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3089. /* Now toggle INITFF bit in the Host Control Register */
  3090. writel(HC_INITFF, phba->HCregaddr);
  3091. mdelay(1);
  3092. readl(phba->HCregaddr); /* flush */
  3093. writel(0, phba->HCregaddr);
  3094. readl(phba->HCregaddr); /* flush */
  3095. /* Restore PCI cmd register */
  3096. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3097. /* Initialize relevant SLI info */
  3098. for (i = 0; i < psli->num_rings; i++) {
  3099. pring = &psli->ring[i];
  3100. pring->flag = 0;
  3101. pring->rspidx = 0;
  3102. pring->next_cmdidx = 0;
  3103. pring->local_getidx = 0;
  3104. pring->cmdidx = 0;
  3105. pring->missbufcnt = 0;
  3106. }
  3107. phba->link_state = LPFC_WARM_START;
  3108. return 0;
  3109. }
  3110. /**
  3111. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3112. * @phba: Pointer to HBA context object.
  3113. *
  3114. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3115. * checking during resets the device. The caller is not required to hold
  3116. * any locks.
  3117. *
  3118. * This function returns 0 always.
  3119. **/
  3120. int
  3121. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3122. {
  3123. struct lpfc_sli *psli = &phba->sli;
  3124. uint16_t cfg_value;
  3125. uint8_t qindx;
  3126. /* Reset HBA */
  3127. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3128. "0295 Reset HBA Data: x%x x%x\n",
  3129. phba->pport->port_state, psli->sli_flag);
  3130. /* perform board reset */
  3131. phba->fc_eventTag = 0;
  3132. phba->link_events = 0;
  3133. phba->pport->fc_myDID = 0;
  3134. phba->pport->fc_prevDID = 0;
  3135. /* Turn off parity checking and serr during the physical reset */
  3136. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3137. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3138. (cfg_value &
  3139. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3140. spin_lock_irq(&phba->hbalock);
  3141. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3142. phba->fcf.fcf_flag = 0;
  3143. /* Clean up the child queue list for the CQs */
  3144. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3145. list_del_init(&phba->sli4_hba.els_wq->list);
  3146. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3147. list_del_init(&phba->sli4_hba.dat_rq->list);
  3148. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3149. list_del_init(&phba->sli4_hba.els_cq->list);
  3150. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3151. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3152. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3153. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3154. spin_unlock_irq(&phba->hbalock);
  3155. /* Now physically reset the device */
  3156. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3157. "0389 Performing PCI function reset!\n");
  3158. /* Perform FCoE PCI function reset */
  3159. lpfc_pci_function_reset(phba);
  3160. return 0;
  3161. }
  3162. /**
  3163. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3164. * @phba: Pointer to HBA context object.
  3165. *
  3166. * This function is called in the SLI initialization code path to
  3167. * restart the HBA. The caller is not required to hold any lock.
  3168. * This function writes MBX_RESTART mailbox command to the SLIM and
  3169. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3170. * function to free any pending commands. The function enables
  3171. * POST only during the first initialization. The function returns zero.
  3172. * The function does not guarantee completion of MBX_RESTART mailbox
  3173. * command before the return of this function.
  3174. **/
  3175. static int
  3176. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3177. {
  3178. MAILBOX_t *mb;
  3179. struct lpfc_sli *psli;
  3180. volatile uint32_t word0;
  3181. void __iomem *to_slim;
  3182. uint32_t hba_aer_enabled;
  3183. spin_lock_irq(&phba->hbalock);
  3184. /* Take PCIe device Advanced Error Reporting (AER) state */
  3185. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3186. psli = &phba->sli;
  3187. /* Restart HBA */
  3188. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3189. "0337 Restart HBA Data: x%x x%x\n",
  3190. phba->pport->port_state, psli->sli_flag);
  3191. word0 = 0;
  3192. mb = (MAILBOX_t *) &word0;
  3193. mb->mbxCommand = MBX_RESTART;
  3194. mb->mbxHc = 1;
  3195. lpfc_reset_barrier(phba);
  3196. to_slim = phba->MBslimaddr;
  3197. writel(*(uint32_t *) mb, to_slim);
  3198. readl(to_slim); /* flush */
  3199. /* Only skip post after fc_ffinit is completed */
  3200. if (phba->pport->port_state)
  3201. word0 = 1; /* This is really setting up word1 */
  3202. else
  3203. word0 = 0; /* This is really setting up word1 */
  3204. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3205. writel(*(uint32_t *) mb, to_slim);
  3206. readl(to_slim); /* flush */
  3207. lpfc_sli_brdreset(phba);
  3208. phba->pport->stopped = 0;
  3209. phba->link_state = LPFC_INIT_START;
  3210. phba->hba_flag = 0;
  3211. spin_unlock_irq(&phba->hbalock);
  3212. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3213. psli->stats_start = get_seconds();
  3214. /* Give the INITFF and Post time to settle. */
  3215. mdelay(100);
  3216. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3217. if (hba_aer_enabled)
  3218. pci_disable_pcie_error_reporting(phba->pcidev);
  3219. lpfc_hba_down_post(phba);
  3220. return 0;
  3221. }
  3222. /**
  3223. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3224. * @phba: Pointer to HBA context object.
  3225. *
  3226. * This function is called in the SLI initialization code path to restart
  3227. * a SLI4 HBA. The caller is not required to hold any lock.
  3228. * At the end of the function, it calls lpfc_hba_down_post function to
  3229. * free any pending commands.
  3230. **/
  3231. static int
  3232. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3233. {
  3234. struct lpfc_sli *psli = &phba->sli;
  3235. /* Restart HBA */
  3236. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3237. "0296 Restart HBA Data: x%x x%x\n",
  3238. phba->pport->port_state, psli->sli_flag);
  3239. lpfc_sli4_brdreset(phba);
  3240. spin_lock_irq(&phba->hbalock);
  3241. phba->pport->stopped = 0;
  3242. phba->link_state = LPFC_INIT_START;
  3243. phba->hba_flag = 0;
  3244. spin_unlock_irq(&phba->hbalock);
  3245. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3246. psli->stats_start = get_seconds();
  3247. lpfc_hba_down_post(phba);
  3248. return 0;
  3249. }
  3250. /**
  3251. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3252. * @phba: Pointer to HBA context object.
  3253. *
  3254. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3255. * API jump table function pointer from the lpfc_hba struct.
  3256. **/
  3257. int
  3258. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3259. {
  3260. return phba->lpfc_sli_brdrestart(phba);
  3261. }
  3262. /**
  3263. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3264. * @phba: Pointer to HBA context object.
  3265. *
  3266. * This function is called after a HBA restart to wait for successful
  3267. * restart of the HBA. Successful restart of the HBA is indicated by
  3268. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3269. * iteration, the function will restart the HBA again. The function returns
  3270. * zero if HBA successfully restarted else returns negative error code.
  3271. **/
  3272. static int
  3273. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3274. {
  3275. uint32_t status, i = 0;
  3276. /* Read the HBA Host Status Register */
  3277. status = readl(phba->HSregaddr);
  3278. /* Check status register to see what current state is */
  3279. i = 0;
  3280. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3281. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3282. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3283. * 4.
  3284. */
  3285. if (i++ >= 20) {
  3286. /* Adapter failed to init, timeout, status reg
  3287. <status> */
  3288. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3289. "0436 Adapter failed to init, "
  3290. "timeout, status reg x%x, "
  3291. "FW Data: A8 x%x AC x%x\n", status,
  3292. readl(phba->MBslimaddr + 0xa8),
  3293. readl(phba->MBslimaddr + 0xac));
  3294. phba->link_state = LPFC_HBA_ERROR;
  3295. return -ETIMEDOUT;
  3296. }
  3297. /* Check to see if any errors occurred during init */
  3298. if (status & HS_FFERM) {
  3299. /* ERROR: During chipset initialization */
  3300. /* Adapter failed to init, chipset, status reg
  3301. <status> */
  3302. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3303. "0437 Adapter failed to init, "
  3304. "chipset, status reg x%x, "
  3305. "FW Data: A8 x%x AC x%x\n", status,
  3306. readl(phba->MBslimaddr + 0xa8),
  3307. readl(phba->MBslimaddr + 0xac));
  3308. phba->link_state = LPFC_HBA_ERROR;
  3309. return -EIO;
  3310. }
  3311. if (i <= 5) {
  3312. msleep(10);
  3313. } else if (i <= 10) {
  3314. msleep(500);
  3315. } else {
  3316. msleep(2500);
  3317. }
  3318. if (i == 15) {
  3319. /* Do post */
  3320. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3321. lpfc_sli_brdrestart(phba);
  3322. }
  3323. /* Read the HBA Host Status Register */
  3324. status = readl(phba->HSregaddr);
  3325. }
  3326. /* Check to see if any errors occurred during init */
  3327. if (status & HS_FFERM) {
  3328. /* ERROR: During chipset initialization */
  3329. /* Adapter failed to init, chipset, status reg <status> */
  3330. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3331. "0438 Adapter failed to init, chipset, "
  3332. "status reg x%x, "
  3333. "FW Data: A8 x%x AC x%x\n", status,
  3334. readl(phba->MBslimaddr + 0xa8),
  3335. readl(phba->MBslimaddr + 0xac));
  3336. phba->link_state = LPFC_HBA_ERROR;
  3337. return -EIO;
  3338. }
  3339. /* Clear all interrupt enable conditions */
  3340. writel(0, phba->HCregaddr);
  3341. readl(phba->HCregaddr); /* flush */
  3342. /* setup host attn register */
  3343. writel(0xffffffff, phba->HAregaddr);
  3344. readl(phba->HAregaddr); /* flush */
  3345. return 0;
  3346. }
  3347. /**
  3348. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3349. *
  3350. * This function calculates and returns the number of HBQs required to be
  3351. * configured.
  3352. **/
  3353. int
  3354. lpfc_sli_hbq_count(void)
  3355. {
  3356. return ARRAY_SIZE(lpfc_hbq_defs);
  3357. }
  3358. /**
  3359. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3360. *
  3361. * This function adds the number of hbq entries in every HBQ to get
  3362. * the total number of hbq entries required for the HBA and returns
  3363. * the total count.
  3364. **/
  3365. static int
  3366. lpfc_sli_hbq_entry_count(void)
  3367. {
  3368. int hbq_count = lpfc_sli_hbq_count();
  3369. int count = 0;
  3370. int i;
  3371. for (i = 0; i < hbq_count; ++i)
  3372. count += lpfc_hbq_defs[i]->entry_count;
  3373. return count;
  3374. }
  3375. /**
  3376. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3377. *
  3378. * This function calculates amount of memory required for all hbq entries
  3379. * to be configured and returns the total memory required.
  3380. **/
  3381. int
  3382. lpfc_sli_hbq_size(void)
  3383. {
  3384. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3385. }
  3386. /**
  3387. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3388. * @phba: Pointer to HBA context object.
  3389. *
  3390. * This function is called during the SLI initialization to configure
  3391. * all the HBQs and post buffers to the HBQ. The caller is not
  3392. * required to hold any locks. This function will return zero if successful
  3393. * else it will return negative error code.
  3394. **/
  3395. static int
  3396. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3397. {
  3398. int hbq_count = lpfc_sli_hbq_count();
  3399. LPFC_MBOXQ_t *pmb;
  3400. MAILBOX_t *pmbox;
  3401. uint32_t hbqno;
  3402. uint32_t hbq_entry_index;
  3403. /* Get a Mailbox buffer to setup mailbox
  3404. * commands for HBA initialization
  3405. */
  3406. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3407. if (!pmb)
  3408. return -ENOMEM;
  3409. pmbox = &pmb->u.mb;
  3410. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3411. phba->link_state = LPFC_INIT_MBX_CMDS;
  3412. phba->hbq_in_use = 1;
  3413. hbq_entry_index = 0;
  3414. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3415. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3416. phba->hbqs[hbqno].hbqPutIdx = 0;
  3417. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3418. phba->hbqs[hbqno].entry_count =
  3419. lpfc_hbq_defs[hbqno]->entry_count;
  3420. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3421. hbq_entry_index, pmb);
  3422. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3423. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3424. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3425. mbxStatus <status>, ring <num> */
  3426. lpfc_printf_log(phba, KERN_ERR,
  3427. LOG_SLI | LOG_VPORT,
  3428. "1805 Adapter failed to init. "
  3429. "Data: x%x x%x x%x\n",
  3430. pmbox->mbxCommand,
  3431. pmbox->mbxStatus, hbqno);
  3432. phba->link_state = LPFC_HBA_ERROR;
  3433. mempool_free(pmb, phba->mbox_mem_pool);
  3434. return ENXIO;
  3435. }
  3436. }
  3437. phba->hbq_count = hbq_count;
  3438. mempool_free(pmb, phba->mbox_mem_pool);
  3439. /* Initially populate or replenish the HBQs */
  3440. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3441. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3442. return 0;
  3443. }
  3444. /**
  3445. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3446. * @phba: Pointer to HBA context object.
  3447. *
  3448. * This function is called during the SLI initialization to configure
  3449. * all the HBQs and post buffers to the HBQ. The caller is not
  3450. * required to hold any locks. This function will return zero if successful
  3451. * else it will return negative error code.
  3452. **/
  3453. static int
  3454. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3455. {
  3456. phba->hbq_in_use = 1;
  3457. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3458. phba->hbq_count = 1;
  3459. /* Initially populate or replenish the HBQs */
  3460. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3461. return 0;
  3462. }
  3463. /**
  3464. * lpfc_sli_config_port - Issue config port mailbox command
  3465. * @phba: Pointer to HBA context object.
  3466. * @sli_mode: sli mode - 2/3
  3467. *
  3468. * This function is called by the sli intialization code path
  3469. * to issue config_port mailbox command. This function restarts the
  3470. * HBA firmware and issues a config_port mailbox command to configure
  3471. * the SLI interface in the sli mode specified by sli_mode
  3472. * variable. The caller is not required to hold any locks.
  3473. * The function returns 0 if successful, else returns negative error
  3474. * code.
  3475. **/
  3476. int
  3477. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3478. {
  3479. LPFC_MBOXQ_t *pmb;
  3480. uint32_t resetcount = 0, rc = 0, done = 0;
  3481. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3482. if (!pmb) {
  3483. phba->link_state = LPFC_HBA_ERROR;
  3484. return -ENOMEM;
  3485. }
  3486. phba->sli_rev = sli_mode;
  3487. while (resetcount < 2 && !done) {
  3488. spin_lock_irq(&phba->hbalock);
  3489. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3490. spin_unlock_irq(&phba->hbalock);
  3491. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3492. lpfc_sli_brdrestart(phba);
  3493. rc = lpfc_sli_chipset_init(phba);
  3494. if (rc)
  3495. break;
  3496. spin_lock_irq(&phba->hbalock);
  3497. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3498. spin_unlock_irq(&phba->hbalock);
  3499. resetcount++;
  3500. /* Call pre CONFIG_PORT mailbox command initialization. A
  3501. * value of 0 means the call was successful. Any other
  3502. * nonzero value is a failure, but if ERESTART is returned,
  3503. * the driver may reset the HBA and try again.
  3504. */
  3505. rc = lpfc_config_port_prep(phba);
  3506. if (rc == -ERESTART) {
  3507. phba->link_state = LPFC_LINK_UNKNOWN;
  3508. continue;
  3509. } else if (rc)
  3510. break;
  3511. phba->link_state = LPFC_INIT_MBX_CMDS;
  3512. lpfc_config_port(phba, pmb);
  3513. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3514. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3515. LPFC_SLI3_HBQ_ENABLED |
  3516. LPFC_SLI3_CRP_ENABLED |
  3517. LPFC_SLI3_INB_ENABLED |
  3518. LPFC_SLI3_BG_ENABLED);
  3519. if (rc != MBX_SUCCESS) {
  3520. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3521. "0442 Adapter failed to init, mbxCmd x%x "
  3522. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3523. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3524. spin_lock_irq(&phba->hbalock);
  3525. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3526. spin_unlock_irq(&phba->hbalock);
  3527. rc = -ENXIO;
  3528. } else {
  3529. /* Allow asynchronous mailbox command to go through */
  3530. spin_lock_irq(&phba->hbalock);
  3531. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3532. spin_unlock_irq(&phba->hbalock);
  3533. done = 1;
  3534. }
  3535. }
  3536. if (!done) {
  3537. rc = -EINVAL;
  3538. goto do_prep_failed;
  3539. }
  3540. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3541. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3542. rc = -ENXIO;
  3543. goto do_prep_failed;
  3544. }
  3545. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3546. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3547. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3548. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3549. phba->max_vpi : phba->max_vports;
  3550. } else
  3551. phba->max_vpi = 0;
  3552. if (pmb->u.mb.un.varCfgPort.gdss)
  3553. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3554. if (pmb->u.mb.un.varCfgPort.gerbm)
  3555. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3556. if (pmb->u.mb.un.varCfgPort.gcrp)
  3557. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3558. if (pmb->u.mb.un.varCfgPort.ginb) {
  3559. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3560. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3561. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3562. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3563. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3564. phba->inb_last_counter =
  3565. phba->mbox->us.s3_inb_pgp.counter;
  3566. } else {
  3567. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3568. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3569. phba->inb_ha_copy = NULL;
  3570. phba->inb_counter = NULL;
  3571. }
  3572. if (phba->cfg_enable_bg) {
  3573. if (pmb->u.mb.un.varCfgPort.gbg)
  3574. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3575. else
  3576. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3577. "0443 Adapter did not grant "
  3578. "BlockGuard\n");
  3579. }
  3580. } else {
  3581. phba->hbq_get = NULL;
  3582. phba->port_gp = phba->mbox->us.s2.port;
  3583. phba->inb_ha_copy = NULL;
  3584. phba->inb_counter = NULL;
  3585. phba->max_vpi = 0;
  3586. }
  3587. do_prep_failed:
  3588. mempool_free(pmb, phba->mbox_mem_pool);
  3589. return rc;
  3590. }
  3591. /**
  3592. * lpfc_sli_hba_setup - SLI intialization function
  3593. * @phba: Pointer to HBA context object.
  3594. *
  3595. * This function is the main SLI intialization function. This function
  3596. * is called by the HBA intialization code, HBA reset code and HBA
  3597. * error attention handler code. Caller is not required to hold any
  3598. * locks. This function issues config_port mailbox command to configure
  3599. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3600. * calls the config_port_post function to issue init_link mailbox
  3601. * command and to start the discovery. The function will return zero
  3602. * if successful, else it will return negative error code.
  3603. **/
  3604. int
  3605. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3606. {
  3607. uint32_t rc;
  3608. int mode = 3;
  3609. switch (lpfc_sli_mode) {
  3610. case 2:
  3611. if (phba->cfg_enable_npiv) {
  3612. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3613. "1824 NPIV enabled: Override lpfc_sli_mode "
  3614. "parameter (%d) to auto (0).\n",
  3615. lpfc_sli_mode);
  3616. break;
  3617. }
  3618. mode = 2;
  3619. break;
  3620. case 0:
  3621. case 3:
  3622. break;
  3623. default:
  3624. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3625. "1819 Unrecognized lpfc_sli_mode "
  3626. "parameter: %d.\n", lpfc_sli_mode);
  3627. break;
  3628. }
  3629. rc = lpfc_sli_config_port(phba, mode);
  3630. if (rc && lpfc_sli_mode == 3)
  3631. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3632. "1820 Unable to select SLI-3. "
  3633. "Not supported by adapter.\n");
  3634. if (rc && mode != 2)
  3635. rc = lpfc_sli_config_port(phba, 2);
  3636. if (rc)
  3637. goto lpfc_sli_hba_setup_error;
  3638. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3639. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3640. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3641. if (!rc) {
  3642. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3643. "2709 This device supports "
  3644. "Advanced Error Reporting (AER)\n");
  3645. spin_lock_irq(&phba->hbalock);
  3646. phba->hba_flag |= HBA_AER_ENABLED;
  3647. spin_unlock_irq(&phba->hbalock);
  3648. } else {
  3649. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3650. "2708 This device does not support "
  3651. "Advanced Error Reporting (AER)\n");
  3652. phba->cfg_aer_support = 0;
  3653. }
  3654. }
  3655. if (phba->sli_rev == 3) {
  3656. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3657. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3658. } else {
  3659. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3660. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3661. phba->sli3_options = 0;
  3662. }
  3663. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3664. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3665. phba->sli_rev, phba->max_vpi);
  3666. rc = lpfc_sli_ring_map(phba);
  3667. if (rc)
  3668. goto lpfc_sli_hba_setup_error;
  3669. /* Init HBQs */
  3670. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3671. rc = lpfc_sli_hbq_setup(phba);
  3672. if (rc)
  3673. goto lpfc_sli_hba_setup_error;
  3674. }
  3675. spin_lock_irq(&phba->hbalock);
  3676. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3677. spin_unlock_irq(&phba->hbalock);
  3678. rc = lpfc_config_port_post(phba);
  3679. if (rc)
  3680. goto lpfc_sli_hba_setup_error;
  3681. return rc;
  3682. lpfc_sli_hba_setup_error:
  3683. phba->link_state = LPFC_HBA_ERROR;
  3684. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3685. "0445 Firmware initialization failed\n");
  3686. return rc;
  3687. }
  3688. /**
  3689. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3690. * @phba: Pointer to HBA context object.
  3691. * @mboxq: mailbox pointer.
  3692. * This function issue a dump mailbox command to read config region
  3693. * 23 and parse the records in the region and populate driver
  3694. * data structure.
  3695. **/
  3696. static int
  3697. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3698. LPFC_MBOXQ_t *mboxq)
  3699. {
  3700. struct lpfc_dmabuf *mp;
  3701. struct lpfc_mqe *mqe;
  3702. uint32_t data_length;
  3703. int rc;
  3704. /* Program the default value of vlan_id and fc_map */
  3705. phba->valid_vlan = 0;
  3706. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3707. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3708. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3709. mqe = &mboxq->u.mqe;
  3710. if (lpfc_dump_fcoe_param(phba, mboxq))
  3711. return -ENOMEM;
  3712. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3713. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3714. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3715. "(%d):2571 Mailbox cmd x%x Status x%x "
  3716. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3717. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3718. "CQ: x%x x%x x%x x%x\n",
  3719. mboxq->vport ? mboxq->vport->vpi : 0,
  3720. bf_get(lpfc_mqe_command, mqe),
  3721. bf_get(lpfc_mqe_status, mqe),
  3722. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3723. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3724. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3725. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3726. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3727. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3728. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3729. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3730. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3731. mboxq->mcqe.word0,
  3732. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3733. mboxq->mcqe.trailer);
  3734. if (rc) {
  3735. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3736. kfree(mp);
  3737. return -EIO;
  3738. }
  3739. data_length = mqe->un.mb_words[5];
  3740. if (data_length > DMP_RGN23_SIZE) {
  3741. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3742. kfree(mp);
  3743. return -EIO;
  3744. }
  3745. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3746. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3747. kfree(mp);
  3748. return 0;
  3749. }
  3750. /**
  3751. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3752. * @phba: pointer to lpfc hba data structure.
  3753. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3754. * @vpd: pointer to the memory to hold resulting port vpd data.
  3755. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3756. * On output, the number of data bytes in @vpd.
  3757. *
  3758. * This routine executes a READ_REV SLI4 mailbox command. In
  3759. * addition, this routine gets the port vpd data.
  3760. *
  3761. * Return codes
  3762. * 0 - successful
  3763. * ENOMEM - could not allocated memory.
  3764. **/
  3765. static int
  3766. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3767. uint8_t *vpd, uint32_t *vpd_size)
  3768. {
  3769. int rc = 0;
  3770. uint32_t dma_size;
  3771. struct lpfc_dmabuf *dmabuf;
  3772. struct lpfc_mqe *mqe;
  3773. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3774. if (!dmabuf)
  3775. return -ENOMEM;
  3776. /*
  3777. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3778. * mailbox command.
  3779. */
  3780. dma_size = *vpd_size;
  3781. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3782. dma_size,
  3783. &dmabuf->phys,
  3784. GFP_KERNEL);
  3785. if (!dmabuf->virt) {
  3786. kfree(dmabuf);
  3787. return -ENOMEM;
  3788. }
  3789. memset(dmabuf->virt, 0, dma_size);
  3790. /*
  3791. * The SLI4 implementation of READ_REV conflicts at word1,
  3792. * bits 31:16 and SLI4 adds vpd functionality not present
  3793. * in SLI3. This code corrects the conflicts.
  3794. */
  3795. lpfc_read_rev(phba, mboxq);
  3796. mqe = &mboxq->u.mqe;
  3797. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3798. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3799. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3800. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3801. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3802. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3803. if (rc) {
  3804. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3805. dmabuf->virt, dmabuf->phys);
  3806. kfree(dmabuf);
  3807. return -EIO;
  3808. }
  3809. /*
  3810. * The available vpd length cannot be bigger than the
  3811. * DMA buffer passed to the port. Catch the less than
  3812. * case and update the caller's size.
  3813. */
  3814. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3815. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3816. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3817. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3818. dmabuf->virt, dmabuf->phys);
  3819. kfree(dmabuf);
  3820. return 0;
  3821. }
  3822. /**
  3823. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3824. * @phba: pointer to lpfc hba data structure.
  3825. *
  3826. * This routine is called to explicitly arm the SLI4 device's completion and
  3827. * event queues
  3828. **/
  3829. static void
  3830. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3831. {
  3832. uint8_t fcp_eqidx;
  3833. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3834. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3835. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3836. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3837. LPFC_QUEUE_REARM);
  3838. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3839. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3840. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3841. LPFC_QUEUE_REARM);
  3842. }
  3843. /**
  3844. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3845. * @phba: Pointer to HBA context object.
  3846. *
  3847. * This function is the main SLI4 device intialization PCI function. This
  3848. * function is called by the HBA intialization code, HBA reset code and
  3849. * HBA error attention handler code. Caller is not required to hold any
  3850. * locks.
  3851. **/
  3852. int
  3853. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3854. {
  3855. int rc;
  3856. LPFC_MBOXQ_t *mboxq;
  3857. struct lpfc_mqe *mqe;
  3858. uint8_t *vpd;
  3859. uint32_t vpd_size;
  3860. uint32_t ftr_rsp = 0;
  3861. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3862. struct lpfc_vport *vport = phba->pport;
  3863. struct lpfc_dmabuf *mp;
  3864. /* Perform a PCI function reset to start from clean */
  3865. rc = lpfc_pci_function_reset(phba);
  3866. if (unlikely(rc))
  3867. return -ENODEV;
  3868. /* Check the HBA Host Status Register for readyness */
  3869. rc = lpfc_sli4_post_status_check(phba);
  3870. if (unlikely(rc))
  3871. return -ENODEV;
  3872. else {
  3873. spin_lock_irq(&phba->hbalock);
  3874. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3875. spin_unlock_irq(&phba->hbalock);
  3876. }
  3877. /*
  3878. * Allocate a single mailbox container for initializing the
  3879. * port.
  3880. */
  3881. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3882. if (!mboxq)
  3883. return -ENOMEM;
  3884. /*
  3885. * Continue initialization with default values even if driver failed
  3886. * to read FCoE param config regions
  3887. */
  3888. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3889. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3890. "2570 Failed to read FCoE parameters\n");
  3891. /* Issue READ_REV to collect vpd and FW information. */
  3892. vpd_size = PAGE_SIZE;
  3893. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3894. if (!vpd) {
  3895. rc = -ENOMEM;
  3896. goto out_free_mbox;
  3897. }
  3898. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3899. if (unlikely(rc))
  3900. goto out_free_vpd;
  3901. mqe = &mboxq->u.mqe;
  3902. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3903. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3904. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3905. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3906. LPFC_DCBX_CEE_MODE)
  3907. phba->hba_flag |= HBA_FIP_SUPPORT;
  3908. else
  3909. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3910. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3911. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3912. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3913. "0376 READ_REV Error. SLI Level %d "
  3914. "FCoE enabled %d\n",
  3915. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3916. rc = -EIO;
  3917. goto out_free_vpd;
  3918. }
  3919. /*
  3920. * Evaluate the read rev and vpd data. Populate the driver
  3921. * state with the results. If this routine fails, the failure
  3922. * is not fatal as the driver will use generic values.
  3923. */
  3924. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3925. if (unlikely(!rc)) {
  3926. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3927. "0377 Error %d parsing vpd. "
  3928. "Using defaults.\n", rc);
  3929. rc = 0;
  3930. }
  3931. /* Save information as VPD data */
  3932. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3933. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3934. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3935. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3936. &mqe->un.read_rev);
  3937. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3938. &mqe->un.read_rev);
  3939. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3940. &mqe->un.read_rev);
  3941. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3942. &mqe->un.read_rev);
  3943. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3944. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3945. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3946. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3947. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3948. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3949. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3950. "(%d):0380 READ_REV Status x%x "
  3951. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3952. mboxq->vport ? mboxq->vport->vpi : 0,
  3953. bf_get(lpfc_mqe_status, mqe),
  3954. phba->vpd.rev.opFwName,
  3955. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3956. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3957. /*
  3958. * Discover the port's supported feature set and match it against the
  3959. * hosts requests.
  3960. */
  3961. lpfc_request_features(phba, mboxq);
  3962. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3963. if (unlikely(rc)) {
  3964. rc = -EIO;
  3965. goto out_free_vpd;
  3966. }
  3967. /*
  3968. * The port must support FCP initiator mode as this is the
  3969. * only mode running in the host.
  3970. */
  3971. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3972. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3973. "0378 No support for fcpi mode.\n");
  3974. ftr_rsp++;
  3975. }
  3976. /*
  3977. * If the port cannot support the host's requested features
  3978. * then turn off the global config parameters to disable the
  3979. * feature in the driver. This is not a fatal error.
  3980. */
  3981. if ((phba->cfg_enable_bg) &&
  3982. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3983. ftr_rsp++;
  3984. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3985. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3986. ftr_rsp++;
  3987. if (ftr_rsp) {
  3988. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3989. "0379 Feature Mismatch Data: x%08x %08x "
  3990. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3991. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3992. phba->cfg_enable_npiv, phba->max_vpi);
  3993. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3994. phba->cfg_enable_bg = 0;
  3995. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3996. phba->cfg_enable_npiv = 0;
  3997. }
  3998. /* These SLI3 features are assumed in SLI4 */
  3999. spin_lock_irq(&phba->hbalock);
  4000. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4001. spin_unlock_irq(&phba->hbalock);
  4002. /* Read the port's service parameters. */
  4003. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4004. if (rc) {
  4005. phba->link_state = LPFC_HBA_ERROR;
  4006. rc = -ENOMEM;
  4007. goto out_free_vpd;
  4008. }
  4009. mboxq->vport = vport;
  4010. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4011. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4012. if (rc == MBX_SUCCESS) {
  4013. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4014. rc = 0;
  4015. }
  4016. /*
  4017. * This memory was allocated by the lpfc_read_sparam routine. Release
  4018. * it to the mbuf pool.
  4019. */
  4020. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4021. kfree(mp);
  4022. mboxq->context1 = NULL;
  4023. if (unlikely(rc)) {
  4024. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4025. "0382 READ_SPARAM command failed "
  4026. "status %d, mbxStatus x%x\n",
  4027. rc, bf_get(lpfc_mqe_status, mqe));
  4028. phba->link_state = LPFC_HBA_ERROR;
  4029. rc = -EIO;
  4030. goto out_free_vpd;
  4031. }
  4032. if (phba->cfg_soft_wwnn)
  4033. u64_to_wwn(phba->cfg_soft_wwnn,
  4034. vport->fc_sparam.nodeName.u.wwn);
  4035. if (phba->cfg_soft_wwpn)
  4036. u64_to_wwn(phba->cfg_soft_wwpn,
  4037. vport->fc_sparam.portName.u.wwn);
  4038. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4039. sizeof(struct lpfc_name));
  4040. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4041. sizeof(struct lpfc_name));
  4042. /* Update the fc_host data structures with new wwn. */
  4043. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4044. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4045. /* Register SGL pool to the device using non-embedded mailbox command */
  4046. rc = lpfc_sli4_post_sgl_list(phba);
  4047. if (unlikely(rc)) {
  4048. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4049. "0582 Error %d during sgl post operation\n",
  4050. rc);
  4051. rc = -ENODEV;
  4052. goto out_free_vpd;
  4053. }
  4054. /* Register SCSI SGL pool to the device */
  4055. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4056. if (unlikely(rc)) {
  4057. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4058. "0383 Error %d during scsi sgl post "
  4059. "operation\n", rc);
  4060. /* Some Scsi buffers were moved to the abort scsi list */
  4061. /* A pci function reset will repost them */
  4062. rc = -ENODEV;
  4063. goto out_free_vpd;
  4064. }
  4065. /* Post the rpi header region to the device. */
  4066. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4067. if (unlikely(rc)) {
  4068. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4069. "0393 Error %d during rpi post operation\n",
  4070. rc);
  4071. rc = -ENODEV;
  4072. goto out_free_vpd;
  4073. }
  4074. /* Set up all the queues to the device */
  4075. rc = lpfc_sli4_queue_setup(phba);
  4076. if (unlikely(rc)) {
  4077. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4078. "0381 Error %d during queue setup.\n ", rc);
  4079. goto out_stop_timers;
  4080. }
  4081. /* Arm the CQs and then EQs on device */
  4082. lpfc_sli4_arm_cqeq_intr(phba);
  4083. /* Indicate device interrupt mode */
  4084. phba->sli4_hba.intr_enable = 1;
  4085. /* Allow asynchronous mailbox command to go through */
  4086. spin_lock_irq(&phba->hbalock);
  4087. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4088. spin_unlock_irq(&phba->hbalock);
  4089. /* Post receive buffers to the device */
  4090. lpfc_sli4_rb_setup(phba);
  4091. /* Reset HBA FCF states after HBA reset */
  4092. phba->fcf.fcf_flag = 0;
  4093. phba->fcf.current_rec.flag = 0;
  4094. /* Start the ELS watchdog timer */
  4095. mod_timer(&vport->els_tmofunc,
  4096. jiffies + HZ * (phba->fc_ratov * 2));
  4097. /* Start heart beat timer */
  4098. mod_timer(&phba->hb_tmofunc,
  4099. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4100. phba->hb_outstanding = 0;
  4101. phba->last_completion_time = jiffies;
  4102. /* Start error attention (ERATT) polling timer */
  4103. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4104. /*
  4105. * The port is ready, set the host's link state to LINK_DOWN
  4106. * in preparation for link interrupts.
  4107. */
  4108. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4109. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4110. lpfc_set_loopback_flag(phba);
  4111. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4112. spin_lock_irq(&phba->hbalock);
  4113. phba->link_state = LPFC_LINK_DOWN;
  4114. spin_unlock_irq(&phba->hbalock);
  4115. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4116. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4117. kfree(vpd);
  4118. return 0;
  4119. } else
  4120. rc = -EIO;
  4121. /* Unset all the queues set up in this routine when error out */
  4122. if (rc)
  4123. lpfc_sli4_queue_unset(phba);
  4124. out_stop_timers:
  4125. if (rc)
  4126. lpfc_stop_hba_timers(phba);
  4127. out_free_vpd:
  4128. kfree(vpd);
  4129. out_free_mbox:
  4130. mempool_free(mboxq, phba->mbox_mem_pool);
  4131. return rc;
  4132. }
  4133. /**
  4134. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4135. * @ptr: context object - pointer to hba structure.
  4136. *
  4137. * This is the callback function for mailbox timer. The mailbox
  4138. * timer is armed when a new mailbox command is issued and the timer
  4139. * is deleted when the mailbox complete. The function is called by
  4140. * the kernel timer code when a mailbox does not complete within
  4141. * expected time. This function wakes up the worker thread to
  4142. * process the mailbox timeout and returns. All the processing is
  4143. * done by the worker thread function lpfc_mbox_timeout_handler.
  4144. **/
  4145. void
  4146. lpfc_mbox_timeout(unsigned long ptr)
  4147. {
  4148. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4149. unsigned long iflag;
  4150. uint32_t tmo_posted;
  4151. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4152. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4153. if (!tmo_posted)
  4154. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4155. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4156. if (!tmo_posted)
  4157. lpfc_worker_wake_up(phba);
  4158. return;
  4159. }
  4160. /**
  4161. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4162. * @phba: Pointer to HBA context object.
  4163. *
  4164. * This function is called from worker thread when a mailbox command times out.
  4165. * The caller is not required to hold any locks. This function will reset the
  4166. * HBA and recover all the pending commands.
  4167. **/
  4168. void
  4169. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4170. {
  4171. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4172. MAILBOX_t *mb = &pmbox->u.mb;
  4173. struct lpfc_sli *psli = &phba->sli;
  4174. struct lpfc_sli_ring *pring;
  4175. /* Check the pmbox pointer first. There is a race condition
  4176. * between the mbox timeout handler getting executed in the
  4177. * worklist and the mailbox actually completing. When this
  4178. * race condition occurs, the mbox_active will be NULL.
  4179. */
  4180. spin_lock_irq(&phba->hbalock);
  4181. if (pmbox == NULL) {
  4182. lpfc_printf_log(phba, KERN_WARNING,
  4183. LOG_MBOX | LOG_SLI,
  4184. "0353 Active Mailbox cleared - mailbox timeout "
  4185. "exiting\n");
  4186. spin_unlock_irq(&phba->hbalock);
  4187. return;
  4188. }
  4189. /* Mbox cmd <mbxCommand> timeout */
  4190. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4191. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4192. mb->mbxCommand,
  4193. phba->pport->port_state,
  4194. phba->sli.sli_flag,
  4195. phba->sli.mbox_active);
  4196. spin_unlock_irq(&phba->hbalock);
  4197. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4198. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4199. * it to fail all oustanding SCSI IO.
  4200. */
  4201. spin_lock_irq(&phba->pport->work_port_lock);
  4202. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4203. spin_unlock_irq(&phba->pport->work_port_lock);
  4204. spin_lock_irq(&phba->hbalock);
  4205. phba->link_state = LPFC_LINK_UNKNOWN;
  4206. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4207. spin_unlock_irq(&phba->hbalock);
  4208. pring = &psli->ring[psli->fcp_ring];
  4209. lpfc_sli_abort_iocb_ring(phba, pring);
  4210. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4211. "0345 Resetting board due to mailbox timeout\n");
  4212. /* Reset the HBA device */
  4213. lpfc_reset_hba(phba);
  4214. }
  4215. /**
  4216. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4217. * @phba: Pointer to HBA context object.
  4218. * @pmbox: Pointer to mailbox object.
  4219. * @flag: Flag indicating how the mailbox need to be processed.
  4220. *
  4221. * This function is called by discovery code and HBA management code
  4222. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4223. * function gets the hbalock to protect the data structures.
  4224. * The mailbox command can be submitted in polling mode, in which case
  4225. * this function will wait in a polling loop for the completion of the
  4226. * mailbox.
  4227. * If the mailbox is submitted in no_wait mode (not polling) the
  4228. * function will submit the command and returns immediately without waiting
  4229. * for the mailbox completion. The no_wait is supported only when HBA
  4230. * is in SLI2/SLI3 mode - interrupts are enabled.
  4231. * The SLI interface allows only one mailbox pending at a time. If the
  4232. * mailbox is issued in polling mode and there is already a mailbox
  4233. * pending, then the function will return an error. If the mailbox is issued
  4234. * in NO_WAIT mode and there is a mailbox pending already, the function
  4235. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4236. * The sli layer owns the mailbox object until the completion of mailbox
  4237. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4238. * return codes the caller owns the mailbox command after the return of
  4239. * the function.
  4240. **/
  4241. static int
  4242. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4243. uint32_t flag)
  4244. {
  4245. MAILBOX_t *mb;
  4246. struct lpfc_sli *psli = &phba->sli;
  4247. uint32_t status, evtctr;
  4248. uint32_t ha_copy;
  4249. int i;
  4250. unsigned long timeout;
  4251. unsigned long drvr_flag = 0;
  4252. uint32_t word0, ldata;
  4253. void __iomem *to_slim;
  4254. int processing_queue = 0;
  4255. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4256. if (!pmbox) {
  4257. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4258. /* processing mbox queue from intr_handler */
  4259. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4260. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4261. return MBX_SUCCESS;
  4262. }
  4263. processing_queue = 1;
  4264. pmbox = lpfc_mbox_get(phba);
  4265. if (!pmbox) {
  4266. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4267. return MBX_SUCCESS;
  4268. }
  4269. }
  4270. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4271. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4272. if(!pmbox->vport) {
  4273. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4274. lpfc_printf_log(phba, KERN_ERR,
  4275. LOG_MBOX | LOG_VPORT,
  4276. "1806 Mbox x%x failed. No vport\n",
  4277. pmbox->u.mb.mbxCommand);
  4278. dump_stack();
  4279. goto out_not_finished;
  4280. }
  4281. }
  4282. /* If the PCI channel is in offline state, do not post mbox. */
  4283. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4284. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4285. goto out_not_finished;
  4286. }
  4287. /* If HBA has a deferred error attention, fail the iocb. */
  4288. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4289. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4290. goto out_not_finished;
  4291. }
  4292. psli = &phba->sli;
  4293. mb = &pmbox->u.mb;
  4294. status = MBX_SUCCESS;
  4295. if (phba->link_state == LPFC_HBA_ERROR) {
  4296. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4297. /* Mbox command <mbxCommand> cannot issue */
  4298. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4299. "(%d):0311 Mailbox command x%x cannot "
  4300. "issue Data: x%x x%x\n",
  4301. pmbox->vport ? pmbox->vport->vpi : 0,
  4302. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4303. goto out_not_finished;
  4304. }
  4305. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4306. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4307. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4308. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4309. "(%d):2528 Mailbox command x%x cannot "
  4310. "issue Data: x%x x%x\n",
  4311. pmbox->vport ? pmbox->vport->vpi : 0,
  4312. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4313. goto out_not_finished;
  4314. }
  4315. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4316. /* Polling for a mbox command when another one is already active
  4317. * is not allowed in SLI. Also, the driver must have established
  4318. * SLI2 mode to queue and process multiple mbox commands.
  4319. */
  4320. if (flag & MBX_POLL) {
  4321. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4322. /* Mbox command <mbxCommand> cannot issue */
  4323. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4324. "(%d):2529 Mailbox command x%x "
  4325. "cannot issue Data: x%x x%x\n",
  4326. pmbox->vport ? pmbox->vport->vpi : 0,
  4327. pmbox->u.mb.mbxCommand,
  4328. psli->sli_flag, flag);
  4329. goto out_not_finished;
  4330. }
  4331. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4332. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4333. /* Mbox command <mbxCommand> cannot issue */
  4334. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4335. "(%d):2530 Mailbox command x%x "
  4336. "cannot issue Data: x%x x%x\n",
  4337. pmbox->vport ? pmbox->vport->vpi : 0,
  4338. pmbox->u.mb.mbxCommand,
  4339. psli->sli_flag, flag);
  4340. goto out_not_finished;
  4341. }
  4342. /* Another mailbox command is still being processed, queue this
  4343. * command to be processed later.
  4344. */
  4345. lpfc_mbox_put(phba, pmbox);
  4346. /* Mbox cmd issue - BUSY */
  4347. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4348. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4349. "x%x x%x x%x x%x\n",
  4350. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4351. mb->mbxCommand, phba->pport->port_state,
  4352. psli->sli_flag, flag);
  4353. psli->slistat.mbox_busy++;
  4354. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4355. if (pmbox->vport) {
  4356. lpfc_debugfs_disc_trc(pmbox->vport,
  4357. LPFC_DISC_TRC_MBOX_VPORT,
  4358. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4359. (uint32_t)mb->mbxCommand,
  4360. mb->un.varWords[0], mb->un.varWords[1]);
  4361. }
  4362. else {
  4363. lpfc_debugfs_disc_trc(phba->pport,
  4364. LPFC_DISC_TRC_MBOX,
  4365. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4366. (uint32_t)mb->mbxCommand,
  4367. mb->un.varWords[0], mb->un.varWords[1]);
  4368. }
  4369. return MBX_BUSY;
  4370. }
  4371. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4372. /* If we are not polling, we MUST be in SLI2 mode */
  4373. if (flag != MBX_POLL) {
  4374. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4375. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4376. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4377. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4378. /* Mbox command <mbxCommand> cannot issue */
  4379. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4380. "(%d):2531 Mailbox command x%x "
  4381. "cannot issue Data: x%x x%x\n",
  4382. pmbox->vport ? pmbox->vport->vpi : 0,
  4383. pmbox->u.mb.mbxCommand,
  4384. psli->sli_flag, flag);
  4385. goto out_not_finished;
  4386. }
  4387. /* timeout active mbox command */
  4388. mod_timer(&psli->mbox_tmo, (jiffies +
  4389. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4390. }
  4391. /* Mailbox cmd <cmd> issue */
  4392. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4393. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4394. "x%x\n",
  4395. pmbox->vport ? pmbox->vport->vpi : 0,
  4396. mb->mbxCommand, phba->pport->port_state,
  4397. psli->sli_flag, flag);
  4398. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4399. if (pmbox->vport) {
  4400. lpfc_debugfs_disc_trc(pmbox->vport,
  4401. LPFC_DISC_TRC_MBOX_VPORT,
  4402. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4403. (uint32_t)mb->mbxCommand,
  4404. mb->un.varWords[0], mb->un.varWords[1]);
  4405. }
  4406. else {
  4407. lpfc_debugfs_disc_trc(phba->pport,
  4408. LPFC_DISC_TRC_MBOX,
  4409. "MBOX Send: cmd:x%x mb:x%x x%x",
  4410. (uint32_t)mb->mbxCommand,
  4411. mb->un.varWords[0], mb->un.varWords[1]);
  4412. }
  4413. }
  4414. psli->slistat.mbox_cmd++;
  4415. evtctr = psli->slistat.mbox_event;
  4416. /* next set own bit for the adapter and copy over command word */
  4417. mb->mbxOwner = OWN_CHIP;
  4418. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4419. /* First copy command data to host SLIM area */
  4420. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4421. } else {
  4422. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4423. /* copy command data into host mbox for cmpl */
  4424. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4425. }
  4426. /* First copy mbox command data to HBA SLIM, skip past first
  4427. word */
  4428. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4429. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4430. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4431. /* Next copy over first word, with mbxOwner set */
  4432. ldata = *((uint32_t *)mb);
  4433. to_slim = phba->MBslimaddr;
  4434. writel(ldata, to_slim);
  4435. readl(to_slim); /* flush */
  4436. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4437. /* switch over to host mailbox */
  4438. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4439. }
  4440. }
  4441. wmb();
  4442. switch (flag) {
  4443. case MBX_NOWAIT:
  4444. /* Set up reference to mailbox command */
  4445. psli->mbox_active = pmbox;
  4446. /* Interrupt board to do it */
  4447. writel(CA_MBATT, phba->CAregaddr);
  4448. readl(phba->CAregaddr); /* flush */
  4449. /* Don't wait for it to finish, just return */
  4450. break;
  4451. case MBX_POLL:
  4452. /* Set up null reference to mailbox command */
  4453. psli->mbox_active = NULL;
  4454. /* Interrupt board to do it */
  4455. writel(CA_MBATT, phba->CAregaddr);
  4456. readl(phba->CAregaddr); /* flush */
  4457. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4458. /* First read mbox status word */
  4459. word0 = *((uint32_t *)phba->mbox);
  4460. word0 = le32_to_cpu(word0);
  4461. } else {
  4462. /* First read mbox status word */
  4463. word0 = readl(phba->MBslimaddr);
  4464. }
  4465. /* Read the HBA Host Attention Register */
  4466. ha_copy = readl(phba->HAregaddr);
  4467. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4468. mb->mbxCommand) *
  4469. 1000) + jiffies;
  4470. i = 0;
  4471. /* Wait for command to complete */
  4472. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4473. (!(ha_copy & HA_MBATT) &&
  4474. (phba->link_state > LPFC_WARM_START))) {
  4475. if (time_after(jiffies, timeout)) {
  4476. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4477. spin_unlock_irqrestore(&phba->hbalock,
  4478. drvr_flag);
  4479. goto out_not_finished;
  4480. }
  4481. /* Check if we took a mbox interrupt while we were
  4482. polling */
  4483. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4484. && (evtctr != psli->slistat.mbox_event))
  4485. break;
  4486. if (i++ > 10) {
  4487. spin_unlock_irqrestore(&phba->hbalock,
  4488. drvr_flag);
  4489. msleep(1);
  4490. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4491. }
  4492. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4493. /* First copy command data */
  4494. word0 = *((uint32_t *)phba->mbox);
  4495. word0 = le32_to_cpu(word0);
  4496. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4497. MAILBOX_t *slimmb;
  4498. uint32_t slimword0;
  4499. /* Check real SLIM for any errors */
  4500. slimword0 = readl(phba->MBslimaddr);
  4501. slimmb = (MAILBOX_t *) & slimword0;
  4502. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4503. && slimmb->mbxStatus) {
  4504. psli->sli_flag &=
  4505. ~LPFC_SLI_ACTIVE;
  4506. word0 = slimword0;
  4507. }
  4508. }
  4509. } else {
  4510. /* First copy command data */
  4511. word0 = readl(phba->MBslimaddr);
  4512. }
  4513. /* Read the HBA Host Attention Register */
  4514. ha_copy = readl(phba->HAregaddr);
  4515. }
  4516. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4517. /* copy results back to user */
  4518. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4519. } else {
  4520. /* First copy command data */
  4521. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4522. MAILBOX_CMD_SIZE);
  4523. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4524. pmbox->context2) {
  4525. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4526. phba->MBslimaddr + DMP_RSP_OFFSET,
  4527. mb->un.varDmp.word_cnt);
  4528. }
  4529. }
  4530. writel(HA_MBATT, phba->HAregaddr);
  4531. readl(phba->HAregaddr); /* flush */
  4532. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4533. status = mb->mbxStatus;
  4534. }
  4535. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4536. return status;
  4537. out_not_finished:
  4538. if (processing_queue) {
  4539. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4540. lpfc_mbox_cmpl_put(phba, pmbox);
  4541. }
  4542. return MBX_NOT_FINISHED;
  4543. }
  4544. /**
  4545. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4546. * @phba: Pointer to HBA context object.
  4547. *
  4548. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4549. * the driver internal pending mailbox queue. It will then try to wait out the
  4550. * possible outstanding mailbox command before return.
  4551. *
  4552. * Returns:
  4553. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4554. * the outstanding mailbox command timed out.
  4555. **/
  4556. static int
  4557. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4558. {
  4559. struct lpfc_sli *psli = &phba->sli;
  4560. uint8_t actcmd = MBX_HEARTBEAT;
  4561. int rc = 0;
  4562. unsigned long timeout;
  4563. /* Mark the asynchronous mailbox command posting as blocked */
  4564. spin_lock_irq(&phba->hbalock);
  4565. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4566. if (phba->sli.mbox_active)
  4567. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4568. spin_unlock_irq(&phba->hbalock);
  4569. /* Determine how long we might wait for the active mailbox
  4570. * command to be gracefully completed by firmware.
  4571. */
  4572. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4573. jiffies;
  4574. /* Wait for the outstnading mailbox command to complete */
  4575. while (phba->sli.mbox_active) {
  4576. /* Check active mailbox complete status every 2ms */
  4577. msleep(2);
  4578. if (time_after(jiffies, timeout)) {
  4579. /* Timeout, marked the outstanding cmd not complete */
  4580. rc = 1;
  4581. break;
  4582. }
  4583. }
  4584. /* Can not cleanly block async mailbox command, fails it */
  4585. if (rc) {
  4586. spin_lock_irq(&phba->hbalock);
  4587. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4588. spin_unlock_irq(&phba->hbalock);
  4589. }
  4590. return rc;
  4591. }
  4592. /**
  4593. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4594. * @phba: Pointer to HBA context object.
  4595. *
  4596. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4597. * commands from the driver internal pending mailbox queue. It makes sure
  4598. * that there is no outstanding mailbox command before resuming posting
  4599. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4600. * mailbox command, it will try to wait it out before resuming asynchronous
  4601. * mailbox command posting.
  4602. **/
  4603. static void
  4604. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4605. {
  4606. struct lpfc_sli *psli = &phba->sli;
  4607. spin_lock_irq(&phba->hbalock);
  4608. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4609. /* Asynchronous mailbox posting is not blocked, do nothing */
  4610. spin_unlock_irq(&phba->hbalock);
  4611. return;
  4612. }
  4613. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4614. * successful or timeout, after timing-out the outstanding mailbox
  4615. * command shall always be removed, so just unblock posting async
  4616. * mailbox command and resume
  4617. */
  4618. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4619. spin_unlock_irq(&phba->hbalock);
  4620. /* wake up worker thread to post asynchronlous mailbox command */
  4621. lpfc_worker_wake_up(phba);
  4622. }
  4623. /**
  4624. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4625. * @phba: Pointer to HBA context object.
  4626. * @mboxq: Pointer to mailbox object.
  4627. *
  4628. * The function posts a mailbox to the port. The mailbox is expected
  4629. * to be comletely filled in and ready for the port to operate on it.
  4630. * This routine executes a synchronous completion operation on the
  4631. * mailbox by polling for its completion.
  4632. *
  4633. * The caller must not be holding any locks when calling this routine.
  4634. *
  4635. * Returns:
  4636. * MBX_SUCCESS - mailbox posted successfully
  4637. * Any of the MBX error values.
  4638. **/
  4639. static int
  4640. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4641. {
  4642. int rc = MBX_SUCCESS;
  4643. unsigned long iflag;
  4644. uint32_t db_ready;
  4645. uint32_t mcqe_status;
  4646. uint32_t mbx_cmnd;
  4647. unsigned long timeout;
  4648. struct lpfc_sli *psli = &phba->sli;
  4649. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4650. struct lpfc_bmbx_create *mbox_rgn;
  4651. struct dma_address *dma_address;
  4652. struct lpfc_register bmbx_reg;
  4653. /*
  4654. * Only one mailbox can be active to the bootstrap mailbox region
  4655. * at a time and there is no queueing provided.
  4656. */
  4657. spin_lock_irqsave(&phba->hbalock, iflag);
  4658. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4659. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4660. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4661. "(%d):2532 Mailbox command x%x (x%x) "
  4662. "cannot issue Data: x%x x%x\n",
  4663. mboxq->vport ? mboxq->vport->vpi : 0,
  4664. mboxq->u.mb.mbxCommand,
  4665. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4666. psli->sli_flag, MBX_POLL);
  4667. return MBXERR_ERROR;
  4668. }
  4669. /* The server grabs the token and owns it until release */
  4670. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4671. phba->sli.mbox_active = mboxq;
  4672. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4673. /*
  4674. * Initialize the bootstrap memory region to avoid stale data areas
  4675. * in the mailbox post. Then copy the caller's mailbox contents to
  4676. * the bmbx mailbox region.
  4677. */
  4678. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4679. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4680. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4681. sizeof(struct lpfc_mqe));
  4682. /* Post the high mailbox dma address to the port and wait for ready. */
  4683. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4684. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4685. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4686. * 1000) + jiffies;
  4687. do {
  4688. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4689. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4690. if (!db_ready)
  4691. msleep(2);
  4692. if (time_after(jiffies, timeout)) {
  4693. rc = MBXERR_ERROR;
  4694. goto exit;
  4695. }
  4696. } while (!db_ready);
  4697. /* Post the low mailbox dma address to the port. */
  4698. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4699. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4700. * 1000) + jiffies;
  4701. do {
  4702. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4703. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4704. if (!db_ready)
  4705. msleep(2);
  4706. if (time_after(jiffies, timeout)) {
  4707. rc = MBXERR_ERROR;
  4708. goto exit;
  4709. }
  4710. } while (!db_ready);
  4711. /*
  4712. * Read the CQ to ensure the mailbox has completed.
  4713. * If so, update the mailbox status so that the upper layers
  4714. * can complete the request normally.
  4715. */
  4716. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4717. sizeof(struct lpfc_mqe));
  4718. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4719. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4720. sizeof(struct lpfc_mcqe));
  4721. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4722. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4723. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4724. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4725. rc = MBXERR_ERROR;
  4726. }
  4727. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4728. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4729. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4730. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4731. mboxq->vport ? mboxq->vport->vpi : 0,
  4732. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4733. bf_get(lpfc_mqe_status, mb),
  4734. mb->un.mb_words[0], mb->un.mb_words[1],
  4735. mb->un.mb_words[2], mb->un.mb_words[3],
  4736. mb->un.mb_words[4], mb->un.mb_words[5],
  4737. mb->un.mb_words[6], mb->un.mb_words[7],
  4738. mb->un.mb_words[8], mb->un.mb_words[9],
  4739. mb->un.mb_words[10], mb->un.mb_words[11],
  4740. mb->un.mb_words[12], mboxq->mcqe.word0,
  4741. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4742. mboxq->mcqe.trailer);
  4743. exit:
  4744. /* We are holding the token, no needed for lock when release */
  4745. spin_lock_irqsave(&phba->hbalock, iflag);
  4746. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4747. phba->sli.mbox_active = NULL;
  4748. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4749. return rc;
  4750. }
  4751. /**
  4752. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4753. * @phba: Pointer to HBA context object.
  4754. * @pmbox: Pointer to mailbox object.
  4755. * @flag: Flag indicating how the mailbox need to be processed.
  4756. *
  4757. * This function is called by discovery code and HBA management code to submit
  4758. * a mailbox command to firmware with SLI-4 interface spec.
  4759. *
  4760. * Return codes the caller owns the mailbox command after the return of the
  4761. * function.
  4762. **/
  4763. static int
  4764. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4765. uint32_t flag)
  4766. {
  4767. struct lpfc_sli *psli = &phba->sli;
  4768. unsigned long iflags;
  4769. int rc;
  4770. rc = lpfc_mbox_dev_check(phba);
  4771. if (unlikely(rc)) {
  4772. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4773. "(%d):2544 Mailbox command x%x (x%x) "
  4774. "cannot issue Data: x%x x%x\n",
  4775. mboxq->vport ? mboxq->vport->vpi : 0,
  4776. mboxq->u.mb.mbxCommand,
  4777. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4778. psli->sli_flag, flag);
  4779. goto out_not_finished;
  4780. }
  4781. /* Detect polling mode and jump to a handler */
  4782. if (!phba->sli4_hba.intr_enable) {
  4783. if (flag == MBX_POLL)
  4784. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4785. else
  4786. rc = -EIO;
  4787. if (rc != MBX_SUCCESS)
  4788. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4789. "(%d):2541 Mailbox command x%x "
  4790. "(x%x) cannot issue Data: x%x x%x\n",
  4791. mboxq->vport ? mboxq->vport->vpi : 0,
  4792. mboxq->u.mb.mbxCommand,
  4793. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4794. psli->sli_flag, flag);
  4795. return rc;
  4796. } else if (flag == MBX_POLL) {
  4797. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4798. "(%d):2542 Try to issue mailbox command "
  4799. "x%x (x%x) synchronously ahead of async"
  4800. "mailbox command queue: x%x x%x\n",
  4801. mboxq->vport ? mboxq->vport->vpi : 0,
  4802. mboxq->u.mb.mbxCommand,
  4803. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4804. psli->sli_flag, flag);
  4805. /* Try to block the asynchronous mailbox posting */
  4806. rc = lpfc_sli4_async_mbox_block(phba);
  4807. if (!rc) {
  4808. /* Successfully blocked, now issue sync mbox cmd */
  4809. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4810. if (rc != MBX_SUCCESS)
  4811. lpfc_printf_log(phba, KERN_ERR,
  4812. LOG_MBOX | LOG_SLI,
  4813. "(%d):2597 Mailbox command "
  4814. "x%x (x%x) cannot issue "
  4815. "Data: x%x x%x\n",
  4816. mboxq->vport ?
  4817. mboxq->vport->vpi : 0,
  4818. mboxq->u.mb.mbxCommand,
  4819. lpfc_sli4_mbox_opcode_get(phba,
  4820. mboxq),
  4821. psli->sli_flag, flag);
  4822. /* Unblock the async mailbox posting afterward */
  4823. lpfc_sli4_async_mbox_unblock(phba);
  4824. }
  4825. return rc;
  4826. }
  4827. /* Now, interrupt mode asynchrous mailbox command */
  4828. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4829. if (rc) {
  4830. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4831. "(%d):2543 Mailbox command x%x (x%x) "
  4832. "cannot issue Data: x%x x%x\n",
  4833. mboxq->vport ? mboxq->vport->vpi : 0,
  4834. mboxq->u.mb.mbxCommand,
  4835. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4836. psli->sli_flag, flag);
  4837. goto out_not_finished;
  4838. }
  4839. /* Put the mailbox command to the driver internal FIFO */
  4840. psli->slistat.mbox_busy++;
  4841. spin_lock_irqsave(&phba->hbalock, iflags);
  4842. lpfc_mbox_put(phba, mboxq);
  4843. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4844. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4845. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4846. "x%x (x%x) x%x x%x x%x\n",
  4847. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4848. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4849. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4850. phba->pport->port_state,
  4851. psli->sli_flag, MBX_NOWAIT);
  4852. /* Wake up worker thread to transport mailbox command from head */
  4853. lpfc_worker_wake_up(phba);
  4854. return MBX_BUSY;
  4855. out_not_finished:
  4856. return MBX_NOT_FINISHED;
  4857. }
  4858. /**
  4859. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4860. * @phba: Pointer to HBA context object.
  4861. *
  4862. * This function is called by worker thread to send a mailbox command to
  4863. * SLI4 HBA firmware.
  4864. *
  4865. **/
  4866. int
  4867. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4868. {
  4869. struct lpfc_sli *psli = &phba->sli;
  4870. LPFC_MBOXQ_t *mboxq;
  4871. int rc = MBX_SUCCESS;
  4872. unsigned long iflags;
  4873. struct lpfc_mqe *mqe;
  4874. uint32_t mbx_cmnd;
  4875. /* Check interrupt mode before post async mailbox command */
  4876. if (unlikely(!phba->sli4_hba.intr_enable))
  4877. return MBX_NOT_FINISHED;
  4878. /* Check for mailbox command service token */
  4879. spin_lock_irqsave(&phba->hbalock, iflags);
  4880. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4881. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4882. return MBX_NOT_FINISHED;
  4883. }
  4884. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4885. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4886. return MBX_NOT_FINISHED;
  4887. }
  4888. if (unlikely(phba->sli.mbox_active)) {
  4889. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4890. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4891. "0384 There is pending active mailbox cmd\n");
  4892. return MBX_NOT_FINISHED;
  4893. }
  4894. /* Take the mailbox command service token */
  4895. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4896. /* Get the next mailbox command from head of queue */
  4897. mboxq = lpfc_mbox_get(phba);
  4898. /* If no more mailbox command waiting for post, we're done */
  4899. if (!mboxq) {
  4900. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4901. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4902. return MBX_SUCCESS;
  4903. }
  4904. phba->sli.mbox_active = mboxq;
  4905. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4906. /* Check device readiness for posting mailbox command */
  4907. rc = lpfc_mbox_dev_check(phba);
  4908. if (unlikely(rc))
  4909. /* Driver clean routine will clean up pending mailbox */
  4910. goto out_not_finished;
  4911. /* Prepare the mbox command to be posted */
  4912. mqe = &mboxq->u.mqe;
  4913. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4914. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4915. mod_timer(&psli->mbox_tmo, (jiffies +
  4916. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4917. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4918. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4919. "x%x x%x\n",
  4920. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4921. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4922. phba->pport->port_state, psli->sli_flag);
  4923. if (mbx_cmnd != MBX_HEARTBEAT) {
  4924. if (mboxq->vport) {
  4925. lpfc_debugfs_disc_trc(mboxq->vport,
  4926. LPFC_DISC_TRC_MBOX_VPORT,
  4927. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4928. mbx_cmnd, mqe->un.mb_words[0],
  4929. mqe->un.mb_words[1]);
  4930. } else {
  4931. lpfc_debugfs_disc_trc(phba->pport,
  4932. LPFC_DISC_TRC_MBOX,
  4933. "MBOX Send: cmd:x%x mb:x%x x%x",
  4934. mbx_cmnd, mqe->un.mb_words[0],
  4935. mqe->un.mb_words[1]);
  4936. }
  4937. }
  4938. psli->slistat.mbox_cmd++;
  4939. /* Post the mailbox command to the port */
  4940. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4941. if (rc != MBX_SUCCESS) {
  4942. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4943. "(%d):2533 Mailbox command x%x (x%x) "
  4944. "cannot issue Data: x%x x%x\n",
  4945. mboxq->vport ? mboxq->vport->vpi : 0,
  4946. mboxq->u.mb.mbxCommand,
  4947. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4948. psli->sli_flag, MBX_NOWAIT);
  4949. goto out_not_finished;
  4950. }
  4951. return rc;
  4952. out_not_finished:
  4953. spin_lock_irqsave(&phba->hbalock, iflags);
  4954. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4955. __lpfc_mbox_cmpl_put(phba, mboxq);
  4956. /* Release the token */
  4957. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4958. phba->sli.mbox_active = NULL;
  4959. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4960. return MBX_NOT_FINISHED;
  4961. }
  4962. /**
  4963. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4964. * @phba: Pointer to HBA context object.
  4965. * @pmbox: Pointer to mailbox object.
  4966. * @flag: Flag indicating how the mailbox need to be processed.
  4967. *
  4968. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4969. * the API jump table function pointer from the lpfc_hba struct.
  4970. *
  4971. * Return codes the caller owns the mailbox command after the return of the
  4972. * function.
  4973. **/
  4974. int
  4975. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4976. {
  4977. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4978. }
  4979. /**
  4980. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4981. * @phba: The hba struct for which this call is being executed.
  4982. * @dev_grp: The HBA PCI-Device group number.
  4983. *
  4984. * This routine sets up the mbox interface API function jump table in @phba
  4985. * struct.
  4986. * Returns: 0 - success, -ENODEV - failure.
  4987. **/
  4988. int
  4989. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4990. {
  4991. switch (dev_grp) {
  4992. case LPFC_PCI_DEV_LP:
  4993. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  4994. phba->lpfc_sli_handle_slow_ring_event =
  4995. lpfc_sli_handle_slow_ring_event_s3;
  4996. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  4997. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  4998. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  4999. break;
  5000. case LPFC_PCI_DEV_OC:
  5001. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5002. phba->lpfc_sli_handle_slow_ring_event =
  5003. lpfc_sli_handle_slow_ring_event_s4;
  5004. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5005. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5006. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5007. break;
  5008. default:
  5009. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5010. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5011. dev_grp);
  5012. return -ENODEV;
  5013. break;
  5014. }
  5015. return 0;
  5016. }
  5017. /**
  5018. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5019. * @phba: Pointer to HBA context object.
  5020. * @pring: Pointer to driver SLI ring object.
  5021. * @piocb: Pointer to address of newly added command iocb.
  5022. *
  5023. * This function is called with hbalock held to add a command
  5024. * iocb to the txq when SLI layer cannot submit the command iocb
  5025. * to the ring.
  5026. **/
  5027. static void
  5028. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5029. struct lpfc_iocbq *piocb)
  5030. {
  5031. /* Insert the caller's iocb in the txq tail for later processing. */
  5032. list_add_tail(&piocb->list, &pring->txq);
  5033. pring->txq_cnt++;
  5034. }
  5035. /**
  5036. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5037. * @phba: Pointer to HBA context object.
  5038. * @pring: Pointer to driver SLI ring object.
  5039. * @piocb: Pointer to address of newly added command iocb.
  5040. *
  5041. * This function is called with hbalock held before a new
  5042. * iocb is submitted to the firmware. This function checks
  5043. * txq to flush the iocbs in txq to Firmware before
  5044. * submitting new iocbs to the Firmware.
  5045. * If there are iocbs in the txq which need to be submitted
  5046. * to firmware, lpfc_sli_next_iocb returns the first element
  5047. * of the txq after dequeuing it from txq.
  5048. * If there is no iocb in the txq then the function will return
  5049. * *piocb and *piocb is set to NULL. Caller needs to check
  5050. * *piocb to find if there are more commands in the txq.
  5051. **/
  5052. static struct lpfc_iocbq *
  5053. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5054. struct lpfc_iocbq **piocb)
  5055. {
  5056. struct lpfc_iocbq * nextiocb;
  5057. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5058. if (!nextiocb) {
  5059. nextiocb = *piocb;
  5060. *piocb = NULL;
  5061. }
  5062. return nextiocb;
  5063. }
  5064. /**
  5065. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5066. * @phba: Pointer to HBA context object.
  5067. * @ring_number: SLI ring number to issue iocb on.
  5068. * @piocb: Pointer to command iocb.
  5069. * @flag: Flag indicating if this command can be put into txq.
  5070. *
  5071. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5072. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5073. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5074. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5075. * this function allows only iocbs for posting buffers. This function finds
  5076. * next available slot in the command ring and posts the command to the
  5077. * available slot and writes the port attention register to request HBA start
  5078. * processing new iocb. If there is no slot available in the ring and
  5079. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5080. * the function returns IOCB_BUSY.
  5081. *
  5082. * This function is called with hbalock held. The function will return success
  5083. * after it successfully submit the iocb to firmware or after adding to the
  5084. * txq.
  5085. **/
  5086. static int
  5087. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5088. struct lpfc_iocbq *piocb, uint32_t flag)
  5089. {
  5090. struct lpfc_iocbq *nextiocb;
  5091. IOCB_t *iocb;
  5092. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5093. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5094. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5095. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5096. lpfc_printf_log(phba, KERN_ERR,
  5097. LOG_SLI | LOG_VPORT,
  5098. "1807 IOCB x%x failed. No vport\n",
  5099. piocb->iocb.ulpCommand);
  5100. dump_stack();
  5101. return IOCB_ERROR;
  5102. }
  5103. /* If the PCI channel is in offline state, do not post iocbs. */
  5104. if (unlikely(pci_channel_offline(phba->pcidev)))
  5105. return IOCB_ERROR;
  5106. /* If HBA has a deferred error attention, fail the iocb. */
  5107. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5108. return IOCB_ERROR;
  5109. /*
  5110. * We should never get an IOCB if we are in a < LINK_DOWN state
  5111. */
  5112. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5113. return IOCB_ERROR;
  5114. /*
  5115. * Check to see if we are blocking IOCB processing because of a
  5116. * outstanding event.
  5117. */
  5118. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5119. goto iocb_busy;
  5120. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5121. /*
  5122. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5123. * can be issued if the link is not up.
  5124. */
  5125. switch (piocb->iocb.ulpCommand) {
  5126. case CMD_GEN_REQUEST64_CR:
  5127. case CMD_GEN_REQUEST64_CX:
  5128. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5129. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5130. FC_RCTL_DD_UNSOL_CMD) ||
  5131. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5132. MENLO_TRANSPORT_TYPE))
  5133. goto iocb_busy;
  5134. break;
  5135. case CMD_QUE_RING_BUF_CN:
  5136. case CMD_QUE_RING_BUF64_CN:
  5137. /*
  5138. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5139. * completion, iocb_cmpl MUST be 0.
  5140. */
  5141. if (piocb->iocb_cmpl)
  5142. piocb->iocb_cmpl = NULL;
  5143. /*FALLTHROUGH*/
  5144. case CMD_CREATE_XRI_CR:
  5145. case CMD_CLOSE_XRI_CN:
  5146. case CMD_CLOSE_XRI_CX:
  5147. break;
  5148. default:
  5149. goto iocb_busy;
  5150. }
  5151. /*
  5152. * For FCP commands, we must be in a state where we can process link
  5153. * attention events.
  5154. */
  5155. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5156. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5157. goto iocb_busy;
  5158. }
  5159. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5160. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5161. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5162. if (iocb)
  5163. lpfc_sli_update_ring(phba, pring);
  5164. else
  5165. lpfc_sli_update_full_ring(phba, pring);
  5166. if (!piocb)
  5167. return IOCB_SUCCESS;
  5168. goto out_busy;
  5169. iocb_busy:
  5170. pring->stats.iocb_cmd_delay++;
  5171. out_busy:
  5172. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5173. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5174. return IOCB_SUCCESS;
  5175. }
  5176. return IOCB_BUSY;
  5177. }
  5178. /**
  5179. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5180. * @phba: Pointer to HBA context object.
  5181. * @piocb: Pointer to command iocb.
  5182. * @sglq: Pointer to the scatter gather queue object.
  5183. *
  5184. * This routine converts the bpl or bde that is in the IOCB
  5185. * to a sgl list for the sli4 hardware. The physical address
  5186. * of the bpl/bde is converted back to a virtual address.
  5187. * If the IOCB contains a BPL then the list of BDE's is
  5188. * converted to sli4_sge's. If the IOCB contains a single
  5189. * BDE then it is converted to a single sli_sge.
  5190. * The IOCB is still in cpu endianess so the contents of
  5191. * the bpl can be used without byte swapping.
  5192. *
  5193. * Returns valid XRI = Success, NO_XRI = Failure.
  5194. **/
  5195. static uint16_t
  5196. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5197. struct lpfc_sglq *sglq)
  5198. {
  5199. uint16_t xritag = NO_XRI;
  5200. struct ulp_bde64 *bpl = NULL;
  5201. struct ulp_bde64 bde;
  5202. struct sli4_sge *sgl = NULL;
  5203. IOCB_t *icmd;
  5204. int numBdes = 0;
  5205. int i = 0;
  5206. if (!piocbq || !sglq)
  5207. return xritag;
  5208. sgl = (struct sli4_sge *)sglq->sgl;
  5209. icmd = &piocbq->iocb;
  5210. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5211. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5212. sizeof(struct ulp_bde64);
  5213. /* The addrHigh and addrLow fields within the IOCB
  5214. * have not been byteswapped yet so there is no
  5215. * need to swap them back.
  5216. */
  5217. bpl = (struct ulp_bde64 *)
  5218. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5219. if (!bpl)
  5220. return xritag;
  5221. for (i = 0; i < numBdes; i++) {
  5222. /* Should already be byte swapped. */
  5223. sgl->addr_hi = bpl->addrHigh;
  5224. sgl->addr_lo = bpl->addrLow;
  5225. if ((i+1) == numBdes)
  5226. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5227. else
  5228. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5229. sgl->word2 = cpu_to_le32(sgl->word2);
  5230. /* swap the size field back to the cpu so we
  5231. * can assign it to the sgl.
  5232. */
  5233. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5234. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5235. bpl++;
  5236. sgl++;
  5237. }
  5238. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5239. /* The addrHigh and addrLow fields of the BDE have not
  5240. * been byteswapped yet so they need to be swapped
  5241. * before putting them in the sgl.
  5242. */
  5243. sgl->addr_hi =
  5244. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5245. sgl->addr_lo =
  5246. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5247. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5248. sgl->word2 = cpu_to_le32(sgl->word2);
  5249. sgl->sge_len =
  5250. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5251. }
  5252. return sglq->sli4_xritag;
  5253. }
  5254. /**
  5255. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5256. * @phba: Pointer to HBA context object.
  5257. *
  5258. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5259. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5260. * held.
  5261. *
  5262. * Return: index into SLI4 fast-path FCP queue index.
  5263. **/
  5264. static uint32_t
  5265. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5266. {
  5267. ++phba->fcp_qidx;
  5268. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5269. phba->fcp_qidx = 0;
  5270. return phba->fcp_qidx;
  5271. }
  5272. /**
  5273. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5274. * @phba: Pointer to HBA context object.
  5275. * @piocb: Pointer to command iocb.
  5276. * @wqe: Pointer to the work queue entry.
  5277. *
  5278. * This routine converts the iocb command to its Work Queue Entry
  5279. * equivalent. The wqe pointer should not have any fields set when
  5280. * this routine is called because it will memcpy over them.
  5281. * This routine does not set the CQ_ID or the WQEC bits in the
  5282. * wqe.
  5283. *
  5284. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5285. **/
  5286. static int
  5287. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5288. union lpfc_wqe *wqe)
  5289. {
  5290. uint32_t xmit_len = 0, total_len = 0;
  5291. uint8_t ct = 0;
  5292. uint32_t fip;
  5293. uint32_t abort_tag;
  5294. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5295. uint8_t cmnd;
  5296. uint16_t xritag;
  5297. struct ulp_bde64 *bpl = NULL;
  5298. uint32_t els_id = ELS_ID_DEFAULT;
  5299. int numBdes, i;
  5300. struct ulp_bde64 bde;
  5301. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5302. /* The fcp commands will set command type */
  5303. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5304. command_type = FCP_COMMAND;
  5305. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5306. command_type = ELS_COMMAND_FIP;
  5307. else
  5308. command_type = ELS_COMMAND_NON_FIP;
  5309. /* Some of the fields are in the right position already */
  5310. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5311. abort_tag = (uint32_t) iocbq->iotag;
  5312. xritag = iocbq->sli4_xritag;
  5313. wqe->words[7] = 0; /* The ct field has moved so reset */
  5314. /* words0-2 bpl convert bde */
  5315. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5316. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5317. sizeof(struct ulp_bde64);
  5318. bpl = (struct ulp_bde64 *)
  5319. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5320. if (!bpl)
  5321. return IOCB_ERROR;
  5322. /* Should already be byte swapped. */
  5323. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5324. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5325. /* swap the size field back to the cpu so we
  5326. * can assign it to the sgl.
  5327. */
  5328. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5329. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5330. total_len = 0;
  5331. for (i = 0; i < numBdes; i++) {
  5332. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5333. total_len += bde.tus.f.bdeSize;
  5334. }
  5335. } else
  5336. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5337. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5338. cmnd = iocbq->iocb.ulpCommand;
  5339. switch (iocbq->iocb.ulpCommand) {
  5340. case CMD_ELS_REQUEST64_CR:
  5341. if (!iocbq->iocb.ulpLe) {
  5342. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5343. "2007 Only Limited Edition cmd Format"
  5344. " supported 0x%x\n",
  5345. iocbq->iocb.ulpCommand);
  5346. return IOCB_ERROR;
  5347. }
  5348. wqe->els_req.payload_len = xmit_len;
  5349. /* Els_reguest64 has a TMO */
  5350. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5351. iocbq->iocb.ulpTimeout);
  5352. /* Need a VF for word 4 set the vf bit*/
  5353. bf_set(els_req64_vf, &wqe->els_req, 0);
  5354. /* And a VFID for word 12 */
  5355. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5356. /*
  5357. * Set ct field to 3, indicates that the context_tag field
  5358. * contains the FCFI and remote N_Port_ID is
  5359. * in word 5.
  5360. */
  5361. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5362. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5363. iocbq->iocb.ulpContext);
  5364. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5365. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5366. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5367. if (command_type == ELS_COMMAND_FIP) {
  5368. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5369. >> LPFC_FIP_ELS_ID_SHIFT);
  5370. }
  5371. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5372. break;
  5373. case CMD_XMIT_SEQUENCE64_CX:
  5374. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5375. iocbq->iocb.un.ulpWord[3]);
  5376. wqe->generic.word3 = 0;
  5377. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5378. /* The entire sequence is transmitted for this IOCB */
  5379. xmit_len = total_len;
  5380. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5381. case CMD_XMIT_SEQUENCE64_CR:
  5382. /* word3 iocb=io_tag32 wqe=payload_offset */
  5383. /* payload offset used for multilpe outstanding
  5384. * sequences on the same exchange
  5385. */
  5386. wqe->words[3] = 0;
  5387. /* word4 relative_offset memcpy */
  5388. /* word5 r_ctl/df_ctl memcpy */
  5389. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5390. wqe->xmit_sequence.xmit_len = xmit_len;
  5391. command_type = OTHER_COMMAND;
  5392. break;
  5393. case CMD_XMIT_BCAST64_CN:
  5394. /* word3 iocb=iotag32 wqe=payload_len */
  5395. wqe->words[3] = 0; /* no definition for this in wqe */
  5396. /* word4 iocb=rsvd wqe=rsvd */
  5397. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5398. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5399. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5400. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5401. break;
  5402. case CMD_FCP_IWRITE64_CR:
  5403. command_type = FCP_COMMAND_DATA_OUT;
  5404. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5405. * confusing.
  5406. * word3 is payload_len: byte offset to the sgl entry for the
  5407. * fcp_command.
  5408. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5409. * word5 is initial xfer len 0 = wait for xfer-ready
  5410. */
  5411. /* Always wait for xfer-ready before sending data */
  5412. wqe->fcp_iwrite.initial_xfer_len = 0;
  5413. /* word 4 (xfer length) should have been set on the memcpy */
  5414. /* allow write to fall through to read */
  5415. case CMD_FCP_IREAD64_CR:
  5416. /* FCP_CMD is always the 1st sgl entry */
  5417. wqe->fcp_iread.payload_len =
  5418. xmit_len + sizeof(struct fcp_rsp);
  5419. /* word 4 (xfer length) should have been set on the memcpy */
  5420. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5421. iocbq->iocb.ulpFCP2Rcvy);
  5422. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5423. /* The XC bit and the XS bit are similar. The driver never
  5424. * tracked whether or not the exchange was previouslly open.
  5425. * XC = Exchange create, 0 is create. 1 is already open.
  5426. * XS = link cmd: 1 do not close the exchange after command.
  5427. * XS = 0 close exchange when command completes.
  5428. * The only time we would not set the XC bit is when the XS bit
  5429. * is set and we are sending our 2nd or greater command on
  5430. * this exchange.
  5431. */
  5432. /* Always open the exchange */
  5433. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5434. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5435. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5436. break;
  5437. case CMD_FCP_ICMND64_CR:
  5438. /* Always open the exchange */
  5439. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5440. wqe->words[4] = 0;
  5441. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5442. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5443. break;
  5444. case CMD_GEN_REQUEST64_CR:
  5445. /* word3 command length is described as byte offset to the
  5446. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5447. * sgl[0] = cmnd
  5448. * sgl[1] = rsp.
  5449. *
  5450. */
  5451. wqe->gen_req.command_len = xmit_len;
  5452. /* Word4 parameter copied in the memcpy */
  5453. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5454. /* word6 context tag copied in memcpy */
  5455. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5456. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5457. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5458. "2015 Invalid CT %x command 0x%x\n",
  5459. ct, iocbq->iocb.ulpCommand);
  5460. return IOCB_ERROR;
  5461. }
  5462. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5463. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5464. iocbq->iocb.ulpTimeout);
  5465. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5466. command_type = OTHER_COMMAND;
  5467. break;
  5468. case CMD_XMIT_ELS_RSP64_CX:
  5469. /* words0-2 BDE memcpy */
  5470. /* word3 iocb=iotag32 wqe=rsvd */
  5471. wqe->words[3] = 0;
  5472. /* word4 iocb=did wge=rsvd. */
  5473. wqe->words[4] = 0;
  5474. /* word5 iocb=rsvd wge=did */
  5475. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5476. iocbq->iocb.un.elsreq64.remoteID);
  5477. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5478. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5479. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5480. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5481. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5482. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5483. iocbq->vport->vpi + phba->vpi_base);
  5484. command_type = OTHER_COMMAND;
  5485. break;
  5486. case CMD_CLOSE_XRI_CN:
  5487. case CMD_ABORT_XRI_CN:
  5488. case CMD_ABORT_XRI_CX:
  5489. /* words 0-2 memcpy should be 0 rserved */
  5490. /* port will send abts */
  5491. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5492. /*
  5493. * The link is down so the fw does not need to send abts
  5494. * on the wire.
  5495. */
  5496. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5497. else
  5498. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5499. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5500. wqe->words[5] = 0;
  5501. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5502. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5503. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5504. /*
  5505. * The abort handler will send us CMD_ABORT_XRI_CN or
  5506. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5507. */
  5508. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5509. cmnd = CMD_ABORT_XRI_CX;
  5510. command_type = OTHER_COMMAND;
  5511. xritag = 0;
  5512. break;
  5513. case CMD_XMIT_BLS_RSP64_CX:
  5514. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5515. * we re-construct this WQE here based on information in
  5516. * iocbq from scratch.
  5517. */
  5518. memset(wqe, 0, sizeof(union lpfc_wqe));
  5519. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5520. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5521. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5522. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5523. LPFC_ABTS_UNSOL_INT) {
  5524. /* ABTS sent by initiator to CT exchange, the
  5525. * RX_ID field will be filled with the newly
  5526. * allocated responder XRI.
  5527. */
  5528. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5529. iocbq->sli4_xritag);
  5530. } else {
  5531. /* ABTS sent by responder to CT exchange, the
  5532. * RX_ID field will be filled with the responder
  5533. * RX_ID from ABTS.
  5534. */
  5535. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5536. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5537. }
  5538. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5539. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5540. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5541. iocbq->iocb.ulpContext);
  5542. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5543. command_type = OTHER_COMMAND;
  5544. break;
  5545. case CMD_XRI_ABORTED_CX:
  5546. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5547. /* words0-2 are all 0's no bde */
  5548. /* word3 and word4 are rsvrd */
  5549. wqe->words[3] = 0;
  5550. wqe->words[4] = 0;
  5551. /* word5 iocb=rsvd wge=did */
  5552. /* There is no remote port id in the IOCB? */
  5553. /* Let this fall through and fail */
  5554. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5555. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5556. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5557. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5558. default:
  5559. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5560. "2014 Invalid command 0x%x\n",
  5561. iocbq->iocb.ulpCommand);
  5562. return IOCB_ERROR;
  5563. break;
  5564. }
  5565. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5566. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5567. wqe->generic.abort_tag = abort_tag;
  5568. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5569. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5570. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5571. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5572. return 0;
  5573. }
  5574. /**
  5575. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5576. * @phba: Pointer to HBA context object.
  5577. * @ring_number: SLI ring number to issue iocb on.
  5578. * @piocb: Pointer to command iocb.
  5579. * @flag: Flag indicating if this command can be put into txq.
  5580. *
  5581. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5582. * an iocb command to an HBA with SLI-4 interface spec.
  5583. *
  5584. * This function is called with hbalock held. The function will return success
  5585. * after it successfully submit the iocb to firmware or after adding to the
  5586. * txq.
  5587. **/
  5588. static int
  5589. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5590. struct lpfc_iocbq *piocb, uint32_t flag)
  5591. {
  5592. struct lpfc_sglq *sglq;
  5593. uint16_t xritag;
  5594. union lpfc_wqe wqe;
  5595. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5596. if (piocb->sli4_xritag == NO_XRI) {
  5597. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5598. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5599. sglq = NULL;
  5600. else {
  5601. sglq = __lpfc_sli_get_sglq(phba);
  5602. if (!sglq)
  5603. return IOCB_ERROR;
  5604. piocb->sli4_xritag = sglq->sli4_xritag;
  5605. }
  5606. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5607. sglq = NULL; /* These IO's already have an XRI and
  5608. * a mapped sgl.
  5609. */
  5610. } else {
  5611. /* This is a continuation of a commandi,(CX) so this
  5612. * sglq is on the active list
  5613. */
  5614. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5615. if (!sglq)
  5616. return IOCB_ERROR;
  5617. }
  5618. if (sglq) {
  5619. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5620. if (xritag != sglq->sli4_xritag)
  5621. return IOCB_ERROR;
  5622. }
  5623. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5624. return IOCB_ERROR;
  5625. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5626. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5627. /*
  5628. * For FCP command IOCB, get a new WQ index to distribute
  5629. * WQE across the WQsr. On the other hand, for abort IOCB,
  5630. * it carries the same WQ index to the original command
  5631. * IOCB.
  5632. */
  5633. if (piocb->iocb_flag & LPFC_IO_FCP)
  5634. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5635. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5636. &wqe))
  5637. return IOCB_ERROR;
  5638. } else {
  5639. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5640. return IOCB_ERROR;
  5641. }
  5642. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5643. return 0;
  5644. }
  5645. /**
  5646. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5647. *
  5648. * This routine wraps the actual lockless version for issusing IOCB function
  5649. * pointer from the lpfc_hba struct.
  5650. *
  5651. * Return codes:
  5652. * IOCB_ERROR - Error
  5653. * IOCB_SUCCESS - Success
  5654. * IOCB_BUSY - Busy
  5655. **/
  5656. static inline int
  5657. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5658. struct lpfc_iocbq *piocb, uint32_t flag)
  5659. {
  5660. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5661. }
  5662. /**
  5663. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5664. * @phba: The hba struct for which this call is being executed.
  5665. * @dev_grp: The HBA PCI-Device group number.
  5666. *
  5667. * This routine sets up the SLI interface API function jump table in @phba
  5668. * struct.
  5669. * Returns: 0 - success, -ENODEV - failure.
  5670. **/
  5671. int
  5672. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5673. {
  5674. switch (dev_grp) {
  5675. case LPFC_PCI_DEV_LP:
  5676. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5677. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5678. break;
  5679. case LPFC_PCI_DEV_OC:
  5680. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5681. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5682. break;
  5683. default:
  5684. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5685. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5686. dev_grp);
  5687. return -ENODEV;
  5688. break;
  5689. }
  5690. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5691. return 0;
  5692. }
  5693. /**
  5694. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5695. * @phba: Pointer to HBA context object.
  5696. * @pring: Pointer to driver SLI ring object.
  5697. * @piocb: Pointer to command iocb.
  5698. * @flag: Flag indicating if this command can be put into txq.
  5699. *
  5700. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5701. * function. This function gets the hbalock and calls
  5702. * __lpfc_sli_issue_iocb function and will return the error returned
  5703. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5704. * functions which do not hold hbalock.
  5705. **/
  5706. int
  5707. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5708. struct lpfc_iocbq *piocb, uint32_t flag)
  5709. {
  5710. unsigned long iflags;
  5711. int rc;
  5712. spin_lock_irqsave(&phba->hbalock, iflags);
  5713. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5714. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5715. return rc;
  5716. }
  5717. /**
  5718. * lpfc_extra_ring_setup - Extra ring setup function
  5719. * @phba: Pointer to HBA context object.
  5720. *
  5721. * This function is called while driver attaches with the
  5722. * HBA to setup the extra ring. The extra ring is used
  5723. * only when driver needs to support target mode functionality
  5724. * or IP over FC functionalities.
  5725. *
  5726. * This function is called with no lock held.
  5727. **/
  5728. static int
  5729. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5730. {
  5731. struct lpfc_sli *psli;
  5732. struct lpfc_sli_ring *pring;
  5733. psli = &phba->sli;
  5734. /* Adjust cmd/rsp ring iocb entries more evenly */
  5735. /* Take some away from the FCP ring */
  5736. pring = &psli->ring[psli->fcp_ring];
  5737. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5738. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5739. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5740. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5741. /* and give them to the extra ring */
  5742. pring = &psli->ring[psli->extra_ring];
  5743. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5744. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5745. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5746. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5747. /* Setup default profile for this ring */
  5748. pring->iotag_max = 4096;
  5749. pring->num_mask = 1;
  5750. pring->prt[0].profile = 0; /* Mask 0 */
  5751. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5752. pring->prt[0].type = phba->cfg_multi_ring_type;
  5753. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5754. return 0;
  5755. }
  5756. /**
  5757. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5758. * @phba: Pointer to HBA context object.
  5759. * @pring: Pointer to driver SLI ring object.
  5760. * @iocbq: Pointer to iocb object.
  5761. *
  5762. * This function is called by the slow ring event handler
  5763. * function when there is an ASYNC event iocb in the ring.
  5764. * This function is called with no lock held.
  5765. * Currently this function handles only temperature related
  5766. * ASYNC events. The function decodes the temperature sensor
  5767. * event message and posts events for the management applications.
  5768. **/
  5769. static void
  5770. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5771. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5772. {
  5773. IOCB_t *icmd;
  5774. uint16_t evt_code;
  5775. uint16_t temp;
  5776. struct temp_event temp_event_data;
  5777. struct Scsi_Host *shost;
  5778. uint32_t *iocb_w;
  5779. icmd = &iocbq->iocb;
  5780. evt_code = icmd->un.asyncstat.evt_code;
  5781. temp = icmd->ulpContext;
  5782. if ((evt_code != ASYNC_TEMP_WARN) &&
  5783. (evt_code != ASYNC_TEMP_SAFE)) {
  5784. iocb_w = (uint32_t *) icmd;
  5785. lpfc_printf_log(phba,
  5786. KERN_ERR,
  5787. LOG_SLI,
  5788. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5789. " evt_code 0x%x\n"
  5790. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5791. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5792. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5793. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5794. pring->ringno,
  5795. icmd->un.asyncstat.evt_code,
  5796. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5797. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5798. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5799. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5800. return;
  5801. }
  5802. temp_event_data.data = (uint32_t)temp;
  5803. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5804. if (evt_code == ASYNC_TEMP_WARN) {
  5805. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5806. lpfc_printf_log(phba,
  5807. KERN_ERR,
  5808. LOG_TEMP,
  5809. "0347 Adapter is very hot, please take "
  5810. "corrective action. temperature : %d Celsius\n",
  5811. temp);
  5812. }
  5813. if (evt_code == ASYNC_TEMP_SAFE) {
  5814. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5815. lpfc_printf_log(phba,
  5816. KERN_ERR,
  5817. LOG_TEMP,
  5818. "0340 Adapter temperature is OK now. "
  5819. "temperature : %d Celsius\n",
  5820. temp);
  5821. }
  5822. /* Send temperature change event to applications */
  5823. shost = lpfc_shost_from_vport(phba->pport);
  5824. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5825. sizeof(temp_event_data), (char *) &temp_event_data,
  5826. LPFC_NL_VENDOR_ID);
  5827. }
  5828. /**
  5829. * lpfc_sli_setup - SLI ring setup function
  5830. * @phba: Pointer to HBA context object.
  5831. *
  5832. * lpfc_sli_setup sets up rings of the SLI interface with
  5833. * number of iocbs per ring and iotags. This function is
  5834. * called while driver attach to the HBA and before the
  5835. * interrupts are enabled. So there is no need for locking.
  5836. *
  5837. * This function always returns 0.
  5838. **/
  5839. int
  5840. lpfc_sli_setup(struct lpfc_hba *phba)
  5841. {
  5842. int i, totiocbsize = 0;
  5843. struct lpfc_sli *psli = &phba->sli;
  5844. struct lpfc_sli_ring *pring;
  5845. psli->num_rings = MAX_CONFIGURED_RINGS;
  5846. psli->sli_flag = 0;
  5847. psli->fcp_ring = LPFC_FCP_RING;
  5848. psli->next_ring = LPFC_FCP_NEXT_RING;
  5849. psli->extra_ring = LPFC_EXTRA_RING;
  5850. psli->iocbq_lookup = NULL;
  5851. psli->iocbq_lookup_len = 0;
  5852. psli->last_iotag = 0;
  5853. for (i = 0; i < psli->num_rings; i++) {
  5854. pring = &psli->ring[i];
  5855. switch (i) {
  5856. case LPFC_FCP_RING: /* ring 0 - FCP */
  5857. /* numCiocb and numRiocb are used in config_port */
  5858. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5859. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5860. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5861. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5862. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5863. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5864. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5865. SLI3_IOCB_CMD_SIZE :
  5866. SLI2_IOCB_CMD_SIZE;
  5867. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5868. SLI3_IOCB_RSP_SIZE :
  5869. SLI2_IOCB_RSP_SIZE;
  5870. pring->iotag_ctr = 0;
  5871. pring->iotag_max =
  5872. (phba->cfg_hba_queue_depth * 2);
  5873. pring->fast_iotag = pring->iotag_max;
  5874. pring->num_mask = 0;
  5875. break;
  5876. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5877. /* numCiocb and numRiocb are used in config_port */
  5878. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5879. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5880. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5881. SLI3_IOCB_CMD_SIZE :
  5882. SLI2_IOCB_CMD_SIZE;
  5883. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5884. SLI3_IOCB_RSP_SIZE :
  5885. SLI2_IOCB_RSP_SIZE;
  5886. pring->iotag_max = phba->cfg_hba_queue_depth;
  5887. pring->num_mask = 0;
  5888. break;
  5889. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5890. /* numCiocb and numRiocb are used in config_port */
  5891. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5892. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5893. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5894. SLI3_IOCB_CMD_SIZE :
  5895. SLI2_IOCB_CMD_SIZE;
  5896. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5897. SLI3_IOCB_RSP_SIZE :
  5898. SLI2_IOCB_RSP_SIZE;
  5899. pring->fast_iotag = 0;
  5900. pring->iotag_ctr = 0;
  5901. pring->iotag_max = 4096;
  5902. pring->lpfc_sli_rcv_async_status =
  5903. lpfc_sli_async_event_handler;
  5904. pring->num_mask = LPFC_MAX_RING_MASK;
  5905. pring->prt[0].profile = 0; /* Mask 0 */
  5906. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5907. pring->prt[0].type = FC_TYPE_ELS;
  5908. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5909. lpfc_els_unsol_event;
  5910. pring->prt[1].profile = 0; /* Mask 1 */
  5911. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5912. pring->prt[1].type = FC_TYPE_ELS;
  5913. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5914. lpfc_els_unsol_event;
  5915. pring->prt[2].profile = 0; /* Mask 2 */
  5916. /* NameServer Inquiry */
  5917. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5918. /* NameServer */
  5919. pring->prt[2].type = FC_TYPE_CT;
  5920. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5921. lpfc_ct_unsol_event;
  5922. pring->prt[3].profile = 0; /* Mask 3 */
  5923. /* NameServer response */
  5924. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  5925. /* NameServer */
  5926. pring->prt[3].type = FC_TYPE_CT;
  5927. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5928. lpfc_ct_unsol_event;
  5929. /* abort unsolicited sequence */
  5930. pring->prt[4].profile = 0; /* Mask 4 */
  5931. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  5932. pring->prt[4].type = FC_TYPE_BLS;
  5933. pring->prt[4].lpfc_sli_rcv_unsol_event =
  5934. lpfc_sli4_ct_abort_unsol_event;
  5935. break;
  5936. }
  5937. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5938. (pring->numRiocb * pring->sizeRiocb);
  5939. }
  5940. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5941. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5942. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5943. "SLI2 SLIM Data: x%x x%lx\n",
  5944. phba->brd_no, totiocbsize,
  5945. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5946. }
  5947. if (phba->cfg_multi_ring_support == 2)
  5948. lpfc_extra_ring_setup(phba);
  5949. return 0;
  5950. }
  5951. /**
  5952. * lpfc_sli_queue_setup - Queue initialization function
  5953. * @phba: Pointer to HBA context object.
  5954. *
  5955. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5956. * ring. This function also initializes ring indices of each ring.
  5957. * This function is called during the initialization of the SLI
  5958. * interface of an HBA.
  5959. * This function is called with no lock held and always returns
  5960. * 1.
  5961. **/
  5962. int
  5963. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5964. {
  5965. struct lpfc_sli *psli;
  5966. struct lpfc_sli_ring *pring;
  5967. int i;
  5968. psli = &phba->sli;
  5969. spin_lock_irq(&phba->hbalock);
  5970. INIT_LIST_HEAD(&psli->mboxq);
  5971. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5972. /* Initialize list headers for txq and txcmplq as double linked lists */
  5973. for (i = 0; i < psli->num_rings; i++) {
  5974. pring = &psli->ring[i];
  5975. pring->ringno = i;
  5976. pring->next_cmdidx = 0;
  5977. pring->local_getidx = 0;
  5978. pring->cmdidx = 0;
  5979. INIT_LIST_HEAD(&pring->txq);
  5980. INIT_LIST_HEAD(&pring->txcmplq);
  5981. INIT_LIST_HEAD(&pring->iocb_continueq);
  5982. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5983. INIT_LIST_HEAD(&pring->postbufq);
  5984. }
  5985. spin_unlock_irq(&phba->hbalock);
  5986. return 1;
  5987. }
  5988. /**
  5989. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5990. * @phba: Pointer to HBA context object.
  5991. *
  5992. * This routine flushes the mailbox command subsystem. It will unconditionally
  5993. * flush all the mailbox commands in the three possible stages in the mailbox
  5994. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5995. * command; and completed mailbox command queue. It is caller's responsibility
  5996. * to make sure that the driver is in the proper state to flush the mailbox
  5997. * command sub-system. Namely, the posting of mailbox commands into the
  5998. * pending mailbox command queue from the various clients must be stopped;
  5999. * either the HBA is in a state that it will never works on the outstanding
  6000. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6001. * mailbox command has been completed.
  6002. **/
  6003. static void
  6004. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6005. {
  6006. LIST_HEAD(completions);
  6007. struct lpfc_sli *psli = &phba->sli;
  6008. LPFC_MBOXQ_t *pmb;
  6009. unsigned long iflag;
  6010. /* Flush all the mailbox commands in the mbox system */
  6011. spin_lock_irqsave(&phba->hbalock, iflag);
  6012. /* The pending mailbox command queue */
  6013. list_splice_init(&phba->sli.mboxq, &completions);
  6014. /* The outstanding active mailbox command */
  6015. if (psli->mbox_active) {
  6016. list_add_tail(&psli->mbox_active->list, &completions);
  6017. psli->mbox_active = NULL;
  6018. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6019. }
  6020. /* The completed mailbox command queue */
  6021. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6022. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6023. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6024. while (!list_empty(&completions)) {
  6025. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6026. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6027. if (pmb->mbox_cmpl)
  6028. pmb->mbox_cmpl(phba, pmb);
  6029. }
  6030. }
  6031. /**
  6032. * lpfc_sli_host_down - Vport cleanup function
  6033. * @vport: Pointer to virtual port object.
  6034. *
  6035. * lpfc_sli_host_down is called to clean up the resources
  6036. * associated with a vport before destroying virtual
  6037. * port data structures.
  6038. * This function does following operations:
  6039. * - Free discovery resources associated with this virtual
  6040. * port.
  6041. * - Free iocbs associated with this virtual port in
  6042. * the txq.
  6043. * - Send abort for all iocb commands associated with this
  6044. * vport in txcmplq.
  6045. *
  6046. * This function is called with no lock held and always returns 1.
  6047. **/
  6048. int
  6049. lpfc_sli_host_down(struct lpfc_vport *vport)
  6050. {
  6051. LIST_HEAD(completions);
  6052. struct lpfc_hba *phba = vport->phba;
  6053. struct lpfc_sli *psli = &phba->sli;
  6054. struct lpfc_sli_ring *pring;
  6055. struct lpfc_iocbq *iocb, *next_iocb;
  6056. int i;
  6057. unsigned long flags = 0;
  6058. uint16_t prev_pring_flag;
  6059. lpfc_cleanup_discovery_resources(vport);
  6060. spin_lock_irqsave(&phba->hbalock, flags);
  6061. for (i = 0; i < psli->num_rings; i++) {
  6062. pring = &psli->ring[i];
  6063. prev_pring_flag = pring->flag;
  6064. /* Only slow rings */
  6065. if (pring->ringno == LPFC_ELS_RING) {
  6066. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6067. /* Set the lpfc data pending flag */
  6068. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6069. }
  6070. /*
  6071. * Error everything on the txq since these iocbs have not been
  6072. * given to the FW yet.
  6073. */
  6074. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6075. if (iocb->vport != vport)
  6076. continue;
  6077. list_move_tail(&iocb->list, &completions);
  6078. pring->txq_cnt--;
  6079. }
  6080. /* Next issue ABTS for everything on the txcmplq */
  6081. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6082. list) {
  6083. if (iocb->vport != vport)
  6084. continue;
  6085. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6086. }
  6087. pring->flag = prev_pring_flag;
  6088. }
  6089. spin_unlock_irqrestore(&phba->hbalock, flags);
  6090. /* Cancel all the IOCBs from the completions list */
  6091. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6092. IOERR_SLI_DOWN);
  6093. return 1;
  6094. }
  6095. /**
  6096. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6097. * @phba: Pointer to HBA context object.
  6098. *
  6099. * This function cleans up all iocb, buffers, mailbox commands
  6100. * while shutting down the HBA. This function is called with no
  6101. * lock held and always returns 1.
  6102. * This function does the following to cleanup driver resources:
  6103. * - Free discovery resources for each virtual port
  6104. * - Cleanup any pending fabric iocbs
  6105. * - Iterate through the iocb txq and free each entry
  6106. * in the list.
  6107. * - Free up any buffer posted to the HBA
  6108. * - Free mailbox commands in the mailbox queue.
  6109. **/
  6110. int
  6111. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6112. {
  6113. LIST_HEAD(completions);
  6114. struct lpfc_sli *psli = &phba->sli;
  6115. struct lpfc_sli_ring *pring;
  6116. struct lpfc_dmabuf *buf_ptr;
  6117. unsigned long flags = 0;
  6118. int i;
  6119. /* Shutdown the mailbox command sub-system */
  6120. lpfc_sli_mbox_sys_shutdown(phba);
  6121. lpfc_hba_down_prep(phba);
  6122. lpfc_fabric_abort_hba(phba);
  6123. spin_lock_irqsave(&phba->hbalock, flags);
  6124. for (i = 0; i < psli->num_rings; i++) {
  6125. pring = &psli->ring[i];
  6126. /* Only slow rings */
  6127. if (pring->ringno == LPFC_ELS_RING) {
  6128. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6129. /* Set the lpfc data pending flag */
  6130. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6131. }
  6132. /*
  6133. * Error everything on the txq since these iocbs have not been
  6134. * given to the FW yet.
  6135. */
  6136. list_splice_init(&pring->txq, &completions);
  6137. pring->txq_cnt = 0;
  6138. }
  6139. spin_unlock_irqrestore(&phba->hbalock, flags);
  6140. /* Cancel all the IOCBs from the completions list */
  6141. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6142. IOERR_SLI_DOWN);
  6143. spin_lock_irqsave(&phba->hbalock, flags);
  6144. list_splice_init(&phba->elsbuf, &completions);
  6145. phba->elsbuf_cnt = 0;
  6146. phba->elsbuf_prev_cnt = 0;
  6147. spin_unlock_irqrestore(&phba->hbalock, flags);
  6148. while (!list_empty(&completions)) {
  6149. list_remove_head(&completions, buf_ptr,
  6150. struct lpfc_dmabuf, list);
  6151. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6152. kfree(buf_ptr);
  6153. }
  6154. /* Return any active mbox cmds */
  6155. del_timer_sync(&psli->mbox_tmo);
  6156. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6157. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6158. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6159. return 1;
  6160. }
  6161. /**
  6162. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6163. * @phba: Pointer to HBA context object.
  6164. *
  6165. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6166. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6167. * lock held and always returns 1.
  6168. *
  6169. * This function does the following to cleanup driver FCoE function resources:
  6170. * - Free discovery resources for each virtual port
  6171. * - Cleanup any pending fabric iocbs
  6172. * - Iterate through the iocb txq and free each entry in the list.
  6173. * - Free up any buffer posted to the HBA.
  6174. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6175. * - Free mailbox commands in the mailbox queue.
  6176. **/
  6177. int
  6178. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6179. {
  6180. /* Stop the SLI4 device port */
  6181. lpfc_stop_port(phba);
  6182. /* Tear down the queues in the HBA */
  6183. lpfc_sli4_queue_unset(phba);
  6184. /* unregister default FCFI from the HBA */
  6185. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6186. return 1;
  6187. }
  6188. /**
  6189. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6190. * @srcp: Source memory pointer.
  6191. * @destp: Destination memory pointer.
  6192. * @cnt: Number of words required to be copied.
  6193. *
  6194. * This function is used for copying data between driver memory
  6195. * and the SLI memory. This function also changes the endianness
  6196. * of each word if native endianness is different from SLI
  6197. * endianness. This function can be called with or without
  6198. * lock.
  6199. **/
  6200. void
  6201. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6202. {
  6203. uint32_t *src = srcp;
  6204. uint32_t *dest = destp;
  6205. uint32_t ldata;
  6206. int i;
  6207. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6208. ldata = *src;
  6209. ldata = le32_to_cpu(ldata);
  6210. *dest = ldata;
  6211. src++;
  6212. dest++;
  6213. }
  6214. }
  6215. /**
  6216. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6217. * @srcp: Source memory pointer.
  6218. * @destp: Destination memory pointer.
  6219. * @cnt: Number of words required to be copied.
  6220. *
  6221. * This function is used for copying data between a data structure
  6222. * with big endian representation to local endianness.
  6223. * This function can be called with or without lock.
  6224. **/
  6225. void
  6226. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6227. {
  6228. uint32_t *src = srcp;
  6229. uint32_t *dest = destp;
  6230. uint32_t ldata;
  6231. int i;
  6232. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6233. ldata = *src;
  6234. ldata = be32_to_cpu(ldata);
  6235. *dest = ldata;
  6236. src++;
  6237. dest++;
  6238. }
  6239. }
  6240. /**
  6241. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6242. * @phba: Pointer to HBA context object.
  6243. * @pring: Pointer to driver SLI ring object.
  6244. * @mp: Pointer to driver buffer object.
  6245. *
  6246. * This function is called with no lock held.
  6247. * It always return zero after adding the buffer to the postbufq
  6248. * buffer list.
  6249. **/
  6250. int
  6251. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6252. struct lpfc_dmabuf *mp)
  6253. {
  6254. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6255. later */
  6256. spin_lock_irq(&phba->hbalock);
  6257. list_add_tail(&mp->list, &pring->postbufq);
  6258. pring->postbufq_cnt++;
  6259. spin_unlock_irq(&phba->hbalock);
  6260. return 0;
  6261. }
  6262. /**
  6263. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6264. * @phba: Pointer to HBA context object.
  6265. *
  6266. * When HBQ is enabled, buffers are searched based on tags. This function
  6267. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6268. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6269. * does not conflict with tags of buffer posted for unsolicited events.
  6270. * The function returns the allocated tag. The function is called with
  6271. * no locks held.
  6272. **/
  6273. uint32_t
  6274. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6275. {
  6276. spin_lock_irq(&phba->hbalock);
  6277. phba->buffer_tag_count++;
  6278. /*
  6279. * Always set the QUE_BUFTAG_BIT to distiguish between
  6280. * a tag assigned by HBQ.
  6281. */
  6282. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6283. spin_unlock_irq(&phba->hbalock);
  6284. return phba->buffer_tag_count;
  6285. }
  6286. /**
  6287. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6288. * @phba: Pointer to HBA context object.
  6289. * @pring: Pointer to driver SLI ring object.
  6290. * @tag: Buffer tag.
  6291. *
  6292. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6293. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6294. * iocb is posted to the response ring with the tag of the buffer.
  6295. * This function searches the pring->postbufq list using the tag
  6296. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6297. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6298. * buffer is returned to the caller else NULL is returned.
  6299. * This function is called with no lock held.
  6300. **/
  6301. struct lpfc_dmabuf *
  6302. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6303. uint32_t tag)
  6304. {
  6305. struct lpfc_dmabuf *mp, *next_mp;
  6306. struct list_head *slp = &pring->postbufq;
  6307. /* Search postbufq, from the begining, looking for a match on tag */
  6308. spin_lock_irq(&phba->hbalock);
  6309. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6310. if (mp->buffer_tag == tag) {
  6311. list_del_init(&mp->list);
  6312. pring->postbufq_cnt--;
  6313. spin_unlock_irq(&phba->hbalock);
  6314. return mp;
  6315. }
  6316. }
  6317. spin_unlock_irq(&phba->hbalock);
  6318. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6319. "0402 Cannot find virtual addr for buffer tag on "
  6320. "ring %d Data x%lx x%p x%p x%x\n",
  6321. pring->ringno, (unsigned long) tag,
  6322. slp->next, slp->prev, pring->postbufq_cnt);
  6323. return NULL;
  6324. }
  6325. /**
  6326. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6327. * @phba: Pointer to HBA context object.
  6328. * @pring: Pointer to driver SLI ring object.
  6329. * @phys: DMA address of the buffer.
  6330. *
  6331. * This function searches the buffer list using the dma_address
  6332. * of unsolicited event to find the driver's lpfc_dmabuf object
  6333. * corresponding to the dma_address. The function returns the
  6334. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6335. * This function is called by the ct and els unsolicited event
  6336. * handlers to get the buffer associated with the unsolicited
  6337. * event.
  6338. *
  6339. * This function is called with no lock held.
  6340. **/
  6341. struct lpfc_dmabuf *
  6342. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6343. dma_addr_t phys)
  6344. {
  6345. struct lpfc_dmabuf *mp, *next_mp;
  6346. struct list_head *slp = &pring->postbufq;
  6347. /* Search postbufq, from the begining, looking for a match on phys */
  6348. spin_lock_irq(&phba->hbalock);
  6349. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6350. if (mp->phys == phys) {
  6351. list_del_init(&mp->list);
  6352. pring->postbufq_cnt--;
  6353. spin_unlock_irq(&phba->hbalock);
  6354. return mp;
  6355. }
  6356. }
  6357. spin_unlock_irq(&phba->hbalock);
  6358. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6359. "0410 Cannot find virtual addr for mapped buf on "
  6360. "ring %d Data x%llx x%p x%p x%x\n",
  6361. pring->ringno, (unsigned long long)phys,
  6362. slp->next, slp->prev, pring->postbufq_cnt);
  6363. return NULL;
  6364. }
  6365. /**
  6366. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6367. * @phba: Pointer to HBA context object.
  6368. * @cmdiocb: Pointer to driver command iocb object.
  6369. * @rspiocb: Pointer to driver response iocb object.
  6370. *
  6371. * This function is the completion handler for the abort iocbs for
  6372. * ELS commands. This function is called from the ELS ring event
  6373. * handler with no lock held. This function frees memory resources
  6374. * associated with the abort iocb.
  6375. **/
  6376. static void
  6377. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6378. struct lpfc_iocbq *rspiocb)
  6379. {
  6380. IOCB_t *irsp = &rspiocb->iocb;
  6381. uint16_t abort_iotag, abort_context;
  6382. struct lpfc_iocbq *abort_iocb;
  6383. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6384. abort_iocb = NULL;
  6385. if (irsp->ulpStatus) {
  6386. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6387. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6388. spin_lock_irq(&phba->hbalock);
  6389. if (phba->sli_rev < LPFC_SLI_REV4) {
  6390. if (abort_iotag != 0 &&
  6391. abort_iotag <= phba->sli.last_iotag)
  6392. abort_iocb =
  6393. phba->sli.iocbq_lookup[abort_iotag];
  6394. } else
  6395. /* For sli4 the abort_tag is the XRI,
  6396. * so the abort routine puts the iotag of the iocb
  6397. * being aborted in the context field of the abort
  6398. * IOCB.
  6399. */
  6400. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6401. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6402. "0327 Cannot abort els iocb %p "
  6403. "with tag %x context %x, abort status %x, "
  6404. "abort code %x\n",
  6405. abort_iocb, abort_iotag, abort_context,
  6406. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6407. /*
  6408. * If the iocb is not found in Firmware queue the iocb
  6409. * might have completed already. Do not free it again.
  6410. */
  6411. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6412. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6413. spin_unlock_irq(&phba->hbalock);
  6414. lpfc_sli_release_iocbq(phba, cmdiocb);
  6415. return;
  6416. }
  6417. /* For SLI4 the ulpContext field for abort IOCB
  6418. * holds the iotag of the IOCB being aborted so
  6419. * the local abort_context needs to be reset to
  6420. * match the aborted IOCBs ulpContext.
  6421. */
  6422. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6423. abort_context = abort_iocb->iocb.ulpContext;
  6424. }
  6425. /*
  6426. * make sure we have the right iocbq before taking it
  6427. * off the txcmplq and try to call completion routine.
  6428. */
  6429. if (!abort_iocb ||
  6430. abort_iocb->iocb.ulpContext != abort_context ||
  6431. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6432. spin_unlock_irq(&phba->hbalock);
  6433. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6434. /*
  6435. * leave the SLI4 aborted command on the txcmplq
  6436. * list and the command complete WCQE's XB bit
  6437. * will tell whether the SGL (XRI) can be released
  6438. * immediately or to the aborted SGL list for the
  6439. * following abort XRI from the HBA.
  6440. */
  6441. list_del_init(&abort_iocb->list);
  6442. pring->txcmplq_cnt--;
  6443. spin_unlock_irq(&phba->hbalock);
  6444. /* Firmware could still be in progress of DMAing
  6445. * payload, so don't free data buffer till after
  6446. * a hbeat.
  6447. */
  6448. spin_lock_irq(&phba->hbalock);
  6449. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6450. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6451. spin_unlock_irq(&phba->hbalock);
  6452. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6453. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6454. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6455. }
  6456. }
  6457. lpfc_sli_release_iocbq(phba, cmdiocb);
  6458. return;
  6459. }
  6460. /**
  6461. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6462. * @phba: Pointer to HBA context object.
  6463. * @cmdiocb: Pointer to driver command iocb object.
  6464. * @rspiocb: Pointer to driver response iocb object.
  6465. *
  6466. * The function is called from SLI ring event handler with no
  6467. * lock held. This function is the completion handler for ELS commands
  6468. * which are aborted. The function frees memory resources used for
  6469. * the aborted ELS commands.
  6470. **/
  6471. static void
  6472. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6473. struct lpfc_iocbq *rspiocb)
  6474. {
  6475. IOCB_t *irsp = &rspiocb->iocb;
  6476. /* ELS cmd tag <ulpIoTag> completes */
  6477. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6478. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6479. "x%x x%x x%x\n",
  6480. irsp->ulpIoTag, irsp->ulpStatus,
  6481. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6482. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6483. lpfc_ct_free_iocb(phba, cmdiocb);
  6484. else
  6485. lpfc_els_free_iocb(phba, cmdiocb);
  6486. return;
  6487. }
  6488. /**
  6489. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6490. * @phba: Pointer to HBA context object.
  6491. * @pring: Pointer to driver SLI ring object.
  6492. * @cmdiocb: Pointer to driver command iocb object.
  6493. *
  6494. * This function issues an abort iocb for the provided command
  6495. * iocb. This function is called with hbalock held.
  6496. * The function returns 0 when it fails due to memory allocation
  6497. * failure or when the command iocb is an abort request.
  6498. **/
  6499. int
  6500. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6501. struct lpfc_iocbq *cmdiocb)
  6502. {
  6503. struct lpfc_vport *vport = cmdiocb->vport;
  6504. struct lpfc_iocbq *abtsiocbp;
  6505. IOCB_t *icmd = NULL;
  6506. IOCB_t *iabt = NULL;
  6507. int retval = IOCB_ERROR;
  6508. /*
  6509. * There are certain command types we don't want to abort. And we
  6510. * don't want to abort commands that are already in the process of
  6511. * being aborted.
  6512. */
  6513. icmd = &cmdiocb->iocb;
  6514. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6515. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6516. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6517. return 0;
  6518. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6519. * callback so that nothing happens when it finishes.
  6520. */
  6521. if ((vport->load_flag & FC_UNLOADING) &&
  6522. (pring->ringno == LPFC_ELS_RING)) {
  6523. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6524. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6525. else
  6526. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6527. goto abort_iotag_exit;
  6528. }
  6529. /* issue ABTS for this IOCB based on iotag */
  6530. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6531. if (abtsiocbp == NULL)
  6532. return 0;
  6533. /* This signals the response to set the correct status
  6534. * before calling the completion handler
  6535. */
  6536. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6537. iabt = &abtsiocbp->iocb;
  6538. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6539. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6540. if (phba->sli_rev == LPFC_SLI_REV4) {
  6541. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6542. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6543. }
  6544. else
  6545. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6546. iabt->ulpLe = 1;
  6547. iabt->ulpClass = icmd->ulpClass;
  6548. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6549. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6550. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6551. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6552. if (phba->link_state >= LPFC_LINK_UP)
  6553. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6554. else
  6555. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6556. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6557. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6558. "0339 Abort xri x%x, original iotag x%x, "
  6559. "abort cmd iotag x%x\n",
  6560. iabt->un.acxri.abortContextTag,
  6561. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6562. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6563. if (retval)
  6564. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6565. abort_iotag_exit:
  6566. /*
  6567. * Caller to this routine should check for IOCB_ERROR
  6568. * and handle it properly. This routine no longer removes
  6569. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6570. */
  6571. return retval;
  6572. }
  6573. /**
  6574. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6575. * @iocbq: Pointer to driver iocb object.
  6576. * @vport: Pointer to driver virtual port object.
  6577. * @tgt_id: SCSI ID of the target.
  6578. * @lun_id: LUN ID of the scsi device.
  6579. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6580. *
  6581. * This function acts as an iocb filter for functions which abort or count
  6582. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6583. * 0 if the filtering criteria is met for the given iocb and will return
  6584. * 1 if the filtering criteria is not met.
  6585. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6586. * given iocb is for the SCSI device specified by vport, tgt_id and
  6587. * lun_id parameter.
  6588. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6589. * given iocb is for the SCSI target specified by vport and tgt_id
  6590. * parameters.
  6591. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6592. * given iocb is for the SCSI host associated with the given vport.
  6593. * This function is called with no locks held.
  6594. **/
  6595. static int
  6596. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6597. uint16_t tgt_id, uint64_t lun_id,
  6598. lpfc_ctx_cmd ctx_cmd)
  6599. {
  6600. struct lpfc_scsi_buf *lpfc_cmd;
  6601. int rc = 1;
  6602. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6603. return rc;
  6604. if (iocbq->vport != vport)
  6605. return rc;
  6606. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6607. if (lpfc_cmd->pCmd == NULL)
  6608. return rc;
  6609. switch (ctx_cmd) {
  6610. case LPFC_CTX_LUN:
  6611. if ((lpfc_cmd->rdata->pnode) &&
  6612. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6613. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6614. rc = 0;
  6615. break;
  6616. case LPFC_CTX_TGT:
  6617. if ((lpfc_cmd->rdata->pnode) &&
  6618. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6619. rc = 0;
  6620. break;
  6621. case LPFC_CTX_HOST:
  6622. rc = 0;
  6623. break;
  6624. default:
  6625. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6626. __func__, ctx_cmd);
  6627. break;
  6628. }
  6629. return rc;
  6630. }
  6631. /**
  6632. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6633. * @vport: Pointer to virtual port.
  6634. * @tgt_id: SCSI ID of the target.
  6635. * @lun_id: LUN ID of the scsi device.
  6636. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6637. *
  6638. * This function returns number of FCP commands pending for the vport.
  6639. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6640. * commands pending on the vport associated with SCSI device specified
  6641. * by tgt_id and lun_id parameters.
  6642. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6643. * commands pending on the vport associated with SCSI target specified
  6644. * by tgt_id parameter.
  6645. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6646. * commands pending on the vport.
  6647. * This function returns the number of iocbs which satisfy the filter.
  6648. * This function is called without any lock held.
  6649. **/
  6650. int
  6651. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6652. lpfc_ctx_cmd ctx_cmd)
  6653. {
  6654. struct lpfc_hba *phba = vport->phba;
  6655. struct lpfc_iocbq *iocbq;
  6656. int sum, i;
  6657. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6658. iocbq = phba->sli.iocbq_lookup[i];
  6659. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6660. ctx_cmd) == 0)
  6661. sum++;
  6662. }
  6663. return sum;
  6664. }
  6665. /**
  6666. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6667. * @phba: Pointer to HBA context object
  6668. * @cmdiocb: Pointer to command iocb object.
  6669. * @rspiocb: Pointer to response iocb object.
  6670. *
  6671. * This function is called when an aborted FCP iocb completes. This
  6672. * function is called by the ring event handler with no lock held.
  6673. * This function frees the iocb.
  6674. **/
  6675. void
  6676. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6677. struct lpfc_iocbq *rspiocb)
  6678. {
  6679. lpfc_sli_release_iocbq(phba, cmdiocb);
  6680. return;
  6681. }
  6682. /**
  6683. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6684. * @vport: Pointer to virtual port.
  6685. * @pring: Pointer to driver SLI ring object.
  6686. * @tgt_id: SCSI ID of the target.
  6687. * @lun_id: LUN ID of the scsi device.
  6688. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6689. *
  6690. * This function sends an abort command for every SCSI command
  6691. * associated with the given virtual port pending on the ring
  6692. * filtered by lpfc_sli_validate_fcp_iocb function.
  6693. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6694. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6695. * parameters
  6696. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6697. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6698. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6699. * FCP iocbs associated with virtual port.
  6700. * This function returns number of iocbs it failed to abort.
  6701. * This function is called with no locks held.
  6702. **/
  6703. int
  6704. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6705. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6706. {
  6707. struct lpfc_hba *phba = vport->phba;
  6708. struct lpfc_iocbq *iocbq;
  6709. struct lpfc_iocbq *abtsiocb;
  6710. IOCB_t *cmd = NULL;
  6711. int errcnt = 0, ret_val = 0;
  6712. int i;
  6713. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6714. iocbq = phba->sli.iocbq_lookup[i];
  6715. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6716. abort_cmd) != 0)
  6717. continue;
  6718. /* issue ABTS for this IOCB based on iotag */
  6719. abtsiocb = lpfc_sli_get_iocbq(phba);
  6720. if (abtsiocb == NULL) {
  6721. errcnt++;
  6722. continue;
  6723. }
  6724. cmd = &iocbq->iocb;
  6725. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6726. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6727. if (phba->sli_rev == LPFC_SLI_REV4)
  6728. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6729. else
  6730. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6731. abtsiocb->iocb.ulpLe = 1;
  6732. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6733. abtsiocb->vport = phba->pport;
  6734. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6735. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6736. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6737. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6738. if (lpfc_is_link_up(phba))
  6739. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6740. else
  6741. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6742. /* Setup callback routine and issue the command. */
  6743. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6744. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6745. abtsiocb, 0);
  6746. if (ret_val == IOCB_ERROR) {
  6747. lpfc_sli_release_iocbq(phba, abtsiocb);
  6748. errcnt++;
  6749. continue;
  6750. }
  6751. }
  6752. return errcnt;
  6753. }
  6754. /**
  6755. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6756. * @phba: Pointer to HBA context object.
  6757. * @cmdiocbq: Pointer to command iocb.
  6758. * @rspiocbq: Pointer to response iocb.
  6759. *
  6760. * This function is the completion handler for iocbs issued using
  6761. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6762. * ring event handler function without any lock held. This function
  6763. * can be called from both worker thread context and interrupt
  6764. * context. This function also can be called from other thread which
  6765. * cleans up the SLI layer objects.
  6766. * This function copy the contents of the response iocb to the
  6767. * response iocb memory object provided by the caller of
  6768. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6769. * sleeps for the iocb completion.
  6770. **/
  6771. static void
  6772. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6773. struct lpfc_iocbq *cmdiocbq,
  6774. struct lpfc_iocbq *rspiocbq)
  6775. {
  6776. wait_queue_head_t *pdone_q;
  6777. unsigned long iflags;
  6778. struct lpfc_scsi_buf *lpfc_cmd;
  6779. spin_lock_irqsave(&phba->hbalock, iflags);
  6780. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6781. if (cmdiocbq->context2 && rspiocbq)
  6782. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6783. &rspiocbq->iocb, sizeof(IOCB_t));
  6784. /* Set the exchange busy flag for task management commands */
  6785. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  6786. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  6787. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  6788. cur_iocbq);
  6789. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  6790. }
  6791. pdone_q = cmdiocbq->context_un.wait_queue;
  6792. if (pdone_q)
  6793. wake_up(pdone_q);
  6794. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6795. return;
  6796. }
  6797. /**
  6798. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6799. * @phba: Pointer to HBA context object..
  6800. * @piocbq: Pointer to command iocb.
  6801. * @flag: Flag to test.
  6802. *
  6803. * This routine grabs the hbalock and then test the iocb_flag to
  6804. * see if the passed in flag is set.
  6805. * Returns:
  6806. * 1 if flag is set.
  6807. * 0 if flag is not set.
  6808. **/
  6809. static int
  6810. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6811. struct lpfc_iocbq *piocbq, uint32_t flag)
  6812. {
  6813. unsigned long iflags;
  6814. int ret;
  6815. spin_lock_irqsave(&phba->hbalock, iflags);
  6816. ret = piocbq->iocb_flag & flag;
  6817. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6818. return ret;
  6819. }
  6820. /**
  6821. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6822. * @phba: Pointer to HBA context object..
  6823. * @pring: Pointer to sli ring.
  6824. * @piocb: Pointer to command iocb.
  6825. * @prspiocbq: Pointer to response iocb.
  6826. * @timeout: Timeout in number of seconds.
  6827. *
  6828. * This function issues the iocb to firmware and waits for the
  6829. * iocb to complete. If the iocb command is not
  6830. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6831. * Caller should not free the iocb resources if this function
  6832. * returns IOCB_TIMEDOUT.
  6833. * The function waits for the iocb completion using an
  6834. * non-interruptible wait.
  6835. * This function will sleep while waiting for iocb completion.
  6836. * So, this function should not be called from any context which
  6837. * does not allow sleeping. Due to the same reason, this function
  6838. * cannot be called with interrupt disabled.
  6839. * This function assumes that the iocb completions occur while
  6840. * this function sleep. So, this function cannot be called from
  6841. * the thread which process iocb completion for this ring.
  6842. * This function clears the iocb_flag of the iocb object before
  6843. * issuing the iocb and the iocb completion handler sets this
  6844. * flag and wakes this thread when the iocb completes.
  6845. * The contents of the response iocb will be copied to prspiocbq
  6846. * by the completion handler when the command completes.
  6847. * This function returns IOCB_SUCCESS when success.
  6848. * This function is called with no lock held.
  6849. **/
  6850. int
  6851. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6852. uint32_t ring_number,
  6853. struct lpfc_iocbq *piocb,
  6854. struct lpfc_iocbq *prspiocbq,
  6855. uint32_t timeout)
  6856. {
  6857. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6858. long timeleft, timeout_req = 0;
  6859. int retval = IOCB_SUCCESS;
  6860. uint32_t creg_val;
  6861. /*
  6862. * If the caller has provided a response iocbq buffer, then context2
  6863. * is NULL or its an error.
  6864. */
  6865. if (prspiocbq) {
  6866. if (piocb->context2)
  6867. return IOCB_ERROR;
  6868. piocb->context2 = prspiocbq;
  6869. }
  6870. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6871. piocb->context_un.wait_queue = &done_q;
  6872. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6873. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6874. creg_val = readl(phba->HCregaddr);
  6875. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6876. writel(creg_val, phba->HCregaddr);
  6877. readl(phba->HCregaddr); /* flush */
  6878. }
  6879. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6880. if (retval == IOCB_SUCCESS) {
  6881. timeout_req = timeout * HZ;
  6882. timeleft = wait_event_timeout(done_q,
  6883. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6884. timeout_req);
  6885. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6886. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6887. "0331 IOCB wake signaled\n");
  6888. } else if (timeleft == 0) {
  6889. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6890. "0338 IOCB wait timeout error - no "
  6891. "wake response Data x%x\n", timeout);
  6892. retval = IOCB_TIMEDOUT;
  6893. } else {
  6894. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6895. "0330 IOCB wake NOT set, "
  6896. "Data x%x x%lx\n",
  6897. timeout, (timeleft / jiffies));
  6898. retval = IOCB_TIMEDOUT;
  6899. }
  6900. } else {
  6901. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6902. "0332 IOCB wait issue failed, Data x%x\n",
  6903. retval);
  6904. retval = IOCB_ERROR;
  6905. }
  6906. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6907. creg_val = readl(phba->HCregaddr);
  6908. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6909. writel(creg_val, phba->HCregaddr);
  6910. readl(phba->HCregaddr); /* flush */
  6911. }
  6912. if (prspiocbq)
  6913. piocb->context2 = NULL;
  6914. piocb->context_un.wait_queue = NULL;
  6915. piocb->iocb_cmpl = NULL;
  6916. return retval;
  6917. }
  6918. /**
  6919. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6920. * @phba: Pointer to HBA context object.
  6921. * @pmboxq: Pointer to driver mailbox object.
  6922. * @timeout: Timeout in number of seconds.
  6923. *
  6924. * This function issues the mailbox to firmware and waits for the
  6925. * mailbox command to complete. If the mailbox command is not
  6926. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6927. * The function waits for the mailbox completion using an
  6928. * interruptible wait. If the thread is woken up due to a
  6929. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6930. * should not free the mailbox resources, if this function returns
  6931. * MBX_TIMEOUT.
  6932. * This function will sleep while waiting for mailbox completion.
  6933. * So, this function should not be called from any context which
  6934. * does not allow sleeping. Due to the same reason, this function
  6935. * cannot be called with interrupt disabled.
  6936. * This function assumes that the mailbox completion occurs while
  6937. * this function sleep. So, this function cannot be called from
  6938. * the worker thread which processes mailbox completion.
  6939. * This function is called in the context of HBA management
  6940. * applications.
  6941. * This function returns MBX_SUCCESS when successful.
  6942. * This function is called with no lock held.
  6943. **/
  6944. int
  6945. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6946. uint32_t timeout)
  6947. {
  6948. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6949. int retval;
  6950. unsigned long flag;
  6951. /* The caller must leave context1 empty. */
  6952. if (pmboxq->context1)
  6953. return MBX_NOT_FINISHED;
  6954. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6955. /* setup wake call as IOCB callback */
  6956. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6957. /* setup context field to pass wait_queue pointer to wake function */
  6958. pmboxq->context1 = &done_q;
  6959. /* now issue the command */
  6960. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6961. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6962. wait_event_interruptible_timeout(done_q,
  6963. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6964. timeout * HZ);
  6965. spin_lock_irqsave(&phba->hbalock, flag);
  6966. pmboxq->context1 = NULL;
  6967. /*
  6968. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6969. * else do not free the resources.
  6970. */
  6971. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6972. retval = MBX_SUCCESS;
  6973. else {
  6974. retval = MBX_TIMEOUT;
  6975. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6976. }
  6977. spin_unlock_irqrestore(&phba->hbalock, flag);
  6978. }
  6979. return retval;
  6980. }
  6981. /**
  6982. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6983. * @phba: Pointer to HBA context.
  6984. *
  6985. * This function is called to shutdown the driver's mailbox sub-system.
  6986. * It first marks the mailbox sub-system is in a block state to prevent
  6987. * the asynchronous mailbox command from issued off the pending mailbox
  6988. * command queue. If the mailbox command sub-system shutdown is due to
  6989. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6990. * the mailbox sub-system flush routine to forcefully bring down the
  6991. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6992. * as with offline or HBA function reset), this routine will wait for the
  6993. * outstanding mailbox command to complete before invoking the mailbox
  6994. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6995. **/
  6996. void
  6997. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6998. {
  6999. struct lpfc_sli *psli = &phba->sli;
  7000. uint8_t actcmd = MBX_HEARTBEAT;
  7001. unsigned long timeout;
  7002. spin_lock_irq(&phba->hbalock);
  7003. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7004. spin_unlock_irq(&phba->hbalock);
  7005. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7006. spin_lock_irq(&phba->hbalock);
  7007. if (phba->sli.mbox_active)
  7008. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7009. spin_unlock_irq(&phba->hbalock);
  7010. /* Determine how long we might wait for the active mailbox
  7011. * command to be gracefully completed by firmware.
  7012. */
  7013. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7014. 1000) + jiffies;
  7015. while (phba->sli.mbox_active) {
  7016. /* Check active mailbox complete status every 2ms */
  7017. msleep(2);
  7018. if (time_after(jiffies, timeout))
  7019. /* Timeout, let the mailbox flush routine to
  7020. * forcefully release active mailbox command
  7021. */
  7022. break;
  7023. }
  7024. }
  7025. lpfc_sli_mbox_sys_flush(phba);
  7026. }
  7027. /**
  7028. * lpfc_sli_eratt_read - read sli-3 error attention events
  7029. * @phba: Pointer to HBA context.
  7030. *
  7031. * This function is called to read the SLI3 device error attention registers
  7032. * for possible error attention events. The caller must hold the hostlock
  7033. * with spin_lock_irq().
  7034. *
  7035. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7036. * Register and returns 0 otherwise.
  7037. **/
  7038. static int
  7039. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7040. {
  7041. uint32_t ha_copy;
  7042. /* Read chip Host Attention (HA) register */
  7043. ha_copy = readl(phba->HAregaddr);
  7044. if (ha_copy & HA_ERATT) {
  7045. /* Read host status register to retrieve error event */
  7046. lpfc_sli_read_hs(phba);
  7047. /* Check if there is a deferred error condition is active */
  7048. if ((HS_FFER1 & phba->work_hs) &&
  7049. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7050. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7051. phba->hba_flag |= DEFER_ERATT;
  7052. /* Clear all interrupt enable conditions */
  7053. writel(0, phba->HCregaddr);
  7054. readl(phba->HCregaddr);
  7055. }
  7056. /* Set the driver HA work bitmap */
  7057. phba->work_ha |= HA_ERATT;
  7058. /* Indicate polling handles this ERATT */
  7059. phba->hba_flag |= HBA_ERATT_HANDLED;
  7060. return 1;
  7061. }
  7062. return 0;
  7063. }
  7064. /**
  7065. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7066. * @phba: Pointer to HBA context.
  7067. *
  7068. * This function is called to read the SLI4 device error attention registers
  7069. * for possible error attention events. The caller must hold the hostlock
  7070. * with spin_lock_irq().
  7071. *
  7072. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7073. * Register and returns 0 otherwise.
  7074. **/
  7075. static int
  7076. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7077. {
  7078. uint32_t uerr_sta_hi, uerr_sta_lo;
  7079. /* For now, use the SLI4 device internal unrecoverable error
  7080. * registers for error attention. This can be changed later.
  7081. */
  7082. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7083. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7084. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7085. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7086. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7087. "1423 HBA Unrecoverable error: "
  7088. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7089. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7090. uerr_sta_lo, uerr_sta_hi,
  7091. phba->sli4_hba.ue_mask_lo,
  7092. phba->sli4_hba.ue_mask_hi);
  7093. phba->work_status[0] = uerr_sta_lo;
  7094. phba->work_status[1] = uerr_sta_hi;
  7095. /* Set the driver HA work bitmap */
  7096. phba->work_ha |= HA_ERATT;
  7097. /* Indicate polling handles this ERATT */
  7098. phba->hba_flag |= HBA_ERATT_HANDLED;
  7099. return 1;
  7100. }
  7101. return 0;
  7102. }
  7103. /**
  7104. * lpfc_sli_check_eratt - check error attention events
  7105. * @phba: Pointer to HBA context.
  7106. *
  7107. * This function is called from timer soft interrupt context to check HBA's
  7108. * error attention register bit for error attention events.
  7109. *
  7110. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7111. * Register and returns 0 otherwise.
  7112. **/
  7113. int
  7114. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7115. {
  7116. uint32_t ha_copy;
  7117. /* If somebody is waiting to handle an eratt, don't process it
  7118. * here. The brdkill function will do this.
  7119. */
  7120. if (phba->link_flag & LS_IGNORE_ERATT)
  7121. return 0;
  7122. /* Check if interrupt handler handles this ERATT */
  7123. spin_lock_irq(&phba->hbalock);
  7124. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7125. /* Interrupt handler has handled ERATT */
  7126. spin_unlock_irq(&phba->hbalock);
  7127. return 0;
  7128. }
  7129. /*
  7130. * If there is deferred error attention, do not check for error
  7131. * attention
  7132. */
  7133. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7134. spin_unlock_irq(&phba->hbalock);
  7135. return 0;
  7136. }
  7137. /* If PCI channel is offline, don't process it */
  7138. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7139. spin_unlock_irq(&phba->hbalock);
  7140. return 0;
  7141. }
  7142. switch (phba->sli_rev) {
  7143. case LPFC_SLI_REV2:
  7144. case LPFC_SLI_REV3:
  7145. /* Read chip Host Attention (HA) register */
  7146. ha_copy = lpfc_sli_eratt_read(phba);
  7147. break;
  7148. case LPFC_SLI_REV4:
  7149. /* Read devcie Uncoverable Error (UERR) registers */
  7150. ha_copy = lpfc_sli4_eratt_read(phba);
  7151. break;
  7152. default:
  7153. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7154. "0299 Invalid SLI revision (%d)\n",
  7155. phba->sli_rev);
  7156. ha_copy = 0;
  7157. break;
  7158. }
  7159. spin_unlock_irq(&phba->hbalock);
  7160. return ha_copy;
  7161. }
  7162. /**
  7163. * lpfc_intr_state_check - Check device state for interrupt handling
  7164. * @phba: Pointer to HBA context.
  7165. *
  7166. * This inline routine checks whether a device or its PCI slot is in a state
  7167. * that the interrupt should be handled.
  7168. *
  7169. * This function returns 0 if the device or the PCI slot is in a state that
  7170. * interrupt should be handled, otherwise -EIO.
  7171. */
  7172. static inline int
  7173. lpfc_intr_state_check(struct lpfc_hba *phba)
  7174. {
  7175. /* If the pci channel is offline, ignore all the interrupts */
  7176. if (unlikely(pci_channel_offline(phba->pcidev)))
  7177. return -EIO;
  7178. /* Update device level interrupt statistics */
  7179. phba->sli.slistat.sli_intr++;
  7180. /* Ignore all interrupts during initialization. */
  7181. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7182. return -EIO;
  7183. return 0;
  7184. }
  7185. /**
  7186. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7187. * @irq: Interrupt number.
  7188. * @dev_id: The device context pointer.
  7189. *
  7190. * This function is directly called from the PCI layer as an interrupt
  7191. * service routine when device with SLI-3 interface spec is enabled with
  7192. * MSI-X multi-message interrupt mode and there are slow-path events in
  7193. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7194. * interrupt mode, this function is called as part of the device-level
  7195. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7196. * is undergoing initialization, the interrupt handler will not process
  7197. * the interrupt. The link attention and ELS ring attention events are
  7198. * handled by the worker thread. The interrupt handler signals the worker
  7199. * thread and returns for these events. This function is called without
  7200. * any lock held. It gets the hbalock to access and update SLI data
  7201. * structures.
  7202. *
  7203. * This function returns IRQ_HANDLED when interrupt is handled else it
  7204. * returns IRQ_NONE.
  7205. **/
  7206. irqreturn_t
  7207. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7208. {
  7209. struct lpfc_hba *phba;
  7210. uint32_t ha_copy, hc_copy;
  7211. uint32_t work_ha_copy;
  7212. unsigned long status;
  7213. unsigned long iflag;
  7214. uint32_t control;
  7215. MAILBOX_t *mbox, *pmbox;
  7216. struct lpfc_vport *vport;
  7217. struct lpfc_nodelist *ndlp;
  7218. struct lpfc_dmabuf *mp;
  7219. LPFC_MBOXQ_t *pmb;
  7220. int rc;
  7221. /*
  7222. * Get the driver's phba structure from the dev_id and
  7223. * assume the HBA is not interrupting.
  7224. */
  7225. phba = (struct lpfc_hba *)dev_id;
  7226. if (unlikely(!phba))
  7227. return IRQ_NONE;
  7228. /*
  7229. * Stuff needs to be attented to when this function is invoked as an
  7230. * individual interrupt handler in MSI-X multi-message interrupt mode
  7231. */
  7232. if (phba->intr_type == MSIX) {
  7233. /* Check device state for handling interrupt */
  7234. if (lpfc_intr_state_check(phba))
  7235. return IRQ_NONE;
  7236. /* Need to read HA REG for slow-path events */
  7237. spin_lock_irqsave(&phba->hbalock, iflag);
  7238. ha_copy = readl(phba->HAregaddr);
  7239. /* If somebody is waiting to handle an eratt don't process it
  7240. * here. The brdkill function will do this.
  7241. */
  7242. if (phba->link_flag & LS_IGNORE_ERATT)
  7243. ha_copy &= ~HA_ERATT;
  7244. /* Check the need for handling ERATT in interrupt handler */
  7245. if (ha_copy & HA_ERATT) {
  7246. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7247. /* ERATT polling has handled ERATT */
  7248. ha_copy &= ~HA_ERATT;
  7249. else
  7250. /* Indicate interrupt handler handles ERATT */
  7251. phba->hba_flag |= HBA_ERATT_HANDLED;
  7252. }
  7253. /*
  7254. * If there is deferred error attention, do not check for any
  7255. * interrupt.
  7256. */
  7257. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7258. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7259. return IRQ_NONE;
  7260. }
  7261. /* Clear up only attention source related to slow-path */
  7262. hc_copy = readl(phba->HCregaddr);
  7263. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7264. HC_LAINT_ENA | HC_ERINT_ENA),
  7265. phba->HCregaddr);
  7266. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7267. phba->HAregaddr);
  7268. writel(hc_copy, phba->HCregaddr);
  7269. readl(phba->HAregaddr); /* flush */
  7270. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7271. } else
  7272. ha_copy = phba->ha_copy;
  7273. work_ha_copy = ha_copy & phba->work_ha_mask;
  7274. if (work_ha_copy) {
  7275. if (work_ha_copy & HA_LATT) {
  7276. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7277. /*
  7278. * Turn off Link Attention interrupts
  7279. * until CLEAR_LA done
  7280. */
  7281. spin_lock_irqsave(&phba->hbalock, iflag);
  7282. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7283. control = readl(phba->HCregaddr);
  7284. control &= ~HC_LAINT_ENA;
  7285. writel(control, phba->HCregaddr);
  7286. readl(phba->HCregaddr); /* flush */
  7287. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7288. }
  7289. else
  7290. work_ha_copy &= ~HA_LATT;
  7291. }
  7292. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7293. /*
  7294. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7295. * the only slow ring.
  7296. */
  7297. status = (work_ha_copy &
  7298. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7299. status >>= (4*LPFC_ELS_RING);
  7300. if (status & HA_RXMASK) {
  7301. spin_lock_irqsave(&phba->hbalock, iflag);
  7302. control = readl(phba->HCregaddr);
  7303. lpfc_debugfs_slow_ring_trc(phba,
  7304. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7305. control, status,
  7306. (uint32_t)phba->sli.slistat.sli_intr);
  7307. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7308. lpfc_debugfs_slow_ring_trc(phba,
  7309. "ISR Disable ring:"
  7310. "pwork:x%x hawork:x%x wait:x%x",
  7311. phba->work_ha, work_ha_copy,
  7312. (uint32_t)((unsigned long)
  7313. &phba->work_waitq));
  7314. control &=
  7315. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7316. writel(control, phba->HCregaddr);
  7317. readl(phba->HCregaddr); /* flush */
  7318. }
  7319. else {
  7320. lpfc_debugfs_slow_ring_trc(phba,
  7321. "ISR slow ring: pwork:"
  7322. "x%x hawork:x%x wait:x%x",
  7323. phba->work_ha, work_ha_copy,
  7324. (uint32_t)((unsigned long)
  7325. &phba->work_waitq));
  7326. }
  7327. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7328. }
  7329. }
  7330. spin_lock_irqsave(&phba->hbalock, iflag);
  7331. if (work_ha_copy & HA_ERATT) {
  7332. lpfc_sli_read_hs(phba);
  7333. /*
  7334. * Check if there is a deferred error condition
  7335. * is active
  7336. */
  7337. if ((HS_FFER1 & phba->work_hs) &&
  7338. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7339. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7340. phba->hba_flag |= DEFER_ERATT;
  7341. /* Clear all interrupt enable conditions */
  7342. writel(0, phba->HCregaddr);
  7343. readl(phba->HCregaddr);
  7344. }
  7345. }
  7346. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7347. pmb = phba->sli.mbox_active;
  7348. pmbox = &pmb->u.mb;
  7349. mbox = phba->mbox;
  7350. vport = pmb->vport;
  7351. /* First check out the status word */
  7352. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7353. if (pmbox->mbxOwner != OWN_HOST) {
  7354. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7355. /*
  7356. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7357. * mbxStatus <status>
  7358. */
  7359. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7360. LOG_SLI,
  7361. "(%d):0304 Stray Mailbox "
  7362. "Interrupt mbxCommand x%x "
  7363. "mbxStatus x%x\n",
  7364. (vport ? vport->vpi : 0),
  7365. pmbox->mbxCommand,
  7366. pmbox->mbxStatus);
  7367. /* clear mailbox attention bit */
  7368. work_ha_copy &= ~HA_MBATT;
  7369. } else {
  7370. phba->sli.mbox_active = NULL;
  7371. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7372. phba->last_completion_time = jiffies;
  7373. del_timer(&phba->sli.mbox_tmo);
  7374. if (pmb->mbox_cmpl) {
  7375. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7376. MAILBOX_CMD_SIZE);
  7377. }
  7378. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7379. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7380. lpfc_debugfs_disc_trc(vport,
  7381. LPFC_DISC_TRC_MBOX_VPORT,
  7382. "MBOX dflt rpi: : "
  7383. "status:x%x rpi:x%x",
  7384. (uint32_t)pmbox->mbxStatus,
  7385. pmbox->un.varWords[0], 0);
  7386. if (!pmbox->mbxStatus) {
  7387. mp = (struct lpfc_dmabuf *)
  7388. (pmb->context1);
  7389. ndlp = (struct lpfc_nodelist *)
  7390. pmb->context2;
  7391. /* Reg_LOGIN of dflt RPI was
  7392. * successful. new lets get
  7393. * rid of the RPI using the
  7394. * same mbox buffer.
  7395. */
  7396. lpfc_unreg_login(phba,
  7397. vport->vpi,
  7398. pmbox->un.varWords[0],
  7399. pmb);
  7400. pmb->mbox_cmpl =
  7401. lpfc_mbx_cmpl_dflt_rpi;
  7402. pmb->context1 = mp;
  7403. pmb->context2 = ndlp;
  7404. pmb->vport = vport;
  7405. rc = lpfc_sli_issue_mbox(phba,
  7406. pmb,
  7407. MBX_NOWAIT);
  7408. if (rc != MBX_BUSY)
  7409. lpfc_printf_log(phba,
  7410. KERN_ERR,
  7411. LOG_MBOX | LOG_SLI,
  7412. "0350 rc should have"
  7413. "been MBX_BUSY\n");
  7414. if (rc != MBX_NOT_FINISHED)
  7415. goto send_current_mbox;
  7416. }
  7417. }
  7418. spin_lock_irqsave(
  7419. &phba->pport->work_port_lock,
  7420. iflag);
  7421. phba->pport->work_port_events &=
  7422. ~WORKER_MBOX_TMO;
  7423. spin_unlock_irqrestore(
  7424. &phba->pport->work_port_lock,
  7425. iflag);
  7426. lpfc_mbox_cmpl_put(phba, pmb);
  7427. }
  7428. } else
  7429. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7430. if ((work_ha_copy & HA_MBATT) &&
  7431. (phba->sli.mbox_active == NULL)) {
  7432. send_current_mbox:
  7433. /* Process next mailbox command if there is one */
  7434. do {
  7435. rc = lpfc_sli_issue_mbox(phba, NULL,
  7436. MBX_NOWAIT);
  7437. } while (rc == MBX_NOT_FINISHED);
  7438. if (rc != MBX_SUCCESS)
  7439. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7440. LOG_SLI, "0349 rc should be "
  7441. "MBX_SUCCESS\n");
  7442. }
  7443. spin_lock_irqsave(&phba->hbalock, iflag);
  7444. phba->work_ha |= work_ha_copy;
  7445. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7446. lpfc_worker_wake_up(phba);
  7447. }
  7448. return IRQ_HANDLED;
  7449. } /* lpfc_sli_sp_intr_handler */
  7450. /**
  7451. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7452. * @irq: Interrupt number.
  7453. * @dev_id: The device context pointer.
  7454. *
  7455. * This function is directly called from the PCI layer as an interrupt
  7456. * service routine when device with SLI-3 interface spec is enabled with
  7457. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7458. * ring event in the HBA. However, when the device is enabled with either
  7459. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7460. * device-level interrupt handler. When the PCI slot is in error recovery
  7461. * or the HBA is undergoing initialization, the interrupt handler will not
  7462. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7463. * the intrrupt context. This function is called without any lock held.
  7464. * It gets the hbalock to access and update SLI data structures.
  7465. *
  7466. * This function returns IRQ_HANDLED when interrupt is handled else it
  7467. * returns IRQ_NONE.
  7468. **/
  7469. irqreturn_t
  7470. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7471. {
  7472. struct lpfc_hba *phba;
  7473. uint32_t ha_copy;
  7474. unsigned long status;
  7475. unsigned long iflag;
  7476. /* Get the driver's phba structure from the dev_id and
  7477. * assume the HBA is not interrupting.
  7478. */
  7479. phba = (struct lpfc_hba *) dev_id;
  7480. if (unlikely(!phba))
  7481. return IRQ_NONE;
  7482. /*
  7483. * Stuff needs to be attented to when this function is invoked as an
  7484. * individual interrupt handler in MSI-X multi-message interrupt mode
  7485. */
  7486. if (phba->intr_type == MSIX) {
  7487. /* Check device state for handling interrupt */
  7488. if (lpfc_intr_state_check(phba))
  7489. return IRQ_NONE;
  7490. /* Need to read HA REG for FCP ring and other ring events */
  7491. ha_copy = readl(phba->HAregaddr);
  7492. /* Clear up only attention source related to fast-path */
  7493. spin_lock_irqsave(&phba->hbalock, iflag);
  7494. /*
  7495. * If there is deferred error attention, do not check for
  7496. * any interrupt.
  7497. */
  7498. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7499. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7500. return IRQ_NONE;
  7501. }
  7502. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7503. phba->HAregaddr);
  7504. readl(phba->HAregaddr); /* flush */
  7505. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7506. } else
  7507. ha_copy = phba->ha_copy;
  7508. /*
  7509. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7510. */
  7511. ha_copy &= ~(phba->work_ha_mask);
  7512. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7513. status >>= (4*LPFC_FCP_RING);
  7514. if (status & HA_RXMASK)
  7515. lpfc_sli_handle_fast_ring_event(phba,
  7516. &phba->sli.ring[LPFC_FCP_RING],
  7517. status);
  7518. if (phba->cfg_multi_ring_support == 2) {
  7519. /*
  7520. * Process all events on extra ring. Take the optimized path
  7521. * for extra ring IO.
  7522. */
  7523. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7524. status >>= (4*LPFC_EXTRA_RING);
  7525. if (status & HA_RXMASK) {
  7526. lpfc_sli_handle_fast_ring_event(phba,
  7527. &phba->sli.ring[LPFC_EXTRA_RING],
  7528. status);
  7529. }
  7530. }
  7531. return IRQ_HANDLED;
  7532. } /* lpfc_sli_fp_intr_handler */
  7533. /**
  7534. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7535. * @irq: Interrupt number.
  7536. * @dev_id: The device context pointer.
  7537. *
  7538. * This function is the HBA device-level interrupt handler to device with
  7539. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7540. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7541. * requires driver attention. This function invokes the slow-path interrupt
  7542. * attention handling function and fast-path interrupt attention handling
  7543. * function in turn to process the relevant HBA attention events. This
  7544. * function is called without any lock held. It gets the hbalock to access
  7545. * and update SLI data structures.
  7546. *
  7547. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7548. * returns IRQ_NONE.
  7549. **/
  7550. irqreturn_t
  7551. lpfc_sli_intr_handler(int irq, void *dev_id)
  7552. {
  7553. struct lpfc_hba *phba;
  7554. irqreturn_t sp_irq_rc, fp_irq_rc;
  7555. unsigned long status1, status2;
  7556. uint32_t hc_copy;
  7557. /*
  7558. * Get the driver's phba structure from the dev_id and
  7559. * assume the HBA is not interrupting.
  7560. */
  7561. phba = (struct lpfc_hba *) dev_id;
  7562. if (unlikely(!phba))
  7563. return IRQ_NONE;
  7564. /* Check device state for handling interrupt */
  7565. if (lpfc_intr_state_check(phba))
  7566. return IRQ_NONE;
  7567. spin_lock(&phba->hbalock);
  7568. phba->ha_copy = readl(phba->HAregaddr);
  7569. if (unlikely(!phba->ha_copy)) {
  7570. spin_unlock(&phba->hbalock);
  7571. return IRQ_NONE;
  7572. } else if (phba->ha_copy & HA_ERATT) {
  7573. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7574. /* ERATT polling has handled ERATT */
  7575. phba->ha_copy &= ~HA_ERATT;
  7576. else
  7577. /* Indicate interrupt handler handles ERATT */
  7578. phba->hba_flag |= HBA_ERATT_HANDLED;
  7579. }
  7580. /*
  7581. * If there is deferred error attention, do not check for any interrupt.
  7582. */
  7583. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7584. spin_unlock_irq(&phba->hbalock);
  7585. return IRQ_NONE;
  7586. }
  7587. /* Clear attention sources except link and error attentions */
  7588. hc_copy = readl(phba->HCregaddr);
  7589. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7590. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7591. phba->HCregaddr);
  7592. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7593. writel(hc_copy, phba->HCregaddr);
  7594. readl(phba->HAregaddr); /* flush */
  7595. spin_unlock(&phba->hbalock);
  7596. /*
  7597. * Invokes slow-path host attention interrupt handling as appropriate.
  7598. */
  7599. /* status of events with mailbox and link attention */
  7600. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7601. /* status of events with ELS ring */
  7602. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7603. status2 >>= (4*LPFC_ELS_RING);
  7604. if (status1 || (status2 & HA_RXMASK))
  7605. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7606. else
  7607. sp_irq_rc = IRQ_NONE;
  7608. /*
  7609. * Invoke fast-path host attention interrupt handling as appropriate.
  7610. */
  7611. /* status of events with FCP ring */
  7612. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7613. status1 >>= (4*LPFC_FCP_RING);
  7614. /* status of events with extra ring */
  7615. if (phba->cfg_multi_ring_support == 2) {
  7616. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7617. status2 >>= (4*LPFC_EXTRA_RING);
  7618. } else
  7619. status2 = 0;
  7620. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7621. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7622. else
  7623. fp_irq_rc = IRQ_NONE;
  7624. /* Return device-level interrupt handling status */
  7625. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7626. } /* lpfc_sli_intr_handler */
  7627. /**
  7628. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7629. * @phba: pointer to lpfc hba data structure.
  7630. *
  7631. * This routine is invoked by the worker thread to process all the pending
  7632. * SLI4 FCP abort XRI events.
  7633. **/
  7634. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7635. {
  7636. struct lpfc_cq_event *cq_event;
  7637. /* First, declare the fcp xri abort event has been handled */
  7638. spin_lock_irq(&phba->hbalock);
  7639. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7640. spin_unlock_irq(&phba->hbalock);
  7641. /* Now, handle all the fcp xri abort events */
  7642. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7643. /* Get the first event from the head of the event queue */
  7644. spin_lock_irq(&phba->hbalock);
  7645. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7646. cq_event, struct lpfc_cq_event, list);
  7647. spin_unlock_irq(&phba->hbalock);
  7648. /* Notify aborted XRI for FCP work queue */
  7649. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7650. /* Free the event processed back to the free pool */
  7651. lpfc_sli4_cq_event_release(phba, cq_event);
  7652. }
  7653. }
  7654. /**
  7655. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7656. * @phba: pointer to lpfc hba data structure.
  7657. *
  7658. * This routine is invoked by the worker thread to process all the pending
  7659. * SLI4 els abort xri events.
  7660. **/
  7661. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7662. {
  7663. struct lpfc_cq_event *cq_event;
  7664. /* First, declare the els xri abort event has been handled */
  7665. spin_lock_irq(&phba->hbalock);
  7666. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7667. spin_unlock_irq(&phba->hbalock);
  7668. /* Now, handle all the els xri abort events */
  7669. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7670. /* Get the first event from the head of the event queue */
  7671. spin_lock_irq(&phba->hbalock);
  7672. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7673. cq_event, struct lpfc_cq_event, list);
  7674. spin_unlock_irq(&phba->hbalock);
  7675. /* Notify aborted XRI for ELS work queue */
  7676. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7677. /* Free the event processed back to the free pool */
  7678. lpfc_sli4_cq_event_release(phba, cq_event);
  7679. }
  7680. }
  7681. /**
  7682. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7683. * @phba: pointer to lpfc hba data structure
  7684. * @pIocbIn: pointer to the rspiocbq
  7685. * @pIocbOut: pointer to the cmdiocbq
  7686. * @wcqe: pointer to the complete wcqe
  7687. *
  7688. * This routine transfers the fields of a command iocbq to a response iocbq
  7689. * by copying all the IOCB fields from command iocbq and transferring the
  7690. * completion status information from the complete wcqe.
  7691. **/
  7692. static void
  7693. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7694. struct lpfc_iocbq *pIocbIn,
  7695. struct lpfc_iocbq *pIocbOut,
  7696. struct lpfc_wcqe_complete *wcqe)
  7697. {
  7698. unsigned long iflags;
  7699. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7700. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7701. sizeof(struct lpfc_iocbq) - offset);
  7702. /* Map WCQE parameters into irspiocb parameters */
  7703. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7704. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7705. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7706. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7707. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7708. wcqe->total_data_placed;
  7709. else
  7710. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7711. else {
  7712. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7713. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7714. }
  7715. /* Pick up HBA exchange busy condition */
  7716. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7717. spin_lock_irqsave(&phba->hbalock, iflags);
  7718. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7719. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7720. }
  7721. }
  7722. /**
  7723. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7724. * @phba: Pointer to HBA context object.
  7725. * @wcqe: Pointer to work-queue completion queue entry.
  7726. *
  7727. * This routine handles an ELS work-queue completion event and construct
  7728. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7729. * discovery engine to handle.
  7730. *
  7731. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7732. **/
  7733. static struct lpfc_iocbq *
  7734. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7735. struct lpfc_iocbq *irspiocbq)
  7736. {
  7737. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7738. struct lpfc_iocbq *cmdiocbq;
  7739. struct lpfc_wcqe_complete *wcqe;
  7740. unsigned long iflags;
  7741. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7742. spin_lock_irqsave(&phba->hbalock, iflags);
  7743. pring->stats.iocb_event++;
  7744. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7745. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7746. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7747. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7748. if (unlikely(!cmdiocbq)) {
  7749. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7750. "0386 ELS complete with no corresponding "
  7751. "cmdiocb: iotag (%d)\n",
  7752. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7753. lpfc_sli_release_iocbq(phba, irspiocbq);
  7754. return NULL;
  7755. }
  7756. /* Fake the irspiocbq and copy necessary response information */
  7757. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  7758. return irspiocbq;
  7759. }
  7760. /**
  7761. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7762. * @phba: Pointer to HBA context object.
  7763. * @cqe: Pointer to mailbox completion queue entry.
  7764. *
  7765. * This routine process a mailbox completion queue entry with asynchrous
  7766. * event.
  7767. *
  7768. * Return: true if work posted to worker thread, otherwise false.
  7769. **/
  7770. static bool
  7771. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7772. {
  7773. struct lpfc_cq_event *cq_event;
  7774. unsigned long iflags;
  7775. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7776. "0392 Async Event: word0:x%x, word1:x%x, "
  7777. "word2:x%x, word3:x%x\n", mcqe->word0,
  7778. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7779. /* Allocate a new internal CQ_EVENT entry */
  7780. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7781. if (!cq_event) {
  7782. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7783. "0394 Failed to allocate CQ_EVENT entry\n");
  7784. return false;
  7785. }
  7786. /* Move the CQE into an asynchronous event entry */
  7787. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7788. spin_lock_irqsave(&phba->hbalock, iflags);
  7789. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7790. /* Set the async event flag */
  7791. phba->hba_flag |= ASYNC_EVENT;
  7792. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7793. return true;
  7794. }
  7795. /**
  7796. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7797. * @phba: Pointer to HBA context object.
  7798. * @cqe: Pointer to mailbox completion queue entry.
  7799. *
  7800. * This routine process a mailbox completion queue entry with mailbox
  7801. * completion event.
  7802. *
  7803. * Return: true if work posted to worker thread, otherwise false.
  7804. **/
  7805. static bool
  7806. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7807. {
  7808. uint32_t mcqe_status;
  7809. MAILBOX_t *mbox, *pmbox;
  7810. struct lpfc_mqe *mqe;
  7811. struct lpfc_vport *vport;
  7812. struct lpfc_nodelist *ndlp;
  7813. struct lpfc_dmabuf *mp;
  7814. unsigned long iflags;
  7815. LPFC_MBOXQ_t *pmb;
  7816. bool workposted = false;
  7817. int rc;
  7818. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7819. if (!bf_get(lpfc_trailer_completed, mcqe))
  7820. goto out_no_mqe_complete;
  7821. /* Get the reference to the active mbox command */
  7822. spin_lock_irqsave(&phba->hbalock, iflags);
  7823. pmb = phba->sli.mbox_active;
  7824. if (unlikely(!pmb)) {
  7825. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7826. "1832 No pending MBOX command to handle\n");
  7827. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7828. goto out_no_mqe_complete;
  7829. }
  7830. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7831. mqe = &pmb->u.mqe;
  7832. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7833. mbox = phba->mbox;
  7834. vport = pmb->vport;
  7835. /* Reset heartbeat timer */
  7836. phba->last_completion_time = jiffies;
  7837. del_timer(&phba->sli.mbox_tmo);
  7838. /* Move mbox data to caller's mailbox region, do endian swapping */
  7839. if (pmb->mbox_cmpl && mbox)
  7840. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7841. /* Set the mailbox status with SLI4 range 0x4000 */
  7842. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7843. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7844. bf_set(lpfc_mqe_status, mqe,
  7845. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7846. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7847. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7848. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7849. "MBOX dflt rpi: status:x%x rpi:x%x",
  7850. mcqe_status,
  7851. pmbox->un.varWords[0], 0);
  7852. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7853. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7854. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7855. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7856. * RID of the PPI using the same mbox buffer.
  7857. */
  7858. lpfc_unreg_login(phba, vport->vpi,
  7859. pmbox->un.varWords[0], pmb);
  7860. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7861. pmb->context1 = mp;
  7862. pmb->context2 = ndlp;
  7863. pmb->vport = vport;
  7864. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7865. if (rc != MBX_BUSY)
  7866. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7867. LOG_SLI, "0385 rc should "
  7868. "have been MBX_BUSY\n");
  7869. if (rc != MBX_NOT_FINISHED)
  7870. goto send_current_mbox;
  7871. }
  7872. }
  7873. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7874. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7875. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7876. /* There is mailbox completion work to do */
  7877. spin_lock_irqsave(&phba->hbalock, iflags);
  7878. __lpfc_mbox_cmpl_put(phba, pmb);
  7879. phba->work_ha |= HA_MBATT;
  7880. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7881. workposted = true;
  7882. send_current_mbox:
  7883. spin_lock_irqsave(&phba->hbalock, iflags);
  7884. /* Release the mailbox command posting token */
  7885. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7886. /* Setting active mailbox pointer need to be in sync to flag clear */
  7887. phba->sli.mbox_active = NULL;
  7888. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7889. /* Wake up worker thread to post the next pending mailbox command */
  7890. lpfc_worker_wake_up(phba);
  7891. out_no_mqe_complete:
  7892. if (bf_get(lpfc_trailer_consumed, mcqe))
  7893. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7894. return workposted;
  7895. }
  7896. /**
  7897. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7898. * @phba: Pointer to HBA context object.
  7899. * @cqe: Pointer to mailbox completion queue entry.
  7900. *
  7901. * This routine process a mailbox completion queue entry, it invokes the
  7902. * proper mailbox complete handling or asynchrous event handling routine
  7903. * according to the MCQE's async bit.
  7904. *
  7905. * Return: true if work posted to worker thread, otherwise false.
  7906. **/
  7907. static bool
  7908. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7909. {
  7910. struct lpfc_mcqe mcqe;
  7911. bool workposted;
  7912. /* Copy the mailbox MCQE and convert endian order as needed */
  7913. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7914. /* Invoke the proper event handling routine */
  7915. if (!bf_get(lpfc_trailer_async, &mcqe))
  7916. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7917. else
  7918. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7919. return workposted;
  7920. }
  7921. /**
  7922. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7923. * @phba: Pointer to HBA context object.
  7924. * @wcqe: Pointer to work-queue completion queue entry.
  7925. *
  7926. * This routine handles an ELS work-queue completion event.
  7927. *
  7928. * Return: true if work posted to worker thread, otherwise false.
  7929. **/
  7930. static bool
  7931. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7932. struct lpfc_wcqe_complete *wcqe)
  7933. {
  7934. struct lpfc_iocbq *irspiocbq;
  7935. unsigned long iflags;
  7936. /* Get an irspiocbq for later ELS response processing use */
  7937. irspiocbq = lpfc_sli_get_iocbq(phba);
  7938. if (!irspiocbq) {
  7939. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7940. "0387 Failed to allocate an iocbq\n");
  7941. return false;
  7942. }
  7943. /* Save off the slow-path queue event for work thread to process */
  7944. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  7945. spin_lock_irqsave(&phba->hbalock, iflags);
  7946. list_add_tail(&irspiocbq->cq_event.list,
  7947. &phba->sli4_hba.sp_queue_event);
  7948. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7949. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7950. return true;
  7951. }
  7952. /**
  7953. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7954. * @phba: Pointer to HBA context object.
  7955. * @wcqe: Pointer to work-queue completion queue entry.
  7956. *
  7957. * This routine handles slow-path WQ entry comsumed event by invoking the
  7958. * proper WQ release routine to the slow-path WQ.
  7959. **/
  7960. static void
  7961. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7962. struct lpfc_wcqe_release *wcqe)
  7963. {
  7964. /* Check for the slow-path ELS work queue */
  7965. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7966. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7967. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7968. else
  7969. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7970. "2579 Slow-path wqe consume event carries "
  7971. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7972. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7973. phba->sli4_hba.els_wq->queue_id);
  7974. }
  7975. /**
  7976. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7977. * @phba: Pointer to HBA context object.
  7978. * @cq: Pointer to a WQ completion queue.
  7979. * @wcqe: Pointer to work-queue completion queue entry.
  7980. *
  7981. * This routine handles an XRI abort event.
  7982. *
  7983. * Return: true if work posted to worker thread, otherwise false.
  7984. **/
  7985. static bool
  7986. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7987. struct lpfc_queue *cq,
  7988. struct sli4_wcqe_xri_aborted *wcqe)
  7989. {
  7990. bool workposted = false;
  7991. struct lpfc_cq_event *cq_event;
  7992. unsigned long iflags;
  7993. /* Allocate a new internal CQ_EVENT entry */
  7994. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7995. if (!cq_event) {
  7996. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7997. "0602 Failed to allocate CQ_EVENT entry\n");
  7998. return false;
  7999. }
  8000. /* Move the CQE into the proper xri abort event list */
  8001. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8002. switch (cq->subtype) {
  8003. case LPFC_FCP:
  8004. spin_lock_irqsave(&phba->hbalock, iflags);
  8005. list_add_tail(&cq_event->list,
  8006. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8007. /* Set the fcp xri abort event flag */
  8008. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8009. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8010. workposted = true;
  8011. break;
  8012. case LPFC_ELS:
  8013. spin_lock_irqsave(&phba->hbalock, iflags);
  8014. list_add_tail(&cq_event->list,
  8015. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8016. /* Set the els xri abort event flag */
  8017. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8018. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8019. workposted = true;
  8020. break;
  8021. default:
  8022. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8023. "0603 Invalid work queue CQE subtype (x%x)\n",
  8024. cq->subtype);
  8025. workposted = false;
  8026. break;
  8027. }
  8028. return workposted;
  8029. }
  8030. /**
  8031. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8032. * @phba: Pointer to HBA context object.
  8033. * @rcqe: Pointer to receive-queue completion queue entry.
  8034. *
  8035. * This routine process a receive-queue completion queue entry.
  8036. *
  8037. * Return: true if work posted to worker thread, otherwise false.
  8038. **/
  8039. static bool
  8040. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8041. {
  8042. bool workposted = false;
  8043. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8044. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8045. struct hbq_dmabuf *dma_buf;
  8046. uint32_t status;
  8047. unsigned long iflags;
  8048. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8049. goto out;
  8050. status = bf_get(lpfc_rcqe_status, rcqe);
  8051. switch (status) {
  8052. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8053. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8054. "2537 Receive Frame Truncated!!\n");
  8055. case FC_STATUS_RQ_SUCCESS:
  8056. lpfc_sli4_rq_release(hrq, drq);
  8057. spin_lock_irqsave(&phba->hbalock, iflags);
  8058. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8059. if (!dma_buf) {
  8060. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8061. goto out;
  8062. }
  8063. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8064. /* save off the frame for the word thread to process */
  8065. list_add_tail(&dma_buf->cq_event.list,
  8066. &phba->sli4_hba.sp_queue_event);
  8067. /* Frame received */
  8068. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8069. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8070. workposted = true;
  8071. break;
  8072. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8073. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8074. /* Post more buffers if possible */
  8075. spin_lock_irqsave(&phba->hbalock, iflags);
  8076. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8077. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8078. workposted = true;
  8079. break;
  8080. }
  8081. out:
  8082. return workposted;
  8083. }
  8084. /**
  8085. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8086. * @phba: Pointer to HBA context object.
  8087. * @cq: Pointer to the completion queue.
  8088. * @wcqe: Pointer to a completion queue entry.
  8089. *
  8090. * This routine process a slow-path work-queue or recieve queue completion queue
  8091. * entry.
  8092. *
  8093. * Return: true if work posted to worker thread, otherwise false.
  8094. **/
  8095. static bool
  8096. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8097. struct lpfc_cqe *cqe)
  8098. {
  8099. struct lpfc_cqe cqevt;
  8100. bool workposted = false;
  8101. /* Copy the work queue CQE and convert endian order if needed */
  8102. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8103. /* Check and process for different type of WCQE and dispatch */
  8104. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8105. case CQE_CODE_COMPL_WQE:
  8106. /* Process the WQ/RQ complete event */
  8107. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8108. (struct lpfc_wcqe_complete *)&cqevt);
  8109. break;
  8110. case CQE_CODE_RELEASE_WQE:
  8111. /* Process the WQ release event */
  8112. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8113. (struct lpfc_wcqe_release *)&cqevt);
  8114. break;
  8115. case CQE_CODE_XRI_ABORTED:
  8116. /* Process the WQ XRI abort event */
  8117. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8118. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8119. break;
  8120. case CQE_CODE_RECEIVE:
  8121. /* Process the RQ event */
  8122. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8123. (struct lpfc_rcqe *)&cqevt);
  8124. break;
  8125. default:
  8126. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8127. "0388 Not a valid WCQE code: x%x\n",
  8128. bf_get(lpfc_cqe_code, &cqevt));
  8129. break;
  8130. }
  8131. return workposted;
  8132. }
  8133. /**
  8134. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8135. * @phba: Pointer to HBA context object.
  8136. * @eqe: Pointer to fast-path event queue entry.
  8137. *
  8138. * This routine process a event queue entry from the slow-path event queue.
  8139. * It will check the MajorCode and MinorCode to determine this is for a
  8140. * completion event on a completion queue, if not, an error shall be logged
  8141. * and just return. Otherwise, it will get to the corresponding completion
  8142. * queue and process all the entries on that completion queue, rearm the
  8143. * completion queue, and then return.
  8144. *
  8145. **/
  8146. static void
  8147. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8148. {
  8149. struct lpfc_queue *cq = NULL, *childq, *speq;
  8150. struct lpfc_cqe *cqe;
  8151. bool workposted = false;
  8152. int ecount = 0;
  8153. uint16_t cqid;
  8154. if (bf_get(lpfc_eqe_major_code, eqe) != 0) {
  8155. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8156. "0359 Not a valid slow-path completion "
  8157. "event: majorcode=x%x, minorcode=x%x\n",
  8158. bf_get(lpfc_eqe_major_code, eqe),
  8159. bf_get(lpfc_eqe_minor_code, eqe));
  8160. return;
  8161. }
  8162. /* Get the reference to the corresponding CQ */
  8163. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8164. /* Search for completion queue pointer matching this cqid */
  8165. speq = phba->sli4_hba.sp_eq;
  8166. list_for_each_entry(childq, &speq->child_list, list) {
  8167. if (childq->queue_id == cqid) {
  8168. cq = childq;
  8169. break;
  8170. }
  8171. }
  8172. if (unlikely(!cq)) {
  8173. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8174. "0365 Slow-path CQ identifier (%d) does "
  8175. "not exist\n", cqid);
  8176. return;
  8177. }
  8178. /* Process all the entries to the CQ */
  8179. switch (cq->type) {
  8180. case LPFC_MCQ:
  8181. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8182. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8183. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8184. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8185. }
  8186. break;
  8187. case LPFC_WCQ:
  8188. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8189. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8190. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8191. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8192. }
  8193. break;
  8194. default:
  8195. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8196. "0370 Invalid completion queue type (%d)\n",
  8197. cq->type);
  8198. return;
  8199. }
  8200. /* Catch the no cq entry condition, log an error */
  8201. if (unlikely(ecount == 0))
  8202. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8203. "0371 No entry from the CQ: identifier "
  8204. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8205. /* In any case, flash and re-arm the RCQ */
  8206. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8207. /* wake up worker thread if there are works to be done */
  8208. if (workposted)
  8209. lpfc_worker_wake_up(phba);
  8210. }
  8211. /**
  8212. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8213. * @eqe: Pointer to fast-path completion queue entry.
  8214. *
  8215. * This routine process a fast-path work queue completion entry from fast-path
  8216. * event queue for FCP command response completion.
  8217. **/
  8218. static void
  8219. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8220. struct lpfc_wcqe_complete *wcqe)
  8221. {
  8222. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8223. struct lpfc_iocbq *cmdiocbq;
  8224. struct lpfc_iocbq irspiocbq;
  8225. unsigned long iflags;
  8226. spin_lock_irqsave(&phba->hbalock, iflags);
  8227. pring->stats.iocb_event++;
  8228. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8229. /* Check for response status */
  8230. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8231. /* If resource errors reported from HBA, reduce queue
  8232. * depth of the SCSI device.
  8233. */
  8234. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8235. IOSTAT_LOCAL_REJECT) &&
  8236. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8237. phba->lpfc_rampdown_queue_depth(phba);
  8238. }
  8239. /* Log the error status */
  8240. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8241. "0373 FCP complete error: status=x%x, "
  8242. "hw_status=x%x, total_data_specified=%d, "
  8243. "parameter=x%x, word3=x%x\n",
  8244. bf_get(lpfc_wcqe_c_status, wcqe),
  8245. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8246. wcqe->total_data_placed, wcqe->parameter,
  8247. wcqe->word3);
  8248. }
  8249. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8250. spin_lock_irqsave(&phba->hbalock, iflags);
  8251. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8252. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8253. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8254. if (unlikely(!cmdiocbq)) {
  8255. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8256. "0374 FCP complete with no corresponding "
  8257. "cmdiocb: iotag (%d)\n",
  8258. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8259. return;
  8260. }
  8261. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8262. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8263. "0375 FCP cmdiocb not callback function "
  8264. "iotag: (%d)\n",
  8265. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8266. return;
  8267. }
  8268. /* Fake the irspiocb and copy necessary response information */
  8269. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8270. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8271. spin_lock_irqsave(&phba->hbalock, iflags);
  8272. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8273. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8274. }
  8275. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8276. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8277. }
  8278. /**
  8279. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8280. * @phba: Pointer to HBA context object.
  8281. * @cq: Pointer to completion queue.
  8282. * @wcqe: Pointer to work-queue completion queue entry.
  8283. *
  8284. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8285. * proper WQ release routine to the slow-path WQ.
  8286. **/
  8287. static void
  8288. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8289. struct lpfc_wcqe_release *wcqe)
  8290. {
  8291. struct lpfc_queue *childwq;
  8292. bool wqid_matched = false;
  8293. uint16_t fcp_wqid;
  8294. /* Check for fast-path FCP work queue release */
  8295. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8296. list_for_each_entry(childwq, &cq->child_list, list) {
  8297. if (childwq->queue_id == fcp_wqid) {
  8298. lpfc_sli4_wq_release(childwq,
  8299. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8300. wqid_matched = true;
  8301. break;
  8302. }
  8303. }
  8304. /* Report warning log message if no match found */
  8305. if (wqid_matched != true)
  8306. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8307. "2580 Fast-path wqe consume event carries "
  8308. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8309. }
  8310. /**
  8311. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8312. * @cq: Pointer to the completion queue.
  8313. * @eqe: Pointer to fast-path completion queue entry.
  8314. *
  8315. * This routine process a fast-path work queue completion entry from fast-path
  8316. * event queue for FCP command response completion.
  8317. **/
  8318. static int
  8319. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8320. struct lpfc_cqe *cqe)
  8321. {
  8322. struct lpfc_wcqe_release wcqe;
  8323. bool workposted = false;
  8324. /* Copy the work queue CQE and convert endian order if needed */
  8325. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8326. /* Check and process for different type of WCQE and dispatch */
  8327. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8328. case CQE_CODE_COMPL_WQE:
  8329. /* Process the WQ complete event */
  8330. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8331. (struct lpfc_wcqe_complete *)&wcqe);
  8332. break;
  8333. case CQE_CODE_RELEASE_WQE:
  8334. /* Process the WQ release event */
  8335. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8336. (struct lpfc_wcqe_release *)&wcqe);
  8337. break;
  8338. case CQE_CODE_XRI_ABORTED:
  8339. /* Process the WQ XRI abort event */
  8340. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8341. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8342. break;
  8343. default:
  8344. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8345. "0144 Not a valid WCQE code: x%x\n",
  8346. bf_get(lpfc_wcqe_c_code, &wcqe));
  8347. break;
  8348. }
  8349. return workposted;
  8350. }
  8351. /**
  8352. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8353. * @phba: Pointer to HBA context object.
  8354. * @eqe: Pointer to fast-path event queue entry.
  8355. *
  8356. * This routine process a event queue entry from the fast-path event queue.
  8357. * It will check the MajorCode and MinorCode to determine this is for a
  8358. * completion event on a completion queue, if not, an error shall be logged
  8359. * and just return. Otherwise, it will get to the corresponding completion
  8360. * queue and process all the entries on the completion queue, rearm the
  8361. * completion queue, and then return.
  8362. **/
  8363. static void
  8364. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8365. uint32_t fcp_cqidx)
  8366. {
  8367. struct lpfc_queue *cq;
  8368. struct lpfc_cqe *cqe;
  8369. bool workposted = false;
  8370. uint16_t cqid;
  8371. int ecount = 0;
  8372. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0)) {
  8373. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8374. "0366 Not a valid fast-path completion "
  8375. "event: majorcode=x%x, minorcode=x%x\n",
  8376. bf_get(lpfc_eqe_major_code, eqe),
  8377. bf_get(lpfc_eqe_minor_code, eqe));
  8378. return;
  8379. }
  8380. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8381. if (unlikely(!cq)) {
  8382. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8383. "0367 Fast-path completion queue does not "
  8384. "exist\n");
  8385. return;
  8386. }
  8387. /* Get the reference to the corresponding CQ */
  8388. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8389. if (unlikely(cqid != cq->queue_id)) {
  8390. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8391. "0368 Miss-matched fast-path completion "
  8392. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8393. cqid, cq->queue_id);
  8394. return;
  8395. }
  8396. /* Process all the entries to the CQ */
  8397. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8398. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8399. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8400. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8401. }
  8402. /* Catch the no cq entry condition */
  8403. if (unlikely(ecount == 0))
  8404. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8405. "0369 No entry from fast-path completion "
  8406. "queue fcpcqid=%d\n", cq->queue_id);
  8407. /* In any case, flash and re-arm the CQ */
  8408. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8409. /* wake up worker thread if there are works to be done */
  8410. if (workposted)
  8411. lpfc_worker_wake_up(phba);
  8412. }
  8413. static void
  8414. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8415. {
  8416. struct lpfc_eqe *eqe;
  8417. /* walk all the EQ entries and drop on the floor */
  8418. while ((eqe = lpfc_sli4_eq_get(eq)))
  8419. ;
  8420. /* Clear and re-arm the EQ */
  8421. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8422. }
  8423. /**
  8424. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8425. * @irq: Interrupt number.
  8426. * @dev_id: The device context pointer.
  8427. *
  8428. * This function is directly called from the PCI layer as an interrupt
  8429. * service routine when device with SLI-4 interface spec is enabled with
  8430. * MSI-X multi-message interrupt mode and there are slow-path events in
  8431. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8432. * interrupt mode, this function is called as part of the device-level
  8433. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8434. * undergoing initialization, the interrupt handler will not process the
  8435. * interrupt. The link attention and ELS ring attention events are handled
  8436. * by the worker thread. The interrupt handler signals the worker thread
  8437. * and returns for these events. This function is called without any lock
  8438. * held. It gets the hbalock to access and update SLI data structures.
  8439. *
  8440. * This function returns IRQ_HANDLED when interrupt is handled else it
  8441. * returns IRQ_NONE.
  8442. **/
  8443. irqreturn_t
  8444. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8445. {
  8446. struct lpfc_hba *phba;
  8447. struct lpfc_queue *speq;
  8448. struct lpfc_eqe *eqe;
  8449. unsigned long iflag;
  8450. int ecount = 0;
  8451. /*
  8452. * Get the driver's phba structure from the dev_id
  8453. */
  8454. phba = (struct lpfc_hba *)dev_id;
  8455. if (unlikely(!phba))
  8456. return IRQ_NONE;
  8457. /* Get to the EQ struct associated with this vector */
  8458. speq = phba->sli4_hba.sp_eq;
  8459. /* Check device state for handling interrupt */
  8460. if (unlikely(lpfc_intr_state_check(phba))) {
  8461. /* Check again for link_state with lock held */
  8462. spin_lock_irqsave(&phba->hbalock, iflag);
  8463. if (phba->link_state < LPFC_LINK_DOWN)
  8464. /* Flush, clear interrupt, and rearm the EQ */
  8465. lpfc_sli4_eq_flush(phba, speq);
  8466. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8467. return IRQ_NONE;
  8468. }
  8469. /*
  8470. * Process all the event on FCP slow-path EQ
  8471. */
  8472. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8473. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8474. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8475. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8476. }
  8477. /* Always clear and re-arm the slow-path EQ */
  8478. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8479. /* Catch the no cq entry condition */
  8480. if (unlikely(ecount == 0)) {
  8481. if (phba->intr_type == MSIX)
  8482. /* MSI-X treated interrupt served as no EQ share INT */
  8483. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8484. "0357 MSI-X interrupt with no EQE\n");
  8485. else
  8486. /* Non MSI-X treated on interrupt as EQ share INT */
  8487. return IRQ_NONE;
  8488. }
  8489. return IRQ_HANDLED;
  8490. } /* lpfc_sli4_sp_intr_handler */
  8491. /**
  8492. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8493. * @irq: Interrupt number.
  8494. * @dev_id: The device context pointer.
  8495. *
  8496. * This function is directly called from the PCI layer as an interrupt
  8497. * service routine when device with SLI-4 interface spec is enabled with
  8498. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8499. * ring event in the HBA. However, when the device is enabled with either
  8500. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8501. * device-level interrupt handler. When the PCI slot is in error recovery
  8502. * or the HBA is undergoing initialization, the interrupt handler will not
  8503. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8504. * the intrrupt context. This function is called without any lock held.
  8505. * It gets the hbalock to access and update SLI data structures. Note that,
  8506. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8507. * equal to that of FCP CQ index.
  8508. *
  8509. * This function returns IRQ_HANDLED when interrupt is handled else it
  8510. * returns IRQ_NONE.
  8511. **/
  8512. irqreturn_t
  8513. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8514. {
  8515. struct lpfc_hba *phba;
  8516. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8517. struct lpfc_queue *fpeq;
  8518. struct lpfc_eqe *eqe;
  8519. unsigned long iflag;
  8520. int ecount = 0;
  8521. uint32_t fcp_eqidx;
  8522. /* Get the driver's phba structure from the dev_id */
  8523. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8524. phba = fcp_eq_hdl->phba;
  8525. fcp_eqidx = fcp_eq_hdl->idx;
  8526. if (unlikely(!phba))
  8527. return IRQ_NONE;
  8528. /* Get to the EQ struct associated with this vector */
  8529. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8530. /* Check device state for handling interrupt */
  8531. if (unlikely(lpfc_intr_state_check(phba))) {
  8532. /* Check again for link_state with lock held */
  8533. spin_lock_irqsave(&phba->hbalock, iflag);
  8534. if (phba->link_state < LPFC_LINK_DOWN)
  8535. /* Flush, clear interrupt, and rearm the EQ */
  8536. lpfc_sli4_eq_flush(phba, fpeq);
  8537. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8538. return IRQ_NONE;
  8539. }
  8540. /*
  8541. * Process all the event on FCP fast-path EQ
  8542. */
  8543. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8544. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8545. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8546. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8547. }
  8548. /* Always clear and re-arm the fast-path EQ */
  8549. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8550. if (unlikely(ecount == 0)) {
  8551. if (phba->intr_type == MSIX)
  8552. /* MSI-X treated interrupt served as no EQ share INT */
  8553. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8554. "0358 MSI-X interrupt with no EQE\n");
  8555. else
  8556. /* Non MSI-X treated on interrupt as EQ share INT */
  8557. return IRQ_NONE;
  8558. }
  8559. return IRQ_HANDLED;
  8560. } /* lpfc_sli4_fp_intr_handler */
  8561. /**
  8562. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8563. * @irq: Interrupt number.
  8564. * @dev_id: The device context pointer.
  8565. *
  8566. * This function is the device-level interrupt handler to device with SLI-4
  8567. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8568. * interrupt mode is enabled and there is an event in the HBA which requires
  8569. * driver attention. This function invokes the slow-path interrupt attention
  8570. * handling function and fast-path interrupt attention handling function in
  8571. * turn to process the relevant HBA attention events. This function is called
  8572. * without any lock held. It gets the hbalock to access and update SLI data
  8573. * structures.
  8574. *
  8575. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8576. * returns IRQ_NONE.
  8577. **/
  8578. irqreturn_t
  8579. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8580. {
  8581. struct lpfc_hba *phba;
  8582. irqreturn_t sp_irq_rc, fp_irq_rc;
  8583. bool fp_handled = false;
  8584. uint32_t fcp_eqidx;
  8585. /* Get the driver's phba structure from the dev_id */
  8586. phba = (struct lpfc_hba *)dev_id;
  8587. if (unlikely(!phba))
  8588. return IRQ_NONE;
  8589. /*
  8590. * Invokes slow-path host attention interrupt handling as appropriate.
  8591. */
  8592. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8593. /*
  8594. * Invoke fast-path host attention interrupt handling as appropriate.
  8595. */
  8596. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8597. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8598. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8599. if (fp_irq_rc == IRQ_HANDLED)
  8600. fp_handled |= true;
  8601. }
  8602. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8603. } /* lpfc_sli4_intr_handler */
  8604. /**
  8605. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8606. * @queue: The queue structure to free.
  8607. *
  8608. * This function frees a queue structure and the DMAable memeory used for
  8609. * the host resident queue. This function must be called after destroying the
  8610. * queue on the HBA.
  8611. **/
  8612. void
  8613. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8614. {
  8615. struct lpfc_dmabuf *dmabuf;
  8616. if (!queue)
  8617. return;
  8618. while (!list_empty(&queue->page_list)) {
  8619. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8620. list);
  8621. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8622. dmabuf->virt, dmabuf->phys);
  8623. kfree(dmabuf);
  8624. }
  8625. kfree(queue);
  8626. return;
  8627. }
  8628. /**
  8629. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8630. * @phba: The HBA that this queue is being created on.
  8631. * @entry_size: The size of each queue entry for this queue.
  8632. * @entry count: The number of entries that this queue will handle.
  8633. *
  8634. * This function allocates a queue structure and the DMAable memory used for
  8635. * the host resident queue. This function must be called before creating the
  8636. * queue on the HBA.
  8637. **/
  8638. struct lpfc_queue *
  8639. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8640. uint32_t entry_count)
  8641. {
  8642. struct lpfc_queue *queue;
  8643. struct lpfc_dmabuf *dmabuf;
  8644. int x, total_qe_count;
  8645. void *dma_pointer;
  8646. queue = kzalloc(sizeof(struct lpfc_queue) +
  8647. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8648. if (!queue)
  8649. return NULL;
  8650. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8651. INIT_LIST_HEAD(&queue->list);
  8652. INIT_LIST_HEAD(&queue->page_list);
  8653. INIT_LIST_HEAD(&queue->child_list);
  8654. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8655. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8656. if (!dmabuf)
  8657. goto out_fail;
  8658. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8659. PAGE_SIZE, &dmabuf->phys,
  8660. GFP_KERNEL);
  8661. if (!dmabuf->virt) {
  8662. kfree(dmabuf);
  8663. goto out_fail;
  8664. }
  8665. memset(dmabuf->virt, 0, PAGE_SIZE);
  8666. dmabuf->buffer_tag = x;
  8667. list_add_tail(&dmabuf->list, &queue->page_list);
  8668. /* initialize queue's entry array */
  8669. dma_pointer = dmabuf->virt;
  8670. for (; total_qe_count < entry_count &&
  8671. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8672. total_qe_count++, dma_pointer += entry_size) {
  8673. queue->qe[total_qe_count].address = dma_pointer;
  8674. }
  8675. }
  8676. queue->entry_size = entry_size;
  8677. queue->entry_count = entry_count;
  8678. queue->phba = phba;
  8679. return queue;
  8680. out_fail:
  8681. lpfc_sli4_queue_free(queue);
  8682. return NULL;
  8683. }
  8684. /**
  8685. * lpfc_eq_create - Create an Event Queue on the HBA
  8686. * @phba: HBA structure that indicates port to create a queue on.
  8687. * @eq: The queue structure to use to create the event queue.
  8688. * @imax: The maximum interrupt per second limit.
  8689. *
  8690. * This function creates an event queue, as detailed in @eq, on a port,
  8691. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8692. *
  8693. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8694. * is used to get the entry count and entry size that are necessary to
  8695. * determine the number of pages to allocate and use for this queue. This
  8696. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8697. * event queue. This function is asynchronous and will wait for the mailbox
  8698. * command to finish before continuing.
  8699. *
  8700. * On success this function will return a zero. If unable to allocate enough
  8701. * memory this function will return ENOMEM. If the queue create mailbox command
  8702. * fails this function will return ENXIO.
  8703. **/
  8704. uint32_t
  8705. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8706. {
  8707. struct lpfc_mbx_eq_create *eq_create;
  8708. LPFC_MBOXQ_t *mbox;
  8709. int rc, length, status = 0;
  8710. struct lpfc_dmabuf *dmabuf;
  8711. uint32_t shdr_status, shdr_add_status;
  8712. union lpfc_sli4_cfg_shdr *shdr;
  8713. uint16_t dmult;
  8714. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8715. if (!mbox)
  8716. return -ENOMEM;
  8717. length = (sizeof(struct lpfc_mbx_eq_create) -
  8718. sizeof(struct lpfc_sli4_cfg_mhdr));
  8719. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8720. LPFC_MBOX_OPCODE_EQ_CREATE,
  8721. length, LPFC_SLI4_MBX_EMBED);
  8722. eq_create = &mbox->u.mqe.un.eq_create;
  8723. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8724. eq->page_count);
  8725. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8726. LPFC_EQE_SIZE);
  8727. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8728. /* Calculate delay multiper from maximum interrupt per second */
  8729. dmult = LPFC_DMULT_CONST/imax - 1;
  8730. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8731. dmult);
  8732. switch (eq->entry_count) {
  8733. default:
  8734. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8735. "0360 Unsupported EQ count. (%d)\n",
  8736. eq->entry_count);
  8737. if (eq->entry_count < 256)
  8738. return -EINVAL;
  8739. /* otherwise default to smallest count (drop through) */
  8740. case 256:
  8741. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8742. LPFC_EQ_CNT_256);
  8743. break;
  8744. case 512:
  8745. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8746. LPFC_EQ_CNT_512);
  8747. break;
  8748. case 1024:
  8749. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8750. LPFC_EQ_CNT_1024);
  8751. break;
  8752. case 2048:
  8753. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8754. LPFC_EQ_CNT_2048);
  8755. break;
  8756. case 4096:
  8757. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8758. LPFC_EQ_CNT_4096);
  8759. break;
  8760. }
  8761. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8762. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8763. putPaddrLow(dmabuf->phys);
  8764. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8765. putPaddrHigh(dmabuf->phys);
  8766. }
  8767. mbox->vport = phba->pport;
  8768. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8769. mbox->context1 = NULL;
  8770. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8771. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8772. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8773. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8774. if (shdr_status || shdr_add_status || rc) {
  8775. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8776. "2500 EQ_CREATE mailbox failed with "
  8777. "status x%x add_status x%x, mbx status x%x\n",
  8778. shdr_status, shdr_add_status, rc);
  8779. status = -ENXIO;
  8780. }
  8781. eq->type = LPFC_EQ;
  8782. eq->subtype = LPFC_NONE;
  8783. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8784. if (eq->queue_id == 0xFFFF)
  8785. status = -ENXIO;
  8786. eq->host_index = 0;
  8787. eq->hba_index = 0;
  8788. mempool_free(mbox, phba->mbox_mem_pool);
  8789. return status;
  8790. }
  8791. /**
  8792. * lpfc_cq_create - Create a Completion Queue on the HBA
  8793. * @phba: HBA structure that indicates port to create a queue on.
  8794. * @cq: The queue structure to use to create the completion queue.
  8795. * @eq: The event queue to bind this completion queue to.
  8796. *
  8797. * This function creates a completion queue, as detailed in @wq, on a port,
  8798. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8799. *
  8800. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8801. * is used to get the entry count and entry size that are necessary to
  8802. * determine the number of pages to allocate and use for this queue. The @eq
  8803. * is used to indicate which event queue to bind this completion queue to. This
  8804. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8805. * completion queue. This function is asynchronous and will wait for the mailbox
  8806. * command to finish before continuing.
  8807. *
  8808. * On success this function will return a zero. If unable to allocate enough
  8809. * memory this function will return ENOMEM. If the queue create mailbox command
  8810. * fails this function will return ENXIO.
  8811. **/
  8812. uint32_t
  8813. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8814. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8815. {
  8816. struct lpfc_mbx_cq_create *cq_create;
  8817. struct lpfc_dmabuf *dmabuf;
  8818. LPFC_MBOXQ_t *mbox;
  8819. int rc, length, status = 0;
  8820. uint32_t shdr_status, shdr_add_status;
  8821. union lpfc_sli4_cfg_shdr *shdr;
  8822. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8823. if (!mbox)
  8824. return -ENOMEM;
  8825. length = (sizeof(struct lpfc_mbx_cq_create) -
  8826. sizeof(struct lpfc_sli4_cfg_mhdr));
  8827. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8828. LPFC_MBOX_OPCODE_CQ_CREATE,
  8829. length, LPFC_SLI4_MBX_EMBED);
  8830. cq_create = &mbox->u.mqe.un.cq_create;
  8831. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8832. cq->page_count);
  8833. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8834. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8835. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8836. switch (cq->entry_count) {
  8837. default:
  8838. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8839. "0361 Unsupported CQ count. (%d)\n",
  8840. cq->entry_count);
  8841. if (cq->entry_count < 256)
  8842. return -EINVAL;
  8843. /* otherwise default to smallest count (drop through) */
  8844. case 256:
  8845. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8846. LPFC_CQ_CNT_256);
  8847. break;
  8848. case 512:
  8849. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8850. LPFC_CQ_CNT_512);
  8851. break;
  8852. case 1024:
  8853. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8854. LPFC_CQ_CNT_1024);
  8855. break;
  8856. }
  8857. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8858. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8859. putPaddrLow(dmabuf->phys);
  8860. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8861. putPaddrHigh(dmabuf->phys);
  8862. }
  8863. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8864. /* The IOCTL status is embedded in the mailbox subheader. */
  8865. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8866. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8867. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8868. if (shdr_status || shdr_add_status || rc) {
  8869. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8870. "2501 CQ_CREATE mailbox failed with "
  8871. "status x%x add_status x%x, mbx status x%x\n",
  8872. shdr_status, shdr_add_status, rc);
  8873. status = -ENXIO;
  8874. goto out;
  8875. }
  8876. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8877. if (cq->queue_id == 0xFFFF) {
  8878. status = -ENXIO;
  8879. goto out;
  8880. }
  8881. /* link the cq onto the parent eq child list */
  8882. list_add_tail(&cq->list, &eq->child_list);
  8883. /* Set up completion queue's type and subtype */
  8884. cq->type = type;
  8885. cq->subtype = subtype;
  8886. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8887. cq->host_index = 0;
  8888. cq->hba_index = 0;
  8889. out:
  8890. mempool_free(mbox, phba->mbox_mem_pool);
  8891. return status;
  8892. }
  8893. /**
  8894. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8895. * @phba: HBA structure that indicates port to create a queue on.
  8896. * @mq: The queue structure to use to create the mailbox queue.
  8897. *
  8898. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8899. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8900. *
  8901. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8902. * is used to get the entry count and entry size that are necessary to
  8903. * determine the number of pages to allocate and use for this queue. This
  8904. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8905. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8906. * command to finish before continuing.
  8907. *
  8908. * On success this function will return a zero. If unable to allocate enough
  8909. * memory this function will return ENOMEM. If the queue create mailbox command
  8910. * fails this function will return ENXIO.
  8911. **/
  8912. uint32_t
  8913. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8914. struct lpfc_queue *cq, uint32_t subtype)
  8915. {
  8916. struct lpfc_mbx_mq_create *mq_create;
  8917. struct lpfc_dmabuf *dmabuf;
  8918. LPFC_MBOXQ_t *mbox;
  8919. int rc, length, status = 0;
  8920. uint32_t shdr_status, shdr_add_status;
  8921. union lpfc_sli4_cfg_shdr *shdr;
  8922. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8923. if (!mbox)
  8924. return -ENOMEM;
  8925. length = (sizeof(struct lpfc_mbx_mq_create) -
  8926. sizeof(struct lpfc_sli4_cfg_mhdr));
  8927. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8928. LPFC_MBOX_OPCODE_MQ_CREATE,
  8929. length, LPFC_SLI4_MBX_EMBED);
  8930. mq_create = &mbox->u.mqe.un.mq_create;
  8931. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8932. mq->page_count);
  8933. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8934. cq->queue_id);
  8935. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8936. switch (mq->entry_count) {
  8937. default:
  8938. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8939. "0362 Unsupported MQ count. (%d)\n",
  8940. mq->entry_count);
  8941. if (mq->entry_count < 16)
  8942. return -EINVAL;
  8943. /* otherwise default to smallest count (drop through) */
  8944. case 16:
  8945. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8946. LPFC_MQ_CNT_16);
  8947. break;
  8948. case 32:
  8949. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8950. LPFC_MQ_CNT_32);
  8951. break;
  8952. case 64:
  8953. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8954. LPFC_MQ_CNT_64);
  8955. break;
  8956. case 128:
  8957. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8958. LPFC_MQ_CNT_128);
  8959. break;
  8960. }
  8961. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8962. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8963. putPaddrLow(dmabuf->phys);
  8964. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8965. putPaddrHigh(dmabuf->phys);
  8966. }
  8967. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8968. /* The IOCTL status is embedded in the mailbox subheader. */
  8969. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8970. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8971. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8972. if (shdr_status || shdr_add_status || rc) {
  8973. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8974. "2502 MQ_CREATE mailbox failed with "
  8975. "status x%x add_status x%x, mbx status x%x\n",
  8976. shdr_status, shdr_add_status, rc);
  8977. status = -ENXIO;
  8978. goto out;
  8979. }
  8980. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8981. if (mq->queue_id == 0xFFFF) {
  8982. status = -ENXIO;
  8983. goto out;
  8984. }
  8985. mq->type = LPFC_MQ;
  8986. mq->subtype = subtype;
  8987. mq->host_index = 0;
  8988. mq->hba_index = 0;
  8989. /* link the mq onto the parent cq child list */
  8990. list_add_tail(&mq->list, &cq->child_list);
  8991. out:
  8992. mempool_free(mbox, phba->mbox_mem_pool);
  8993. return status;
  8994. }
  8995. /**
  8996. * lpfc_wq_create - Create a Work Queue on the HBA
  8997. * @phba: HBA structure that indicates port to create a queue on.
  8998. * @wq: The queue structure to use to create the work queue.
  8999. * @cq: The completion queue to bind this work queue to.
  9000. * @subtype: The subtype of the work queue indicating its functionality.
  9001. *
  9002. * This function creates a work queue, as detailed in @wq, on a port, described
  9003. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9004. *
  9005. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9006. * is used to get the entry count and entry size that are necessary to
  9007. * determine the number of pages to allocate and use for this queue. The @cq
  9008. * is used to indicate which completion queue to bind this work queue to. This
  9009. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9010. * work queue. This function is asynchronous and will wait for the mailbox
  9011. * command to finish before continuing.
  9012. *
  9013. * On success this function will return a zero. If unable to allocate enough
  9014. * memory this function will return ENOMEM. If the queue create mailbox command
  9015. * fails this function will return ENXIO.
  9016. **/
  9017. uint32_t
  9018. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9019. struct lpfc_queue *cq, uint32_t subtype)
  9020. {
  9021. struct lpfc_mbx_wq_create *wq_create;
  9022. struct lpfc_dmabuf *dmabuf;
  9023. LPFC_MBOXQ_t *mbox;
  9024. int rc, length, status = 0;
  9025. uint32_t shdr_status, shdr_add_status;
  9026. union lpfc_sli4_cfg_shdr *shdr;
  9027. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9028. if (!mbox)
  9029. return -ENOMEM;
  9030. length = (sizeof(struct lpfc_mbx_wq_create) -
  9031. sizeof(struct lpfc_sli4_cfg_mhdr));
  9032. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9033. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9034. length, LPFC_SLI4_MBX_EMBED);
  9035. wq_create = &mbox->u.mqe.un.wq_create;
  9036. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9037. wq->page_count);
  9038. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9039. cq->queue_id);
  9040. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9041. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9042. putPaddrLow(dmabuf->phys);
  9043. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9044. putPaddrHigh(dmabuf->phys);
  9045. }
  9046. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9047. /* The IOCTL status is embedded in the mailbox subheader. */
  9048. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9049. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9050. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9051. if (shdr_status || shdr_add_status || rc) {
  9052. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9053. "2503 WQ_CREATE mailbox failed with "
  9054. "status x%x add_status x%x, mbx status x%x\n",
  9055. shdr_status, shdr_add_status, rc);
  9056. status = -ENXIO;
  9057. goto out;
  9058. }
  9059. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9060. if (wq->queue_id == 0xFFFF) {
  9061. status = -ENXIO;
  9062. goto out;
  9063. }
  9064. wq->type = LPFC_WQ;
  9065. wq->subtype = subtype;
  9066. wq->host_index = 0;
  9067. wq->hba_index = 0;
  9068. /* link the wq onto the parent cq child list */
  9069. list_add_tail(&wq->list, &cq->child_list);
  9070. out:
  9071. mempool_free(mbox, phba->mbox_mem_pool);
  9072. return status;
  9073. }
  9074. /**
  9075. * lpfc_rq_create - Create a Receive Queue on the HBA
  9076. * @phba: HBA structure that indicates port to create a queue on.
  9077. * @hrq: The queue structure to use to create the header receive queue.
  9078. * @drq: The queue structure to use to create the data receive queue.
  9079. * @cq: The completion queue to bind this work queue to.
  9080. *
  9081. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9082. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9083. * to the HBA.
  9084. *
  9085. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9086. * struct is used to get the entry count that is necessary to determine the
  9087. * number of pages to use for this queue. The @cq is used to indicate which
  9088. * completion queue to bind received buffers that are posted to these queues to.
  9089. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9090. * receive queue pair. This function is asynchronous and will wait for the
  9091. * mailbox command to finish before continuing.
  9092. *
  9093. * On success this function will return a zero. If unable to allocate enough
  9094. * memory this function will return ENOMEM. If the queue create mailbox command
  9095. * fails this function will return ENXIO.
  9096. **/
  9097. uint32_t
  9098. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9099. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9100. {
  9101. struct lpfc_mbx_rq_create *rq_create;
  9102. struct lpfc_dmabuf *dmabuf;
  9103. LPFC_MBOXQ_t *mbox;
  9104. int rc, length, status = 0;
  9105. uint32_t shdr_status, shdr_add_status;
  9106. union lpfc_sli4_cfg_shdr *shdr;
  9107. if (hrq->entry_count != drq->entry_count)
  9108. return -EINVAL;
  9109. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9110. if (!mbox)
  9111. return -ENOMEM;
  9112. length = (sizeof(struct lpfc_mbx_rq_create) -
  9113. sizeof(struct lpfc_sli4_cfg_mhdr));
  9114. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9115. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9116. length, LPFC_SLI4_MBX_EMBED);
  9117. rq_create = &mbox->u.mqe.un.rq_create;
  9118. switch (hrq->entry_count) {
  9119. default:
  9120. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9121. "2535 Unsupported RQ count. (%d)\n",
  9122. hrq->entry_count);
  9123. if (hrq->entry_count < 512)
  9124. return -EINVAL;
  9125. /* otherwise default to smallest count (drop through) */
  9126. case 512:
  9127. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9128. LPFC_RQ_RING_SIZE_512);
  9129. break;
  9130. case 1024:
  9131. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9132. LPFC_RQ_RING_SIZE_1024);
  9133. break;
  9134. case 2048:
  9135. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9136. LPFC_RQ_RING_SIZE_2048);
  9137. break;
  9138. case 4096:
  9139. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9140. LPFC_RQ_RING_SIZE_4096);
  9141. break;
  9142. }
  9143. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9144. cq->queue_id);
  9145. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9146. hrq->page_count);
  9147. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9148. LPFC_HDR_BUF_SIZE);
  9149. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9150. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9151. putPaddrLow(dmabuf->phys);
  9152. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9153. putPaddrHigh(dmabuf->phys);
  9154. }
  9155. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9156. /* The IOCTL status is embedded in the mailbox subheader. */
  9157. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9158. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9159. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9160. if (shdr_status || shdr_add_status || rc) {
  9161. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9162. "2504 RQ_CREATE mailbox failed with "
  9163. "status x%x add_status x%x, mbx status x%x\n",
  9164. shdr_status, shdr_add_status, rc);
  9165. status = -ENXIO;
  9166. goto out;
  9167. }
  9168. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9169. if (hrq->queue_id == 0xFFFF) {
  9170. status = -ENXIO;
  9171. goto out;
  9172. }
  9173. hrq->type = LPFC_HRQ;
  9174. hrq->subtype = subtype;
  9175. hrq->host_index = 0;
  9176. hrq->hba_index = 0;
  9177. /* now create the data queue */
  9178. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9179. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9180. length, LPFC_SLI4_MBX_EMBED);
  9181. switch (drq->entry_count) {
  9182. default:
  9183. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9184. "2536 Unsupported RQ count. (%d)\n",
  9185. drq->entry_count);
  9186. if (drq->entry_count < 512)
  9187. return -EINVAL;
  9188. /* otherwise default to smallest count (drop through) */
  9189. case 512:
  9190. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9191. LPFC_RQ_RING_SIZE_512);
  9192. break;
  9193. case 1024:
  9194. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9195. LPFC_RQ_RING_SIZE_1024);
  9196. break;
  9197. case 2048:
  9198. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9199. LPFC_RQ_RING_SIZE_2048);
  9200. break;
  9201. case 4096:
  9202. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9203. LPFC_RQ_RING_SIZE_4096);
  9204. break;
  9205. }
  9206. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9207. cq->queue_id);
  9208. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9209. drq->page_count);
  9210. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9211. LPFC_DATA_BUF_SIZE);
  9212. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9213. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9214. putPaddrLow(dmabuf->phys);
  9215. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9216. putPaddrHigh(dmabuf->phys);
  9217. }
  9218. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9219. /* The IOCTL status is embedded in the mailbox subheader. */
  9220. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9221. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9222. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9223. if (shdr_status || shdr_add_status || rc) {
  9224. status = -ENXIO;
  9225. goto out;
  9226. }
  9227. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9228. if (drq->queue_id == 0xFFFF) {
  9229. status = -ENXIO;
  9230. goto out;
  9231. }
  9232. drq->type = LPFC_DRQ;
  9233. drq->subtype = subtype;
  9234. drq->host_index = 0;
  9235. drq->hba_index = 0;
  9236. /* link the header and data RQs onto the parent cq child list */
  9237. list_add_tail(&hrq->list, &cq->child_list);
  9238. list_add_tail(&drq->list, &cq->child_list);
  9239. out:
  9240. mempool_free(mbox, phba->mbox_mem_pool);
  9241. return status;
  9242. }
  9243. /**
  9244. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9245. * @eq: The queue structure associated with the queue to destroy.
  9246. *
  9247. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9248. * command, specific to the type of queue, to the HBA.
  9249. *
  9250. * The @eq struct is used to get the queue ID of the queue to destroy.
  9251. *
  9252. * On success this function will return a zero. If the queue destroy mailbox
  9253. * command fails this function will return ENXIO.
  9254. **/
  9255. uint32_t
  9256. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9257. {
  9258. LPFC_MBOXQ_t *mbox;
  9259. int rc, length, status = 0;
  9260. uint32_t shdr_status, shdr_add_status;
  9261. union lpfc_sli4_cfg_shdr *shdr;
  9262. if (!eq)
  9263. return -ENODEV;
  9264. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9265. if (!mbox)
  9266. return -ENOMEM;
  9267. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9268. sizeof(struct lpfc_sli4_cfg_mhdr));
  9269. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9270. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9271. length, LPFC_SLI4_MBX_EMBED);
  9272. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9273. eq->queue_id);
  9274. mbox->vport = eq->phba->pport;
  9275. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9276. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9277. /* The IOCTL status is embedded in the mailbox subheader. */
  9278. shdr = (union lpfc_sli4_cfg_shdr *)
  9279. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9280. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9281. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9282. if (shdr_status || shdr_add_status || rc) {
  9283. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9284. "2505 EQ_DESTROY mailbox failed with "
  9285. "status x%x add_status x%x, mbx status x%x\n",
  9286. shdr_status, shdr_add_status, rc);
  9287. status = -ENXIO;
  9288. }
  9289. /* Remove eq from any list */
  9290. list_del_init(&eq->list);
  9291. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9292. return status;
  9293. }
  9294. /**
  9295. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9296. * @cq: The queue structure associated with the queue to destroy.
  9297. *
  9298. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9299. * command, specific to the type of queue, to the HBA.
  9300. *
  9301. * The @cq struct is used to get the queue ID of the queue to destroy.
  9302. *
  9303. * On success this function will return a zero. If the queue destroy mailbox
  9304. * command fails this function will return ENXIO.
  9305. **/
  9306. uint32_t
  9307. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9308. {
  9309. LPFC_MBOXQ_t *mbox;
  9310. int rc, length, status = 0;
  9311. uint32_t shdr_status, shdr_add_status;
  9312. union lpfc_sli4_cfg_shdr *shdr;
  9313. if (!cq)
  9314. return -ENODEV;
  9315. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9316. if (!mbox)
  9317. return -ENOMEM;
  9318. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9319. sizeof(struct lpfc_sli4_cfg_mhdr));
  9320. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9321. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9322. length, LPFC_SLI4_MBX_EMBED);
  9323. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9324. cq->queue_id);
  9325. mbox->vport = cq->phba->pport;
  9326. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9327. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9328. /* The IOCTL status is embedded in the mailbox subheader. */
  9329. shdr = (union lpfc_sli4_cfg_shdr *)
  9330. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9331. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9332. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9333. if (shdr_status || shdr_add_status || rc) {
  9334. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9335. "2506 CQ_DESTROY mailbox failed with "
  9336. "status x%x add_status x%x, mbx status x%x\n",
  9337. shdr_status, shdr_add_status, rc);
  9338. status = -ENXIO;
  9339. }
  9340. /* Remove cq from any list */
  9341. list_del_init(&cq->list);
  9342. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9343. return status;
  9344. }
  9345. /**
  9346. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9347. * @qm: The queue structure associated with the queue to destroy.
  9348. *
  9349. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9350. * command, specific to the type of queue, to the HBA.
  9351. *
  9352. * The @mq struct is used to get the queue ID of the queue to destroy.
  9353. *
  9354. * On success this function will return a zero. If the queue destroy mailbox
  9355. * command fails this function will return ENXIO.
  9356. **/
  9357. uint32_t
  9358. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9359. {
  9360. LPFC_MBOXQ_t *mbox;
  9361. int rc, length, status = 0;
  9362. uint32_t shdr_status, shdr_add_status;
  9363. union lpfc_sli4_cfg_shdr *shdr;
  9364. if (!mq)
  9365. return -ENODEV;
  9366. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9367. if (!mbox)
  9368. return -ENOMEM;
  9369. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9370. sizeof(struct lpfc_sli4_cfg_mhdr));
  9371. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9372. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9373. length, LPFC_SLI4_MBX_EMBED);
  9374. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9375. mq->queue_id);
  9376. mbox->vport = mq->phba->pport;
  9377. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9378. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9379. /* The IOCTL status is embedded in the mailbox subheader. */
  9380. shdr = (union lpfc_sli4_cfg_shdr *)
  9381. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9382. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9383. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9384. if (shdr_status || shdr_add_status || rc) {
  9385. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9386. "2507 MQ_DESTROY mailbox failed with "
  9387. "status x%x add_status x%x, mbx status x%x\n",
  9388. shdr_status, shdr_add_status, rc);
  9389. status = -ENXIO;
  9390. }
  9391. /* Remove mq from any list */
  9392. list_del_init(&mq->list);
  9393. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9394. return status;
  9395. }
  9396. /**
  9397. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9398. * @wq: The queue structure associated with the queue to destroy.
  9399. *
  9400. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9401. * command, specific to the type of queue, to the HBA.
  9402. *
  9403. * The @wq struct is used to get the queue ID of the queue to destroy.
  9404. *
  9405. * On success this function will return a zero. If the queue destroy mailbox
  9406. * command fails this function will return ENXIO.
  9407. **/
  9408. uint32_t
  9409. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9410. {
  9411. LPFC_MBOXQ_t *mbox;
  9412. int rc, length, status = 0;
  9413. uint32_t shdr_status, shdr_add_status;
  9414. union lpfc_sli4_cfg_shdr *shdr;
  9415. if (!wq)
  9416. return -ENODEV;
  9417. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9418. if (!mbox)
  9419. return -ENOMEM;
  9420. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9421. sizeof(struct lpfc_sli4_cfg_mhdr));
  9422. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9423. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9424. length, LPFC_SLI4_MBX_EMBED);
  9425. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9426. wq->queue_id);
  9427. mbox->vport = wq->phba->pport;
  9428. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9429. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9430. shdr = (union lpfc_sli4_cfg_shdr *)
  9431. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9432. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9433. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9434. if (shdr_status || shdr_add_status || rc) {
  9435. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9436. "2508 WQ_DESTROY mailbox failed with "
  9437. "status x%x add_status x%x, mbx status x%x\n",
  9438. shdr_status, shdr_add_status, rc);
  9439. status = -ENXIO;
  9440. }
  9441. /* Remove wq from any list */
  9442. list_del_init(&wq->list);
  9443. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9444. return status;
  9445. }
  9446. /**
  9447. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9448. * @rq: The queue structure associated with the queue to destroy.
  9449. *
  9450. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9451. * command, specific to the type of queue, to the HBA.
  9452. *
  9453. * The @rq struct is used to get the queue ID of the queue to destroy.
  9454. *
  9455. * On success this function will return a zero. If the queue destroy mailbox
  9456. * command fails this function will return ENXIO.
  9457. **/
  9458. uint32_t
  9459. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9460. struct lpfc_queue *drq)
  9461. {
  9462. LPFC_MBOXQ_t *mbox;
  9463. int rc, length, status = 0;
  9464. uint32_t shdr_status, shdr_add_status;
  9465. union lpfc_sli4_cfg_shdr *shdr;
  9466. if (!hrq || !drq)
  9467. return -ENODEV;
  9468. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9469. if (!mbox)
  9470. return -ENOMEM;
  9471. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9472. sizeof(struct mbox_header));
  9473. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9474. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9475. length, LPFC_SLI4_MBX_EMBED);
  9476. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9477. hrq->queue_id);
  9478. mbox->vport = hrq->phba->pport;
  9479. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9480. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9481. /* The IOCTL status is embedded in the mailbox subheader. */
  9482. shdr = (union lpfc_sli4_cfg_shdr *)
  9483. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9484. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9485. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9486. if (shdr_status || shdr_add_status || rc) {
  9487. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9488. "2509 RQ_DESTROY mailbox failed with "
  9489. "status x%x add_status x%x, mbx status x%x\n",
  9490. shdr_status, shdr_add_status, rc);
  9491. if (rc != MBX_TIMEOUT)
  9492. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9493. return -ENXIO;
  9494. }
  9495. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9496. drq->queue_id);
  9497. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9498. shdr = (union lpfc_sli4_cfg_shdr *)
  9499. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9500. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9501. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9502. if (shdr_status || shdr_add_status || rc) {
  9503. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9504. "2510 RQ_DESTROY mailbox failed with "
  9505. "status x%x add_status x%x, mbx status x%x\n",
  9506. shdr_status, shdr_add_status, rc);
  9507. status = -ENXIO;
  9508. }
  9509. list_del_init(&hrq->list);
  9510. list_del_init(&drq->list);
  9511. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9512. return status;
  9513. }
  9514. /**
  9515. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9516. * @phba: The virtual port for which this call being executed.
  9517. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9518. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9519. * @xritag: the xritag that ties this io to the SGL pages.
  9520. *
  9521. * This routine will post the sgl pages for the IO that has the xritag
  9522. * that is in the iocbq structure. The xritag is assigned during iocbq
  9523. * creation and persists for as long as the driver is loaded.
  9524. * if the caller has fewer than 256 scatter gather segments to map then
  9525. * pdma_phys_addr1 should be 0.
  9526. * If the caller needs to map more than 256 scatter gather segment then
  9527. * pdma_phys_addr1 should be a valid physical address.
  9528. * physical address for SGLs must be 64 byte aligned.
  9529. * If you are going to map 2 SGL's then the first one must have 256 entries
  9530. * the second sgl can have between 1 and 256 entries.
  9531. *
  9532. * Return codes:
  9533. * 0 - Success
  9534. * -ENXIO, -ENOMEM - Failure
  9535. **/
  9536. int
  9537. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9538. dma_addr_t pdma_phys_addr0,
  9539. dma_addr_t pdma_phys_addr1,
  9540. uint16_t xritag)
  9541. {
  9542. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9543. LPFC_MBOXQ_t *mbox;
  9544. int rc;
  9545. uint32_t shdr_status, shdr_add_status;
  9546. union lpfc_sli4_cfg_shdr *shdr;
  9547. if (xritag == NO_XRI) {
  9548. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9549. "0364 Invalid param:\n");
  9550. return -EINVAL;
  9551. }
  9552. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9553. if (!mbox)
  9554. return -ENOMEM;
  9555. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9556. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9557. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9558. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9559. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9560. &mbox->u.mqe.un.post_sgl_pages;
  9561. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9562. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9563. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9564. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9565. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9566. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9567. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9568. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9569. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9570. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9571. if (!phba->sli4_hba.intr_enable)
  9572. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9573. else
  9574. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9575. /* The IOCTL status is embedded in the mailbox subheader. */
  9576. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9577. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9578. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9579. if (rc != MBX_TIMEOUT)
  9580. mempool_free(mbox, phba->mbox_mem_pool);
  9581. if (shdr_status || shdr_add_status || rc) {
  9582. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9583. "2511 POST_SGL mailbox failed with "
  9584. "status x%x add_status x%x, mbx status x%x\n",
  9585. shdr_status, shdr_add_status, rc);
  9586. rc = -ENXIO;
  9587. }
  9588. return 0;
  9589. }
  9590. /**
  9591. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9592. * @phba: The virtual port for which this call being executed.
  9593. *
  9594. * This routine will remove all of the sgl pages registered with the hba.
  9595. *
  9596. * Return codes:
  9597. * 0 - Success
  9598. * -ENXIO, -ENOMEM - Failure
  9599. **/
  9600. int
  9601. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9602. {
  9603. LPFC_MBOXQ_t *mbox;
  9604. int rc;
  9605. uint32_t shdr_status, shdr_add_status;
  9606. union lpfc_sli4_cfg_shdr *shdr;
  9607. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9608. if (!mbox)
  9609. return -ENOMEM;
  9610. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9611. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9612. LPFC_SLI4_MBX_EMBED);
  9613. if (!phba->sli4_hba.intr_enable)
  9614. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9615. else
  9616. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9617. /* The IOCTL status is embedded in the mailbox subheader. */
  9618. shdr = (union lpfc_sli4_cfg_shdr *)
  9619. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9620. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9621. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9622. if (rc != MBX_TIMEOUT)
  9623. mempool_free(mbox, phba->mbox_mem_pool);
  9624. if (shdr_status || shdr_add_status || rc) {
  9625. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9626. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9627. "status x%x add_status x%x, mbx status x%x\n",
  9628. shdr_status, shdr_add_status, rc);
  9629. rc = -ENXIO;
  9630. }
  9631. return rc;
  9632. }
  9633. /**
  9634. * lpfc_sli4_next_xritag - Get an xritag for the io
  9635. * @phba: Pointer to HBA context object.
  9636. *
  9637. * This function gets an xritag for the iocb. If there is no unused xritag
  9638. * it will return 0xffff.
  9639. * The function returns the allocated xritag if successful, else returns zero.
  9640. * Zero is not a valid xritag.
  9641. * The caller is not required to hold any lock.
  9642. **/
  9643. uint16_t
  9644. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9645. {
  9646. uint16_t xritag;
  9647. spin_lock_irq(&phba->hbalock);
  9648. xritag = phba->sli4_hba.next_xri;
  9649. if ((xritag != (uint16_t) -1) && xritag <
  9650. (phba->sli4_hba.max_cfg_param.max_xri
  9651. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9652. phba->sli4_hba.next_xri++;
  9653. phba->sli4_hba.max_cfg_param.xri_used++;
  9654. spin_unlock_irq(&phba->hbalock);
  9655. return xritag;
  9656. }
  9657. spin_unlock_irq(&phba->hbalock);
  9658. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9659. "2004 Failed to allocate XRI.last XRITAG is %d"
  9660. " Max XRI is %d, Used XRI is %d\n",
  9661. phba->sli4_hba.next_xri,
  9662. phba->sli4_hba.max_cfg_param.max_xri,
  9663. phba->sli4_hba.max_cfg_param.xri_used);
  9664. return -1;
  9665. }
  9666. /**
  9667. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9668. * @phba: pointer to lpfc hba data structure.
  9669. *
  9670. * This routine is invoked to post a block of driver's sgl pages to the
  9671. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9672. * is only called when the driver is loading and after all IO has been
  9673. * stopped.
  9674. **/
  9675. int
  9676. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9677. {
  9678. struct lpfc_sglq *sglq_entry;
  9679. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9680. struct sgl_page_pairs *sgl_pg_pairs;
  9681. void *viraddr;
  9682. LPFC_MBOXQ_t *mbox;
  9683. uint32_t reqlen, alloclen, pg_pairs;
  9684. uint32_t mbox_tmo;
  9685. uint16_t xritag_start = 0;
  9686. int els_xri_cnt, rc = 0;
  9687. uint32_t shdr_status, shdr_add_status;
  9688. union lpfc_sli4_cfg_shdr *shdr;
  9689. /* The number of sgls to be posted */
  9690. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9691. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9692. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9693. if (reqlen > PAGE_SIZE) {
  9694. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9695. "2559 Block sgl registration required DMA "
  9696. "size (%d) great than a page\n", reqlen);
  9697. return -ENOMEM;
  9698. }
  9699. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9700. if (!mbox) {
  9701. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9702. "2560 Failed to allocate mbox cmd memory\n");
  9703. return -ENOMEM;
  9704. }
  9705. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9706. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9707. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9708. LPFC_SLI4_MBX_NEMBED);
  9709. if (alloclen < reqlen) {
  9710. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9711. "0285 Allocated DMA memory size (%d) is "
  9712. "less than the requested DMA memory "
  9713. "size (%d)\n", alloclen, reqlen);
  9714. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9715. return -ENOMEM;
  9716. }
  9717. /* Get the first SGE entry from the non-embedded DMA memory */
  9718. viraddr = mbox->sge_array->addr[0];
  9719. /* Set up the SGL pages in the non-embedded DMA pages */
  9720. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9721. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9722. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9723. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9724. /* Set up the sge entry */
  9725. sgl_pg_pairs->sgl_pg0_addr_lo =
  9726. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9727. sgl_pg_pairs->sgl_pg0_addr_hi =
  9728. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9729. sgl_pg_pairs->sgl_pg1_addr_lo =
  9730. cpu_to_le32(putPaddrLow(0));
  9731. sgl_pg_pairs->sgl_pg1_addr_hi =
  9732. cpu_to_le32(putPaddrHigh(0));
  9733. /* Keep the first xritag on the list */
  9734. if (pg_pairs == 0)
  9735. xritag_start = sglq_entry->sli4_xritag;
  9736. sgl_pg_pairs++;
  9737. }
  9738. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9739. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9740. /* Perform endian conversion if necessary */
  9741. sgl->word0 = cpu_to_le32(sgl->word0);
  9742. if (!phba->sli4_hba.intr_enable)
  9743. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9744. else {
  9745. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9746. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9747. }
  9748. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9749. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9750. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9751. if (rc != MBX_TIMEOUT)
  9752. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9753. if (shdr_status || shdr_add_status || rc) {
  9754. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9755. "2513 POST_SGL_BLOCK mailbox command failed "
  9756. "status x%x add_status x%x mbx status x%x\n",
  9757. shdr_status, shdr_add_status, rc);
  9758. rc = -ENXIO;
  9759. }
  9760. return rc;
  9761. }
  9762. /**
  9763. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9764. * @phba: pointer to lpfc hba data structure.
  9765. * @sblist: pointer to scsi buffer list.
  9766. * @count: number of scsi buffers on the list.
  9767. *
  9768. * This routine is invoked to post a block of @count scsi sgl pages from a
  9769. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9770. * No Lock is held.
  9771. *
  9772. **/
  9773. int
  9774. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9775. int cnt)
  9776. {
  9777. struct lpfc_scsi_buf *psb;
  9778. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9779. struct sgl_page_pairs *sgl_pg_pairs;
  9780. void *viraddr;
  9781. LPFC_MBOXQ_t *mbox;
  9782. uint32_t reqlen, alloclen, pg_pairs;
  9783. uint32_t mbox_tmo;
  9784. uint16_t xritag_start = 0;
  9785. int rc = 0;
  9786. uint32_t shdr_status, shdr_add_status;
  9787. dma_addr_t pdma_phys_bpl1;
  9788. union lpfc_sli4_cfg_shdr *shdr;
  9789. /* Calculate the requested length of the dma memory */
  9790. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9791. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9792. if (reqlen > PAGE_SIZE) {
  9793. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9794. "0217 Block sgl registration required DMA "
  9795. "size (%d) great than a page\n", reqlen);
  9796. return -ENOMEM;
  9797. }
  9798. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9799. if (!mbox) {
  9800. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9801. "0283 Failed to allocate mbox cmd memory\n");
  9802. return -ENOMEM;
  9803. }
  9804. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9805. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9806. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9807. LPFC_SLI4_MBX_NEMBED);
  9808. if (alloclen < reqlen) {
  9809. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9810. "2561 Allocated DMA memory size (%d) is "
  9811. "less than the requested DMA memory "
  9812. "size (%d)\n", alloclen, reqlen);
  9813. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9814. return -ENOMEM;
  9815. }
  9816. /* Get the first SGE entry from the non-embedded DMA memory */
  9817. viraddr = mbox->sge_array->addr[0];
  9818. /* Set up the SGL pages in the non-embedded DMA pages */
  9819. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9820. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9821. pg_pairs = 0;
  9822. list_for_each_entry(psb, sblist, list) {
  9823. /* Set up the sge entry */
  9824. sgl_pg_pairs->sgl_pg0_addr_lo =
  9825. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9826. sgl_pg_pairs->sgl_pg0_addr_hi =
  9827. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9828. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9829. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9830. else
  9831. pdma_phys_bpl1 = 0;
  9832. sgl_pg_pairs->sgl_pg1_addr_lo =
  9833. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9834. sgl_pg_pairs->sgl_pg1_addr_hi =
  9835. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9836. /* Keep the first xritag on the list */
  9837. if (pg_pairs == 0)
  9838. xritag_start = psb->cur_iocbq.sli4_xritag;
  9839. sgl_pg_pairs++;
  9840. pg_pairs++;
  9841. }
  9842. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9843. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9844. /* Perform endian conversion if necessary */
  9845. sgl->word0 = cpu_to_le32(sgl->word0);
  9846. if (!phba->sli4_hba.intr_enable)
  9847. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9848. else {
  9849. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9850. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9851. }
  9852. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9853. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9854. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9855. if (rc != MBX_TIMEOUT)
  9856. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9857. if (shdr_status || shdr_add_status || rc) {
  9858. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9859. "2564 POST_SGL_BLOCK mailbox command failed "
  9860. "status x%x add_status x%x mbx status x%x\n",
  9861. shdr_status, shdr_add_status, rc);
  9862. rc = -ENXIO;
  9863. }
  9864. return rc;
  9865. }
  9866. /**
  9867. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9868. * @phba: pointer to lpfc_hba struct that the frame was received on
  9869. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9870. *
  9871. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9872. * valid type of frame that the LPFC driver will handle. This function will
  9873. * return a zero if the frame is a valid frame or a non zero value when the
  9874. * frame does not pass the check.
  9875. **/
  9876. static int
  9877. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9878. {
  9879. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9880. char *type_names[] = FC_TYPE_NAMES_INIT;
  9881. struct fc_vft_header *fc_vft_hdr;
  9882. switch (fc_hdr->fh_r_ctl) {
  9883. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9884. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9885. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9886. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9887. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9888. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9889. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9890. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9891. case FC_RCTL_ELS_REQ: /* extended link services request */
  9892. case FC_RCTL_ELS_REP: /* extended link services reply */
  9893. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9894. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9895. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9896. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9897. case FC_RCTL_BA_RMC: /* remove connection */
  9898. case FC_RCTL_BA_ACC: /* basic accept */
  9899. case FC_RCTL_BA_RJT: /* basic reject */
  9900. case FC_RCTL_BA_PRMT:
  9901. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9902. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9903. case FC_RCTL_P_RJT: /* port reject */
  9904. case FC_RCTL_F_RJT: /* fabric reject */
  9905. case FC_RCTL_P_BSY: /* port busy */
  9906. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9907. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9908. case FC_RCTL_LCR: /* link credit reset */
  9909. case FC_RCTL_END: /* end */
  9910. break;
  9911. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9912. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9913. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9914. return lpfc_fc_frame_check(phba, fc_hdr);
  9915. default:
  9916. goto drop;
  9917. }
  9918. switch (fc_hdr->fh_type) {
  9919. case FC_TYPE_BLS:
  9920. case FC_TYPE_ELS:
  9921. case FC_TYPE_FCP:
  9922. case FC_TYPE_CT:
  9923. break;
  9924. case FC_TYPE_IP:
  9925. case FC_TYPE_ILS:
  9926. default:
  9927. goto drop;
  9928. }
  9929. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9930. "2538 Received frame rctl:%s type:%s\n",
  9931. rctl_names[fc_hdr->fh_r_ctl],
  9932. type_names[fc_hdr->fh_type]);
  9933. return 0;
  9934. drop:
  9935. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9936. "2539 Dropped frame rctl:%s type:%s\n",
  9937. rctl_names[fc_hdr->fh_r_ctl],
  9938. type_names[fc_hdr->fh_type]);
  9939. return 1;
  9940. }
  9941. /**
  9942. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9943. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9944. *
  9945. * This function processes the FC header to retrieve the VFI from the VF
  9946. * header, if one exists. This function will return the VFI if one exists
  9947. * or 0 if no VSAN Header exists.
  9948. **/
  9949. static uint32_t
  9950. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9951. {
  9952. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9953. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9954. return 0;
  9955. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9956. }
  9957. /**
  9958. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9959. * @phba: Pointer to the HBA structure to search for the vport on
  9960. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9961. * @fcfi: The FC Fabric ID that the frame came from
  9962. *
  9963. * This function searches the @phba for a vport that matches the content of the
  9964. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9965. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9966. * returns the matching vport pointer or NULL if unable to match frame to a
  9967. * vport.
  9968. **/
  9969. static struct lpfc_vport *
  9970. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9971. uint16_t fcfi)
  9972. {
  9973. struct lpfc_vport **vports;
  9974. struct lpfc_vport *vport = NULL;
  9975. int i;
  9976. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9977. fc_hdr->fh_d_id[1] << 8 |
  9978. fc_hdr->fh_d_id[2]);
  9979. vports = lpfc_create_vport_work_array(phba);
  9980. if (vports != NULL)
  9981. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9982. if (phba->fcf.fcfi == fcfi &&
  9983. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9984. vports[i]->fc_myDID == did) {
  9985. vport = vports[i];
  9986. break;
  9987. }
  9988. }
  9989. lpfc_destroy_vport_work_array(phba, vports);
  9990. return vport;
  9991. }
  9992. /**
  9993. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  9994. * @vport: The vport to work on.
  9995. *
  9996. * This function updates the receive sequence time stamp for this vport. The
  9997. * receive sequence time stamp indicates the time that the last frame of the
  9998. * the sequence that has been idle for the longest amount of time was received.
  9999. * the driver uses this time stamp to indicate if any received sequences have
  10000. * timed out.
  10001. **/
  10002. void
  10003. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10004. {
  10005. struct lpfc_dmabuf *h_buf;
  10006. struct hbq_dmabuf *dmabuf = NULL;
  10007. /* get the oldest sequence on the rcv list */
  10008. h_buf = list_get_first(&vport->rcv_buffer_list,
  10009. struct lpfc_dmabuf, list);
  10010. if (!h_buf)
  10011. return;
  10012. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10013. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10014. }
  10015. /**
  10016. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10017. * @vport: The vport that the received sequences were sent to.
  10018. *
  10019. * This function cleans up all outstanding received sequences. This is called
  10020. * by the driver when a link event or user action invalidates all the received
  10021. * sequences.
  10022. **/
  10023. void
  10024. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10025. {
  10026. struct lpfc_dmabuf *h_buf, *hnext;
  10027. struct lpfc_dmabuf *d_buf, *dnext;
  10028. struct hbq_dmabuf *dmabuf = NULL;
  10029. /* start with the oldest sequence on the rcv list */
  10030. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10031. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10032. list_del_init(&dmabuf->hbuf.list);
  10033. list_for_each_entry_safe(d_buf, dnext,
  10034. &dmabuf->dbuf.list, list) {
  10035. list_del_init(&d_buf->list);
  10036. lpfc_in_buf_free(vport->phba, d_buf);
  10037. }
  10038. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10039. }
  10040. }
  10041. /**
  10042. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10043. * @vport: The vport that the received sequences were sent to.
  10044. *
  10045. * This function determines whether any received sequences have timed out by
  10046. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10047. * indicates that there is at least one timed out sequence this routine will
  10048. * go through the received sequences one at a time from most inactive to most
  10049. * active to determine which ones need to be cleaned up. Once it has determined
  10050. * that a sequence needs to be cleaned up it will simply free up the resources
  10051. * without sending an abort.
  10052. **/
  10053. void
  10054. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10055. {
  10056. struct lpfc_dmabuf *h_buf, *hnext;
  10057. struct lpfc_dmabuf *d_buf, *dnext;
  10058. struct hbq_dmabuf *dmabuf = NULL;
  10059. unsigned long timeout;
  10060. int abort_count = 0;
  10061. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10062. vport->rcv_buffer_time_stamp);
  10063. if (list_empty(&vport->rcv_buffer_list) ||
  10064. time_before(jiffies, timeout))
  10065. return;
  10066. /* start with the oldest sequence on the rcv list */
  10067. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10068. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10069. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10070. dmabuf->time_stamp);
  10071. if (time_before(jiffies, timeout))
  10072. break;
  10073. abort_count++;
  10074. list_del_init(&dmabuf->hbuf.list);
  10075. list_for_each_entry_safe(d_buf, dnext,
  10076. &dmabuf->dbuf.list, list) {
  10077. list_del_init(&d_buf->list);
  10078. lpfc_in_buf_free(vport->phba, d_buf);
  10079. }
  10080. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10081. }
  10082. if (abort_count)
  10083. lpfc_update_rcv_time_stamp(vport);
  10084. }
  10085. /**
  10086. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10087. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10088. *
  10089. * This function searches through the existing incomplete sequences that have
  10090. * been sent to this @vport. If the frame matches one of the incomplete
  10091. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10092. * make up that sequence. If no sequence is found that matches this frame then
  10093. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10094. * This function returns a pointer to the first dmabuf in the sequence list that
  10095. * the frame was linked to.
  10096. **/
  10097. static struct hbq_dmabuf *
  10098. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10099. {
  10100. struct fc_frame_header *new_hdr;
  10101. struct fc_frame_header *temp_hdr;
  10102. struct lpfc_dmabuf *d_buf;
  10103. struct lpfc_dmabuf *h_buf;
  10104. struct hbq_dmabuf *seq_dmabuf = NULL;
  10105. struct hbq_dmabuf *temp_dmabuf = NULL;
  10106. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10107. dmabuf->time_stamp = jiffies;
  10108. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10109. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10110. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10111. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10112. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10113. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10114. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10115. continue;
  10116. /* found a pending sequence that matches this frame */
  10117. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10118. break;
  10119. }
  10120. if (!seq_dmabuf) {
  10121. /*
  10122. * This indicates first frame received for this sequence.
  10123. * Queue the buffer on the vport's rcv_buffer_list.
  10124. */
  10125. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10126. lpfc_update_rcv_time_stamp(vport);
  10127. return dmabuf;
  10128. }
  10129. temp_hdr = seq_dmabuf->hbuf.virt;
  10130. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10131. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10132. list_del_init(&seq_dmabuf->hbuf.list);
  10133. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10134. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10135. lpfc_update_rcv_time_stamp(vport);
  10136. return dmabuf;
  10137. }
  10138. /* move this sequence to the tail to indicate a young sequence */
  10139. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10140. seq_dmabuf->time_stamp = jiffies;
  10141. lpfc_update_rcv_time_stamp(vport);
  10142. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10143. temp_hdr = dmabuf->hbuf.virt;
  10144. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10145. return seq_dmabuf;
  10146. }
  10147. /* find the correct place in the sequence to insert this frame */
  10148. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10149. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10150. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10151. /*
  10152. * If the frame's sequence count is greater than the frame on
  10153. * the list then insert the frame right after this frame
  10154. */
  10155. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10156. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10157. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10158. return seq_dmabuf;
  10159. }
  10160. }
  10161. return NULL;
  10162. }
  10163. /**
  10164. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10165. * @vport: pointer to a vitural port
  10166. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10167. *
  10168. * This function tries to abort from the partially assembed sequence, described
  10169. * by the information from basic abbort @dmabuf. It checks to see whether such
  10170. * partially assembled sequence held by the driver. If so, it shall free up all
  10171. * the frames from the partially assembled sequence.
  10172. *
  10173. * Return
  10174. * true -- if there is matching partially assembled sequence present and all
  10175. * the frames freed with the sequence;
  10176. * false -- if there is no matching partially assembled sequence present so
  10177. * nothing got aborted in the lower layer driver
  10178. **/
  10179. static bool
  10180. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10181. struct hbq_dmabuf *dmabuf)
  10182. {
  10183. struct fc_frame_header *new_hdr;
  10184. struct fc_frame_header *temp_hdr;
  10185. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10186. struct hbq_dmabuf *seq_dmabuf = NULL;
  10187. /* Use the hdr_buf to find the sequence that matches this frame */
  10188. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10189. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10190. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10191. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10192. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10193. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10194. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10195. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10196. continue;
  10197. /* found a pending sequence that matches this frame */
  10198. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10199. break;
  10200. }
  10201. /* Free up all the frames from the partially assembled sequence */
  10202. if (seq_dmabuf) {
  10203. list_for_each_entry_safe(d_buf, n_buf,
  10204. &seq_dmabuf->dbuf.list, list) {
  10205. list_del_init(&d_buf->list);
  10206. lpfc_in_buf_free(vport->phba, d_buf);
  10207. }
  10208. return true;
  10209. }
  10210. return false;
  10211. }
  10212. /**
  10213. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10214. * @phba: Pointer to HBA context object.
  10215. * @cmd_iocbq: pointer to the command iocbq structure.
  10216. * @rsp_iocbq: pointer to the response iocbq structure.
  10217. *
  10218. * This function handles the sequence abort accept iocb command complete
  10219. * event. It properly releases the memory allocated to the sequence abort
  10220. * accept iocb.
  10221. **/
  10222. static void
  10223. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10224. struct lpfc_iocbq *cmd_iocbq,
  10225. struct lpfc_iocbq *rsp_iocbq)
  10226. {
  10227. if (cmd_iocbq)
  10228. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10229. }
  10230. /**
  10231. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10232. * @phba: Pointer to HBA context object.
  10233. * @fc_hdr: pointer to a FC frame header.
  10234. *
  10235. * This function sends a basic accept to a previous unsol sequence abort
  10236. * event after aborting the sequence handling.
  10237. **/
  10238. static void
  10239. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10240. struct fc_frame_header *fc_hdr)
  10241. {
  10242. struct lpfc_iocbq *ctiocb = NULL;
  10243. struct lpfc_nodelist *ndlp;
  10244. uint16_t oxid, rxid;
  10245. uint32_t sid, fctl;
  10246. IOCB_t *icmd;
  10247. if (!lpfc_is_link_up(phba))
  10248. return;
  10249. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10250. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10251. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10252. ndlp = lpfc_findnode_did(phba->pport, sid);
  10253. if (!ndlp) {
  10254. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10255. "1268 Find ndlp returned NULL for oxid:x%x "
  10256. "SID:x%x\n", oxid, sid);
  10257. return;
  10258. }
  10259. /* Allocate buffer for acc iocb */
  10260. ctiocb = lpfc_sli_get_iocbq(phba);
  10261. if (!ctiocb)
  10262. return;
  10263. /* Extract the F_CTL field from FC_HDR */
  10264. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10265. icmd = &ctiocb->iocb;
  10266. icmd->un.xseq64.bdl.bdeSize = 0;
  10267. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10268. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10269. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10270. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10271. /* Fill in the rest of iocb fields */
  10272. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10273. icmd->ulpBdeCount = 0;
  10274. icmd->ulpLe = 1;
  10275. icmd->ulpClass = CLASS3;
  10276. icmd->ulpContext = ndlp->nlp_rpi;
  10277. ctiocb->iocb_cmpl = NULL;
  10278. ctiocb->vport = phba->pport;
  10279. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10280. if (fctl & FC_FC_EX_CTX) {
  10281. /* ABTS sent by responder to CT exchange, construction
  10282. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10283. * field and RX_ID from ABTS for RX_ID field.
  10284. */
  10285. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10286. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10287. ctiocb->sli4_xritag = oxid;
  10288. } else {
  10289. /* ABTS sent by initiator to CT exchange, construction
  10290. * of BA_ACC will need to allocate a new XRI as for the
  10291. * XRI_TAG and RX_ID fields.
  10292. */
  10293. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10294. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10295. ctiocb->sli4_xritag = NO_XRI;
  10296. }
  10297. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10298. /* Xmit CT abts accept on exchange <xid> */
  10299. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10300. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10301. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10302. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10303. }
  10304. /**
  10305. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10306. * @vport: Pointer to the vport on which this sequence was received
  10307. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10308. *
  10309. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10310. * receive sequence is only partially assembed by the driver, it shall abort
  10311. * the partially assembled frames for the sequence. Otherwise, if the
  10312. * unsolicited receive sequence has been completely assembled and passed to
  10313. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10314. * unsolicited sequence has been aborted. After that, it will issue a basic
  10315. * accept to accept the abort.
  10316. **/
  10317. void
  10318. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10319. struct hbq_dmabuf *dmabuf)
  10320. {
  10321. struct lpfc_hba *phba = vport->phba;
  10322. struct fc_frame_header fc_hdr;
  10323. uint32_t fctl;
  10324. bool abts_par;
  10325. /* Make a copy of fc_hdr before the dmabuf being released */
  10326. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10327. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10328. if (fctl & FC_FC_EX_CTX) {
  10329. /*
  10330. * ABTS sent by responder to exchange, just free the buffer
  10331. */
  10332. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10333. } else {
  10334. /*
  10335. * ABTS sent by initiator to exchange, need to do cleanup
  10336. */
  10337. /* Try to abort partially assembled seq */
  10338. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10339. /* Send abort to ULP if partially seq abort failed */
  10340. if (abts_par == false)
  10341. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10342. else
  10343. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10344. }
  10345. /* Send basic accept (BA_ACC) to the abort requester */
  10346. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10347. }
  10348. /**
  10349. * lpfc_seq_complete - Indicates if a sequence is complete
  10350. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10351. *
  10352. * This function checks the sequence, starting with the frame described by
  10353. * @dmabuf, to see if all the frames associated with this sequence are present.
  10354. * the frames associated with this sequence are linked to the @dmabuf using the
  10355. * dbuf list. This function looks for two major things. 1) That the first frame
  10356. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10357. * set. 3) That there are no holes in the sequence count. The function will
  10358. * return 1 when the sequence is complete, otherwise it will return 0.
  10359. **/
  10360. static int
  10361. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10362. {
  10363. struct fc_frame_header *hdr;
  10364. struct lpfc_dmabuf *d_buf;
  10365. struct hbq_dmabuf *seq_dmabuf;
  10366. uint32_t fctl;
  10367. int seq_count = 0;
  10368. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10369. /* make sure first fame of sequence has a sequence count of zero */
  10370. if (hdr->fh_seq_cnt != seq_count)
  10371. return 0;
  10372. fctl = (hdr->fh_f_ctl[0] << 16 |
  10373. hdr->fh_f_ctl[1] << 8 |
  10374. hdr->fh_f_ctl[2]);
  10375. /* If last frame of sequence we can return success. */
  10376. if (fctl & FC_FC_END_SEQ)
  10377. return 1;
  10378. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10379. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10380. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10381. /* If there is a hole in the sequence count then fail. */
  10382. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10383. return 0;
  10384. fctl = (hdr->fh_f_ctl[0] << 16 |
  10385. hdr->fh_f_ctl[1] << 8 |
  10386. hdr->fh_f_ctl[2]);
  10387. /* If last frame of sequence we can return success. */
  10388. if (fctl & FC_FC_END_SEQ)
  10389. return 1;
  10390. }
  10391. return 0;
  10392. }
  10393. /**
  10394. * lpfc_prep_seq - Prep sequence for ULP processing
  10395. * @vport: Pointer to the vport on which this sequence was received
  10396. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10397. *
  10398. * This function takes a sequence, described by a list of frames, and creates
  10399. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10400. * used to issue to the generic unsolicited sequence handler. This routine
  10401. * returns a pointer to the first iocbq in the list. If the function is unable
  10402. * to allocate an iocbq then it throw out the received frames that were not
  10403. * able to be described and return a pointer to the first iocbq. If unable to
  10404. * allocate any iocbqs (including the first) this function will return NULL.
  10405. **/
  10406. static struct lpfc_iocbq *
  10407. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10408. {
  10409. struct lpfc_dmabuf *d_buf, *n_buf;
  10410. struct lpfc_iocbq *first_iocbq, *iocbq;
  10411. struct fc_frame_header *fc_hdr;
  10412. uint32_t sid;
  10413. struct ulp_bde64 *pbde;
  10414. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10415. /* remove from receive buffer list */
  10416. list_del_init(&seq_dmabuf->hbuf.list);
  10417. lpfc_update_rcv_time_stamp(vport);
  10418. /* get the Remote Port's SID */
  10419. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10420. /* Get an iocbq struct to fill in. */
  10421. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10422. if (first_iocbq) {
  10423. /* Initialize the first IOCB. */
  10424. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10425. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10426. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10427. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10428. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10429. vport->vpi + vport->phba->vpi_base;
  10430. /* put the first buffer into the first IOCBq */
  10431. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10432. first_iocbq->context3 = NULL;
  10433. first_iocbq->iocb.ulpBdeCount = 1;
  10434. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10435. LPFC_DATA_BUF_SIZE;
  10436. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10437. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10438. bf_get(lpfc_rcqe_length,
  10439. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10440. }
  10441. iocbq = first_iocbq;
  10442. /*
  10443. * Each IOCBq can have two Buffers assigned, so go through the list
  10444. * of buffers for this sequence and save two buffers in each IOCBq
  10445. */
  10446. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10447. if (!iocbq) {
  10448. lpfc_in_buf_free(vport->phba, d_buf);
  10449. continue;
  10450. }
  10451. if (!iocbq->context3) {
  10452. iocbq->context3 = d_buf;
  10453. iocbq->iocb.ulpBdeCount++;
  10454. pbde = (struct ulp_bde64 *)
  10455. &iocbq->iocb.unsli3.sli3Words[4];
  10456. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10457. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10458. bf_get(lpfc_rcqe_length,
  10459. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10460. } else {
  10461. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10462. if (!iocbq) {
  10463. if (first_iocbq) {
  10464. first_iocbq->iocb.ulpStatus =
  10465. IOSTAT_FCP_RSP_ERROR;
  10466. first_iocbq->iocb.un.ulpWord[4] =
  10467. IOERR_NO_RESOURCES;
  10468. }
  10469. lpfc_in_buf_free(vport->phba, d_buf);
  10470. continue;
  10471. }
  10472. iocbq->context2 = d_buf;
  10473. iocbq->context3 = NULL;
  10474. iocbq->iocb.ulpBdeCount = 1;
  10475. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10476. LPFC_DATA_BUF_SIZE;
  10477. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10478. bf_get(lpfc_rcqe_length,
  10479. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10480. iocbq->iocb.un.rcvels.remoteID = sid;
  10481. list_add_tail(&iocbq->list, &first_iocbq->list);
  10482. }
  10483. }
  10484. return first_iocbq;
  10485. }
  10486. static void
  10487. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10488. struct hbq_dmabuf *seq_dmabuf)
  10489. {
  10490. struct fc_frame_header *fc_hdr;
  10491. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10492. struct lpfc_hba *phba = vport->phba;
  10493. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10494. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10495. if (!iocbq) {
  10496. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10497. "2707 Ring %d handler: Failed to allocate "
  10498. "iocb Rctl x%x Type x%x received\n",
  10499. LPFC_ELS_RING,
  10500. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10501. return;
  10502. }
  10503. if (!lpfc_complete_unsol_iocb(phba,
  10504. &phba->sli.ring[LPFC_ELS_RING],
  10505. iocbq, fc_hdr->fh_r_ctl,
  10506. fc_hdr->fh_type))
  10507. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10508. "2540 Ring %d handler: unexpected Rctl "
  10509. "x%x Type x%x received\n",
  10510. LPFC_ELS_RING,
  10511. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10512. /* Free iocb created in lpfc_prep_seq */
  10513. list_for_each_entry_safe(curr_iocb, next_iocb,
  10514. &iocbq->list, list) {
  10515. list_del_init(&curr_iocb->list);
  10516. lpfc_sli_release_iocbq(phba, curr_iocb);
  10517. }
  10518. lpfc_sli_release_iocbq(phba, iocbq);
  10519. }
  10520. /**
  10521. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10522. * @phba: Pointer to HBA context object.
  10523. *
  10524. * This function is called with no lock held. This function processes all
  10525. * the received buffers and gives it to upper layers when a received buffer
  10526. * indicates that it is the final frame in the sequence. The interrupt
  10527. * service routine processes received buffers at interrupt contexts and adds
  10528. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10529. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10530. * appropriate receive function when the final frame in a sequence is received.
  10531. **/
  10532. void
  10533. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10534. struct hbq_dmabuf *dmabuf)
  10535. {
  10536. struct hbq_dmabuf *seq_dmabuf;
  10537. struct fc_frame_header *fc_hdr;
  10538. struct lpfc_vport *vport;
  10539. uint32_t fcfi;
  10540. /* Process each received buffer */
  10541. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10542. /* check to see if this a valid type of frame */
  10543. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10544. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10545. return;
  10546. }
  10547. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10548. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10549. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10550. /* throw out the frame */
  10551. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10552. return;
  10553. }
  10554. /* Handle the basic abort sequence (BA_ABTS) event */
  10555. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10556. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10557. return;
  10558. }
  10559. /* Link this frame */
  10560. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10561. if (!seq_dmabuf) {
  10562. /* unable to add frame to vport - throw it out */
  10563. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10564. return;
  10565. }
  10566. /* If not last frame in sequence continue processing frames. */
  10567. if (!lpfc_seq_complete(seq_dmabuf))
  10568. return;
  10569. /* Send the complete sequence to the upper layer protocol */
  10570. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10571. }
  10572. /**
  10573. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10574. * @phba: pointer to lpfc hba data structure.
  10575. *
  10576. * This routine is invoked to post rpi header templates to the
  10577. * HBA consistent with the SLI-4 interface spec. This routine
  10578. * posts a PAGE_SIZE memory region to the port to hold up to
  10579. * PAGE_SIZE modulo 64 rpi context headers.
  10580. *
  10581. * This routine does not require any locks. It's usage is expected
  10582. * to be driver load or reset recovery when the driver is
  10583. * sequential.
  10584. *
  10585. * Return codes
  10586. * 0 - successful
  10587. * EIO - The mailbox failed to complete successfully.
  10588. * When this error occurs, the driver is not guaranteed
  10589. * to have any rpi regions posted to the device and
  10590. * must either attempt to repost the regions or take a
  10591. * fatal error.
  10592. **/
  10593. int
  10594. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10595. {
  10596. struct lpfc_rpi_hdr *rpi_page;
  10597. uint32_t rc = 0;
  10598. /* Post all rpi memory regions to the port. */
  10599. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10600. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10601. if (rc != MBX_SUCCESS) {
  10602. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10603. "2008 Error %d posting all rpi "
  10604. "headers\n", rc);
  10605. rc = -EIO;
  10606. break;
  10607. }
  10608. }
  10609. return rc;
  10610. }
  10611. /**
  10612. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10613. * @phba: pointer to lpfc hba data structure.
  10614. * @rpi_page: pointer to the rpi memory region.
  10615. *
  10616. * This routine is invoked to post a single rpi header to the
  10617. * HBA consistent with the SLI-4 interface spec. This memory region
  10618. * maps up to 64 rpi context regions.
  10619. *
  10620. * Return codes
  10621. * 0 - successful
  10622. * ENOMEM - No available memory
  10623. * EIO - The mailbox failed to complete successfully.
  10624. **/
  10625. int
  10626. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10627. {
  10628. LPFC_MBOXQ_t *mboxq;
  10629. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10630. uint32_t rc = 0;
  10631. uint32_t mbox_tmo;
  10632. uint32_t shdr_status, shdr_add_status;
  10633. union lpfc_sli4_cfg_shdr *shdr;
  10634. /* The port is notified of the header region via a mailbox command. */
  10635. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10636. if (!mboxq) {
  10637. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10638. "2001 Unable to allocate memory for issuing "
  10639. "SLI_CONFIG_SPECIAL mailbox command\n");
  10640. return -ENOMEM;
  10641. }
  10642. /* Post all rpi memory regions to the port. */
  10643. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10644. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10645. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10646. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10647. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10648. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10649. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10650. hdr_tmpl, rpi_page->page_count);
  10651. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10652. rpi_page->start_rpi);
  10653. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10654. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10655. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10656. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10657. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10658. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10659. if (rc != MBX_TIMEOUT)
  10660. mempool_free(mboxq, phba->mbox_mem_pool);
  10661. if (shdr_status || shdr_add_status || rc) {
  10662. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10663. "2514 POST_RPI_HDR mailbox failed with "
  10664. "status x%x add_status x%x, mbx status x%x\n",
  10665. shdr_status, shdr_add_status, rc);
  10666. rc = -ENXIO;
  10667. }
  10668. return rc;
  10669. }
  10670. /**
  10671. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10672. * @phba: pointer to lpfc hba data structure.
  10673. *
  10674. * This routine is invoked to post rpi header templates to the
  10675. * HBA consistent with the SLI-4 interface spec. This routine
  10676. * posts a PAGE_SIZE memory region to the port to hold up to
  10677. * PAGE_SIZE modulo 64 rpi context headers.
  10678. *
  10679. * Returns
  10680. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10681. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10682. **/
  10683. int
  10684. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10685. {
  10686. int rpi;
  10687. uint16_t max_rpi, rpi_base, rpi_limit;
  10688. uint16_t rpi_remaining;
  10689. struct lpfc_rpi_hdr *rpi_hdr;
  10690. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10691. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10692. rpi_limit = phba->sli4_hba.next_rpi;
  10693. /*
  10694. * The valid rpi range is not guaranteed to be zero-based. Start
  10695. * the search at the rpi_base as reported by the port.
  10696. */
  10697. spin_lock_irq(&phba->hbalock);
  10698. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10699. if (rpi >= rpi_limit || rpi < rpi_base)
  10700. rpi = LPFC_RPI_ALLOC_ERROR;
  10701. else {
  10702. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10703. phba->sli4_hba.max_cfg_param.rpi_used++;
  10704. phba->sli4_hba.rpi_count++;
  10705. }
  10706. /*
  10707. * Don't try to allocate more rpi header regions if the device limit
  10708. * on available rpis max has been exhausted.
  10709. */
  10710. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10711. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10712. spin_unlock_irq(&phba->hbalock);
  10713. return rpi;
  10714. }
  10715. /*
  10716. * If the driver is running low on rpi resources, allocate another
  10717. * page now. Note that the next_rpi value is used because
  10718. * it represents how many are actually in use whereas max_rpi notes
  10719. * how many are supported max by the device.
  10720. */
  10721. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10722. phba->sli4_hba.rpi_count;
  10723. spin_unlock_irq(&phba->hbalock);
  10724. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10725. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10726. if (!rpi_hdr) {
  10727. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10728. "2002 Error Could not grow rpi "
  10729. "count\n");
  10730. } else {
  10731. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10732. }
  10733. }
  10734. return rpi;
  10735. }
  10736. /**
  10737. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10738. * @phba: pointer to lpfc hba data structure.
  10739. *
  10740. * This routine is invoked to release an rpi to the pool of
  10741. * available rpis maintained by the driver.
  10742. **/
  10743. void
  10744. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10745. {
  10746. spin_lock_irq(&phba->hbalock);
  10747. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10748. phba->sli4_hba.rpi_count--;
  10749. phba->sli4_hba.max_cfg_param.rpi_used--;
  10750. spin_unlock_irq(&phba->hbalock);
  10751. }
  10752. /**
  10753. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10754. * @phba: pointer to lpfc hba data structure.
  10755. *
  10756. * This routine is invoked to remove the memory region that
  10757. * provided rpi via a bitmask.
  10758. **/
  10759. void
  10760. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10761. {
  10762. kfree(phba->sli4_hba.rpi_bmask);
  10763. }
  10764. /**
  10765. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10766. * @phba: pointer to lpfc hba data structure.
  10767. *
  10768. * This routine is invoked to remove the memory region that
  10769. * provided rpi via a bitmask.
  10770. **/
  10771. int
  10772. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10773. {
  10774. LPFC_MBOXQ_t *mboxq;
  10775. struct lpfc_hba *phba = ndlp->phba;
  10776. int rc;
  10777. /* The port is notified of the header region via a mailbox command. */
  10778. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10779. if (!mboxq)
  10780. return -ENOMEM;
  10781. /* Post all rpi memory regions to the port. */
  10782. lpfc_resume_rpi(mboxq, ndlp);
  10783. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10784. if (rc == MBX_NOT_FINISHED) {
  10785. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10786. "2010 Resume RPI Mailbox failed "
  10787. "status %d, mbxStatus x%x\n", rc,
  10788. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10789. mempool_free(mboxq, phba->mbox_mem_pool);
  10790. return -EIO;
  10791. }
  10792. return 0;
  10793. }
  10794. /**
  10795. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10796. * @phba: pointer to lpfc hba data structure.
  10797. * @vpi: vpi value to activate with the port.
  10798. *
  10799. * This routine is invoked to activate a vpi with the
  10800. * port when the host intends to use vports with a
  10801. * nonzero vpi.
  10802. *
  10803. * Returns:
  10804. * 0 success
  10805. * -Evalue otherwise
  10806. **/
  10807. int
  10808. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10809. {
  10810. LPFC_MBOXQ_t *mboxq;
  10811. int rc = 0;
  10812. int retval = MBX_SUCCESS;
  10813. uint32_t mbox_tmo;
  10814. if (vpi == 0)
  10815. return -EINVAL;
  10816. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10817. if (!mboxq)
  10818. return -ENOMEM;
  10819. lpfc_init_vpi(phba, mboxq, vpi);
  10820. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10821. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10822. if (rc != MBX_SUCCESS) {
  10823. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10824. "2022 INIT VPI Mailbox failed "
  10825. "status %d, mbxStatus x%x\n", rc,
  10826. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10827. retval = -EIO;
  10828. }
  10829. if (rc != MBX_TIMEOUT)
  10830. mempool_free(mboxq, phba->mbox_mem_pool);
  10831. return retval;
  10832. }
  10833. /**
  10834. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10835. * @phba: pointer to lpfc hba data structure.
  10836. * @mboxq: Pointer to mailbox object.
  10837. *
  10838. * This routine is invoked to manually add a single FCF record. The caller
  10839. * must pass a completely initialized FCF_Record. This routine takes
  10840. * care of the nonembedded mailbox operations.
  10841. **/
  10842. static void
  10843. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10844. {
  10845. void *virt_addr;
  10846. union lpfc_sli4_cfg_shdr *shdr;
  10847. uint32_t shdr_status, shdr_add_status;
  10848. virt_addr = mboxq->sge_array->addr[0];
  10849. /* The IOCTL status is embedded in the mailbox subheader. */
  10850. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10851. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10852. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10853. if ((shdr_status || shdr_add_status) &&
  10854. (shdr_status != STATUS_FCF_IN_USE))
  10855. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10856. "2558 ADD_FCF_RECORD mailbox failed with "
  10857. "status x%x add_status x%x\n",
  10858. shdr_status, shdr_add_status);
  10859. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10860. }
  10861. /**
  10862. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10863. * @phba: pointer to lpfc hba data structure.
  10864. * @fcf_record: pointer to the initialized fcf record to add.
  10865. *
  10866. * This routine is invoked to manually add a single FCF record. The caller
  10867. * must pass a completely initialized FCF_Record. This routine takes
  10868. * care of the nonembedded mailbox operations.
  10869. **/
  10870. int
  10871. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10872. {
  10873. int rc = 0;
  10874. LPFC_MBOXQ_t *mboxq;
  10875. uint8_t *bytep;
  10876. void *virt_addr;
  10877. dma_addr_t phys_addr;
  10878. struct lpfc_mbx_sge sge;
  10879. uint32_t alloc_len, req_len;
  10880. uint32_t fcfindex;
  10881. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10882. if (!mboxq) {
  10883. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10884. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10885. return -ENOMEM;
  10886. }
  10887. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10888. sizeof(uint32_t);
  10889. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10890. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10891. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10892. req_len, LPFC_SLI4_MBX_NEMBED);
  10893. if (alloc_len < req_len) {
  10894. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10895. "2523 Allocated DMA memory size (x%x) is "
  10896. "less than the requested DMA memory "
  10897. "size (x%x)\n", alloc_len, req_len);
  10898. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10899. return -ENOMEM;
  10900. }
  10901. /*
  10902. * Get the first SGE entry from the non-embedded DMA memory. This
  10903. * routine only uses a single SGE.
  10904. */
  10905. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10906. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10907. virt_addr = mboxq->sge_array->addr[0];
  10908. /*
  10909. * Configure the FCF record for FCFI 0. This is the driver's
  10910. * hardcoded default and gets used in nonFIP mode.
  10911. */
  10912. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10913. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10914. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10915. /*
  10916. * Copy the fcf_index and the FCF Record Data. The data starts after
  10917. * the FCoE header plus word10. The data copy needs to be endian
  10918. * correct.
  10919. */
  10920. bytep += sizeof(uint32_t);
  10921. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10922. mboxq->vport = phba->pport;
  10923. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10924. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10925. if (rc == MBX_NOT_FINISHED) {
  10926. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10927. "2515 ADD_FCF_RECORD mailbox failed with "
  10928. "status 0x%x\n", rc);
  10929. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10930. rc = -EIO;
  10931. } else
  10932. rc = 0;
  10933. return rc;
  10934. }
  10935. /**
  10936. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10937. * @phba: pointer to lpfc hba data structure.
  10938. * @fcf_record: pointer to the fcf record to write the default data.
  10939. * @fcf_index: FCF table entry index.
  10940. *
  10941. * This routine is invoked to build the driver's default FCF record. The
  10942. * values used are hardcoded. This routine handles memory initialization.
  10943. *
  10944. **/
  10945. void
  10946. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10947. struct fcf_record *fcf_record,
  10948. uint16_t fcf_index)
  10949. {
  10950. memset(fcf_record, 0, sizeof(struct fcf_record));
  10951. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10952. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10953. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10954. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10955. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10956. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10957. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10958. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10959. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10960. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10961. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10962. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10963. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10964. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  10965. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10966. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10967. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10968. /* Set the VLAN bit map */
  10969. if (phba->valid_vlan) {
  10970. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10971. = 1 << (phba->vlan_id % 8);
  10972. }
  10973. }
  10974. /**
  10975. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  10976. * @phba: pointer to lpfc hba data structure.
  10977. * @fcf_index: FCF table entry offset.
  10978. *
  10979. * This routine is invoked to scan the entire FCF table by reading FCF
  10980. * record and processing it one at a time starting from the @fcf_index
  10981. * for initial FCF discovery or fast FCF failover rediscovery.
  10982. *
  10983. * Return 0 if the mailbox command is submitted sucessfully, none 0
  10984. * otherwise.
  10985. **/
  10986. int
  10987. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  10988. {
  10989. int rc = 0, error;
  10990. LPFC_MBOXQ_t *mboxq;
  10991. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  10992. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10993. if (!mboxq) {
  10994. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10995. "2000 Failed to allocate mbox for "
  10996. "READ_FCF cmd\n");
  10997. error = -ENOMEM;
  10998. goto fail_fcf_scan;
  10999. }
  11000. /* Construct the read FCF record mailbox command */
  11001. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11002. if (rc) {
  11003. error = -EINVAL;
  11004. goto fail_fcf_scan;
  11005. }
  11006. /* Issue the mailbox command asynchronously */
  11007. mboxq->vport = phba->pport;
  11008. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11009. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11010. if (rc == MBX_NOT_FINISHED)
  11011. error = -EIO;
  11012. else {
  11013. spin_lock_irq(&phba->hbalock);
  11014. phba->hba_flag |= FCF_DISC_INPROGRESS;
  11015. spin_unlock_irq(&phba->hbalock);
  11016. /* Reset FCF round robin index bmask for new scan */
  11017. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) {
  11018. memset(phba->fcf.fcf_rr_bmask, 0,
  11019. sizeof(*phba->fcf.fcf_rr_bmask));
  11020. phba->fcf.eligible_fcf_cnt = 0;
  11021. }
  11022. error = 0;
  11023. }
  11024. fail_fcf_scan:
  11025. if (error) {
  11026. if (mboxq)
  11027. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11028. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  11029. spin_lock_irq(&phba->hbalock);
  11030. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  11031. spin_unlock_irq(&phba->hbalock);
  11032. }
  11033. return error;
  11034. }
  11035. /**
  11036. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf.
  11037. * @phba: pointer to lpfc hba data structure.
  11038. * @fcf_index: FCF table entry offset.
  11039. *
  11040. * This routine is invoked to read an FCF record indicated by @fcf_index
  11041. * and to use it for FLOGI round robin FCF failover.
  11042. *
  11043. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11044. * otherwise.
  11045. **/
  11046. int
  11047. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11048. {
  11049. int rc = 0, error;
  11050. LPFC_MBOXQ_t *mboxq;
  11051. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11052. if (!mboxq) {
  11053. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11054. "2763 Failed to allocate mbox for "
  11055. "READ_FCF cmd\n");
  11056. error = -ENOMEM;
  11057. goto fail_fcf_read;
  11058. }
  11059. /* Construct the read FCF record mailbox command */
  11060. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11061. if (rc) {
  11062. error = -EINVAL;
  11063. goto fail_fcf_read;
  11064. }
  11065. /* Issue the mailbox command asynchronously */
  11066. mboxq->vport = phba->pport;
  11067. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11068. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11069. if (rc == MBX_NOT_FINISHED)
  11070. error = -EIO;
  11071. else
  11072. error = 0;
  11073. fail_fcf_read:
  11074. if (error && mboxq)
  11075. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11076. return error;
  11077. }
  11078. /**
  11079. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11080. * @phba: pointer to lpfc hba data structure.
  11081. * @fcf_index: FCF table entry offset.
  11082. *
  11083. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11084. * determine whether it's eligible for FLOGI round robin failover list.
  11085. *
  11086. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11087. * otherwise.
  11088. **/
  11089. int
  11090. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11091. {
  11092. int rc = 0, error;
  11093. LPFC_MBOXQ_t *mboxq;
  11094. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11095. if (!mboxq) {
  11096. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11097. "2758 Failed to allocate mbox for "
  11098. "READ_FCF cmd\n");
  11099. error = -ENOMEM;
  11100. goto fail_fcf_read;
  11101. }
  11102. /* Construct the read FCF record mailbox command */
  11103. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11104. if (rc) {
  11105. error = -EINVAL;
  11106. goto fail_fcf_read;
  11107. }
  11108. /* Issue the mailbox command asynchronously */
  11109. mboxq->vport = phba->pport;
  11110. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11111. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11112. if (rc == MBX_NOT_FINISHED)
  11113. error = -EIO;
  11114. else
  11115. error = 0;
  11116. fail_fcf_read:
  11117. if (error && mboxq)
  11118. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11119. return error;
  11120. }
  11121. /**
  11122. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11123. * @phba: pointer to lpfc hba data structure.
  11124. *
  11125. * This routine is to get the next eligible FCF record index in a round
  11126. * robin fashion. If the next eligible FCF record index equals to the
  11127. * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11128. * shall be returned, otherwise, the next eligible FCF record's index
  11129. * shall be returned.
  11130. **/
  11131. uint16_t
  11132. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11133. {
  11134. uint16_t next_fcf_index;
  11135. /* Search from the currently registered FCF index */
  11136. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11137. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11138. phba->fcf.current_rec.fcf_indx);
  11139. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11140. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11141. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11142. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11143. /* Round robin failover stop condition */
  11144. if (next_fcf_index == phba->fcf.fcf_rr_init_indx)
  11145. return LPFC_FCOE_FCF_NEXT_NONE;
  11146. return next_fcf_index;
  11147. }
  11148. /**
  11149. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11150. * @phba: pointer to lpfc hba data structure.
  11151. *
  11152. * This routine sets the FCF record index in to the eligible bmask for
  11153. * round robin failover search. It checks to make sure that the index
  11154. * does not go beyond the range of the driver allocated bmask dimension
  11155. * before setting the bit.
  11156. *
  11157. * Returns 0 if the index bit successfully set, otherwise, it returns
  11158. * -EINVAL.
  11159. **/
  11160. int
  11161. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11162. {
  11163. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11164. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11165. "2610 HBA FCF index reached driver's "
  11166. "book keeping dimension: fcf_index:%d, "
  11167. "driver_bmask_max:%d\n",
  11168. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11169. return -EINVAL;
  11170. }
  11171. /* Set the eligible FCF record index bmask */
  11172. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11173. return 0;
  11174. }
  11175. /**
  11176. * lpfc_sli4_fcf_rr_index_set - Clear bmask from eligible fcf record index
  11177. * @phba: pointer to lpfc hba data structure.
  11178. *
  11179. * This routine clears the FCF record index from the eligible bmask for
  11180. * round robin failover search. It checks to make sure that the index
  11181. * does not go beyond the range of the driver allocated bmask dimension
  11182. * before clearing the bit.
  11183. **/
  11184. void
  11185. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11186. {
  11187. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11188. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11189. "2762 HBA FCF index goes beyond driver's "
  11190. "book keeping dimension: fcf_index:%d, "
  11191. "driver_bmask_max:%d\n",
  11192. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11193. return;
  11194. }
  11195. /* Clear the eligible FCF record index bmask */
  11196. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11197. }
  11198. /**
  11199. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11200. * @phba: pointer to lpfc hba data structure.
  11201. *
  11202. * This routine is the completion routine for the rediscover FCF table mailbox
  11203. * command. If the mailbox command returned failure, it will try to stop the
  11204. * FCF rediscover wait timer.
  11205. **/
  11206. void
  11207. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11208. {
  11209. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11210. uint32_t shdr_status, shdr_add_status;
  11211. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11212. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11213. &redisc_fcf->header.cfg_shdr.response);
  11214. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11215. &redisc_fcf->header.cfg_shdr.response);
  11216. if (shdr_status || shdr_add_status) {
  11217. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11218. "2746 Requesting for FCF rediscovery failed "
  11219. "status x%x add_status x%x\n",
  11220. shdr_status, shdr_add_status);
  11221. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11222. spin_lock_irq(&phba->hbalock);
  11223. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11224. spin_unlock_irq(&phba->hbalock);
  11225. /*
  11226. * CVL event triggered FCF rediscover request failed,
  11227. * last resort to re-try current registered FCF entry.
  11228. */
  11229. lpfc_retry_pport_discovery(phba);
  11230. } else {
  11231. spin_lock_irq(&phba->hbalock);
  11232. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11233. spin_unlock_irq(&phba->hbalock);
  11234. /*
  11235. * DEAD FCF event triggered FCF rediscover request
  11236. * failed, last resort to fail over as a link down
  11237. * to FCF registration.
  11238. */
  11239. lpfc_sli4_fcf_dead_failthrough(phba);
  11240. }
  11241. } else {
  11242. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11243. "2775 Start FCF rediscovery quiescent period "
  11244. "wait timer before scaning FCF table\n");
  11245. /*
  11246. * Start FCF rediscovery wait timer for pending FCF
  11247. * before rescan FCF record table.
  11248. */
  11249. lpfc_fcf_redisc_wait_start_timer(phba);
  11250. }
  11251. mempool_free(mbox, phba->mbox_mem_pool);
  11252. }
  11253. /**
  11254. * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
  11255. * @phba: pointer to lpfc hba data structure.
  11256. *
  11257. * This routine is invoked to request for rediscovery of the entire FCF table
  11258. * by the port.
  11259. **/
  11260. int
  11261. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11262. {
  11263. LPFC_MBOXQ_t *mbox;
  11264. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11265. int rc, length;
  11266. /* Cancel retry delay timers to all vports before FCF rediscover */
  11267. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11268. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11269. if (!mbox) {
  11270. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11271. "2745 Failed to allocate mbox for "
  11272. "requesting FCF rediscover.\n");
  11273. return -ENOMEM;
  11274. }
  11275. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11276. sizeof(struct lpfc_sli4_cfg_mhdr));
  11277. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11278. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11279. length, LPFC_SLI4_MBX_EMBED);
  11280. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11281. /* Set count to 0 for invalidating the entire FCF database */
  11282. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11283. /* Issue the mailbox command asynchronously */
  11284. mbox->vport = phba->pport;
  11285. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11286. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11287. if (rc == MBX_NOT_FINISHED) {
  11288. mempool_free(mbox, phba->mbox_mem_pool);
  11289. return -EIO;
  11290. }
  11291. return 0;
  11292. }
  11293. /**
  11294. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  11295. * @phba: pointer to lpfc hba data structure.
  11296. *
  11297. * This function is the failover routine as a last resort to the FCF DEAD
  11298. * event when driver failed to perform fast FCF failover.
  11299. **/
  11300. void
  11301. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  11302. {
  11303. uint32_t link_state;
  11304. /*
  11305. * Last resort as FCF DEAD event failover will treat this as
  11306. * a link down, but save the link state because we don't want
  11307. * it to be changed to Link Down unless it is already down.
  11308. */
  11309. link_state = phba->link_state;
  11310. lpfc_linkdown(phba);
  11311. phba->link_state = link_state;
  11312. /* Unregister FCF if no devices connected to it */
  11313. lpfc_unregister_unused_fcf(phba);
  11314. }
  11315. /**
  11316. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11317. * @phba: pointer to lpfc hba data structure.
  11318. *
  11319. * This function read region 23 and parse TLV for port status to
  11320. * decide if the user disaled the port. If the TLV indicates the
  11321. * port is disabled, the hba_flag is set accordingly.
  11322. **/
  11323. void
  11324. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11325. {
  11326. LPFC_MBOXQ_t *pmb = NULL;
  11327. MAILBOX_t *mb;
  11328. uint8_t *rgn23_data = NULL;
  11329. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11330. int rc;
  11331. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11332. if (!pmb) {
  11333. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11334. "2600 lpfc_sli_read_serdes_param failed to"
  11335. " allocate mailbox memory\n");
  11336. goto out;
  11337. }
  11338. mb = &pmb->u.mb;
  11339. /* Get adapter Region 23 data */
  11340. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11341. if (!rgn23_data)
  11342. goto out;
  11343. do {
  11344. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11345. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11346. if (rc != MBX_SUCCESS) {
  11347. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11348. "2601 lpfc_sli_read_link_ste failed to"
  11349. " read config region 23 rc 0x%x Status 0x%x\n",
  11350. rc, mb->mbxStatus);
  11351. mb->un.varDmp.word_cnt = 0;
  11352. }
  11353. /*
  11354. * dump mem may return a zero when finished or we got a
  11355. * mailbox error, either way we are done.
  11356. */
  11357. if (mb->un.varDmp.word_cnt == 0)
  11358. break;
  11359. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11360. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11361. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11362. rgn23_data + offset,
  11363. mb->un.varDmp.word_cnt);
  11364. offset += mb->un.varDmp.word_cnt;
  11365. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11366. data_size = offset;
  11367. offset = 0;
  11368. if (!data_size)
  11369. goto out;
  11370. /* Check the region signature first */
  11371. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11372. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11373. "2619 Config region 23 has bad signature\n");
  11374. goto out;
  11375. }
  11376. offset += 4;
  11377. /* Check the data structure version */
  11378. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11379. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11380. "2620 Config region 23 has bad version\n");
  11381. goto out;
  11382. }
  11383. offset += 4;
  11384. /* Parse TLV entries in the region */
  11385. while (offset < data_size) {
  11386. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11387. break;
  11388. /*
  11389. * If the TLV is not driver specific TLV or driver id is
  11390. * not linux driver id, skip the record.
  11391. */
  11392. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11393. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11394. (rgn23_data[offset + 3] != 0)) {
  11395. offset += rgn23_data[offset + 1] * 4 + 4;
  11396. continue;
  11397. }
  11398. /* Driver found a driver specific TLV in the config region */
  11399. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11400. offset += 4;
  11401. tlv_offset = 0;
  11402. /*
  11403. * Search for configured port state sub-TLV.
  11404. */
  11405. while ((offset < data_size) &&
  11406. (tlv_offset < sub_tlv_len)) {
  11407. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11408. offset += 4;
  11409. tlv_offset += 4;
  11410. break;
  11411. }
  11412. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11413. offset += rgn23_data[offset + 1] * 4 + 4;
  11414. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11415. continue;
  11416. }
  11417. /* This HBA contains PORT_STE configured */
  11418. if (!rgn23_data[offset + 2])
  11419. phba->hba_flag |= LINK_DISABLED;
  11420. goto out;
  11421. }
  11422. }
  11423. out:
  11424. if (pmb)
  11425. mempool_free(pmb, phba->mbox_mem_pool);
  11426. kfree(rgn23_data);
  11427. return;
  11428. }
  11429. /**
  11430. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11431. * @vport: pointer to vport data structure.
  11432. *
  11433. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11434. * and REG_VPI mailbox commands associated with the vport. This function
  11435. * is called when driver want to restart discovery of the vport due to
  11436. * a Clear Virtual Link event.
  11437. **/
  11438. void
  11439. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11440. {
  11441. struct lpfc_hba *phba = vport->phba;
  11442. LPFC_MBOXQ_t *mb, *nextmb;
  11443. struct lpfc_dmabuf *mp;
  11444. spin_lock_irq(&phba->hbalock);
  11445. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11446. if (mb->vport != vport)
  11447. continue;
  11448. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11449. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11450. continue;
  11451. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11452. mp = (struct lpfc_dmabuf *) (mb->context1);
  11453. if (mp) {
  11454. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11455. kfree(mp);
  11456. }
  11457. }
  11458. list_del(&mb->list);
  11459. mempool_free(mb, phba->mbox_mem_pool);
  11460. }
  11461. mb = phba->sli.mbox_active;
  11462. if (mb && (mb->vport == vport)) {
  11463. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11464. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11465. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11466. }
  11467. spin_unlock_irq(&phba->hbalock);
  11468. }