lpfc_sli.c 369 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_cmnd.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include <scsi/fc/fc_fs.h>
  31. #include <linux/aer.h>
  32. #include "lpfc_hw4.h"
  33. #include "lpfc_hw.h"
  34. #include "lpfc_sli.h"
  35. #include "lpfc_sli4.h"
  36. #include "lpfc_nl.h"
  37. #include "lpfc_disc.h"
  38. #include "lpfc_scsi.h"
  39. #include "lpfc.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_logmsg.h"
  42. #include "lpfc_compat.h"
  43. #include "lpfc_debugfs.h"
  44. #include "lpfc_vport.h"
  45. /* There are only four IOCB completion types. */
  46. typedef enum _lpfc_iocb_type {
  47. LPFC_UNKNOWN_IOCB,
  48. LPFC_UNSOL_IOCB,
  49. LPFC_SOL_IOCB,
  50. LPFC_ABORT_IOCB
  51. } lpfc_iocb_type;
  52. /* Provide function prototypes local to this module. */
  53. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  54. uint32_t);
  55. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  56. uint8_t *, uint32_t *);
  57. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  58. struct lpfc_iocbq *);
  59. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  60. struct hbq_dmabuf *);
  61. static IOCB_t *
  62. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  63. {
  64. return &iocbq->iocb;
  65. }
  66. /**
  67. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  68. * @q: The Work Queue to operate on.
  69. * @wqe: The work Queue Entry to put on the Work queue.
  70. *
  71. * This routine will copy the contents of @wqe to the next available entry on
  72. * the @q. This function will then ring the Work Queue Doorbell to signal the
  73. * HBA to start processing the Work Queue Entry. This function returns 0 if
  74. * successful. If no entries are available on @q then this function will return
  75. * -ENOMEM.
  76. * The caller is expected to hold the hbalock when calling this routine.
  77. **/
  78. static uint32_t
  79. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  80. {
  81. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  82. struct lpfc_register doorbell;
  83. uint32_t host_index;
  84. /* If the host has not yet processed the next entry then we are done */
  85. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  86. return -ENOMEM;
  87. /* set consumption flag every once in a while */
  88. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  89. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  90. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  91. /* Update the host index before invoking device */
  92. host_index = q->host_index;
  93. q->host_index = ((q->host_index + 1) % q->entry_count);
  94. /* Ring Doorbell */
  95. doorbell.word0 = 0;
  96. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  97. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  98. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  99. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  100. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  101. return 0;
  102. }
  103. /**
  104. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  105. * @q: The Work Queue to operate on.
  106. * @index: The index to advance the hba index to.
  107. *
  108. * This routine will update the HBA index of a queue to reflect consumption of
  109. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  110. * an entry the host calls this function to update the queue's internal
  111. * pointers. This routine returns the number of entries that were consumed by
  112. * the HBA.
  113. **/
  114. static uint32_t
  115. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  116. {
  117. uint32_t released = 0;
  118. if (q->hba_index == index)
  119. return 0;
  120. do {
  121. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  122. released++;
  123. } while (q->hba_index != index);
  124. return released;
  125. }
  126. /**
  127. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  128. * @q: The Mailbox Queue to operate on.
  129. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  130. *
  131. * This routine will copy the contents of @mqe to the next available entry on
  132. * the @q. This function will then ring the Work Queue Doorbell to signal the
  133. * HBA to start processing the Work Queue Entry. This function returns 0 if
  134. * successful. If no entries are available on @q then this function will return
  135. * -ENOMEM.
  136. * The caller is expected to hold the hbalock when calling this routine.
  137. **/
  138. static uint32_t
  139. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  140. {
  141. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  142. struct lpfc_register doorbell;
  143. uint32_t host_index;
  144. /* If the host has not yet processed the next entry then we are done */
  145. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  146. return -ENOMEM;
  147. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  148. /* Save off the mailbox pointer for completion */
  149. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  150. /* Update the host index before invoking device */
  151. host_index = q->host_index;
  152. q->host_index = ((q->host_index + 1) % q->entry_count);
  153. /* Ring Doorbell */
  154. doorbell.word0 = 0;
  155. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  156. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  157. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  158. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  159. return 0;
  160. }
  161. /**
  162. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  163. * @q: The Mailbox Queue to operate on.
  164. *
  165. * This routine will update the HBA index of a queue to reflect consumption of
  166. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  167. * an entry the host calls this function to update the queue's internal
  168. * pointers. This routine returns the number of entries that were consumed by
  169. * the HBA.
  170. **/
  171. static uint32_t
  172. lpfc_sli4_mq_release(struct lpfc_queue *q)
  173. {
  174. /* Clear the mailbox pointer for completion */
  175. q->phba->mbox = NULL;
  176. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  177. return 1;
  178. }
  179. /**
  180. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  181. * @q: The Event Queue to get the first valid EQE from
  182. *
  183. * This routine will get the first valid Event Queue Entry from @q, update
  184. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  185. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  186. * processed, but not popped back to the HBA then this routine will return NULL.
  187. **/
  188. static struct lpfc_eqe *
  189. lpfc_sli4_eq_get(struct lpfc_queue *q)
  190. {
  191. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  192. /* If the next EQE is not valid then we are done */
  193. if (!bf_get(lpfc_eqe_valid, eqe))
  194. return NULL;
  195. /* If the host has not yet processed the next entry then we are done */
  196. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  197. return NULL;
  198. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  199. return eqe;
  200. }
  201. /**
  202. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  203. * @q: The Event Queue that the host has completed processing for.
  204. * @arm: Indicates whether the host wants to arms this CQ.
  205. *
  206. * This routine will mark all Event Queue Entries on @q, from the last
  207. * known completed entry to the last entry that was processed, as completed
  208. * by clearing the valid bit for each completion queue entry. Then it will
  209. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  210. * The internal host index in the @q will be updated by this routine to indicate
  211. * that the host has finished processing the entries. The @arm parameter
  212. * indicates that the queue should be rearmed when ringing the doorbell.
  213. *
  214. * This function will return the number of EQEs that were popped.
  215. **/
  216. uint32_t
  217. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  218. {
  219. uint32_t released = 0;
  220. struct lpfc_eqe *temp_eqe;
  221. struct lpfc_register doorbell;
  222. /* while there are valid entries */
  223. while (q->hba_index != q->host_index) {
  224. temp_eqe = q->qe[q->host_index].eqe;
  225. bf_set(lpfc_eqe_valid, temp_eqe, 0);
  226. released++;
  227. q->host_index = ((q->host_index + 1) % q->entry_count);
  228. }
  229. if (unlikely(released == 0 && !arm))
  230. return 0;
  231. /* ring doorbell for number popped */
  232. doorbell.word0 = 0;
  233. if (arm) {
  234. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  235. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  236. }
  237. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  238. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  239. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  240. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  241. return released;
  242. }
  243. /**
  244. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  245. * @q: The Completion Queue to get the first valid CQE from
  246. *
  247. * This routine will get the first valid Completion Queue Entry from @q, update
  248. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  249. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  250. * processed, but not popped back to the HBA then this routine will return NULL.
  251. **/
  252. static struct lpfc_cqe *
  253. lpfc_sli4_cq_get(struct lpfc_queue *q)
  254. {
  255. struct lpfc_cqe *cqe;
  256. /* If the next CQE is not valid then we are done */
  257. if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  258. return NULL;
  259. /* If the host has not yet processed the next entry then we are done */
  260. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  261. return NULL;
  262. cqe = q->qe[q->hba_index].cqe;
  263. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  264. return cqe;
  265. }
  266. /**
  267. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  268. * @q: The Completion Queue that the host has completed processing for.
  269. * @arm: Indicates whether the host wants to arms this CQ.
  270. *
  271. * This routine will mark all Completion queue entries on @q, from the last
  272. * known completed entry to the last entry that was processed, as completed
  273. * by clearing the valid bit for each completion queue entry. Then it will
  274. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  275. * The internal host index in the @q will be updated by this routine to indicate
  276. * that the host has finished processing the entries. The @arm parameter
  277. * indicates that the queue should be rearmed when ringing the doorbell.
  278. *
  279. * This function will return the number of CQEs that were released.
  280. **/
  281. uint32_t
  282. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  283. {
  284. uint32_t released = 0;
  285. struct lpfc_cqe *temp_qe;
  286. struct lpfc_register doorbell;
  287. /* while there are valid entries */
  288. while (q->hba_index != q->host_index) {
  289. temp_qe = q->qe[q->host_index].cqe;
  290. bf_set(lpfc_cqe_valid, temp_qe, 0);
  291. released++;
  292. q->host_index = ((q->host_index + 1) % q->entry_count);
  293. }
  294. if (unlikely(released == 0 && !arm))
  295. return 0;
  296. /* ring doorbell for number popped */
  297. doorbell.word0 = 0;
  298. if (arm)
  299. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  300. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  301. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  302. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  303. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  304. return released;
  305. }
  306. /**
  307. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  308. * @q: The Header Receive Queue to operate on.
  309. * @wqe: The Receive Queue Entry to put on the Receive queue.
  310. *
  311. * This routine will copy the contents of @wqe to the next available entry on
  312. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  313. * HBA to start processing the Receive Queue Entry. This function returns the
  314. * index that the rqe was copied to if successful. If no entries are available
  315. * on @q then this function will return -ENOMEM.
  316. * The caller is expected to hold the hbalock when calling this routine.
  317. **/
  318. static int
  319. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  320. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  321. {
  322. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  323. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  324. struct lpfc_register doorbell;
  325. int put_index = hq->host_index;
  326. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  327. return -EINVAL;
  328. if (hq->host_index != dq->host_index)
  329. return -EINVAL;
  330. /* If the host has not yet processed the next entry then we are done */
  331. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  332. return -EBUSY;
  333. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  334. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  335. /* Update the host index to point to the next slot */
  336. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  337. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  338. /* Ring The Header Receive Queue Doorbell */
  339. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  340. doorbell.word0 = 0;
  341. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  342. LPFC_RQ_POST_BATCH);
  343. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  344. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  345. }
  346. return put_index;
  347. }
  348. /**
  349. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  350. * @q: The Header Receive Queue to operate on.
  351. *
  352. * This routine will update the HBA index of a queue to reflect consumption of
  353. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  354. * consumed an entry the host calls this function to update the queue's
  355. * internal pointers. This routine returns the number of entries that were
  356. * consumed by the HBA.
  357. **/
  358. static uint32_t
  359. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  360. {
  361. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  362. return 0;
  363. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  364. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  365. return 1;
  366. }
  367. /**
  368. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  369. * @phba: Pointer to HBA context object.
  370. * @pring: Pointer to driver SLI ring object.
  371. *
  372. * This function returns pointer to next command iocb entry
  373. * in the command ring. The caller must hold hbalock to prevent
  374. * other threads consume the next command iocb.
  375. * SLI-2/SLI-3 provide different sized iocbs.
  376. **/
  377. static inline IOCB_t *
  378. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  379. {
  380. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  381. pring->cmdidx * phba->iocb_cmd_size);
  382. }
  383. /**
  384. * lpfc_resp_iocb - Get next response iocb entry in the ring
  385. * @phba: Pointer to HBA context object.
  386. * @pring: Pointer to driver SLI ring object.
  387. *
  388. * This function returns pointer to next response iocb entry
  389. * in the response ring. The caller must hold hbalock to make sure
  390. * that no other thread consume the next response iocb.
  391. * SLI-2/SLI-3 provide different sized iocbs.
  392. **/
  393. static inline IOCB_t *
  394. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  395. {
  396. return (IOCB_t *) (((char *) pring->rspringaddr) +
  397. pring->rspidx * phba->iocb_rsp_size);
  398. }
  399. /**
  400. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  401. * @phba: Pointer to HBA context object.
  402. *
  403. * This function is called with hbalock held. This function
  404. * allocates a new driver iocb object from the iocb pool. If the
  405. * allocation is successful, it returns pointer to the newly
  406. * allocated iocb object else it returns NULL.
  407. **/
  408. static struct lpfc_iocbq *
  409. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  410. {
  411. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  412. struct lpfc_iocbq * iocbq = NULL;
  413. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  414. return iocbq;
  415. }
  416. /**
  417. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  418. * @phba: Pointer to HBA context object.
  419. * @xritag: XRI value.
  420. *
  421. * This function clears the sglq pointer from the array of acive
  422. * sglq's. The xritag that is passed in is used to index into the
  423. * array. Before the xritag can be used it needs to be adjusted
  424. * by subtracting the xribase.
  425. *
  426. * Returns sglq ponter = success, NULL = Failure.
  427. **/
  428. static struct lpfc_sglq *
  429. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  430. {
  431. uint16_t adj_xri;
  432. struct lpfc_sglq *sglq;
  433. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  434. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  435. return NULL;
  436. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  437. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  438. return sglq;
  439. }
  440. /**
  441. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  442. * @phba: Pointer to HBA context object.
  443. * @xritag: XRI value.
  444. *
  445. * This function returns the sglq pointer from the array of acive
  446. * sglq's. The xritag that is passed in is used to index into the
  447. * array. Before the xritag can be used it needs to be adjusted
  448. * by subtracting the xribase.
  449. *
  450. * Returns sglq ponter = success, NULL = Failure.
  451. **/
  452. static struct lpfc_sglq *
  453. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  454. {
  455. uint16_t adj_xri;
  456. struct lpfc_sglq *sglq;
  457. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  458. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  459. return NULL;
  460. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  461. return sglq;
  462. }
  463. /**
  464. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  465. * @phba: Pointer to HBA context object.
  466. *
  467. * This function is called with hbalock held. This function
  468. * Gets a new driver sglq object from the sglq list. If the
  469. * list is not empty then it is successful, it returns pointer to the newly
  470. * allocated sglq object else it returns NULL.
  471. **/
  472. static struct lpfc_sglq *
  473. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  474. {
  475. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  476. struct lpfc_sglq *sglq = NULL;
  477. uint16_t adj_xri;
  478. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  479. if (!sglq)
  480. return NULL;
  481. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  482. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  483. return sglq;
  484. }
  485. /**
  486. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  487. * @phba: Pointer to HBA context object.
  488. *
  489. * This function is called with no lock held. This function
  490. * allocates a new driver iocb object from the iocb pool. If the
  491. * allocation is successful, it returns pointer to the newly
  492. * allocated iocb object else it returns NULL.
  493. **/
  494. struct lpfc_iocbq *
  495. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  496. {
  497. struct lpfc_iocbq * iocbq = NULL;
  498. unsigned long iflags;
  499. spin_lock_irqsave(&phba->hbalock, iflags);
  500. iocbq = __lpfc_sli_get_iocbq(phba);
  501. spin_unlock_irqrestore(&phba->hbalock, iflags);
  502. return iocbq;
  503. }
  504. /**
  505. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  506. * @phba: Pointer to HBA context object.
  507. * @iocbq: Pointer to driver iocb object.
  508. *
  509. * This function is called with hbalock held to release driver
  510. * iocb object to the iocb pool. The iotag in the iocb object
  511. * does not change for each use of the iocb object. This function
  512. * clears all other fields of the iocb object when it is freed.
  513. * The sqlq structure that holds the xritag and phys and virtual
  514. * mappings for the scatter gather list is retrieved from the
  515. * active array of sglq. The get of the sglq pointer also clears
  516. * the entry in the array. If the status of the IO indiactes that
  517. * this IO was aborted then the sglq entry it put on the
  518. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  519. * IO has good status or fails for any other reason then the sglq
  520. * entry is added to the free list (lpfc_sgl_list).
  521. **/
  522. static void
  523. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  524. {
  525. struct lpfc_sglq *sglq;
  526. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  527. unsigned long iflag;
  528. if (iocbq->sli4_xritag == NO_XRI)
  529. sglq = NULL;
  530. else
  531. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  532. if (sglq) {
  533. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED
  534. && ((iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  535. && (iocbq->iocb.un.ulpWord[4]
  536. == IOERR_ABORT_REQUESTED))) {
  537. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  538. iflag);
  539. list_add(&sglq->list,
  540. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  541. spin_unlock_irqrestore(
  542. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  543. } else
  544. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  545. }
  546. /*
  547. * Clean all volatile data fields, preserve iotag and node struct.
  548. */
  549. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  550. iocbq->sli4_xritag = NO_XRI;
  551. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  552. }
  553. /**
  554. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  555. * @phba: Pointer to HBA context object.
  556. * @iocbq: Pointer to driver iocb object.
  557. *
  558. * This function is called with hbalock held to release driver
  559. * iocb object to the iocb pool. The iotag in the iocb object
  560. * does not change for each use of the iocb object. This function
  561. * clears all other fields of the iocb object when it is freed.
  562. **/
  563. static void
  564. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  565. {
  566. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  567. /*
  568. * Clean all volatile data fields, preserve iotag and node struct.
  569. */
  570. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  571. iocbq->sli4_xritag = NO_XRI;
  572. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  573. }
  574. /**
  575. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  576. * @phba: Pointer to HBA context object.
  577. * @iocbq: Pointer to driver iocb object.
  578. *
  579. * This function is called with hbalock held to release driver
  580. * iocb object to the iocb pool. The iotag in the iocb object
  581. * does not change for each use of the iocb object. This function
  582. * clears all other fields of the iocb object when it is freed.
  583. **/
  584. static void
  585. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  586. {
  587. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  588. }
  589. /**
  590. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  591. * @phba: Pointer to HBA context object.
  592. * @iocbq: Pointer to driver iocb object.
  593. *
  594. * This function is called with no lock held to release the iocb to
  595. * iocb pool.
  596. **/
  597. void
  598. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  599. {
  600. unsigned long iflags;
  601. /*
  602. * Clean all volatile data fields, preserve iotag and node struct.
  603. */
  604. spin_lock_irqsave(&phba->hbalock, iflags);
  605. __lpfc_sli_release_iocbq(phba, iocbq);
  606. spin_unlock_irqrestore(&phba->hbalock, iflags);
  607. }
  608. /**
  609. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  610. * @phba: Pointer to HBA context object.
  611. * @iocblist: List of IOCBs.
  612. * @ulpstatus: ULP status in IOCB command field.
  613. * @ulpWord4: ULP word-4 in IOCB command field.
  614. *
  615. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  616. * on the list by invoking the complete callback function associated with the
  617. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  618. * fields.
  619. **/
  620. void
  621. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  622. uint32_t ulpstatus, uint32_t ulpWord4)
  623. {
  624. struct lpfc_iocbq *piocb;
  625. while (!list_empty(iocblist)) {
  626. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  627. if (!piocb->iocb_cmpl)
  628. lpfc_sli_release_iocbq(phba, piocb);
  629. else {
  630. piocb->iocb.ulpStatus = ulpstatus;
  631. piocb->iocb.un.ulpWord[4] = ulpWord4;
  632. (piocb->iocb_cmpl) (phba, piocb, piocb);
  633. }
  634. }
  635. return;
  636. }
  637. /**
  638. * lpfc_sli_iocb_cmd_type - Get the iocb type
  639. * @iocb_cmnd: iocb command code.
  640. *
  641. * This function is called by ring event handler function to get the iocb type.
  642. * This function translates the iocb command to an iocb command type used to
  643. * decide the final disposition of each completed IOCB.
  644. * The function returns
  645. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  646. * LPFC_SOL_IOCB if it is a solicited iocb completion
  647. * LPFC_ABORT_IOCB if it is an abort iocb
  648. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  649. *
  650. * The caller is not required to hold any lock.
  651. **/
  652. static lpfc_iocb_type
  653. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  654. {
  655. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  656. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  657. return 0;
  658. switch (iocb_cmnd) {
  659. case CMD_XMIT_SEQUENCE_CR:
  660. case CMD_XMIT_SEQUENCE_CX:
  661. case CMD_XMIT_BCAST_CN:
  662. case CMD_XMIT_BCAST_CX:
  663. case CMD_ELS_REQUEST_CR:
  664. case CMD_ELS_REQUEST_CX:
  665. case CMD_CREATE_XRI_CR:
  666. case CMD_CREATE_XRI_CX:
  667. case CMD_GET_RPI_CN:
  668. case CMD_XMIT_ELS_RSP_CX:
  669. case CMD_GET_RPI_CR:
  670. case CMD_FCP_IWRITE_CR:
  671. case CMD_FCP_IWRITE_CX:
  672. case CMD_FCP_IREAD_CR:
  673. case CMD_FCP_IREAD_CX:
  674. case CMD_FCP_ICMND_CR:
  675. case CMD_FCP_ICMND_CX:
  676. case CMD_FCP_TSEND_CX:
  677. case CMD_FCP_TRSP_CX:
  678. case CMD_FCP_TRECEIVE_CX:
  679. case CMD_FCP_AUTO_TRSP_CX:
  680. case CMD_ADAPTER_MSG:
  681. case CMD_ADAPTER_DUMP:
  682. case CMD_XMIT_SEQUENCE64_CR:
  683. case CMD_XMIT_SEQUENCE64_CX:
  684. case CMD_XMIT_BCAST64_CN:
  685. case CMD_XMIT_BCAST64_CX:
  686. case CMD_ELS_REQUEST64_CR:
  687. case CMD_ELS_REQUEST64_CX:
  688. case CMD_FCP_IWRITE64_CR:
  689. case CMD_FCP_IWRITE64_CX:
  690. case CMD_FCP_IREAD64_CR:
  691. case CMD_FCP_IREAD64_CX:
  692. case CMD_FCP_ICMND64_CR:
  693. case CMD_FCP_ICMND64_CX:
  694. case CMD_FCP_TSEND64_CX:
  695. case CMD_FCP_TRSP64_CX:
  696. case CMD_FCP_TRECEIVE64_CX:
  697. case CMD_GEN_REQUEST64_CR:
  698. case CMD_GEN_REQUEST64_CX:
  699. case CMD_XMIT_ELS_RSP64_CX:
  700. case DSSCMD_IWRITE64_CR:
  701. case DSSCMD_IWRITE64_CX:
  702. case DSSCMD_IREAD64_CR:
  703. case DSSCMD_IREAD64_CX:
  704. case DSSCMD_INVALIDATE_DEK:
  705. case DSSCMD_SET_KEK:
  706. case DSSCMD_GET_KEK_ID:
  707. case DSSCMD_GEN_XFER:
  708. type = LPFC_SOL_IOCB;
  709. break;
  710. case CMD_ABORT_XRI_CN:
  711. case CMD_ABORT_XRI_CX:
  712. case CMD_CLOSE_XRI_CN:
  713. case CMD_CLOSE_XRI_CX:
  714. case CMD_XRI_ABORTED_CX:
  715. case CMD_ABORT_MXRI64_CN:
  716. case CMD_XMIT_BLS_RSP64_CX:
  717. type = LPFC_ABORT_IOCB;
  718. break;
  719. case CMD_RCV_SEQUENCE_CX:
  720. case CMD_RCV_ELS_REQ_CX:
  721. case CMD_RCV_SEQUENCE64_CX:
  722. case CMD_RCV_ELS_REQ64_CX:
  723. case CMD_ASYNC_STATUS:
  724. case CMD_IOCB_RCV_SEQ64_CX:
  725. case CMD_IOCB_RCV_ELS64_CX:
  726. case CMD_IOCB_RCV_CONT64_CX:
  727. case CMD_IOCB_RET_XRI64_CX:
  728. type = LPFC_UNSOL_IOCB;
  729. break;
  730. case CMD_IOCB_XMIT_MSEQ64_CR:
  731. case CMD_IOCB_XMIT_MSEQ64_CX:
  732. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  733. case CMD_IOCB_RCV_ELS_LIST64_CX:
  734. case CMD_IOCB_CLOSE_EXTENDED_CN:
  735. case CMD_IOCB_ABORT_EXTENDED_CN:
  736. case CMD_IOCB_RET_HBQE64_CN:
  737. case CMD_IOCB_FCP_IBIDIR64_CR:
  738. case CMD_IOCB_FCP_IBIDIR64_CX:
  739. case CMD_IOCB_FCP_ITASKMGT64_CX:
  740. case CMD_IOCB_LOGENTRY_CN:
  741. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  742. printk("%s - Unhandled SLI-3 Command x%x\n",
  743. __func__, iocb_cmnd);
  744. type = LPFC_UNKNOWN_IOCB;
  745. break;
  746. default:
  747. type = LPFC_UNKNOWN_IOCB;
  748. break;
  749. }
  750. return type;
  751. }
  752. /**
  753. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  754. * @phba: Pointer to HBA context object.
  755. *
  756. * This function is called from SLI initialization code
  757. * to configure every ring of the HBA's SLI interface. The
  758. * caller is not required to hold any lock. This function issues
  759. * a config_ring mailbox command for each ring.
  760. * This function returns zero if successful else returns a negative
  761. * error code.
  762. **/
  763. static int
  764. lpfc_sli_ring_map(struct lpfc_hba *phba)
  765. {
  766. struct lpfc_sli *psli = &phba->sli;
  767. LPFC_MBOXQ_t *pmb;
  768. MAILBOX_t *pmbox;
  769. int i, rc, ret = 0;
  770. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  771. if (!pmb)
  772. return -ENOMEM;
  773. pmbox = &pmb->u.mb;
  774. phba->link_state = LPFC_INIT_MBX_CMDS;
  775. for (i = 0; i < psli->num_rings; i++) {
  776. lpfc_config_ring(phba, i, pmb);
  777. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  778. if (rc != MBX_SUCCESS) {
  779. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  780. "0446 Adapter failed to init (%d), "
  781. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  782. "ring %d\n",
  783. rc, pmbox->mbxCommand,
  784. pmbox->mbxStatus, i);
  785. phba->link_state = LPFC_HBA_ERROR;
  786. ret = -ENXIO;
  787. break;
  788. }
  789. }
  790. mempool_free(pmb, phba->mbox_mem_pool);
  791. return ret;
  792. }
  793. /**
  794. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  795. * @phba: Pointer to HBA context object.
  796. * @pring: Pointer to driver SLI ring object.
  797. * @piocb: Pointer to the driver iocb object.
  798. *
  799. * This function is called with hbalock held. The function adds the
  800. * new iocb to txcmplq of the given ring. This function always returns
  801. * 0. If this function is called for ELS ring, this function checks if
  802. * there is a vport associated with the ELS command. This function also
  803. * starts els_tmofunc timer if this is an ELS command.
  804. **/
  805. static int
  806. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  807. struct lpfc_iocbq *piocb)
  808. {
  809. list_add_tail(&piocb->list, &pring->txcmplq);
  810. pring->txcmplq_cnt++;
  811. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  812. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  813. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  814. if (!piocb->vport)
  815. BUG();
  816. else
  817. mod_timer(&piocb->vport->els_tmofunc,
  818. jiffies + HZ * (phba->fc_ratov << 1));
  819. }
  820. return 0;
  821. }
  822. /**
  823. * lpfc_sli_ringtx_get - Get first element of the txq
  824. * @phba: Pointer to HBA context object.
  825. * @pring: Pointer to driver SLI ring object.
  826. *
  827. * This function is called with hbalock held to get next
  828. * iocb in txq of the given ring. If there is any iocb in
  829. * the txq, the function returns first iocb in the list after
  830. * removing the iocb from the list, else it returns NULL.
  831. **/
  832. static struct lpfc_iocbq *
  833. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  834. {
  835. struct lpfc_iocbq *cmd_iocb;
  836. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  837. if (cmd_iocb != NULL)
  838. pring->txq_cnt--;
  839. return cmd_iocb;
  840. }
  841. /**
  842. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  843. * @phba: Pointer to HBA context object.
  844. * @pring: Pointer to driver SLI ring object.
  845. *
  846. * This function is called with hbalock held and the caller must post the
  847. * iocb without releasing the lock. If the caller releases the lock,
  848. * iocb slot returned by the function is not guaranteed to be available.
  849. * The function returns pointer to the next available iocb slot if there
  850. * is available slot in the ring, else it returns NULL.
  851. * If the get index of the ring is ahead of the put index, the function
  852. * will post an error attention event to the worker thread to take the
  853. * HBA to offline state.
  854. **/
  855. static IOCB_t *
  856. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  857. {
  858. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  859. uint32_t max_cmd_idx = pring->numCiocb;
  860. if ((pring->next_cmdidx == pring->cmdidx) &&
  861. (++pring->next_cmdidx >= max_cmd_idx))
  862. pring->next_cmdidx = 0;
  863. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  864. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  865. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  866. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  867. "0315 Ring %d issue: portCmdGet %d "
  868. "is bigger than cmd ring %d\n",
  869. pring->ringno,
  870. pring->local_getidx, max_cmd_idx);
  871. phba->link_state = LPFC_HBA_ERROR;
  872. /*
  873. * All error attention handlers are posted to
  874. * worker thread
  875. */
  876. phba->work_ha |= HA_ERATT;
  877. phba->work_hs = HS_FFER3;
  878. lpfc_worker_wake_up(phba);
  879. return NULL;
  880. }
  881. if (pring->local_getidx == pring->next_cmdidx)
  882. return NULL;
  883. }
  884. return lpfc_cmd_iocb(phba, pring);
  885. }
  886. /**
  887. * lpfc_sli_next_iotag - Get an iotag for the iocb
  888. * @phba: Pointer to HBA context object.
  889. * @iocbq: Pointer to driver iocb object.
  890. *
  891. * This function gets an iotag for the iocb. If there is no unused iotag and
  892. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  893. * array and assigns a new iotag.
  894. * The function returns the allocated iotag if successful, else returns zero.
  895. * Zero is not a valid iotag.
  896. * The caller is not required to hold any lock.
  897. **/
  898. uint16_t
  899. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  900. {
  901. struct lpfc_iocbq **new_arr;
  902. struct lpfc_iocbq **old_arr;
  903. size_t new_len;
  904. struct lpfc_sli *psli = &phba->sli;
  905. uint16_t iotag;
  906. spin_lock_irq(&phba->hbalock);
  907. iotag = psli->last_iotag;
  908. if(++iotag < psli->iocbq_lookup_len) {
  909. psli->last_iotag = iotag;
  910. psli->iocbq_lookup[iotag] = iocbq;
  911. spin_unlock_irq(&phba->hbalock);
  912. iocbq->iotag = iotag;
  913. return iotag;
  914. } else if (psli->iocbq_lookup_len < (0xffff
  915. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  916. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  917. spin_unlock_irq(&phba->hbalock);
  918. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  919. GFP_KERNEL);
  920. if (new_arr) {
  921. spin_lock_irq(&phba->hbalock);
  922. old_arr = psli->iocbq_lookup;
  923. if (new_len <= psli->iocbq_lookup_len) {
  924. /* highly unprobable case */
  925. kfree(new_arr);
  926. iotag = psli->last_iotag;
  927. if(++iotag < psli->iocbq_lookup_len) {
  928. psli->last_iotag = iotag;
  929. psli->iocbq_lookup[iotag] = iocbq;
  930. spin_unlock_irq(&phba->hbalock);
  931. iocbq->iotag = iotag;
  932. return iotag;
  933. }
  934. spin_unlock_irq(&phba->hbalock);
  935. return 0;
  936. }
  937. if (psli->iocbq_lookup)
  938. memcpy(new_arr, old_arr,
  939. ((psli->last_iotag + 1) *
  940. sizeof (struct lpfc_iocbq *)));
  941. psli->iocbq_lookup = new_arr;
  942. psli->iocbq_lookup_len = new_len;
  943. psli->last_iotag = iotag;
  944. psli->iocbq_lookup[iotag] = iocbq;
  945. spin_unlock_irq(&phba->hbalock);
  946. iocbq->iotag = iotag;
  947. kfree(old_arr);
  948. return iotag;
  949. }
  950. } else
  951. spin_unlock_irq(&phba->hbalock);
  952. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  953. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  954. psli->last_iotag);
  955. return 0;
  956. }
  957. /**
  958. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  959. * @phba: Pointer to HBA context object.
  960. * @pring: Pointer to driver SLI ring object.
  961. * @iocb: Pointer to iocb slot in the ring.
  962. * @nextiocb: Pointer to driver iocb object which need to be
  963. * posted to firmware.
  964. *
  965. * This function is called with hbalock held to post a new iocb to
  966. * the firmware. This function copies the new iocb to ring iocb slot and
  967. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  968. * a completion call back for this iocb else the function will free the
  969. * iocb object.
  970. **/
  971. static void
  972. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  973. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  974. {
  975. /*
  976. * Set up an iotag
  977. */
  978. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  979. if (pring->ringno == LPFC_ELS_RING) {
  980. lpfc_debugfs_slow_ring_trc(phba,
  981. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  982. *(((uint32_t *) &nextiocb->iocb) + 4),
  983. *(((uint32_t *) &nextiocb->iocb) + 6),
  984. *(((uint32_t *) &nextiocb->iocb) + 7));
  985. }
  986. /*
  987. * Issue iocb command to adapter
  988. */
  989. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  990. wmb();
  991. pring->stats.iocb_cmd++;
  992. /*
  993. * If there is no completion routine to call, we can release the
  994. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  995. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  996. */
  997. if (nextiocb->iocb_cmpl)
  998. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  999. else
  1000. __lpfc_sli_release_iocbq(phba, nextiocb);
  1001. /*
  1002. * Let the HBA know what IOCB slot will be the next one the
  1003. * driver will put a command into.
  1004. */
  1005. pring->cmdidx = pring->next_cmdidx;
  1006. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1007. }
  1008. /**
  1009. * lpfc_sli_update_full_ring - Update the chip attention register
  1010. * @phba: Pointer to HBA context object.
  1011. * @pring: Pointer to driver SLI ring object.
  1012. *
  1013. * The caller is not required to hold any lock for calling this function.
  1014. * This function updates the chip attention bits for the ring to inform firmware
  1015. * that there are pending work to be done for this ring and requests an
  1016. * interrupt when there is space available in the ring. This function is
  1017. * called when the driver is unable to post more iocbs to the ring due
  1018. * to unavailability of space in the ring.
  1019. **/
  1020. static void
  1021. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1022. {
  1023. int ringno = pring->ringno;
  1024. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1025. wmb();
  1026. /*
  1027. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1028. * The HBA will tell us when an IOCB entry is available.
  1029. */
  1030. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1031. readl(phba->CAregaddr); /* flush */
  1032. pring->stats.iocb_cmd_full++;
  1033. }
  1034. /**
  1035. * lpfc_sli_update_ring - Update chip attention register
  1036. * @phba: Pointer to HBA context object.
  1037. * @pring: Pointer to driver SLI ring object.
  1038. *
  1039. * This function updates the chip attention register bit for the
  1040. * given ring to inform HBA that there is more work to be done
  1041. * in this ring. The caller is not required to hold any lock.
  1042. **/
  1043. static void
  1044. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1045. {
  1046. int ringno = pring->ringno;
  1047. /*
  1048. * Tell the HBA that there is work to do in this ring.
  1049. */
  1050. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1051. wmb();
  1052. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1053. readl(phba->CAregaddr); /* flush */
  1054. }
  1055. }
  1056. /**
  1057. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1058. * @phba: Pointer to HBA context object.
  1059. * @pring: Pointer to driver SLI ring object.
  1060. *
  1061. * This function is called with hbalock held to post pending iocbs
  1062. * in the txq to the firmware. This function is called when driver
  1063. * detects space available in the ring.
  1064. **/
  1065. static void
  1066. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1067. {
  1068. IOCB_t *iocb;
  1069. struct lpfc_iocbq *nextiocb;
  1070. /*
  1071. * Check to see if:
  1072. * (a) there is anything on the txq to send
  1073. * (b) link is up
  1074. * (c) link attention events can be processed (fcp ring only)
  1075. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1076. */
  1077. if (pring->txq_cnt &&
  1078. lpfc_is_link_up(phba) &&
  1079. (pring->ringno != phba->sli.fcp_ring ||
  1080. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1081. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1082. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1083. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1084. if (iocb)
  1085. lpfc_sli_update_ring(phba, pring);
  1086. else
  1087. lpfc_sli_update_full_ring(phba, pring);
  1088. }
  1089. return;
  1090. }
  1091. /**
  1092. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1093. * @phba: Pointer to HBA context object.
  1094. * @hbqno: HBQ number.
  1095. *
  1096. * This function is called with hbalock held to get the next
  1097. * available slot for the given HBQ. If there is free slot
  1098. * available for the HBQ it will return pointer to the next available
  1099. * HBQ entry else it will return NULL.
  1100. **/
  1101. static struct lpfc_hbq_entry *
  1102. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1103. {
  1104. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1105. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1106. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1107. hbqp->next_hbqPutIdx = 0;
  1108. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1109. uint32_t raw_index = phba->hbq_get[hbqno];
  1110. uint32_t getidx = le32_to_cpu(raw_index);
  1111. hbqp->local_hbqGetIdx = getidx;
  1112. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1113. lpfc_printf_log(phba, KERN_ERR,
  1114. LOG_SLI | LOG_VPORT,
  1115. "1802 HBQ %d: local_hbqGetIdx "
  1116. "%u is > than hbqp->entry_count %u\n",
  1117. hbqno, hbqp->local_hbqGetIdx,
  1118. hbqp->entry_count);
  1119. phba->link_state = LPFC_HBA_ERROR;
  1120. return NULL;
  1121. }
  1122. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1123. return NULL;
  1124. }
  1125. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1126. hbqp->hbqPutIdx;
  1127. }
  1128. /**
  1129. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1130. * @phba: Pointer to HBA context object.
  1131. *
  1132. * This function is called with no lock held to free all the
  1133. * hbq buffers while uninitializing the SLI interface. It also
  1134. * frees the HBQ buffers returned by the firmware but not yet
  1135. * processed by the upper layers.
  1136. **/
  1137. void
  1138. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1139. {
  1140. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1141. struct hbq_dmabuf *hbq_buf;
  1142. unsigned long flags;
  1143. int i, hbq_count;
  1144. uint32_t hbqno;
  1145. hbq_count = lpfc_sli_hbq_count();
  1146. /* Return all memory used by all HBQs */
  1147. spin_lock_irqsave(&phba->hbalock, flags);
  1148. for (i = 0; i < hbq_count; ++i) {
  1149. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1150. &phba->hbqs[i].hbq_buffer_list, list) {
  1151. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1152. list_del(&hbq_buf->dbuf.list);
  1153. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1154. }
  1155. phba->hbqs[i].buffer_count = 0;
  1156. }
  1157. /* Return all HBQ buffer that are in-fly */
  1158. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1159. list) {
  1160. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1161. list_del(&hbq_buf->dbuf.list);
  1162. if (hbq_buf->tag == -1) {
  1163. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1164. (phba, hbq_buf);
  1165. } else {
  1166. hbqno = hbq_buf->tag >> 16;
  1167. if (hbqno >= LPFC_MAX_HBQS)
  1168. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1169. (phba, hbq_buf);
  1170. else
  1171. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1172. hbq_buf);
  1173. }
  1174. }
  1175. /* Mark the HBQs not in use */
  1176. phba->hbq_in_use = 0;
  1177. spin_unlock_irqrestore(&phba->hbalock, flags);
  1178. }
  1179. /**
  1180. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1181. * @phba: Pointer to HBA context object.
  1182. * @hbqno: HBQ number.
  1183. * @hbq_buf: Pointer to HBQ buffer.
  1184. *
  1185. * This function is called with the hbalock held to post a
  1186. * hbq buffer to the firmware. If the function finds an empty
  1187. * slot in the HBQ, it will post the buffer. The function will return
  1188. * pointer to the hbq entry if it successfully post the buffer
  1189. * else it will return NULL.
  1190. **/
  1191. static int
  1192. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1193. struct hbq_dmabuf *hbq_buf)
  1194. {
  1195. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1196. }
  1197. /**
  1198. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1199. * @phba: Pointer to HBA context object.
  1200. * @hbqno: HBQ number.
  1201. * @hbq_buf: Pointer to HBQ buffer.
  1202. *
  1203. * This function is called with the hbalock held to post a hbq buffer to the
  1204. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1205. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1206. * it successfully post the buffer else it will return an error.
  1207. **/
  1208. static int
  1209. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1210. struct hbq_dmabuf *hbq_buf)
  1211. {
  1212. struct lpfc_hbq_entry *hbqe;
  1213. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1214. /* Get next HBQ entry slot to use */
  1215. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1216. if (hbqe) {
  1217. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1218. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1219. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1220. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1221. hbqe->bde.tus.f.bdeFlags = 0;
  1222. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1223. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1224. /* Sync SLIM */
  1225. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1226. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1227. /* flush */
  1228. readl(phba->hbq_put + hbqno);
  1229. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1230. return 0;
  1231. } else
  1232. return -ENOMEM;
  1233. }
  1234. /**
  1235. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1236. * @phba: Pointer to HBA context object.
  1237. * @hbqno: HBQ number.
  1238. * @hbq_buf: Pointer to HBQ buffer.
  1239. *
  1240. * This function is called with the hbalock held to post an RQE to the SLI4
  1241. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1242. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1243. **/
  1244. static int
  1245. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1246. struct hbq_dmabuf *hbq_buf)
  1247. {
  1248. int rc;
  1249. struct lpfc_rqe hrqe;
  1250. struct lpfc_rqe drqe;
  1251. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1252. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1253. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1254. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1255. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1256. &hrqe, &drqe);
  1257. if (rc < 0)
  1258. return rc;
  1259. hbq_buf->tag = rc;
  1260. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1261. return 0;
  1262. }
  1263. /* HBQ for ELS and CT traffic. */
  1264. static struct lpfc_hbq_init lpfc_els_hbq = {
  1265. .rn = 1,
  1266. .entry_count = 200,
  1267. .mask_count = 0,
  1268. .profile = 0,
  1269. .ring_mask = (1 << LPFC_ELS_RING),
  1270. .buffer_count = 0,
  1271. .init_count = 40,
  1272. .add_count = 40,
  1273. };
  1274. /* HBQ for the extra ring if needed */
  1275. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1276. .rn = 1,
  1277. .entry_count = 200,
  1278. .mask_count = 0,
  1279. .profile = 0,
  1280. .ring_mask = (1 << LPFC_EXTRA_RING),
  1281. .buffer_count = 0,
  1282. .init_count = 0,
  1283. .add_count = 5,
  1284. };
  1285. /* Array of HBQs */
  1286. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1287. &lpfc_els_hbq,
  1288. &lpfc_extra_hbq,
  1289. };
  1290. /**
  1291. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1292. * @phba: Pointer to HBA context object.
  1293. * @hbqno: HBQ number.
  1294. * @count: Number of HBQ buffers to be posted.
  1295. *
  1296. * This function is called with no lock held to post more hbq buffers to the
  1297. * given HBQ. The function returns the number of HBQ buffers successfully
  1298. * posted.
  1299. **/
  1300. static int
  1301. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1302. {
  1303. uint32_t i, posted = 0;
  1304. unsigned long flags;
  1305. struct hbq_dmabuf *hbq_buffer;
  1306. LIST_HEAD(hbq_buf_list);
  1307. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1308. return 0;
  1309. if ((phba->hbqs[hbqno].buffer_count + count) >
  1310. lpfc_hbq_defs[hbqno]->entry_count)
  1311. count = lpfc_hbq_defs[hbqno]->entry_count -
  1312. phba->hbqs[hbqno].buffer_count;
  1313. if (!count)
  1314. return 0;
  1315. /* Allocate HBQ entries */
  1316. for (i = 0; i < count; i++) {
  1317. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1318. if (!hbq_buffer)
  1319. break;
  1320. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1321. }
  1322. /* Check whether HBQ is still in use */
  1323. spin_lock_irqsave(&phba->hbalock, flags);
  1324. if (!phba->hbq_in_use)
  1325. goto err;
  1326. while (!list_empty(&hbq_buf_list)) {
  1327. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1328. dbuf.list);
  1329. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1330. (hbqno << 16));
  1331. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1332. phba->hbqs[hbqno].buffer_count++;
  1333. posted++;
  1334. } else
  1335. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1336. }
  1337. spin_unlock_irqrestore(&phba->hbalock, flags);
  1338. return posted;
  1339. err:
  1340. spin_unlock_irqrestore(&phba->hbalock, flags);
  1341. while (!list_empty(&hbq_buf_list)) {
  1342. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1343. dbuf.list);
  1344. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1345. }
  1346. return 0;
  1347. }
  1348. /**
  1349. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1350. * @phba: Pointer to HBA context object.
  1351. * @qno: HBQ number.
  1352. *
  1353. * This function posts more buffers to the HBQ. This function
  1354. * is called with no lock held. The function returns the number of HBQ entries
  1355. * successfully allocated.
  1356. **/
  1357. int
  1358. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1359. {
  1360. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1361. lpfc_hbq_defs[qno]->add_count));
  1362. }
  1363. /**
  1364. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1365. * @phba: Pointer to HBA context object.
  1366. * @qno: HBQ queue number.
  1367. *
  1368. * This function is called from SLI initialization code path with
  1369. * no lock held to post initial HBQ buffers to firmware. The
  1370. * function returns the number of HBQ entries successfully allocated.
  1371. **/
  1372. static int
  1373. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1374. {
  1375. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1376. lpfc_hbq_defs[qno]->init_count));
  1377. }
  1378. /**
  1379. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1380. * @phba: Pointer to HBA context object.
  1381. * @hbqno: HBQ number.
  1382. *
  1383. * This function removes the first hbq buffer on an hbq list and returns a
  1384. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1385. **/
  1386. static struct hbq_dmabuf *
  1387. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1388. {
  1389. struct lpfc_dmabuf *d_buf;
  1390. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1391. if (!d_buf)
  1392. return NULL;
  1393. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1394. }
  1395. /**
  1396. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1397. * @phba: Pointer to HBA context object.
  1398. * @tag: Tag of the hbq buffer.
  1399. *
  1400. * This function is called with hbalock held. This function searches
  1401. * for the hbq buffer associated with the given tag in the hbq buffer
  1402. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1403. * it returns NULL.
  1404. **/
  1405. static struct hbq_dmabuf *
  1406. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1407. {
  1408. struct lpfc_dmabuf *d_buf;
  1409. struct hbq_dmabuf *hbq_buf;
  1410. uint32_t hbqno;
  1411. hbqno = tag >> 16;
  1412. if (hbqno >= LPFC_MAX_HBQS)
  1413. return NULL;
  1414. spin_lock_irq(&phba->hbalock);
  1415. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1416. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1417. if (hbq_buf->tag == tag) {
  1418. spin_unlock_irq(&phba->hbalock);
  1419. return hbq_buf;
  1420. }
  1421. }
  1422. spin_unlock_irq(&phba->hbalock);
  1423. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1424. "1803 Bad hbq tag. Data: x%x x%x\n",
  1425. tag, phba->hbqs[tag >> 16].buffer_count);
  1426. return NULL;
  1427. }
  1428. /**
  1429. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1430. * @phba: Pointer to HBA context object.
  1431. * @hbq_buffer: Pointer to HBQ buffer.
  1432. *
  1433. * This function is called with hbalock. This function gives back
  1434. * the hbq buffer to firmware. If the HBQ does not have space to
  1435. * post the buffer, it will free the buffer.
  1436. **/
  1437. void
  1438. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1439. {
  1440. uint32_t hbqno;
  1441. if (hbq_buffer) {
  1442. hbqno = hbq_buffer->tag >> 16;
  1443. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1444. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1445. }
  1446. }
  1447. /**
  1448. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1449. * @mbxCommand: mailbox command code.
  1450. *
  1451. * This function is called by the mailbox event handler function to verify
  1452. * that the completed mailbox command is a legitimate mailbox command. If the
  1453. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1454. * and the mailbox event handler will take the HBA offline.
  1455. **/
  1456. static int
  1457. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1458. {
  1459. uint8_t ret;
  1460. switch (mbxCommand) {
  1461. case MBX_LOAD_SM:
  1462. case MBX_READ_NV:
  1463. case MBX_WRITE_NV:
  1464. case MBX_WRITE_VPARMS:
  1465. case MBX_RUN_BIU_DIAG:
  1466. case MBX_INIT_LINK:
  1467. case MBX_DOWN_LINK:
  1468. case MBX_CONFIG_LINK:
  1469. case MBX_CONFIG_RING:
  1470. case MBX_RESET_RING:
  1471. case MBX_READ_CONFIG:
  1472. case MBX_READ_RCONFIG:
  1473. case MBX_READ_SPARM:
  1474. case MBX_READ_STATUS:
  1475. case MBX_READ_RPI:
  1476. case MBX_READ_XRI:
  1477. case MBX_READ_REV:
  1478. case MBX_READ_LNK_STAT:
  1479. case MBX_REG_LOGIN:
  1480. case MBX_UNREG_LOGIN:
  1481. case MBX_READ_LA:
  1482. case MBX_CLEAR_LA:
  1483. case MBX_DUMP_MEMORY:
  1484. case MBX_DUMP_CONTEXT:
  1485. case MBX_RUN_DIAGS:
  1486. case MBX_RESTART:
  1487. case MBX_UPDATE_CFG:
  1488. case MBX_DOWN_LOAD:
  1489. case MBX_DEL_LD_ENTRY:
  1490. case MBX_RUN_PROGRAM:
  1491. case MBX_SET_MASK:
  1492. case MBX_SET_VARIABLE:
  1493. case MBX_UNREG_D_ID:
  1494. case MBX_KILL_BOARD:
  1495. case MBX_CONFIG_FARP:
  1496. case MBX_BEACON:
  1497. case MBX_LOAD_AREA:
  1498. case MBX_RUN_BIU_DIAG64:
  1499. case MBX_CONFIG_PORT:
  1500. case MBX_READ_SPARM64:
  1501. case MBX_READ_RPI64:
  1502. case MBX_REG_LOGIN64:
  1503. case MBX_READ_LA64:
  1504. case MBX_WRITE_WWN:
  1505. case MBX_SET_DEBUG:
  1506. case MBX_LOAD_EXP_ROM:
  1507. case MBX_ASYNCEVT_ENABLE:
  1508. case MBX_REG_VPI:
  1509. case MBX_UNREG_VPI:
  1510. case MBX_HEARTBEAT:
  1511. case MBX_PORT_CAPABILITIES:
  1512. case MBX_PORT_IOV_CONTROL:
  1513. case MBX_SLI4_CONFIG:
  1514. case MBX_SLI4_REQ_FTRS:
  1515. case MBX_REG_FCFI:
  1516. case MBX_UNREG_FCFI:
  1517. case MBX_REG_VFI:
  1518. case MBX_UNREG_VFI:
  1519. case MBX_INIT_VPI:
  1520. case MBX_INIT_VFI:
  1521. case MBX_RESUME_RPI:
  1522. ret = mbxCommand;
  1523. break;
  1524. default:
  1525. ret = MBX_SHUTDOWN;
  1526. break;
  1527. }
  1528. return ret;
  1529. }
  1530. /**
  1531. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1532. * @phba: Pointer to HBA context object.
  1533. * @pmboxq: Pointer to mailbox command.
  1534. *
  1535. * This is completion handler function for mailbox commands issued from
  1536. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1537. * mailbox event handler function with no lock held. This function
  1538. * will wake up thread waiting on the wait queue pointed by context1
  1539. * of the mailbox.
  1540. **/
  1541. void
  1542. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1543. {
  1544. wait_queue_head_t *pdone_q;
  1545. unsigned long drvr_flag;
  1546. /*
  1547. * If pdone_q is empty, the driver thread gave up waiting and
  1548. * continued running.
  1549. */
  1550. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1551. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1552. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1553. if (pdone_q)
  1554. wake_up_interruptible(pdone_q);
  1555. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1556. return;
  1557. }
  1558. /**
  1559. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1560. * @phba: Pointer to HBA context object.
  1561. * @pmb: Pointer to mailbox object.
  1562. *
  1563. * This function is the default mailbox completion handler. It
  1564. * frees the memory resources associated with the completed mailbox
  1565. * command. If the completed command is a REG_LOGIN mailbox command,
  1566. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1567. **/
  1568. void
  1569. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1570. {
  1571. struct lpfc_dmabuf *mp;
  1572. uint16_t rpi, vpi;
  1573. int rc;
  1574. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1575. if (mp) {
  1576. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1577. kfree(mp);
  1578. }
  1579. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1580. (phba->sli_rev == LPFC_SLI_REV4))
  1581. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1582. /*
  1583. * If a REG_LOGIN succeeded after node is destroyed or node
  1584. * is in re-discovery driver need to cleanup the RPI.
  1585. */
  1586. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1587. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1588. !pmb->u.mb.mbxStatus) {
  1589. rpi = pmb->u.mb.un.varWords[0];
  1590. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1591. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1592. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1593. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1594. if (rc != MBX_NOT_FINISHED)
  1595. return;
  1596. }
  1597. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1598. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1599. else
  1600. mempool_free(pmb, phba->mbox_mem_pool);
  1601. }
  1602. /**
  1603. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1604. * @phba: Pointer to HBA context object.
  1605. *
  1606. * This function is called with no lock held. This function processes all
  1607. * the completed mailbox commands and gives it to upper layers. The interrupt
  1608. * service routine processes mailbox completion interrupt and adds completed
  1609. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1610. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1611. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1612. * function returns the mailbox commands to the upper layer by calling the
  1613. * completion handler function of each mailbox.
  1614. **/
  1615. int
  1616. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1617. {
  1618. MAILBOX_t *pmbox;
  1619. LPFC_MBOXQ_t *pmb;
  1620. int rc;
  1621. LIST_HEAD(cmplq);
  1622. phba->sli.slistat.mbox_event++;
  1623. /* Get all completed mailboxe buffers into the cmplq */
  1624. spin_lock_irq(&phba->hbalock);
  1625. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1626. spin_unlock_irq(&phba->hbalock);
  1627. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1628. do {
  1629. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1630. if (pmb == NULL)
  1631. break;
  1632. pmbox = &pmb->u.mb;
  1633. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1634. if (pmb->vport) {
  1635. lpfc_debugfs_disc_trc(pmb->vport,
  1636. LPFC_DISC_TRC_MBOX_VPORT,
  1637. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1638. (uint32_t)pmbox->mbxCommand,
  1639. pmbox->un.varWords[0],
  1640. pmbox->un.varWords[1]);
  1641. }
  1642. else {
  1643. lpfc_debugfs_disc_trc(phba->pport,
  1644. LPFC_DISC_TRC_MBOX,
  1645. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1646. (uint32_t)pmbox->mbxCommand,
  1647. pmbox->un.varWords[0],
  1648. pmbox->un.varWords[1]);
  1649. }
  1650. }
  1651. /*
  1652. * It is a fatal error if unknown mbox command completion.
  1653. */
  1654. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1655. MBX_SHUTDOWN) {
  1656. /* Unknow mailbox command compl */
  1657. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1658. "(%d):0323 Unknown Mailbox command "
  1659. "x%x (x%x) Cmpl\n",
  1660. pmb->vport ? pmb->vport->vpi : 0,
  1661. pmbox->mbxCommand,
  1662. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1663. phba->link_state = LPFC_HBA_ERROR;
  1664. phba->work_hs = HS_FFER3;
  1665. lpfc_handle_eratt(phba);
  1666. continue;
  1667. }
  1668. if (pmbox->mbxStatus) {
  1669. phba->sli.slistat.mbox_stat_err++;
  1670. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1671. /* Mbox cmd cmpl error - RETRYing */
  1672. lpfc_printf_log(phba, KERN_INFO,
  1673. LOG_MBOX | LOG_SLI,
  1674. "(%d):0305 Mbox cmd cmpl "
  1675. "error - RETRYing Data: x%x "
  1676. "(x%x) x%x x%x x%x\n",
  1677. pmb->vport ? pmb->vport->vpi :0,
  1678. pmbox->mbxCommand,
  1679. lpfc_sli4_mbox_opcode_get(phba,
  1680. pmb),
  1681. pmbox->mbxStatus,
  1682. pmbox->un.varWords[0],
  1683. pmb->vport->port_state);
  1684. pmbox->mbxStatus = 0;
  1685. pmbox->mbxOwner = OWN_HOST;
  1686. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1687. if (rc != MBX_NOT_FINISHED)
  1688. continue;
  1689. }
  1690. }
  1691. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1692. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1693. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1694. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1695. pmb->vport ? pmb->vport->vpi : 0,
  1696. pmbox->mbxCommand,
  1697. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1698. pmb->mbox_cmpl,
  1699. *((uint32_t *) pmbox),
  1700. pmbox->un.varWords[0],
  1701. pmbox->un.varWords[1],
  1702. pmbox->un.varWords[2],
  1703. pmbox->un.varWords[3],
  1704. pmbox->un.varWords[4],
  1705. pmbox->un.varWords[5],
  1706. pmbox->un.varWords[6],
  1707. pmbox->un.varWords[7]);
  1708. if (pmb->mbox_cmpl)
  1709. pmb->mbox_cmpl(phba,pmb);
  1710. } while (1);
  1711. return 0;
  1712. }
  1713. /**
  1714. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1715. * @phba: Pointer to HBA context object.
  1716. * @pring: Pointer to driver SLI ring object.
  1717. * @tag: buffer tag.
  1718. *
  1719. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1720. * is set in the tag the buffer is posted for a particular exchange,
  1721. * the function will return the buffer without replacing the buffer.
  1722. * If the buffer is for unsolicited ELS or CT traffic, this function
  1723. * returns the buffer and also posts another buffer to the firmware.
  1724. **/
  1725. static struct lpfc_dmabuf *
  1726. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1727. struct lpfc_sli_ring *pring,
  1728. uint32_t tag)
  1729. {
  1730. struct hbq_dmabuf *hbq_entry;
  1731. if (tag & QUE_BUFTAG_BIT)
  1732. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1733. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1734. if (!hbq_entry)
  1735. return NULL;
  1736. return &hbq_entry->dbuf;
  1737. }
  1738. /**
  1739. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1740. * @phba: Pointer to HBA context object.
  1741. * @pring: Pointer to driver SLI ring object.
  1742. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1743. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1744. * @fch_type: the type for the first frame of the sequence.
  1745. *
  1746. * This function is called with no lock held. This function uses the r_ctl and
  1747. * type of the received sequence to find the correct callback function to call
  1748. * to process the sequence.
  1749. **/
  1750. static int
  1751. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1752. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1753. uint32_t fch_type)
  1754. {
  1755. int i;
  1756. /* unSolicited Responses */
  1757. if (pring->prt[0].profile) {
  1758. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1759. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1760. saveq);
  1761. return 1;
  1762. }
  1763. /* We must search, based on rctl / type
  1764. for the right routine */
  1765. for (i = 0; i < pring->num_mask; i++) {
  1766. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1767. (pring->prt[i].type == fch_type)) {
  1768. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1769. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1770. (phba, pring, saveq);
  1771. return 1;
  1772. }
  1773. }
  1774. return 0;
  1775. }
  1776. /**
  1777. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1778. * @phba: Pointer to HBA context object.
  1779. * @pring: Pointer to driver SLI ring object.
  1780. * @saveq: Pointer to the unsolicited iocb.
  1781. *
  1782. * This function is called with no lock held by the ring event handler
  1783. * when there is an unsolicited iocb posted to the response ring by the
  1784. * firmware. This function gets the buffer associated with the iocbs
  1785. * and calls the event handler for the ring. This function handles both
  1786. * qring buffers and hbq buffers.
  1787. * When the function returns 1 the caller can free the iocb object otherwise
  1788. * upper layer functions will free the iocb objects.
  1789. **/
  1790. static int
  1791. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1792. struct lpfc_iocbq *saveq)
  1793. {
  1794. IOCB_t * irsp;
  1795. WORD5 * w5p;
  1796. uint32_t Rctl, Type;
  1797. uint32_t match;
  1798. struct lpfc_iocbq *iocbq;
  1799. struct lpfc_dmabuf *dmzbuf;
  1800. match = 0;
  1801. irsp = &(saveq->iocb);
  1802. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1803. if (pring->lpfc_sli_rcv_async_status)
  1804. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1805. else
  1806. lpfc_printf_log(phba,
  1807. KERN_WARNING,
  1808. LOG_SLI,
  1809. "0316 Ring %d handler: unexpected "
  1810. "ASYNC_STATUS iocb received evt_code "
  1811. "0x%x\n",
  1812. pring->ringno,
  1813. irsp->un.asyncstat.evt_code);
  1814. return 1;
  1815. }
  1816. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1817. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1818. if (irsp->ulpBdeCount > 0) {
  1819. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1820. irsp->un.ulpWord[3]);
  1821. lpfc_in_buf_free(phba, dmzbuf);
  1822. }
  1823. if (irsp->ulpBdeCount > 1) {
  1824. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1825. irsp->unsli3.sli3Words[3]);
  1826. lpfc_in_buf_free(phba, dmzbuf);
  1827. }
  1828. if (irsp->ulpBdeCount > 2) {
  1829. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1830. irsp->unsli3.sli3Words[7]);
  1831. lpfc_in_buf_free(phba, dmzbuf);
  1832. }
  1833. return 1;
  1834. }
  1835. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1836. if (irsp->ulpBdeCount != 0) {
  1837. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1838. irsp->un.ulpWord[3]);
  1839. if (!saveq->context2)
  1840. lpfc_printf_log(phba,
  1841. KERN_ERR,
  1842. LOG_SLI,
  1843. "0341 Ring %d Cannot find buffer for "
  1844. "an unsolicited iocb. tag 0x%x\n",
  1845. pring->ringno,
  1846. irsp->un.ulpWord[3]);
  1847. }
  1848. if (irsp->ulpBdeCount == 2) {
  1849. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1850. irsp->unsli3.sli3Words[7]);
  1851. if (!saveq->context3)
  1852. lpfc_printf_log(phba,
  1853. KERN_ERR,
  1854. LOG_SLI,
  1855. "0342 Ring %d Cannot find buffer for an"
  1856. " unsolicited iocb. tag 0x%x\n",
  1857. pring->ringno,
  1858. irsp->unsli3.sli3Words[7]);
  1859. }
  1860. list_for_each_entry(iocbq, &saveq->list, list) {
  1861. irsp = &(iocbq->iocb);
  1862. if (irsp->ulpBdeCount != 0) {
  1863. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1864. irsp->un.ulpWord[3]);
  1865. if (!iocbq->context2)
  1866. lpfc_printf_log(phba,
  1867. KERN_ERR,
  1868. LOG_SLI,
  1869. "0343 Ring %d Cannot find "
  1870. "buffer for an unsolicited iocb"
  1871. ". tag 0x%x\n", pring->ringno,
  1872. irsp->un.ulpWord[3]);
  1873. }
  1874. if (irsp->ulpBdeCount == 2) {
  1875. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1876. irsp->unsli3.sli3Words[7]);
  1877. if (!iocbq->context3)
  1878. lpfc_printf_log(phba,
  1879. KERN_ERR,
  1880. LOG_SLI,
  1881. "0344 Ring %d Cannot find "
  1882. "buffer for an unsolicited "
  1883. "iocb. tag 0x%x\n",
  1884. pring->ringno,
  1885. irsp->unsli3.sli3Words[7]);
  1886. }
  1887. }
  1888. }
  1889. if (irsp->ulpBdeCount != 0 &&
  1890. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1891. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1892. int found = 0;
  1893. /* search continue save q for same XRI */
  1894. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1895. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1896. list_add_tail(&saveq->list, &iocbq->list);
  1897. found = 1;
  1898. break;
  1899. }
  1900. }
  1901. if (!found)
  1902. list_add_tail(&saveq->clist,
  1903. &pring->iocb_continue_saveq);
  1904. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1905. list_del_init(&iocbq->clist);
  1906. saveq = iocbq;
  1907. irsp = &(saveq->iocb);
  1908. } else
  1909. return 0;
  1910. }
  1911. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1912. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1913. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1914. Rctl = FC_RCTL_ELS_REQ;
  1915. Type = FC_TYPE_ELS;
  1916. } else {
  1917. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1918. Rctl = w5p->hcsw.Rctl;
  1919. Type = w5p->hcsw.Type;
  1920. /* Firmware Workaround */
  1921. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1922. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1923. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1924. Rctl = FC_RCTL_ELS_REQ;
  1925. Type = FC_TYPE_ELS;
  1926. w5p->hcsw.Rctl = Rctl;
  1927. w5p->hcsw.Type = Type;
  1928. }
  1929. }
  1930. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1931. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1932. "0313 Ring %d handler: unexpected Rctl x%x "
  1933. "Type x%x received\n",
  1934. pring->ringno, Rctl, Type);
  1935. return 1;
  1936. }
  1937. /**
  1938. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1939. * @phba: Pointer to HBA context object.
  1940. * @pring: Pointer to driver SLI ring object.
  1941. * @prspiocb: Pointer to response iocb object.
  1942. *
  1943. * This function looks up the iocb_lookup table to get the command iocb
  1944. * corresponding to the given response iocb using the iotag of the
  1945. * response iocb. This function is called with the hbalock held.
  1946. * This function returns the command iocb object if it finds the command
  1947. * iocb else returns NULL.
  1948. **/
  1949. static struct lpfc_iocbq *
  1950. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1951. struct lpfc_sli_ring *pring,
  1952. struct lpfc_iocbq *prspiocb)
  1953. {
  1954. struct lpfc_iocbq *cmd_iocb = NULL;
  1955. uint16_t iotag;
  1956. iotag = prspiocb->iocb.ulpIoTag;
  1957. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1958. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1959. list_del_init(&cmd_iocb->list);
  1960. pring->txcmplq_cnt--;
  1961. return cmd_iocb;
  1962. }
  1963. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1964. "0317 iotag x%x is out off "
  1965. "range: max iotag x%x wd0 x%x\n",
  1966. iotag, phba->sli.last_iotag,
  1967. *(((uint32_t *) &prspiocb->iocb) + 7));
  1968. return NULL;
  1969. }
  1970. /**
  1971. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1972. * @phba: Pointer to HBA context object.
  1973. * @pring: Pointer to driver SLI ring object.
  1974. * @iotag: IOCB tag.
  1975. *
  1976. * This function looks up the iocb_lookup table to get the command iocb
  1977. * corresponding to the given iotag. This function is called with the
  1978. * hbalock held.
  1979. * This function returns the command iocb object if it finds the command
  1980. * iocb else returns NULL.
  1981. **/
  1982. static struct lpfc_iocbq *
  1983. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  1984. struct lpfc_sli_ring *pring, uint16_t iotag)
  1985. {
  1986. struct lpfc_iocbq *cmd_iocb;
  1987. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1988. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1989. list_del_init(&cmd_iocb->list);
  1990. pring->txcmplq_cnt--;
  1991. return cmd_iocb;
  1992. }
  1993. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1994. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  1995. iotag, phba->sli.last_iotag);
  1996. return NULL;
  1997. }
  1998. /**
  1999. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2000. * @phba: Pointer to HBA context object.
  2001. * @pring: Pointer to driver SLI ring object.
  2002. * @saveq: Pointer to the response iocb to be processed.
  2003. *
  2004. * This function is called by the ring event handler for non-fcp
  2005. * rings when there is a new response iocb in the response ring.
  2006. * The caller is not required to hold any locks. This function
  2007. * gets the command iocb associated with the response iocb and
  2008. * calls the completion handler for the command iocb. If there
  2009. * is no completion handler, the function will free the resources
  2010. * associated with command iocb. If the response iocb is for
  2011. * an already aborted command iocb, the status of the completion
  2012. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2013. * This function always returns 1.
  2014. **/
  2015. static int
  2016. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2017. struct lpfc_iocbq *saveq)
  2018. {
  2019. struct lpfc_iocbq *cmdiocbp;
  2020. int rc = 1;
  2021. unsigned long iflag;
  2022. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2023. spin_lock_irqsave(&phba->hbalock, iflag);
  2024. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2025. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2026. if (cmdiocbp) {
  2027. if (cmdiocbp->iocb_cmpl) {
  2028. /*
  2029. * If an ELS command failed send an event to mgmt
  2030. * application.
  2031. */
  2032. if (saveq->iocb.ulpStatus &&
  2033. (pring->ringno == LPFC_ELS_RING) &&
  2034. (cmdiocbp->iocb.ulpCommand ==
  2035. CMD_ELS_REQUEST64_CR))
  2036. lpfc_send_els_failure_event(phba,
  2037. cmdiocbp, saveq);
  2038. /*
  2039. * Post all ELS completions to the worker thread.
  2040. * All other are passed to the completion callback.
  2041. */
  2042. if (pring->ringno == LPFC_ELS_RING) {
  2043. if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
  2044. cmdiocbp->iocb_flag &=
  2045. ~LPFC_DRIVER_ABORTED;
  2046. saveq->iocb.ulpStatus =
  2047. IOSTAT_LOCAL_REJECT;
  2048. saveq->iocb.un.ulpWord[4] =
  2049. IOERR_SLI_ABORTED;
  2050. /* Firmware could still be in progress
  2051. * of DMAing payload, so don't free data
  2052. * buffer till after a hbeat.
  2053. */
  2054. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2055. }
  2056. }
  2057. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2058. } else
  2059. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2060. } else {
  2061. /*
  2062. * Unknown initiating command based on the response iotag.
  2063. * This could be the case on the ELS ring because of
  2064. * lpfc_els_abort().
  2065. */
  2066. if (pring->ringno != LPFC_ELS_RING) {
  2067. /*
  2068. * Ring <ringno> handler: unexpected completion IoTag
  2069. * <IoTag>
  2070. */
  2071. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2072. "0322 Ring %d handler: "
  2073. "unexpected completion IoTag x%x "
  2074. "Data: x%x x%x x%x x%x\n",
  2075. pring->ringno,
  2076. saveq->iocb.ulpIoTag,
  2077. saveq->iocb.ulpStatus,
  2078. saveq->iocb.un.ulpWord[4],
  2079. saveq->iocb.ulpCommand,
  2080. saveq->iocb.ulpContext);
  2081. }
  2082. }
  2083. return rc;
  2084. }
  2085. /**
  2086. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2087. * @phba: Pointer to HBA context object.
  2088. * @pring: Pointer to driver SLI ring object.
  2089. *
  2090. * This function is called from the iocb ring event handlers when
  2091. * put pointer is ahead of the get pointer for a ring. This function signal
  2092. * an error attention condition to the worker thread and the worker
  2093. * thread will transition the HBA to offline state.
  2094. **/
  2095. static void
  2096. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2097. {
  2098. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2099. /*
  2100. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2101. * rsp ring <portRspMax>
  2102. */
  2103. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2104. "0312 Ring %d handler: portRspPut %d "
  2105. "is bigger than rsp ring %d\n",
  2106. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2107. pring->numRiocb);
  2108. phba->link_state = LPFC_HBA_ERROR;
  2109. /*
  2110. * All error attention handlers are posted to
  2111. * worker thread
  2112. */
  2113. phba->work_ha |= HA_ERATT;
  2114. phba->work_hs = HS_FFER3;
  2115. lpfc_worker_wake_up(phba);
  2116. return;
  2117. }
  2118. /**
  2119. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2120. * @ptr: Pointer to address of HBA context object.
  2121. *
  2122. * This function is invoked by the Error Attention polling timer when the
  2123. * timer times out. It will check the SLI Error Attention register for
  2124. * possible attention events. If so, it will post an Error Attention event
  2125. * and wake up worker thread to process it. Otherwise, it will set up the
  2126. * Error Attention polling timer for the next poll.
  2127. **/
  2128. void lpfc_poll_eratt(unsigned long ptr)
  2129. {
  2130. struct lpfc_hba *phba;
  2131. uint32_t eratt = 0;
  2132. phba = (struct lpfc_hba *)ptr;
  2133. /* Check chip HA register for error event */
  2134. eratt = lpfc_sli_check_eratt(phba);
  2135. if (eratt)
  2136. /* Tell the worker thread there is work to do */
  2137. lpfc_worker_wake_up(phba);
  2138. else
  2139. /* Restart the timer for next eratt poll */
  2140. mod_timer(&phba->eratt_poll, jiffies +
  2141. HZ * LPFC_ERATT_POLL_INTERVAL);
  2142. return;
  2143. }
  2144. /**
  2145. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2146. * @phba: Pointer to HBA context object.
  2147. * @pring: Pointer to driver SLI ring object.
  2148. * @mask: Host attention register mask for this ring.
  2149. *
  2150. * This function is called from the interrupt context when there is a ring
  2151. * event for the fcp ring. The caller does not hold any lock.
  2152. * The function processes each response iocb in the response ring until it
  2153. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2154. * LE bit set. The function will call the completion handler of the command iocb
  2155. * if the response iocb indicates a completion for a command iocb or it is
  2156. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2157. * function if this is an unsolicited iocb.
  2158. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2159. * to check it explicitly.
  2160. */
  2161. int
  2162. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2163. struct lpfc_sli_ring *pring, uint32_t mask)
  2164. {
  2165. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2166. IOCB_t *irsp = NULL;
  2167. IOCB_t *entry = NULL;
  2168. struct lpfc_iocbq *cmdiocbq = NULL;
  2169. struct lpfc_iocbq rspiocbq;
  2170. uint32_t status;
  2171. uint32_t portRspPut, portRspMax;
  2172. int rc = 1;
  2173. lpfc_iocb_type type;
  2174. unsigned long iflag;
  2175. uint32_t rsp_cmpl = 0;
  2176. spin_lock_irqsave(&phba->hbalock, iflag);
  2177. pring->stats.iocb_event++;
  2178. /*
  2179. * The next available response entry should never exceed the maximum
  2180. * entries. If it does, treat it as an adapter hardware error.
  2181. */
  2182. portRspMax = pring->numRiocb;
  2183. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2184. if (unlikely(portRspPut >= portRspMax)) {
  2185. lpfc_sli_rsp_pointers_error(phba, pring);
  2186. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2187. return 1;
  2188. }
  2189. if (phba->fcp_ring_in_use) {
  2190. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2191. return 1;
  2192. } else
  2193. phba->fcp_ring_in_use = 1;
  2194. rmb();
  2195. while (pring->rspidx != portRspPut) {
  2196. /*
  2197. * Fetch an entry off the ring and copy it into a local data
  2198. * structure. The copy involves a byte-swap since the
  2199. * network byte order and pci byte orders are different.
  2200. */
  2201. entry = lpfc_resp_iocb(phba, pring);
  2202. phba->last_completion_time = jiffies;
  2203. if (++pring->rspidx >= portRspMax)
  2204. pring->rspidx = 0;
  2205. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2206. (uint32_t *) &rspiocbq.iocb,
  2207. phba->iocb_rsp_size);
  2208. INIT_LIST_HEAD(&(rspiocbq.list));
  2209. irsp = &rspiocbq.iocb;
  2210. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2211. pring->stats.iocb_rsp++;
  2212. rsp_cmpl++;
  2213. if (unlikely(irsp->ulpStatus)) {
  2214. /*
  2215. * If resource errors reported from HBA, reduce
  2216. * queuedepths of the SCSI device.
  2217. */
  2218. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2219. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2220. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2221. phba->lpfc_rampdown_queue_depth(phba);
  2222. spin_lock_irqsave(&phba->hbalock, iflag);
  2223. }
  2224. /* Rsp ring <ringno> error: IOCB */
  2225. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2226. "0336 Rsp Ring %d error: IOCB Data: "
  2227. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2228. pring->ringno,
  2229. irsp->un.ulpWord[0],
  2230. irsp->un.ulpWord[1],
  2231. irsp->un.ulpWord[2],
  2232. irsp->un.ulpWord[3],
  2233. irsp->un.ulpWord[4],
  2234. irsp->un.ulpWord[5],
  2235. *(uint32_t *)&irsp->un1,
  2236. *((uint32_t *)&irsp->un1 + 1));
  2237. }
  2238. switch (type) {
  2239. case LPFC_ABORT_IOCB:
  2240. case LPFC_SOL_IOCB:
  2241. /*
  2242. * Idle exchange closed via ABTS from port. No iocb
  2243. * resources need to be recovered.
  2244. */
  2245. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2246. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2247. "0333 IOCB cmd 0x%x"
  2248. " processed. Skipping"
  2249. " completion\n",
  2250. irsp->ulpCommand);
  2251. break;
  2252. }
  2253. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2254. &rspiocbq);
  2255. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2256. spin_unlock_irqrestore(&phba->hbalock,
  2257. iflag);
  2258. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2259. &rspiocbq);
  2260. spin_lock_irqsave(&phba->hbalock,
  2261. iflag);
  2262. }
  2263. break;
  2264. case LPFC_UNSOL_IOCB:
  2265. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2266. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2267. spin_lock_irqsave(&phba->hbalock, iflag);
  2268. break;
  2269. default:
  2270. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2271. char adaptermsg[LPFC_MAX_ADPTMSG];
  2272. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2273. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2274. MAX_MSG_DATA);
  2275. dev_warn(&((phba->pcidev)->dev),
  2276. "lpfc%d: %s\n",
  2277. phba->brd_no, adaptermsg);
  2278. } else {
  2279. /* Unknown IOCB command */
  2280. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2281. "0334 Unknown IOCB command "
  2282. "Data: x%x, x%x x%x x%x x%x\n",
  2283. type, irsp->ulpCommand,
  2284. irsp->ulpStatus,
  2285. irsp->ulpIoTag,
  2286. irsp->ulpContext);
  2287. }
  2288. break;
  2289. }
  2290. /*
  2291. * The response IOCB has been processed. Update the ring
  2292. * pointer in SLIM. If the port response put pointer has not
  2293. * been updated, sync the pgp->rspPutInx and fetch the new port
  2294. * response put pointer.
  2295. */
  2296. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2297. if (pring->rspidx == portRspPut)
  2298. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2299. }
  2300. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2301. pring->stats.iocb_rsp_full++;
  2302. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2303. writel(status, phba->CAregaddr);
  2304. readl(phba->CAregaddr);
  2305. }
  2306. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2307. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2308. pring->stats.iocb_cmd_empty++;
  2309. /* Force update of the local copy of cmdGetInx */
  2310. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2311. lpfc_sli_resume_iocb(phba, pring);
  2312. if ((pring->lpfc_sli_cmd_available))
  2313. (pring->lpfc_sli_cmd_available) (phba, pring);
  2314. }
  2315. phba->fcp_ring_in_use = 0;
  2316. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2317. return rc;
  2318. }
  2319. /**
  2320. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2321. * @phba: Pointer to HBA context object.
  2322. * @pring: Pointer to driver SLI ring object.
  2323. * @rspiocbp: Pointer to driver response IOCB object.
  2324. *
  2325. * This function is called from the worker thread when there is a slow-path
  2326. * response IOCB to process. This function chains all the response iocbs until
  2327. * seeing the iocb with the LE bit set. The function will call
  2328. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2329. * completion of a command iocb. The function will call the
  2330. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2331. * The function frees the resources or calls the completion handler if this
  2332. * iocb is an abort completion. The function returns NULL when the response
  2333. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2334. * this function shall chain the iocb on to the iocb_continueq and return the
  2335. * response iocb passed in.
  2336. **/
  2337. static struct lpfc_iocbq *
  2338. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2339. struct lpfc_iocbq *rspiocbp)
  2340. {
  2341. struct lpfc_iocbq *saveq;
  2342. struct lpfc_iocbq *cmdiocbp;
  2343. struct lpfc_iocbq *next_iocb;
  2344. IOCB_t *irsp = NULL;
  2345. uint32_t free_saveq;
  2346. uint8_t iocb_cmd_type;
  2347. lpfc_iocb_type type;
  2348. unsigned long iflag;
  2349. int rc;
  2350. spin_lock_irqsave(&phba->hbalock, iflag);
  2351. /* First add the response iocb to the countinueq list */
  2352. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2353. pring->iocb_continueq_cnt++;
  2354. /* Now, determine whetehr the list is completed for processing */
  2355. irsp = &rspiocbp->iocb;
  2356. if (irsp->ulpLe) {
  2357. /*
  2358. * By default, the driver expects to free all resources
  2359. * associated with this iocb completion.
  2360. */
  2361. free_saveq = 1;
  2362. saveq = list_get_first(&pring->iocb_continueq,
  2363. struct lpfc_iocbq, list);
  2364. irsp = &(saveq->iocb);
  2365. list_del_init(&pring->iocb_continueq);
  2366. pring->iocb_continueq_cnt = 0;
  2367. pring->stats.iocb_rsp++;
  2368. /*
  2369. * If resource errors reported from HBA, reduce
  2370. * queuedepths of the SCSI device.
  2371. */
  2372. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2373. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2374. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2375. phba->lpfc_rampdown_queue_depth(phba);
  2376. spin_lock_irqsave(&phba->hbalock, iflag);
  2377. }
  2378. if (irsp->ulpStatus) {
  2379. /* Rsp ring <ringno> error: IOCB */
  2380. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2381. "0328 Rsp Ring %d error: "
  2382. "IOCB Data: "
  2383. "x%x x%x x%x x%x "
  2384. "x%x x%x x%x x%x "
  2385. "x%x x%x x%x x%x "
  2386. "x%x x%x x%x x%x\n",
  2387. pring->ringno,
  2388. irsp->un.ulpWord[0],
  2389. irsp->un.ulpWord[1],
  2390. irsp->un.ulpWord[2],
  2391. irsp->un.ulpWord[3],
  2392. irsp->un.ulpWord[4],
  2393. irsp->un.ulpWord[5],
  2394. *(((uint32_t *) irsp) + 6),
  2395. *(((uint32_t *) irsp) + 7),
  2396. *(((uint32_t *) irsp) + 8),
  2397. *(((uint32_t *) irsp) + 9),
  2398. *(((uint32_t *) irsp) + 10),
  2399. *(((uint32_t *) irsp) + 11),
  2400. *(((uint32_t *) irsp) + 12),
  2401. *(((uint32_t *) irsp) + 13),
  2402. *(((uint32_t *) irsp) + 14),
  2403. *(((uint32_t *) irsp) + 15));
  2404. }
  2405. /*
  2406. * Fetch the IOCB command type and call the correct completion
  2407. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2408. * get freed back to the lpfc_iocb_list by the discovery
  2409. * kernel thread.
  2410. */
  2411. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2412. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2413. switch (type) {
  2414. case LPFC_SOL_IOCB:
  2415. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2416. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2417. spin_lock_irqsave(&phba->hbalock, iflag);
  2418. break;
  2419. case LPFC_UNSOL_IOCB:
  2420. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2421. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2422. spin_lock_irqsave(&phba->hbalock, iflag);
  2423. if (!rc)
  2424. free_saveq = 0;
  2425. break;
  2426. case LPFC_ABORT_IOCB:
  2427. cmdiocbp = NULL;
  2428. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2429. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2430. saveq);
  2431. if (cmdiocbp) {
  2432. /* Call the specified completion routine */
  2433. if (cmdiocbp->iocb_cmpl) {
  2434. spin_unlock_irqrestore(&phba->hbalock,
  2435. iflag);
  2436. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2437. saveq);
  2438. spin_lock_irqsave(&phba->hbalock,
  2439. iflag);
  2440. } else
  2441. __lpfc_sli_release_iocbq(phba,
  2442. cmdiocbp);
  2443. }
  2444. break;
  2445. case LPFC_UNKNOWN_IOCB:
  2446. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2447. char adaptermsg[LPFC_MAX_ADPTMSG];
  2448. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2449. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2450. MAX_MSG_DATA);
  2451. dev_warn(&((phba->pcidev)->dev),
  2452. "lpfc%d: %s\n",
  2453. phba->brd_no, adaptermsg);
  2454. } else {
  2455. /* Unknown IOCB command */
  2456. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2457. "0335 Unknown IOCB "
  2458. "command Data: x%x "
  2459. "x%x x%x x%x\n",
  2460. irsp->ulpCommand,
  2461. irsp->ulpStatus,
  2462. irsp->ulpIoTag,
  2463. irsp->ulpContext);
  2464. }
  2465. break;
  2466. }
  2467. if (free_saveq) {
  2468. list_for_each_entry_safe(rspiocbp, next_iocb,
  2469. &saveq->list, list) {
  2470. list_del(&rspiocbp->list);
  2471. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2472. }
  2473. __lpfc_sli_release_iocbq(phba, saveq);
  2474. }
  2475. rspiocbp = NULL;
  2476. }
  2477. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2478. return rspiocbp;
  2479. }
  2480. /**
  2481. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2482. * @phba: Pointer to HBA context object.
  2483. * @pring: Pointer to driver SLI ring object.
  2484. * @mask: Host attention register mask for this ring.
  2485. *
  2486. * This routine wraps the actual slow_ring event process routine from the
  2487. * API jump table function pointer from the lpfc_hba struct.
  2488. **/
  2489. void
  2490. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2491. struct lpfc_sli_ring *pring, uint32_t mask)
  2492. {
  2493. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2494. }
  2495. /**
  2496. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2497. * @phba: Pointer to HBA context object.
  2498. * @pring: Pointer to driver SLI ring object.
  2499. * @mask: Host attention register mask for this ring.
  2500. *
  2501. * This function is called from the worker thread when there is a ring event
  2502. * for non-fcp rings. The caller does not hold any lock. The function will
  2503. * remove each response iocb in the response ring and calls the handle
  2504. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2505. **/
  2506. static void
  2507. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2508. struct lpfc_sli_ring *pring, uint32_t mask)
  2509. {
  2510. struct lpfc_pgp *pgp;
  2511. IOCB_t *entry;
  2512. IOCB_t *irsp = NULL;
  2513. struct lpfc_iocbq *rspiocbp = NULL;
  2514. uint32_t portRspPut, portRspMax;
  2515. unsigned long iflag;
  2516. uint32_t status;
  2517. pgp = &phba->port_gp[pring->ringno];
  2518. spin_lock_irqsave(&phba->hbalock, iflag);
  2519. pring->stats.iocb_event++;
  2520. /*
  2521. * The next available response entry should never exceed the maximum
  2522. * entries. If it does, treat it as an adapter hardware error.
  2523. */
  2524. portRspMax = pring->numRiocb;
  2525. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2526. if (portRspPut >= portRspMax) {
  2527. /*
  2528. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2529. * rsp ring <portRspMax>
  2530. */
  2531. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2532. "0303 Ring %d handler: portRspPut %d "
  2533. "is bigger than rsp ring %d\n",
  2534. pring->ringno, portRspPut, portRspMax);
  2535. phba->link_state = LPFC_HBA_ERROR;
  2536. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2537. phba->work_hs = HS_FFER3;
  2538. lpfc_handle_eratt(phba);
  2539. return;
  2540. }
  2541. rmb();
  2542. while (pring->rspidx != portRspPut) {
  2543. /*
  2544. * Build a completion list and call the appropriate handler.
  2545. * The process is to get the next available response iocb, get
  2546. * a free iocb from the list, copy the response data into the
  2547. * free iocb, insert to the continuation list, and update the
  2548. * next response index to slim. This process makes response
  2549. * iocb's in the ring available to DMA as fast as possible but
  2550. * pays a penalty for a copy operation. Since the iocb is
  2551. * only 32 bytes, this penalty is considered small relative to
  2552. * the PCI reads for register values and a slim write. When
  2553. * the ulpLe field is set, the entire Command has been
  2554. * received.
  2555. */
  2556. entry = lpfc_resp_iocb(phba, pring);
  2557. phba->last_completion_time = jiffies;
  2558. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2559. if (rspiocbp == NULL) {
  2560. printk(KERN_ERR "%s: out of buffers! Failing "
  2561. "completion.\n", __func__);
  2562. break;
  2563. }
  2564. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2565. phba->iocb_rsp_size);
  2566. irsp = &rspiocbp->iocb;
  2567. if (++pring->rspidx >= portRspMax)
  2568. pring->rspidx = 0;
  2569. if (pring->ringno == LPFC_ELS_RING) {
  2570. lpfc_debugfs_slow_ring_trc(phba,
  2571. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2572. *(((uint32_t *) irsp) + 4),
  2573. *(((uint32_t *) irsp) + 6),
  2574. *(((uint32_t *) irsp) + 7));
  2575. }
  2576. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2577. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2578. /* Handle the response IOCB */
  2579. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2580. spin_lock_irqsave(&phba->hbalock, iflag);
  2581. /*
  2582. * If the port response put pointer has not been updated, sync
  2583. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2584. * response put pointer.
  2585. */
  2586. if (pring->rspidx == portRspPut) {
  2587. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2588. }
  2589. } /* while (pring->rspidx != portRspPut) */
  2590. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2591. /* At least one response entry has been freed */
  2592. pring->stats.iocb_rsp_full++;
  2593. /* SET RxRE_RSP in Chip Att register */
  2594. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2595. writel(status, phba->CAregaddr);
  2596. readl(phba->CAregaddr); /* flush */
  2597. }
  2598. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2599. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2600. pring->stats.iocb_cmd_empty++;
  2601. /* Force update of the local copy of cmdGetInx */
  2602. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2603. lpfc_sli_resume_iocb(phba, pring);
  2604. if ((pring->lpfc_sli_cmd_available))
  2605. (pring->lpfc_sli_cmd_available) (phba, pring);
  2606. }
  2607. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2608. return;
  2609. }
  2610. /**
  2611. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2612. * @phba: Pointer to HBA context object.
  2613. * @pring: Pointer to driver SLI ring object.
  2614. * @mask: Host attention register mask for this ring.
  2615. *
  2616. * This function is called from the worker thread when there is a pending
  2617. * ELS response iocb on the driver internal slow-path response iocb worker
  2618. * queue. The caller does not hold any lock. The function will remove each
  2619. * response iocb from the response worker queue and calls the handle
  2620. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2621. **/
  2622. static void
  2623. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2624. struct lpfc_sli_ring *pring, uint32_t mask)
  2625. {
  2626. struct lpfc_iocbq *irspiocbq;
  2627. struct hbq_dmabuf *dmabuf;
  2628. struct lpfc_cq_event *cq_event;
  2629. unsigned long iflag;
  2630. spin_lock_irqsave(&phba->hbalock, iflag);
  2631. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2632. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2633. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2634. /* Get the response iocb from the head of work queue */
  2635. spin_lock_irqsave(&phba->hbalock, iflag);
  2636. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2637. cq_event, struct lpfc_cq_event, list);
  2638. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2639. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2640. case CQE_CODE_COMPL_WQE:
  2641. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2642. cq_event);
  2643. /* Translate ELS WCQE to response IOCBQ */
  2644. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2645. irspiocbq);
  2646. if (irspiocbq)
  2647. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2648. irspiocbq);
  2649. break;
  2650. case CQE_CODE_RECEIVE:
  2651. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2652. cq_event);
  2653. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2654. break;
  2655. default:
  2656. break;
  2657. }
  2658. }
  2659. }
  2660. /**
  2661. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2662. * @phba: Pointer to HBA context object.
  2663. * @pring: Pointer to driver SLI ring object.
  2664. *
  2665. * This function aborts all iocbs in the given ring and frees all the iocb
  2666. * objects in txq. This function issues an abort iocb for all the iocb commands
  2667. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2668. * the return of this function. The caller is not required to hold any locks.
  2669. **/
  2670. void
  2671. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2672. {
  2673. LIST_HEAD(completions);
  2674. struct lpfc_iocbq *iocb, *next_iocb;
  2675. if (pring->ringno == LPFC_ELS_RING) {
  2676. lpfc_fabric_abort_hba(phba);
  2677. }
  2678. /* Error everything on txq and txcmplq
  2679. * First do the txq.
  2680. */
  2681. spin_lock_irq(&phba->hbalock);
  2682. list_splice_init(&pring->txq, &completions);
  2683. pring->txq_cnt = 0;
  2684. /* Next issue ABTS for everything on the txcmplq */
  2685. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2686. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2687. spin_unlock_irq(&phba->hbalock);
  2688. /* Cancel all the IOCBs from the completions list */
  2689. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2690. IOERR_SLI_ABORTED);
  2691. }
  2692. /**
  2693. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2694. * @phba: Pointer to HBA context object.
  2695. *
  2696. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2697. * objects in txq and txcmplq. This function will not issue abort iocbs
  2698. * for all the iocb commands in txcmplq, they will just be returned with
  2699. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2700. * slot has been permanently disabled.
  2701. **/
  2702. void
  2703. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2704. {
  2705. LIST_HEAD(txq);
  2706. LIST_HEAD(txcmplq);
  2707. struct lpfc_sli *psli = &phba->sli;
  2708. struct lpfc_sli_ring *pring;
  2709. /* Currently, only one fcp ring */
  2710. pring = &psli->ring[psli->fcp_ring];
  2711. spin_lock_irq(&phba->hbalock);
  2712. /* Retrieve everything on txq */
  2713. list_splice_init(&pring->txq, &txq);
  2714. pring->txq_cnt = 0;
  2715. /* Retrieve everything on the txcmplq */
  2716. list_splice_init(&pring->txcmplq, &txcmplq);
  2717. pring->txcmplq_cnt = 0;
  2718. spin_unlock_irq(&phba->hbalock);
  2719. /* Flush the txq */
  2720. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2721. IOERR_SLI_DOWN);
  2722. /* Flush the txcmpq */
  2723. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2724. IOERR_SLI_DOWN);
  2725. }
  2726. /**
  2727. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2728. * @phba: Pointer to HBA context object.
  2729. * @mask: Bit mask to be checked.
  2730. *
  2731. * This function reads the host status register and compares
  2732. * with the provided bit mask to check if HBA completed
  2733. * the restart. This function will wait in a loop for the
  2734. * HBA to complete restart. If the HBA does not restart within
  2735. * 15 iterations, the function will reset the HBA again. The
  2736. * function returns 1 when HBA fail to restart otherwise returns
  2737. * zero.
  2738. **/
  2739. static int
  2740. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2741. {
  2742. uint32_t status;
  2743. int i = 0;
  2744. int retval = 0;
  2745. /* Read the HBA Host Status Register */
  2746. status = readl(phba->HSregaddr);
  2747. /*
  2748. * Check status register every 100ms for 5 retries, then every
  2749. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2750. * every 2.5 sec for 4.
  2751. * Break our of the loop if errors occurred during init.
  2752. */
  2753. while (((status & mask) != mask) &&
  2754. !(status & HS_FFERM) &&
  2755. i++ < 20) {
  2756. if (i <= 5)
  2757. msleep(10);
  2758. else if (i <= 10)
  2759. msleep(500);
  2760. else
  2761. msleep(2500);
  2762. if (i == 15) {
  2763. /* Do post */
  2764. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2765. lpfc_sli_brdrestart(phba);
  2766. }
  2767. /* Read the HBA Host Status Register */
  2768. status = readl(phba->HSregaddr);
  2769. }
  2770. /* Check to see if any errors occurred during init */
  2771. if ((status & HS_FFERM) || (i >= 20)) {
  2772. phba->link_state = LPFC_HBA_ERROR;
  2773. retval = 1;
  2774. }
  2775. return retval;
  2776. }
  2777. /**
  2778. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2779. * @phba: Pointer to HBA context object.
  2780. * @mask: Bit mask to be checked.
  2781. *
  2782. * This function checks the host status register to check if HBA is
  2783. * ready. This function will wait in a loop for the HBA to be ready
  2784. * If the HBA is not ready , the function will will reset the HBA PCI
  2785. * function again. The function returns 1 when HBA fail to be ready
  2786. * otherwise returns zero.
  2787. **/
  2788. static int
  2789. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2790. {
  2791. uint32_t status;
  2792. int retval = 0;
  2793. /* Read the HBA Host Status Register */
  2794. status = lpfc_sli4_post_status_check(phba);
  2795. if (status) {
  2796. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2797. lpfc_sli_brdrestart(phba);
  2798. status = lpfc_sli4_post_status_check(phba);
  2799. }
  2800. /* Check to see if any errors occurred during init */
  2801. if (status) {
  2802. phba->link_state = LPFC_HBA_ERROR;
  2803. retval = 1;
  2804. } else
  2805. phba->sli4_hba.intr_enable = 0;
  2806. return retval;
  2807. }
  2808. /**
  2809. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2810. * @phba: Pointer to HBA context object.
  2811. * @mask: Bit mask to be checked.
  2812. *
  2813. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2814. * from the API jump table function pointer from the lpfc_hba struct.
  2815. **/
  2816. int
  2817. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2818. {
  2819. return phba->lpfc_sli_brdready(phba, mask);
  2820. }
  2821. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2822. /**
  2823. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2824. * @phba: Pointer to HBA context object.
  2825. *
  2826. * This function is called before resetting an HBA. This
  2827. * function requests HBA to quiesce DMAs before a reset.
  2828. **/
  2829. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2830. {
  2831. uint32_t __iomem *resp_buf;
  2832. uint32_t __iomem *mbox_buf;
  2833. volatile uint32_t mbox;
  2834. uint32_t hc_copy;
  2835. int i;
  2836. uint8_t hdrtype;
  2837. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2838. if (hdrtype != 0x80 ||
  2839. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2840. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2841. return;
  2842. /*
  2843. * Tell the other part of the chip to suspend temporarily all
  2844. * its DMA activity.
  2845. */
  2846. resp_buf = phba->MBslimaddr;
  2847. /* Disable the error attention */
  2848. hc_copy = readl(phba->HCregaddr);
  2849. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2850. readl(phba->HCregaddr); /* flush */
  2851. phba->link_flag |= LS_IGNORE_ERATT;
  2852. if (readl(phba->HAregaddr) & HA_ERATT) {
  2853. /* Clear Chip error bit */
  2854. writel(HA_ERATT, phba->HAregaddr);
  2855. phba->pport->stopped = 1;
  2856. }
  2857. mbox = 0;
  2858. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2859. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2860. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2861. mbox_buf = phba->MBslimaddr;
  2862. writel(mbox, mbox_buf);
  2863. for (i = 0;
  2864. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2865. mdelay(1);
  2866. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2867. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2868. phba->pport->stopped)
  2869. goto restore_hc;
  2870. else
  2871. goto clear_errat;
  2872. }
  2873. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2874. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2875. mdelay(1);
  2876. clear_errat:
  2877. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2878. mdelay(1);
  2879. if (readl(phba->HAregaddr) & HA_ERATT) {
  2880. writel(HA_ERATT, phba->HAregaddr);
  2881. phba->pport->stopped = 1;
  2882. }
  2883. restore_hc:
  2884. phba->link_flag &= ~LS_IGNORE_ERATT;
  2885. writel(hc_copy, phba->HCregaddr);
  2886. readl(phba->HCregaddr); /* flush */
  2887. }
  2888. /**
  2889. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  2890. * @phba: Pointer to HBA context object.
  2891. *
  2892. * This function issues a kill_board mailbox command and waits for
  2893. * the error attention interrupt. This function is called for stopping
  2894. * the firmware processing. The caller is not required to hold any
  2895. * locks. This function calls lpfc_hba_down_post function to free
  2896. * any pending commands after the kill. The function will return 1 when it
  2897. * fails to kill the board else will return 0.
  2898. **/
  2899. int
  2900. lpfc_sli_brdkill(struct lpfc_hba *phba)
  2901. {
  2902. struct lpfc_sli *psli;
  2903. LPFC_MBOXQ_t *pmb;
  2904. uint32_t status;
  2905. uint32_t ha_copy;
  2906. int retval;
  2907. int i = 0;
  2908. psli = &phba->sli;
  2909. /* Kill HBA */
  2910. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2911. "0329 Kill HBA Data: x%x x%x\n",
  2912. phba->pport->port_state, psli->sli_flag);
  2913. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2914. if (!pmb)
  2915. return 1;
  2916. /* Disable the error attention */
  2917. spin_lock_irq(&phba->hbalock);
  2918. status = readl(phba->HCregaddr);
  2919. status &= ~HC_ERINT_ENA;
  2920. writel(status, phba->HCregaddr);
  2921. readl(phba->HCregaddr); /* flush */
  2922. phba->link_flag |= LS_IGNORE_ERATT;
  2923. spin_unlock_irq(&phba->hbalock);
  2924. lpfc_kill_board(phba, pmb);
  2925. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2926. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2927. if (retval != MBX_SUCCESS) {
  2928. if (retval != MBX_BUSY)
  2929. mempool_free(pmb, phba->mbox_mem_pool);
  2930. spin_lock_irq(&phba->hbalock);
  2931. phba->link_flag &= ~LS_IGNORE_ERATT;
  2932. spin_unlock_irq(&phba->hbalock);
  2933. return 1;
  2934. }
  2935. spin_lock_irq(&phba->hbalock);
  2936. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  2937. spin_unlock_irq(&phba->hbalock);
  2938. mempool_free(pmb, phba->mbox_mem_pool);
  2939. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  2940. * attention every 100ms for 3 seconds. If we don't get ERATT after
  2941. * 3 seconds we still set HBA_ERROR state because the status of the
  2942. * board is now undefined.
  2943. */
  2944. ha_copy = readl(phba->HAregaddr);
  2945. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  2946. mdelay(100);
  2947. ha_copy = readl(phba->HAregaddr);
  2948. }
  2949. del_timer_sync(&psli->mbox_tmo);
  2950. if (ha_copy & HA_ERATT) {
  2951. writel(HA_ERATT, phba->HAregaddr);
  2952. phba->pport->stopped = 1;
  2953. }
  2954. spin_lock_irq(&phba->hbalock);
  2955. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2956. psli->mbox_active = NULL;
  2957. phba->link_flag &= ~LS_IGNORE_ERATT;
  2958. spin_unlock_irq(&phba->hbalock);
  2959. lpfc_hba_down_post(phba);
  2960. phba->link_state = LPFC_HBA_ERROR;
  2961. return ha_copy & HA_ERATT ? 0 : 1;
  2962. }
  2963. /**
  2964. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  2965. * @phba: Pointer to HBA context object.
  2966. *
  2967. * This function resets the HBA by writing HC_INITFF to the control
  2968. * register. After the HBA resets, this function resets all the iocb ring
  2969. * indices. This function disables PCI layer parity checking during
  2970. * the reset.
  2971. * This function returns 0 always.
  2972. * The caller is not required to hold any locks.
  2973. **/
  2974. int
  2975. lpfc_sli_brdreset(struct lpfc_hba *phba)
  2976. {
  2977. struct lpfc_sli *psli;
  2978. struct lpfc_sli_ring *pring;
  2979. uint16_t cfg_value;
  2980. int i;
  2981. psli = &phba->sli;
  2982. /* Reset HBA */
  2983. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2984. "0325 Reset HBA Data: x%x x%x\n",
  2985. phba->pport->port_state, psli->sli_flag);
  2986. /* perform board reset */
  2987. phba->fc_eventTag = 0;
  2988. phba->link_events = 0;
  2989. phba->pport->fc_myDID = 0;
  2990. phba->pport->fc_prevDID = 0;
  2991. /* Turn off parity checking and serr during the physical reset */
  2992. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  2993. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  2994. (cfg_value &
  2995. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  2996. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  2997. /* Now toggle INITFF bit in the Host Control Register */
  2998. writel(HC_INITFF, phba->HCregaddr);
  2999. mdelay(1);
  3000. readl(phba->HCregaddr); /* flush */
  3001. writel(0, phba->HCregaddr);
  3002. readl(phba->HCregaddr); /* flush */
  3003. /* Restore PCI cmd register */
  3004. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3005. /* Initialize relevant SLI info */
  3006. for (i = 0; i < psli->num_rings; i++) {
  3007. pring = &psli->ring[i];
  3008. pring->flag = 0;
  3009. pring->rspidx = 0;
  3010. pring->next_cmdidx = 0;
  3011. pring->local_getidx = 0;
  3012. pring->cmdidx = 0;
  3013. pring->missbufcnt = 0;
  3014. }
  3015. phba->link_state = LPFC_WARM_START;
  3016. return 0;
  3017. }
  3018. /**
  3019. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3020. * @phba: Pointer to HBA context object.
  3021. *
  3022. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3023. * checking during resets the device. The caller is not required to hold
  3024. * any locks.
  3025. *
  3026. * This function returns 0 always.
  3027. **/
  3028. int
  3029. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3030. {
  3031. struct lpfc_sli *psli = &phba->sli;
  3032. uint16_t cfg_value;
  3033. uint8_t qindx;
  3034. /* Reset HBA */
  3035. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3036. "0295 Reset HBA Data: x%x x%x\n",
  3037. phba->pport->port_state, psli->sli_flag);
  3038. /* perform board reset */
  3039. phba->fc_eventTag = 0;
  3040. phba->link_events = 0;
  3041. phba->pport->fc_myDID = 0;
  3042. phba->pport->fc_prevDID = 0;
  3043. /* Turn off parity checking and serr during the physical reset */
  3044. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3045. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3046. (cfg_value &
  3047. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3048. spin_lock_irq(&phba->hbalock);
  3049. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3050. phba->fcf.fcf_flag = 0;
  3051. /* Clean up the child queue list for the CQs */
  3052. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3053. list_del_init(&phba->sli4_hba.els_wq->list);
  3054. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3055. list_del_init(&phba->sli4_hba.dat_rq->list);
  3056. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3057. list_del_init(&phba->sli4_hba.els_cq->list);
  3058. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3059. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3060. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3061. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3062. spin_unlock_irq(&phba->hbalock);
  3063. /* Now physically reset the device */
  3064. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3065. "0389 Performing PCI function reset!\n");
  3066. /* Perform FCoE PCI function reset */
  3067. lpfc_pci_function_reset(phba);
  3068. return 0;
  3069. }
  3070. /**
  3071. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3072. * @phba: Pointer to HBA context object.
  3073. *
  3074. * This function is called in the SLI initialization code path to
  3075. * restart the HBA. The caller is not required to hold any lock.
  3076. * This function writes MBX_RESTART mailbox command to the SLIM and
  3077. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3078. * function to free any pending commands. The function enables
  3079. * POST only during the first initialization. The function returns zero.
  3080. * The function does not guarantee completion of MBX_RESTART mailbox
  3081. * command before the return of this function.
  3082. **/
  3083. static int
  3084. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3085. {
  3086. MAILBOX_t *mb;
  3087. struct lpfc_sli *psli;
  3088. volatile uint32_t word0;
  3089. void __iomem *to_slim;
  3090. uint32_t hba_aer_enabled;
  3091. spin_lock_irq(&phba->hbalock);
  3092. /* Take PCIe device Advanced Error Reporting (AER) state */
  3093. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3094. psli = &phba->sli;
  3095. /* Restart HBA */
  3096. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3097. "0337 Restart HBA Data: x%x x%x\n",
  3098. phba->pport->port_state, psli->sli_flag);
  3099. word0 = 0;
  3100. mb = (MAILBOX_t *) &word0;
  3101. mb->mbxCommand = MBX_RESTART;
  3102. mb->mbxHc = 1;
  3103. lpfc_reset_barrier(phba);
  3104. to_slim = phba->MBslimaddr;
  3105. writel(*(uint32_t *) mb, to_slim);
  3106. readl(to_slim); /* flush */
  3107. /* Only skip post after fc_ffinit is completed */
  3108. if (phba->pport->port_state)
  3109. word0 = 1; /* This is really setting up word1 */
  3110. else
  3111. word0 = 0; /* This is really setting up word1 */
  3112. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3113. writel(*(uint32_t *) mb, to_slim);
  3114. readl(to_slim); /* flush */
  3115. lpfc_sli_brdreset(phba);
  3116. phba->pport->stopped = 0;
  3117. phba->link_state = LPFC_INIT_START;
  3118. phba->hba_flag = 0;
  3119. spin_unlock_irq(&phba->hbalock);
  3120. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3121. psli->stats_start = get_seconds();
  3122. /* Give the INITFF and Post time to settle. */
  3123. mdelay(100);
  3124. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3125. if (hba_aer_enabled)
  3126. pci_disable_pcie_error_reporting(phba->pcidev);
  3127. lpfc_hba_down_post(phba);
  3128. return 0;
  3129. }
  3130. /**
  3131. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3132. * @phba: Pointer to HBA context object.
  3133. *
  3134. * This function is called in the SLI initialization code path to restart
  3135. * a SLI4 HBA. The caller is not required to hold any lock.
  3136. * At the end of the function, it calls lpfc_hba_down_post function to
  3137. * free any pending commands.
  3138. **/
  3139. static int
  3140. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3141. {
  3142. struct lpfc_sli *psli = &phba->sli;
  3143. /* Restart HBA */
  3144. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3145. "0296 Restart HBA Data: x%x x%x\n",
  3146. phba->pport->port_state, psli->sli_flag);
  3147. lpfc_sli4_brdreset(phba);
  3148. spin_lock_irq(&phba->hbalock);
  3149. phba->pport->stopped = 0;
  3150. phba->link_state = LPFC_INIT_START;
  3151. phba->hba_flag = 0;
  3152. spin_unlock_irq(&phba->hbalock);
  3153. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3154. psli->stats_start = get_seconds();
  3155. lpfc_hba_down_post(phba);
  3156. return 0;
  3157. }
  3158. /**
  3159. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3160. * @phba: Pointer to HBA context object.
  3161. *
  3162. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3163. * API jump table function pointer from the lpfc_hba struct.
  3164. **/
  3165. int
  3166. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3167. {
  3168. return phba->lpfc_sli_brdrestart(phba);
  3169. }
  3170. /**
  3171. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3172. * @phba: Pointer to HBA context object.
  3173. *
  3174. * This function is called after a HBA restart to wait for successful
  3175. * restart of the HBA. Successful restart of the HBA is indicated by
  3176. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3177. * iteration, the function will restart the HBA again. The function returns
  3178. * zero if HBA successfully restarted else returns negative error code.
  3179. **/
  3180. static int
  3181. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3182. {
  3183. uint32_t status, i = 0;
  3184. /* Read the HBA Host Status Register */
  3185. status = readl(phba->HSregaddr);
  3186. /* Check status register to see what current state is */
  3187. i = 0;
  3188. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3189. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3190. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3191. * 4.
  3192. */
  3193. if (i++ >= 20) {
  3194. /* Adapter failed to init, timeout, status reg
  3195. <status> */
  3196. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3197. "0436 Adapter failed to init, "
  3198. "timeout, status reg x%x, "
  3199. "FW Data: A8 x%x AC x%x\n", status,
  3200. readl(phba->MBslimaddr + 0xa8),
  3201. readl(phba->MBslimaddr + 0xac));
  3202. phba->link_state = LPFC_HBA_ERROR;
  3203. return -ETIMEDOUT;
  3204. }
  3205. /* Check to see if any errors occurred during init */
  3206. if (status & HS_FFERM) {
  3207. /* ERROR: During chipset initialization */
  3208. /* Adapter failed to init, chipset, status reg
  3209. <status> */
  3210. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3211. "0437 Adapter failed to init, "
  3212. "chipset, status reg x%x, "
  3213. "FW Data: A8 x%x AC x%x\n", status,
  3214. readl(phba->MBslimaddr + 0xa8),
  3215. readl(phba->MBslimaddr + 0xac));
  3216. phba->link_state = LPFC_HBA_ERROR;
  3217. return -EIO;
  3218. }
  3219. if (i <= 5) {
  3220. msleep(10);
  3221. } else if (i <= 10) {
  3222. msleep(500);
  3223. } else {
  3224. msleep(2500);
  3225. }
  3226. if (i == 15) {
  3227. /* Do post */
  3228. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3229. lpfc_sli_brdrestart(phba);
  3230. }
  3231. /* Read the HBA Host Status Register */
  3232. status = readl(phba->HSregaddr);
  3233. }
  3234. /* Check to see if any errors occurred during init */
  3235. if (status & HS_FFERM) {
  3236. /* ERROR: During chipset initialization */
  3237. /* Adapter failed to init, chipset, status reg <status> */
  3238. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3239. "0438 Adapter failed to init, chipset, "
  3240. "status reg x%x, "
  3241. "FW Data: A8 x%x AC x%x\n", status,
  3242. readl(phba->MBslimaddr + 0xa8),
  3243. readl(phba->MBslimaddr + 0xac));
  3244. phba->link_state = LPFC_HBA_ERROR;
  3245. return -EIO;
  3246. }
  3247. /* Clear all interrupt enable conditions */
  3248. writel(0, phba->HCregaddr);
  3249. readl(phba->HCregaddr); /* flush */
  3250. /* setup host attn register */
  3251. writel(0xffffffff, phba->HAregaddr);
  3252. readl(phba->HAregaddr); /* flush */
  3253. return 0;
  3254. }
  3255. /**
  3256. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3257. *
  3258. * This function calculates and returns the number of HBQs required to be
  3259. * configured.
  3260. **/
  3261. int
  3262. lpfc_sli_hbq_count(void)
  3263. {
  3264. return ARRAY_SIZE(lpfc_hbq_defs);
  3265. }
  3266. /**
  3267. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3268. *
  3269. * This function adds the number of hbq entries in every HBQ to get
  3270. * the total number of hbq entries required for the HBA and returns
  3271. * the total count.
  3272. **/
  3273. static int
  3274. lpfc_sli_hbq_entry_count(void)
  3275. {
  3276. int hbq_count = lpfc_sli_hbq_count();
  3277. int count = 0;
  3278. int i;
  3279. for (i = 0; i < hbq_count; ++i)
  3280. count += lpfc_hbq_defs[i]->entry_count;
  3281. return count;
  3282. }
  3283. /**
  3284. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3285. *
  3286. * This function calculates amount of memory required for all hbq entries
  3287. * to be configured and returns the total memory required.
  3288. **/
  3289. int
  3290. lpfc_sli_hbq_size(void)
  3291. {
  3292. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3293. }
  3294. /**
  3295. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3296. * @phba: Pointer to HBA context object.
  3297. *
  3298. * This function is called during the SLI initialization to configure
  3299. * all the HBQs and post buffers to the HBQ. The caller is not
  3300. * required to hold any locks. This function will return zero if successful
  3301. * else it will return negative error code.
  3302. **/
  3303. static int
  3304. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3305. {
  3306. int hbq_count = lpfc_sli_hbq_count();
  3307. LPFC_MBOXQ_t *pmb;
  3308. MAILBOX_t *pmbox;
  3309. uint32_t hbqno;
  3310. uint32_t hbq_entry_index;
  3311. /* Get a Mailbox buffer to setup mailbox
  3312. * commands for HBA initialization
  3313. */
  3314. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3315. if (!pmb)
  3316. return -ENOMEM;
  3317. pmbox = &pmb->u.mb;
  3318. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3319. phba->link_state = LPFC_INIT_MBX_CMDS;
  3320. phba->hbq_in_use = 1;
  3321. hbq_entry_index = 0;
  3322. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3323. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3324. phba->hbqs[hbqno].hbqPutIdx = 0;
  3325. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3326. phba->hbqs[hbqno].entry_count =
  3327. lpfc_hbq_defs[hbqno]->entry_count;
  3328. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3329. hbq_entry_index, pmb);
  3330. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3331. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3332. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3333. mbxStatus <status>, ring <num> */
  3334. lpfc_printf_log(phba, KERN_ERR,
  3335. LOG_SLI | LOG_VPORT,
  3336. "1805 Adapter failed to init. "
  3337. "Data: x%x x%x x%x\n",
  3338. pmbox->mbxCommand,
  3339. pmbox->mbxStatus, hbqno);
  3340. phba->link_state = LPFC_HBA_ERROR;
  3341. mempool_free(pmb, phba->mbox_mem_pool);
  3342. return ENXIO;
  3343. }
  3344. }
  3345. phba->hbq_count = hbq_count;
  3346. mempool_free(pmb, phba->mbox_mem_pool);
  3347. /* Initially populate or replenish the HBQs */
  3348. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3349. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3350. return 0;
  3351. }
  3352. /**
  3353. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3354. * @phba: Pointer to HBA context object.
  3355. *
  3356. * This function is called during the SLI initialization to configure
  3357. * all the HBQs and post buffers to the HBQ. The caller is not
  3358. * required to hold any locks. This function will return zero if successful
  3359. * else it will return negative error code.
  3360. **/
  3361. static int
  3362. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3363. {
  3364. phba->hbq_in_use = 1;
  3365. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3366. phba->hbq_count = 1;
  3367. /* Initially populate or replenish the HBQs */
  3368. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3369. return 0;
  3370. }
  3371. /**
  3372. * lpfc_sli_config_port - Issue config port mailbox command
  3373. * @phba: Pointer to HBA context object.
  3374. * @sli_mode: sli mode - 2/3
  3375. *
  3376. * This function is called by the sli intialization code path
  3377. * to issue config_port mailbox command. This function restarts the
  3378. * HBA firmware and issues a config_port mailbox command to configure
  3379. * the SLI interface in the sli mode specified by sli_mode
  3380. * variable. The caller is not required to hold any locks.
  3381. * The function returns 0 if successful, else returns negative error
  3382. * code.
  3383. **/
  3384. int
  3385. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3386. {
  3387. LPFC_MBOXQ_t *pmb;
  3388. uint32_t resetcount = 0, rc = 0, done = 0;
  3389. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3390. if (!pmb) {
  3391. phba->link_state = LPFC_HBA_ERROR;
  3392. return -ENOMEM;
  3393. }
  3394. phba->sli_rev = sli_mode;
  3395. while (resetcount < 2 && !done) {
  3396. spin_lock_irq(&phba->hbalock);
  3397. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3398. spin_unlock_irq(&phba->hbalock);
  3399. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3400. lpfc_sli_brdrestart(phba);
  3401. rc = lpfc_sli_chipset_init(phba);
  3402. if (rc)
  3403. break;
  3404. spin_lock_irq(&phba->hbalock);
  3405. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3406. spin_unlock_irq(&phba->hbalock);
  3407. resetcount++;
  3408. /* Call pre CONFIG_PORT mailbox command initialization. A
  3409. * value of 0 means the call was successful. Any other
  3410. * nonzero value is a failure, but if ERESTART is returned,
  3411. * the driver may reset the HBA and try again.
  3412. */
  3413. rc = lpfc_config_port_prep(phba);
  3414. if (rc == -ERESTART) {
  3415. phba->link_state = LPFC_LINK_UNKNOWN;
  3416. continue;
  3417. } else if (rc)
  3418. break;
  3419. phba->link_state = LPFC_INIT_MBX_CMDS;
  3420. lpfc_config_port(phba, pmb);
  3421. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3422. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3423. LPFC_SLI3_HBQ_ENABLED |
  3424. LPFC_SLI3_CRP_ENABLED |
  3425. LPFC_SLI3_INB_ENABLED |
  3426. LPFC_SLI3_BG_ENABLED);
  3427. if (rc != MBX_SUCCESS) {
  3428. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3429. "0442 Adapter failed to init, mbxCmd x%x "
  3430. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3431. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3432. spin_lock_irq(&phba->hbalock);
  3433. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3434. spin_unlock_irq(&phba->hbalock);
  3435. rc = -ENXIO;
  3436. } else {
  3437. /* Allow asynchronous mailbox command to go through */
  3438. spin_lock_irq(&phba->hbalock);
  3439. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3440. spin_unlock_irq(&phba->hbalock);
  3441. done = 1;
  3442. }
  3443. }
  3444. if (!done) {
  3445. rc = -EINVAL;
  3446. goto do_prep_failed;
  3447. }
  3448. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3449. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3450. rc = -ENXIO;
  3451. goto do_prep_failed;
  3452. }
  3453. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3454. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3455. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3456. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3457. phba->max_vpi : phba->max_vports;
  3458. } else
  3459. phba->max_vpi = 0;
  3460. if (pmb->u.mb.un.varCfgPort.gdss)
  3461. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3462. if (pmb->u.mb.un.varCfgPort.gerbm)
  3463. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3464. if (pmb->u.mb.un.varCfgPort.gcrp)
  3465. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3466. if (pmb->u.mb.un.varCfgPort.ginb) {
  3467. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3468. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3469. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3470. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3471. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3472. phba->inb_last_counter =
  3473. phba->mbox->us.s3_inb_pgp.counter;
  3474. } else {
  3475. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3476. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3477. phba->inb_ha_copy = NULL;
  3478. phba->inb_counter = NULL;
  3479. }
  3480. if (phba->cfg_enable_bg) {
  3481. if (pmb->u.mb.un.varCfgPort.gbg)
  3482. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3483. else
  3484. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3485. "0443 Adapter did not grant "
  3486. "BlockGuard\n");
  3487. }
  3488. } else {
  3489. phba->hbq_get = NULL;
  3490. phba->port_gp = phba->mbox->us.s2.port;
  3491. phba->inb_ha_copy = NULL;
  3492. phba->inb_counter = NULL;
  3493. phba->max_vpi = 0;
  3494. }
  3495. do_prep_failed:
  3496. mempool_free(pmb, phba->mbox_mem_pool);
  3497. return rc;
  3498. }
  3499. /**
  3500. * lpfc_sli_hba_setup - SLI intialization function
  3501. * @phba: Pointer to HBA context object.
  3502. *
  3503. * This function is the main SLI intialization function. This function
  3504. * is called by the HBA intialization code, HBA reset code and HBA
  3505. * error attention handler code. Caller is not required to hold any
  3506. * locks. This function issues config_port mailbox command to configure
  3507. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3508. * calls the config_port_post function to issue init_link mailbox
  3509. * command and to start the discovery. The function will return zero
  3510. * if successful, else it will return negative error code.
  3511. **/
  3512. int
  3513. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3514. {
  3515. uint32_t rc;
  3516. int mode = 3;
  3517. switch (lpfc_sli_mode) {
  3518. case 2:
  3519. if (phba->cfg_enable_npiv) {
  3520. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3521. "1824 NPIV enabled: Override lpfc_sli_mode "
  3522. "parameter (%d) to auto (0).\n",
  3523. lpfc_sli_mode);
  3524. break;
  3525. }
  3526. mode = 2;
  3527. break;
  3528. case 0:
  3529. case 3:
  3530. break;
  3531. default:
  3532. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3533. "1819 Unrecognized lpfc_sli_mode "
  3534. "parameter: %d.\n", lpfc_sli_mode);
  3535. break;
  3536. }
  3537. rc = lpfc_sli_config_port(phba, mode);
  3538. if (rc && lpfc_sli_mode == 3)
  3539. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3540. "1820 Unable to select SLI-3. "
  3541. "Not supported by adapter.\n");
  3542. if (rc && mode != 2)
  3543. rc = lpfc_sli_config_port(phba, 2);
  3544. if (rc)
  3545. goto lpfc_sli_hba_setup_error;
  3546. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3547. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3548. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3549. if (!rc) {
  3550. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3551. "2709 This device supports "
  3552. "Advanced Error Reporting (AER)\n");
  3553. spin_lock_irq(&phba->hbalock);
  3554. phba->hba_flag |= HBA_AER_ENABLED;
  3555. spin_unlock_irq(&phba->hbalock);
  3556. } else {
  3557. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3558. "2708 This device does not support "
  3559. "Advanced Error Reporting (AER)\n");
  3560. phba->cfg_aer_support = 0;
  3561. }
  3562. }
  3563. if (phba->sli_rev == 3) {
  3564. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3565. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3566. } else {
  3567. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3568. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3569. phba->sli3_options = 0;
  3570. }
  3571. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3572. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3573. phba->sli_rev, phba->max_vpi);
  3574. rc = lpfc_sli_ring_map(phba);
  3575. if (rc)
  3576. goto lpfc_sli_hba_setup_error;
  3577. /* Init HBQs */
  3578. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3579. rc = lpfc_sli_hbq_setup(phba);
  3580. if (rc)
  3581. goto lpfc_sli_hba_setup_error;
  3582. }
  3583. spin_lock_irq(&phba->hbalock);
  3584. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3585. spin_unlock_irq(&phba->hbalock);
  3586. rc = lpfc_config_port_post(phba);
  3587. if (rc)
  3588. goto lpfc_sli_hba_setup_error;
  3589. return rc;
  3590. lpfc_sli_hba_setup_error:
  3591. phba->link_state = LPFC_HBA_ERROR;
  3592. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3593. "0445 Firmware initialization failed\n");
  3594. return rc;
  3595. }
  3596. /**
  3597. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3598. * @phba: Pointer to HBA context object.
  3599. * @mboxq: mailbox pointer.
  3600. * This function issue a dump mailbox command to read config region
  3601. * 23 and parse the records in the region and populate driver
  3602. * data structure.
  3603. **/
  3604. static int
  3605. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3606. LPFC_MBOXQ_t *mboxq)
  3607. {
  3608. struct lpfc_dmabuf *mp;
  3609. struct lpfc_mqe *mqe;
  3610. uint32_t data_length;
  3611. int rc;
  3612. /* Program the default value of vlan_id and fc_map */
  3613. phba->valid_vlan = 0;
  3614. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3615. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3616. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3617. mqe = &mboxq->u.mqe;
  3618. if (lpfc_dump_fcoe_param(phba, mboxq))
  3619. return -ENOMEM;
  3620. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3621. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3622. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3623. "(%d):2571 Mailbox cmd x%x Status x%x "
  3624. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3625. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3626. "CQ: x%x x%x x%x x%x\n",
  3627. mboxq->vport ? mboxq->vport->vpi : 0,
  3628. bf_get(lpfc_mqe_command, mqe),
  3629. bf_get(lpfc_mqe_status, mqe),
  3630. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3631. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3632. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3633. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3634. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3635. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3636. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3637. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3638. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3639. mboxq->mcqe.word0,
  3640. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3641. mboxq->mcqe.trailer);
  3642. if (rc) {
  3643. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3644. kfree(mp);
  3645. return -EIO;
  3646. }
  3647. data_length = mqe->un.mb_words[5];
  3648. if (data_length > DMP_RGN23_SIZE) {
  3649. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3650. kfree(mp);
  3651. return -EIO;
  3652. }
  3653. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3654. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3655. kfree(mp);
  3656. return 0;
  3657. }
  3658. /**
  3659. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3660. * @phba: pointer to lpfc hba data structure.
  3661. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3662. * @vpd: pointer to the memory to hold resulting port vpd data.
  3663. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3664. * On output, the number of data bytes in @vpd.
  3665. *
  3666. * This routine executes a READ_REV SLI4 mailbox command. In
  3667. * addition, this routine gets the port vpd data.
  3668. *
  3669. * Return codes
  3670. * 0 - sucessful
  3671. * ENOMEM - could not allocated memory.
  3672. **/
  3673. static int
  3674. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3675. uint8_t *vpd, uint32_t *vpd_size)
  3676. {
  3677. int rc = 0;
  3678. uint32_t dma_size;
  3679. struct lpfc_dmabuf *dmabuf;
  3680. struct lpfc_mqe *mqe;
  3681. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3682. if (!dmabuf)
  3683. return -ENOMEM;
  3684. /*
  3685. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3686. * mailbox command.
  3687. */
  3688. dma_size = *vpd_size;
  3689. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3690. dma_size,
  3691. &dmabuf->phys,
  3692. GFP_KERNEL);
  3693. if (!dmabuf->virt) {
  3694. kfree(dmabuf);
  3695. return -ENOMEM;
  3696. }
  3697. memset(dmabuf->virt, 0, dma_size);
  3698. /*
  3699. * The SLI4 implementation of READ_REV conflicts at word1,
  3700. * bits 31:16 and SLI4 adds vpd functionality not present
  3701. * in SLI3. This code corrects the conflicts.
  3702. */
  3703. lpfc_read_rev(phba, mboxq);
  3704. mqe = &mboxq->u.mqe;
  3705. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3706. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3707. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3708. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3709. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3710. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3711. if (rc) {
  3712. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3713. dmabuf->virt, dmabuf->phys);
  3714. return -EIO;
  3715. }
  3716. /*
  3717. * The available vpd length cannot be bigger than the
  3718. * DMA buffer passed to the port. Catch the less than
  3719. * case and update the caller's size.
  3720. */
  3721. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3722. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3723. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3724. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3725. dmabuf->virt, dmabuf->phys);
  3726. kfree(dmabuf);
  3727. return 0;
  3728. }
  3729. /**
  3730. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3731. * @phba: pointer to lpfc hba data structure.
  3732. *
  3733. * This routine is called to explicitly arm the SLI4 device's completion and
  3734. * event queues
  3735. **/
  3736. static void
  3737. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3738. {
  3739. uint8_t fcp_eqidx;
  3740. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3741. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3742. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3743. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3744. LPFC_QUEUE_REARM);
  3745. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3746. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3747. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3748. LPFC_QUEUE_REARM);
  3749. }
  3750. /**
  3751. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3752. * @phba: Pointer to HBA context object.
  3753. *
  3754. * This function is the main SLI4 device intialization PCI function. This
  3755. * function is called by the HBA intialization code, HBA reset code and
  3756. * HBA error attention handler code. Caller is not required to hold any
  3757. * locks.
  3758. **/
  3759. int
  3760. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3761. {
  3762. int rc;
  3763. LPFC_MBOXQ_t *mboxq;
  3764. struct lpfc_mqe *mqe;
  3765. uint8_t *vpd;
  3766. uint32_t vpd_size;
  3767. uint32_t ftr_rsp = 0;
  3768. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3769. struct lpfc_vport *vport = phba->pport;
  3770. struct lpfc_dmabuf *mp;
  3771. /* Perform a PCI function reset to start from clean */
  3772. rc = lpfc_pci_function_reset(phba);
  3773. if (unlikely(rc))
  3774. return -ENODEV;
  3775. /* Check the HBA Host Status Register for readyness */
  3776. rc = lpfc_sli4_post_status_check(phba);
  3777. if (unlikely(rc))
  3778. return -ENODEV;
  3779. else {
  3780. spin_lock_irq(&phba->hbalock);
  3781. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3782. spin_unlock_irq(&phba->hbalock);
  3783. }
  3784. /*
  3785. * Allocate a single mailbox container for initializing the
  3786. * port.
  3787. */
  3788. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3789. if (!mboxq)
  3790. return -ENOMEM;
  3791. /*
  3792. * Continue initialization with default values even if driver failed
  3793. * to read FCoE param config regions
  3794. */
  3795. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3796. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3797. "2570 Failed to read FCoE parameters\n");
  3798. /* Issue READ_REV to collect vpd and FW information. */
  3799. vpd_size = PAGE_SIZE;
  3800. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3801. if (!vpd) {
  3802. rc = -ENOMEM;
  3803. goto out_free_mbox;
  3804. }
  3805. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3806. if (unlikely(rc))
  3807. goto out_free_vpd;
  3808. mqe = &mboxq->u.mqe;
  3809. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3810. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3811. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3812. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3813. LPFC_DCBX_CEE_MODE)
  3814. phba->hba_flag |= HBA_FIP_SUPPORT;
  3815. else
  3816. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3817. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3818. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3819. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3820. "0376 READ_REV Error. SLI Level %d "
  3821. "FCoE enabled %d\n",
  3822. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3823. rc = -EIO;
  3824. goto out_free_vpd;
  3825. }
  3826. /*
  3827. * Evaluate the read rev and vpd data. Populate the driver
  3828. * state with the results. If this routine fails, the failure
  3829. * is not fatal as the driver will use generic values.
  3830. */
  3831. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3832. if (unlikely(!rc)) {
  3833. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3834. "0377 Error %d parsing vpd. "
  3835. "Using defaults.\n", rc);
  3836. rc = 0;
  3837. }
  3838. /* Save information as VPD data */
  3839. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3840. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3841. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3842. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3843. &mqe->un.read_rev);
  3844. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3845. &mqe->un.read_rev);
  3846. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3847. &mqe->un.read_rev);
  3848. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3849. &mqe->un.read_rev);
  3850. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3851. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3852. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3853. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3854. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3855. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3856. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3857. "(%d):0380 READ_REV Status x%x "
  3858. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3859. mboxq->vport ? mboxq->vport->vpi : 0,
  3860. bf_get(lpfc_mqe_status, mqe),
  3861. phba->vpd.rev.opFwName,
  3862. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3863. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3864. /*
  3865. * Discover the port's supported feature set and match it against the
  3866. * hosts requests.
  3867. */
  3868. lpfc_request_features(phba, mboxq);
  3869. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3870. if (unlikely(rc)) {
  3871. rc = -EIO;
  3872. goto out_free_vpd;
  3873. }
  3874. /*
  3875. * The port must support FCP initiator mode as this is the
  3876. * only mode running in the host.
  3877. */
  3878. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3879. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3880. "0378 No support for fcpi mode.\n");
  3881. ftr_rsp++;
  3882. }
  3883. /*
  3884. * If the port cannot support the host's requested features
  3885. * then turn off the global config parameters to disable the
  3886. * feature in the driver. This is not a fatal error.
  3887. */
  3888. if ((phba->cfg_enable_bg) &&
  3889. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3890. ftr_rsp++;
  3891. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3892. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3893. ftr_rsp++;
  3894. if (ftr_rsp) {
  3895. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3896. "0379 Feature Mismatch Data: x%08x %08x "
  3897. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3898. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3899. phba->cfg_enable_npiv, phba->max_vpi);
  3900. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3901. phba->cfg_enable_bg = 0;
  3902. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3903. phba->cfg_enable_npiv = 0;
  3904. }
  3905. /* These SLI3 features are assumed in SLI4 */
  3906. spin_lock_irq(&phba->hbalock);
  3907. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  3908. spin_unlock_irq(&phba->hbalock);
  3909. /* Read the port's service parameters. */
  3910. lpfc_read_sparam(phba, mboxq, vport->vpi);
  3911. mboxq->vport = vport;
  3912. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3913. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3914. if (rc == MBX_SUCCESS) {
  3915. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  3916. rc = 0;
  3917. }
  3918. /*
  3919. * This memory was allocated by the lpfc_read_sparam routine. Release
  3920. * it to the mbuf pool.
  3921. */
  3922. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3923. kfree(mp);
  3924. mboxq->context1 = NULL;
  3925. if (unlikely(rc)) {
  3926. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3927. "0382 READ_SPARAM command failed "
  3928. "status %d, mbxStatus x%x\n",
  3929. rc, bf_get(lpfc_mqe_status, mqe));
  3930. phba->link_state = LPFC_HBA_ERROR;
  3931. rc = -EIO;
  3932. goto out_free_vpd;
  3933. }
  3934. if (phba->cfg_soft_wwnn)
  3935. u64_to_wwn(phba->cfg_soft_wwnn,
  3936. vport->fc_sparam.nodeName.u.wwn);
  3937. if (phba->cfg_soft_wwpn)
  3938. u64_to_wwn(phba->cfg_soft_wwpn,
  3939. vport->fc_sparam.portName.u.wwn);
  3940. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  3941. sizeof(struct lpfc_name));
  3942. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  3943. sizeof(struct lpfc_name));
  3944. /* Update the fc_host data structures with new wwn. */
  3945. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  3946. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  3947. /* Register SGL pool to the device using non-embedded mailbox command */
  3948. rc = lpfc_sli4_post_sgl_list(phba);
  3949. if (unlikely(rc)) {
  3950. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3951. "0582 Error %d during sgl post operation\n",
  3952. rc);
  3953. rc = -ENODEV;
  3954. goto out_free_vpd;
  3955. }
  3956. /* Register SCSI SGL pool to the device */
  3957. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  3958. if (unlikely(rc)) {
  3959. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3960. "0383 Error %d during scsi sgl post "
  3961. "operation\n", rc);
  3962. /* Some Scsi buffers were moved to the abort scsi list */
  3963. /* A pci function reset will repost them */
  3964. rc = -ENODEV;
  3965. goto out_free_vpd;
  3966. }
  3967. /* Post the rpi header region to the device. */
  3968. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  3969. if (unlikely(rc)) {
  3970. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3971. "0393 Error %d during rpi post operation\n",
  3972. rc);
  3973. rc = -ENODEV;
  3974. goto out_free_vpd;
  3975. }
  3976. /* Set up all the queues to the device */
  3977. rc = lpfc_sli4_queue_setup(phba);
  3978. if (unlikely(rc)) {
  3979. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3980. "0381 Error %d during queue setup.\n ", rc);
  3981. goto out_stop_timers;
  3982. }
  3983. /* Arm the CQs and then EQs on device */
  3984. lpfc_sli4_arm_cqeq_intr(phba);
  3985. /* Indicate device interrupt mode */
  3986. phba->sli4_hba.intr_enable = 1;
  3987. /* Allow asynchronous mailbox command to go through */
  3988. spin_lock_irq(&phba->hbalock);
  3989. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3990. spin_unlock_irq(&phba->hbalock);
  3991. /* Post receive buffers to the device */
  3992. lpfc_sli4_rb_setup(phba);
  3993. /* Start the ELS watchdog timer */
  3994. mod_timer(&vport->els_tmofunc,
  3995. jiffies + HZ * (phba->fc_ratov * 2));
  3996. /* Start heart beat timer */
  3997. mod_timer(&phba->hb_tmofunc,
  3998. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  3999. phba->hb_outstanding = 0;
  4000. phba->last_completion_time = jiffies;
  4001. /* Start error attention (ERATT) polling timer */
  4002. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4003. /*
  4004. * The port is ready, set the host's link state to LINK_DOWN
  4005. * in preparation for link interrupts.
  4006. */
  4007. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4008. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4009. lpfc_set_loopback_flag(phba);
  4010. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4011. spin_lock_irq(&phba->hbalock);
  4012. phba->link_state = LPFC_LINK_DOWN;
  4013. spin_unlock_irq(&phba->hbalock);
  4014. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4015. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4016. kfree(vpd);
  4017. return 0;
  4018. } else
  4019. rc = -EIO;
  4020. /* Unset all the queues set up in this routine when error out */
  4021. if (rc)
  4022. lpfc_sli4_queue_unset(phba);
  4023. out_stop_timers:
  4024. if (rc)
  4025. lpfc_stop_hba_timers(phba);
  4026. out_free_vpd:
  4027. kfree(vpd);
  4028. out_free_mbox:
  4029. mempool_free(mboxq, phba->mbox_mem_pool);
  4030. return rc;
  4031. }
  4032. /**
  4033. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4034. * @ptr: context object - pointer to hba structure.
  4035. *
  4036. * This is the callback function for mailbox timer. The mailbox
  4037. * timer is armed when a new mailbox command is issued and the timer
  4038. * is deleted when the mailbox complete. The function is called by
  4039. * the kernel timer code when a mailbox does not complete within
  4040. * expected time. This function wakes up the worker thread to
  4041. * process the mailbox timeout and returns. All the processing is
  4042. * done by the worker thread function lpfc_mbox_timeout_handler.
  4043. **/
  4044. void
  4045. lpfc_mbox_timeout(unsigned long ptr)
  4046. {
  4047. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4048. unsigned long iflag;
  4049. uint32_t tmo_posted;
  4050. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4051. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4052. if (!tmo_posted)
  4053. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4054. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4055. if (!tmo_posted)
  4056. lpfc_worker_wake_up(phba);
  4057. return;
  4058. }
  4059. /**
  4060. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4061. * @phba: Pointer to HBA context object.
  4062. *
  4063. * This function is called from worker thread when a mailbox command times out.
  4064. * The caller is not required to hold any locks. This function will reset the
  4065. * HBA and recover all the pending commands.
  4066. **/
  4067. void
  4068. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4069. {
  4070. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4071. MAILBOX_t *mb = &pmbox->u.mb;
  4072. struct lpfc_sli *psli = &phba->sli;
  4073. struct lpfc_sli_ring *pring;
  4074. /* Check the pmbox pointer first. There is a race condition
  4075. * between the mbox timeout handler getting executed in the
  4076. * worklist and the mailbox actually completing. When this
  4077. * race condition occurs, the mbox_active will be NULL.
  4078. */
  4079. spin_lock_irq(&phba->hbalock);
  4080. if (pmbox == NULL) {
  4081. lpfc_printf_log(phba, KERN_WARNING,
  4082. LOG_MBOX | LOG_SLI,
  4083. "0353 Active Mailbox cleared - mailbox timeout "
  4084. "exiting\n");
  4085. spin_unlock_irq(&phba->hbalock);
  4086. return;
  4087. }
  4088. /* Mbox cmd <mbxCommand> timeout */
  4089. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4090. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4091. mb->mbxCommand,
  4092. phba->pport->port_state,
  4093. phba->sli.sli_flag,
  4094. phba->sli.mbox_active);
  4095. spin_unlock_irq(&phba->hbalock);
  4096. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4097. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4098. * it to fail all oustanding SCSI IO.
  4099. */
  4100. spin_lock_irq(&phba->pport->work_port_lock);
  4101. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4102. spin_unlock_irq(&phba->pport->work_port_lock);
  4103. spin_lock_irq(&phba->hbalock);
  4104. phba->link_state = LPFC_LINK_UNKNOWN;
  4105. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4106. spin_unlock_irq(&phba->hbalock);
  4107. pring = &psli->ring[psli->fcp_ring];
  4108. lpfc_sli_abort_iocb_ring(phba, pring);
  4109. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4110. "0345 Resetting board due to mailbox timeout\n");
  4111. /* Reset the HBA device */
  4112. lpfc_reset_hba(phba);
  4113. }
  4114. /**
  4115. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4116. * @phba: Pointer to HBA context object.
  4117. * @pmbox: Pointer to mailbox object.
  4118. * @flag: Flag indicating how the mailbox need to be processed.
  4119. *
  4120. * This function is called by discovery code and HBA management code
  4121. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4122. * function gets the hbalock to protect the data structures.
  4123. * The mailbox command can be submitted in polling mode, in which case
  4124. * this function will wait in a polling loop for the completion of the
  4125. * mailbox.
  4126. * If the mailbox is submitted in no_wait mode (not polling) the
  4127. * function will submit the command and returns immediately without waiting
  4128. * for the mailbox completion. The no_wait is supported only when HBA
  4129. * is in SLI2/SLI3 mode - interrupts are enabled.
  4130. * The SLI interface allows only one mailbox pending at a time. If the
  4131. * mailbox is issued in polling mode and there is already a mailbox
  4132. * pending, then the function will return an error. If the mailbox is issued
  4133. * in NO_WAIT mode and there is a mailbox pending already, the function
  4134. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4135. * The sli layer owns the mailbox object until the completion of mailbox
  4136. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4137. * return codes the caller owns the mailbox command after the return of
  4138. * the function.
  4139. **/
  4140. static int
  4141. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4142. uint32_t flag)
  4143. {
  4144. MAILBOX_t *mb;
  4145. struct lpfc_sli *psli = &phba->sli;
  4146. uint32_t status, evtctr;
  4147. uint32_t ha_copy;
  4148. int i;
  4149. unsigned long timeout;
  4150. unsigned long drvr_flag = 0;
  4151. uint32_t word0, ldata;
  4152. void __iomem *to_slim;
  4153. int processing_queue = 0;
  4154. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4155. if (!pmbox) {
  4156. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4157. /* processing mbox queue from intr_handler */
  4158. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4159. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4160. return MBX_SUCCESS;
  4161. }
  4162. processing_queue = 1;
  4163. pmbox = lpfc_mbox_get(phba);
  4164. if (!pmbox) {
  4165. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4166. return MBX_SUCCESS;
  4167. }
  4168. }
  4169. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4170. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4171. if(!pmbox->vport) {
  4172. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4173. lpfc_printf_log(phba, KERN_ERR,
  4174. LOG_MBOX | LOG_VPORT,
  4175. "1806 Mbox x%x failed. No vport\n",
  4176. pmbox->u.mb.mbxCommand);
  4177. dump_stack();
  4178. goto out_not_finished;
  4179. }
  4180. }
  4181. /* If the PCI channel is in offline state, do not post mbox. */
  4182. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4183. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4184. goto out_not_finished;
  4185. }
  4186. /* If HBA has a deferred error attention, fail the iocb. */
  4187. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4188. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4189. goto out_not_finished;
  4190. }
  4191. psli = &phba->sli;
  4192. mb = &pmbox->u.mb;
  4193. status = MBX_SUCCESS;
  4194. if (phba->link_state == LPFC_HBA_ERROR) {
  4195. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4196. /* Mbox command <mbxCommand> cannot issue */
  4197. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4198. "(%d):0311 Mailbox command x%x cannot "
  4199. "issue Data: x%x x%x\n",
  4200. pmbox->vport ? pmbox->vport->vpi : 0,
  4201. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4202. goto out_not_finished;
  4203. }
  4204. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4205. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4206. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4207. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4208. "(%d):2528 Mailbox command x%x cannot "
  4209. "issue Data: x%x x%x\n",
  4210. pmbox->vport ? pmbox->vport->vpi : 0,
  4211. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4212. goto out_not_finished;
  4213. }
  4214. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4215. /* Polling for a mbox command when another one is already active
  4216. * is not allowed in SLI. Also, the driver must have established
  4217. * SLI2 mode to queue and process multiple mbox commands.
  4218. */
  4219. if (flag & MBX_POLL) {
  4220. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4221. /* Mbox command <mbxCommand> cannot issue */
  4222. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4223. "(%d):2529 Mailbox command x%x "
  4224. "cannot issue Data: x%x x%x\n",
  4225. pmbox->vport ? pmbox->vport->vpi : 0,
  4226. pmbox->u.mb.mbxCommand,
  4227. psli->sli_flag, flag);
  4228. goto out_not_finished;
  4229. }
  4230. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4231. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4232. /* Mbox command <mbxCommand> cannot issue */
  4233. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4234. "(%d):2530 Mailbox command x%x "
  4235. "cannot issue Data: x%x x%x\n",
  4236. pmbox->vport ? pmbox->vport->vpi : 0,
  4237. pmbox->u.mb.mbxCommand,
  4238. psli->sli_flag, flag);
  4239. goto out_not_finished;
  4240. }
  4241. /* Another mailbox command is still being processed, queue this
  4242. * command to be processed later.
  4243. */
  4244. lpfc_mbox_put(phba, pmbox);
  4245. /* Mbox cmd issue - BUSY */
  4246. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4247. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4248. "x%x x%x x%x x%x\n",
  4249. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4250. mb->mbxCommand, phba->pport->port_state,
  4251. psli->sli_flag, flag);
  4252. psli->slistat.mbox_busy++;
  4253. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4254. if (pmbox->vport) {
  4255. lpfc_debugfs_disc_trc(pmbox->vport,
  4256. LPFC_DISC_TRC_MBOX_VPORT,
  4257. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4258. (uint32_t)mb->mbxCommand,
  4259. mb->un.varWords[0], mb->un.varWords[1]);
  4260. }
  4261. else {
  4262. lpfc_debugfs_disc_trc(phba->pport,
  4263. LPFC_DISC_TRC_MBOX,
  4264. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4265. (uint32_t)mb->mbxCommand,
  4266. mb->un.varWords[0], mb->un.varWords[1]);
  4267. }
  4268. return MBX_BUSY;
  4269. }
  4270. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4271. /* If we are not polling, we MUST be in SLI2 mode */
  4272. if (flag != MBX_POLL) {
  4273. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4274. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4275. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4276. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4277. /* Mbox command <mbxCommand> cannot issue */
  4278. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4279. "(%d):2531 Mailbox command x%x "
  4280. "cannot issue Data: x%x x%x\n",
  4281. pmbox->vport ? pmbox->vport->vpi : 0,
  4282. pmbox->u.mb.mbxCommand,
  4283. psli->sli_flag, flag);
  4284. goto out_not_finished;
  4285. }
  4286. /* timeout active mbox command */
  4287. mod_timer(&psli->mbox_tmo, (jiffies +
  4288. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4289. }
  4290. /* Mailbox cmd <cmd> issue */
  4291. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4292. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4293. "x%x\n",
  4294. pmbox->vport ? pmbox->vport->vpi : 0,
  4295. mb->mbxCommand, phba->pport->port_state,
  4296. psli->sli_flag, flag);
  4297. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4298. if (pmbox->vport) {
  4299. lpfc_debugfs_disc_trc(pmbox->vport,
  4300. LPFC_DISC_TRC_MBOX_VPORT,
  4301. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4302. (uint32_t)mb->mbxCommand,
  4303. mb->un.varWords[0], mb->un.varWords[1]);
  4304. }
  4305. else {
  4306. lpfc_debugfs_disc_trc(phba->pport,
  4307. LPFC_DISC_TRC_MBOX,
  4308. "MBOX Send: cmd:x%x mb:x%x x%x",
  4309. (uint32_t)mb->mbxCommand,
  4310. mb->un.varWords[0], mb->un.varWords[1]);
  4311. }
  4312. }
  4313. psli->slistat.mbox_cmd++;
  4314. evtctr = psli->slistat.mbox_event;
  4315. /* next set own bit for the adapter and copy over command word */
  4316. mb->mbxOwner = OWN_CHIP;
  4317. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4318. /* First copy command data to host SLIM area */
  4319. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4320. } else {
  4321. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4322. /* copy command data into host mbox for cmpl */
  4323. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4324. }
  4325. /* First copy mbox command data to HBA SLIM, skip past first
  4326. word */
  4327. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4328. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4329. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4330. /* Next copy over first word, with mbxOwner set */
  4331. ldata = *((uint32_t *)mb);
  4332. to_slim = phba->MBslimaddr;
  4333. writel(ldata, to_slim);
  4334. readl(to_slim); /* flush */
  4335. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4336. /* switch over to host mailbox */
  4337. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4338. }
  4339. }
  4340. wmb();
  4341. switch (flag) {
  4342. case MBX_NOWAIT:
  4343. /* Set up reference to mailbox command */
  4344. psli->mbox_active = pmbox;
  4345. /* Interrupt board to do it */
  4346. writel(CA_MBATT, phba->CAregaddr);
  4347. readl(phba->CAregaddr); /* flush */
  4348. /* Don't wait for it to finish, just return */
  4349. break;
  4350. case MBX_POLL:
  4351. /* Set up null reference to mailbox command */
  4352. psli->mbox_active = NULL;
  4353. /* Interrupt board to do it */
  4354. writel(CA_MBATT, phba->CAregaddr);
  4355. readl(phba->CAregaddr); /* flush */
  4356. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4357. /* First read mbox status word */
  4358. word0 = *((uint32_t *)phba->mbox);
  4359. word0 = le32_to_cpu(word0);
  4360. } else {
  4361. /* First read mbox status word */
  4362. word0 = readl(phba->MBslimaddr);
  4363. }
  4364. /* Read the HBA Host Attention Register */
  4365. ha_copy = readl(phba->HAregaddr);
  4366. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4367. mb->mbxCommand) *
  4368. 1000) + jiffies;
  4369. i = 0;
  4370. /* Wait for command to complete */
  4371. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4372. (!(ha_copy & HA_MBATT) &&
  4373. (phba->link_state > LPFC_WARM_START))) {
  4374. if (time_after(jiffies, timeout)) {
  4375. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4376. spin_unlock_irqrestore(&phba->hbalock,
  4377. drvr_flag);
  4378. goto out_not_finished;
  4379. }
  4380. /* Check if we took a mbox interrupt while we were
  4381. polling */
  4382. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4383. && (evtctr != psli->slistat.mbox_event))
  4384. break;
  4385. if (i++ > 10) {
  4386. spin_unlock_irqrestore(&phba->hbalock,
  4387. drvr_flag);
  4388. msleep(1);
  4389. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4390. }
  4391. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4392. /* First copy command data */
  4393. word0 = *((uint32_t *)phba->mbox);
  4394. word0 = le32_to_cpu(word0);
  4395. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4396. MAILBOX_t *slimmb;
  4397. uint32_t slimword0;
  4398. /* Check real SLIM for any errors */
  4399. slimword0 = readl(phba->MBslimaddr);
  4400. slimmb = (MAILBOX_t *) & slimword0;
  4401. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4402. && slimmb->mbxStatus) {
  4403. psli->sli_flag &=
  4404. ~LPFC_SLI_ACTIVE;
  4405. word0 = slimword0;
  4406. }
  4407. }
  4408. } else {
  4409. /* First copy command data */
  4410. word0 = readl(phba->MBslimaddr);
  4411. }
  4412. /* Read the HBA Host Attention Register */
  4413. ha_copy = readl(phba->HAregaddr);
  4414. }
  4415. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4416. /* copy results back to user */
  4417. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4418. } else {
  4419. /* First copy command data */
  4420. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4421. MAILBOX_CMD_SIZE);
  4422. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4423. pmbox->context2) {
  4424. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4425. phba->MBslimaddr + DMP_RSP_OFFSET,
  4426. mb->un.varDmp.word_cnt);
  4427. }
  4428. }
  4429. writel(HA_MBATT, phba->HAregaddr);
  4430. readl(phba->HAregaddr); /* flush */
  4431. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4432. status = mb->mbxStatus;
  4433. }
  4434. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4435. return status;
  4436. out_not_finished:
  4437. if (processing_queue) {
  4438. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4439. lpfc_mbox_cmpl_put(phba, pmbox);
  4440. }
  4441. return MBX_NOT_FINISHED;
  4442. }
  4443. /**
  4444. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4445. * @phba: Pointer to HBA context object.
  4446. *
  4447. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4448. * the driver internal pending mailbox queue. It will then try to wait out the
  4449. * possible outstanding mailbox command before return.
  4450. *
  4451. * Returns:
  4452. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4453. * the outstanding mailbox command timed out.
  4454. **/
  4455. static int
  4456. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4457. {
  4458. struct lpfc_sli *psli = &phba->sli;
  4459. uint8_t actcmd = MBX_HEARTBEAT;
  4460. int rc = 0;
  4461. unsigned long timeout;
  4462. /* Mark the asynchronous mailbox command posting as blocked */
  4463. spin_lock_irq(&phba->hbalock);
  4464. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4465. if (phba->sli.mbox_active)
  4466. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4467. spin_unlock_irq(&phba->hbalock);
  4468. /* Determine how long we might wait for the active mailbox
  4469. * command to be gracefully completed by firmware.
  4470. */
  4471. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4472. jiffies;
  4473. /* Wait for the outstnading mailbox command to complete */
  4474. while (phba->sli.mbox_active) {
  4475. /* Check active mailbox complete status every 2ms */
  4476. msleep(2);
  4477. if (time_after(jiffies, timeout)) {
  4478. /* Timeout, marked the outstanding cmd not complete */
  4479. rc = 1;
  4480. break;
  4481. }
  4482. }
  4483. /* Can not cleanly block async mailbox command, fails it */
  4484. if (rc) {
  4485. spin_lock_irq(&phba->hbalock);
  4486. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4487. spin_unlock_irq(&phba->hbalock);
  4488. }
  4489. return rc;
  4490. }
  4491. /**
  4492. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4493. * @phba: Pointer to HBA context object.
  4494. *
  4495. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4496. * commands from the driver internal pending mailbox queue. It makes sure
  4497. * that there is no outstanding mailbox command before resuming posting
  4498. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4499. * mailbox command, it will try to wait it out before resuming asynchronous
  4500. * mailbox command posting.
  4501. **/
  4502. static void
  4503. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4504. {
  4505. struct lpfc_sli *psli = &phba->sli;
  4506. spin_lock_irq(&phba->hbalock);
  4507. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4508. /* Asynchronous mailbox posting is not blocked, do nothing */
  4509. spin_unlock_irq(&phba->hbalock);
  4510. return;
  4511. }
  4512. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4513. * successful or timeout, after timing-out the outstanding mailbox
  4514. * command shall always be removed, so just unblock posting async
  4515. * mailbox command and resume
  4516. */
  4517. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4518. spin_unlock_irq(&phba->hbalock);
  4519. /* wake up worker thread to post asynchronlous mailbox command */
  4520. lpfc_worker_wake_up(phba);
  4521. }
  4522. /**
  4523. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4524. * @phba: Pointer to HBA context object.
  4525. * @mboxq: Pointer to mailbox object.
  4526. *
  4527. * The function posts a mailbox to the port. The mailbox is expected
  4528. * to be comletely filled in and ready for the port to operate on it.
  4529. * This routine executes a synchronous completion operation on the
  4530. * mailbox by polling for its completion.
  4531. *
  4532. * The caller must not be holding any locks when calling this routine.
  4533. *
  4534. * Returns:
  4535. * MBX_SUCCESS - mailbox posted successfully
  4536. * Any of the MBX error values.
  4537. **/
  4538. static int
  4539. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4540. {
  4541. int rc = MBX_SUCCESS;
  4542. unsigned long iflag;
  4543. uint32_t db_ready;
  4544. uint32_t mcqe_status;
  4545. uint32_t mbx_cmnd;
  4546. unsigned long timeout;
  4547. struct lpfc_sli *psli = &phba->sli;
  4548. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4549. struct lpfc_bmbx_create *mbox_rgn;
  4550. struct dma_address *dma_address;
  4551. struct lpfc_register bmbx_reg;
  4552. /*
  4553. * Only one mailbox can be active to the bootstrap mailbox region
  4554. * at a time and there is no queueing provided.
  4555. */
  4556. spin_lock_irqsave(&phba->hbalock, iflag);
  4557. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4558. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4559. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4560. "(%d):2532 Mailbox command x%x (x%x) "
  4561. "cannot issue Data: x%x x%x\n",
  4562. mboxq->vport ? mboxq->vport->vpi : 0,
  4563. mboxq->u.mb.mbxCommand,
  4564. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4565. psli->sli_flag, MBX_POLL);
  4566. return MBXERR_ERROR;
  4567. }
  4568. /* The server grabs the token and owns it until release */
  4569. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4570. phba->sli.mbox_active = mboxq;
  4571. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4572. /*
  4573. * Initialize the bootstrap memory region to avoid stale data areas
  4574. * in the mailbox post. Then copy the caller's mailbox contents to
  4575. * the bmbx mailbox region.
  4576. */
  4577. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4578. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4579. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4580. sizeof(struct lpfc_mqe));
  4581. /* Post the high mailbox dma address to the port and wait for ready. */
  4582. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4583. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4584. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4585. * 1000) + jiffies;
  4586. do {
  4587. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4588. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4589. if (!db_ready)
  4590. msleep(2);
  4591. if (time_after(jiffies, timeout)) {
  4592. rc = MBXERR_ERROR;
  4593. goto exit;
  4594. }
  4595. } while (!db_ready);
  4596. /* Post the low mailbox dma address to the port. */
  4597. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4598. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4599. * 1000) + jiffies;
  4600. do {
  4601. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4602. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4603. if (!db_ready)
  4604. msleep(2);
  4605. if (time_after(jiffies, timeout)) {
  4606. rc = MBXERR_ERROR;
  4607. goto exit;
  4608. }
  4609. } while (!db_ready);
  4610. /*
  4611. * Read the CQ to ensure the mailbox has completed.
  4612. * If so, update the mailbox status so that the upper layers
  4613. * can complete the request normally.
  4614. */
  4615. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4616. sizeof(struct lpfc_mqe));
  4617. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4618. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4619. sizeof(struct lpfc_mcqe));
  4620. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4621. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4622. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4623. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4624. rc = MBXERR_ERROR;
  4625. }
  4626. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4627. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4628. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4629. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4630. mboxq->vport ? mboxq->vport->vpi : 0,
  4631. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4632. bf_get(lpfc_mqe_status, mb),
  4633. mb->un.mb_words[0], mb->un.mb_words[1],
  4634. mb->un.mb_words[2], mb->un.mb_words[3],
  4635. mb->un.mb_words[4], mb->un.mb_words[5],
  4636. mb->un.mb_words[6], mb->un.mb_words[7],
  4637. mb->un.mb_words[8], mb->un.mb_words[9],
  4638. mb->un.mb_words[10], mb->un.mb_words[11],
  4639. mb->un.mb_words[12], mboxq->mcqe.word0,
  4640. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4641. mboxq->mcqe.trailer);
  4642. exit:
  4643. /* We are holding the token, no needed for lock when release */
  4644. spin_lock_irqsave(&phba->hbalock, iflag);
  4645. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4646. phba->sli.mbox_active = NULL;
  4647. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4648. return rc;
  4649. }
  4650. /**
  4651. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4652. * @phba: Pointer to HBA context object.
  4653. * @pmbox: Pointer to mailbox object.
  4654. * @flag: Flag indicating how the mailbox need to be processed.
  4655. *
  4656. * This function is called by discovery code and HBA management code to submit
  4657. * a mailbox command to firmware with SLI-4 interface spec.
  4658. *
  4659. * Return codes the caller owns the mailbox command after the return of the
  4660. * function.
  4661. **/
  4662. static int
  4663. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4664. uint32_t flag)
  4665. {
  4666. struct lpfc_sli *psli = &phba->sli;
  4667. unsigned long iflags;
  4668. int rc;
  4669. rc = lpfc_mbox_dev_check(phba);
  4670. if (unlikely(rc)) {
  4671. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4672. "(%d):2544 Mailbox command x%x (x%x) "
  4673. "cannot issue Data: x%x x%x\n",
  4674. mboxq->vport ? mboxq->vport->vpi : 0,
  4675. mboxq->u.mb.mbxCommand,
  4676. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4677. psli->sli_flag, flag);
  4678. goto out_not_finished;
  4679. }
  4680. /* Detect polling mode and jump to a handler */
  4681. if (!phba->sli4_hba.intr_enable) {
  4682. if (flag == MBX_POLL)
  4683. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4684. else
  4685. rc = -EIO;
  4686. if (rc != MBX_SUCCESS)
  4687. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4688. "(%d):2541 Mailbox command x%x "
  4689. "(x%x) cannot issue Data: x%x x%x\n",
  4690. mboxq->vport ? mboxq->vport->vpi : 0,
  4691. mboxq->u.mb.mbxCommand,
  4692. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4693. psli->sli_flag, flag);
  4694. return rc;
  4695. } else if (flag == MBX_POLL) {
  4696. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4697. "(%d):2542 Try to issue mailbox command "
  4698. "x%x (x%x) synchronously ahead of async"
  4699. "mailbox command queue: x%x x%x\n",
  4700. mboxq->vport ? mboxq->vport->vpi : 0,
  4701. mboxq->u.mb.mbxCommand,
  4702. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4703. psli->sli_flag, flag);
  4704. /* Try to block the asynchronous mailbox posting */
  4705. rc = lpfc_sli4_async_mbox_block(phba);
  4706. if (!rc) {
  4707. /* Successfully blocked, now issue sync mbox cmd */
  4708. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4709. if (rc != MBX_SUCCESS)
  4710. lpfc_printf_log(phba, KERN_ERR,
  4711. LOG_MBOX | LOG_SLI,
  4712. "(%d):2597 Mailbox command "
  4713. "x%x (x%x) cannot issue "
  4714. "Data: x%x x%x\n",
  4715. mboxq->vport ?
  4716. mboxq->vport->vpi : 0,
  4717. mboxq->u.mb.mbxCommand,
  4718. lpfc_sli4_mbox_opcode_get(phba,
  4719. mboxq),
  4720. psli->sli_flag, flag);
  4721. /* Unblock the async mailbox posting afterward */
  4722. lpfc_sli4_async_mbox_unblock(phba);
  4723. }
  4724. return rc;
  4725. }
  4726. /* Now, interrupt mode asynchrous mailbox command */
  4727. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4728. if (rc) {
  4729. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4730. "(%d):2543 Mailbox command x%x (x%x) "
  4731. "cannot issue Data: x%x x%x\n",
  4732. mboxq->vport ? mboxq->vport->vpi : 0,
  4733. mboxq->u.mb.mbxCommand,
  4734. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4735. psli->sli_flag, flag);
  4736. goto out_not_finished;
  4737. }
  4738. /* Put the mailbox command to the driver internal FIFO */
  4739. psli->slistat.mbox_busy++;
  4740. spin_lock_irqsave(&phba->hbalock, iflags);
  4741. lpfc_mbox_put(phba, mboxq);
  4742. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4743. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4744. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4745. "x%x (x%x) x%x x%x x%x\n",
  4746. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4747. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4748. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4749. phba->pport->port_state,
  4750. psli->sli_flag, MBX_NOWAIT);
  4751. /* Wake up worker thread to transport mailbox command from head */
  4752. lpfc_worker_wake_up(phba);
  4753. return MBX_BUSY;
  4754. out_not_finished:
  4755. return MBX_NOT_FINISHED;
  4756. }
  4757. /**
  4758. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4759. * @phba: Pointer to HBA context object.
  4760. *
  4761. * This function is called by worker thread to send a mailbox command to
  4762. * SLI4 HBA firmware.
  4763. *
  4764. **/
  4765. int
  4766. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4767. {
  4768. struct lpfc_sli *psli = &phba->sli;
  4769. LPFC_MBOXQ_t *mboxq;
  4770. int rc = MBX_SUCCESS;
  4771. unsigned long iflags;
  4772. struct lpfc_mqe *mqe;
  4773. uint32_t mbx_cmnd;
  4774. /* Check interrupt mode before post async mailbox command */
  4775. if (unlikely(!phba->sli4_hba.intr_enable))
  4776. return MBX_NOT_FINISHED;
  4777. /* Check for mailbox command service token */
  4778. spin_lock_irqsave(&phba->hbalock, iflags);
  4779. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4780. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4781. return MBX_NOT_FINISHED;
  4782. }
  4783. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4784. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4785. return MBX_NOT_FINISHED;
  4786. }
  4787. if (unlikely(phba->sli.mbox_active)) {
  4788. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4789. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4790. "0384 There is pending active mailbox cmd\n");
  4791. return MBX_NOT_FINISHED;
  4792. }
  4793. /* Take the mailbox command service token */
  4794. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4795. /* Get the next mailbox command from head of queue */
  4796. mboxq = lpfc_mbox_get(phba);
  4797. /* If no more mailbox command waiting for post, we're done */
  4798. if (!mboxq) {
  4799. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4800. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4801. return MBX_SUCCESS;
  4802. }
  4803. phba->sli.mbox_active = mboxq;
  4804. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4805. /* Check device readiness for posting mailbox command */
  4806. rc = lpfc_mbox_dev_check(phba);
  4807. if (unlikely(rc))
  4808. /* Driver clean routine will clean up pending mailbox */
  4809. goto out_not_finished;
  4810. /* Prepare the mbox command to be posted */
  4811. mqe = &mboxq->u.mqe;
  4812. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4813. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4814. mod_timer(&psli->mbox_tmo, (jiffies +
  4815. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4816. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4817. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4818. "x%x x%x\n",
  4819. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4820. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4821. phba->pport->port_state, psli->sli_flag);
  4822. if (mbx_cmnd != MBX_HEARTBEAT) {
  4823. if (mboxq->vport) {
  4824. lpfc_debugfs_disc_trc(mboxq->vport,
  4825. LPFC_DISC_TRC_MBOX_VPORT,
  4826. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4827. mbx_cmnd, mqe->un.mb_words[0],
  4828. mqe->un.mb_words[1]);
  4829. } else {
  4830. lpfc_debugfs_disc_trc(phba->pport,
  4831. LPFC_DISC_TRC_MBOX,
  4832. "MBOX Send: cmd:x%x mb:x%x x%x",
  4833. mbx_cmnd, mqe->un.mb_words[0],
  4834. mqe->un.mb_words[1]);
  4835. }
  4836. }
  4837. psli->slistat.mbox_cmd++;
  4838. /* Post the mailbox command to the port */
  4839. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4840. if (rc != MBX_SUCCESS) {
  4841. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4842. "(%d):2533 Mailbox command x%x (x%x) "
  4843. "cannot issue Data: x%x x%x\n",
  4844. mboxq->vport ? mboxq->vport->vpi : 0,
  4845. mboxq->u.mb.mbxCommand,
  4846. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4847. psli->sli_flag, MBX_NOWAIT);
  4848. goto out_not_finished;
  4849. }
  4850. return rc;
  4851. out_not_finished:
  4852. spin_lock_irqsave(&phba->hbalock, iflags);
  4853. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4854. __lpfc_mbox_cmpl_put(phba, mboxq);
  4855. /* Release the token */
  4856. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4857. phba->sli.mbox_active = NULL;
  4858. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4859. return MBX_NOT_FINISHED;
  4860. }
  4861. /**
  4862. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4863. * @phba: Pointer to HBA context object.
  4864. * @pmbox: Pointer to mailbox object.
  4865. * @flag: Flag indicating how the mailbox need to be processed.
  4866. *
  4867. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4868. * the API jump table function pointer from the lpfc_hba struct.
  4869. *
  4870. * Return codes the caller owns the mailbox command after the return of the
  4871. * function.
  4872. **/
  4873. int
  4874. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4875. {
  4876. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4877. }
  4878. /**
  4879. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4880. * @phba: The hba struct for which this call is being executed.
  4881. * @dev_grp: The HBA PCI-Device group number.
  4882. *
  4883. * This routine sets up the mbox interface API function jump table in @phba
  4884. * struct.
  4885. * Returns: 0 - success, -ENODEV - failure.
  4886. **/
  4887. int
  4888. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4889. {
  4890. switch (dev_grp) {
  4891. case LPFC_PCI_DEV_LP:
  4892. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  4893. phba->lpfc_sli_handle_slow_ring_event =
  4894. lpfc_sli_handle_slow_ring_event_s3;
  4895. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  4896. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  4897. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  4898. break;
  4899. case LPFC_PCI_DEV_OC:
  4900. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  4901. phba->lpfc_sli_handle_slow_ring_event =
  4902. lpfc_sli_handle_slow_ring_event_s4;
  4903. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  4904. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  4905. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  4906. break;
  4907. default:
  4908. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4909. "1420 Invalid HBA PCI-device group: 0x%x\n",
  4910. dev_grp);
  4911. return -ENODEV;
  4912. break;
  4913. }
  4914. return 0;
  4915. }
  4916. /**
  4917. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  4918. * @phba: Pointer to HBA context object.
  4919. * @pring: Pointer to driver SLI ring object.
  4920. * @piocb: Pointer to address of newly added command iocb.
  4921. *
  4922. * This function is called with hbalock held to add a command
  4923. * iocb to the txq when SLI layer cannot submit the command iocb
  4924. * to the ring.
  4925. **/
  4926. static void
  4927. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  4928. struct lpfc_iocbq *piocb)
  4929. {
  4930. /* Insert the caller's iocb in the txq tail for later processing. */
  4931. list_add_tail(&piocb->list, &pring->txq);
  4932. pring->txq_cnt++;
  4933. }
  4934. /**
  4935. * lpfc_sli_next_iocb - Get the next iocb in the txq
  4936. * @phba: Pointer to HBA context object.
  4937. * @pring: Pointer to driver SLI ring object.
  4938. * @piocb: Pointer to address of newly added command iocb.
  4939. *
  4940. * This function is called with hbalock held before a new
  4941. * iocb is submitted to the firmware. This function checks
  4942. * txq to flush the iocbs in txq to Firmware before
  4943. * submitting new iocbs to the Firmware.
  4944. * If there are iocbs in the txq which need to be submitted
  4945. * to firmware, lpfc_sli_next_iocb returns the first element
  4946. * of the txq after dequeuing it from txq.
  4947. * If there is no iocb in the txq then the function will return
  4948. * *piocb and *piocb is set to NULL. Caller needs to check
  4949. * *piocb to find if there are more commands in the txq.
  4950. **/
  4951. static struct lpfc_iocbq *
  4952. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  4953. struct lpfc_iocbq **piocb)
  4954. {
  4955. struct lpfc_iocbq * nextiocb;
  4956. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  4957. if (!nextiocb) {
  4958. nextiocb = *piocb;
  4959. *piocb = NULL;
  4960. }
  4961. return nextiocb;
  4962. }
  4963. /**
  4964. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  4965. * @phba: Pointer to HBA context object.
  4966. * @ring_number: SLI ring number to issue iocb on.
  4967. * @piocb: Pointer to command iocb.
  4968. * @flag: Flag indicating if this command can be put into txq.
  4969. *
  4970. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  4971. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  4972. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  4973. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  4974. * this function allows only iocbs for posting buffers. This function finds
  4975. * next available slot in the command ring and posts the command to the
  4976. * available slot and writes the port attention register to request HBA start
  4977. * processing new iocb. If there is no slot available in the ring and
  4978. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  4979. * the function returns IOCB_BUSY.
  4980. *
  4981. * This function is called with hbalock held. The function will return success
  4982. * after it successfully submit the iocb to firmware or after adding to the
  4983. * txq.
  4984. **/
  4985. static int
  4986. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  4987. struct lpfc_iocbq *piocb, uint32_t flag)
  4988. {
  4989. struct lpfc_iocbq *nextiocb;
  4990. IOCB_t *iocb;
  4991. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  4992. if (piocb->iocb_cmpl && (!piocb->vport) &&
  4993. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  4994. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  4995. lpfc_printf_log(phba, KERN_ERR,
  4996. LOG_SLI | LOG_VPORT,
  4997. "1807 IOCB x%x failed. No vport\n",
  4998. piocb->iocb.ulpCommand);
  4999. dump_stack();
  5000. return IOCB_ERROR;
  5001. }
  5002. /* If the PCI channel is in offline state, do not post iocbs. */
  5003. if (unlikely(pci_channel_offline(phba->pcidev)))
  5004. return IOCB_ERROR;
  5005. /* If HBA has a deferred error attention, fail the iocb. */
  5006. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5007. return IOCB_ERROR;
  5008. /*
  5009. * We should never get an IOCB if we are in a < LINK_DOWN state
  5010. */
  5011. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5012. return IOCB_ERROR;
  5013. /*
  5014. * Check to see if we are blocking IOCB processing because of a
  5015. * outstanding event.
  5016. */
  5017. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5018. goto iocb_busy;
  5019. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5020. /*
  5021. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5022. * can be issued if the link is not up.
  5023. */
  5024. switch (piocb->iocb.ulpCommand) {
  5025. case CMD_GEN_REQUEST64_CR:
  5026. case CMD_GEN_REQUEST64_CX:
  5027. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5028. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5029. FC_RCTL_DD_UNSOL_CMD) ||
  5030. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5031. MENLO_TRANSPORT_TYPE))
  5032. goto iocb_busy;
  5033. break;
  5034. case CMD_QUE_RING_BUF_CN:
  5035. case CMD_QUE_RING_BUF64_CN:
  5036. /*
  5037. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5038. * completion, iocb_cmpl MUST be 0.
  5039. */
  5040. if (piocb->iocb_cmpl)
  5041. piocb->iocb_cmpl = NULL;
  5042. /*FALLTHROUGH*/
  5043. case CMD_CREATE_XRI_CR:
  5044. case CMD_CLOSE_XRI_CN:
  5045. case CMD_CLOSE_XRI_CX:
  5046. break;
  5047. default:
  5048. goto iocb_busy;
  5049. }
  5050. /*
  5051. * For FCP commands, we must be in a state where we can process link
  5052. * attention events.
  5053. */
  5054. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5055. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5056. goto iocb_busy;
  5057. }
  5058. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5059. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5060. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5061. if (iocb)
  5062. lpfc_sli_update_ring(phba, pring);
  5063. else
  5064. lpfc_sli_update_full_ring(phba, pring);
  5065. if (!piocb)
  5066. return IOCB_SUCCESS;
  5067. goto out_busy;
  5068. iocb_busy:
  5069. pring->stats.iocb_cmd_delay++;
  5070. out_busy:
  5071. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5072. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5073. return IOCB_SUCCESS;
  5074. }
  5075. return IOCB_BUSY;
  5076. }
  5077. /**
  5078. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5079. * @phba: Pointer to HBA context object.
  5080. * @piocb: Pointer to command iocb.
  5081. * @sglq: Pointer to the scatter gather queue object.
  5082. *
  5083. * This routine converts the bpl or bde that is in the IOCB
  5084. * to a sgl list for the sli4 hardware. The physical address
  5085. * of the bpl/bde is converted back to a virtual address.
  5086. * If the IOCB contains a BPL then the list of BDE's is
  5087. * converted to sli4_sge's. If the IOCB contains a single
  5088. * BDE then it is converted to a single sli_sge.
  5089. * The IOCB is still in cpu endianess so the contents of
  5090. * the bpl can be used without byte swapping.
  5091. *
  5092. * Returns valid XRI = Success, NO_XRI = Failure.
  5093. **/
  5094. static uint16_t
  5095. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5096. struct lpfc_sglq *sglq)
  5097. {
  5098. uint16_t xritag = NO_XRI;
  5099. struct ulp_bde64 *bpl = NULL;
  5100. struct ulp_bde64 bde;
  5101. struct sli4_sge *sgl = NULL;
  5102. IOCB_t *icmd;
  5103. int numBdes = 0;
  5104. int i = 0;
  5105. if (!piocbq || !sglq)
  5106. return xritag;
  5107. sgl = (struct sli4_sge *)sglq->sgl;
  5108. icmd = &piocbq->iocb;
  5109. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5110. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5111. sizeof(struct ulp_bde64);
  5112. /* The addrHigh and addrLow fields within the IOCB
  5113. * have not been byteswapped yet so there is no
  5114. * need to swap them back.
  5115. */
  5116. bpl = (struct ulp_bde64 *)
  5117. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5118. if (!bpl)
  5119. return xritag;
  5120. for (i = 0; i < numBdes; i++) {
  5121. /* Should already be byte swapped. */
  5122. sgl->addr_hi = bpl->addrHigh;
  5123. sgl->addr_lo = bpl->addrLow;
  5124. /* swap the size field back to the cpu so we
  5125. * can assign it to the sgl.
  5126. */
  5127. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5128. bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize);
  5129. if ((i+1) == numBdes)
  5130. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5131. else
  5132. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5133. sgl->word2 = cpu_to_le32(sgl->word2);
  5134. sgl->word3 = cpu_to_le32(sgl->word3);
  5135. bpl++;
  5136. sgl++;
  5137. }
  5138. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5139. /* The addrHigh and addrLow fields of the BDE have not
  5140. * been byteswapped yet so they need to be swapped
  5141. * before putting them in the sgl.
  5142. */
  5143. sgl->addr_hi =
  5144. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5145. sgl->addr_lo =
  5146. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5147. bf_set(lpfc_sli4_sge_len, sgl,
  5148. icmd->un.genreq64.bdl.bdeSize);
  5149. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5150. sgl->word2 = cpu_to_le32(sgl->word2);
  5151. sgl->word3 = cpu_to_le32(sgl->word3);
  5152. }
  5153. return sglq->sli4_xritag;
  5154. }
  5155. /**
  5156. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5157. * @phba: Pointer to HBA context object.
  5158. *
  5159. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5160. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5161. * held.
  5162. *
  5163. * Return: index into SLI4 fast-path FCP queue index.
  5164. **/
  5165. static uint32_t
  5166. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5167. {
  5168. ++phba->fcp_qidx;
  5169. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5170. phba->fcp_qidx = 0;
  5171. return phba->fcp_qidx;
  5172. }
  5173. /**
  5174. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5175. * @phba: Pointer to HBA context object.
  5176. * @piocb: Pointer to command iocb.
  5177. * @wqe: Pointer to the work queue entry.
  5178. *
  5179. * This routine converts the iocb command to its Work Queue Entry
  5180. * equivalent. The wqe pointer should not have any fields set when
  5181. * this routine is called because it will memcpy over them.
  5182. * This routine does not set the CQ_ID or the WQEC bits in the
  5183. * wqe.
  5184. *
  5185. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5186. **/
  5187. static int
  5188. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5189. union lpfc_wqe *wqe)
  5190. {
  5191. uint32_t payload_len = 0;
  5192. uint8_t ct = 0;
  5193. uint32_t fip;
  5194. uint32_t abort_tag;
  5195. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5196. uint8_t cmnd;
  5197. uint16_t xritag;
  5198. struct ulp_bde64 *bpl = NULL;
  5199. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5200. /* The fcp commands will set command type */
  5201. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5202. command_type = FCP_COMMAND;
  5203. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS))
  5204. command_type = ELS_COMMAND_FIP;
  5205. else
  5206. command_type = ELS_COMMAND_NON_FIP;
  5207. /* Some of the fields are in the right position already */
  5208. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5209. abort_tag = (uint32_t) iocbq->iotag;
  5210. xritag = iocbq->sli4_xritag;
  5211. wqe->words[7] = 0; /* The ct field has moved so reset */
  5212. /* words0-2 bpl convert bde */
  5213. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5214. bpl = (struct ulp_bde64 *)
  5215. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5216. if (!bpl)
  5217. return IOCB_ERROR;
  5218. /* Should already be byte swapped. */
  5219. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5220. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5221. /* swap the size field back to the cpu so we
  5222. * can assign it to the sgl.
  5223. */
  5224. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5225. payload_len = wqe->generic.bde.tus.f.bdeSize;
  5226. } else
  5227. payload_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5228. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5229. cmnd = iocbq->iocb.ulpCommand;
  5230. switch (iocbq->iocb.ulpCommand) {
  5231. case CMD_ELS_REQUEST64_CR:
  5232. if (!iocbq->iocb.ulpLe) {
  5233. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5234. "2007 Only Limited Edition cmd Format"
  5235. " supported 0x%x\n",
  5236. iocbq->iocb.ulpCommand);
  5237. return IOCB_ERROR;
  5238. }
  5239. wqe->els_req.payload_len = payload_len;
  5240. /* Els_reguest64 has a TMO */
  5241. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5242. iocbq->iocb.ulpTimeout);
  5243. /* Need a VF for word 4 set the vf bit*/
  5244. bf_set(els_req64_vf, &wqe->els_req, 0);
  5245. /* And a VFID for word 12 */
  5246. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5247. /*
  5248. * Set ct field to 3, indicates that the context_tag field
  5249. * contains the FCFI and remote N_Port_ID is
  5250. * in word 5.
  5251. */
  5252. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5253. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5254. iocbq->iocb.ulpContext);
  5255. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5256. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5257. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5258. break;
  5259. case CMD_XMIT_SEQUENCE64_CR:
  5260. /* word3 iocb=io_tag32 wqe=payload_offset */
  5261. /* payload offset used for multilpe outstanding
  5262. * sequences on the same exchange
  5263. */
  5264. wqe->words[3] = 0;
  5265. /* word4 relative_offset memcpy */
  5266. /* word5 r_ctl/df_ctl memcpy */
  5267. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5268. wqe->xmit_sequence.xmit_len = payload_len;
  5269. break;
  5270. case CMD_XMIT_BCAST64_CN:
  5271. /* word3 iocb=iotag32 wqe=payload_len */
  5272. wqe->words[3] = 0; /* no definition for this in wqe */
  5273. /* word4 iocb=rsvd wqe=rsvd */
  5274. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5275. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5276. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5277. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5278. break;
  5279. case CMD_FCP_IWRITE64_CR:
  5280. command_type = FCP_COMMAND_DATA_OUT;
  5281. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5282. * confusing.
  5283. * word3 is payload_len: byte offset to the sgl entry for the
  5284. * fcp_command.
  5285. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5286. * word5 is initial xfer len 0 = wait for xfer-ready
  5287. */
  5288. /* Always wait for xfer-ready before sending data */
  5289. wqe->fcp_iwrite.initial_xfer_len = 0;
  5290. /* word 4 (xfer length) should have been set on the memcpy */
  5291. /* allow write to fall through to read */
  5292. case CMD_FCP_IREAD64_CR:
  5293. /* FCP_CMD is always the 1st sgl entry */
  5294. wqe->fcp_iread.payload_len =
  5295. payload_len + sizeof(struct fcp_rsp);
  5296. /* word 4 (xfer length) should have been set on the memcpy */
  5297. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5298. iocbq->iocb.ulpFCP2Rcvy);
  5299. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5300. /* The XC bit and the XS bit are similar. The driver never
  5301. * tracked whether or not the exchange was previouslly open.
  5302. * XC = Exchange create, 0 is create. 1 is already open.
  5303. * XS = link cmd: 1 do not close the exchange after command.
  5304. * XS = 0 close exchange when command completes.
  5305. * The only time we would not set the XC bit is when the XS bit
  5306. * is set and we are sending our 2nd or greater command on
  5307. * this exchange.
  5308. */
  5309. /* Always open the exchange */
  5310. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5311. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5312. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5313. break;
  5314. case CMD_FCP_ICMND64_CR:
  5315. /* Always open the exchange */
  5316. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5317. wqe->words[4] = 0;
  5318. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5319. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5320. break;
  5321. case CMD_GEN_REQUEST64_CR:
  5322. /* word3 command length is described as byte offset to the
  5323. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5324. * sgl[0] = cmnd
  5325. * sgl[1] = rsp.
  5326. *
  5327. */
  5328. wqe->gen_req.command_len = payload_len;
  5329. /* Word4 parameter copied in the memcpy */
  5330. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5331. /* word6 context tag copied in memcpy */
  5332. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5333. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5334. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5335. "2015 Invalid CT %x command 0x%x\n",
  5336. ct, iocbq->iocb.ulpCommand);
  5337. return IOCB_ERROR;
  5338. }
  5339. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5340. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5341. iocbq->iocb.ulpTimeout);
  5342. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5343. command_type = OTHER_COMMAND;
  5344. break;
  5345. case CMD_XMIT_ELS_RSP64_CX:
  5346. /* words0-2 BDE memcpy */
  5347. /* word3 iocb=iotag32 wqe=rsvd */
  5348. wqe->words[3] = 0;
  5349. /* word4 iocb=did wge=rsvd. */
  5350. wqe->words[4] = 0;
  5351. /* word5 iocb=rsvd wge=did */
  5352. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5353. iocbq->iocb.un.elsreq64.remoteID);
  5354. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5355. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5356. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5357. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5358. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5359. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5360. iocbq->vport->vpi + phba->vpi_base);
  5361. command_type = OTHER_COMMAND;
  5362. break;
  5363. case CMD_CLOSE_XRI_CN:
  5364. case CMD_ABORT_XRI_CN:
  5365. case CMD_ABORT_XRI_CX:
  5366. /* words 0-2 memcpy should be 0 rserved */
  5367. /* port will send abts */
  5368. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5369. /*
  5370. * The link is down so the fw does not need to send abts
  5371. * on the wire.
  5372. */
  5373. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5374. else
  5375. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5376. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5377. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5378. wqe->words[5] = 0;
  5379. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5380. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5381. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5382. wqe->generic.abort_tag = abort_tag;
  5383. /*
  5384. * The abort handler will send us CMD_ABORT_XRI_CN or
  5385. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5386. */
  5387. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5388. cmnd = CMD_ABORT_XRI_CX;
  5389. command_type = OTHER_COMMAND;
  5390. xritag = 0;
  5391. break;
  5392. case CMD_XMIT_BLS_RSP64_CX:
  5393. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5394. * we re-construct this WQE here based on information in
  5395. * iocbq from scratch.
  5396. */
  5397. memset(wqe, 0, sizeof(union lpfc_wqe));
  5398. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5399. iocbq->iocb.un.ulpWord[3]);
  5400. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5401. iocbq->sli4_xritag);
  5402. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5403. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5404. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5405. iocbq->iocb.ulpContext);
  5406. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5407. command_type = OTHER_COMMAND;
  5408. break;
  5409. case CMD_XRI_ABORTED_CX:
  5410. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5411. /* words0-2 are all 0's no bde */
  5412. /* word3 and word4 are rsvrd */
  5413. wqe->words[3] = 0;
  5414. wqe->words[4] = 0;
  5415. /* word5 iocb=rsvd wge=did */
  5416. /* There is no remote port id in the IOCB? */
  5417. /* Let this fall through and fail */
  5418. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5419. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5420. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5421. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5422. default:
  5423. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5424. "2014 Invalid command 0x%x\n",
  5425. iocbq->iocb.ulpCommand);
  5426. return IOCB_ERROR;
  5427. break;
  5428. }
  5429. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5430. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5431. wqe->generic.abort_tag = abort_tag;
  5432. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5433. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5434. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5435. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5436. return 0;
  5437. }
  5438. /**
  5439. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5440. * @phba: Pointer to HBA context object.
  5441. * @ring_number: SLI ring number to issue iocb on.
  5442. * @piocb: Pointer to command iocb.
  5443. * @flag: Flag indicating if this command can be put into txq.
  5444. *
  5445. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5446. * an iocb command to an HBA with SLI-4 interface spec.
  5447. *
  5448. * This function is called with hbalock held. The function will return success
  5449. * after it successfully submit the iocb to firmware or after adding to the
  5450. * txq.
  5451. **/
  5452. static int
  5453. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5454. struct lpfc_iocbq *piocb, uint32_t flag)
  5455. {
  5456. struct lpfc_sglq *sglq;
  5457. uint16_t xritag;
  5458. union lpfc_wqe wqe;
  5459. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5460. uint32_t fcp_wqidx;
  5461. if (piocb->sli4_xritag == NO_XRI) {
  5462. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5463. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5464. sglq = NULL;
  5465. else {
  5466. sglq = __lpfc_sli_get_sglq(phba);
  5467. if (!sglq)
  5468. return IOCB_ERROR;
  5469. piocb->sli4_xritag = sglq->sli4_xritag;
  5470. }
  5471. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5472. sglq = NULL; /* These IO's already have an XRI and
  5473. * a mapped sgl.
  5474. */
  5475. } else {
  5476. /* This is a continuation of a commandi,(CX) so this
  5477. * sglq is on the active list
  5478. */
  5479. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5480. if (!sglq)
  5481. return IOCB_ERROR;
  5482. }
  5483. if (sglq) {
  5484. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5485. if (xritag != sglq->sli4_xritag)
  5486. return IOCB_ERROR;
  5487. }
  5488. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5489. return IOCB_ERROR;
  5490. if (piocb->iocb_flag & LPFC_IO_FCP) {
  5491. fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5492. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[fcp_wqidx], &wqe))
  5493. return IOCB_ERROR;
  5494. } else {
  5495. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5496. return IOCB_ERROR;
  5497. }
  5498. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5499. return 0;
  5500. }
  5501. /**
  5502. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5503. *
  5504. * This routine wraps the actual lockless version for issusing IOCB function
  5505. * pointer from the lpfc_hba struct.
  5506. *
  5507. * Return codes:
  5508. * IOCB_ERROR - Error
  5509. * IOCB_SUCCESS - Success
  5510. * IOCB_BUSY - Busy
  5511. **/
  5512. static inline int
  5513. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5514. struct lpfc_iocbq *piocb, uint32_t flag)
  5515. {
  5516. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5517. }
  5518. /**
  5519. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5520. * @phba: The hba struct for which this call is being executed.
  5521. * @dev_grp: The HBA PCI-Device group number.
  5522. *
  5523. * This routine sets up the SLI interface API function jump table in @phba
  5524. * struct.
  5525. * Returns: 0 - success, -ENODEV - failure.
  5526. **/
  5527. int
  5528. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5529. {
  5530. switch (dev_grp) {
  5531. case LPFC_PCI_DEV_LP:
  5532. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5533. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5534. break;
  5535. case LPFC_PCI_DEV_OC:
  5536. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5537. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5538. break;
  5539. default:
  5540. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5541. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5542. dev_grp);
  5543. return -ENODEV;
  5544. break;
  5545. }
  5546. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5547. return 0;
  5548. }
  5549. /**
  5550. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5551. * @phba: Pointer to HBA context object.
  5552. * @pring: Pointer to driver SLI ring object.
  5553. * @piocb: Pointer to command iocb.
  5554. * @flag: Flag indicating if this command can be put into txq.
  5555. *
  5556. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5557. * function. This function gets the hbalock and calls
  5558. * __lpfc_sli_issue_iocb function and will return the error returned
  5559. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5560. * functions which do not hold hbalock.
  5561. **/
  5562. int
  5563. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5564. struct lpfc_iocbq *piocb, uint32_t flag)
  5565. {
  5566. unsigned long iflags;
  5567. int rc;
  5568. spin_lock_irqsave(&phba->hbalock, iflags);
  5569. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5570. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5571. return rc;
  5572. }
  5573. /**
  5574. * lpfc_extra_ring_setup - Extra ring setup function
  5575. * @phba: Pointer to HBA context object.
  5576. *
  5577. * This function is called while driver attaches with the
  5578. * HBA to setup the extra ring. The extra ring is used
  5579. * only when driver needs to support target mode functionality
  5580. * or IP over FC functionalities.
  5581. *
  5582. * This function is called with no lock held.
  5583. **/
  5584. static int
  5585. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5586. {
  5587. struct lpfc_sli *psli;
  5588. struct lpfc_sli_ring *pring;
  5589. psli = &phba->sli;
  5590. /* Adjust cmd/rsp ring iocb entries more evenly */
  5591. /* Take some away from the FCP ring */
  5592. pring = &psli->ring[psli->fcp_ring];
  5593. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5594. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5595. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5596. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5597. /* and give them to the extra ring */
  5598. pring = &psli->ring[psli->extra_ring];
  5599. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5600. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5601. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5602. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5603. /* Setup default profile for this ring */
  5604. pring->iotag_max = 4096;
  5605. pring->num_mask = 1;
  5606. pring->prt[0].profile = 0; /* Mask 0 */
  5607. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5608. pring->prt[0].type = phba->cfg_multi_ring_type;
  5609. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5610. return 0;
  5611. }
  5612. /**
  5613. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5614. * @phba: Pointer to HBA context object.
  5615. * @pring: Pointer to driver SLI ring object.
  5616. * @iocbq: Pointer to iocb object.
  5617. *
  5618. * This function is called by the slow ring event handler
  5619. * function when there is an ASYNC event iocb in the ring.
  5620. * This function is called with no lock held.
  5621. * Currently this function handles only temperature related
  5622. * ASYNC events. The function decodes the temperature sensor
  5623. * event message and posts events for the management applications.
  5624. **/
  5625. static void
  5626. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5627. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5628. {
  5629. IOCB_t *icmd;
  5630. uint16_t evt_code;
  5631. uint16_t temp;
  5632. struct temp_event temp_event_data;
  5633. struct Scsi_Host *shost;
  5634. uint32_t *iocb_w;
  5635. icmd = &iocbq->iocb;
  5636. evt_code = icmd->un.asyncstat.evt_code;
  5637. temp = icmd->ulpContext;
  5638. if ((evt_code != ASYNC_TEMP_WARN) &&
  5639. (evt_code != ASYNC_TEMP_SAFE)) {
  5640. iocb_w = (uint32_t *) icmd;
  5641. lpfc_printf_log(phba,
  5642. KERN_ERR,
  5643. LOG_SLI,
  5644. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5645. " evt_code 0x%x\n"
  5646. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5647. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5648. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5649. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5650. pring->ringno,
  5651. icmd->un.asyncstat.evt_code,
  5652. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5653. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5654. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5655. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5656. return;
  5657. }
  5658. temp_event_data.data = (uint32_t)temp;
  5659. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5660. if (evt_code == ASYNC_TEMP_WARN) {
  5661. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5662. lpfc_printf_log(phba,
  5663. KERN_ERR,
  5664. LOG_TEMP,
  5665. "0347 Adapter is very hot, please take "
  5666. "corrective action. temperature : %d Celsius\n",
  5667. temp);
  5668. }
  5669. if (evt_code == ASYNC_TEMP_SAFE) {
  5670. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5671. lpfc_printf_log(phba,
  5672. KERN_ERR,
  5673. LOG_TEMP,
  5674. "0340 Adapter temperature is OK now. "
  5675. "temperature : %d Celsius\n",
  5676. temp);
  5677. }
  5678. /* Send temperature change event to applications */
  5679. shost = lpfc_shost_from_vport(phba->pport);
  5680. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5681. sizeof(temp_event_data), (char *) &temp_event_data,
  5682. LPFC_NL_VENDOR_ID);
  5683. }
  5684. /**
  5685. * lpfc_sli_setup - SLI ring setup function
  5686. * @phba: Pointer to HBA context object.
  5687. *
  5688. * lpfc_sli_setup sets up rings of the SLI interface with
  5689. * number of iocbs per ring and iotags. This function is
  5690. * called while driver attach to the HBA and before the
  5691. * interrupts are enabled. So there is no need for locking.
  5692. *
  5693. * This function always returns 0.
  5694. **/
  5695. int
  5696. lpfc_sli_setup(struct lpfc_hba *phba)
  5697. {
  5698. int i, totiocbsize = 0;
  5699. struct lpfc_sli *psli = &phba->sli;
  5700. struct lpfc_sli_ring *pring;
  5701. psli->num_rings = MAX_CONFIGURED_RINGS;
  5702. psli->sli_flag = 0;
  5703. psli->fcp_ring = LPFC_FCP_RING;
  5704. psli->next_ring = LPFC_FCP_NEXT_RING;
  5705. psli->extra_ring = LPFC_EXTRA_RING;
  5706. psli->iocbq_lookup = NULL;
  5707. psli->iocbq_lookup_len = 0;
  5708. psli->last_iotag = 0;
  5709. for (i = 0; i < psli->num_rings; i++) {
  5710. pring = &psli->ring[i];
  5711. switch (i) {
  5712. case LPFC_FCP_RING: /* ring 0 - FCP */
  5713. /* numCiocb and numRiocb are used in config_port */
  5714. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5715. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5716. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5717. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5718. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5719. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5720. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5721. SLI3_IOCB_CMD_SIZE :
  5722. SLI2_IOCB_CMD_SIZE;
  5723. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5724. SLI3_IOCB_RSP_SIZE :
  5725. SLI2_IOCB_RSP_SIZE;
  5726. pring->iotag_ctr = 0;
  5727. pring->iotag_max =
  5728. (phba->cfg_hba_queue_depth * 2);
  5729. pring->fast_iotag = pring->iotag_max;
  5730. pring->num_mask = 0;
  5731. break;
  5732. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5733. /* numCiocb and numRiocb are used in config_port */
  5734. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5735. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5736. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5737. SLI3_IOCB_CMD_SIZE :
  5738. SLI2_IOCB_CMD_SIZE;
  5739. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5740. SLI3_IOCB_RSP_SIZE :
  5741. SLI2_IOCB_RSP_SIZE;
  5742. pring->iotag_max = phba->cfg_hba_queue_depth;
  5743. pring->num_mask = 0;
  5744. break;
  5745. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5746. /* numCiocb and numRiocb are used in config_port */
  5747. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5748. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5749. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5750. SLI3_IOCB_CMD_SIZE :
  5751. SLI2_IOCB_CMD_SIZE;
  5752. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5753. SLI3_IOCB_RSP_SIZE :
  5754. SLI2_IOCB_RSP_SIZE;
  5755. pring->fast_iotag = 0;
  5756. pring->iotag_ctr = 0;
  5757. pring->iotag_max = 4096;
  5758. pring->lpfc_sli_rcv_async_status =
  5759. lpfc_sli_async_event_handler;
  5760. pring->num_mask = LPFC_MAX_RING_MASK;
  5761. pring->prt[0].profile = 0; /* Mask 0 */
  5762. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5763. pring->prt[0].type = FC_TYPE_ELS;
  5764. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5765. lpfc_els_unsol_event;
  5766. pring->prt[1].profile = 0; /* Mask 1 */
  5767. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5768. pring->prt[1].type = FC_TYPE_ELS;
  5769. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5770. lpfc_els_unsol_event;
  5771. pring->prt[2].profile = 0; /* Mask 2 */
  5772. /* NameServer Inquiry */
  5773. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5774. /* NameServer */
  5775. pring->prt[2].type = FC_TYPE_CT;
  5776. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5777. lpfc_ct_unsol_event;
  5778. pring->prt[3].profile = 0; /* Mask 3 */
  5779. /* NameServer response */
  5780. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  5781. /* NameServer */
  5782. pring->prt[3].type = FC_TYPE_CT;
  5783. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5784. lpfc_ct_unsol_event;
  5785. /* abort unsolicited sequence */
  5786. pring->prt[4].profile = 0; /* Mask 4 */
  5787. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  5788. pring->prt[4].type = FC_TYPE_BLS;
  5789. pring->prt[4].lpfc_sli_rcv_unsol_event =
  5790. lpfc_sli4_ct_abort_unsol_event;
  5791. break;
  5792. }
  5793. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5794. (pring->numRiocb * pring->sizeRiocb);
  5795. }
  5796. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5797. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5798. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5799. "SLI2 SLIM Data: x%x x%lx\n",
  5800. phba->brd_no, totiocbsize,
  5801. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5802. }
  5803. if (phba->cfg_multi_ring_support == 2)
  5804. lpfc_extra_ring_setup(phba);
  5805. return 0;
  5806. }
  5807. /**
  5808. * lpfc_sli_queue_setup - Queue initialization function
  5809. * @phba: Pointer to HBA context object.
  5810. *
  5811. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5812. * ring. This function also initializes ring indices of each ring.
  5813. * This function is called during the initialization of the SLI
  5814. * interface of an HBA.
  5815. * This function is called with no lock held and always returns
  5816. * 1.
  5817. **/
  5818. int
  5819. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5820. {
  5821. struct lpfc_sli *psli;
  5822. struct lpfc_sli_ring *pring;
  5823. int i;
  5824. psli = &phba->sli;
  5825. spin_lock_irq(&phba->hbalock);
  5826. INIT_LIST_HEAD(&psli->mboxq);
  5827. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5828. /* Initialize list headers for txq and txcmplq as double linked lists */
  5829. for (i = 0; i < psli->num_rings; i++) {
  5830. pring = &psli->ring[i];
  5831. pring->ringno = i;
  5832. pring->next_cmdidx = 0;
  5833. pring->local_getidx = 0;
  5834. pring->cmdidx = 0;
  5835. INIT_LIST_HEAD(&pring->txq);
  5836. INIT_LIST_HEAD(&pring->txcmplq);
  5837. INIT_LIST_HEAD(&pring->iocb_continueq);
  5838. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5839. INIT_LIST_HEAD(&pring->postbufq);
  5840. }
  5841. spin_unlock_irq(&phba->hbalock);
  5842. return 1;
  5843. }
  5844. /**
  5845. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5846. * @phba: Pointer to HBA context object.
  5847. *
  5848. * This routine flushes the mailbox command subsystem. It will unconditionally
  5849. * flush all the mailbox commands in the three possible stages in the mailbox
  5850. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5851. * command; and completed mailbox command queue. It is caller's responsibility
  5852. * to make sure that the driver is in the proper state to flush the mailbox
  5853. * command sub-system. Namely, the posting of mailbox commands into the
  5854. * pending mailbox command queue from the various clients must be stopped;
  5855. * either the HBA is in a state that it will never works on the outstanding
  5856. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  5857. * mailbox command has been completed.
  5858. **/
  5859. static void
  5860. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  5861. {
  5862. LIST_HEAD(completions);
  5863. struct lpfc_sli *psli = &phba->sli;
  5864. LPFC_MBOXQ_t *pmb;
  5865. unsigned long iflag;
  5866. /* Flush all the mailbox commands in the mbox system */
  5867. spin_lock_irqsave(&phba->hbalock, iflag);
  5868. /* The pending mailbox command queue */
  5869. list_splice_init(&phba->sli.mboxq, &completions);
  5870. /* The outstanding active mailbox command */
  5871. if (psli->mbox_active) {
  5872. list_add_tail(&psli->mbox_active->list, &completions);
  5873. psli->mbox_active = NULL;
  5874. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5875. }
  5876. /* The completed mailbox command queue */
  5877. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  5878. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5879. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  5880. while (!list_empty(&completions)) {
  5881. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  5882. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5883. if (pmb->mbox_cmpl)
  5884. pmb->mbox_cmpl(phba, pmb);
  5885. }
  5886. }
  5887. /**
  5888. * lpfc_sli_host_down - Vport cleanup function
  5889. * @vport: Pointer to virtual port object.
  5890. *
  5891. * lpfc_sli_host_down is called to clean up the resources
  5892. * associated with a vport before destroying virtual
  5893. * port data structures.
  5894. * This function does following operations:
  5895. * - Free discovery resources associated with this virtual
  5896. * port.
  5897. * - Free iocbs associated with this virtual port in
  5898. * the txq.
  5899. * - Send abort for all iocb commands associated with this
  5900. * vport in txcmplq.
  5901. *
  5902. * This function is called with no lock held and always returns 1.
  5903. **/
  5904. int
  5905. lpfc_sli_host_down(struct lpfc_vport *vport)
  5906. {
  5907. LIST_HEAD(completions);
  5908. struct lpfc_hba *phba = vport->phba;
  5909. struct lpfc_sli *psli = &phba->sli;
  5910. struct lpfc_sli_ring *pring;
  5911. struct lpfc_iocbq *iocb, *next_iocb;
  5912. int i;
  5913. unsigned long flags = 0;
  5914. uint16_t prev_pring_flag;
  5915. lpfc_cleanup_discovery_resources(vport);
  5916. spin_lock_irqsave(&phba->hbalock, flags);
  5917. for (i = 0; i < psli->num_rings; i++) {
  5918. pring = &psli->ring[i];
  5919. prev_pring_flag = pring->flag;
  5920. /* Only slow rings */
  5921. if (pring->ringno == LPFC_ELS_RING) {
  5922. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  5923. /* Set the lpfc data pending flag */
  5924. set_bit(LPFC_DATA_READY, &phba->data_flags);
  5925. }
  5926. /*
  5927. * Error everything on the txq since these iocbs have not been
  5928. * given to the FW yet.
  5929. */
  5930. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  5931. if (iocb->vport != vport)
  5932. continue;
  5933. list_move_tail(&iocb->list, &completions);
  5934. pring->txq_cnt--;
  5935. }
  5936. /* Next issue ABTS for everything on the txcmplq */
  5937. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  5938. list) {
  5939. if (iocb->vport != vport)
  5940. continue;
  5941. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  5942. }
  5943. pring->flag = prev_pring_flag;
  5944. }
  5945. spin_unlock_irqrestore(&phba->hbalock, flags);
  5946. /* Cancel all the IOCBs from the completions list */
  5947. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  5948. IOERR_SLI_DOWN);
  5949. return 1;
  5950. }
  5951. /**
  5952. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  5953. * @phba: Pointer to HBA context object.
  5954. *
  5955. * This function cleans up all iocb, buffers, mailbox commands
  5956. * while shutting down the HBA. This function is called with no
  5957. * lock held and always returns 1.
  5958. * This function does the following to cleanup driver resources:
  5959. * - Free discovery resources for each virtual port
  5960. * - Cleanup any pending fabric iocbs
  5961. * - Iterate through the iocb txq and free each entry
  5962. * in the list.
  5963. * - Free up any buffer posted to the HBA
  5964. * - Free mailbox commands in the mailbox queue.
  5965. **/
  5966. int
  5967. lpfc_sli_hba_down(struct lpfc_hba *phba)
  5968. {
  5969. LIST_HEAD(completions);
  5970. struct lpfc_sli *psli = &phba->sli;
  5971. struct lpfc_sli_ring *pring;
  5972. struct lpfc_dmabuf *buf_ptr;
  5973. unsigned long flags = 0;
  5974. int i;
  5975. /* Shutdown the mailbox command sub-system */
  5976. lpfc_sli_mbox_sys_shutdown(phba);
  5977. lpfc_hba_down_prep(phba);
  5978. lpfc_fabric_abort_hba(phba);
  5979. spin_lock_irqsave(&phba->hbalock, flags);
  5980. for (i = 0; i < psli->num_rings; i++) {
  5981. pring = &psli->ring[i];
  5982. /* Only slow rings */
  5983. if (pring->ringno == LPFC_ELS_RING) {
  5984. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  5985. /* Set the lpfc data pending flag */
  5986. set_bit(LPFC_DATA_READY, &phba->data_flags);
  5987. }
  5988. /*
  5989. * Error everything on the txq since these iocbs have not been
  5990. * given to the FW yet.
  5991. */
  5992. list_splice_init(&pring->txq, &completions);
  5993. pring->txq_cnt = 0;
  5994. }
  5995. spin_unlock_irqrestore(&phba->hbalock, flags);
  5996. /* Cancel all the IOCBs from the completions list */
  5997. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  5998. IOERR_SLI_DOWN);
  5999. spin_lock_irqsave(&phba->hbalock, flags);
  6000. list_splice_init(&phba->elsbuf, &completions);
  6001. phba->elsbuf_cnt = 0;
  6002. phba->elsbuf_prev_cnt = 0;
  6003. spin_unlock_irqrestore(&phba->hbalock, flags);
  6004. while (!list_empty(&completions)) {
  6005. list_remove_head(&completions, buf_ptr,
  6006. struct lpfc_dmabuf, list);
  6007. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6008. kfree(buf_ptr);
  6009. }
  6010. /* Return any active mbox cmds */
  6011. del_timer_sync(&psli->mbox_tmo);
  6012. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6013. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6014. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6015. return 1;
  6016. }
  6017. /**
  6018. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6019. * @phba: Pointer to HBA context object.
  6020. *
  6021. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6022. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6023. * lock held and always returns 1.
  6024. *
  6025. * This function does the following to cleanup driver FCoE function resources:
  6026. * - Free discovery resources for each virtual port
  6027. * - Cleanup any pending fabric iocbs
  6028. * - Iterate through the iocb txq and free each entry in the list.
  6029. * - Free up any buffer posted to the HBA.
  6030. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6031. * - Free mailbox commands in the mailbox queue.
  6032. **/
  6033. int
  6034. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6035. {
  6036. /* Stop the SLI4 device port */
  6037. lpfc_stop_port(phba);
  6038. /* Tear down the queues in the HBA */
  6039. lpfc_sli4_queue_unset(phba);
  6040. /* unregister default FCFI from the HBA */
  6041. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6042. return 1;
  6043. }
  6044. /**
  6045. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6046. * @srcp: Source memory pointer.
  6047. * @destp: Destination memory pointer.
  6048. * @cnt: Number of words required to be copied.
  6049. *
  6050. * This function is used for copying data between driver memory
  6051. * and the SLI memory. This function also changes the endianness
  6052. * of each word if native endianness is different from SLI
  6053. * endianness. This function can be called with or without
  6054. * lock.
  6055. **/
  6056. void
  6057. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6058. {
  6059. uint32_t *src = srcp;
  6060. uint32_t *dest = destp;
  6061. uint32_t ldata;
  6062. int i;
  6063. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6064. ldata = *src;
  6065. ldata = le32_to_cpu(ldata);
  6066. *dest = ldata;
  6067. src++;
  6068. dest++;
  6069. }
  6070. }
  6071. /**
  6072. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6073. * @srcp: Source memory pointer.
  6074. * @destp: Destination memory pointer.
  6075. * @cnt: Number of words required to be copied.
  6076. *
  6077. * This function is used for copying data between a data structure
  6078. * with big endian representation to local endianness.
  6079. * This function can be called with or without lock.
  6080. **/
  6081. void
  6082. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6083. {
  6084. uint32_t *src = srcp;
  6085. uint32_t *dest = destp;
  6086. uint32_t ldata;
  6087. int i;
  6088. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6089. ldata = *src;
  6090. ldata = be32_to_cpu(ldata);
  6091. *dest = ldata;
  6092. src++;
  6093. dest++;
  6094. }
  6095. }
  6096. /**
  6097. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6098. * @phba: Pointer to HBA context object.
  6099. * @pring: Pointer to driver SLI ring object.
  6100. * @mp: Pointer to driver buffer object.
  6101. *
  6102. * This function is called with no lock held.
  6103. * It always return zero after adding the buffer to the postbufq
  6104. * buffer list.
  6105. **/
  6106. int
  6107. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6108. struct lpfc_dmabuf *mp)
  6109. {
  6110. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6111. later */
  6112. spin_lock_irq(&phba->hbalock);
  6113. list_add_tail(&mp->list, &pring->postbufq);
  6114. pring->postbufq_cnt++;
  6115. spin_unlock_irq(&phba->hbalock);
  6116. return 0;
  6117. }
  6118. /**
  6119. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6120. * @phba: Pointer to HBA context object.
  6121. *
  6122. * When HBQ is enabled, buffers are searched based on tags. This function
  6123. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6124. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6125. * does not conflict with tags of buffer posted for unsolicited events.
  6126. * The function returns the allocated tag. The function is called with
  6127. * no locks held.
  6128. **/
  6129. uint32_t
  6130. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6131. {
  6132. spin_lock_irq(&phba->hbalock);
  6133. phba->buffer_tag_count++;
  6134. /*
  6135. * Always set the QUE_BUFTAG_BIT to distiguish between
  6136. * a tag assigned by HBQ.
  6137. */
  6138. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6139. spin_unlock_irq(&phba->hbalock);
  6140. return phba->buffer_tag_count;
  6141. }
  6142. /**
  6143. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6144. * @phba: Pointer to HBA context object.
  6145. * @pring: Pointer to driver SLI ring object.
  6146. * @tag: Buffer tag.
  6147. *
  6148. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6149. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6150. * iocb is posted to the response ring with the tag of the buffer.
  6151. * This function searches the pring->postbufq list using the tag
  6152. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6153. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6154. * buffer is returned to the caller else NULL is returned.
  6155. * This function is called with no lock held.
  6156. **/
  6157. struct lpfc_dmabuf *
  6158. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6159. uint32_t tag)
  6160. {
  6161. struct lpfc_dmabuf *mp, *next_mp;
  6162. struct list_head *slp = &pring->postbufq;
  6163. /* Search postbufq, from the begining, looking for a match on tag */
  6164. spin_lock_irq(&phba->hbalock);
  6165. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6166. if (mp->buffer_tag == tag) {
  6167. list_del_init(&mp->list);
  6168. pring->postbufq_cnt--;
  6169. spin_unlock_irq(&phba->hbalock);
  6170. return mp;
  6171. }
  6172. }
  6173. spin_unlock_irq(&phba->hbalock);
  6174. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6175. "0402 Cannot find virtual addr for buffer tag on "
  6176. "ring %d Data x%lx x%p x%p x%x\n",
  6177. pring->ringno, (unsigned long) tag,
  6178. slp->next, slp->prev, pring->postbufq_cnt);
  6179. return NULL;
  6180. }
  6181. /**
  6182. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6183. * @phba: Pointer to HBA context object.
  6184. * @pring: Pointer to driver SLI ring object.
  6185. * @phys: DMA address of the buffer.
  6186. *
  6187. * This function searches the buffer list using the dma_address
  6188. * of unsolicited event to find the driver's lpfc_dmabuf object
  6189. * corresponding to the dma_address. The function returns the
  6190. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6191. * This function is called by the ct and els unsolicited event
  6192. * handlers to get the buffer associated with the unsolicited
  6193. * event.
  6194. *
  6195. * This function is called with no lock held.
  6196. **/
  6197. struct lpfc_dmabuf *
  6198. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6199. dma_addr_t phys)
  6200. {
  6201. struct lpfc_dmabuf *mp, *next_mp;
  6202. struct list_head *slp = &pring->postbufq;
  6203. /* Search postbufq, from the begining, looking for a match on phys */
  6204. spin_lock_irq(&phba->hbalock);
  6205. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6206. if (mp->phys == phys) {
  6207. list_del_init(&mp->list);
  6208. pring->postbufq_cnt--;
  6209. spin_unlock_irq(&phba->hbalock);
  6210. return mp;
  6211. }
  6212. }
  6213. spin_unlock_irq(&phba->hbalock);
  6214. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6215. "0410 Cannot find virtual addr for mapped buf on "
  6216. "ring %d Data x%llx x%p x%p x%x\n",
  6217. pring->ringno, (unsigned long long)phys,
  6218. slp->next, slp->prev, pring->postbufq_cnt);
  6219. return NULL;
  6220. }
  6221. /**
  6222. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6223. * @phba: Pointer to HBA context object.
  6224. * @cmdiocb: Pointer to driver command iocb object.
  6225. * @rspiocb: Pointer to driver response iocb object.
  6226. *
  6227. * This function is the completion handler for the abort iocbs for
  6228. * ELS commands. This function is called from the ELS ring event
  6229. * handler with no lock held. This function frees memory resources
  6230. * associated with the abort iocb.
  6231. **/
  6232. static void
  6233. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6234. struct lpfc_iocbq *rspiocb)
  6235. {
  6236. IOCB_t *irsp = &rspiocb->iocb;
  6237. uint16_t abort_iotag, abort_context;
  6238. struct lpfc_iocbq *abort_iocb;
  6239. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6240. abort_iocb = NULL;
  6241. if (irsp->ulpStatus) {
  6242. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6243. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6244. spin_lock_irq(&phba->hbalock);
  6245. if (phba->sli_rev < LPFC_SLI_REV4) {
  6246. if (abort_iotag != 0 &&
  6247. abort_iotag <= phba->sli.last_iotag)
  6248. abort_iocb =
  6249. phba->sli.iocbq_lookup[abort_iotag];
  6250. } else
  6251. /* For sli4 the abort_tag is the XRI,
  6252. * so the abort routine puts the iotag of the iocb
  6253. * being aborted in the context field of the abort
  6254. * IOCB.
  6255. */
  6256. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6257. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6258. "0327 Cannot abort els iocb %p "
  6259. "with tag %x context %x, abort status %x, "
  6260. "abort code %x\n",
  6261. abort_iocb, abort_iotag, abort_context,
  6262. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6263. /*
  6264. * If the iocb is not found in Firmware queue the iocb
  6265. * might have completed already. Do not free it again.
  6266. */
  6267. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6268. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6269. spin_unlock_irq(&phba->hbalock);
  6270. lpfc_sli_release_iocbq(phba, cmdiocb);
  6271. return;
  6272. }
  6273. /* For SLI4 the ulpContext field for abort IOCB
  6274. * holds the iotag of the IOCB being aborted so
  6275. * the local abort_context needs to be reset to
  6276. * match the aborted IOCBs ulpContext.
  6277. */
  6278. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6279. abort_context = abort_iocb->iocb.ulpContext;
  6280. }
  6281. /*
  6282. * make sure we have the right iocbq before taking it
  6283. * off the txcmplq and try to call completion routine.
  6284. */
  6285. if (!abort_iocb ||
  6286. abort_iocb->iocb.ulpContext != abort_context ||
  6287. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6288. spin_unlock_irq(&phba->hbalock);
  6289. else {
  6290. list_del_init(&abort_iocb->list);
  6291. pring->txcmplq_cnt--;
  6292. spin_unlock_irq(&phba->hbalock);
  6293. /* Firmware could still be in progress of DMAing
  6294. * payload, so don't free data buffer till after
  6295. * a hbeat.
  6296. */
  6297. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6298. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6299. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6300. abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
  6301. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6302. }
  6303. }
  6304. lpfc_sli_release_iocbq(phba, cmdiocb);
  6305. return;
  6306. }
  6307. /**
  6308. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6309. * @phba: Pointer to HBA context object.
  6310. * @cmdiocb: Pointer to driver command iocb object.
  6311. * @rspiocb: Pointer to driver response iocb object.
  6312. *
  6313. * The function is called from SLI ring event handler with no
  6314. * lock held. This function is the completion handler for ELS commands
  6315. * which are aborted. The function frees memory resources used for
  6316. * the aborted ELS commands.
  6317. **/
  6318. static void
  6319. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6320. struct lpfc_iocbq *rspiocb)
  6321. {
  6322. IOCB_t *irsp = &rspiocb->iocb;
  6323. /* ELS cmd tag <ulpIoTag> completes */
  6324. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6325. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6326. "x%x x%x x%x\n",
  6327. irsp->ulpIoTag, irsp->ulpStatus,
  6328. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6329. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6330. lpfc_ct_free_iocb(phba, cmdiocb);
  6331. else
  6332. lpfc_els_free_iocb(phba, cmdiocb);
  6333. return;
  6334. }
  6335. /**
  6336. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6337. * @phba: Pointer to HBA context object.
  6338. * @pring: Pointer to driver SLI ring object.
  6339. * @cmdiocb: Pointer to driver command iocb object.
  6340. *
  6341. * This function issues an abort iocb for the provided command
  6342. * iocb. This function is called with hbalock held.
  6343. * The function returns 0 when it fails due to memory allocation
  6344. * failure or when the command iocb is an abort request.
  6345. **/
  6346. int
  6347. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6348. struct lpfc_iocbq *cmdiocb)
  6349. {
  6350. struct lpfc_vport *vport = cmdiocb->vport;
  6351. struct lpfc_iocbq *abtsiocbp;
  6352. IOCB_t *icmd = NULL;
  6353. IOCB_t *iabt = NULL;
  6354. int retval = IOCB_ERROR;
  6355. /*
  6356. * There are certain command types we don't want to abort. And we
  6357. * don't want to abort commands that are already in the process of
  6358. * being aborted.
  6359. */
  6360. icmd = &cmdiocb->iocb;
  6361. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6362. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6363. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6364. return 0;
  6365. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6366. * callback so that nothing happens when it finishes.
  6367. */
  6368. if ((vport->load_flag & FC_UNLOADING) &&
  6369. (pring->ringno == LPFC_ELS_RING)) {
  6370. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6371. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6372. else
  6373. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6374. goto abort_iotag_exit;
  6375. }
  6376. /* issue ABTS for this IOCB based on iotag */
  6377. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6378. if (abtsiocbp == NULL)
  6379. return 0;
  6380. /* This signals the response to set the correct status
  6381. * before calling the completion handler.
  6382. */
  6383. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6384. iabt = &abtsiocbp->iocb;
  6385. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6386. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6387. if (phba->sli_rev == LPFC_SLI_REV4) {
  6388. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6389. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6390. }
  6391. else
  6392. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6393. iabt->ulpLe = 1;
  6394. iabt->ulpClass = icmd->ulpClass;
  6395. if (phba->link_state >= LPFC_LINK_UP)
  6396. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6397. else
  6398. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6399. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6400. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6401. "0339 Abort xri x%x, original iotag x%x, "
  6402. "abort cmd iotag x%x\n",
  6403. iabt->un.acxri.abortContextTag,
  6404. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6405. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6406. if (retval)
  6407. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6408. abort_iotag_exit:
  6409. /*
  6410. * Caller to this routine should check for IOCB_ERROR
  6411. * and handle it properly. This routine no longer removes
  6412. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6413. */
  6414. return retval;
  6415. }
  6416. /**
  6417. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6418. * @iocbq: Pointer to driver iocb object.
  6419. * @vport: Pointer to driver virtual port object.
  6420. * @tgt_id: SCSI ID of the target.
  6421. * @lun_id: LUN ID of the scsi device.
  6422. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6423. *
  6424. * This function acts as an iocb filter for functions which abort or count
  6425. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6426. * 0 if the filtering criteria is met for the given iocb and will return
  6427. * 1 if the filtering criteria is not met.
  6428. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6429. * given iocb is for the SCSI device specified by vport, tgt_id and
  6430. * lun_id parameter.
  6431. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6432. * given iocb is for the SCSI target specified by vport and tgt_id
  6433. * parameters.
  6434. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6435. * given iocb is for the SCSI host associated with the given vport.
  6436. * This function is called with no locks held.
  6437. **/
  6438. static int
  6439. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6440. uint16_t tgt_id, uint64_t lun_id,
  6441. lpfc_ctx_cmd ctx_cmd)
  6442. {
  6443. struct lpfc_scsi_buf *lpfc_cmd;
  6444. int rc = 1;
  6445. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6446. return rc;
  6447. if (iocbq->vport != vport)
  6448. return rc;
  6449. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6450. if (lpfc_cmd->pCmd == NULL)
  6451. return rc;
  6452. switch (ctx_cmd) {
  6453. case LPFC_CTX_LUN:
  6454. if ((lpfc_cmd->rdata->pnode) &&
  6455. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6456. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6457. rc = 0;
  6458. break;
  6459. case LPFC_CTX_TGT:
  6460. if ((lpfc_cmd->rdata->pnode) &&
  6461. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6462. rc = 0;
  6463. break;
  6464. case LPFC_CTX_HOST:
  6465. rc = 0;
  6466. break;
  6467. default:
  6468. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6469. __func__, ctx_cmd);
  6470. break;
  6471. }
  6472. return rc;
  6473. }
  6474. /**
  6475. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6476. * @vport: Pointer to virtual port.
  6477. * @tgt_id: SCSI ID of the target.
  6478. * @lun_id: LUN ID of the scsi device.
  6479. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6480. *
  6481. * This function returns number of FCP commands pending for the vport.
  6482. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6483. * commands pending on the vport associated with SCSI device specified
  6484. * by tgt_id and lun_id parameters.
  6485. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6486. * commands pending on the vport associated with SCSI target specified
  6487. * by tgt_id parameter.
  6488. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6489. * commands pending on the vport.
  6490. * This function returns the number of iocbs which satisfy the filter.
  6491. * This function is called without any lock held.
  6492. **/
  6493. int
  6494. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6495. lpfc_ctx_cmd ctx_cmd)
  6496. {
  6497. struct lpfc_hba *phba = vport->phba;
  6498. struct lpfc_iocbq *iocbq;
  6499. int sum, i;
  6500. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6501. iocbq = phba->sli.iocbq_lookup[i];
  6502. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6503. ctx_cmd) == 0)
  6504. sum++;
  6505. }
  6506. return sum;
  6507. }
  6508. /**
  6509. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6510. * @phba: Pointer to HBA context object
  6511. * @cmdiocb: Pointer to command iocb object.
  6512. * @rspiocb: Pointer to response iocb object.
  6513. *
  6514. * This function is called when an aborted FCP iocb completes. This
  6515. * function is called by the ring event handler with no lock held.
  6516. * This function frees the iocb.
  6517. **/
  6518. void
  6519. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6520. struct lpfc_iocbq *rspiocb)
  6521. {
  6522. lpfc_sli_release_iocbq(phba, cmdiocb);
  6523. return;
  6524. }
  6525. /**
  6526. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6527. * @vport: Pointer to virtual port.
  6528. * @pring: Pointer to driver SLI ring object.
  6529. * @tgt_id: SCSI ID of the target.
  6530. * @lun_id: LUN ID of the scsi device.
  6531. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6532. *
  6533. * This function sends an abort command for every SCSI command
  6534. * associated with the given virtual port pending on the ring
  6535. * filtered by lpfc_sli_validate_fcp_iocb function.
  6536. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6537. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6538. * parameters
  6539. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6540. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6541. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6542. * FCP iocbs associated with virtual port.
  6543. * This function returns number of iocbs it failed to abort.
  6544. * This function is called with no locks held.
  6545. **/
  6546. int
  6547. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6548. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6549. {
  6550. struct lpfc_hba *phba = vport->phba;
  6551. struct lpfc_iocbq *iocbq;
  6552. struct lpfc_iocbq *abtsiocb;
  6553. IOCB_t *cmd = NULL;
  6554. int errcnt = 0, ret_val = 0;
  6555. int i;
  6556. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6557. iocbq = phba->sli.iocbq_lookup[i];
  6558. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6559. abort_cmd) != 0)
  6560. continue;
  6561. /* issue ABTS for this IOCB based on iotag */
  6562. abtsiocb = lpfc_sli_get_iocbq(phba);
  6563. if (abtsiocb == NULL) {
  6564. errcnt++;
  6565. continue;
  6566. }
  6567. cmd = &iocbq->iocb;
  6568. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6569. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6570. if (phba->sli_rev == LPFC_SLI_REV4)
  6571. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6572. else
  6573. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6574. abtsiocb->iocb.ulpLe = 1;
  6575. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6576. abtsiocb->vport = phba->pport;
  6577. if (lpfc_is_link_up(phba))
  6578. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6579. else
  6580. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6581. /* Setup callback routine and issue the command. */
  6582. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6583. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6584. abtsiocb, 0);
  6585. if (ret_val == IOCB_ERROR) {
  6586. lpfc_sli_release_iocbq(phba, abtsiocb);
  6587. errcnt++;
  6588. continue;
  6589. }
  6590. }
  6591. return errcnt;
  6592. }
  6593. /**
  6594. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6595. * @phba: Pointer to HBA context object.
  6596. * @cmdiocbq: Pointer to command iocb.
  6597. * @rspiocbq: Pointer to response iocb.
  6598. *
  6599. * This function is the completion handler for iocbs issued using
  6600. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6601. * ring event handler function without any lock held. This function
  6602. * can be called from both worker thread context and interrupt
  6603. * context. This function also can be called from other thread which
  6604. * cleans up the SLI layer objects.
  6605. * This function copy the contents of the response iocb to the
  6606. * response iocb memory object provided by the caller of
  6607. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6608. * sleeps for the iocb completion.
  6609. **/
  6610. static void
  6611. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6612. struct lpfc_iocbq *cmdiocbq,
  6613. struct lpfc_iocbq *rspiocbq)
  6614. {
  6615. wait_queue_head_t *pdone_q;
  6616. unsigned long iflags;
  6617. spin_lock_irqsave(&phba->hbalock, iflags);
  6618. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6619. if (cmdiocbq->context2 && rspiocbq)
  6620. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6621. &rspiocbq->iocb, sizeof(IOCB_t));
  6622. pdone_q = cmdiocbq->context_un.wait_queue;
  6623. if (pdone_q)
  6624. wake_up(pdone_q);
  6625. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6626. return;
  6627. }
  6628. /**
  6629. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6630. * @phba: Pointer to HBA context object..
  6631. * @piocbq: Pointer to command iocb.
  6632. * @flag: Flag to test.
  6633. *
  6634. * This routine grabs the hbalock and then test the iocb_flag to
  6635. * see if the passed in flag is set.
  6636. * Returns:
  6637. * 1 if flag is set.
  6638. * 0 if flag is not set.
  6639. **/
  6640. static int
  6641. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6642. struct lpfc_iocbq *piocbq, uint32_t flag)
  6643. {
  6644. unsigned long iflags;
  6645. int ret;
  6646. spin_lock_irqsave(&phba->hbalock, iflags);
  6647. ret = piocbq->iocb_flag & flag;
  6648. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6649. return ret;
  6650. }
  6651. /**
  6652. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6653. * @phba: Pointer to HBA context object..
  6654. * @pring: Pointer to sli ring.
  6655. * @piocb: Pointer to command iocb.
  6656. * @prspiocbq: Pointer to response iocb.
  6657. * @timeout: Timeout in number of seconds.
  6658. *
  6659. * This function issues the iocb to firmware and waits for the
  6660. * iocb to complete. If the iocb command is not
  6661. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6662. * Caller should not free the iocb resources if this function
  6663. * returns IOCB_TIMEDOUT.
  6664. * The function waits for the iocb completion using an
  6665. * non-interruptible wait.
  6666. * This function will sleep while waiting for iocb completion.
  6667. * So, this function should not be called from any context which
  6668. * does not allow sleeping. Due to the same reason, this function
  6669. * cannot be called with interrupt disabled.
  6670. * This function assumes that the iocb completions occur while
  6671. * this function sleep. So, this function cannot be called from
  6672. * the thread which process iocb completion for this ring.
  6673. * This function clears the iocb_flag of the iocb object before
  6674. * issuing the iocb and the iocb completion handler sets this
  6675. * flag and wakes this thread when the iocb completes.
  6676. * The contents of the response iocb will be copied to prspiocbq
  6677. * by the completion handler when the command completes.
  6678. * This function returns IOCB_SUCCESS when success.
  6679. * This function is called with no lock held.
  6680. **/
  6681. int
  6682. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6683. uint32_t ring_number,
  6684. struct lpfc_iocbq *piocb,
  6685. struct lpfc_iocbq *prspiocbq,
  6686. uint32_t timeout)
  6687. {
  6688. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6689. long timeleft, timeout_req = 0;
  6690. int retval = IOCB_SUCCESS;
  6691. uint32_t creg_val;
  6692. /*
  6693. * If the caller has provided a response iocbq buffer, then context2
  6694. * is NULL or its an error.
  6695. */
  6696. if (prspiocbq) {
  6697. if (piocb->context2)
  6698. return IOCB_ERROR;
  6699. piocb->context2 = prspiocbq;
  6700. }
  6701. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6702. piocb->context_un.wait_queue = &done_q;
  6703. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6704. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6705. creg_val = readl(phba->HCregaddr);
  6706. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6707. writel(creg_val, phba->HCregaddr);
  6708. readl(phba->HCregaddr); /* flush */
  6709. }
  6710. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6711. if (retval == IOCB_SUCCESS) {
  6712. timeout_req = timeout * HZ;
  6713. timeleft = wait_event_timeout(done_q,
  6714. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6715. timeout_req);
  6716. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6717. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6718. "0331 IOCB wake signaled\n");
  6719. } else if (timeleft == 0) {
  6720. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6721. "0338 IOCB wait timeout error - no "
  6722. "wake response Data x%x\n", timeout);
  6723. retval = IOCB_TIMEDOUT;
  6724. } else {
  6725. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6726. "0330 IOCB wake NOT set, "
  6727. "Data x%x x%lx\n",
  6728. timeout, (timeleft / jiffies));
  6729. retval = IOCB_TIMEDOUT;
  6730. }
  6731. } else {
  6732. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6733. "0332 IOCB wait issue failed, Data x%x\n",
  6734. retval);
  6735. retval = IOCB_ERROR;
  6736. }
  6737. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6738. creg_val = readl(phba->HCregaddr);
  6739. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6740. writel(creg_val, phba->HCregaddr);
  6741. readl(phba->HCregaddr); /* flush */
  6742. }
  6743. if (prspiocbq)
  6744. piocb->context2 = NULL;
  6745. piocb->context_un.wait_queue = NULL;
  6746. piocb->iocb_cmpl = NULL;
  6747. return retval;
  6748. }
  6749. /**
  6750. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6751. * @phba: Pointer to HBA context object.
  6752. * @pmboxq: Pointer to driver mailbox object.
  6753. * @timeout: Timeout in number of seconds.
  6754. *
  6755. * This function issues the mailbox to firmware and waits for the
  6756. * mailbox command to complete. If the mailbox command is not
  6757. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6758. * The function waits for the mailbox completion using an
  6759. * interruptible wait. If the thread is woken up due to a
  6760. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6761. * should not free the mailbox resources, if this function returns
  6762. * MBX_TIMEOUT.
  6763. * This function will sleep while waiting for mailbox completion.
  6764. * So, this function should not be called from any context which
  6765. * does not allow sleeping. Due to the same reason, this function
  6766. * cannot be called with interrupt disabled.
  6767. * This function assumes that the mailbox completion occurs while
  6768. * this function sleep. So, this function cannot be called from
  6769. * the worker thread which processes mailbox completion.
  6770. * This function is called in the context of HBA management
  6771. * applications.
  6772. * This function returns MBX_SUCCESS when successful.
  6773. * This function is called with no lock held.
  6774. **/
  6775. int
  6776. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6777. uint32_t timeout)
  6778. {
  6779. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6780. int retval;
  6781. unsigned long flag;
  6782. /* The caller must leave context1 empty. */
  6783. if (pmboxq->context1)
  6784. return MBX_NOT_FINISHED;
  6785. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6786. /* setup wake call as IOCB callback */
  6787. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6788. /* setup context field to pass wait_queue pointer to wake function */
  6789. pmboxq->context1 = &done_q;
  6790. /* now issue the command */
  6791. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6792. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6793. wait_event_interruptible_timeout(done_q,
  6794. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6795. timeout * HZ);
  6796. spin_lock_irqsave(&phba->hbalock, flag);
  6797. pmboxq->context1 = NULL;
  6798. /*
  6799. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6800. * else do not free the resources.
  6801. */
  6802. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6803. retval = MBX_SUCCESS;
  6804. else {
  6805. retval = MBX_TIMEOUT;
  6806. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6807. }
  6808. spin_unlock_irqrestore(&phba->hbalock, flag);
  6809. }
  6810. return retval;
  6811. }
  6812. /**
  6813. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6814. * @phba: Pointer to HBA context.
  6815. *
  6816. * This function is called to shutdown the driver's mailbox sub-system.
  6817. * It first marks the mailbox sub-system is in a block state to prevent
  6818. * the asynchronous mailbox command from issued off the pending mailbox
  6819. * command queue. If the mailbox command sub-system shutdown is due to
  6820. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6821. * the mailbox sub-system flush routine to forcefully bring down the
  6822. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6823. * as with offline or HBA function reset), this routine will wait for the
  6824. * outstanding mailbox command to complete before invoking the mailbox
  6825. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6826. **/
  6827. void
  6828. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6829. {
  6830. struct lpfc_sli *psli = &phba->sli;
  6831. uint8_t actcmd = MBX_HEARTBEAT;
  6832. unsigned long timeout;
  6833. spin_lock_irq(&phba->hbalock);
  6834. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6835. spin_unlock_irq(&phba->hbalock);
  6836. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6837. spin_lock_irq(&phba->hbalock);
  6838. if (phba->sli.mbox_active)
  6839. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  6840. spin_unlock_irq(&phba->hbalock);
  6841. /* Determine how long we might wait for the active mailbox
  6842. * command to be gracefully completed by firmware.
  6843. */
  6844. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  6845. 1000) + jiffies;
  6846. while (phba->sli.mbox_active) {
  6847. /* Check active mailbox complete status every 2ms */
  6848. msleep(2);
  6849. if (time_after(jiffies, timeout))
  6850. /* Timeout, let the mailbox flush routine to
  6851. * forcefully release active mailbox command
  6852. */
  6853. break;
  6854. }
  6855. }
  6856. lpfc_sli_mbox_sys_flush(phba);
  6857. }
  6858. /**
  6859. * lpfc_sli_eratt_read - read sli-3 error attention events
  6860. * @phba: Pointer to HBA context.
  6861. *
  6862. * This function is called to read the SLI3 device error attention registers
  6863. * for possible error attention events. The caller must hold the hostlock
  6864. * with spin_lock_irq().
  6865. *
  6866. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6867. * Register and returns 0 otherwise.
  6868. **/
  6869. static int
  6870. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  6871. {
  6872. uint32_t ha_copy;
  6873. /* Read chip Host Attention (HA) register */
  6874. ha_copy = readl(phba->HAregaddr);
  6875. if (ha_copy & HA_ERATT) {
  6876. /* Read host status register to retrieve error event */
  6877. lpfc_sli_read_hs(phba);
  6878. /* Check if there is a deferred error condition is active */
  6879. if ((HS_FFER1 & phba->work_hs) &&
  6880. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  6881. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  6882. phba->hba_flag |= DEFER_ERATT;
  6883. /* Clear all interrupt enable conditions */
  6884. writel(0, phba->HCregaddr);
  6885. readl(phba->HCregaddr);
  6886. }
  6887. /* Set the driver HA work bitmap */
  6888. phba->work_ha |= HA_ERATT;
  6889. /* Indicate polling handles this ERATT */
  6890. phba->hba_flag |= HBA_ERATT_HANDLED;
  6891. return 1;
  6892. }
  6893. return 0;
  6894. }
  6895. /**
  6896. * lpfc_sli4_eratt_read - read sli-4 error attention events
  6897. * @phba: Pointer to HBA context.
  6898. *
  6899. * This function is called to read the SLI4 device error attention registers
  6900. * for possible error attention events. The caller must hold the hostlock
  6901. * with spin_lock_irq().
  6902. *
  6903. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6904. * Register and returns 0 otherwise.
  6905. **/
  6906. static int
  6907. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  6908. {
  6909. uint32_t uerr_sta_hi, uerr_sta_lo;
  6910. uint32_t onlnreg0, onlnreg1;
  6911. /* For now, use the SLI4 device internal unrecoverable error
  6912. * registers for error attention. This can be changed later.
  6913. */
  6914. onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
  6915. onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
  6916. if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
  6917. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  6918. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  6919. if (uerr_sta_lo || uerr_sta_hi) {
  6920. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6921. "1423 HBA Unrecoverable error: "
  6922. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  6923. "online0_reg=0x%x, online1_reg=0x%x\n",
  6924. uerr_sta_lo, uerr_sta_hi,
  6925. onlnreg0, onlnreg1);
  6926. phba->work_status[0] = uerr_sta_lo;
  6927. phba->work_status[1] = uerr_sta_hi;
  6928. /* Set the driver HA work bitmap */
  6929. phba->work_ha |= HA_ERATT;
  6930. /* Indicate polling handles this ERATT */
  6931. phba->hba_flag |= HBA_ERATT_HANDLED;
  6932. return 1;
  6933. }
  6934. }
  6935. return 0;
  6936. }
  6937. /**
  6938. * lpfc_sli_check_eratt - check error attention events
  6939. * @phba: Pointer to HBA context.
  6940. *
  6941. * This function is called from timer soft interrupt context to check HBA's
  6942. * error attention register bit for error attention events.
  6943. *
  6944. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6945. * Register and returns 0 otherwise.
  6946. **/
  6947. int
  6948. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  6949. {
  6950. uint32_t ha_copy;
  6951. /* If somebody is waiting to handle an eratt, don't process it
  6952. * here. The brdkill function will do this.
  6953. */
  6954. if (phba->link_flag & LS_IGNORE_ERATT)
  6955. return 0;
  6956. /* Check if interrupt handler handles this ERATT */
  6957. spin_lock_irq(&phba->hbalock);
  6958. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  6959. /* Interrupt handler has handled ERATT */
  6960. spin_unlock_irq(&phba->hbalock);
  6961. return 0;
  6962. }
  6963. /*
  6964. * If there is deferred error attention, do not check for error
  6965. * attention
  6966. */
  6967. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  6968. spin_unlock_irq(&phba->hbalock);
  6969. return 0;
  6970. }
  6971. /* If PCI channel is offline, don't process it */
  6972. if (unlikely(pci_channel_offline(phba->pcidev))) {
  6973. spin_unlock_irq(&phba->hbalock);
  6974. return 0;
  6975. }
  6976. switch (phba->sli_rev) {
  6977. case LPFC_SLI_REV2:
  6978. case LPFC_SLI_REV3:
  6979. /* Read chip Host Attention (HA) register */
  6980. ha_copy = lpfc_sli_eratt_read(phba);
  6981. break;
  6982. case LPFC_SLI_REV4:
  6983. /* Read devcie Uncoverable Error (UERR) registers */
  6984. ha_copy = lpfc_sli4_eratt_read(phba);
  6985. break;
  6986. default:
  6987. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6988. "0299 Invalid SLI revision (%d)\n",
  6989. phba->sli_rev);
  6990. ha_copy = 0;
  6991. break;
  6992. }
  6993. spin_unlock_irq(&phba->hbalock);
  6994. return ha_copy;
  6995. }
  6996. /**
  6997. * lpfc_intr_state_check - Check device state for interrupt handling
  6998. * @phba: Pointer to HBA context.
  6999. *
  7000. * This inline routine checks whether a device or its PCI slot is in a state
  7001. * that the interrupt should be handled.
  7002. *
  7003. * This function returns 0 if the device or the PCI slot is in a state that
  7004. * interrupt should be handled, otherwise -EIO.
  7005. */
  7006. static inline int
  7007. lpfc_intr_state_check(struct lpfc_hba *phba)
  7008. {
  7009. /* If the pci channel is offline, ignore all the interrupts */
  7010. if (unlikely(pci_channel_offline(phba->pcidev)))
  7011. return -EIO;
  7012. /* Update device level interrupt statistics */
  7013. phba->sli.slistat.sli_intr++;
  7014. /* Ignore all interrupts during initialization. */
  7015. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7016. return -EIO;
  7017. return 0;
  7018. }
  7019. /**
  7020. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7021. * @irq: Interrupt number.
  7022. * @dev_id: The device context pointer.
  7023. *
  7024. * This function is directly called from the PCI layer as an interrupt
  7025. * service routine when device with SLI-3 interface spec is enabled with
  7026. * MSI-X multi-message interrupt mode and there are slow-path events in
  7027. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7028. * interrupt mode, this function is called as part of the device-level
  7029. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7030. * is undergoing initialization, the interrupt handler will not process
  7031. * the interrupt. The link attention and ELS ring attention events are
  7032. * handled by the worker thread. The interrupt handler signals the worker
  7033. * thread and returns for these events. This function is called without
  7034. * any lock held. It gets the hbalock to access and update SLI data
  7035. * structures.
  7036. *
  7037. * This function returns IRQ_HANDLED when interrupt is handled else it
  7038. * returns IRQ_NONE.
  7039. **/
  7040. irqreturn_t
  7041. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7042. {
  7043. struct lpfc_hba *phba;
  7044. uint32_t ha_copy;
  7045. uint32_t work_ha_copy;
  7046. unsigned long status;
  7047. unsigned long iflag;
  7048. uint32_t control;
  7049. MAILBOX_t *mbox, *pmbox;
  7050. struct lpfc_vport *vport;
  7051. struct lpfc_nodelist *ndlp;
  7052. struct lpfc_dmabuf *mp;
  7053. LPFC_MBOXQ_t *pmb;
  7054. int rc;
  7055. /*
  7056. * Get the driver's phba structure from the dev_id and
  7057. * assume the HBA is not interrupting.
  7058. */
  7059. phba = (struct lpfc_hba *)dev_id;
  7060. if (unlikely(!phba))
  7061. return IRQ_NONE;
  7062. /*
  7063. * Stuff needs to be attented to when this function is invoked as an
  7064. * individual interrupt handler in MSI-X multi-message interrupt mode
  7065. */
  7066. if (phba->intr_type == MSIX) {
  7067. /* Check device state for handling interrupt */
  7068. if (lpfc_intr_state_check(phba))
  7069. return IRQ_NONE;
  7070. /* Need to read HA REG for slow-path events */
  7071. spin_lock_irqsave(&phba->hbalock, iflag);
  7072. ha_copy = readl(phba->HAregaddr);
  7073. /* If somebody is waiting to handle an eratt don't process it
  7074. * here. The brdkill function will do this.
  7075. */
  7076. if (phba->link_flag & LS_IGNORE_ERATT)
  7077. ha_copy &= ~HA_ERATT;
  7078. /* Check the need for handling ERATT in interrupt handler */
  7079. if (ha_copy & HA_ERATT) {
  7080. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7081. /* ERATT polling has handled ERATT */
  7082. ha_copy &= ~HA_ERATT;
  7083. else
  7084. /* Indicate interrupt handler handles ERATT */
  7085. phba->hba_flag |= HBA_ERATT_HANDLED;
  7086. }
  7087. /*
  7088. * If there is deferred error attention, do not check for any
  7089. * interrupt.
  7090. */
  7091. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7092. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7093. return IRQ_NONE;
  7094. }
  7095. /* Clear up only attention source related to slow-path */
  7096. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7097. phba->HAregaddr);
  7098. readl(phba->HAregaddr); /* flush */
  7099. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7100. } else
  7101. ha_copy = phba->ha_copy;
  7102. work_ha_copy = ha_copy & phba->work_ha_mask;
  7103. if (work_ha_copy) {
  7104. if (work_ha_copy & HA_LATT) {
  7105. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7106. /*
  7107. * Turn off Link Attention interrupts
  7108. * until CLEAR_LA done
  7109. */
  7110. spin_lock_irqsave(&phba->hbalock, iflag);
  7111. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7112. control = readl(phba->HCregaddr);
  7113. control &= ~HC_LAINT_ENA;
  7114. writel(control, phba->HCregaddr);
  7115. readl(phba->HCregaddr); /* flush */
  7116. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7117. }
  7118. else
  7119. work_ha_copy &= ~HA_LATT;
  7120. }
  7121. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7122. /*
  7123. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7124. * the only slow ring.
  7125. */
  7126. status = (work_ha_copy &
  7127. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7128. status >>= (4*LPFC_ELS_RING);
  7129. if (status & HA_RXMASK) {
  7130. spin_lock_irqsave(&phba->hbalock, iflag);
  7131. control = readl(phba->HCregaddr);
  7132. lpfc_debugfs_slow_ring_trc(phba,
  7133. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7134. control, status,
  7135. (uint32_t)phba->sli.slistat.sli_intr);
  7136. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7137. lpfc_debugfs_slow_ring_trc(phba,
  7138. "ISR Disable ring:"
  7139. "pwork:x%x hawork:x%x wait:x%x",
  7140. phba->work_ha, work_ha_copy,
  7141. (uint32_t)((unsigned long)
  7142. &phba->work_waitq));
  7143. control &=
  7144. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7145. writel(control, phba->HCregaddr);
  7146. readl(phba->HCregaddr); /* flush */
  7147. }
  7148. else {
  7149. lpfc_debugfs_slow_ring_trc(phba,
  7150. "ISR slow ring: pwork:"
  7151. "x%x hawork:x%x wait:x%x",
  7152. phba->work_ha, work_ha_copy,
  7153. (uint32_t)((unsigned long)
  7154. &phba->work_waitq));
  7155. }
  7156. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7157. }
  7158. }
  7159. spin_lock_irqsave(&phba->hbalock, iflag);
  7160. if (work_ha_copy & HA_ERATT) {
  7161. lpfc_sli_read_hs(phba);
  7162. /*
  7163. * Check if there is a deferred error condition
  7164. * is active
  7165. */
  7166. if ((HS_FFER1 & phba->work_hs) &&
  7167. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7168. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7169. phba->hba_flag |= DEFER_ERATT;
  7170. /* Clear all interrupt enable conditions */
  7171. writel(0, phba->HCregaddr);
  7172. readl(phba->HCregaddr);
  7173. }
  7174. }
  7175. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7176. pmb = phba->sli.mbox_active;
  7177. pmbox = &pmb->u.mb;
  7178. mbox = phba->mbox;
  7179. vport = pmb->vport;
  7180. /* First check out the status word */
  7181. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7182. if (pmbox->mbxOwner != OWN_HOST) {
  7183. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7184. /*
  7185. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7186. * mbxStatus <status>
  7187. */
  7188. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7189. LOG_SLI,
  7190. "(%d):0304 Stray Mailbox "
  7191. "Interrupt mbxCommand x%x "
  7192. "mbxStatus x%x\n",
  7193. (vport ? vport->vpi : 0),
  7194. pmbox->mbxCommand,
  7195. pmbox->mbxStatus);
  7196. /* clear mailbox attention bit */
  7197. work_ha_copy &= ~HA_MBATT;
  7198. } else {
  7199. phba->sli.mbox_active = NULL;
  7200. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7201. phba->last_completion_time = jiffies;
  7202. del_timer(&phba->sli.mbox_tmo);
  7203. if (pmb->mbox_cmpl) {
  7204. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7205. MAILBOX_CMD_SIZE);
  7206. }
  7207. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7208. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7209. lpfc_debugfs_disc_trc(vport,
  7210. LPFC_DISC_TRC_MBOX_VPORT,
  7211. "MBOX dflt rpi: : "
  7212. "status:x%x rpi:x%x",
  7213. (uint32_t)pmbox->mbxStatus,
  7214. pmbox->un.varWords[0], 0);
  7215. if (!pmbox->mbxStatus) {
  7216. mp = (struct lpfc_dmabuf *)
  7217. (pmb->context1);
  7218. ndlp = (struct lpfc_nodelist *)
  7219. pmb->context2;
  7220. /* Reg_LOGIN of dflt RPI was
  7221. * successful. new lets get
  7222. * rid of the RPI using the
  7223. * same mbox buffer.
  7224. */
  7225. lpfc_unreg_login(phba,
  7226. vport->vpi,
  7227. pmbox->un.varWords[0],
  7228. pmb);
  7229. pmb->mbox_cmpl =
  7230. lpfc_mbx_cmpl_dflt_rpi;
  7231. pmb->context1 = mp;
  7232. pmb->context2 = ndlp;
  7233. pmb->vport = vport;
  7234. rc = lpfc_sli_issue_mbox(phba,
  7235. pmb,
  7236. MBX_NOWAIT);
  7237. if (rc != MBX_BUSY)
  7238. lpfc_printf_log(phba,
  7239. KERN_ERR,
  7240. LOG_MBOX | LOG_SLI,
  7241. "0350 rc should have"
  7242. "been MBX_BUSY\n");
  7243. if (rc != MBX_NOT_FINISHED)
  7244. goto send_current_mbox;
  7245. }
  7246. }
  7247. spin_lock_irqsave(
  7248. &phba->pport->work_port_lock,
  7249. iflag);
  7250. phba->pport->work_port_events &=
  7251. ~WORKER_MBOX_TMO;
  7252. spin_unlock_irqrestore(
  7253. &phba->pport->work_port_lock,
  7254. iflag);
  7255. lpfc_mbox_cmpl_put(phba, pmb);
  7256. }
  7257. } else
  7258. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7259. if ((work_ha_copy & HA_MBATT) &&
  7260. (phba->sli.mbox_active == NULL)) {
  7261. send_current_mbox:
  7262. /* Process next mailbox command if there is one */
  7263. do {
  7264. rc = lpfc_sli_issue_mbox(phba, NULL,
  7265. MBX_NOWAIT);
  7266. } while (rc == MBX_NOT_FINISHED);
  7267. if (rc != MBX_SUCCESS)
  7268. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7269. LOG_SLI, "0349 rc should be "
  7270. "MBX_SUCCESS\n");
  7271. }
  7272. spin_lock_irqsave(&phba->hbalock, iflag);
  7273. phba->work_ha |= work_ha_copy;
  7274. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7275. lpfc_worker_wake_up(phba);
  7276. }
  7277. return IRQ_HANDLED;
  7278. } /* lpfc_sli_sp_intr_handler */
  7279. /**
  7280. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7281. * @irq: Interrupt number.
  7282. * @dev_id: The device context pointer.
  7283. *
  7284. * This function is directly called from the PCI layer as an interrupt
  7285. * service routine when device with SLI-3 interface spec is enabled with
  7286. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7287. * ring event in the HBA. However, when the device is enabled with either
  7288. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7289. * device-level interrupt handler. When the PCI slot is in error recovery
  7290. * or the HBA is undergoing initialization, the interrupt handler will not
  7291. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7292. * the intrrupt context. This function is called without any lock held.
  7293. * It gets the hbalock to access and update SLI data structures.
  7294. *
  7295. * This function returns IRQ_HANDLED when interrupt is handled else it
  7296. * returns IRQ_NONE.
  7297. **/
  7298. irqreturn_t
  7299. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7300. {
  7301. struct lpfc_hba *phba;
  7302. uint32_t ha_copy;
  7303. unsigned long status;
  7304. unsigned long iflag;
  7305. /* Get the driver's phba structure from the dev_id and
  7306. * assume the HBA is not interrupting.
  7307. */
  7308. phba = (struct lpfc_hba *) dev_id;
  7309. if (unlikely(!phba))
  7310. return IRQ_NONE;
  7311. /*
  7312. * Stuff needs to be attented to when this function is invoked as an
  7313. * individual interrupt handler in MSI-X multi-message interrupt mode
  7314. */
  7315. if (phba->intr_type == MSIX) {
  7316. /* Check device state for handling interrupt */
  7317. if (lpfc_intr_state_check(phba))
  7318. return IRQ_NONE;
  7319. /* Need to read HA REG for FCP ring and other ring events */
  7320. ha_copy = readl(phba->HAregaddr);
  7321. /* Clear up only attention source related to fast-path */
  7322. spin_lock_irqsave(&phba->hbalock, iflag);
  7323. /*
  7324. * If there is deferred error attention, do not check for
  7325. * any interrupt.
  7326. */
  7327. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7328. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7329. return IRQ_NONE;
  7330. }
  7331. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7332. phba->HAregaddr);
  7333. readl(phba->HAregaddr); /* flush */
  7334. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7335. } else
  7336. ha_copy = phba->ha_copy;
  7337. /*
  7338. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7339. */
  7340. ha_copy &= ~(phba->work_ha_mask);
  7341. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7342. status >>= (4*LPFC_FCP_RING);
  7343. if (status & HA_RXMASK)
  7344. lpfc_sli_handle_fast_ring_event(phba,
  7345. &phba->sli.ring[LPFC_FCP_RING],
  7346. status);
  7347. if (phba->cfg_multi_ring_support == 2) {
  7348. /*
  7349. * Process all events on extra ring. Take the optimized path
  7350. * for extra ring IO.
  7351. */
  7352. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7353. status >>= (4*LPFC_EXTRA_RING);
  7354. if (status & HA_RXMASK) {
  7355. lpfc_sli_handle_fast_ring_event(phba,
  7356. &phba->sli.ring[LPFC_EXTRA_RING],
  7357. status);
  7358. }
  7359. }
  7360. return IRQ_HANDLED;
  7361. } /* lpfc_sli_fp_intr_handler */
  7362. /**
  7363. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7364. * @irq: Interrupt number.
  7365. * @dev_id: The device context pointer.
  7366. *
  7367. * This function is the HBA device-level interrupt handler to device with
  7368. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7369. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7370. * requires driver attention. This function invokes the slow-path interrupt
  7371. * attention handling function and fast-path interrupt attention handling
  7372. * function in turn to process the relevant HBA attention events. This
  7373. * function is called without any lock held. It gets the hbalock to access
  7374. * and update SLI data structures.
  7375. *
  7376. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7377. * returns IRQ_NONE.
  7378. **/
  7379. irqreturn_t
  7380. lpfc_sli_intr_handler(int irq, void *dev_id)
  7381. {
  7382. struct lpfc_hba *phba;
  7383. irqreturn_t sp_irq_rc, fp_irq_rc;
  7384. unsigned long status1, status2;
  7385. /*
  7386. * Get the driver's phba structure from the dev_id and
  7387. * assume the HBA is not interrupting.
  7388. */
  7389. phba = (struct lpfc_hba *) dev_id;
  7390. if (unlikely(!phba))
  7391. return IRQ_NONE;
  7392. /* Check device state for handling interrupt */
  7393. if (lpfc_intr_state_check(phba))
  7394. return IRQ_NONE;
  7395. spin_lock(&phba->hbalock);
  7396. phba->ha_copy = readl(phba->HAregaddr);
  7397. if (unlikely(!phba->ha_copy)) {
  7398. spin_unlock(&phba->hbalock);
  7399. return IRQ_NONE;
  7400. } else if (phba->ha_copy & HA_ERATT) {
  7401. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7402. /* ERATT polling has handled ERATT */
  7403. phba->ha_copy &= ~HA_ERATT;
  7404. else
  7405. /* Indicate interrupt handler handles ERATT */
  7406. phba->hba_flag |= HBA_ERATT_HANDLED;
  7407. }
  7408. /*
  7409. * If there is deferred error attention, do not check for any interrupt.
  7410. */
  7411. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7412. spin_unlock_irq(&phba->hbalock);
  7413. return IRQ_NONE;
  7414. }
  7415. /* Clear attention sources except link and error attentions */
  7416. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7417. readl(phba->HAregaddr); /* flush */
  7418. spin_unlock(&phba->hbalock);
  7419. /*
  7420. * Invokes slow-path host attention interrupt handling as appropriate.
  7421. */
  7422. /* status of events with mailbox and link attention */
  7423. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7424. /* status of events with ELS ring */
  7425. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7426. status2 >>= (4*LPFC_ELS_RING);
  7427. if (status1 || (status2 & HA_RXMASK))
  7428. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7429. else
  7430. sp_irq_rc = IRQ_NONE;
  7431. /*
  7432. * Invoke fast-path host attention interrupt handling as appropriate.
  7433. */
  7434. /* status of events with FCP ring */
  7435. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7436. status1 >>= (4*LPFC_FCP_RING);
  7437. /* status of events with extra ring */
  7438. if (phba->cfg_multi_ring_support == 2) {
  7439. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7440. status2 >>= (4*LPFC_EXTRA_RING);
  7441. } else
  7442. status2 = 0;
  7443. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7444. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7445. else
  7446. fp_irq_rc = IRQ_NONE;
  7447. /* Return device-level interrupt handling status */
  7448. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7449. } /* lpfc_sli_intr_handler */
  7450. /**
  7451. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7452. * @phba: pointer to lpfc hba data structure.
  7453. *
  7454. * This routine is invoked by the worker thread to process all the pending
  7455. * SLI4 FCP abort XRI events.
  7456. **/
  7457. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7458. {
  7459. struct lpfc_cq_event *cq_event;
  7460. /* First, declare the fcp xri abort event has been handled */
  7461. spin_lock_irq(&phba->hbalock);
  7462. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7463. spin_unlock_irq(&phba->hbalock);
  7464. /* Now, handle all the fcp xri abort events */
  7465. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7466. /* Get the first event from the head of the event queue */
  7467. spin_lock_irq(&phba->hbalock);
  7468. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7469. cq_event, struct lpfc_cq_event, list);
  7470. spin_unlock_irq(&phba->hbalock);
  7471. /* Notify aborted XRI for FCP work queue */
  7472. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7473. /* Free the event processed back to the free pool */
  7474. lpfc_sli4_cq_event_release(phba, cq_event);
  7475. }
  7476. }
  7477. /**
  7478. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7479. * @phba: pointer to lpfc hba data structure.
  7480. *
  7481. * This routine is invoked by the worker thread to process all the pending
  7482. * SLI4 els abort xri events.
  7483. **/
  7484. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7485. {
  7486. struct lpfc_cq_event *cq_event;
  7487. /* First, declare the els xri abort event has been handled */
  7488. spin_lock_irq(&phba->hbalock);
  7489. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7490. spin_unlock_irq(&phba->hbalock);
  7491. /* Now, handle all the els xri abort events */
  7492. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7493. /* Get the first event from the head of the event queue */
  7494. spin_lock_irq(&phba->hbalock);
  7495. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7496. cq_event, struct lpfc_cq_event, list);
  7497. spin_unlock_irq(&phba->hbalock);
  7498. /* Notify aborted XRI for ELS work queue */
  7499. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7500. /* Free the event processed back to the free pool */
  7501. lpfc_sli4_cq_event_release(phba, cq_event);
  7502. }
  7503. }
  7504. static void
  7505. lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn,
  7506. struct lpfc_iocbq *pIocbOut,
  7507. struct lpfc_wcqe_complete *wcqe)
  7508. {
  7509. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7510. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7511. sizeof(struct lpfc_iocbq) - offset);
  7512. /* Map WCQE parameters into irspiocb parameters */
  7513. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7514. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7515. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7516. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7517. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7518. wcqe->total_data_placed;
  7519. else
  7520. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7521. else
  7522. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7523. }
  7524. /**
  7525. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7526. * @phba: Pointer to HBA context object.
  7527. * @wcqe: Pointer to work-queue completion queue entry.
  7528. *
  7529. * This routine handles an ELS work-queue completion event and construct
  7530. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7531. * discovery engine to handle.
  7532. *
  7533. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7534. **/
  7535. static struct lpfc_iocbq *
  7536. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7537. struct lpfc_iocbq *irspiocbq)
  7538. {
  7539. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7540. struct lpfc_iocbq *cmdiocbq;
  7541. struct lpfc_wcqe_complete *wcqe;
  7542. unsigned long iflags;
  7543. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7544. spin_lock_irqsave(&phba->hbalock, iflags);
  7545. pring->stats.iocb_event++;
  7546. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7547. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7548. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7549. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7550. if (unlikely(!cmdiocbq)) {
  7551. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7552. "0386 ELS complete with no corresponding "
  7553. "cmdiocb: iotag (%d)\n",
  7554. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7555. lpfc_sli_release_iocbq(phba, irspiocbq);
  7556. return NULL;
  7557. }
  7558. /* Fake the irspiocbq and copy necessary response information */
  7559. lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe);
  7560. return irspiocbq;
  7561. }
  7562. /**
  7563. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7564. * @phba: Pointer to HBA context object.
  7565. * @cqe: Pointer to mailbox completion queue entry.
  7566. *
  7567. * This routine process a mailbox completion queue entry with asynchrous
  7568. * event.
  7569. *
  7570. * Return: true if work posted to worker thread, otherwise false.
  7571. **/
  7572. static bool
  7573. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7574. {
  7575. struct lpfc_cq_event *cq_event;
  7576. unsigned long iflags;
  7577. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7578. "0392 Async Event: word0:x%x, word1:x%x, "
  7579. "word2:x%x, word3:x%x\n", mcqe->word0,
  7580. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7581. /* Allocate a new internal CQ_EVENT entry */
  7582. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7583. if (!cq_event) {
  7584. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7585. "0394 Failed to allocate CQ_EVENT entry\n");
  7586. return false;
  7587. }
  7588. /* Move the CQE into an asynchronous event entry */
  7589. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7590. spin_lock_irqsave(&phba->hbalock, iflags);
  7591. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7592. /* Set the async event flag */
  7593. phba->hba_flag |= ASYNC_EVENT;
  7594. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7595. return true;
  7596. }
  7597. /**
  7598. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7599. * @phba: Pointer to HBA context object.
  7600. * @cqe: Pointer to mailbox completion queue entry.
  7601. *
  7602. * This routine process a mailbox completion queue entry with mailbox
  7603. * completion event.
  7604. *
  7605. * Return: true if work posted to worker thread, otherwise false.
  7606. **/
  7607. static bool
  7608. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7609. {
  7610. uint32_t mcqe_status;
  7611. MAILBOX_t *mbox, *pmbox;
  7612. struct lpfc_mqe *mqe;
  7613. struct lpfc_vport *vport;
  7614. struct lpfc_nodelist *ndlp;
  7615. struct lpfc_dmabuf *mp;
  7616. unsigned long iflags;
  7617. LPFC_MBOXQ_t *pmb;
  7618. bool workposted = false;
  7619. int rc;
  7620. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7621. if (!bf_get(lpfc_trailer_completed, mcqe))
  7622. goto out_no_mqe_complete;
  7623. /* Get the reference to the active mbox command */
  7624. spin_lock_irqsave(&phba->hbalock, iflags);
  7625. pmb = phba->sli.mbox_active;
  7626. if (unlikely(!pmb)) {
  7627. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7628. "1832 No pending MBOX command to handle\n");
  7629. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7630. goto out_no_mqe_complete;
  7631. }
  7632. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7633. mqe = &pmb->u.mqe;
  7634. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7635. mbox = phba->mbox;
  7636. vport = pmb->vport;
  7637. /* Reset heartbeat timer */
  7638. phba->last_completion_time = jiffies;
  7639. del_timer(&phba->sli.mbox_tmo);
  7640. /* Move mbox data to caller's mailbox region, do endian swapping */
  7641. if (pmb->mbox_cmpl && mbox)
  7642. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7643. /* Set the mailbox status with SLI4 range 0x4000 */
  7644. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7645. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7646. bf_set(lpfc_mqe_status, mqe,
  7647. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7648. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7649. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7650. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7651. "MBOX dflt rpi: status:x%x rpi:x%x",
  7652. mcqe_status,
  7653. pmbox->un.varWords[0], 0);
  7654. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7655. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7656. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7657. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7658. * RID of the PPI using the same mbox buffer.
  7659. */
  7660. lpfc_unreg_login(phba, vport->vpi,
  7661. pmbox->un.varWords[0], pmb);
  7662. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7663. pmb->context1 = mp;
  7664. pmb->context2 = ndlp;
  7665. pmb->vport = vport;
  7666. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7667. if (rc != MBX_BUSY)
  7668. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7669. LOG_SLI, "0385 rc should "
  7670. "have been MBX_BUSY\n");
  7671. if (rc != MBX_NOT_FINISHED)
  7672. goto send_current_mbox;
  7673. }
  7674. }
  7675. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7676. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7677. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7678. /* There is mailbox completion work to do */
  7679. spin_lock_irqsave(&phba->hbalock, iflags);
  7680. __lpfc_mbox_cmpl_put(phba, pmb);
  7681. phba->work_ha |= HA_MBATT;
  7682. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7683. workposted = true;
  7684. send_current_mbox:
  7685. spin_lock_irqsave(&phba->hbalock, iflags);
  7686. /* Release the mailbox command posting token */
  7687. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7688. /* Setting active mailbox pointer need to be in sync to flag clear */
  7689. phba->sli.mbox_active = NULL;
  7690. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7691. /* Wake up worker thread to post the next pending mailbox command */
  7692. lpfc_worker_wake_up(phba);
  7693. out_no_mqe_complete:
  7694. if (bf_get(lpfc_trailer_consumed, mcqe))
  7695. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7696. return workposted;
  7697. }
  7698. /**
  7699. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7700. * @phba: Pointer to HBA context object.
  7701. * @cqe: Pointer to mailbox completion queue entry.
  7702. *
  7703. * This routine process a mailbox completion queue entry, it invokes the
  7704. * proper mailbox complete handling or asynchrous event handling routine
  7705. * according to the MCQE's async bit.
  7706. *
  7707. * Return: true if work posted to worker thread, otherwise false.
  7708. **/
  7709. static bool
  7710. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7711. {
  7712. struct lpfc_mcqe mcqe;
  7713. bool workposted;
  7714. /* Copy the mailbox MCQE and convert endian order as needed */
  7715. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7716. /* Invoke the proper event handling routine */
  7717. if (!bf_get(lpfc_trailer_async, &mcqe))
  7718. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7719. else
  7720. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7721. return workposted;
  7722. }
  7723. /**
  7724. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7725. * @phba: Pointer to HBA context object.
  7726. * @wcqe: Pointer to work-queue completion queue entry.
  7727. *
  7728. * This routine handles an ELS work-queue completion event.
  7729. *
  7730. * Return: true if work posted to worker thread, otherwise false.
  7731. **/
  7732. static bool
  7733. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7734. struct lpfc_wcqe_complete *wcqe)
  7735. {
  7736. struct lpfc_iocbq *irspiocbq;
  7737. unsigned long iflags;
  7738. /* Get an irspiocbq for later ELS response processing use */
  7739. irspiocbq = lpfc_sli_get_iocbq(phba);
  7740. if (!irspiocbq) {
  7741. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7742. "0387 Failed to allocate an iocbq\n");
  7743. return false;
  7744. }
  7745. /* Save off the slow-path queue event for work thread to process */
  7746. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  7747. spin_lock_irqsave(&phba->hbalock, iflags);
  7748. list_add_tail(&irspiocbq->cq_event.list,
  7749. &phba->sli4_hba.sp_queue_event);
  7750. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7751. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7752. return true;
  7753. }
  7754. /**
  7755. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7756. * @phba: Pointer to HBA context object.
  7757. * @wcqe: Pointer to work-queue completion queue entry.
  7758. *
  7759. * This routine handles slow-path WQ entry comsumed event by invoking the
  7760. * proper WQ release routine to the slow-path WQ.
  7761. **/
  7762. static void
  7763. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7764. struct lpfc_wcqe_release *wcqe)
  7765. {
  7766. /* Check for the slow-path ELS work queue */
  7767. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7768. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7769. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7770. else
  7771. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7772. "2579 Slow-path wqe consume event carries "
  7773. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7774. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7775. phba->sli4_hba.els_wq->queue_id);
  7776. }
  7777. /**
  7778. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7779. * @phba: Pointer to HBA context object.
  7780. * @cq: Pointer to a WQ completion queue.
  7781. * @wcqe: Pointer to work-queue completion queue entry.
  7782. *
  7783. * This routine handles an XRI abort event.
  7784. *
  7785. * Return: true if work posted to worker thread, otherwise false.
  7786. **/
  7787. static bool
  7788. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7789. struct lpfc_queue *cq,
  7790. struct sli4_wcqe_xri_aborted *wcqe)
  7791. {
  7792. bool workposted = false;
  7793. struct lpfc_cq_event *cq_event;
  7794. unsigned long iflags;
  7795. /* Allocate a new internal CQ_EVENT entry */
  7796. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7797. if (!cq_event) {
  7798. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7799. "0602 Failed to allocate CQ_EVENT entry\n");
  7800. return false;
  7801. }
  7802. /* Move the CQE into the proper xri abort event list */
  7803. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  7804. switch (cq->subtype) {
  7805. case LPFC_FCP:
  7806. spin_lock_irqsave(&phba->hbalock, iflags);
  7807. list_add_tail(&cq_event->list,
  7808. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  7809. /* Set the fcp xri abort event flag */
  7810. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  7811. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7812. workposted = true;
  7813. break;
  7814. case LPFC_ELS:
  7815. spin_lock_irqsave(&phba->hbalock, iflags);
  7816. list_add_tail(&cq_event->list,
  7817. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  7818. /* Set the els xri abort event flag */
  7819. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  7820. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7821. workposted = true;
  7822. break;
  7823. default:
  7824. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7825. "0603 Invalid work queue CQE subtype (x%x)\n",
  7826. cq->subtype);
  7827. workposted = false;
  7828. break;
  7829. }
  7830. return workposted;
  7831. }
  7832. /**
  7833. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  7834. * @phba: Pointer to HBA context object.
  7835. * @rcqe: Pointer to receive-queue completion queue entry.
  7836. *
  7837. * This routine process a receive-queue completion queue entry.
  7838. *
  7839. * Return: true if work posted to worker thread, otherwise false.
  7840. **/
  7841. static bool
  7842. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  7843. {
  7844. bool workposted = false;
  7845. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  7846. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  7847. struct hbq_dmabuf *dma_buf;
  7848. uint32_t status;
  7849. unsigned long iflags;
  7850. lpfc_sli4_rq_release(hrq, drq);
  7851. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  7852. goto out;
  7853. status = bf_get(lpfc_rcqe_status, rcqe);
  7854. switch (status) {
  7855. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  7856. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7857. "2537 Receive Frame Truncated!!\n");
  7858. case FC_STATUS_RQ_SUCCESS:
  7859. spin_lock_irqsave(&phba->hbalock, iflags);
  7860. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  7861. if (!dma_buf) {
  7862. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7863. goto out;
  7864. }
  7865. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  7866. /* save off the frame for the word thread to process */
  7867. list_add_tail(&dma_buf->cq_event.list,
  7868. &phba->sli4_hba.sp_queue_event);
  7869. /* Frame received */
  7870. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7871. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7872. workposted = true;
  7873. break;
  7874. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  7875. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  7876. /* Post more buffers if possible */
  7877. spin_lock_irqsave(&phba->hbalock, iflags);
  7878. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  7879. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7880. workposted = true;
  7881. break;
  7882. }
  7883. out:
  7884. return workposted;
  7885. }
  7886. /**
  7887. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  7888. * @phba: Pointer to HBA context object.
  7889. * @cq: Pointer to the completion queue.
  7890. * @wcqe: Pointer to a completion queue entry.
  7891. *
  7892. * This routine process a slow-path work-queue or recieve queue completion queue
  7893. * entry.
  7894. *
  7895. * Return: true if work posted to worker thread, otherwise false.
  7896. **/
  7897. static bool
  7898. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  7899. struct lpfc_cqe *cqe)
  7900. {
  7901. struct lpfc_cqe cqevt;
  7902. bool workposted = false;
  7903. /* Copy the work queue CQE and convert endian order if needed */
  7904. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  7905. /* Check and process for different type of WCQE and dispatch */
  7906. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  7907. case CQE_CODE_COMPL_WQE:
  7908. /* Process the WQ/RQ complete event */
  7909. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  7910. (struct lpfc_wcqe_complete *)&cqevt);
  7911. break;
  7912. case CQE_CODE_RELEASE_WQE:
  7913. /* Process the WQ release event */
  7914. lpfc_sli4_sp_handle_rel_wcqe(phba,
  7915. (struct lpfc_wcqe_release *)&cqevt);
  7916. break;
  7917. case CQE_CODE_XRI_ABORTED:
  7918. /* Process the WQ XRI abort event */
  7919. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  7920. (struct sli4_wcqe_xri_aborted *)&cqevt);
  7921. break;
  7922. case CQE_CODE_RECEIVE:
  7923. /* Process the RQ event */
  7924. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  7925. (struct lpfc_rcqe *)&cqevt);
  7926. break;
  7927. default:
  7928. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7929. "0388 Not a valid WCQE code: x%x\n",
  7930. bf_get(lpfc_cqe_code, &cqevt));
  7931. break;
  7932. }
  7933. return workposted;
  7934. }
  7935. /**
  7936. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  7937. * @phba: Pointer to HBA context object.
  7938. * @eqe: Pointer to fast-path event queue entry.
  7939. *
  7940. * This routine process a event queue entry from the slow-path event queue.
  7941. * It will check the MajorCode and MinorCode to determine this is for a
  7942. * completion event on a completion queue, if not, an error shall be logged
  7943. * and just return. Otherwise, it will get to the corresponding completion
  7944. * queue and process all the entries on that completion queue, rearm the
  7945. * completion queue, and then return.
  7946. *
  7947. **/
  7948. static void
  7949. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  7950. {
  7951. struct lpfc_queue *cq = NULL, *childq, *speq;
  7952. struct lpfc_cqe *cqe;
  7953. bool workposted = false;
  7954. int ecount = 0;
  7955. uint16_t cqid;
  7956. if (bf_get(lpfc_eqe_major_code, eqe) != 0 ||
  7957. bf_get(lpfc_eqe_minor_code, eqe) != 0) {
  7958. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7959. "0359 Not a valid slow-path completion "
  7960. "event: majorcode=x%x, minorcode=x%x\n",
  7961. bf_get(lpfc_eqe_major_code, eqe),
  7962. bf_get(lpfc_eqe_minor_code, eqe));
  7963. return;
  7964. }
  7965. /* Get the reference to the corresponding CQ */
  7966. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  7967. /* Search for completion queue pointer matching this cqid */
  7968. speq = phba->sli4_hba.sp_eq;
  7969. list_for_each_entry(childq, &speq->child_list, list) {
  7970. if (childq->queue_id == cqid) {
  7971. cq = childq;
  7972. break;
  7973. }
  7974. }
  7975. if (unlikely(!cq)) {
  7976. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7977. "0365 Slow-path CQ identifier (%d) does "
  7978. "not exist\n", cqid);
  7979. return;
  7980. }
  7981. /* Process all the entries to the CQ */
  7982. switch (cq->type) {
  7983. case LPFC_MCQ:
  7984. while ((cqe = lpfc_sli4_cq_get(cq))) {
  7985. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  7986. if (!(++ecount % LPFC_GET_QE_REL_INT))
  7987. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  7988. }
  7989. break;
  7990. case LPFC_WCQ:
  7991. while ((cqe = lpfc_sli4_cq_get(cq))) {
  7992. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  7993. if (!(++ecount % LPFC_GET_QE_REL_INT))
  7994. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  7995. }
  7996. break;
  7997. default:
  7998. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7999. "0370 Invalid completion queue type (%d)\n",
  8000. cq->type);
  8001. return;
  8002. }
  8003. /* Catch the no cq entry condition, log an error */
  8004. if (unlikely(ecount == 0))
  8005. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8006. "0371 No entry from the CQ: identifier "
  8007. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8008. /* In any case, flash and re-arm the RCQ */
  8009. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8010. /* wake up worker thread if there are works to be done */
  8011. if (workposted)
  8012. lpfc_worker_wake_up(phba);
  8013. }
  8014. /**
  8015. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8016. * @eqe: Pointer to fast-path completion queue entry.
  8017. *
  8018. * This routine process a fast-path work queue completion entry from fast-path
  8019. * event queue for FCP command response completion.
  8020. **/
  8021. static void
  8022. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8023. struct lpfc_wcqe_complete *wcqe)
  8024. {
  8025. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8026. struct lpfc_iocbq *cmdiocbq;
  8027. struct lpfc_iocbq irspiocbq;
  8028. unsigned long iflags;
  8029. spin_lock_irqsave(&phba->hbalock, iflags);
  8030. pring->stats.iocb_event++;
  8031. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8032. /* Check for response status */
  8033. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8034. /* If resource errors reported from HBA, reduce queue
  8035. * depth of the SCSI device.
  8036. */
  8037. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8038. IOSTAT_LOCAL_REJECT) &&
  8039. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8040. phba->lpfc_rampdown_queue_depth(phba);
  8041. }
  8042. /* Log the error status */
  8043. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8044. "0373 FCP complete error: status=x%x, "
  8045. "hw_status=x%x, total_data_specified=%d, "
  8046. "parameter=x%x, word3=x%x\n",
  8047. bf_get(lpfc_wcqe_c_status, wcqe),
  8048. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8049. wcqe->total_data_placed, wcqe->parameter,
  8050. wcqe->word3);
  8051. }
  8052. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8053. spin_lock_irqsave(&phba->hbalock, iflags);
  8054. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8055. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8056. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8057. if (unlikely(!cmdiocbq)) {
  8058. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8059. "0374 FCP complete with no corresponding "
  8060. "cmdiocb: iotag (%d)\n",
  8061. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8062. return;
  8063. }
  8064. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8065. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8066. "0375 FCP cmdiocb not callback function "
  8067. "iotag: (%d)\n",
  8068. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8069. return;
  8070. }
  8071. /* Fake the irspiocb and copy necessary response information */
  8072. lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe);
  8073. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8074. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8075. }
  8076. /**
  8077. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8078. * @phba: Pointer to HBA context object.
  8079. * @cq: Pointer to completion queue.
  8080. * @wcqe: Pointer to work-queue completion queue entry.
  8081. *
  8082. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8083. * proper WQ release routine to the slow-path WQ.
  8084. **/
  8085. static void
  8086. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8087. struct lpfc_wcqe_release *wcqe)
  8088. {
  8089. struct lpfc_queue *childwq;
  8090. bool wqid_matched = false;
  8091. uint16_t fcp_wqid;
  8092. /* Check for fast-path FCP work queue release */
  8093. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8094. list_for_each_entry(childwq, &cq->child_list, list) {
  8095. if (childwq->queue_id == fcp_wqid) {
  8096. lpfc_sli4_wq_release(childwq,
  8097. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8098. wqid_matched = true;
  8099. break;
  8100. }
  8101. }
  8102. /* Report warning log message if no match found */
  8103. if (wqid_matched != true)
  8104. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8105. "2580 Fast-path wqe consume event carries "
  8106. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8107. }
  8108. /**
  8109. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8110. * @cq: Pointer to the completion queue.
  8111. * @eqe: Pointer to fast-path completion queue entry.
  8112. *
  8113. * This routine process a fast-path work queue completion entry from fast-path
  8114. * event queue for FCP command response completion.
  8115. **/
  8116. static int
  8117. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8118. struct lpfc_cqe *cqe)
  8119. {
  8120. struct lpfc_wcqe_release wcqe;
  8121. bool workposted = false;
  8122. /* Copy the work queue CQE and convert endian order if needed */
  8123. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8124. /* Check and process for different type of WCQE and dispatch */
  8125. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8126. case CQE_CODE_COMPL_WQE:
  8127. /* Process the WQ complete event */
  8128. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8129. (struct lpfc_wcqe_complete *)&wcqe);
  8130. break;
  8131. case CQE_CODE_RELEASE_WQE:
  8132. /* Process the WQ release event */
  8133. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8134. (struct lpfc_wcqe_release *)&wcqe);
  8135. break;
  8136. case CQE_CODE_XRI_ABORTED:
  8137. /* Process the WQ XRI abort event */
  8138. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8139. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8140. break;
  8141. default:
  8142. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8143. "0144 Not a valid WCQE code: x%x\n",
  8144. bf_get(lpfc_wcqe_c_code, &wcqe));
  8145. break;
  8146. }
  8147. return workposted;
  8148. }
  8149. /**
  8150. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8151. * @phba: Pointer to HBA context object.
  8152. * @eqe: Pointer to fast-path event queue entry.
  8153. *
  8154. * This routine process a event queue entry from the fast-path event queue.
  8155. * It will check the MajorCode and MinorCode to determine this is for a
  8156. * completion event on a completion queue, if not, an error shall be logged
  8157. * and just return. Otherwise, it will get to the corresponding completion
  8158. * queue and process all the entries on the completion queue, rearm the
  8159. * completion queue, and then return.
  8160. **/
  8161. static void
  8162. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8163. uint32_t fcp_cqidx)
  8164. {
  8165. struct lpfc_queue *cq;
  8166. struct lpfc_cqe *cqe;
  8167. bool workposted = false;
  8168. uint16_t cqid;
  8169. int ecount = 0;
  8170. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) ||
  8171. unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) {
  8172. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8173. "0366 Not a valid fast-path completion "
  8174. "event: majorcode=x%x, minorcode=x%x\n",
  8175. bf_get(lpfc_eqe_major_code, eqe),
  8176. bf_get(lpfc_eqe_minor_code, eqe));
  8177. return;
  8178. }
  8179. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8180. if (unlikely(!cq)) {
  8181. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8182. "0367 Fast-path completion queue does not "
  8183. "exist\n");
  8184. return;
  8185. }
  8186. /* Get the reference to the corresponding CQ */
  8187. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8188. if (unlikely(cqid != cq->queue_id)) {
  8189. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8190. "0368 Miss-matched fast-path completion "
  8191. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8192. cqid, cq->queue_id);
  8193. return;
  8194. }
  8195. /* Process all the entries to the CQ */
  8196. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8197. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8198. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8199. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8200. }
  8201. /* Catch the no cq entry condition */
  8202. if (unlikely(ecount == 0))
  8203. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8204. "0369 No entry from fast-path completion "
  8205. "queue fcpcqid=%d\n", cq->queue_id);
  8206. /* In any case, flash and re-arm the CQ */
  8207. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8208. /* wake up worker thread if there are works to be done */
  8209. if (workposted)
  8210. lpfc_worker_wake_up(phba);
  8211. }
  8212. static void
  8213. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8214. {
  8215. struct lpfc_eqe *eqe;
  8216. /* walk all the EQ entries and drop on the floor */
  8217. while ((eqe = lpfc_sli4_eq_get(eq)))
  8218. ;
  8219. /* Clear and re-arm the EQ */
  8220. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8221. }
  8222. /**
  8223. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8224. * @irq: Interrupt number.
  8225. * @dev_id: The device context pointer.
  8226. *
  8227. * This function is directly called from the PCI layer as an interrupt
  8228. * service routine when device with SLI-4 interface spec is enabled with
  8229. * MSI-X multi-message interrupt mode and there are slow-path events in
  8230. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8231. * interrupt mode, this function is called as part of the device-level
  8232. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8233. * undergoing initialization, the interrupt handler will not process the
  8234. * interrupt. The link attention and ELS ring attention events are handled
  8235. * by the worker thread. The interrupt handler signals the worker thread
  8236. * and returns for these events. This function is called without any lock
  8237. * held. It gets the hbalock to access and update SLI data structures.
  8238. *
  8239. * This function returns IRQ_HANDLED when interrupt is handled else it
  8240. * returns IRQ_NONE.
  8241. **/
  8242. irqreturn_t
  8243. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8244. {
  8245. struct lpfc_hba *phba;
  8246. struct lpfc_queue *speq;
  8247. struct lpfc_eqe *eqe;
  8248. unsigned long iflag;
  8249. int ecount = 0;
  8250. /*
  8251. * Get the driver's phba structure from the dev_id
  8252. */
  8253. phba = (struct lpfc_hba *)dev_id;
  8254. if (unlikely(!phba))
  8255. return IRQ_NONE;
  8256. /* Get to the EQ struct associated with this vector */
  8257. speq = phba->sli4_hba.sp_eq;
  8258. /* Check device state for handling interrupt */
  8259. if (unlikely(lpfc_intr_state_check(phba))) {
  8260. /* Check again for link_state with lock held */
  8261. spin_lock_irqsave(&phba->hbalock, iflag);
  8262. if (phba->link_state < LPFC_LINK_DOWN)
  8263. /* Flush, clear interrupt, and rearm the EQ */
  8264. lpfc_sli4_eq_flush(phba, speq);
  8265. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8266. return IRQ_NONE;
  8267. }
  8268. /*
  8269. * Process all the event on FCP slow-path EQ
  8270. */
  8271. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8272. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8273. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8274. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8275. }
  8276. /* Always clear and re-arm the slow-path EQ */
  8277. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8278. /* Catch the no cq entry condition */
  8279. if (unlikely(ecount == 0)) {
  8280. if (phba->intr_type == MSIX)
  8281. /* MSI-X treated interrupt served as no EQ share INT */
  8282. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8283. "0357 MSI-X interrupt with no EQE\n");
  8284. else
  8285. /* Non MSI-X treated on interrupt as EQ share INT */
  8286. return IRQ_NONE;
  8287. }
  8288. return IRQ_HANDLED;
  8289. } /* lpfc_sli4_sp_intr_handler */
  8290. /**
  8291. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8292. * @irq: Interrupt number.
  8293. * @dev_id: The device context pointer.
  8294. *
  8295. * This function is directly called from the PCI layer as an interrupt
  8296. * service routine when device with SLI-4 interface spec is enabled with
  8297. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8298. * ring event in the HBA. However, when the device is enabled with either
  8299. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8300. * device-level interrupt handler. When the PCI slot is in error recovery
  8301. * or the HBA is undergoing initialization, the interrupt handler will not
  8302. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8303. * the intrrupt context. This function is called without any lock held.
  8304. * It gets the hbalock to access and update SLI data structures. Note that,
  8305. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8306. * equal to that of FCP CQ index.
  8307. *
  8308. * This function returns IRQ_HANDLED when interrupt is handled else it
  8309. * returns IRQ_NONE.
  8310. **/
  8311. irqreturn_t
  8312. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8313. {
  8314. struct lpfc_hba *phba;
  8315. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8316. struct lpfc_queue *fpeq;
  8317. struct lpfc_eqe *eqe;
  8318. unsigned long iflag;
  8319. int ecount = 0;
  8320. uint32_t fcp_eqidx;
  8321. /* Get the driver's phba structure from the dev_id */
  8322. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8323. phba = fcp_eq_hdl->phba;
  8324. fcp_eqidx = fcp_eq_hdl->idx;
  8325. if (unlikely(!phba))
  8326. return IRQ_NONE;
  8327. /* Get to the EQ struct associated with this vector */
  8328. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8329. /* Check device state for handling interrupt */
  8330. if (unlikely(lpfc_intr_state_check(phba))) {
  8331. /* Check again for link_state with lock held */
  8332. spin_lock_irqsave(&phba->hbalock, iflag);
  8333. if (phba->link_state < LPFC_LINK_DOWN)
  8334. /* Flush, clear interrupt, and rearm the EQ */
  8335. lpfc_sli4_eq_flush(phba, fpeq);
  8336. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8337. return IRQ_NONE;
  8338. }
  8339. /*
  8340. * Process all the event on FCP fast-path EQ
  8341. */
  8342. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8343. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8344. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8345. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8346. }
  8347. /* Always clear and re-arm the fast-path EQ */
  8348. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8349. if (unlikely(ecount == 0)) {
  8350. if (phba->intr_type == MSIX)
  8351. /* MSI-X treated interrupt served as no EQ share INT */
  8352. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8353. "0358 MSI-X interrupt with no EQE\n");
  8354. else
  8355. /* Non MSI-X treated on interrupt as EQ share INT */
  8356. return IRQ_NONE;
  8357. }
  8358. return IRQ_HANDLED;
  8359. } /* lpfc_sli4_fp_intr_handler */
  8360. /**
  8361. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8362. * @irq: Interrupt number.
  8363. * @dev_id: The device context pointer.
  8364. *
  8365. * This function is the device-level interrupt handler to device with SLI-4
  8366. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8367. * interrupt mode is enabled and there is an event in the HBA which requires
  8368. * driver attention. This function invokes the slow-path interrupt attention
  8369. * handling function and fast-path interrupt attention handling function in
  8370. * turn to process the relevant HBA attention events. This function is called
  8371. * without any lock held. It gets the hbalock to access and update SLI data
  8372. * structures.
  8373. *
  8374. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8375. * returns IRQ_NONE.
  8376. **/
  8377. irqreturn_t
  8378. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8379. {
  8380. struct lpfc_hba *phba;
  8381. irqreturn_t sp_irq_rc, fp_irq_rc;
  8382. bool fp_handled = false;
  8383. uint32_t fcp_eqidx;
  8384. /* Get the driver's phba structure from the dev_id */
  8385. phba = (struct lpfc_hba *)dev_id;
  8386. if (unlikely(!phba))
  8387. return IRQ_NONE;
  8388. /*
  8389. * Invokes slow-path host attention interrupt handling as appropriate.
  8390. */
  8391. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8392. /*
  8393. * Invoke fast-path host attention interrupt handling as appropriate.
  8394. */
  8395. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8396. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8397. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8398. if (fp_irq_rc == IRQ_HANDLED)
  8399. fp_handled |= true;
  8400. }
  8401. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8402. } /* lpfc_sli4_intr_handler */
  8403. /**
  8404. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8405. * @queue: The queue structure to free.
  8406. *
  8407. * This function frees a queue structure and the DMAable memeory used for
  8408. * the host resident queue. This function must be called after destroying the
  8409. * queue on the HBA.
  8410. **/
  8411. void
  8412. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8413. {
  8414. struct lpfc_dmabuf *dmabuf;
  8415. if (!queue)
  8416. return;
  8417. while (!list_empty(&queue->page_list)) {
  8418. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8419. list);
  8420. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8421. dmabuf->virt, dmabuf->phys);
  8422. kfree(dmabuf);
  8423. }
  8424. kfree(queue);
  8425. return;
  8426. }
  8427. /**
  8428. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8429. * @phba: The HBA that this queue is being created on.
  8430. * @entry_size: The size of each queue entry for this queue.
  8431. * @entry count: The number of entries that this queue will handle.
  8432. *
  8433. * This function allocates a queue structure and the DMAable memory used for
  8434. * the host resident queue. This function must be called before creating the
  8435. * queue on the HBA.
  8436. **/
  8437. struct lpfc_queue *
  8438. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8439. uint32_t entry_count)
  8440. {
  8441. struct lpfc_queue *queue;
  8442. struct lpfc_dmabuf *dmabuf;
  8443. int x, total_qe_count;
  8444. void *dma_pointer;
  8445. queue = kzalloc(sizeof(struct lpfc_queue) +
  8446. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8447. if (!queue)
  8448. return NULL;
  8449. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8450. INIT_LIST_HEAD(&queue->list);
  8451. INIT_LIST_HEAD(&queue->page_list);
  8452. INIT_LIST_HEAD(&queue->child_list);
  8453. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8454. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8455. if (!dmabuf)
  8456. goto out_fail;
  8457. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8458. PAGE_SIZE, &dmabuf->phys,
  8459. GFP_KERNEL);
  8460. if (!dmabuf->virt) {
  8461. kfree(dmabuf);
  8462. goto out_fail;
  8463. }
  8464. memset(dmabuf->virt, 0, PAGE_SIZE);
  8465. dmabuf->buffer_tag = x;
  8466. list_add_tail(&dmabuf->list, &queue->page_list);
  8467. /* initialize queue's entry array */
  8468. dma_pointer = dmabuf->virt;
  8469. for (; total_qe_count < entry_count &&
  8470. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8471. total_qe_count++, dma_pointer += entry_size) {
  8472. queue->qe[total_qe_count].address = dma_pointer;
  8473. }
  8474. }
  8475. queue->entry_size = entry_size;
  8476. queue->entry_count = entry_count;
  8477. queue->phba = phba;
  8478. return queue;
  8479. out_fail:
  8480. lpfc_sli4_queue_free(queue);
  8481. return NULL;
  8482. }
  8483. /**
  8484. * lpfc_eq_create - Create an Event Queue on the HBA
  8485. * @phba: HBA structure that indicates port to create a queue on.
  8486. * @eq: The queue structure to use to create the event queue.
  8487. * @imax: The maximum interrupt per second limit.
  8488. *
  8489. * This function creates an event queue, as detailed in @eq, on a port,
  8490. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8491. *
  8492. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8493. * is used to get the entry count and entry size that are necessary to
  8494. * determine the number of pages to allocate and use for this queue. This
  8495. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8496. * event queue. This function is asynchronous and will wait for the mailbox
  8497. * command to finish before continuing.
  8498. *
  8499. * On success this function will return a zero. If unable to allocate enough
  8500. * memory this function will return ENOMEM. If the queue create mailbox command
  8501. * fails this function will return ENXIO.
  8502. **/
  8503. uint32_t
  8504. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8505. {
  8506. struct lpfc_mbx_eq_create *eq_create;
  8507. LPFC_MBOXQ_t *mbox;
  8508. int rc, length, status = 0;
  8509. struct lpfc_dmabuf *dmabuf;
  8510. uint32_t shdr_status, shdr_add_status;
  8511. union lpfc_sli4_cfg_shdr *shdr;
  8512. uint16_t dmult;
  8513. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8514. if (!mbox)
  8515. return -ENOMEM;
  8516. length = (sizeof(struct lpfc_mbx_eq_create) -
  8517. sizeof(struct lpfc_sli4_cfg_mhdr));
  8518. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8519. LPFC_MBOX_OPCODE_EQ_CREATE,
  8520. length, LPFC_SLI4_MBX_EMBED);
  8521. eq_create = &mbox->u.mqe.un.eq_create;
  8522. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8523. eq->page_count);
  8524. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8525. LPFC_EQE_SIZE);
  8526. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8527. /* Calculate delay multiper from maximum interrupt per second */
  8528. dmult = LPFC_DMULT_CONST/imax - 1;
  8529. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8530. dmult);
  8531. switch (eq->entry_count) {
  8532. default:
  8533. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8534. "0360 Unsupported EQ count. (%d)\n",
  8535. eq->entry_count);
  8536. if (eq->entry_count < 256)
  8537. return -EINVAL;
  8538. /* otherwise default to smallest count (drop through) */
  8539. case 256:
  8540. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8541. LPFC_EQ_CNT_256);
  8542. break;
  8543. case 512:
  8544. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8545. LPFC_EQ_CNT_512);
  8546. break;
  8547. case 1024:
  8548. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8549. LPFC_EQ_CNT_1024);
  8550. break;
  8551. case 2048:
  8552. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8553. LPFC_EQ_CNT_2048);
  8554. break;
  8555. case 4096:
  8556. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8557. LPFC_EQ_CNT_4096);
  8558. break;
  8559. }
  8560. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8561. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8562. putPaddrLow(dmabuf->phys);
  8563. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8564. putPaddrHigh(dmabuf->phys);
  8565. }
  8566. mbox->vport = phba->pport;
  8567. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8568. mbox->context1 = NULL;
  8569. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8570. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8571. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8572. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8573. if (shdr_status || shdr_add_status || rc) {
  8574. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8575. "2500 EQ_CREATE mailbox failed with "
  8576. "status x%x add_status x%x, mbx status x%x\n",
  8577. shdr_status, shdr_add_status, rc);
  8578. status = -ENXIO;
  8579. }
  8580. eq->type = LPFC_EQ;
  8581. eq->subtype = LPFC_NONE;
  8582. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8583. if (eq->queue_id == 0xFFFF)
  8584. status = -ENXIO;
  8585. eq->host_index = 0;
  8586. eq->hba_index = 0;
  8587. mempool_free(mbox, phba->mbox_mem_pool);
  8588. return status;
  8589. }
  8590. /**
  8591. * lpfc_cq_create - Create a Completion Queue on the HBA
  8592. * @phba: HBA structure that indicates port to create a queue on.
  8593. * @cq: The queue structure to use to create the completion queue.
  8594. * @eq: The event queue to bind this completion queue to.
  8595. *
  8596. * This function creates a completion queue, as detailed in @wq, on a port,
  8597. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8598. *
  8599. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8600. * is used to get the entry count and entry size that are necessary to
  8601. * determine the number of pages to allocate and use for this queue. The @eq
  8602. * is used to indicate which event queue to bind this completion queue to. This
  8603. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8604. * completion queue. This function is asynchronous and will wait for the mailbox
  8605. * command to finish before continuing.
  8606. *
  8607. * On success this function will return a zero. If unable to allocate enough
  8608. * memory this function will return ENOMEM. If the queue create mailbox command
  8609. * fails this function will return ENXIO.
  8610. **/
  8611. uint32_t
  8612. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8613. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8614. {
  8615. struct lpfc_mbx_cq_create *cq_create;
  8616. struct lpfc_dmabuf *dmabuf;
  8617. LPFC_MBOXQ_t *mbox;
  8618. int rc, length, status = 0;
  8619. uint32_t shdr_status, shdr_add_status;
  8620. union lpfc_sli4_cfg_shdr *shdr;
  8621. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8622. if (!mbox)
  8623. return -ENOMEM;
  8624. length = (sizeof(struct lpfc_mbx_cq_create) -
  8625. sizeof(struct lpfc_sli4_cfg_mhdr));
  8626. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8627. LPFC_MBOX_OPCODE_CQ_CREATE,
  8628. length, LPFC_SLI4_MBX_EMBED);
  8629. cq_create = &mbox->u.mqe.un.cq_create;
  8630. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8631. cq->page_count);
  8632. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8633. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8634. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8635. switch (cq->entry_count) {
  8636. default:
  8637. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8638. "0361 Unsupported CQ count. (%d)\n",
  8639. cq->entry_count);
  8640. if (cq->entry_count < 256)
  8641. return -EINVAL;
  8642. /* otherwise default to smallest count (drop through) */
  8643. case 256:
  8644. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8645. LPFC_CQ_CNT_256);
  8646. break;
  8647. case 512:
  8648. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8649. LPFC_CQ_CNT_512);
  8650. break;
  8651. case 1024:
  8652. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8653. LPFC_CQ_CNT_1024);
  8654. break;
  8655. }
  8656. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8657. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8658. putPaddrLow(dmabuf->phys);
  8659. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8660. putPaddrHigh(dmabuf->phys);
  8661. }
  8662. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8663. /* The IOCTL status is embedded in the mailbox subheader. */
  8664. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8665. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8666. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8667. if (shdr_status || shdr_add_status || rc) {
  8668. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8669. "2501 CQ_CREATE mailbox failed with "
  8670. "status x%x add_status x%x, mbx status x%x\n",
  8671. shdr_status, shdr_add_status, rc);
  8672. status = -ENXIO;
  8673. goto out;
  8674. }
  8675. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8676. if (cq->queue_id == 0xFFFF) {
  8677. status = -ENXIO;
  8678. goto out;
  8679. }
  8680. /* link the cq onto the parent eq child list */
  8681. list_add_tail(&cq->list, &eq->child_list);
  8682. /* Set up completion queue's type and subtype */
  8683. cq->type = type;
  8684. cq->subtype = subtype;
  8685. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8686. cq->host_index = 0;
  8687. cq->hba_index = 0;
  8688. out:
  8689. mempool_free(mbox, phba->mbox_mem_pool);
  8690. return status;
  8691. }
  8692. /**
  8693. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8694. * @phba: HBA structure that indicates port to create a queue on.
  8695. * @mq: The queue structure to use to create the mailbox queue.
  8696. *
  8697. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8698. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8699. *
  8700. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8701. * is used to get the entry count and entry size that are necessary to
  8702. * determine the number of pages to allocate and use for this queue. This
  8703. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8704. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8705. * command to finish before continuing.
  8706. *
  8707. * On success this function will return a zero. If unable to allocate enough
  8708. * memory this function will return ENOMEM. If the queue create mailbox command
  8709. * fails this function will return ENXIO.
  8710. **/
  8711. uint32_t
  8712. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8713. struct lpfc_queue *cq, uint32_t subtype)
  8714. {
  8715. struct lpfc_mbx_mq_create *mq_create;
  8716. struct lpfc_dmabuf *dmabuf;
  8717. LPFC_MBOXQ_t *mbox;
  8718. int rc, length, status = 0;
  8719. uint32_t shdr_status, shdr_add_status;
  8720. union lpfc_sli4_cfg_shdr *shdr;
  8721. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8722. if (!mbox)
  8723. return -ENOMEM;
  8724. length = (sizeof(struct lpfc_mbx_mq_create) -
  8725. sizeof(struct lpfc_sli4_cfg_mhdr));
  8726. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8727. LPFC_MBOX_OPCODE_MQ_CREATE,
  8728. length, LPFC_SLI4_MBX_EMBED);
  8729. mq_create = &mbox->u.mqe.un.mq_create;
  8730. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8731. mq->page_count);
  8732. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8733. cq->queue_id);
  8734. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8735. switch (mq->entry_count) {
  8736. default:
  8737. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8738. "0362 Unsupported MQ count. (%d)\n",
  8739. mq->entry_count);
  8740. if (mq->entry_count < 16)
  8741. return -EINVAL;
  8742. /* otherwise default to smallest count (drop through) */
  8743. case 16:
  8744. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8745. LPFC_MQ_CNT_16);
  8746. break;
  8747. case 32:
  8748. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8749. LPFC_MQ_CNT_32);
  8750. break;
  8751. case 64:
  8752. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8753. LPFC_MQ_CNT_64);
  8754. break;
  8755. case 128:
  8756. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8757. LPFC_MQ_CNT_128);
  8758. break;
  8759. }
  8760. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8761. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8762. putPaddrLow(dmabuf->phys);
  8763. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8764. putPaddrHigh(dmabuf->phys);
  8765. }
  8766. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8767. /* The IOCTL status is embedded in the mailbox subheader. */
  8768. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8769. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8770. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8771. if (shdr_status || shdr_add_status || rc) {
  8772. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8773. "2502 MQ_CREATE mailbox failed with "
  8774. "status x%x add_status x%x, mbx status x%x\n",
  8775. shdr_status, shdr_add_status, rc);
  8776. status = -ENXIO;
  8777. goto out;
  8778. }
  8779. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8780. if (mq->queue_id == 0xFFFF) {
  8781. status = -ENXIO;
  8782. goto out;
  8783. }
  8784. mq->type = LPFC_MQ;
  8785. mq->subtype = subtype;
  8786. mq->host_index = 0;
  8787. mq->hba_index = 0;
  8788. /* link the mq onto the parent cq child list */
  8789. list_add_tail(&mq->list, &cq->child_list);
  8790. out:
  8791. mempool_free(mbox, phba->mbox_mem_pool);
  8792. return status;
  8793. }
  8794. /**
  8795. * lpfc_wq_create - Create a Work Queue on the HBA
  8796. * @phba: HBA structure that indicates port to create a queue on.
  8797. * @wq: The queue structure to use to create the work queue.
  8798. * @cq: The completion queue to bind this work queue to.
  8799. * @subtype: The subtype of the work queue indicating its functionality.
  8800. *
  8801. * This function creates a work queue, as detailed in @wq, on a port, described
  8802. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  8803. *
  8804. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  8805. * is used to get the entry count and entry size that are necessary to
  8806. * determine the number of pages to allocate and use for this queue. The @cq
  8807. * is used to indicate which completion queue to bind this work queue to. This
  8808. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  8809. * work queue. This function is asynchronous and will wait for the mailbox
  8810. * command to finish before continuing.
  8811. *
  8812. * On success this function will return a zero. If unable to allocate enough
  8813. * memory this function will return ENOMEM. If the queue create mailbox command
  8814. * fails this function will return ENXIO.
  8815. **/
  8816. uint32_t
  8817. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  8818. struct lpfc_queue *cq, uint32_t subtype)
  8819. {
  8820. struct lpfc_mbx_wq_create *wq_create;
  8821. struct lpfc_dmabuf *dmabuf;
  8822. LPFC_MBOXQ_t *mbox;
  8823. int rc, length, status = 0;
  8824. uint32_t shdr_status, shdr_add_status;
  8825. union lpfc_sli4_cfg_shdr *shdr;
  8826. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8827. if (!mbox)
  8828. return -ENOMEM;
  8829. length = (sizeof(struct lpfc_mbx_wq_create) -
  8830. sizeof(struct lpfc_sli4_cfg_mhdr));
  8831. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8832. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  8833. length, LPFC_SLI4_MBX_EMBED);
  8834. wq_create = &mbox->u.mqe.un.wq_create;
  8835. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  8836. wq->page_count);
  8837. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  8838. cq->queue_id);
  8839. list_for_each_entry(dmabuf, &wq->page_list, list) {
  8840. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8841. putPaddrLow(dmabuf->phys);
  8842. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8843. putPaddrHigh(dmabuf->phys);
  8844. }
  8845. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8846. /* The IOCTL status is embedded in the mailbox subheader. */
  8847. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  8848. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8849. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8850. if (shdr_status || shdr_add_status || rc) {
  8851. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8852. "2503 WQ_CREATE mailbox failed with "
  8853. "status x%x add_status x%x, mbx status x%x\n",
  8854. shdr_status, shdr_add_status, rc);
  8855. status = -ENXIO;
  8856. goto out;
  8857. }
  8858. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  8859. if (wq->queue_id == 0xFFFF) {
  8860. status = -ENXIO;
  8861. goto out;
  8862. }
  8863. wq->type = LPFC_WQ;
  8864. wq->subtype = subtype;
  8865. wq->host_index = 0;
  8866. wq->hba_index = 0;
  8867. /* link the wq onto the parent cq child list */
  8868. list_add_tail(&wq->list, &cq->child_list);
  8869. out:
  8870. mempool_free(mbox, phba->mbox_mem_pool);
  8871. return status;
  8872. }
  8873. /**
  8874. * lpfc_rq_create - Create a Receive Queue on the HBA
  8875. * @phba: HBA structure that indicates port to create a queue on.
  8876. * @hrq: The queue structure to use to create the header receive queue.
  8877. * @drq: The queue structure to use to create the data receive queue.
  8878. * @cq: The completion queue to bind this work queue to.
  8879. *
  8880. * This function creates a receive buffer queue pair , as detailed in @hrq and
  8881. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  8882. * to the HBA.
  8883. *
  8884. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  8885. * struct is used to get the entry count that is necessary to determine the
  8886. * number of pages to use for this queue. The @cq is used to indicate which
  8887. * completion queue to bind received buffers that are posted to these queues to.
  8888. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  8889. * receive queue pair. This function is asynchronous and will wait for the
  8890. * mailbox command to finish before continuing.
  8891. *
  8892. * On success this function will return a zero. If unable to allocate enough
  8893. * memory this function will return ENOMEM. If the queue create mailbox command
  8894. * fails this function will return ENXIO.
  8895. **/
  8896. uint32_t
  8897. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  8898. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  8899. {
  8900. struct lpfc_mbx_rq_create *rq_create;
  8901. struct lpfc_dmabuf *dmabuf;
  8902. LPFC_MBOXQ_t *mbox;
  8903. int rc, length, status = 0;
  8904. uint32_t shdr_status, shdr_add_status;
  8905. union lpfc_sli4_cfg_shdr *shdr;
  8906. if (hrq->entry_count != drq->entry_count)
  8907. return -EINVAL;
  8908. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8909. if (!mbox)
  8910. return -ENOMEM;
  8911. length = (sizeof(struct lpfc_mbx_rq_create) -
  8912. sizeof(struct lpfc_sli4_cfg_mhdr));
  8913. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8914. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  8915. length, LPFC_SLI4_MBX_EMBED);
  8916. rq_create = &mbox->u.mqe.un.rq_create;
  8917. switch (hrq->entry_count) {
  8918. default:
  8919. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8920. "2535 Unsupported RQ count. (%d)\n",
  8921. hrq->entry_count);
  8922. if (hrq->entry_count < 512)
  8923. return -EINVAL;
  8924. /* otherwise default to smallest count (drop through) */
  8925. case 512:
  8926. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8927. LPFC_RQ_RING_SIZE_512);
  8928. break;
  8929. case 1024:
  8930. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8931. LPFC_RQ_RING_SIZE_1024);
  8932. break;
  8933. case 2048:
  8934. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8935. LPFC_RQ_RING_SIZE_2048);
  8936. break;
  8937. case 4096:
  8938. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8939. LPFC_RQ_RING_SIZE_4096);
  8940. break;
  8941. }
  8942. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  8943. cq->queue_id);
  8944. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  8945. hrq->page_count);
  8946. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  8947. LPFC_HDR_BUF_SIZE);
  8948. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  8949. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8950. putPaddrLow(dmabuf->phys);
  8951. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8952. putPaddrHigh(dmabuf->phys);
  8953. }
  8954. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8955. /* The IOCTL status is embedded in the mailbox subheader. */
  8956. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  8957. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8958. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8959. if (shdr_status || shdr_add_status || rc) {
  8960. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8961. "2504 RQ_CREATE mailbox failed with "
  8962. "status x%x add_status x%x, mbx status x%x\n",
  8963. shdr_status, shdr_add_status, rc);
  8964. status = -ENXIO;
  8965. goto out;
  8966. }
  8967. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  8968. if (hrq->queue_id == 0xFFFF) {
  8969. status = -ENXIO;
  8970. goto out;
  8971. }
  8972. hrq->type = LPFC_HRQ;
  8973. hrq->subtype = subtype;
  8974. hrq->host_index = 0;
  8975. hrq->hba_index = 0;
  8976. /* now create the data queue */
  8977. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8978. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  8979. length, LPFC_SLI4_MBX_EMBED);
  8980. switch (drq->entry_count) {
  8981. default:
  8982. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8983. "2536 Unsupported RQ count. (%d)\n",
  8984. drq->entry_count);
  8985. if (drq->entry_count < 512)
  8986. return -EINVAL;
  8987. /* otherwise default to smallest count (drop through) */
  8988. case 512:
  8989. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8990. LPFC_RQ_RING_SIZE_512);
  8991. break;
  8992. case 1024:
  8993. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8994. LPFC_RQ_RING_SIZE_1024);
  8995. break;
  8996. case 2048:
  8997. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8998. LPFC_RQ_RING_SIZE_2048);
  8999. break;
  9000. case 4096:
  9001. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9002. LPFC_RQ_RING_SIZE_4096);
  9003. break;
  9004. }
  9005. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9006. cq->queue_id);
  9007. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9008. drq->page_count);
  9009. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9010. LPFC_DATA_BUF_SIZE);
  9011. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9012. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9013. putPaddrLow(dmabuf->phys);
  9014. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9015. putPaddrHigh(dmabuf->phys);
  9016. }
  9017. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9018. /* The IOCTL status is embedded in the mailbox subheader. */
  9019. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9020. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9021. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9022. if (shdr_status || shdr_add_status || rc) {
  9023. status = -ENXIO;
  9024. goto out;
  9025. }
  9026. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9027. if (drq->queue_id == 0xFFFF) {
  9028. status = -ENXIO;
  9029. goto out;
  9030. }
  9031. drq->type = LPFC_DRQ;
  9032. drq->subtype = subtype;
  9033. drq->host_index = 0;
  9034. drq->hba_index = 0;
  9035. /* link the header and data RQs onto the parent cq child list */
  9036. list_add_tail(&hrq->list, &cq->child_list);
  9037. list_add_tail(&drq->list, &cq->child_list);
  9038. out:
  9039. mempool_free(mbox, phba->mbox_mem_pool);
  9040. return status;
  9041. }
  9042. /**
  9043. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9044. * @eq: The queue structure associated with the queue to destroy.
  9045. *
  9046. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9047. * command, specific to the type of queue, to the HBA.
  9048. *
  9049. * The @eq struct is used to get the queue ID of the queue to destroy.
  9050. *
  9051. * On success this function will return a zero. If the queue destroy mailbox
  9052. * command fails this function will return ENXIO.
  9053. **/
  9054. uint32_t
  9055. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9056. {
  9057. LPFC_MBOXQ_t *mbox;
  9058. int rc, length, status = 0;
  9059. uint32_t shdr_status, shdr_add_status;
  9060. union lpfc_sli4_cfg_shdr *shdr;
  9061. if (!eq)
  9062. return -ENODEV;
  9063. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9064. if (!mbox)
  9065. return -ENOMEM;
  9066. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9067. sizeof(struct lpfc_sli4_cfg_mhdr));
  9068. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9069. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9070. length, LPFC_SLI4_MBX_EMBED);
  9071. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9072. eq->queue_id);
  9073. mbox->vport = eq->phba->pport;
  9074. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9075. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9076. /* The IOCTL status is embedded in the mailbox subheader. */
  9077. shdr = (union lpfc_sli4_cfg_shdr *)
  9078. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9079. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9080. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9081. if (shdr_status || shdr_add_status || rc) {
  9082. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9083. "2505 EQ_DESTROY mailbox failed with "
  9084. "status x%x add_status x%x, mbx status x%x\n",
  9085. shdr_status, shdr_add_status, rc);
  9086. status = -ENXIO;
  9087. }
  9088. /* Remove eq from any list */
  9089. list_del_init(&eq->list);
  9090. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9091. return status;
  9092. }
  9093. /**
  9094. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9095. * @cq: The queue structure associated with the queue to destroy.
  9096. *
  9097. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9098. * command, specific to the type of queue, to the HBA.
  9099. *
  9100. * The @cq struct is used to get the queue ID of the queue to destroy.
  9101. *
  9102. * On success this function will return a zero. If the queue destroy mailbox
  9103. * command fails this function will return ENXIO.
  9104. **/
  9105. uint32_t
  9106. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9107. {
  9108. LPFC_MBOXQ_t *mbox;
  9109. int rc, length, status = 0;
  9110. uint32_t shdr_status, shdr_add_status;
  9111. union lpfc_sli4_cfg_shdr *shdr;
  9112. if (!cq)
  9113. return -ENODEV;
  9114. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9115. if (!mbox)
  9116. return -ENOMEM;
  9117. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9118. sizeof(struct lpfc_sli4_cfg_mhdr));
  9119. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9120. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9121. length, LPFC_SLI4_MBX_EMBED);
  9122. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9123. cq->queue_id);
  9124. mbox->vport = cq->phba->pport;
  9125. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9126. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9127. /* The IOCTL status is embedded in the mailbox subheader. */
  9128. shdr = (union lpfc_sli4_cfg_shdr *)
  9129. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9130. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9131. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9132. if (shdr_status || shdr_add_status || rc) {
  9133. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9134. "2506 CQ_DESTROY mailbox failed with "
  9135. "status x%x add_status x%x, mbx status x%x\n",
  9136. shdr_status, shdr_add_status, rc);
  9137. status = -ENXIO;
  9138. }
  9139. /* Remove cq from any list */
  9140. list_del_init(&cq->list);
  9141. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9142. return status;
  9143. }
  9144. /**
  9145. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9146. * @qm: The queue structure associated with the queue to destroy.
  9147. *
  9148. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9149. * command, specific to the type of queue, to the HBA.
  9150. *
  9151. * The @mq struct is used to get the queue ID of the queue to destroy.
  9152. *
  9153. * On success this function will return a zero. If the queue destroy mailbox
  9154. * command fails this function will return ENXIO.
  9155. **/
  9156. uint32_t
  9157. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9158. {
  9159. LPFC_MBOXQ_t *mbox;
  9160. int rc, length, status = 0;
  9161. uint32_t shdr_status, shdr_add_status;
  9162. union lpfc_sli4_cfg_shdr *shdr;
  9163. if (!mq)
  9164. return -ENODEV;
  9165. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9166. if (!mbox)
  9167. return -ENOMEM;
  9168. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9169. sizeof(struct lpfc_sli4_cfg_mhdr));
  9170. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9171. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9172. length, LPFC_SLI4_MBX_EMBED);
  9173. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9174. mq->queue_id);
  9175. mbox->vport = mq->phba->pport;
  9176. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9177. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9178. /* The IOCTL status is embedded in the mailbox subheader. */
  9179. shdr = (union lpfc_sli4_cfg_shdr *)
  9180. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9181. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9182. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9183. if (shdr_status || shdr_add_status || rc) {
  9184. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9185. "2507 MQ_DESTROY mailbox failed with "
  9186. "status x%x add_status x%x, mbx status x%x\n",
  9187. shdr_status, shdr_add_status, rc);
  9188. status = -ENXIO;
  9189. }
  9190. /* Remove mq from any list */
  9191. list_del_init(&mq->list);
  9192. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9193. return status;
  9194. }
  9195. /**
  9196. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9197. * @wq: The queue structure associated with the queue to destroy.
  9198. *
  9199. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9200. * command, specific to the type of queue, to the HBA.
  9201. *
  9202. * The @wq struct is used to get the queue ID of the queue to destroy.
  9203. *
  9204. * On success this function will return a zero. If the queue destroy mailbox
  9205. * command fails this function will return ENXIO.
  9206. **/
  9207. uint32_t
  9208. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9209. {
  9210. LPFC_MBOXQ_t *mbox;
  9211. int rc, length, status = 0;
  9212. uint32_t shdr_status, shdr_add_status;
  9213. union lpfc_sli4_cfg_shdr *shdr;
  9214. if (!wq)
  9215. return -ENODEV;
  9216. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9217. if (!mbox)
  9218. return -ENOMEM;
  9219. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9220. sizeof(struct lpfc_sli4_cfg_mhdr));
  9221. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9222. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9223. length, LPFC_SLI4_MBX_EMBED);
  9224. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9225. wq->queue_id);
  9226. mbox->vport = wq->phba->pport;
  9227. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9228. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9229. shdr = (union lpfc_sli4_cfg_shdr *)
  9230. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9231. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9232. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9233. if (shdr_status || shdr_add_status || rc) {
  9234. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9235. "2508 WQ_DESTROY mailbox failed with "
  9236. "status x%x add_status x%x, mbx status x%x\n",
  9237. shdr_status, shdr_add_status, rc);
  9238. status = -ENXIO;
  9239. }
  9240. /* Remove wq from any list */
  9241. list_del_init(&wq->list);
  9242. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9243. return status;
  9244. }
  9245. /**
  9246. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9247. * @rq: The queue structure associated with the queue to destroy.
  9248. *
  9249. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9250. * command, specific to the type of queue, to the HBA.
  9251. *
  9252. * The @rq struct is used to get the queue ID of the queue to destroy.
  9253. *
  9254. * On success this function will return a zero. If the queue destroy mailbox
  9255. * command fails this function will return ENXIO.
  9256. **/
  9257. uint32_t
  9258. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9259. struct lpfc_queue *drq)
  9260. {
  9261. LPFC_MBOXQ_t *mbox;
  9262. int rc, length, status = 0;
  9263. uint32_t shdr_status, shdr_add_status;
  9264. union lpfc_sli4_cfg_shdr *shdr;
  9265. if (!hrq || !drq)
  9266. return -ENODEV;
  9267. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9268. if (!mbox)
  9269. return -ENOMEM;
  9270. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9271. sizeof(struct mbox_header));
  9272. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9273. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9274. length, LPFC_SLI4_MBX_EMBED);
  9275. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9276. hrq->queue_id);
  9277. mbox->vport = hrq->phba->pport;
  9278. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9279. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9280. /* The IOCTL status is embedded in the mailbox subheader. */
  9281. shdr = (union lpfc_sli4_cfg_shdr *)
  9282. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9283. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9284. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9285. if (shdr_status || shdr_add_status || rc) {
  9286. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9287. "2509 RQ_DESTROY mailbox failed with "
  9288. "status x%x add_status x%x, mbx status x%x\n",
  9289. shdr_status, shdr_add_status, rc);
  9290. if (rc != MBX_TIMEOUT)
  9291. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9292. return -ENXIO;
  9293. }
  9294. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9295. drq->queue_id);
  9296. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9297. shdr = (union lpfc_sli4_cfg_shdr *)
  9298. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9299. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9300. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9301. if (shdr_status || shdr_add_status || rc) {
  9302. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9303. "2510 RQ_DESTROY mailbox failed with "
  9304. "status x%x add_status x%x, mbx status x%x\n",
  9305. shdr_status, shdr_add_status, rc);
  9306. status = -ENXIO;
  9307. }
  9308. list_del_init(&hrq->list);
  9309. list_del_init(&drq->list);
  9310. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9311. return status;
  9312. }
  9313. /**
  9314. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9315. * @phba: The virtual port for which this call being executed.
  9316. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9317. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9318. * @xritag: the xritag that ties this io to the SGL pages.
  9319. *
  9320. * This routine will post the sgl pages for the IO that has the xritag
  9321. * that is in the iocbq structure. The xritag is assigned during iocbq
  9322. * creation and persists for as long as the driver is loaded.
  9323. * if the caller has fewer than 256 scatter gather segments to map then
  9324. * pdma_phys_addr1 should be 0.
  9325. * If the caller needs to map more than 256 scatter gather segment then
  9326. * pdma_phys_addr1 should be a valid physical address.
  9327. * physical address for SGLs must be 64 byte aligned.
  9328. * If you are going to map 2 SGL's then the first one must have 256 entries
  9329. * the second sgl can have between 1 and 256 entries.
  9330. *
  9331. * Return codes:
  9332. * 0 - Success
  9333. * -ENXIO, -ENOMEM - Failure
  9334. **/
  9335. int
  9336. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9337. dma_addr_t pdma_phys_addr0,
  9338. dma_addr_t pdma_phys_addr1,
  9339. uint16_t xritag)
  9340. {
  9341. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9342. LPFC_MBOXQ_t *mbox;
  9343. int rc;
  9344. uint32_t shdr_status, shdr_add_status;
  9345. union lpfc_sli4_cfg_shdr *shdr;
  9346. if (xritag == NO_XRI) {
  9347. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9348. "0364 Invalid param:\n");
  9349. return -EINVAL;
  9350. }
  9351. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9352. if (!mbox)
  9353. return -ENOMEM;
  9354. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9355. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9356. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9357. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9358. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9359. &mbox->u.mqe.un.post_sgl_pages;
  9360. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9361. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9362. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9363. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9364. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9365. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9366. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9367. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9368. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9369. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9370. if (!phba->sli4_hba.intr_enable)
  9371. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9372. else
  9373. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9374. /* The IOCTL status is embedded in the mailbox subheader. */
  9375. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9376. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9377. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9378. if (rc != MBX_TIMEOUT)
  9379. mempool_free(mbox, phba->mbox_mem_pool);
  9380. if (shdr_status || shdr_add_status || rc) {
  9381. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9382. "2511 POST_SGL mailbox failed with "
  9383. "status x%x add_status x%x, mbx status x%x\n",
  9384. shdr_status, shdr_add_status, rc);
  9385. rc = -ENXIO;
  9386. }
  9387. return 0;
  9388. }
  9389. /**
  9390. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9391. * @phba: The virtual port for which this call being executed.
  9392. *
  9393. * This routine will remove all of the sgl pages registered with the hba.
  9394. *
  9395. * Return codes:
  9396. * 0 - Success
  9397. * -ENXIO, -ENOMEM - Failure
  9398. **/
  9399. int
  9400. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9401. {
  9402. LPFC_MBOXQ_t *mbox;
  9403. int rc;
  9404. uint32_t shdr_status, shdr_add_status;
  9405. union lpfc_sli4_cfg_shdr *shdr;
  9406. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9407. if (!mbox)
  9408. return -ENOMEM;
  9409. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9410. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9411. LPFC_SLI4_MBX_EMBED);
  9412. if (!phba->sli4_hba.intr_enable)
  9413. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9414. else
  9415. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9416. /* The IOCTL status is embedded in the mailbox subheader. */
  9417. shdr = (union lpfc_sli4_cfg_shdr *)
  9418. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9419. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9420. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9421. if (rc != MBX_TIMEOUT)
  9422. mempool_free(mbox, phba->mbox_mem_pool);
  9423. if (shdr_status || shdr_add_status || rc) {
  9424. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9425. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9426. "status x%x add_status x%x, mbx status x%x\n",
  9427. shdr_status, shdr_add_status, rc);
  9428. rc = -ENXIO;
  9429. }
  9430. return rc;
  9431. }
  9432. /**
  9433. * lpfc_sli4_next_xritag - Get an xritag for the io
  9434. * @phba: Pointer to HBA context object.
  9435. *
  9436. * This function gets an xritag for the iocb. If there is no unused xritag
  9437. * it will return 0xffff.
  9438. * The function returns the allocated xritag if successful, else returns zero.
  9439. * Zero is not a valid xritag.
  9440. * The caller is not required to hold any lock.
  9441. **/
  9442. uint16_t
  9443. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9444. {
  9445. uint16_t xritag;
  9446. spin_lock_irq(&phba->hbalock);
  9447. xritag = phba->sli4_hba.next_xri;
  9448. if ((xritag != (uint16_t) -1) && xritag <
  9449. (phba->sli4_hba.max_cfg_param.max_xri
  9450. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9451. phba->sli4_hba.next_xri++;
  9452. phba->sli4_hba.max_cfg_param.xri_used++;
  9453. spin_unlock_irq(&phba->hbalock);
  9454. return xritag;
  9455. }
  9456. spin_unlock_irq(&phba->hbalock);
  9457. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9458. "2004 Failed to allocate XRI.last XRITAG is %d"
  9459. " Max XRI is %d, Used XRI is %d\n",
  9460. phba->sli4_hba.next_xri,
  9461. phba->sli4_hba.max_cfg_param.max_xri,
  9462. phba->sli4_hba.max_cfg_param.xri_used);
  9463. return -1;
  9464. }
  9465. /**
  9466. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9467. * @phba: pointer to lpfc hba data structure.
  9468. *
  9469. * This routine is invoked to post a block of driver's sgl pages to the
  9470. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9471. * is only called when the driver is loading and after all IO has been
  9472. * stopped.
  9473. **/
  9474. int
  9475. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9476. {
  9477. struct lpfc_sglq *sglq_entry;
  9478. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9479. struct sgl_page_pairs *sgl_pg_pairs;
  9480. void *viraddr;
  9481. LPFC_MBOXQ_t *mbox;
  9482. uint32_t reqlen, alloclen, pg_pairs;
  9483. uint32_t mbox_tmo;
  9484. uint16_t xritag_start = 0;
  9485. int els_xri_cnt, rc = 0;
  9486. uint32_t shdr_status, shdr_add_status;
  9487. union lpfc_sli4_cfg_shdr *shdr;
  9488. /* The number of sgls to be posted */
  9489. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9490. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9491. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9492. if (reqlen > PAGE_SIZE) {
  9493. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9494. "2559 Block sgl registration required DMA "
  9495. "size (%d) great than a page\n", reqlen);
  9496. return -ENOMEM;
  9497. }
  9498. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9499. if (!mbox) {
  9500. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9501. "2560 Failed to allocate mbox cmd memory\n");
  9502. return -ENOMEM;
  9503. }
  9504. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9505. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9506. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9507. LPFC_SLI4_MBX_NEMBED);
  9508. if (alloclen < reqlen) {
  9509. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9510. "0285 Allocated DMA memory size (%d) is "
  9511. "less than the requested DMA memory "
  9512. "size (%d)\n", alloclen, reqlen);
  9513. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9514. return -ENOMEM;
  9515. }
  9516. /* Get the first SGE entry from the non-embedded DMA memory */
  9517. viraddr = mbox->sge_array->addr[0];
  9518. /* Set up the SGL pages in the non-embedded DMA pages */
  9519. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9520. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9521. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9522. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9523. /* Set up the sge entry */
  9524. sgl_pg_pairs->sgl_pg0_addr_lo =
  9525. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9526. sgl_pg_pairs->sgl_pg0_addr_hi =
  9527. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9528. sgl_pg_pairs->sgl_pg1_addr_lo =
  9529. cpu_to_le32(putPaddrLow(0));
  9530. sgl_pg_pairs->sgl_pg1_addr_hi =
  9531. cpu_to_le32(putPaddrHigh(0));
  9532. /* Keep the first xritag on the list */
  9533. if (pg_pairs == 0)
  9534. xritag_start = sglq_entry->sli4_xritag;
  9535. sgl_pg_pairs++;
  9536. }
  9537. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9538. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9539. /* Perform endian conversion if necessary */
  9540. sgl->word0 = cpu_to_le32(sgl->word0);
  9541. if (!phba->sli4_hba.intr_enable)
  9542. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9543. else {
  9544. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9545. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9546. }
  9547. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9548. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9549. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9550. if (rc != MBX_TIMEOUT)
  9551. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9552. if (shdr_status || shdr_add_status || rc) {
  9553. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9554. "2513 POST_SGL_BLOCK mailbox command failed "
  9555. "status x%x add_status x%x mbx status x%x\n",
  9556. shdr_status, shdr_add_status, rc);
  9557. rc = -ENXIO;
  9558. }
  9559. return rc;
  9560. }
  9561. /**
  9562. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9563. * @phba: pointer to lpfc hba data structure.
  9564. * @sblist: pointer to scsi buffer list.
  9565. * @count: number of scsi buffers on the list.
  9566. *
  9567. * This routine is invoked to post a block of @count scsi sgl pages from a
  9568. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9569. * No Lock is held.
  9570. *
  9571. **/
  9572. int
  9573. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9574. int cnt)
  9575. {
  9576. struct lpfc_scsi_buf *psb;
  9577. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9578. struct sgl_page_pairs *sgl_pg_pairs;
  9579. void *viraddr;
  9580. LPFC_MBOXQ_t *mbox;
  9581. uint32_t reqlen, alloclen, pg_pairs;
  9582. uint32_t mbox_tmo;
  9583. uint16_t xritag_start = 0;
  9584. int rc = 0;
  9585. uint32_t shdr_status, shdr_add_status;
  9586. dma_addr_t pdma_phys_bpl1;
  9587. union lpfc_sli4_cfg_shdr *shdr;
  9588. /* Calculate the requested length of the dma memory */
  9589. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9590. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9591. if (reqlen > PAGE_SIZE) {
  9592. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9593. "0217 Block sgl registration required DMA "
  9594. "size (%d) great than a page\n", reqlen);
  9595. return -ENOMEM;
  9596. }
  9597. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9598. if (!mbox) {
  9599. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9600. "0283 Failed to allocate mbox cmd memory\n");
  9601. return -ENOMEM;
  9602. }
  9603. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9604. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9605. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9606. LPFC_SLI4_MBX_NEMBED);
  9607. if (alloclen < reqlen) {
  9608. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9609. "2561 Allocated DMA memory size (%d) is "
  9610. "less than the requested DMA memory "
  9611. "size (%d)\n", alloclen, reqlen);
  9612. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9613. return -ENOMEM;
  9614. }
  9615. /* Get the first SGE entry from the non-embedded DMA memory */
  9616. viraddr = mbox->sge_array->addr[0];
  9617. /* Set up the SGL pages in the non-embedded DMA pages */
  9618. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9619. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9620. pg_pairs = 0;
  9621. list_for_each_entry(psb, sblist, list) {
  9622. /* Set up the sge entry */
  9623. sgl_pg_pairs->sgl_pg0_addr_lo =
  9624. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9625. sgl_pg_pairs->sgl_pg0_addr_hi =
  9626. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9627. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9628. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9629. else
  9630. pdma_phys_bpl1 = 0;
  9631. sgl_pg_pairs->sgl_pg1_addr_lo =
  9632. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9633. sgl_pg_pairs->sgl_pg1_addr_hi =
  9634. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9635. /* Keep the first xritag on the list */
  9636. if (pg_pairs == 0)
  9637. xritag_start = psb->cur_iocbq.sli4_xritag;
  9638. sgl_pg_pairs++;
  9639. pg_pairs++;
  9640. }
  9641. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9642. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9643. /* Perform endian conversion if necessary */
  9644. sgl->word0 = cpu_to_le32(sgl->word0);
  9645. if (!phba->sli4_hba.intr_enable)
  9646. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9647. else {
  9648. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9649. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9650. }
  9651. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9652. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9653. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9654. if (rc != MBX_TIMEOUT)
  9655. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9656. if (shdr_status || shdr_add_status || rc) {
  9657. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9658. "2564 POST_SGL_BLOCK mailbox command failed "
  9659. "status x%x add_status x%x mbx status x%x\n",
  9660. shdr_status, shdr_add_status, rc);
  9661. rc = -ENXIO;
  9662. }
  9663. return rc;
  9664. }
  9665. /**
  9666. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9667. * @phba: pointer to lpfc_hba struct that the frame was received on
  9668. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9669. *
  9670. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9671. * valid type of frame that the LPFC driver will handle. This function will
  9672. * return a zero if the frame is a valid frame or a non zero value when the
  9673. * frame does not pass the check.
  9674. **/
  9675. static int
  9676. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9677. {
  9678. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9679. char *type_names[] = FC_TYPE_NAMES_INIT;
  9680. struct fc_vft_header *fc_vft_hdr;
  9681. switch (fc_hdr->fh_r_ctl) {
  9682. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9683. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9684. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9685. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9686. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9687. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9688. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9689. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9690. case FC_RCTL_ELS_REQ: /* extended link services request */
  9691. case FC_RCTL_ELS_REP: /* extended link services reply */
  9692. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9693. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9694. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9695. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9696. case FC_RCTL_BA_RMC: /* remove connection */
  9697. case FC_RCTL_BA_ACC: /* basic accept */
  9698. case FC_RCTL_BA_RJT: /* basic reject */
  9699. case FC_RCTL_BA_PRMT:
  9700. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9701. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9702. case FC_RCTL_P_RJT: /* port reject */
  9703. case FC_RCTL_F_RJT: /* fabric reject */
  9704. case FC_RCTL_P_BSY: /* port busy */
  9705. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9706. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9707. case FC_RCTL_LCR: /* link credit reset */
  9708. case FC_RCTL_END: /* end */
  9709. break;
  9710. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9711. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9712. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9713. return lpfc_fc_frame_check(phba, fc_hdr);
  9714. default:
  9715. goto drop;
  9716. }
  9717. switch (fc_hdr->fh_type) {
  9718. case FC_TYPE_BLS:
  9719. case FC_TYPE_ELS:
  9720. case FC_TYPE_FCP:
  9721. case FC_TYPE_CT:
  9722. break;
  9723. case FC_TYPE_IP:
  9724. case FC_TYPE_ILS:
  9725. default:
  9726. goto drop;
  9727. }
  9728. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9729. "2538 Received frame rctl:%s type:%s\n",
  9730. rctl_names[fc_hdr->fh_r_ctl],
  9731. type_names[fc_hdr->fh_type]);
  9732. return 0;
  9733. drop:
  9734. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9735. "2539 Dropped frame rctl:%s type:%s\n",
  9736. rctl_names[fc_hdr->fh_r_ctl],
  9737. type_names[fc_hdr->fh_type]);
  9738. return 1;
  9739. }
  9740. /**
  9741. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9742. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9743. *
  9744. * This function processes the FC header to retrieve the VFI from the VF
  9745. * header, if one exists. This function will return the VFI if one exists
  9746. * or 0 if no VSAN Header exists.
  9747. **/
  9748. static uint32_t
  9749. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9750. {
  9751. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9752. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9753. return 0;
  9754. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9755. }
  9756. /**
  9757. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9758. * @phba: Pointer to the HBA structure to search for the vport on
  9759. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9760. * @fcfi: The FC Fabric ID that the frame came from
  9761. *
  9762. * This function searches the @phba for a vport that matches the content of the
  9763. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9764. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9765. * returns the matching vport pointer or NULL if unable to match frame to a
  9766. * vport.
  9767. **/
  9768. static struct lpfc_vport *
  9769. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9770. uint16_t fcfi)
  9771. {
  9772. struct lpfc_vport **vports;
  9773. struct lpfc_vport *vport = NULL;
  9774. int i;
  9775. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9776. fc_hdr->fh_d_id[1] << 8 |
  9777. fc_hdr->fh_d_id[2]);
  9778. vports = lpfc_create_vport_work_array(phba);
  9779. if (vports != NULL)
  9780. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9781. if (phba->fcf.fcfi == fcfi &&
  9782. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9783. vports[i]->fc_myDID == did) {
  9784. vport = vports[i];
  9785. break;
  9786. }
  9787. }
  9788. lpfc_destroy_vport_work_array(phba, vports);
  9789. return vport;
  9790. }
  9791. /**
  9792. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  9793. * @vport: The vport to work on.
  9794. *
  9795. * This function updates the receive sequence time stamp for this vport. The
  9796. * receive sequence time stamp indicates the time that the last frame of the
  9797. * the sequence that has been idle for the longest amount of time was received.
  9798. * the driver uses this time stamp to indicate if any received sequences have
  9799. * timed out.
  9800. **/
  9801. void
  9802. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  9803. {
  9804. struct lpfc_dmabuf *h_buf;
  9805. struct hbq_dmabuf *dmabuf = NULL;
  9806. /* get the oldest sequence on the rcv list */
  9807. h_buf = list_get_first(&vport->rcv_buffer_list,
  9808. struct lpfc_dmabuf, list);
  9809. if (!h_buf)
  9810. return;
  9811. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9812. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  9813. }
  9814. /**
  9815. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  9816. * @vport: The vport that the received sequences were sent to.
  9817. *
  9818. * This function cleans up all outstanding received sequences. This is called
  9819. * by the driver when a link event or user action invalidates all the received
  9820. * sequences.
  9821. **/
  9822. void
  9823. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  9824. {
  9825. struct lpfc_dmabuf *h_buf, *hnext;
  9826. struct lpfc_dmabuf *d_buf, *dnext;
  9827. struct hbq_dmabuf *dmabuf = NULL;
  9828. /* start with the oldest sequence on the rcv list */
  9829. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  9830. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9831. list_del_init(&dmabuf->hbuf.list);
  9832. list_for_each_entry_safe(d_buf, dnext,
  9833. &dmabuf->dbuf.list, list) {
  9834. list_del_init(&d_buf->list);
  9835. lpfc_in_buf_free(vport->phba, d_buf);
  9836. }
  9837. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  9838. }
  9839. }
  9840. /**
  9841. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  9842. * @vport: The vport that the received sequences were sent to.
  9843. *
  9844. * This function determines whether any received sequences have timed out by
  9845. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  9846. * indicates that there is at least one timed out sequence this routine will
  9847. * go through the received sequences one at a time from most inactive to most
  9848. * active to determine which ones need to be cleaned up. Once it has determined
  9849. * that a sequence needs to be cleaned up it will simply free up the resources
  9850. * without sending an abort.
  9851. **/
  9852. void
  9853. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  9854. {
  9855. struct lpfc_dmabuf *h_buf, *hnext;
  9856. struct lpfc_dmabuf *d_buf, *dnext;
  9857. struct hbq_dmabuf *dmabuf = NULL;
  9858. unsigned long timeout;
  9859. int abort_count = 0;
  9860. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  9861. vport->rcv_buffer_time_stamp);
  9862. if (list_empty(&vport->rcv_buffer_list) ||
  9863. time_before(jiffies, timeout))
  9864. return;
  9865. /* start with the oldest sequence on the rcv list */
  9866. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  9867. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9868. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  9869. dmabuf->time_stamp);
  9870. if (time_before(jiffies, timeout))
  9871. break;
  9872. abort_count++;
  9873. list_del_init(&dmabuf->hbuf.list);
  9874. list_for_each_entry_safe(d_buf, dnext,
  9875. &dmabuf->dbuf.list, list) {
  9876. list_del_init(&d_buf->list);
  9877. lpfc_in_buf_free(vport->phba, d_buf);
  9878. }
  9879. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  9880. }
  9881. if (abort_count)
  9882. lpfc_update_rcv_time_stamp(vport);
  9883. }
  9884. /**
  9885. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  9886. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  9887. *
  9888. * This function searches through the existing incomplete sequences that have
  9889. * been sent to this @vport. If the frame matches one of the incomplete
  9890. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  9891. * make up that sequence. If no sequence is found that matches this frame then
  9892. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  9893. * This function returns a pointer to the first dmabuf in the sequence list that
  9894. * the frame was linked to.
  9895. **/
  9896. static struct hbq_dmabuf *
  9897. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  9898. {
  9899. struct fc_frame_header *new_hdr;
  9900. struct fc_frame_header *temp_hdr;
  9901. struct lpfc_dmabuf *d_buf;
  9902. struct lpfc_dmabuf *h_buf;
  9903. struct hbq_dmabuf *seq_dmabuf = NULL;
  9904. struct hbq_dmabuf *temp_dmabuf = NULL;
  9905. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  9906. dmabuf->time_stamp = jiffies;
  9907. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9908. /* Use the hdr_buf to find the sequence that this frame belongs to */
  9909. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  9910. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  9911. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  9912. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  9913. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  9914. continue;
  9915. /* found a pending sequence that matches this frame */
  9916. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9917. break;
  9918. }
  9919. if (!seq_dmabuf) {
  9920. /*
  9921. * This indicates first frame received for this sequence.
  9922. * Queue the buffer on the vport's rcv_buffer_list.
  9923. */
  9924. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9925. lpfc_update_rcv_time_stamp(vport);
  9926. return dmabuf;
  9927. }
  9928. temp_hdr = seq_dmabuf->hbuf.virt;
  9929. if (new_hdr->fh_seq_cnt < temp_hdr->fh_seq_cnt) {
  9930. list_del_init(&seq_dmabuf->hbuf.list);
  9931. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9932. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  9933. lpfc_update_rcv_time_stamp(vport);
  9934. return dmabuf;
  9935. }
  9936. /* move this sequence to the tail to indicate a young sequence */
  9937. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9938. seq_dmabuf->time_stamp = jiffies;
  9939. lpfc_update_rcv_time_stamp(vport);
  9940. /* find the correct place in the sequence to insert this frame */
  9941. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  9942. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  9943. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  9944. /*
  9945. * If the frame's sequence count is greater than the frame on
  9946. * the list then insert the frame right after this frame
  9947. */
  9948. if (new_hdr->fh_seq_cnt > temp_hdr->fh_seq_cnt) {
  9949. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  9950. return seq_dmabuf;
  9951. }
  9952. }
  9953. return NULL;
  9954. }
  9955. /**
  9956. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  9957. * @vport: pointer to a vitural port
  9958. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  9959. *
  9960. * This function tries to abort from the partially assembed sequence, described
  9961. * by the information from basic abbort @dmabuf. It checks to see whether such
  9962. * partially assembled sequence held by the driver. If so, it shall free up all
  9963. * the frames from the partially assembled sequence.
  9964. *
  9965. * Return
  9966. * true -- if there is matching partially assembled sequence present and all
  9967. * the frames freed with the sequence;
  9968. * false -- if there is no matching partially assembled sequence present so
  9969. * nothing got aborted in the lower layer driver
  9970. **/
  9971. static bool
  9972. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  9973. struct hbq_dmabuf *dmabuf)
  9974. {
  9975. struct fc_frame_header *new_hdr;
  9976. struct fc_frame_header *temp_hdr;
  9977. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  9978. struct hbq_dmabuf *seq_dmabuf = NULL;
  9979. /* Use the hdr_buf to find the sequence that matches this frame */
  9980. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  9981. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  9982. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9983. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  9984. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  9985. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  9986. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  9987. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  9988. continue;
  9989. /* found a pending sequence that matches this frame */
  9990. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9991. break;
  9992. }
  9993. /* Free up all the frames from the partially assembled sequence */
  9994. if (seq_dmabuf) {
  9995. list_for_each_entry_safe(d_buf, n_buf,
  9996. &seq_dmabuf->dbuf.list, list) {
  9997. list_del_init(&d_buf->list);
  9998. lpfc_in_buf_free(vport->phba, d_buf);
  9999. }
  10000. return true;
  10001. }
  10002. return false;
  10003. }
  10004. /**
  10005. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10006. * @phba: Pointer to HBA context object.
  10007. * @cmd_iocbq: pointer to the command iocbq structure.
  10008. * @rsp_iocbq: pointer to the response iocbq structure.
  10009. *
  10010. * This function handles the sequence abort accept iocb command complete
  10011. * event. It properly releases the memory allocated to the sequence abort
  10012. * accept iocb.
  10013. **/
  10014. static void
  10015. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10016. struct lpfc_iocbq *cmd_iocbq,
  10017. struct lpfc_iocbq *rsp_iocbq)
  10018. {
  10019. if (cmd_iocbq)
  10020. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10021. }
  10022. /**
  10023. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10024. * @phba: Pointer to HBA context object.
  10025. * @fc_hdr: pointer to a FC frame header.
  10026. *
  10027. * This function sends a basic accept to a previous unsol sequence abort
  10028. * event after aborting the sequence handling.
  10029. **/
  10030. static void
  10031. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10032. struct fc_frame_header *fc_hdr)
  10033. {
  10034. struct lpfc_iocbq *ctiocb = NULL;
  10035. struct lpfc_nodelist *ndlp;
  10036. uint16_t oxid;
  10037. uint32_t sid;
  10038. IOCB_t *icmd;
  10039. if (!lpfc_is_link_up(phba))
  10040. return;
  10041. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10042. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10043. ndlp = lpfc_findnode_did(phba->pport, sid);
  10044. if (!ndlp) {
  10045. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10046. "1268 Find ndlp returned NULL for oxid:x%x "
  10047. "SID:x%x\n", oxid, sid);
  10048. return;
  10049. }
  10050. /* Allocate buffer for acc iocb */
  10051. ctiocb = lpfc_sli_get_iocbq(phba);
  10052. if (!ctiocb)
  10053. return;
  10054. icmd = &ctiocb->iocb;
  10055. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10056. icmd->un.xseq64.bdl.bdeSize = 0;
  10057. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10058. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10059. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10060. /* Fill in the rest of iocb fields */
  10061. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10062. icmd->ulpBdeCount = 0;
  10063. icmd->ulpLe = 1;
  10064. icmd->ulpClass = CLASS3;
  10065. icmd->ulpContext = ndlp->nlp_rpi;
  10066. icmd->un.ulpWord[3] = oxid;
  10067. ctiocb->sli4_xritag = NO_XRI;
  10068. ctiocb->iocb_cmpl = NULL;
  10069. ctiocb->vport = phba->pport;
  10070. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10071. /* Xmit CT abts accept on exchange <xid> */
  10072. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10073. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10074. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10075. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10076. }
  10077. /**
  10078. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10079. * @vport: Pointer to the vport on which this sequence was received
  10080. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10081. *
  10082. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10083. * receive sequence is only partially assembed by the driver, it shall abort
  10084. * the partially assembled frames for the sequence. Otherwise, if the
  10085. * unsolicited receive sequence has been completely assembled and passed to
  10086. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10087. * unsolicited sequence has been aborted. After that, it will issue a basic
  10088. * accept to accept the abort.
  10089. **/
  10090. void
  10091. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10092. struct hbq_dmabuf *dmabuf)
  10093. {
  10094. struct lpfc_hba *phba = vport->phba;
  10095. struct fc_frame_header fc_hdr;
  10096. bool abts_par;
  10097. /* Try to abort partially assembled seq */
  10098. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10099. /* Make a copy of fc_hdr before the dmabuf being released */
  10100. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10101. /* Send abort to ULP if partially seq abort failed */
  10102. if (abts_par == false)
  10103. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10104. else
  10105. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10106. /* Send basic accept (BA_ACC) to the abort requester */
  10107. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10108. }
  10109. /**
  10110. * lpfc_seq_complete - Indicates if a sequence is complete
  10111. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10112. *
  10113. * This function checks the sequence, starting with the frame described by
  10114. * @dmabuf, to see if all the frames associated with this sequence are present.
  10115. * the frames associated with this sequence are linked to the @dmabuf using the
  10116. * dbuf list. This function looks for two major things. 1) That the first frame
  10117. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10118. * set. 3) That there are no holes in the sequence count. The function will
  10119. * return 1 when the sequence is complete, otherwise it will return 0.
  10120. **/
  10121. static int
  10122. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10123. {
  10124. struct fc_frame_header *hdr;
  10125. struct lpfc_dmabuf *d_buf;
  10126. struct hbq_dmabuf *seq_dmabuf;
  10127. uint32_t fctl;
  10128. int seq_count = 0;
  10129. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10130. /* make sure first fame of sequence has a sequence count of zero */
  10131. if (hdr->fh_seq_cnt != seq_count)
  10132. return 0;
  10133. fctl = (hdr->fh_f_ctl[0] << 16 |
  10134. hdr->fh_f_ctl[1] << 8 |
  10135. hdr->fh_f_ctl[2]);
  10136. /* If last frame of sequence we can return success. */
  10137. if (fctl & FC_FC_END_SEQ)
  10138. return 1;
  10139. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10140. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10141. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10142. /* If there is a hole in the sequence count then fail. */
  10143. if (++seq_count != hdr->fh_seq_cnt)
  10144. return 0;
  10145. fctl = (hdr->fh_f_ctl[0] << 16 |
  10146. hdr->fh_f_ctl[1] << 8 |
  10147. hdr->fh_f_ctl[2]);
  10148. /* If last frame of sequence we can return success. */
  10149. if (fctl & FC_FC_END_SEQ)
  10150. return 1;
  10151. }
  10152. return 0;
  10153. }
  10154. /**
  10155. * lpfc_prep_seq - Prep sequence for ULP processing
  10156. * @vport: Pointer to the vport on which this sequence was received
  10157. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10158. *
  10159. * This function takes a sequence, described by a list of frames, and creates
  10160. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10161. * used to issue to the generic unsolicited sequence handler. This routine
  10162. * returns a pointer to the first iocbq in the list. If the function is unable
  10163. * to allocate an iocbq then it throw out the received frames that were not
  10164. * able to be described and return a pointer to the first iocbq. If unable to
  10165. * allocate any iocbqs (including the first) this function will return NULL.
  10166. **/
  10167. static struct lpfc_iocbq *
  10168. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10169. {
  10170. struct lpfc_dmabuf *d_buf, *n_buf;
  10171. struct lpfc_iocbq *first_iocbq, *iocbq;
  10172. struct fc_frame_header *fc_hdr;
  10173. uint32_t sid;
  10174. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10175. /* remove from receive buffer list */
  10176. list_del_init(&seq_dmabuf->hbuf.list);
  10177. lpfc_update_rcv_time_stamp(vport);
  10178. /* get the Remote Port's SID */
  10179. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10180. /* Get an iocbq struct to fill in. */
  10181. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10182. if (first_iocbq) {
  10183. /* Initialize the first IOCB. */
  10184. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10185. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10186. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10187. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10188. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10189. vport->vpi + vport->phba->vpi_base;
  10190. /* put the first buffer into the first IOCBq */
  10191. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10192. first_iocbq->context3 = NULL;
  10193. first_iocbq->iocb.ulpBdeCount = 1;
  10194. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10195. LPFC_DATA_BUF_SIZE;
  10196. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10197. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10198. bf_get(lpfc_rcqe_length,
  10199. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10200. }
  10201. iocbq = first_iocbq;
  10202. /*
  10203. * Each IOCBq can have two Buffers assigned, so go through the list
  10204. * of buffers for this sequence and save two buffers in each IOCBq
  10205. */
  10206. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10207. if (!iocbq) {
  10208. lpfc_in_buf_free(vport->phba, d_buf);
  10209. continue;
  10210. }
  10211. if (!iocbq->context3) {
  10212. iocbq->context3 = d_buf;
  10213. iocbq->iocb.ulpBdeCount++;
  10214. iocbq->iocb.unsli3.rcvsli3.bde2.tus.f.bdeSize =
  10215. LPFC_DATA_BUF_SIZE;
  10216. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10217. bf_get(lpfc_rcqe_length,
  10218. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10219. } else {
  10220. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10221. if (!iocbq) {
  10222. if (first_iocbq) {
  10223. first_iocbq->iocb.ulpStatus =
  10224. IOSTAT_FCP_RSP_ERROR;
  10225. first_iocbq->iocb.un.ulpWord[4] =
  10226. IOERR_NO_RESOURCES;
  10227. }
  10228. lpfc_in_buf_free(vport->phba, d_buf);
  10229. continue;
  10230. }
  10231. iocbq->context2 = d_buf;
  10232. iocbq->context3 = NULL;
  10233. iocbq->iocb.ulpBdeCount = 1;
  10234. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10235. LPFC_DATA_BUF_SIZE;
  10236. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10237. bf_get(lpfc_rcqe_length,
  10238. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10239. iocbq->iocb.un.rcvels.remoteID = sid;
  10240. list_add_tail(&iocbq->list, &first_iocbq->list);
  10241. }
  10242. }
  10243. return first_iocbq;
  10244. }
  10245. static void
  10246. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10247. struct hbq_dmabuf *seq_dmabuf)
  10248. {
  10249. struct fc_frame_header *fc_hdr;
  10250. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10251. struct lpfc_hba *phba = vport->phba;
  10252. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10253. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10254. if (!iocbq) {
  10255. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10256. "2707 Ring %d handler: Failed to allocate "
  10257. "iocb Rctl x%x Type x%x received\n",
  10258. LPFC_ELS_RING,
  10259. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10260. return;
  10261. }
  10262. if (!lpfc_complete_unsol_iocb(phba,
  10263. &phba->sli.ring[LPFC_ELS_RING],
  10264. iocbq, fc_hdr->fh_r_ctl,
  10265. fc_hdr->fh_type))
  10266. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10267. "2540 Ring %d handler: unexpected Rctl "
  10268. "x%x Type x%x received\n",
  10269. LPFC_ELS_RING,
  10270. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10271. /* Free iocb created in lpfc_prep_seq */
  10272. list_for_each_entry_safe(curr_iocb, next_iocb,
  10273. &iocbq->list, list) {
  10274. list_del_init(&curr_iocb->list);
  10275. lpfc_sli_release_iocbq(phba, curr_iocb);
  10276. }
  10277. lpfc_sli_release_iocbq(phba, iocbq);
  10278. }
  10279. /**
  10280. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10281. * @phba: Pointer to HBA context object.
  10282. *
  10283. * This function is called with no lock held. This function processes all
  10284. * the received buffers and gives it to upper layers when a received buffer
  10285. * indicates that it is the final frame in the sequence. The interrupt
  10286. * service routine processes received buffers at interrupt contexts and adds
  10287. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10288. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10289. * appropriate receive function when the final frame in a sequence is received.
  10290. **/
  10291. void
  10292. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10293. struct hbq_dmabuf *dmabuf)
  10294. {
  10295. struct hbq_dmabuf *seq_dmabuf;
  10296. struct fc_frame_header *fc_hdr;
  10297. struct lpfc_vport *vport;
  10298. uint32_t fcfi;
  10299. /* Process each received buffer */
  10300. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10301. /* check to see if this a valid type of frame */
  10302. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10303. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10304. return;
  10305. }
  10306. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10307. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10308. if (!vport) {
  10309. /* throw out the frame */
  10310. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10311. return;
  10312. }
  10313. /* Handle the basic abort sequence (BA_ABTS) event */
  10314. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10315. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10316. return;
  10317. }
  10318. /* Link this frame */
  10319. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10320. if (!seq_dmabuf) {
  10321. /* unable to add frame to vport - throw it out */
  10322. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10323. return;
  10324. }
  10325. /* If not last frame in sequence continue processing frames. */
  10326. if (!lpfc_seq_complete(seq_dmabuf)) {
  10327. /*
  10328. * When saving off frames post a new one and mark this
  10329. * frame to be freed when it is finished.
  10330. **/
  10331. lpfc_sli_hbqbuf_fill_hbqs(phba, LPFC_ELS_HBQ, 1);
  10332. dmabuf->tag = -1;
  10333. return;
  10334. }
  10335. /* Send the complete sequence to the upper layer protocol */
  10336. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10337. }
  10338. /**
  10339. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10340. * @phba: pointer to lpfc hba data structure.
  10341. *
  10342. * This routine is invoked to post rpi header templates to the
  10343. * HBA consistent with the SLI-4 interface spec. This routine
  10344. * posts a PAGE_SIZE memory region to the port to hold up to
  10345. * PAGE_SIZE modulo 64 rpi context headers.
  10346. *
  10347. * This routine does not require any locks. It's usage is expected
  10348. * to be driver load or reset recovery when the driver is
  10349. * sequential.
  10350. *
  10351. * Return codes
  10352. * 0 - sucessful
  10353. * EIO - The mailbox failed to complete successfully.
  10354. * When this error occurs, the driver is not guaranteed
  10355. * to have any rpi regions posted to the device and
  10356. * must either attempt to repost the regions or take a
  10357. * fatal error.
  10358. **/
  10359. int
  10360. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10361. {
  10362. struct lpfc_rpi_hdr *rpi_page;
  10363. uint32_t rc = 0;
  10364. /* Post all rpi memory regions to the port. */
  10365. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10366. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10367. if (rc != MBX_SUCCESS) {
  10368. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10369. "2008 Error %d posting all rpi "
  10370. "headers\n", rc);
  10371. rc = -EIO;
  10372. break;
  10373. }
  10374. }
  10375. return rc;
  10376. }
  10377. /**
  10378. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10379. * @phba: pointer to lpfc hba data structure.
  10380. * @rpi_page: pointer to the rpi memory region.
  10381. *
  10382. * This routine is invoked to post a single rpi header to the
  10383. * HBA consistent with the SLI-4 interface spec. This memory region
  10384. * maps up to 64 rpi context regions.
  10385. *
  10386. * Return codes
  10387. * 0 - sucessful
  10388. * ENOMEM - No available memory
  10389. * EIO - The mailbox failed to complete successfully.
  10390. **/
  10391. int
  10392. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10393. {
  10394. LPFC_MBOXQ_t *mboxq;
  10395. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10396. uint32_t rc = 0;
  10397. uint32_t mbox_tmo;
  10398. uint32_t shdr_status, shdr_add_status;
  10399. union lpfc_sli4_cfg_shdr *shdr;
  10400. /* The port is notified of the header region via a mailbox command. */
  10401. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10402. if (!mboxq) {
  10403. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10404. "2001 Unable to allocate memory for issuing "
  10405. "SLI_CONFIG_SPECIAL mailbox command\n");
  10406. return -ENOMEM;
  10407. }
  10408. /* Post all rpi memory regions to the port. */
  10409. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10410. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10411. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10412. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10413. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10414. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10415. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10416. hdr_tmpl, rpi_page->page_count);
  10417. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10418. rpi_page->start_rpi);
  10419. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10420. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10421. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10422. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10423. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10424. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10425. if (rc != MBX_TIMEOUT)
  10426. mempool_free(mboxq, phba->mbox_mem_pool);
  10427. if (shdr_status || shdr_add_status || rc) {
  10428. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10429. "2514 POST_RPI_HDR mailbox failed with "
  10430. "status x%x add_status x%x, mbx status x%x\n",
  10431. shdr_status, shdr_add_status, rc);
  10432. rc = -ENXIO;
  10433. }
  10434. return rc;
  10435. }
  10436. /**
  10437. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10438. * @phba: pointer to lpfc hba data structure.
  10439. *
  10440. * This routine is invoked to post rpi header templates to the
  10441. * HBA consistent with the SLI-4 interface spec. This routine
  10442. * posts a PAGE_SIZE memory region to the port to hold up to
  10443. * PAGE_SIZE modulo 64 rpi context headers.
  10444. *
  10445. * Returns
  10446. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if sucessful
  10447. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10448. **/
  10449. int
  10450. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10451. {
  10452. int rpi;
  10453. uint16_t max_rpi, rpi_base, rpi_limit;
  10454. uint16_t rpi_remaining;
  10455. struct lpfc_rpi_hdr *rpi_hdr;
  10456. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10457. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10458. rpi_limit = phba->sli4_hba.next_rpi;
  10459. /*
  10460. * The valid rpi range is not guaranteed to be zero-based. Start
  10461. * the search at the rpi_base as reported by the port.
  10462. */
  10463. spin_lock_irq(&phba->hbalock);
  10464. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10465. if (rpi >= rpi_limit || rpi < rpi_base)
  10466. rpi = LPFC_RPI_ALLOC_ERROR;
  10467. else {
  10468. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10469. phba->sli4_hba.max_cfg_param.rpi_used++;
  10470. phba->sli4_hba.rpi_count++;
  10471. }
  10472. /*
  10473. * Don't try to allocate more rpi header regions if the device limit
  10474. * on available rpis max has been exhausted.
  10475. */
  10476. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10477. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10478. spin_unlock_irq(&phba->hbalock);
  10479. return rpi;
  10480. }
  10481. /*
  10482. * If the driver is running low on rpi resources, allocate another
  10483. * page now. Note that the next_rpi value is used because
  10484. * it represents how many are actually in use whereas max_rpi notes
  10485. * how many are supported max by the device.
  10486. */
  10487. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10488. phba->sli4_hba.rpi_count;
  10489. spin_unlock_irq(&phba->hbalock);
  10490. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10491. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10492. if (!rpi_hdr) {
  10493. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10494. "2002 Error Could not grow rpi "
  10495. "count\n");
  10496. } else {
  10497. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10498. }
  10499. }
  10500. return rpi;
  10501. }
  10502. /**
  10503. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10504. * @phba: pointer to lpfc hba data structure.
  10505. *
  10506. * This routine is invoked to release an rpi to the pool of
  10507. * available rpis maintained by the driver.
  10508. **/
  10509. void
  10510. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10511. {
  10512. spin_lock_irq(&phba->hbalock);
  10513. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10514. phba->sli4_hba.rpi_count--;
  10515. phba->sli4_hba.max_cfg_param.rpi_used--;
  10516. spin_unlock_irq(&phba->hbalock);
  10517. }
  10518. /**
  10519. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10520. * @phba: pointer to lpfc hba data structure.
  10521. *
  10522. * This routine is invoked to remove the memory region that
  10523. * provided rpi via a bitmask.
  10524. **/
  10525. void
  10526. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10527. {
  10528. kfree(phba->sli4_hba.rpi_bmask);
  10529. }
  10530. /**
  10531. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10532. * @phba: pointer to lpfc hba data structure.
  10533. *
  10534. * This routine is invoked to remove the memory region that
  10535. * provided rpi via a bitmask.
  10536. **/
  10537. int
  10538. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10539. {
  10540. LPFC_MBOXQ_t *mboxq;
  10541. struct lpfc_hba *phba = ndlp->phba;
  10542. int rc;
  10543. /* The port is notified of the header region via a mailbox command. */
  10544. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10545. if (!mboxq)
  10546. return -ENOMEM;
  10547. /* Post all rpi memory regions to the port. */
  10548. lpfc_resume_rpi(mboxq, ndlp);
  10549. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10550. if (rc == MBX_NOT_FINISHED) {
  10551. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10552. "2010 Resume RPI Mailbox failed "
  10553. "status %d, mbxStatus x%x\n", rc,
  10554. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10555. mempool_free(mboxq, phba->mbox_mem_pool);
  10556. return -EIO;
  10557. }
  10558. return 0;
  10559. }
  10560. /**
  10561. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10562. * @phba: pointer to lpfc hba data structure.
  10563. * @vpi: vpi value to activate with the port.
  10564. *
  10565. * This routine is invoked to activate a vpi with the
  10566. * port when the host intends to use vports with a
  10567. * nonzero vpi.
  10568. *
  10569. * Returns:
  10570. * 0 success
  10571. * -Evalue otherwise
  10572. **/
  10573. int
  10574. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10575. {
  10576. LPFC_MBOXQ_t *mboxq;
  10577. int rc = 0;
  10578. int retval = MBX_SUCCESS;
  10579. uint32_t mbox_tmo;
  10580. if (vpi == 0)
  10581. return -EINVAL;
  10582. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10583. if (!mboxq)
  10584. return -ENOMEM;
  10585. lpfc_init_vpi(phba, mboxq, vpi);
  10586. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10587. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10588. if (rc != MBX_SUCCESS) {
  10589. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10590. "2022 INIT VPI Mailbox failed "
  10591. "status %d, mbxStatus x%x\n", rc,
  10592. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10593. retval = -EIO;
  10594. }
  10595. if (rc != MBX_TIMEOUT)
  10596. mempool_free(mboxq, phba->mbox_mem_pool);
  10597. return retval;
  10598. }
  10599. /**
  10600. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10601. * @phba: pointer to lpfc hba data structure.
  10602. * @mboxq: Pointer to mailbox object.
  10603. *
  10604. * This routine is invoked to manually add a single FCF record. The caller
  10605. * must pass a completely initialized FCF_Record. This routine takes
  10606. * care of the nonembedded mailbox operations.
  10607. **/
  10608. static void
  10609. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10610. {
  10611. void *virt_addr;
  10612. union lpfc_sli4_cfg_shdr *shdr;
  10613. uint32_t shdr_status, shdr_add_status;
  10614. virt_addr = mboxq->sge_array->addr[0];
  10615. /* The IOCTL status is embedded in the mailbox subheader. */
  10616. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10617. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10618. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10619. if ((shdr_status || shdr_add_status) &&
  10620. (shdr_status != STATUS_FCF_IN_USE))
  10621. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10622. "2558 ADD_FCF_RECORD mailbox failed with "
  10623. "status x%x add_status x%x\n",
  10624. shdr_status, shdr_add_status);
  10625. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10626. }
  10627. /**
  10628. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10629. * @phba: pointer to lpfc hba data structure.
  10630. * @fcf_record: pointer to the initialized fcf record to add.
  10631. *
  10632. * This routine is invoked to manually add a single FCF record. The caller
  10633. * must pass a completely initialized FCF_Record. This routine takes
  10634. * care of the nonembedded mailbox operations.
  10635. **/
  10636. int
  10637. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10638. {
  10639. int rc = 0;
  10640. LPFC_MBOXQ_t *mboxq;
  10641. uint8_t *bytep;
  10642. void *virt_addr;
  10643. dma_addr_t phys_addr;
  10644. struct lpfc_mbx_sge sge;
  10645. uint32_t alloc_len, req_len;
  10646. uint32_t fcfindex;
  10647. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10648. if (!mboxq) {
  10649. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10650. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10651. return -ENOMEM;
  10652. }
  10653. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10654. sizeof(uint32_t);
  10655. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10656. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10657. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10658. req_len, LPFC_SLI4_MBX_NEMBED);
  10659. if (alloc_len < req_len) {
  10660. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10661. "2523 Allocated DMA memory size (x%x) is "
  10662. "less than the requested DMA memory "
  10663. "size (x%x)\n", alloc_len, req_len);
  10664. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10665. return -ENOMEM;
  10666. }
  10667. /*
  10668. * Get the first SGE entry from the non-embedded DMA memory. This
  10669. * routine only uses a single SGE.
  10670. */
  10671. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10672. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10673. virt_addr = mboxq->sge_array->addr[0];
  10674. /*
  10675. * Configure the FCF record for FCFI 0. This is the driver's
  10676. * hardcoded default and gets used in nonFIP mode.
  10677. */
  10678. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10679. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10680. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10681. /*
  10682. * Copy the fcf_index and the FCF Record Data. The data starts after
  10683. * the FCoE header plus word10. The data copy needs to be endian
  10684. * correct.
  10685. */
  10686. bytep += sizeof(uint32_t);
  10687. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10688. mboxq->vport = phba->pport;
  10689. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10690. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10691. if (rc == MBX_NOT_FINISHED) {
  10692. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10693. "2515 ADD_FCF_RECORD mailbox failed with "
  10694. "status 0x%x\n", rc);
  10695. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10696. rc = -EIO;
  10697. } else
  10698. rc = 0;
  10699. return rc;
  10700. }
  10701. /**
  10702. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10703. * @phba: pointer to lpfc hba data structure.
  10704. * @fcf_record: pointer to the fcf record to write the default data.
  10705. * @fcf_index: FCF table entry index.
  10706. *
  10707. * This routine is invoked to build the driver's default FCF record. The
  10708. * values used are hardcoded. This routine handles memory initialization.
  10709. *
  10710. **/
  10711. void
  10712. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10713. struct fcf_record *fcf_record,
  10714. uint16_t fcf_index)
  10715. {
  10716. memset(fcf_record, 0, sizeof(struct fcf_record));
  10717. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10718. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10719. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10720. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10721. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10722. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10723. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10724. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10725. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10726. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10727. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10728. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10729. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10730. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  10731. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10732. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10733. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10734. /* Set the VLAN bit map */
  10735. if (phba->valid_vlan) {
  10736. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10737. = 1 << (phba->vlan_id % 8);
  10738. }
  10739. }
  10740. /**
  10741. * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
  10742. * @phba: pointer to lpfc hba data structure.
  10743. * @fcf_index: FCF table entry offset.
  10744. *
  10745. * This routine is invoked to read up to @fcf_num of FCF record from the
  10746. * device starting with the given @fcf_index.
  10747. **/
  10748. int
  10749. lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
  10750. {
  10751. int rc = 0, error;
  10752. LPFC_MBOXQ_t *mboxq;
  10753. void *virt_addr;
  10754. dma_addr_t phys_addr;
  10755. uint8_t *bytep;
  10756. struct lpfc_mbx_sge sge;
  10757. uint32_t alloc_len, req_len;
  10758. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  10759. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  10760. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10761. if (!mboxq) {
  10762. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10763. "2000 Failed to allocate mbox for "
  10764. "READ_FCF cmd\n");
  10765. error = -ENOMEM;
  10766. goto fail_fcfscan;
  10767. }
  10768. req_len = sizeof(struct fcf_record) +
  10769. sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
  10770. /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
  10771. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10772. LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
  10773. LPFC_SLI4_MBX_NEMBED);
  10774. if (alloc_len < req_len) {
  10775. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10776. "0291 Allocated DMA memory size (x%x) is "
  10777. "less than the requested DMA memory "
  10778. "size (x%x)\n", alloc_len, req_len);
  10779. error = -ENOMEM;
  10780. goto fail_fcfscan;
  10781. }
  10782. /* Get the first SGE entry from the non-embedded DMA memory. This
  10783. * routine only uses a single SGE.
  10784. */
  10785. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10786. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10787. virt_addr = mboxq->sge_array->addr[0];
  10788. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  10789. /* Set up command fields */
  10790. bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
  10791. /* Perform necessary endian conversion */
  10792. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10793. lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
  10794. mboxq->vport = phba->pport;
  10795. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
  10796. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10797. if (rc == MBX_NOT_FINISHED) {
  10798. error = -EIO;
  10799. } else {
  10800. spin_lock_irq(&phba->hbalock);
  10801. phba->hba_flag |= FCF_DISC_INPROGRESS;
  10802. spin_unlock_irq(&phba->hbalock);
  10803. error = 0;
  10804. }
  10805. fail_fcfscan:
  10806. if (error) {
  10807. if (mboxq)
  10808. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10809. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  10810. spin_lock_irq(&phba->hbalock);
  10811. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  10812. spin_unlock_irq(&phba->hbalock);
  10813. }
  10814. return error;
  10815. }
  10816. /**
  10817. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  10818. * @phba: pointer to lpfc hba data structure.
  10819. *
  10820. * This function read region 23 and parse TLV for port status to
  10821. * decide if the user disaled the port. If the TLV indicates the
  10822. * port is disabled, the hba_flag is set accordingly.
  10823. **/
  10824. void
  10825. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  10826. {
  10827. LPFC_MBOXQ_t *pmb = NULL;
  10828. MAILBOX_t *mb;
  10829. uint8_t *rgn23_data = NULL;
  10830. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  10831. int rc;
  10832. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10833. if (!pmb) {
  10834. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10835. "2600 lpfc_sli_read_serdes_param failed to"
  10836. " allocate mailbox memory\n");
  10837. goto out;
  10838. }
  10839. mb = &pmb->u.mb;
  10840. /* Get adapter Region 23 data */
  10841. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  10842. if (!rgn23_data)
  10843. goto out;
  10844. do {
  10845. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  10846. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  10847. if (rc != MBX_SUCCESS) {
  10848. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10849. "2601 lpfc_sli_read_link_ste failed to"
  10850. " read config region 23 rc 0x%x Status 0x%x\n",
  10851. rc, mb->mbxStatus);
  10852. mb->un.varDmp.word_cnt = 0;
  10853. }
  10854. /*
  10855. * dump mem may return a zero when finished or we got a
  10856. * mailbox error, either way we are done.
  10857. */
  10858. if (mb->un.varDmp.word_cnt == 0)
  10859. break;
  10860. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  10861. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  10862. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  10863. rgn23_data + offset,
  10864. mb->un.varDmp.word_cnt);
  10865. offset += mb->un.varDmp.word_cnt;
  10866. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  10867. data_size = offset;
  10868. offset = 0;
  10869. if (!data_size)
  10870. goto out;
  10871. /* Check the region signature first */
  10872. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  10873. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10874. "2619 Config region 23 has bad signature\n");
  10875. goto out;
  10876. }
  10877. offset += 4;
  10878. /* Check the data structure version */
  10879. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  10880. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10881. "2620 Config region 23 has bad version\n");
  10882. goto out;
  10883. }
  10884. offset += 4;
  10885. /* Parse TLV entries in the region */
  10886. while (offset < data_size) {
  10887. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  10888. break;
  10889. /*
  10890. * If the TLV is not driver specific TLV or driver id is
  10891. * not linux driver id, skip the record.
  10892. */
  10893. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  10894. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  10895. (rgn23_data[offset + 3] != 0)) {
  10896. offset += rgn23_data[offset + 1] * 4 + 4;
  10897. continue;
  10898. }
  10899. /* Driver found a driver specific TLV in the config region */
  10900. sub_tlv_len = rgn23_data[offset + 1] * 4;
  10901. offset += 4;
  10902. tlv_offset = 0;
  10903. /*
  10904. * Search for configured port state sub-TLV.
  10905. */
  10906. while ((offset < data_size) &&
  10907. (tlv_offset < sub_tlv_len)) {
  10908. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  10909. offset += 4;
  10910. tlv_offset += 4;
  10911. break;
  10912. }
  10913. if (rgn23_data[offset] != PORT_STE_TYPE) {
  10914. offset += rgn23_data[offset + 1] * 4 + 4;
  10915. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  10916. continue;
  10917. }
  10918. /* This HBA contains PORT_STE configured */
  10919. if (!rgn23_data[offset + 2])
  10920. phba->hba_flag |= LINK_DISABLED;
  10921. goto out;
  10922. }
  10923. }
  10924. out:
  10925. if (pmb)
  10926. mempool_free(pmb, phba->mbox_mem_pool);
  10927. kfree(rgn23_data);
  10928. return;
  10929. }